From ee5f974f984d3e1ee488629faa25ced684cbff72 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 2 Oct 2026 10:31:23 +0800 Subject: [PATCH] =?UTF-8?q?providers:=20PipeLLM=20is=20a=20built-in=20pres?= =?UTF-8?q?et=20(the=20owner:=20=E4=BD=9C=E4=B8=BA=E5=86=85=E7=BD=AE=20pro?= =?UTF-8?q?vider=20=E5=8A=A0=E4=B8=8A=E5=90=A7)=20=E2=80=94=20one=20key=20?= =?UTF-8?q?for=20OpenAI's,=20Anthropic's=20and=20Gemini's=20models=20at=20?= =?UTF-8?q?api.pipellm.ai.=20Chat=20goes=20to=20its=20converter=20(/openai?= =?UTF-8?q?/v1),=20which=20takes=20every=20family,=20as=20its=20own=20Open?= =?UTF-8?q?Code=20and=20OpenClaw=20guides=20set=20it=20up;=20GPT=20goes=20?= =?UTF-8?q?to=20its=20own=20Responses=20API=20(/v1)=20and=20Claude=20to=20?= =?UTF-8?q?its=20own=20Messages=20API=20(the=20root),=20each=20of=20which?= =?UTF-8?q?=20serves=20its=20family=20alone.=20A=20model=20list's=20type?= =?UTF-8?q?=5Ftarget=20(openai,=20anthropic,=20gemini)=20now=20says=20whic?= =?UTF-8?q?h=20APIs=20a=20model=20is=20served=20on=20when=20the=20list=20n?= =?UTF-8?q?ames=20no=20endpoints:=20openai=20on=20Chat=20and=20Responses?= =?UTF-8?q?=20(Responses=20first=20for=20GPT,=20as=20on=20OpenAI's=20API),?= =?UTF-8?q?=20anthropic=20on=20Messages=20alone,=20gemini=20on=20Chat=20al?= =?UTF-8?q?one.=20Keys=20at=20console.pipellm.ai;=20its=20icon=20is=20the?= =?UTF-8?q?=20site's=20favicon;=20README=20lists=20it.=20Not=20sponsored.?= =?UTF-8?q?=20No=20PipeLLM=20key=20was=20at=20hand,=20so=20no=20real=20req?= =?UTF-8?q?uest=20was=20made;=20TestPipeLLMRoutesByTypeTarget=20(httptest?= =?UTF-8?q?=20list)=20fails=20without=20the=20change.=20go=20vet,=20go=20b?= =?UTF-8?q?uild=20-tags=20nogui=20(darwin,=20GOOS=3Dlinux),=20GOOS=3Dwindo?= =?UTF-8?q?ws=20go=20build,=20go=20test=20-tags=20nogui=20./...=20pass.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- internal/catalog/live.go | 23 +++++++ internal/gui/assets/icons/pipellm-color.svg | 5 ++ internal/provider/pipellm_test.go | 70 +++++++++++++++++++++ internal/provider/presets.go | 7 +++ internal/provider/provider.go | 4 +- 6 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 internal/gui/assets/icons/pipellm-color.svg create mode 100644 internal/provider/pipellm_test.go diff --git a/README.md b/README.md index b99a5c429..d80914160 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ and there is a terminal version (`magpie tui`) and a plain CLI. - **Providers with one field.** Pick a preset (Anthropic, OpenAI, Gemini, DeepSeek, Kimi, GLM, MiniMax, StepFun, Qwen, Baidu Qianfan, Tencent Cloud Token Plan, Huawei Cloud MaaS, Volcengine Ark, Mistral, Groq, xAI, OpenRouter, Together, - Fireworks, SiliconFlow, NVIDIA NIM, ModelScope, AiHubMix, 302.AI, Ollama, LM Studio…), + Fireworks, SiliconFlow, NVIDIA NIM, ModelScope, AiHubMix, PipeLLM, 302.AI, Ollama, LM Studio…), paste a key, done. Custom vendors need a name and a base URL. magpie never reads keys from your shell environment. - **Real model lists, nothing compiled in.** With a key in hand magpie asks diff --git a/internal/catalog/live.go b/internal/catalog/live.go index a9053e698..256b686d3 100644 --- a/internal/catalog/live.go +++ b/internal/catalog/live.go @@ -281,6 +281,9 @@ func fetchOne(ctx context.Context, url, key string, anthropic bool, headers map[ if native := EndpointAPIs(r.Native); len(native) > 0 { apis = native } + if len(apis) == 0 { + apis = targetAPIs(r.TypeTarget) + } m := Model{ID: id, Name: name, ImageInput: input, APIs: apis, Draws: drawer} if n, ok := r.ContextLength.(float64); ok && n > 0 { m.Context = int(n) @@ -350,6 +353,9 @@ type liveModel struct { // it, and "image" on one it draws with Label string `json:"magpie_label"` Kind string `json:"kind"` + // the protocol family PipeLLM routes the model by: openai, anthropic + // or gemini + TypeTarget string `json:"type_target"` } // levelsOf are the efforts of a list's supported_reasoning_levels, as @@ -391,6 +397,23 @@ func EndpointAPIs(endpoints []string) []string { return out } +// targetAPIs are the APIs a model is served on by its type_target, as +// PipeLLM's list says it: its own /v1/chat/completions and /v1/responses +// take the openai family alone, /v1/messages the anthropic one (asked +// there rather than through a converter), and its converter for Chat +// (/openai/v1) every family, Gemini's too. +func targetAPIs(target string) []string { + switch target { + case "openai": + return []string{"chat", "responses"} + case "anthropic": + return []string{"anthropic"} + case "gemini": + return []string{"chat"} + } + return nil +} + // Decorate fills in names and reasoning levels for live models from the // catalog's entry for the same id, keeping the live order. func Decorate(live []Model, known []Model) []Model { diff --git a/internal/gui/assets/icons/pipellm-color.svg b/internal/gui/assets/icons/pipellm-color.svg new file mode 100644 index 000000000..8c420c684 --- /dev/null +++ b/internal/gui/assets/icons/pipellm-color.svg @@ -0,0 +1,5 @@ +PipeLLM + + + + diff --git a/internal/provider/pipellm_test.go b/internal/provider/pipellm_test.go new file mode 100644 index 000000000..3079ece37 --- /dev/null +++ b/internal/provider/pipellm_test.go @@ -0,0 +1,70 @@ +package provider + +import ( + "context" + "net/http" + "net/http/httptest" + "path/filepath" + "testing" + + "github.com/yetone/magpie/internal/catalog" +) + +// PipeLLM's own Chat and Responses take OpenAI's family alone and its +// Messages Anthropic's; its Chat converter takes every family. Each model +// is asked where its list's type_target says it is served: GPT on +// Responses, Claude on Messages, Gemini (and any model the list doesn't +// place) on the converter. +func TestPipeLLMRoutesByTypeTarget(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + rw.Write([]byte(`{"object":"list","data":[ + {"id":"gpt-5","display_name":"Gpt 5","type_target":"openai"}, + {"id":"deepseek-v4","type_target":"openai"}, + {"id":"claude-sonnet-4-6","display_name":"Claude Sonnet 4.6","type_target":"anthropic"}, + {"id":"gemini-3-flash-preview","type_target":"gemini"}, + {"id":"new-model"}]}`)) + })) + defer srv.Close() + ms, _, err := catalog.FetchAt(context.Background(), srv.URL+"/v1", "k", false, nil) + if err != nil { + t.Fatal(err) + } + if err := catalog.SaveLive("pipellm", "", ms); err != nil { + t.Fatal(err) + } + p, err := FromPreset("pipellm") + if err != nil { + t.Fatal(err) + } + if p.Chat != "https://api.pipellm.ai/openai/v1" || p.Responses != "https://api.pipellm.ai/v1" || p.Anthropic != "https://api.pipellm.ai" { + t.Fatalf("endpoints %q %q %q", p.Chat, p.Responses, p.Anthropic) + } + for model, want := range map[string]Protocol{ + "gpt-5": Responses, + "deepseek-v4": Chat, + "claude-sonnet-4-6": Anthropic, + "gemini-3-flash-preview": Chat, + "new-model": Chat, + } { + if got := p.Native(model); got != want { + t.Errorf("%s: native %q, want %q", model, got, want) + } + } + for model, never := range map[string]Protocol{"gpt-5": Anthropic, "gemini-3-flash-preview": Responses, "claude-sonnet-4-6": Chat} { + for _, a := range p.APIs(model) { + if a == never { + t.Errorf("%s offered on %s", model, never) + } + } + } + for _, a := range p.APIs("gemini-3-flash-preview") { + if a != Chat { + t.Errorf("gemini on %s", a) + } + } +} diff --git a/internal/provider/presets.go b/internal/provider/presets.go index fb098ef12..37ea0a8df 100644 --- a/internal/provider/presets.go +++ b/internal/provider/presets.go @@ -327,6 +327,13 @@ var presets = []PresetDef{ {ID: "aihubmix", Name: "AiHubMix", Icon: "aihubmix-color", Kind: KindRelay, Chat: "https://aihubmix.com/v1", Anthropic: "https://aihubmix.com", Website: "https://aihubmix.com", KeysURL: "https://console.aihubmix.com/token"}, + // one key for every vendor's models: Chat on its converter, which + // takes any of them; GPT on its own Responses API and Claude on its + // own Messages API, each of which serves its family alone (the + // model list's type_target says which is which) + {ID: "pipellm", Name: "PipeLLM", Icon: "pipellm-color", Kind: KindRelay, + Chat: "https://api.pipellm.ai/openai/v1", Responses: "https://api.pipellm.ai/v1", Anthropic: "https://api.pipellm.ai", + Website: "https://www.pipellm.ai", KeysURL: "https://console.pipellm.ai"}, {ID: "302ai", Name: "302.AI", Icon: "ai302-color", Kind: KindRelay, Chat: "https://api.302.ai/v1", Anthropic: "https://api.302.ai", Website: "https://302.ai", KeysURL: "https://302.ai/api-keys/list"}, diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 5c01d7e2f..74f3a9d0d 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -799,7 +799,7 @@ func (p Provider) Speaks() []Protocol { return out } -// ResponsesFirst: an OpenAI model on OpenAI's API, Copilot's or Bedrock's, +// ResponsesFirst: an OpenAI model on OpenAI's API, Copilot's, PipeLLM's or Bedrock's, // which is best asked on the Responses API though Chat serves it too. func (p Provider) ResponsesFirst(model string) bool { if p.Responses != "" && p.IsBedrock() { @@ -807,7 +807,7 @@ func (p Provider) ResponsesFirst(model string) bool { } // Azure OpenAI's deployments are named as the user likes; one named // for its model (gpt-5-codex, o4-mini) is taken for it - if p.Responses == "" || (p.ID != "copilot" && HostOf(p.Responses) != "api.openai.com" && !p.IsAzure()) { + if p.Responses == "" || (p.ID != "copilot" && HostOf(p.Responses) != "api.openai.com" && HostOf(p.Responses) != "api.pipellm.ai" && !p.IsAzure()) { return false } m := strings.ToLower(model[strings.LastIndex(model, "/")+1:])