types.go

 1package providers
 2
 3type ProviderType string
 4
 5const (
 6	ProviderTypeOpenAI     ProviderType = "openai"
 7	ProviderTypeAnthropic  ProviderType = "anthropic"
 8	ProviderTypeGemini     ProviderType = "gemini"
 9	ProviderTypeAzure      ProviderType = "azure"
10	ProviderTypeBedrock    ProviderType = "bedrock"
11	ProviderTypeVertexAI   ProviderType = "vertexai"
12	ProviderTypeXAI        ProviderType = "xai"
13	ProviderTypeOpenRouter ProviderType = "openrouter"
14)
15
16type InferenceProvider string
17
18const (
19	InferenceProviderOpenAI     InferenceProvider = "openai"
20	InferenceProviderAnthropic  InferenceProvider = "anthropic"
21	InferenceProviderGemini     InferenceProvider = "gemini"
22	InferenceProviderAzure      InferenceProvider = "azure"
23	InferenceProviderBedrock    InferenceProvider = "bedrock"
24	InferenceProviderVertexAI   InferenceProvider = "vertexai"
25	InferenceProviderXAI        InferenceProvider = "xai"
26	InferenceProviderOpenRouter InferenceProvider = "openrouter"
27)
28
29type Provider struct {
30	Name           string            `json:"name"`
31	ID             InferenceProvider `json:"id"`
32	APIKey         string            `json:"api_key,omitempty"`
33	APIEndpoint    string            `json:"api_endpoint,omitempty"`
34	Type           ProviderType      `json:"type,omitempty"`
35	DefaultModelID string            `json:"default_model_id,omitempty"`
36	Models         []Model           `json:"models,omitempty"`
37}
38
39type Model struct {
40	ID                 string  `json:"id"`
41	Name               string  `json:"model"`
42	CostPer1MIn        float64 `json:"cost_per_1m_in"`
43	CostPer1MOut       float64 `json:"cost_per_1m_out"`
44	CostPer1MInCached  float64 `json:"cost_per_1m_in_cached"`
45	CostPer1MOutCached float64 `json:"cost_per_1m_out_cached"`
46	ContextWindow      int64   `json:"context_window"`
47	DefaultMaxTokens   int64   `json:"default_max_tokens"`
48	CanReason          bool    `json:"can_reason"`
49	SupportsImages     bool    `json:"supports_attachments"`
50}
51
52type ProviderFunc func() Provider
53
54var providerRegistry = map[InferenceProvider]ProviderFunc{
55	InferenceProviderOpenAI:     openAIProvider,
56	InferenceProviderAnthropic:  anthropicProvider,
57	InferenceProviderGemini:     geminiProvider,
58	InferenceProviderAzure:      azureProvider,
59	InferenceProviderBedrock:    bedrockProvider,
60	InferenceProviderVertexAI:   vertexAIProvider,
61	InferenceProviderXAI:        xAIProvider,
62	InferenceProviderOpenRouter: openRouterProvider,
63}
64
65func GetAll() []Provider {
66	providers := make([]Provider, 0, len(providerRegistry))
67	for _, providerFunc := range providerRegistry {
68		providers = append(providers, providerFunc())
69	}
70	return providers
71}
72
73func GetByID(id InferenceProvider) (Provider, bool) {
74	providerFunc, exists := providerRegistry[id]
75	if !exists {
76		return Provider{}, false
77	}
78	return providerFunc(), true
79}
80
81func GetAvailableIDs() []InferenceProvider {
82	ids := make([]InferenceProvider, 0, len(providerRegistry))
83	for id := range providerRegistry {
84		ids = append(ids, id)
85	}
86	return ids
87}
88