Skip to content

Commit 7a86964

Browse files
author
OpenClaw-User
committed
Merge PR sipeed#1399
2 parents e8d6bff + 1ed21fd commit 7a86964

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

pkg/config/migration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ func ConvertProvidersToModelList(cfg *Config) []ModelConfig {
453453
// Check if this is the user's configured provider
454454
if slices.Contains(m.providerNames, userProvider) && userModel != "" {
455455
// Use the user's configured model instead of default
456+
mc.ModelName = userModel
456457
mc.Model = buildModelWithProtocol(m.protocol, userModel)
457458
} else if userProvider == "" && userModel != "" && !legacyModelNameApplied {
458459
// Legacy config: no explicit provider field but model is specified

pkg/config/migration_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ func TestConvertProvidersToModelList_PreservesUserModel_OpenAI(t *testing.T) {
283283
t.Fatalf("len(result) = %d, want 1", len(result))
284284
}
285285

286+
if result[0].ModelName != "gpt-4-turbo" {
287+
t.Errorf("ModelName = %q, want %q", result[0].ModelName, "gpt-4-turbo")
288+
}
289+
286290
if result[0].Model != "openai/gpt-4-turbo" {
287291
t.Errorf("Model = %q, want %q", result[0].Model, "openai/gpt-4-turbo")
288292
}
@@ -331,11 +335,43 @@ func TestConvertProvidersToModelList_PreservesUserModel_Qwen(t *testing.T) {
331335
t.Fatalf("len(result) = %d, want 1", len(result))
332336
}
333337

338+
if result[0].ModelName != "qwen-plus" {
339+
t.Errorf("ModelName = %q, want %q", result[0].ModelName, "qwen-plus")
340+
}
341+
334342
if result[0].Model != "qwen/qwen-plus" {
335343
t.Errorf("Model = %q, want %q", result[0].Model, "qwen/qwen-plus")
336344
}
337345
}
338346

347+
func TestConvertProvidersToModelList_PreservesUserModelName_Ollama(t *testing.T) {
348+
cfg := &Config{
349+
Agents: AgentsConfig{
350+
Defaults: AgentDefaults{
351+
Provider: "ollama",
352+
Model: "llama3.2",
353+
},
354+
},
355+
Providers: ProvidersConfig{
356+
Ollama: ProviderConfig{
357+
APIBase: "http://localhost:11434/v1",
358+
},
359+
},
360+
}
361+
362+
result := ConvertProvidersToModelList(cfg)
363+
364+
if len(result) != 1 {
365+
t.Fatalf("len(result) = %d, want 1", len(result))
366+
}
367+
if result[0].ModelName != "llama3.2" {
368+
t.Fatalf("ModelName = %q, want %q", result[0].ModelName, "llama3.2")
369+
}
370+
if result[0].Model != "ollama/llama3.2" {
371+
t.Fatalf("Model = %q, want %q", result[0].Model, "ollama/llama3.2")
372+
}
373+
}
374+
339375
func TestConvertProvidersToModelList_UsesDefaultWhenNoUserModel(t *testing.T) {
340376
cfg := &Config{
341377
Agents: AgentsConfig{

pkg/providers/factory_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,24 @@ func TestCreateProviderReturnsClaudeProviderForAnthropicOAuth(t *testing.T) {
344344
// TODO: Test custom APIBase when createClaudeAuthProvider supports it
345345
}
346346

347+
func TestCreateProvider_LegacyOllamaProviderUsesUserModelAlias(t *testing.T) {
348+
cfg := config.DefaultConfig()
349+
cfg.Agents.Defaults.Provider = "ollama"
350+
cfg.Agents.Defaults.Model = "llama3.2"
351+
cfg.Providers.Ollama.APIBase = "http://localhost:11434/v1"
352+
353+
provider, modelID, err := CreateProvider(cfg)
354+
if err != nil {
355+
t.Fatalf("CreateProvider() error = %v", err)
356+
}
357+
if provider == nil {
358+
t.Fatal("CreateProvider() returned nil provider")
359+
}
360+
if modelID != "llama3.2" {
361+
t.Fatalf("modelID = %q, want %q", modelID, "llama3.2")
362+
}
363+
}
364+
347365
func TestCreateProviderReturnsCodexProviderForOpenAIOAuth(t *testing.T) {
348366
// TODO: This test requires openai protocol to support auth_method: "oauth"
349367
// which is not yet implemented in the new factory_provider.go

0 commit comments

Comments
 (0)