Archie627 said magpie has no Vercel AI Gateway. It is now a preset in Add: Chat Completions and Responses at https://ai-gateway.vercel.sh/v1, Anthropic Messages at https://ai-gateway.vercel.sh (Vercel takes the key as Bearer there too), models.dev's "vercel" catalog, the vercel icon the vercel-jev decision preset already used, and its API keys page. An OpenCode or URL import at that host becomes the preset. READMEs and the site's import pages (en, zh, ja) list it. Its /v1/models (public, 505 rows today) marks each row's "type". Read as before, the decision models (liquid/d1, typesafe-ai/jev) and realtime voices showed as chat models, ElevenLabs voices were dropped, and transcribers (elevenlabs/scribe-v2) showed as chat. At Vercel's host alone (catalog.VercelGateway) the type now decides: evaluation and realtime rows are left out, speech, transcription, embedding and reranking rows get their Serves, image rows draw and video rows film. The 48 "-batch" ids are left out: Vercel's docs say "Synchronous requests don't accept -batch IDs". context_window gives the window. Another host's "type" is read as before. Run: TestVercelPreset and TestVercelLiveList (real rows from Vercel's list in testdata, served through an httptest server, no network); go test ./internal/catalog ./internal/provider on Linux (wsl-run) and macOS (mote, -run Vercel|Preset|Import before mote stopped taking SSH); gofmt; go vet linux, windows, darwin (CGO off). Broken by hand: VercelGateway returning false turns TestVercelLiveList red (decision, realtime, batch and transcriber rows back in chat); the -batch skip alone turned off turns it red too. Not tried: no Vercel key, so no real chat, Responses or Messages call; only the public GET /v1/models. No GUI file reads the preset list by name (the Add sheet is built from /api/presets), so no GUI run.
110 lines
3.5 KiB
Go
110 lines
3.5 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// Vercel AI Gateway is a preset (Archie627 on X): Chat Completions and
|
|
// Responses at /v1, Anthropic's Messages at the root, models.dev's
|
|
// "vercel" catalog, and an entry imported at its base URL is the preset.
|
|
func TestVercelPreset(t *testing.T) {
|
|
p, err := FromPreset("vercel")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if p.Name != "Vercel AI Gateway" || p.Icon != "vercel" || p.Catalog != "vercel" || p.KeysURL == "" {
|
|
t.Fatalf("%+v", p)
|
|
}
|
|
if p.Chat != "https://ai-gateway.vercel.sh/v1" || p.Responses != "https://ai-gateway.vercel.sh/v1" || p.Anthropic != "https://ai-gateway.vercel.sh" {
|
|
t.Fatalf("endpoints: %q %q %q", p.Chat, p.Responses, p.Anthropic)
|
|
}
|
|
if pr := Preset("vercel"); pr.Kind != KindRelay || pr.NoKey {
|
|
t.Fatalf("%+v", pr)
|
|
}
|
|
im, _ := imported("x", "k", endpoints{chat: "https://ai-gateway.vercel.sh/v1/"}, nil)
|
|
if im.Preset != "vercel" || im.Icon != "vercel" {
|
|
t.Fatalf("imported: %+v", im)
|
|
}
|
|
// the decision preset at /typesafe stays its own
|
|
if Preset("vercel-jev").ID != "vercel-jev" {
|
|
t.Fatal("vercel-jev gone")
|
|
}
|
|
}
|
|
|
|
// Vercel's /v1/models, real rows of it (testdata/vercel-models.json):
|
|
// each row's "type" says what it is. Its decision and realtime models and
|
|
// its batch-only ids answer no chat; its voices, transcribers, embedders,
|
|
// rerankers, image and video models go where they serve. Only at Vercel's
|
|
// host: the same rows elsewhere are read as before.
|
|
func TestVercelLiveList(t *testing.T) {
|
|
body, err := os.ReadFile("testdata/vercel-models.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/v1/models" || r.Header.Get("Authorization") != "Bearer k" {
|
|
rw.WriteHeader(http.StatusUnauthorized)
|
|
return
|
|
}
|
|
rw.Write(body)
|
|
}))
|
|
defer srv.Close()
|
|
old := http.DefaultClient.Transport
|
|
t.Cleanup(func() { http.DefaultClient.Transport = old })
|
|
http.DefaultClient.Transport = rewrite{srv}
|
|
|
|
ms, _, err := catalog.FetchAt(context.Background(), "https://ai-gateway.vercel.sh/v1", "k", false, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
by := map[string]catalog.Model{}
|
|
for _, m := range ms {
|
|
by[m.ID] = m
|
|
}
|
|
chat := catalog.Chat(ms)
|
|
if len(chat) != 1 || chat[0].ID != "anthropic/claude-sonnet-4.6" || chat[0].Context != 1000000 {
|
|
t.Fatalf("chat: %+v", chat)
|
|
}
|
|
for _, id := range []string{"anthropic/claude-sonnet-4.6-batch", "liquid/d1", "spacexai/grok-voice-3.0"} {
|
|
if _, ok := by[id]; ok {
|
|
t.Fatalf("%s kept: %+v", id, by[id])
|
|
}
|
|
}
|
|
for id, serves := range map[string]string{
|
|
"elevenlabs/eleven-v3": catalog.ServesSpeech,
|
|
"elevenlabs/scribe-v2": catalog.ServesTranscription,
|
|
"openai/text-embedding-3-small": catalog.ServesEmbedding,
|
|
"cohere/rerank-v3.5": catalog.ServesRerank,
|
|
} {
|
|
if m, ok := by[id]; !ok || m.Serves != serves {
|
|
t.Fatalf("%s: %+v (want %s)", id, m, serves)
|
|
}
|
|
}
|
|
if m := by["bfl/flux-2-flex"]; !m.Draws || m.Films {
|
|
t.Fatalf("image: %+v", m)
|
|
}
|
|
if m := by["alibaba/wan-v2.6-i2v"]; !m.Films || m.Draws {
|
|
t.Fatalf("video: %+v", m)
|
|
}
|
|
|
|
// another host's "type" is not Vercel's: the decision model stays
|
|
http.DefaultClient.Transport = old
|
|
ms, _, err = catalog.FetchAt(context.Background(), srv.URL+"/v1", "k", false, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
kept := false
|
|
for _, m := range catalog.Chat(ms) {
|
|
kept = kept || m.ID == "liquid/d1"
|
|
}
|
|
if !kept {
|
|
t.Fatalf("elsewhere: %+v", ms)
|
|
}
|
|
}
|