providers: PipeLLM is a built-in preset (the owner: 作为内置 provider 加上吧) — one key for OpenAI's, Anthropic's and Gemini's models at api.pipellm.ai. Chat goes to its converter (/openai/v1), which takes every family, as its own OpenCode and OpenClaw guides set it up; GPT goes to its own Responses API (/v1) and Claude to its own Messages API (the root), each of which serves its family alone. A model list's type_target (openai, anthropic, gemini) now says which APIs a model is served on when the list names no endpoints: openai on Chat and Responses (Responses first for GPT, as on OpenAI's API), anthropic on Messages alone, gemini on Chat alone. Keys at console.pipellm.ai; its icon is the site's favicon; README lists it. Not sponsored. No PipeLLM key was at hand, so no real request was made; TestPipeLLMRoutesByTypeTarget (httptest list) fails without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass.

This commit is contained in:
yetone
2026-10-02 10:31:23 +08:00
parent f3ba918491
commit ee5f974f98
6 changed files with 108 additions and 3 deletions
+1 -1
View File
@@ -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
+23
View File
@@ -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 {
@@ -0,0 +1,5 @@
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" fill="none" xmlns="http://www.w3.org/2000/svg"><title>PipeLLM</title>
<path d="M24 23C24 23.5523 23.5523 24 23 24H1C0.447716 24 0 23.5523 0 23V1C0 0.447716 0.447715 0 1 0H19.5515C19.7106 0 19.8632 0.0632141 19.9757 0.175736L23.8243 4.02426C23.9368 4.13679 24 4.2894 24 4.44853V23Z" fill="#13171B"/>
<path d="M4.23987 19.744L19.7439 4.24001" stroke="white" stroke-width="3"/>
<path opacity="0.1" d="M5.59987 21.2C5.59987 21.2 5.19993 18 6.39993 16.4C7.59993 14.8 8.72372 16.0762 10.7999 14C11.773 13.027 11.8159 10.984 13.1999 9.6C14.4661 8.33379 15.5013 9.04578 16.7999 8C18.5317 6.60544 18 3.2 18 3.2" stroke="black" stroke-width="0.4"/>
</svg>

After

Width:  |  Height:  |  Size: 728 B

+70
View File
@@ -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)
}
}
}
+7
View File
@@ -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"},
+2 -2
View File
@@ -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:])