support openai response format through config

This commit is contained in:
Yang 2026-02-17 22:23:19 +08:00
parent 920e30a241
commit 66591dfdb7
3 changed files with 16 additions and 1 deletions

View file

@ -188,6 +188,7 @@ type ProviderConfig struct {
Proxy string `json:"proxy,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_PROXY"` Proxy string `json:"proxy,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_PROXY"`
AuthMethod string `json:"auth_method,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_AUTH_METHOD"` AuthMethod string `json:"auth_method,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_AUTH_METHOD"`
ConnectMode string `json:"connect_mode,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_CONNECT_MODE"` //only for Github Copilot, `stdio` or `grpc` ConnectMode string `json:"connect_mode,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_CONNECT_MODE"` //only for Github Copilot, `stdio` or `grpc`
APIFormat string `json:"api_format,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_API_FORMAT"` // "responses" to use OpenAI Responses API
} }
type GatewayConfig struct { type GatewayConfig struct {

View file

@ -26,8 +26,15 @@ type CodexProvider struct {
const defaultCodexInstructions = "You are Codex, a coding assistant." const defaultCodexInstructions = "You are Codex, a coding assistant."
func NewCodexProvider(token, accountID string) *CodexProvider { func NewCodexProvider(token, accountID string) *CodexProvider {
return NewCodexProviderWithBase(token, accountID, "https://chatgpt.com/backend-api/codex")
}
func NewCodexProviderWithBase(token, accountID, baseURL string) *CodexProvider {
if baseURL == "" {
baseURL = "https://chatgpt.com/backend-api/codex"
}
opts := []option.RequestOption{ opts := []option.RequestOption{
option.WithBaseURL("https://chatgpt.com/backend-api/codex"), option.WithBaseURL(baseURL),
option.WithAPIKey(token), option.WithAPIKey(token),
option.WithHeader("originator", "codex_cli_rs"), option.WithHeader("originator", "codex_cli_rs"),
option.WithHeader("OpenAI-Beta", "responses=experimental"), option.WithHeader("OpenAI-Beta", "responses=experimental"),

View file

@ -246,6 +246,13 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) {
if cfg.Providers.OpenAI.AuthMethod == "oauth" || cfg.Providers.OpenAI.AuthMethod == "token" { if cfg.Providers.OpenAI.AuthMethod == "oauth" || cfg.Providers.OpenAI.AuthMethod == "token" {
return createCodexAuthProvider() return createCodexAuthProvider()
} }
if cfg.Providers.OpenAI.APIFormat == "responses" {
base := cfg.Providers.OpenAI.APIBase
if base == "" {
base = "https://api.openai.com/v1"
}
return NewCodexProviderWithBase(cfg.Providers.OpenAI.APIKey, "", base), nil
}
apiKey = cfg.Providers.OpenAI.APIKey apiKey = cfg.Providers.OpenAI.APIKey
apiBase = cfg.Providers.OpenAI.APIBase apiBase = cfg.Providers.OpenAI.APIBase
if apiBase == "" { if apiBase == "" {