fix(provider): preserve @cf model identifiers
This commit is contained in:
parent
5bc4fe4dea
commit
9897923c86
4 changed files with 51 additions and 0 deletions
|
|
@ -46,6 +46,9 @@ func createCodexAuthProvider() (LLMProvider, error) {
|
||||||
// - "gpt-4o" -> ("openai", "gpt-4o") // default protocol
|
// - "gpt-4o" -> ("openai", "gpt-4o") // default protocol
|
||||||
func ExtractProtocol(model string) (protocol, modelID string) {
|
func ExtractProtocol(model string) (protocol, modelID string) {
|
||||||
model = strings.TrimSpace(model)
|
model = strings.TrimSpace(model)
|
||||||
|
if strings.HasPrefix(model, "@") {
|
||||||
|
return "openai", model
|
||||||
|
}
|
||||||
protocol, modelID, found := strings.Cut(model, "/")
|
protocol, modelID, found := strings.Cut(model, "/")
|
||||||
if !found {
|
if !found {
|
||||||
return "openai", model
|
return "openai", model
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,12 @@ func TestExtractProtocol(t *testing.T) {
|
||||||
wantProtocol: "azure",
|
wantProtocol: "azure",
|
||||||
wantModelID: "my-gpt5-deployment",
|
wantModelID: "my-gpt5-deployment",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "at-prefixed cloudflare model id",
|
||||||
|
model: "@cf/qwen/qwen1.5-0.5b-chat",
|
||||||
|
wantProtocol: "openai",
|
||||||
|
wantModelID: "@cf/qwen/qwen1.5-0.5b-chat",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
@ -105,6 +111,26 @@ func TestCreateProviderFromConfig_OpenAI(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateProviderFromConfig_OpenAIPreservesAtPrefixedModelID(t *testing.T) {
|
||||||
|
cfg := &config.ModelConfig{
|
||||||
|
ModelName: "test-cf-openai",
|
||||||
|
Model: "@cf/qwen/qwen1.5-0.5b-chat",
|
||||||
|
APIKey: "test-key",
|
||||||
|
APIBase: "https://api.example.com/v1",
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, modelID, err := CreateProviderFromConfig(cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("CreateProviderFromConfig() error = %v", err)
|
||||||
|
}
|
||||||
|
if provider == nil {
|
||||||
|
t.Fatal("CreateProviderFromConfig() returned nil provider")
|
||||||
|
}
|
||||||
|
if modelID != "@cf/qwen/qwen1.5-0.5b-chat" {
|
||||||
|
t.Fatalf("modelID = %q, want full @cf model id", modelID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateProviderFromConfig_DefaultAPIBase(t *testing.T) {
|
func TestCreateProviderFromConfig_DefaultAPIBase(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,15 @@ func ParseModelRef(raw string, defaultProvider string) *ModelRef {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Providers like Cloudflare use model IDs such as "@cf/..." where the slash
|
||||||
|
// belongs to the model path, not a provider prefix.
|
||||||
|
if strings.HasPrefix(raw, "@") {
|
||||||
|
return &ModelRef{
|
||||||
|
Provider: NormalizeProvider(defaultProvider),
|
||||||
|
Model: raw,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if idx := strings.Index(raw, "/"); idx > 0 {
|
if idx := strings.Index(raw, "/"); idx > 0 {
|
||||||
provider := NormalizeProvider(raw[:idx])
|
provider := NormalizeProvider(raw[:idx])
|
||||||
model := strings.TrimSpace(raw[idx+1:])
|
model := strings.TrimSpace(raw[idx+1:])
|
||||||
|
|
|
||||||
|
|
@ -123,3 +123,16 @@ func TestParseModelRef_DefaultProviderNormalization(t *testing.T) {
|
||||||
t.Errorf("provider = %q, want openai (normalized from GPT)", ref.Provider)
|
t.Errorf("provider = %q, want openai (normalized from GPT)", ref.Provider)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseModelRef_AtPrefixedModelUsesDefaultProvider(t *testing.T) {
|
||||||
|
ref := ParseModelRef("@cf/qwen/qwen1.5-0.5b-chat", "openai")
|
||||||
|
if ref == nil {
|
||||||
|
t.Fatal("expected non-nil ref")
|
||||||
|
}
|
||||||
|
if ref.Provider != "openai" {
|
||||||
|
t.Fatalf("provider = %q, want %q", ref.Provider, "openai")
|
||||||
|
}
|
||||||
|
if ref.Model != "@cf/qwen/qwen1.5-0.5b-chat" {
|
||||||
|
t.Fatalf("model = %q, want full @cf model id", ref.Model)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue