Skip to content

Commit 667998d

Browse files
default the api_type as openai_response for appropriate github copilot models
1 parent d773763 commit 667998d

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

pkg/model/provider/provider.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ func applyModelDefaults(cfg *latest.ModelConfig) {
422422
return
423423
}
424424

425+
// Set appropriate github copilot api_type.
426+
applyGithubCopilotAPIType(cfg)
427+
425428
// No thinking_budget configured — only thinking-only models get a default.
426429
switch providerType {
427430
case "openai", "openai_chatcompletions", "openai_responses":
@@ -467,6 +470,19 @@ func ensureInterleavedThinking(cfg *latest.ModelConfig, providerType string) {
467470
}
468471
}
469472

473+
// applyGithubCopilotAPIType ensures api_type is set to openai_responses for appropriate models.
474+
func applyGithubCopilotAPIType(cfg *latest.ModelConfig) {
475+
if isGithubCopilotProvider(cfg.Provider) && isCopilotResponsesModel(cfg.Model) {
476+
if cfg.ProviderOpts == nil {
477+
cfg.ProviderOpts = make(map[string]any)
478+
}
479+
// If it's not set, or was set to openai_chatcompletions by the generic fallback, override it.
480+
if apiType, ok := cfg.ProviderOpts["api_type"].(string); !ok || apiType == "" || apiType == "openai_chatcompletions" {
481+
cfg.ProviderOpts["api_type"] = "openai_responses"
482+
}
483+
}
484+
}
485+
470486
// isOpenAIThinkingOnlyModel returns true for OpenAI models that require thinking
471487
// to function properly (o-series reasoning models).
472488
func isOpenAIThinkingOnlyModel(model string) bool {
@@ -529,6 +545,23 @@ func resolveEffectiveProvider(cfg latest.ProviderConfig) string {
529545
return "openai"
530546
}
531547

548+
func isGithubCopilotProvider(providerType string) bool {
549+
switch providerType {
550+
case "github-copilot":
551+
return true
552+
default:
553+
return false
554+
}
555+
}
556+
557+
func isCopilotResponsesModel(model string) bool {
558+
codex := map[string]bool{
559+
"gpt-5.3-codex": true,
560+
"gpt-5.2-codex": true,
561+
}
562+
return codex[model]
563+
}
564+
532565
// isOpenAICompatibleProvider returns true if the provider type uses the OpenAI API protocol.
533566
func isOpenAICompatibleProvider(providerType string) bool {
534567
switch providerType {

pkg/model/provider/provider_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"testing"
55

66
"github.com/stretchr/testify/assert"
7+
8+
"github.com/docker/docker-agent/pkg/config/latest"
79
)
810

911
func TestCatalogProviders(t *testing.T) {
@@ -88,3 +90,50 @@ func TestIsKnownProvider(t *testing.T) {
8890
assert.False(t, IsKnownProvider("unknown"))
8991
assert.False(t, IsKnownProvider(""))
9092
}
93+
94+
func TestIsGithubCopilotProvider(t *testing.T) {
95+
t.Parallel()
96+
97+
assert.True(t, isGithubCopilotProvider("github-copilot"))
98+
assert.False(t, isGithubCopilotProvider("openai"))
99+
assert.False(t, isGithubCopilotProvider(""))
100+
}
101+
102+
func TestIsCopilotResponsesModel(t *testing.T) {
103+
t.Parallel()
104+
105+
assert.True(t, isCopilotResponsesModel("gpt-5.3-codex"))
106+
assert.True(t, isCopilotResponsesModel("gpt-5.2-codex"))
107+
assert.False(t, isCopilotResponsesModel("gpt-4o"))
108+
assert.False(t, isCopilotResponsesModel("claude-sonnet-4-5"))
109+
assert.False(t, isCopilotResponsesModel(""))
110+
}
111+
112+
func TestGithubCopilotApiType(t *testing.T) {
113+
cfg := &latest.ModelConfig{
114+
Provider: "github-copilot",
115+
Model: "gpt-5.3-codex",
116+
}
117+
118+
enhancedCfg := applyProviderDefaults(cfg, nil)
119+
120+
apiType := resolveProviderType(enhancedCfg)
121+
122+
if apiType != "openai_responses" {
123+
t.Errorf("Expected api_type to be 'openai_responses', got '%s'", apiType)
124+
}
125+
126+
// test when it is a custom provider
127+
customProviders := map[string]latest.ProviderConfig{
128+
"github-copilot": {
129+
Provider: "github-copilot",
130+
},
131+
}
132+
133+
enhancedCfg2 := applyProviderDefaults(cfg, customProviders)
134+
apiType2 := resolveProviderType(enhancedCfg2)
135+
136+
if apiType2 != "openai_responses" {
137+
t.Errorf("Expected api_type to be 'openai_responses', got '%s'", apiType2)
138+
}
139+
}

0 commit comments

Comments
 (0)