provider.go

  1package catwalk
  2
  3// Type represents the type of AI provider.
  4type Type string
  5
  6// All the supported AI provider types.
  7const (
  8	TypeOpenAI       Type = "openai"
  9	TypeOpenAICompat Type = "openai-compat"
 10	TypeOpenRouter   Type = "openrouter"
 11	TypeAnthropic    Type = "anthropic"
 12	TypeGoogle       Type = "google"
 13	TypeAzure        Type = "azure"
 14	TypeBedrock      Type = "bedrock"
 15	TypeVertexAI     Type = "google-vertex"
 16)
 17
 18// InferenceProvider represents the inference provider identifier.
 19type InferenceProvider string
 20
 21// All the inference providers supported by the system.
 22const (
 23	InferenceProviderOpenAI      InferenceProvider = "openai"
 24	InferenceProviderAnthropic   InferenceProvider = "anthropic"
 25	InferenceProviderSynthetic   InferenceProvider = "synthetic"
 26	InferenceProviderGemini      InferenceProvider = "gemini"
 27	InferenceProviderAzure       InferenceProvider = "azure"
 28	InferenceProviderBedrock     InferenceProvider = "bedrock"
 29	InferenceProviderVertexAI    InferenceProvider = "vertexai"
 30	InferenceProviderXAI         InferenceProvider = "xai"
 31	InferenceProviderZAI         InferenceProvider = "zai"
 32	InferenceProviderGROQ        InferenceProvider = "groq"
 33	InferenceProviderOpenRouter  InferenceProvider = "openrouter"
 34	InferenceProviderCerebras    InferenceProvider = "cerebras"
 35	InferenceProviderVenice      InferenceProvider = "venice"
 36	InferenceProviderChutes      InferenceProvider = "chutes"
 37	InferenceProviderHuggingFace InferenceProvider = "huggingface"
 38	InferenceAIHubMix            InferenceProvider = "aihubmix"
 39	InferenceKimiCoding          InferenceProvider = "kimi-coding"
 40)
 41
 42// Provider represents an AI provider configuration.
 43type Provider struct {
 44	Name                string            `json:"name"`
 45	ID                  InferenceProvider `json:"id"`
 46	APIKey              string            `json:"api_key,omitempty"`
 47	APIEndpoint         string            `json:"api_endpoint,omitempty"`
 48	Type                Type              `json:"type,omitempty"`
 49	DefaultLargeModelID string            `json:"default_large_model_id,omitempty"`
 50	DefaultSmallModelID string            `json:"default_small_model_id,omitempty"`
 51	Models              []Model           `json:"models,omitempty"`
 52	DefaultHeaders      map[string]string `json:"default_headers,omitempty"`
 53}
 54
 55// ModelOptions stores extra options for models.
 56type ModelOptions struct {
 57	Temperature      *float64       `json:"temperature,omitempty"`
 58	TopP             *float64       `json:"top_p,omitempty"`
 59	TopK             *int64         `json:"top_k,omitempty"`
 60	FrequencyPenalty *float64       `json:"frequency_penalty,omitempty"`
 61	PresencePenalty  *float64       `json:"presence_penalty,omitempty"`
 62	ProviderOptions  map[string]any `json:"provider_options,omitempty"`
 63}
 64
 65// Model represents an AI model configuration.
 66type Model struct {
 67	ID                     string       `json:"id"`
 68	Name                   string       `json:"name"`
 69	CostPer1MIn            float64      `json:"cost_per_1m_in"`
 70	CostPer1MOut           float64      `json:"cost_per_1m_out"`
 71	CostPer1MInCached      float64      `json:"cost_per_1m_in_cached"`
 72	CostPer1MOutCached     float64      `json:"cost_per_1m_out_cached"`
 73	ContextWindow          int64        `json:"context_window"`
 74	DefaultMaxTokens       int64        `json:"default_max_tokens"`
 75	CanReason              bool         `json:"can_reason"`
 76	ReasoningLevels        []string     `json:"reasoning_levels,omitempty"`
 77	DefaultReasoningEffort string       `json:"default_reasoning_effort,omitempty"`
 78	SupportsImages         bool         `json:"supports_attachments"`
 79	Options                ModelOptions `json:"options"`
 80}
 81
 82// KnownProviders returns all the known inference providers.
 83func KnownProviders() []InferenceProvider {
 84	return []InferenceProvider{
 85		InferenceProviderOpenAI,
 86		InferenceProviderSynthetic,
 87		InferenceProviderAnthropic,
 88		InferenceProviderGemini,
 89		InferenceProviderAzure,
 90		InferenceProviderBedrock,
 91		InferenceProviderVertexAI,
 92		InferenceProviderXAI,
 93		InferenceProviderZAI,
 94		InferenceProviderGROQ,
 95		InferenceProviderOpenRouter,
 96		InferenceProviderCerebras,
 97		InferenceProviderVenice,
 98		InferenceProviderChutes,
 99		InferenceProviderHuggingFace,
100		InferenceAIHubMix,
101		InferenceKimiCoding,
102	}
103}
104
105// KnownProviderTypes returns all the known inference providers types.
106func KnownProviderTypes() []Type {
107	return []Type{
108		TypeOpenAI,
109		TypeOpenAICompat,
110		TypeOpenRouter,
111		TypeAnthropic,
112		TypeGoogle,
113		TypeAzure,
114		TypeBedrock,
115		TypeVertexAI,
116	}
117}