mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-13 19:20:06 +00:00
10abb29e4f
- replace npmToLLMProvider map with npmToWireProtocol (openai/anthropic/google) - add createAutoRoutedGoogleProvider so @ai-sdk/google proxies work (fixes opencode/gemini-* failing with "no LLM provider mapping") - strip the genai-injected v1beta segment for proxies whose base URL already carries a version (e.g. opencode's /zen/v1) - preserve openai-compat fallback and clearer error for unroutable providers - document auto-routing in README and providers docs; update CreateProvider godoc - add regression tests for wire routing and version-path rewriting Fixes #41
76 lines
2.8 KiB
Go
76 lines
2.8 KiB
Go
package models
|
|
|
|
// ModelsDBProviders is the top-level type for models.dev/api.json data:
|
|
// a map of provider ID → provider object.
|
|
type ModelsDBProviders = map[string]modelsDBProvider
|
|
|
|
// modelsDBProvider represents a provider entry from models.dev/api.json.
|
|
type modelsDBProvider struct {
|
|
ID string `json:"id"`
|
|
Env []string `json:"env"`
|
|
NPM string `json:"npm"`
|
|
API string `json:"api,omitempty"`
|
|
Name string `json:"name"`
|
|
Doc string `json:"doc,omitempty"`
|
|
Models map[string]modelsDBModel `json:"models"`
|
|
}
|
|
|
|
// modelsDBModel represents a model entry from models.dev/api.json.
|
|
type modelsDBModel struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Family string `json:"family,omitempty"`
|
|
Attachment bool `json:"attachment"`
|
|
Reasoning bool `json:"reasoning"`
|
|
ToolCall bool `json:"tool_call"`
|
|
Temperature bool `json:"temperature"`
|
|
Cost modelsDBCost `json:"cost"`
|
|
Limit modelsDBLimit `json:"limit"`
|
|
Provider *modelsDBModelProvider `json:"provider,omitempty"` // Model-specific provider override
|
|
}
|
|
|
|
// modelsDBModelProvider represents a provider reference within a model.
|
|
type modelsDBModelProvider struct {
|
|
NPM string `json:"npm"`
|
|
}
|
|
|
|
// modelsDBCost represents model pricing from models.dev.
|
|
type modelsDBCost struct {
|
|
Input float64 `json:"input"`
|
|
Output float64 `json:"output"`
|
|
CacheRead *float64 `json:"cache_read,omitempty"`
|
|
CacheWrite *float64 `json:"cache_write,omitempty"`
|
|
}
|
|
|
|
// modelsDBLimit represents model context/output limits from models.dev.
|
|
type modelsDBLimit struct {
|
|
Context int `json:"context"`
|
|
Output int `json:"output"`
|
|
}
|
|
|
|
// wireProtocol identifies which LLM API protocol an npm package speaks.
|
|
// Fantasy implements three native protocols (openai, anthropic, google);
|
|
// everything else in its providers/ tree is a thin wrapper around one of
|
|
// them with a pre-baked default URL or auth scheme.
|
|
type wireProtocol int
|
|
|
|
const (
|
|
wireUnknown wireProtocol = iota
|
|
wireOpenAI
|
|
wireAnthropic
|
|
wireGoogle
|
|
)
|
|
|
|
// npmToWireProtocol maps npm package names from models.dev to the wire
|
|
// protocol they speak. Provider-specific bundles (azure, bedrock, vercel,
|
|
// openrouter, google-vertex, google-vertex-anthropic) are intentionally
|
|
// absent — they have native top-level cases in CreateProvider and never
|
|
// reach the auto-router. Providers not in this map but with an api URL
|
|
// are auto-routed through the OpenAI-compatible wire.
|
|
var npmToWireProtocol = map[string]wireProtocol{
|
|
"@ai-sdk/openai": wireOpenAI,
|
|
"@ai-sdk/openai-compatible": wireOpenAI,
|
|
"@ai-sdk/anthropic": wireAnthropic,
|
|
"@ai-sdk/google": wireGoogle,
|
|
}
|