Merge PR #1398
This commit is contained in:
commit
e8d6bff740
4 changed files with 49 additions and 0 deletions
|
|
@ -45,6 +45,9 @@ func createCodexAuthProvider() (LLMProvider, error) {
|
|||
// - "gpt-4o" -> ("openai", "gpt-4o") // default protocol
|
||||
func ExtractProtocol(model string) (protocol, modelID string) {
|
||||
model = strings.TrimSpace(model)
|
||||
if strings.HasPrefix(model, "@") {
|
||||
return "openai", model
|
||||
}
|
||||
protocol, modelID, found := strings.Cut(model, "/")
|
||||
if !found {
|
||||
return "openai", model
|
||||
|
|
|
|||
|
|
@ -64,6 +64,12 @@ func TestExtractProtocol(t *testing.T) {
|
|||
wantProtocol: "nvidia",
|
||||
wantModelID: "meta/llama-3.1-8b",
|
||||
},
|
||||
{
|
||||
name: "cloudflare model id keeps full path",
|
||||
model: "@cf/qwen/qwen1.5-0.5b-chat",
|
||||
wantProtocol: "openai",
|
||||
wantModelID: "@cf/qwen/qwen1.5-0.5b-chat",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -99,6 +105,26 @@ func TestCreateProviderFromConfig_OpenAI(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCreateProviderFromConfig_CloudflareModelID(t *testing.T) {
|
||||
cfg := &config.ModelConfig{
|
||||
ModelName: "cf-qwen",
|
||||
Model: "@cf/qwen/qwen1.5-0.5b-chat",
|
||||
APIKey: "test-key",
|
||||
APIBase: "https://api.cloudflare.com/client/v4/accounts/test/ai/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 %q", modelID, "@cf/qwen/qwen1.5-0.5b-chat")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateProviderFromConfig_DefaultAPIBase(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
|||
|
|
@ -17,6 +17,13 @@ func ParseModelRef(raw string, defaultProvider string) *ModelRef {
|
|||
return nil
|
||||
}
|
||||
|
||||
if strings.HasPrefix(raw, "@") {
|
||||
return &ModelRef{
|
||||
Provider: NormalizeProvider(defaultProvider),
|
||||
Model: raw,
|
||||
}
|
||||
}
|
||||
|
||||
if idx := strings.Index(raw, "/"); idx > 0 {
|
||||
provider := NormalizeProvider(raw[:idx])
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseModelRef_CloudflareModelPathUsesDefaultProvider(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 openai", ref.Provider)
|
||||
}
|
||||
if ref.Model != "@cf/qwen/qwen1.5-0.5b-chat" {
|
||||
t.Fatalf("model = %q, want %q", ref.Model, "@cf/qwen/qwen1.5-0.5b-chat")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue