diff --git a/internal/provider/workbuddy_models.go b/internal/provider/workbuddy_models.go index 7548d5954..de46c3657 100644 --- a/internal/provider/workbuddy_models.go +++ b/internal/provider/workbuddy_models.go @@ -13,6 +13,7 @@ import ( "fmt" "io" "net/http" + "strings" "github.com/yetone/magpie/internal/catalog" ) @@ -108,5 +109,26 @@ func (c wbProductConfig) cliModels() []catalog.Model { out = append(out, m) } } - return out + return wbDistinctNames(out) +} + +// wbDistinctNames tells apart models the config gives the same name: +// WorkBuddy AI lists deepseek-v4.1-flash (free) and deepseek-v4.1-flash-sg +// (Singapore, x0.03 credits) both as "Deepseek-V4.1-Flash". A later one is +// named for what its id adds to the first's ("… (SG)"), or else its id. +func wbDistinctNames(ms []catalog.Model) []catalog.Model { + first := map[string]string{} // name → the id that has it + for i, m := range ms { + id, ok := first[m.Name] + if !ok { + first[m.Name] = m.ID + continue + } + tag := m.ID + if rest, ok := strings.CutPrefix(m.ID, id+"-"); ok && rest != "" { + tag = strings.ToUpper(rest) + } + ms[i].Name = m.Name + " (" + tag + ")" + } + return ms } diff --git a/internal/provider/workbuddy_names_test.go b/internal/provider/workbuddy_names_test.go new file mode 100644 index 000000000..9a8269656 --- /dev/null +++ b/internal/provider/workbuddy_names_test.go @@ -0,0 +1,24 @@ +package provider + +import ( + "testing" + + "github.com/yetone/magpie/internal/catalog" +) + +// Two models WorkBuddy names alike are told apart by what the second's id +// adds, or by its id. +func TestWorkBuddyDistinctNames(t *testing.T) { + ms := wbDistinctNames([]catalog.Model{ + {ID: "deepseek-v4.1-flash", Name: "Deepseek-V4.1-Flash"}, + {ID: "deepseek-v4.1-flash-sg", Name: "Deepseek-V4.1-Flash"}, + {ID: "glm-5.3", Name: "GLM-5.3"}, + {ID: "glm-x", Name: "GLM-5.3"}, + }) + want := []string{"Deepseek-V4.1-Flash", "Deepseek-V4.1-Flash (SG)", "GLM-5.3", "GLM-5.3 (glm-x)"} + for i, m := range ms { + if m.Name != want[i] { + t.Errorf("%s: %q, want %q", m.ID, m.Name, want[i]) + } + } +}