Documentation
¶
Overview ¶
Package llm provides LLM provider abstractions for DraftCrew.
Supported providers: OpenAI, Anthropic, Google Gemini, and any OpenAI-compatible endpoint. Each provider implements the Client interface defined in this package.
Index ¶
- type AnthropicProvider
- type Client
- type CompatibleProvider
- func NewAzureOpenAI(endpoint, apiKey, deploymentName string, opts ...GenerateOption) *CompatibleProvider
- func NewDeepSeek(apiKey, model string, opts ...GenerateOption) *CompatibleProvider
- func NewMistral(apiKey, model string, opts ...GenerateOption) *CompatibleProvider
- func NewOllama(model string, opts ...GenerateOption) *CompatibleProvider
- func NewOpenAICompatible(baseURL, apiKey, model string, opts ...GenerateOption) *CompatibleProvider
- func NewOpenRouter(apiKey, model string, opts ...GenerateOption) *CompatibleProvider
- type GeminiProvider
- type GenerateOption
- type GenerateOptions
- type Message
- type OpenAIProvider
- type Response
- type Role
- type StreamChunk
- type ToolCall
- type ToolDef
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnthropicProvider ¶
type AnthropicProvider struct {
// contains filtered or unexported fields
}
AnthropicProvider implements the LLM Client interface for Anthropic.
func NewAnthropic ¶
func NewAnthropic(apiKey, model string, opts ...GenerateOption) *AnthropicProvider
NewAnthropic creates a new Anthropic provider with the given API key and model.
func (*AnthropicProvider) Generate ¶
func (p *AnthropicProvider) Generate(ctx context.Context, msgs []Message, opts ...GenerateOption) (Response, error)
Generate sends a messages request to Anthropic and returns the response.
func (*AnthropicProvider) Stream ¶
func (p *AnthropicProvider) Stream(ctx context.Context, msgs []Message, opts ...GenerateOption) (<-chan StreamChunk, error)
Stream sends a streaming messages request to Anthropic.
type Client ¶
type Client interface {
Generate(ctx context.Context, msgs []Message, opts ...GenerateOption) (Response, error)
Stream(ctx context.Context, msgs []Message, opts ...GenerateOption) (<-chan StreamChunk, error)
}
Client is the interface for LLM providers supporting both generate and stream.
type CompatibleProvider ¶
type CompatibleProvider struct {
// contains filtered or unexported fields
}
CompatibleProvider implements the LLM Client interface for OpenAI-compatible APIs.
func NewAzureOpenAI ¶
func NewAzureOpenAI(endpoint, apiKey, deploymentName string, opts ...GenerateOption) *CompatibleProvider
NewAzureOpenAI creates a new provider for Azure OpenAI Service.
func NewDeepSeek ¶
func NewDeepSeek(apiKey, model string, opts ...GenerateOption) *CompatibleProvider
NewDeepSeek creates a new provider for DeepSeek's API.
func NewMistral ¶
func NewMistral(apiKey, model string, opts ...GenerateOption) *CompatibleProvider
NewMistral creates a new provider for Mistral's API.
func NewOllama ¶
func NewOllama(model string, opts ...GenerateOption) *CompatibleProvider
NewOllama creates a new provider for a local Ollama instance.
func NewOpenAICompatible ¶
func NewOpenAICompatible(baseURL, apiKey, model string, opts ...GenerateOption) *CompatibleProvider
NewOpenAICompatible creates a new provider for any OpenAI-compatible API endpoint.
func NewOpenRouter ¶
func NewOpenRouter(apiKey, model string, opts ...GenerateOption) *CompatibleProvider
NewOpenRouter creates a new provider for OpenRouter's API.
func (*CompatibleProvider) Generate ¶
func (p *CompatibleProvider) Generate(ctx context.Context, msgs []Message, opts ...GenerateOption) (Response, error)
Generate sends a chat completion request to the compatible API and returns the response.
func (*CompatibleProvider) Stream ¶
func (p *CompatibleProvider) Stream(ctx context.Context, msgs []Message, opts ...GenerateOption) (<-chan StreamChunk, error)
Stream sends a streaming chat completion request to the compatible API.
type GeminiProvider ¶
type GeminiProvider struct {
// contains filtered or unexported fields
}
GeminiProvider implements the LLM Client interface for Google Gemini.
func NewGemini ¶
func NewGemini(apiKey, model string, opts ...GenerateOption) *GeminiProvider
NewGemini creates a new Gemini provider with the given API key and model.
func (*GeminiProvider) Generate ¶
func (p *GeminiProvider) Generate(ctx context.Context, msgs []Message, opts ...GenerateOption) (Response, error)
Generate sends a content generation request to Gemini and returns the response.
func (*GeminiProvider) Stream ¶
func (p *GeminiProvider) Stream(ctx context.Context, msgs []Message, opts ...GenerateOption) (<-chan StreamChunk, error)
Stream sends a streaming content generation request to Gemini.
type GenerateOption ¶
type GenerateOption func(*GenerateOptions)
GenerateOption configures a generation request.
func WithMaxTokens ¶
func WithMaxTokens(n int) GenerateOption
WithMaxTokens sets the maximum number of tokens to generate.
func WithSchema ¶
func WithSchema(schema any) GenerateOption
WithSchema sets a JSON schema for structured output.
func WithStop ¶
func WithStop(stop []string) GenerateOption
WithStop sets stop sequences for generation.
func WithTemperature ¶
func WithTemperature(t float32) GenerateOption
WithTemperature sets the sampling temperature for generation.
func WithTools ¶
func WithTools(tools []ToolDef) GenerateOption
WithTools sets the available tools for function calling.
func WithTopP ¶
func WithTopP(p float32) GenerateOption
WithTopP sets the nucleus sampling top-p value.
type GenerateOptions ¶
type GenerateOptions struct {
Temperature float32
MaxTokens int
TopP float32
Stop []string
Schema any
Tools []ToolDef
}
GenerateOptions holds the configuration for a generation request.
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content"`
Name string `json:"name,omitempty"`
ToolID string `json:"tool_call_id,omitempty"`
}
Message represents a single message in a conversation with role and content.
type OpenAIProvider ¶
type OpenAIProvider struct {
// contains filtered or unexported fields
}
OpenAIProvider implements the LLM Client interface for OpenAI.
func NewOpenAI ¶
func NewOpenAI(apiKey, model string, opts ...GenerateOption) *OpenAIProvider
NewOpenAI creates a new OpenAI provider with the given API key and model.
func (*OpenAIProvider) Generate ¶
func (p *OpenAIProvider) Generate(ctx context.Context, msgs []Message, opts ...GenerateOption) (Response, error)
Generate sends a chat completion request to OpenAI and returns the response.
func (*OpenAIProvider) Stream ¶
func (p *OpenAIProvider) Stream(ctx context.Context, msgs []Message, opts ...GenerateOption) (<-chan StreamChunk, error)
Stream sends a streaming chat completion request to OpenAI.
type StreamChunk ¶
StreamChunk represents a single chunk from a streaming LLM response.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
FuncName string `json:"function_name"`
FuncArgs string `json:"function_args"`
}
ToolCall represents a function tool invocation requested by the LLM.