Documentation
¶
Index ¶
- Constants
- func CountTokens(text string) int
- func EstimateMaxTokens(promptTokens, contextWindowSize int) int
- func RegisterCustomProvider(name string, factory LlmFactory)
- func RegisterProvider(provider Provider, factory LlmFactory)
- type AgentInterface
- type LlmFactory
- type LlmInterface
- type LlmOptions
- type OutputFormat
- type Provider
Constants ¶
const GEMINI_MODEL_1_5_FLASH = "gemini-1.5-flash" // supported but now old
const GEMINI_MODEL_1_5_PRO = "gemini-1.5-pro" // supported but now old
const GEMINI_MODEL_2_0_FLASH_EXP_IMAGE_GENERATION = "gemini-2.0-flash-exp-image-generation"
const GEMINI_MODEL_2_0_FLASH = "gemini-2.0-flash-001" const GEMINI_MODEL_2_0_FLASH_LITE = "gemini-2.0-flash-lite-001"
const GEMINI_MODEL_2_5_FLASH = "gemini-2.5-flash"
const GEMINI_MODEL_2_5_FLASH_LITE = "gemini-2.5-flash-lite"
const GEMINI_MODEL_2_5_PRO = "gemini-2.5-pro"
const GEMINI_MODEL_3_0_IMAGEN = "imagen-3.0-generate-002" // not supported
const OPENROUTER_MODEL_CODESTRAL_EMBED_2505 = "mistralai/codestral-embed-2505"
Mistral Codestral Embedding 2505 Input $0.15/M Output $0.00/M
const OPENROUTER_MODEL_DEEPSEEK_V3_1 = "deepseek/deepseek-chat-v3.1"
DeepSeek DeepSeek V3.1 Input $0.20/M Output $0.80/M Context 163,840
const OPENROUTER_MODEL_GEMINI_2_5_FLASH = "google/gemini-2.5-flash"
Google Gemini 2.5 Flash Input $0.30/M Output $2.50/M Context 1,048,576
const OPENROUTER_MODEL_GEMINI_2_5_FLASH_IMAGE = "google/gemini-2.5-flash-image"
Google Gemini 2.5 Flash Image Input $0.30/M Output $2.50/M Context 1,048,576
const OPENROUTER_MODEL_GEMINI_2_5_FLASH_LITE = "google/gemini-2.5-flash-lite"
Google Gemini 2.5 Flash Lite Input $0.10/M Output $0.40/M Context 1,048,576
const OPENROUTER_MODEL_GEMINI_2_5_PRO = "google/gemini-2.5-pro"
Google Gemini 2.5 Pro Input $1.25/M Output $10/M Context 1,048,576
const OPENROUTER_MODEL_GEMINI_3_PRO_PREVIEW = "google/gemini-3-pro-preview"
Google Gemini 3 Pro Preview Input $2/M Output $12/M Context 1,048,576
const OPENROUTER_MODEL_GEMINI_EMBED_001 = "google/gemini-embedding-001"
Google Gemini Embedding 001 Input $0.15/M Output $0.00/M
const OPENROUTER_MODEL_GEMMA_3_12B_IT = "google/gemma-3-12b-it"
Google Gemma 3 12B Input $0.048/M Output $0.193/M Context 96,000
const OPENROUTER_MODEL_GEMMA_3_27B_IT = "google/gemma-3-27b-it"
Google Gemma 3 27B Input $0.067/M Output $0.267/M Context 96,000
const OPENROUTER_MODEL_GPT_4_1_NANO = "openai/gpt-4.1-nano"
OpenAI GPT-4.1 Nano Input $0.10/M Output $0.40/M Context 1,047,576
const OPENROUTER_MODEL_GPT_5_1 = "openai/gpt-5.1"
OpenAI GPT-5.1 Input $1.25/M Output $10.00/M Context 400,000 Web Search: $10/K
const OPENROUTER_MODEL_GPT_5_IMAGE = "openai/gpt-5-image"
OpenAI GPT-5 Image Input $10.00/M Output $10/M Context 1,048,576
const OPENROUTER_MODEL_GPT_5_IMAGE_MINI = "openai/gpt-5-image-mini"
OpenAI GPT-5 Image Mini Input $2.50/M Output $2/M Context 1,048,576
const OPENROUTER_MODEL_GPT_5_NANO = "openai/gpt-5-nano"
OpenAI GPT-5 Nano Input $0.05/M Output $0.40/M Context 400,000
const OPENROUTER_MODEL_GPT_OSS_120B = "openai/gpt-oss-120b"
OpenAI GPT-OSS-120B Input $0.072/M Output $0.28/M Context 131,000
const OPENROUTER_MODEL_GPT_OSS_20B = "openai/gpt-oss-20b"
OpenAI GPT-OSS-20B Input $0.04/M Output $0.15/M Context 131,000
const OPENROUTER_MODEL_MISTRAL_EMBED_2312 = "mistralai/mistral-embed-2312"
Mistral Mistral Embedding 2312 Input $0.10/M Output $0.00/M
const OPENROUTER_MODEL_MISTRAL_MEDIUM_3_1 = "mistralai/mistral-medium-3.1"
Mistral Mistral Medium 3.1 Input $0.40/M output $2/M Context 131,072
const OPENROUTER_MODEL_MISTRAL_NEMO = "mistralai/mistral-nemo"
Mistral Mistral Nemo Input $0.01/M Output $0.04/M Context 131,072
const OPENROUTER_MODEL_O4_MINI = "openai/o4-mini"
OpenAI O4 Mini Input $1.10/M Output $4.40/M Context 200,000
const OPENROUTER_MODEL_QWEN_3_235B_A22B_INSTRUCT_2507 = "qwen/qwen3-235b-a22b-2507"
Qwen Qwen3 235B A22B Instruct 2507 Input $0.078/M Output $0.312/M Context 262,144
const OPENROUTER_MODEL_QWEN_3_30B_A3B = "qwen/qwen3-30b-a3b"
Qwen Qwen3 30B A3B Input $0.02/M Output $0.08/M Context 40,960
const OPENROUTER_MODEL_QWEN_3_EMBEDDING_0_6B = "qwen/qwen3-embedding-0.6b"
Qwen Qwen3 Embedding 0.6B Input $0.01/M Output $0.00/M
const OPENROUTER_MODEL_TEXT_EMBEDDING_3_LARGE = "openai/text-embedding-3-large"
OpenAI Text Embedding 3 Large Input $0.13/M Output $0.00/M
const OPENROUTER_MODEL_TEXT_EMBEDDING_3_SMALL = "openai/text-embedding-3-small"
OpenAI Text Embedding 3 Small Input $0.02/M Output $0.00/M
const OPENROUTER_MODEL_TEXT_EMBEDDING_ADA_002 = "openai/text-embedding-ada-002"
OpenAI Text Embedding Ada 002 Input $0.10/M Output $0.00/M
Variables ¶
This section is empty.
Functions ¶
func CountTokens ¶
CountTokens provides a simple approximation of token counting Note: This is a basic implementation and not accurate for all models Production code should use model-specific tokenizers
func EstimateMaxTokens ¶
EstimateMaxTokens estimates the maximum number of tokens that could be generated given the model's context window size and the prompt length
func RegisterCustomProvider ¶ added in v0.2.0
func RegisterCustomProvider(name string, factory LlmFactory)
RegisterCustomProvider registers a custom LLM provider
func RegisterProvider ¶ added in v0.2.0
func RegisterProvider(provider Provider, factory LlmFactory)
RegisterProvider registers a new LLM provider factory
Types ¶
type AgentInterface ¶ added in v0.2.0
type AgentInterface interface {
// SetRole sets the role of the agent
// i.e. "You are a helpful assistant"
SetRole(role string)
// GetRole returns the role of the agent
GetRole() string
// SetTask sets the task for the agent
// i.e. "Your task is to write a book about self-improvement"
SetTask(task string)
// GetTask returns the task of the agent
GetTask() string
// Execute runs the agent and returns the response
Execute() (response string, err error)
}
AgentInterface defines the core interface that all agents must implement
type LlmFactory ¶ added in v0.2.0
type LlmFactory func(options LlmOptions) (LlmInterface, error)
LlmFactory is a function type that creates a new LLM instance Now returns (LlmInterface, error)
type LlmInterface ¶ added in v0.2.0
type LlmInterface interface {
// GenerateText generates a text response from the LLM based on the given prompt
GenerateText(systemPrompt string, userPrompt string, options ...LlmOptions) (string, error)
// GenerateJSON generates a JSON response from the LLM based on the given prompt
GenerateJSON(systemPrompt string, userPrompt string, options ...LlmOptions) (string, error)
// GenerateImage generates an image from the LLM based on the given prompt
GenerateImage(prompt string, options ...LlmOptions) ([]byte, error)
// DEPRECATED: Generate generates a response from the LLM based on the given prompt and options
Generate(systemPrompt string, userMessage string, options ...LlmOptions) (string, error)
// GenerateEmbedding generates embeddings for the given text
GenerateEmbedding(text string) ([]float32, error)
}
LlmInterface is an interface for making LLM API calls
func ImageModel ¶
func ImageModel(provider Provider, options LlmOptions) (LlmInterface, error)
ImageModel creates an LLM model for image output
func JSONModel ¶
func JSONModel(provider Provider, options LlmOptions) (LlmInterface, error)
JSONModel creates an LLM model for JSON output
func NewLLM ¶ added in v0.2.0
func NewLLM(options LlmOptions) (LlmInterface, error)
NewLLM creates a new LLM instance based on the provider specified in options
func TextModel ¶
func TextModel(provider Provider, options LlmOptions) (LlmInterface, error)
TextModel creates an LLM model for text output
type LlmOptions ¶ added in v0.2.0
type LlmOptions struct {
// Provider specifies which LLM provider to use
Provider Provider
// MockResponse, if not empty, will be returned by the mock implementation
// instead of making an actual API call. This is useful for testing.
MockResponse string `json:"-"`
// ApiKey specifies the API key for the LLM provider
ApiKey string
// ProjectID specifies the project ID for the LLM (used by Vertex AI)
ProjectID string
// Region specifies the region for the LLM (used by Vertex AI)
Region string
// Model specifies the LLM model to use
Model string
// MaxTokens specifies the maximum number of tokens to generate
MaxTokens int
// Temperature controls the randomness of the response
// A higher temperature (e.g., 0.8) makes the output more random and creative,
// while a lower temperature (e.g., 0.2) makes the output more focused and deterministic.
Temperature float64
// Verbose controls whether to log detailed information
Verbose bool
// Logger specifies a logger to use for error logging
Logger *slog.Logger
// OutputFormat specifies the output format from the LLM
OutputFormat OutputFormat
// Additional options specific to the LLM provider
ProviderOptions map[string]any
}
type OutputFormat ¶
type OutputFormat string
OutputFormat specifies the desired output format from the LLM
const ( OutputFormatText OutputFormat = "text" OutputFormatJSON OutputFormat = "json" OutputFormatXML OutputFormat = "xml" OutputFormatYAML OutputFormat = "yaml" OutputFormatEnum OutputFormat = "enum" OutputFormatImagePNG OutputFormat = "image/png" OutputFormatImageJPG OutputFormat = "image/jpeg" )