Documentation
¶
Overview ¶
Package providers implements LLM client providers for various APIs.
Index ¶
- func NewClient(provider string, cfg llm.ClientConfig) (llm.Client, error)
- func NewEmbedder(provider string, cfg OpenAIEmbedderConfig) (llm.Embedder, error)
- type AnthropicClient
- type OAuthClient
- type OllamaClient
- type OllamaEmbedder
- type OpenAIClient
- type OpenAIEmbedder
- type OpenAIEmbedderConfig
- type ResponsesClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
NewClient creates an LLM client for the specified provider. Supported providers: "openai", "anthropic", "ollama".
func NewEmbedder ¶
func NewEmbedder(provider string, cfg OpenAIEmbedderConfig) (llm.Embedder, error)
NewEmbedder creates an Embedder for the specified provider. Supported providers: "openai", "gemini", "ollama". Returns an error for "anthropic" (no embedding API).
Types ¶
type AnthropicClient ¶
type AnthropicClient struct {
// contains filtered or unexported fields
}
AnthropicClient implements llm.Client for the Anthropic Messages API.
func NewAnthropicClient ¶
func NewAnthropicClient(cfg llm.ClientConfig) *AnthropicClient
NewAnthropicClient creates a new Anthropic client.
func (*AnthropicClient) Chat ¶
func (c *AnthropicClient) Chat(ctx context.Context, req *llm.ChatRequest) (*llm.ChatResponse, error)
Chat sends a non-streaming messages request.
func (*AnthropicClient) ChatStream ¶
func (c *AnthropicClient) ChatStream(ctx context.Context, req *llm.ChatRequest) (<-chan llm.StreamDelta, error)
ChatStream sends a streaming messages request.
func (*AnthropicClient) ModelID ¶
func (c *AnthropicClient) ModelID() string
type OAuthClient ¶
type OAuthClient struct {
// contains filtered or unexported fields
}
OAuthClient wraps a ResponsesClient with automatic OAuth token refresh. It implements llm.Client and transparently refreshes expired tokens before each API call. ChatGPT OAuth tokens are scoped to the Responses API, not the Chat Completions API, so this client uses the Responses API format.
func NewOAuthClient ¶
func NewOAuthClient(cfg llm.ClientConfig, provider string, oauthConfig oauth.ProviderConfig) *OAuthClient
NewOAuthClient creates a new OAuth-aware client that uses the Responses API. The token is loaded from stored credentials and refreshed automatically.
func (*OAuthClient) Chat ¶
func (c *OAuthClient) Chat(ctx context.Context, req *llm.ChatRequest) (*llm.ChatResponse, error)
Chat sends a Responses API request, refreshing the token if needed.
func (*OAuthClient) ChatStream ¶
func (c *OAuthClient) ChatStream(ctx context.Context, req *llm.ChatRequest) (<-chan llm.StreamDelta, error)
ChatStream sends a streaming Responses API request, refreshing the token if needed.
func (*OAuthClient) ModelID ¶
func (c *OAuthClient) ModelID() string
ModelID returns the model identifier.
type OllamaClient ¶
type OllamaClient struct {
*OpenAIClient
}
OllamaClient wraps OpenAIClient with Ollama-specific defaults. Ollama provides an OpenAI-compatible API at localhost:11434/v1.
func NewOllamaClient ¶
func NewOllamaClient(cfg llm.ClientConfig) *OllamaClient
NewOllamaClient creates a client that talks to a local Ollama server.
type OllamaEmbedder ¶
type OllamaEmbedder struct {
*OpenAIEmbedder
}
OllamaEmbedder wraps OpenAIEmbedder with Ollama-specific defaults. Ollama provides an OpenAI-compatible /v1/embeddings endpoint.
func NewOllamaEmbedder ¶
func NewOllamaEmbedder(cfg OpenAIEmbedderConfig) *OllamaEmbedder
NewOllamaEmbedder creates an embedder that talks to a local Ollama server.
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
OpenAIClient implements llm.Client for the OpenAI Chat Completions API. Also works with Azure OpenAI and any OpenAI-compatible endpoint.
func NewOpenAIClient ¶
func NewOpenAIClient(cfg llm.ClientConfig) *OpenAIClient
NewOpenAIClient creates a new OpenAI client.
func (*OpenAIClient) Chat ¶
func (c *OpenAIClient) Chat(ctx context.Context, req *llm.ChatRequest) (*llm.ChatResponse, error)
Chat sends a non-streaming chat completion request.
func (*OpenAIClient) ChatStream ¶
func (c *OpenAIClient) ChatStream(ctx context.Context, req *llm.ChatRequest) (<-chan llm.StreamDelta, error)
ChatStream sends a streaming chat completion request.
func (*OpenAIClient) ModelID ¶
func (c *OpenAIClient) ModelID() string
type OpenAIEmbedder ¶
type OpenAIEmbedder struct {
// contains filtered or unexported fields
}
OpenAIEmbedder implements llm.Embedder using the OpenAI Embeddings API.
func NewOpenAIEmbedder ¶
func NewOpenAIEmbedder(cfg OpenAIEmbedderConfig) *OpenAIEmbedder
NewOpenAIEmbedder creates an OpenAI embedder.
func (*OpenAIEmbedder) Dimensions ¶
func (e *OpenAIEmbedder) Dimensions() int
func (*OpenAIEmbedder) Embed ¶
func (e *OpenAIEmbedder) Embed(ctx context.Context, req *llm.EmbeddingRequest) (*llm.EmbeddingResponse, error)
Embed produces embeddings for the given texts using POST /v1/embeddings.
type OpenAIEmbedderConfig ¶
type OpenAIEmbedderConfig struct {
APIKey string
OrgID string
BaseURL string
Model string
Dims int
}
OpenAIEmbedderConfig configures the OpenAI embedder.
type ResponsesClient ¶
type ResponsesClient struct {
// contains filtered or unexported fields
}
ResponsesClient implements llm.Client using the OpenAI Responses API. This is used with ChatGPT OAuth tokens which are scoped to the Responses API endpoint (chatgpt.com/backend-api) rather than the Chat Completions API.
func NewResponsesClient ¶
func NewResponsesClient(cfg llm.ClientConfig) *ResponsesClient
NewResponsesClient creates a new Responses API client.
func (*ResponsesClient) Chat ¶
func (c *ResponsesClient) Chat(ctx context.Context, req *llm.ChatRequest) (*llm.ChatResponse, error)
Chat sends a Responses API request. The ChatGPT Codex backend requires streaming, so this method always uses stream=true internally and collects the full response from the streamed deltas.
func (*ResponsesClient) ChatStream ¶
func (c *ResponsesClient) ChatStream(ctx context.Context, req *llm.ChatRequest) (<-chan llm.StreamDelta, error)
ChatStream sends a streaming Responses API request.
func (*ResponsesClient) ModelID ¶
func (c *ResponsesClient) ModelID() string