Documentation
¶
Index ¶
- type Agent
- type AnthropicLLM
- type CachedLLM
- type DummyLLM
- type File
- type GeminiLLM
- type OllamaLLM
- func (o *OllamaLLM) Generate(ctx context.Context, prompt string) (any, error)
- func (o *OllamaLLM) GenerateStream(ctx context.Context, prompt string) (<-chan StreamChunk, error)
- func (o *OllamaLLM) GenerateWithFiles(ctx context.Context, prompt string, files []File) (any, error)
- func (o *OllamaLLM) WebSearch(ctx context.Context, query string, limit int) ([]map[string]string, error)
- type OpenAILLM
- type OpenRouterLLM
- type StreamChunk
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface {
Generate(context.Context, string) (any, error)
GenerateWithFiles(context.Context, string, []File) (any, error)
// GenerateStream returns a channel that yields incremental text chunks.
// The final chunk has Done=true and FullText set to the complete response.
// If the provider doesn't support streaming natively, it falls back to
// a single-chunk response wrapping Generate.
GenerateStream(ctx context.Context, prompt string) (<-chan StreamChunk, error)
}
func NewGeminiLLM ¶
func NewLLMProvider ¶
func NewLLMProvider(ctx context.Context, provider string, model string, promptPrefix string) (Agent, error)
NewLLMProvider returns a concrete Agent.
func TryCreateCachedLLM ¶ added in v1.10.5
TryCreateCachedLLM checks env vars and wraps the agent if caching is enabled.
type AnthropicLLM ¶
type AnthropicLLM struct {
Client *anthropic.Client
Model string
MaxTokens int
PromptPrefix string
}
AnthropicLLM implements your Agent interface using Anthropic's Messages API.
func NewAnthropicLLM ¶
func NewAnthropicLLM(model, promptPrefix string) *AnthropicLLM
NewAnthropicLLM constructs a client. It reads ANTHROPIC_API_KEY from the env.
func (*AnthropicLLM) Generate ¶
Generate performs a single-turn completion and returns concatenated text.
func (*AnthropicLLM) GenerateStream ¶ added in v1.10.6
func (a *AnthropicLLM) GenerateStream(ctx context.Context, prompt string) (<-chan StreamChunk, error)
GenerateStream uses Anthropic's streaming messages API.
func (*AnthropicLLM) GenerateWithFiles ¶
type CachedLLM ¶ added in v1.10.5
CachedLLM wraps an Agent and caches Generate calls.
func NewCachedLLM ¶ added in v1.10.5
NewCachedLLM creates a new CachedLLM wrapper.
func (*CachedLLM) Generate ¶ added in v1.10.5
Generate checks the cache before calling the underlying agent.
func (*CachedLLM) GenerateStream ¶ added in v1.10.6
GenerateStream passes through to the underlying agent's streaming. If the prompt is already cached, it returns a single-chunk stream from cache. Otherwise, it streams from the underlying agent and caches the full result when done.
type DummyLLM ¶
type DummyLLM struct {
Prefix string
}
DummyLLM is a lightweight model implementation useful for local testing without API calls.
func NewDummyLLM ¶
func (*DummyLLM) GenerateStream ¶ added in v1.10.6
GenerateStream simulates streaming by splitting the response into word-level chunks.
type File ¶
File is a lightweight in-memory attachment. Name is used for display; MIME should be best-effort (e.g., "text/markdown").
type GeminiLLM ¶
func (*GeminiLLM) GenerateStream ¶ added in v1.10.6
GenerateStream uses Gemini's streaming API to yield tokens incrementally.
type OllamaLLM ¶
type OllamaLLM struct {
Client *ollama.Client
Model string
PromptPrefix string
// contains filtered or unexported fields
}
func (*OllamaLLM) GenerateStream ¶ added in v1.10.6
GenerateStream leverages Ollama's native callback-based streaming.
func (*OllamaLLM) GenerateWithFiles ¶
type OpenAILLM ¶
func NewOpenAILLM ¶
func (*OpenAILLM) GenerateStream ¶ added in v1.10.6
GenerateStream uses OpenAI's streaming chat completion API.
type OpenRouterLLM ¶ added in v1.12.0
type OpenRouterLLM struct {
Client *openrouter.Client
Model string
PromptPrefix string
}
func NewOpenRouterLLM ¶ added in v1.12.0
func NewOpenRouterLLM(model string, promptPrefix string) *OpenRouterLLM
func (*OpenRouterLLM) GenerateStream ¶ added in v1.12.0
func (o *OpenRouterLLM) GenerateStream(ctx context.Context, prompt string) (<-chan StreamChunk, error)
GenerateStream uses OpenRouter's streaming chat completion API
func (*OpenRouterLLM) GenerateWithFiles ¶ added in v1.12.0
type StreamChunk ¶ added in v1.10.6
type StreamChunk struct {
Delta string // incremental text token
Done bool // true on the final chunk
FullText string // aggregated text (populated only on the final chunk)
Err error // non-nil if the stream encountered a fatal error
}
StreamChunk represents a single piece of a streaming LLM response. When Done is true, the stream is complete and FullText holds the aggregated output. When Err is non-nil, the stream encountered an error.