Documentation
¶
Index ¶
- Constants
- Variables
- func WithProperty(name, description string, required bool) func(FunctionShape)
- type Agent
- type AnthropicModelList
- type FunctionProps
- type FunctionShape
- type GeminiModelList
- type LLMAgent
- type LLMConfig
- func (c *LLMConfig) Validate() error
- func (c *LLMConfig) WithAnthropicCredentials(apiKey string) *LLMConfig
- func (c *LLMConfig) WithAzureOpenAiCredentials(azureApiKey, azureEndpoint string) *LLMConfig
- func (c *LLMConfig) WithGeminiCredentials(apiKey string) *LLMConfig
- func (c *LLMConfig) WithMaxRetries(n int) *LLMConfig
- func (c *LLMConfig) WithMaxTokens(maxTokens int) *LLMConfig
- func (c *LLMConfig) WithModel(model string) *LLMConfig
- func (c *LLMConfig) WithOllamaCredentials(endpoint string) *LLMConfig
- func (c *LLMConfig) WithOpenAiCredentials(openAiApiKey string) *LLMConfig
- func (c *LLMConfig) WithProvider(provider string) *LLMConfig
- func (c *LLMConfig) WithTemperature(temperature float64) *LLMConfig
- func (c *LLMConfig) WithTimeout(d time.Duration) *LLMConfig
- type Models
- type OllamaModelList
- type OpenAIModelList
- type Pipeline
- func (p *Pipeline) AddTasks(fn ...TaskChainFn)
- func (p *Pipeline) CreateChain(tasks ...TaskChainFn) TaskFn
- func (p *Pipeline) RunConcurrently(ctx context.Context) ([]string, error)
- func (p *Pipeline) RunSequentially(ctx context.Context) ([]string, error)
- func (p *Pipeline) WithLogger(l *slog.Logger) *Pipeline
- type TaskChainFn
- type TaskFn
Constants ¶
const ( ProviderOpenAi = "openai" ProviderAzure = "openai-azure" ProviderAnthropic = "anthropic" ProviderGemini = "gemini" ProviderOllama = "ollama" )
Provider constants.
Variables ¶
var ( ErrProviderNotFound = errors.New("provider does not exist") ErrModelNotFound = errors.New("model does not exist for the selected provider") ErrMissingRole = errors.New("agent Role is required (use WithRole())") ErrMissingBackstory = errors.New("agent Backstory is required (use WithBackstory())") ErrMissingGoal = errors.New("agent Goal is required (use WithGoal())") ErrMissingPrompt = errors.New("user prompt is required (use WithUserPrompt())") ErrMissingAPIKey = errors.New("API key not provided") ErrMissingEndpoint = errors.New("endpoint not provided") ErrTooManyArgs = errors.New("too many arguments: only one optional context argument is allowed") ErrNilTask = errors.New("task function is nil") ErrCompletionFailed = errors.New("completion request failed") ErrToolCallFailed = errors.New("tool call execution failed") ErrChainInterrupted = errors.New("chain interrupted by task error") ErrMaxToolRoundsExceeded = errors.New("maximum tool call rounds exceeded") ErrInvalidConfig = errors.New("invalid LLM configuration") ErrResponseTooLarge = errors.New("response body exceeds maximum allowed size") )
var AnthropicModels = AnthropicModelList{
Claude3Haiku: "claude-3-haiku-20240307",
Claude35Sonnet: "claude-3-5-sonnet-latest",
Claude37Sonnet: "claude-3-7-sonnet-latest",
Claude4Sonnet: "claude-sonnet-4-20250514",
Claude4Opus: "claude-opus-4-20250514",
Claude45Sonnet: "claude-sonnet-4-5-20250620",
Claude45Opus: "claude-opus-4-5-20250620",
Claude46Sonnet: "claude-sonnet-4-6-20250827",
Claude46Opus: "claude-opus-4-6-20250827",
}
AnthropicModels contains the predefined Anthropic model strings.
var GeminiModels = GeminiModelList{
Gemini20Flash: "gemini-2.0-flash",
Gemini20FlashExp: "gemini-2.0-flash-exp",
Gemini25Pro: "gemini-2.5-pro",
Gemini25Flash: "gemini-2.5-flash",
Gemini3Flash: "gemini-3.0-flash",
Gemini3Pro: "gemini-3.0-pro",
}
GeminiModels contains the predefined Gemini model strings.
var OllamaModels = OllamaModelList{
Llama3: "llama3",
Llama31: "llama3.1",
Mistral: "mistral",
Mixtral: "mixtral",
Phi3: "phi3",
Gemma2: "gemma2",
}
OllamaModels contains common Ollama model strings. Users can also pass any custom model name string that is available on their Ollama instance.
var OpenAIModels = OpenAIModelList{
GPT35Turbo: "gpt-3.5-turbo",
GPT4: "gpt-4",
GPT4o: "gpt-4o",
GPT4Turbo: "gpt-4-turbo",
GPT4oMini: "gpt-4o-mini",
O1Mini: "o1-mini",
O1: "o1",
GPT5: "gpt-5",
Codex52: "codex-5.2",
}
OpenAIModels contains the predefined OpenAI model strings.
Functions ¶
func WithProperty ¶
func WithProperty(name, description string, required bool) func(FunctionShape)
WithProperty returns an option that adds a parameter definition to a FunctionShape.
Types ¶
type Agent ¶
Agent represents an AI agent with a role, backstory, and goal.
func (*Agent) NewLLMTask ¶
NewLLMTask creates an LLMAgent for this agent using the provided configuration. Returns an error if the agent is incomplete or the provider/model is invalid.
func (*Agent) WithBackstory ¶
WithBackstory sets the agent's backstory.
type AnthropicModelList ¶
type AnthropicModelList struct {
Claude3Haiku string
Claude35Sonnet string
Claude37Sonnet string
Claude4Sonnet string
Claude4Opus string
Claude45Sonnet string
Claude45Opus string
Claude46Sonnet string
Claude46Opus string
}
AnthropicModelList holds available Anthropic model identifiers.
func (AnthropicModelList) ListModels ¶
func (m AnthropicModelList) ListModels() []string
type FunctionProps ¶
FunctionProps defines properties for a function parameter.
type FunctionShape ¶
type FunctionShape map[string]FunctionProps
FunctionShape maps parameter names to their properties.
func NewFunction ¶
func NewFunction(properties ...func(FunctionShape)) FunctionShape
NewFunction creates a new FunctionShape with the given property options.
type GeminiModelList ¶
type GeminiModelList struct {
Gemini20Flash string
Gemini20FlashExp string
Gemini25Pro string
Gemini25Flash string
Gemini3Flash string
Gemini3Pro string
}
GeminiModelList holds available Google Gemini model identifiers.
func (GeminiModelList) ListModels ¶
func (m GeminiModelList) ListModels() []string
type LLMAgent ¶
type LLMAgent interface {
// Completion sends the prompt to the LLM and returns the response.
// An optional context string can be passed (used in chains).
Completion(ctx context.Context, params ...string) (string, error)
// AddCustomTools registers a custom function-calling tool.
AddCustomTools(name string, description string, params FunctionShape, fn func(param string) (string, error))
// WithUserPrompt sets the user prompt for the next completion.
WithUserPrompt(prompt string)
// WithTools registers pre-built tools (e.g. scraper).
WithTools(tools ...tools.Tool)
}
LLMAgent is the interface that all LLM provider implementations must satisfy.
type LLMConfig ¶
type LLMConfig struct {
// contains filtered or unexported fields
}
LLMConfig holds the configuration for an LLM provider.
func NewLLMConfig ¶
func NewLLMConfig() *LLMConfig
NewLLMConfig creates a new LLMConfig with sensible defaults.
func (*LLMConfig) WithAnthropicCredentials ¶
WithAnthropicCredentials sets Anthropic API credentials.
func (*LLMConfig) WithAzureOpenAiCredentials ¶
WithAzureOpenAiCredentials sets Azure OpenAI credentials.
func (*LLMConfig) WithGeminiCredentials ¶
WithGeminiCredentials sets Google Gemini API credentials.
func (*LLMConfig) WithMaxRetries ¶
WithMaxRetries sets the maximum number of retry attempts for transient errors.
func (*LLMConfig) WithMaxTokens ¶
WithMaxTokens sets the maximum number of tokens in the response.
func (*LLMConfig) WithOllamaCredentials ¶
WithOllamaCredentials sets the Ollama endpoint (default: http://localhost:11434).
func (*LLMConfig) WithOpenAiCredentials ¶
WithOpenAiCredentials sets OpenAI API credentials.
func (*LLMConfig) WithProvider ¶
WithProvider sets the LLM provider (e.g. ProviderOpenAi, ProviderAnthropic).
func (*LLMConfig) WithTemperature ¶
WithTemperature sets the sampling temperature (0.0 - 2.0).
type Models ¶
type Models interface {
ListModels() []string
}
Models interface allows listing available models for a provider.
type OllamaModelList ¶
type OllamaModelList struct {
Llama3 string
Llama31 string
Mistral string
Mixtral string
Phi3 string
Gemma2 string
}
OllamaModelList holds common Ollama model identifiers.
func (OllamaModelList) ListModels ¶
func (m OllamaModelList) ListModels() []string
type OpenAIModelList ¶
type OpenAIModelList struct {
GPT35Turbo string // Deprecated: use GPT4oMini instead
GPT4 string
GPT4o string
GPT4Turbo string
GPT4oMini string
O1Mini string
O1 string
GPT5 string
Codex52 string
}
OpenAIModelList holds available OpenAI model identifiers.
func (OpenAIModelList) ListModels ¶
func (m OpenAIModelList) ListModels() []string
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline orchestrates the execution of multiple LLM tasks.
func (*Pipeline) AddTasks ¶
func (p *Pipeline) AddTasks(fn ...TaskChainFn)
AddTasks appends one or more task functions to the pipeline.
func (*Pipeline) CreateChain ¶
func (p *Pipeline) CreateChain(tasks ...TaskChainFn) TaskFn
CreateChain returns a TaskFn that executes tasks sequentially, passing each task's result as context to the next task. If any task returns an error, the chain stops and the error is returned.
func (*Pipeline) RunConcurrently ¶
RunConcurrently executes all added tasks concurrently and returns their results in the original order. If any task fails or panics, its error is collected and returned as a combined error after all tasks complete.
func (*Pipeline) RunSequentially ¶
RunSequentially executes all added tasks one after another. Each task receives no context arguments. If any task fails, execution stops and the error is returned.
type TaskChainFn ¶
TaskChainFn is a function that takes a context and optional context strings and returns a result or error.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
anthropic-completion
command
|
|
|
chains
command
|
|
|
completion
command
|
|
|
completion-concurrently
command
|
|
|
functionCalling
command
|
|
|
gemini-completion
command
|
|
|
ollama-completion
command
|
|