provider

package
v0.3.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package provider implements LLM provider interfaces and implementations

Index

Constants

This section is empty.

Variables

Registry holds all registered provider factories

Functions

func ContextToInternal

func ContextToInternal(ctx context.Context) context.Context

ContextToInternal converts context to provider-specific format

func CreateAllProviders

CreateAllProviders creates all configured providers

func CreateProvider

func CreateProvider(cfg llmproxy.ProviderConfig) (llmproxy.Provider, error)

CreateProvider creates a provider from its configuration

func MessagesToInternal

func MessagesToInternal(msgs []llmproxy.Message) []llmproxy.Message

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

func StreamDone(ch chan<- llmproxy.ChatChunk)

StreamDone sends a completion signal through a chunk channel

func StreamError

func StreamError(ch chan<- llmproxy.ChatChunk, err error)

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

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

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

func (b *BaseProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)

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

func (g *GLMProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)

CalculateCost calculates the cost for a given usage

func (*GLMProvider) Chat

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

func (g *GrokProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)

CalculateCost calculates the cost for a given usage

func (*GrokProvider) Chat

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

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

func (g *GroqProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)

CalculateCost calculates the cost for a given usage

func (*GroqProvider) Chat

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

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

func (o *OpenAIProvider) CalculateCost(model string, usage *llmproxy.Usage) (*llmproxy.Cost, error)

CalculateCost calculates the cost for a given usage

func (*OpenAIProvider) Chat

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL