Documentation
¶
Overview ¶
Package provider implements LLM provider interfaces and implementations
Index ¶
- Variables
- func ContextToInternal(ctx context.Context) context.Context
- func CreateAllProviders(configs map[llmproxy.ProviderType]llmproxy.ProviderConfig) (map[llmproxy.ProviderType]llmproxy.Provider, error)
- func CreateProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
- func MessagesToInternal(msgs []llmproxy.Message) []llmproxy.Message
- func NewAnthropicProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
- func NewGLMProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
- func NewGrokProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
- func NewGroqProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
- func NewOpenAIProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
- func StreamDone(ch chan<- llmproxy.ChatChunk)
- func StreamError(ch chan<- llmproxy.ChatChunk, err error)
- type AnthropicProvider
- func (a *AnthropicProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)
- func (a *AnthropicProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
- func (a *AnthropicProvider) GetModels() []llmproxy.Model
- func (a *AnthropicProvider) Name() llmproxy.ProviderType
- func (a *AnthropicProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
- func (a *AnthropicProvider) Validate() error
- type BaseProvider
- type Factory
- type GLMProvider
- func (g *GLMProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)
- func (g *GLMProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
- func (g *GLMProvider) GetModels() []llmproxy.Model
- func (g *GLMProvider) Name() llmproxy.ProviderType
- func (g *GLMProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
- func (g *GLMProvider) Validate() error
- type GrokProvider
- func (g *GrokProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)
- func (g *GrokProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
- func (g *GrokProvider) GetModels() []llmproxy.Model
- func (g *GrokProvider) Name() llmproxy.ProviderType
- func (g *GrokProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
- func (g *GrokProvider) Validate() error
- type GroqProvider
- func (g *GroqProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)
- func (g *GroqProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
- func (g *GroqProvider) GetModels() []llmproxy.Model
- func (g *GroqProvider) Name() llmproxy.ProviderType
- func (g *GroqProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
- func (g *GroqProvider) Validate() error
- type OpenAIProvider
- func (o *OpenAIProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)
- func (o *OpenAIProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
- func (o *OpenAIProvider) GetModels() []llmproxy.Model
- func (o *OpenAIProvider) Name() llmproxy.ProviderType
- func (o *OpenAIProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
- func (o *OpenAIProvider) Validate() error
Constants ¶
This section is empty.
Variables ¶
var Registry = map[llmproxy.ProviderType]Factory{ llmproxy.ProviderAnthropic: NewAnthropicProvider, llmproxy.ProviderOpenAI: NewOpenAIProvider, llmproxy.ProviderGLM: NewGLMProvider, llmproxy.ProviderGroq: NewGroqProvider, llmproxy.ProviderGrok: NewGrokProvider, }
Registry holds all registered provider factories
Functions ¶
func ContextToInternal ¶
ContextToInternal converts context to provider-specific format
func CreateAllProviders ¶
func CreateAllProviders(configs map[llmproxy.ProviderType]llmproxy.ProviderConfig) (map[llmproxy.ProviderType]llmproxy.Provider, error)
CreateAllProviders creates all configured providers
func CreateProvider ¶
func CreateProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
CreateProvider creates a provider from its configuration
func MessagesToInternal ¶
MessagesToInternal converts between message formats if needed
func NewAnthropicProvider ¶
func NewAnthropicProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
NewAnthropicProvider creates a new Anthropic provider
func NewGLMProvider ¶
func NewGLMProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
NewGLMProvider creates a new GLM provider
func NewGrokProvider ¶
func NewGrokProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
NewGrokProvider creates a new Grok provider
func NewGroqProvider ¶
func NewGroqProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
NewGroqProvider creates a new Groq provider
func NewOpenAIProvider ¶
func NewOpenAIProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
NewOpenAIProvider creates a new OpenAI provider
func StreamDone ¶
StreamDone sends a completion signal through a chunk channel
func StreamError ¶
StreamError sends an error through a chunk channel
Types ¶
type AnthropicProvider ¶
type AnthropicProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
AnthropicProvider implements the Anthropic (Claude) provider
func (*AnthropicProvider) CalculateCost ¶
func (a *AnthropicProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)
CalculateCost calculates the cost for a given usage
func (*AnthropicProvider) Chat ¶
func (a *AnthropicProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
Chat generates a non-streaming chat completion
func (*AnthropicProvider) GetModels ¶
func (a *AnthropicProvider) GetModels() []llmproxy.Model
GetModels returns the list of available models
func (*AnthropicProvider) Name ¶
func (a *AnthropicProvider) Name() llmproxy.ProviderType
Name returns the provider name
func (*AnthropicProvider) StreamChat ¶
func (a *AnthropicProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
StreamChat generates a streaming chat completion
func (*AnthropicProvider) Validate ¶
func (a *AnthropicProvider) Validate() error
Validate checks if the provider configuration is valid
type BaseProvider ¶
type BaseProvider struct {
Config llmproxy.ProviderConfig
ModelInfo map[string]llmproxy.Model
}
BaseProvider provides common functionality for all providers
func (*BaseProvider) ApplyModelAlias ¶
func (b *BaseProvider) ApplyModelAlias(model string) string
ApplyModelAlias applies model alias configuration
func (*BaseProvider) CalculateCost ¶
CalculateCost calculates the cost based on token usage
func (*BaseProvider) GetModels ¶
func (b *BaseProvider) GetModels() []llmproxy.Model
GetModels returns the list of available models
func (*BaseProvider) Validate ¶
func (b *BaseProvider) Validate() error
Validate checks if the provider configuration is valid
type Factory ¶
type Factory func(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)
Factory creates a provider from its configuration
type GLMProvider ¶
type GLMProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
GLMProvider implements the GLM (ZhipuAI) provider
func (*GLMProvider) CalculateCost ¶
CalculateCost calculates the cost for a given usage
func (*GLMProvider) Chat ¶
func (g *GLMProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
Chat generates a non-streaming chat completion
func (*GLMProvider) GetModels ¶
func (g *GLMProvider) GetModels() []llmproxy.Model
GetModels returns the list of available models
func (*GLMProvider) Name ¶
func (g *GLMProvider) Name() llmproxy.ProviderType
Name returns the provider name
func (*GLMProvider) StreamChat ¶
func (g *GLMProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
StreamChat generates a streaming chat completion
func (*GLMProvider) Validate ¶
func (g *GLMProvider) Validate() error
Validate checks if the provider configuration is valid
type GrokProvider ¶
type GrokProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
GrokProvider implements the Grok (xAI) provider
func (*GrokProvider) CalculateCost ¶
CalculateCost calculates the cost for a given usage
func (*GrokProvider) Chat ¶
func (g *GrokProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
Chat generates a non-streaming chat completion
func (*GrokProvider) GetModels ¶
func (g *GrokProvider) GetModels() []llmproxy.Model
GetModels returns the list of available models
func (*GrokProvider) Name ¶
func (g *GrokProvider) Name() llmproxy.ProviderType
Name returns the provider name
func (*GrokProvider) StreamChat ¶
func (g *GrokProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
StreamChat generates a streaming chat completion
func (*GrokProvider) Validate ¶
func (g *GrokProvider) Validate() error
Validate checks if the provider configuration is valid
type GroqProvider ¶
type GroqProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
GroqProvider implements the Groq provider
func (*GroqProvider) CalculateCost ¶
CalculateCost calculates the cost for a given usage
func (*GroqProvider) Chat ¶
func (g *GroqProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
Chat generates a non-streaming chat completion
func (*GroqProvider) GetModels ¶
func (g *GroqProvider) GetModels() []llmproxy.Model
GetModels returns the list of available models
func (*GroqProvider) Name ¶
func (g *GroqProvider) Name() llmproxy.ProviderType
Name returns the provider name
func (*GroqProvider) StreamChat ¶
func (g *GroqProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
StreamChat generates a streaming chat completion
func (*GroqProvider) Validate ¶
func (g *GroqProvider) Validate() error
Validate checks if the provider configuration is valid
type OpenAIProvider ¶
type OpenAIProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
OpenAIProvider implements the OpenAI provider
func (*OpenAIProvider) CalculateCost ¶
CalculateCost calculates the cost for a given usage
func (*OpenAIProvider) Chat ¶
func (o *OpenAIProvider) Chat(ctx context.Context, req *llmproxy.ChatRequest) (*llmproxy.ChatResponse, error)
Chat generates a non-streaming chat completion
func (*OpenAIProvider) GetModels ¶
func (o *OpenAIProvider) GetModels() []llmproxy.Model
GetModels returns the list of available models
func (*OpenAIProvider) Name ¶
func (o *OpenAIProvider) Name() llmproxy.ProviderType
Name returns the provider name
func (*OpenAIProvider) StreamChat ¶
func (o *OpenAIProvider) StreamChat(ctx context.Context, req *llmproxy.ChatRequest) (<-chan llmproxy.ChatChunk, error)
StreamChat generates a streaming chat completion
func (*OpenAIProvider) Validate ¶
func (o *OpenAIProvider) Validate() error
Validate checks if the provider configuration is valid