Documentation
¶
Overview ¶
Package llm provides LLM agent integration and invocation.
Index ¶
- Constants
- Variables
- func AgentEnabled(name string) bool
- func AgentModelName(name string) string
- func ConvertFromString(input string) (map[string]any, error)
- func CountMessageTokens(messages []*Message) (int, error)
- func CountToken(text string) int
- func GetModel(modelName string) config.Model
- func LLMGenerate(ctx context.Context, modelName, prompt string) (string, error)
- func RegisterAnthropic()
- func RegisterGemini()
- func RegisterOpenAI()
- func Stream(ctx context.Context, client *Client, messages []*Message) (<-chan *Message, error)
- type BaseTool
- type ChatTemplate
- type Client
- type FunctionTool
- type GenerateRequest
- type InvokableTool
- type Message
- type MessageFragment
- type ParamsOneOf
- type Provider
- type Role
- type Schema
- type Tool
- type ToolCall
- type ToolCallFunction
- type ToolInfo
Constants ¶
const ( SystemRole = "system" UserRole = "user" AssistantRole = "model" ToolRole = "tool" )
Role constants
const ( AgentChat = "chat" AgentBillClassify = "bill_classify" AgentExtractTags = "extract_tags" AgentSimilarTags = "similar_tags" AgentNewsSummary = "news_summary" AgentRepoReviewComment = "repo_review_comment" )
Agent name constants
const ( ProviderOpenAI = "openai" ProviderOpenAICompatible = "openai_compatible" ProviderGemini = "gemini" ProviderAnthropic = "anthropic" )
Model provider constants
Variables ¶
var ErrUnknownProvider = errors.New("unknown llm provider")
Functions ¶
func AgentEnabled ¶
func AgentModelName ¶
func ConvertFromString ¶
ConvertFromString converts string input to map if needed
func CountMessageTokens ¶
func CountToken ¶
func RegisterAnthropic ¶
func RegisterAnthropic()
RegisterAnthropic registers the Anthropic LLM provider in the global provider registry.
func RegisterGemini ¶
func RegisterGemini()
RegisterGemini registers the Gemini LLM provider in the global provider registry.
func RegisterOpenAI ¶
func RegisterOpenAI()
RegisterOpenAI registers the OpenAI and OpenAI-compatible LLM providers.
Types ¶
type BaseTool ¶
type BaseTool interface {
Info(ctx context.Context) (*ToolInfo, error)
InvokableRun(ctx context.Context, input string) (string, error)
}
BaseTool is the base interface for all tools
type ChatTemplate ¶
type ChatTemplate interface {
Format(ctx context.Context, data map[string]any) ([]*Message, error)
}
func BaseTemplate ¶
func BaseTemplate() ChatTemplate
func DefaultMultiChatTemplate ¶
func DefaultMultiChatTemplate() ChatTemplate
func DefaultTemplate ¶
func DefaultTemplate() ChatTemplate
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a Provider for model operations
type FunctionTool ¶
type FunctionTool struct {
Name string
Description string
Parameters *ParamsOneOf
Execute func(ctx context.Context, input string) (string, error)
}
FunctionTool implements InvokableTool for function-based tools
func (*FunctionTool) Info ¶
func (f *FunctionTool) Info(_ context.Context) (*ToolInfo, error)
Info returns tool metadata
func (*FunctionTool) InvokableRun ¶
InvokableRun executes the tool
type GenerateRequest ¶
type GenerateRequest struct {
Model string
Messages []*Message
Tools []Tool
MaxTokens int
Temperature float64
}
GenerateRequest holds parameters for a model generation call
type InvokableTool ¶
type InvokableTool interface {
BaseTool
}
InvokableTool is a tool that can be invoked
type MessageFragment ¶
MessageFragment represents a partial streaming response chunk
type ParamsOneOf ¶
type ParamsOneOf struct {
OneOf []Schema
}
ParamsOneOf represents tool parameters schema
func (*ParamsOneOf) ToJSONSchema ¶
func (p *ParamsOneOf) ToJSONSchema() (map[string]any, error)
ToJSONSchema converts ParamsOneOf to JSON schema map
type Provider ¶
type Provider interface {
Name() string
Generate(ctx context.Context, req *GenerateRequest) (*Message, error)
GenerateStream(ctx context.Context, req *GenerateRequest) (<-chan MessageFragment, error)
}
Provider is the interface for LLM model backends
type Schema ¶
type Schema struct {
Type string
Description string
Properties map[string]Schema
Required []string
}
Schema represents JSON schema for tool parameters
type Tool ¶
type Tool interface {
Name() string
Description() string
Parameters() *ParamsOneOf
Execute(ctx context.Context, input string) (string, error)
}
Tool interface for agent tools
type ToolCall ¶
type ToolCall struct {
ID string
Type string
Function ToolCallFunction
}
ToolCall represents a function call from the model
type ToolCallFunction ¶
ToolCallFunction represents function call details
type ToolInfo ¶
type ToolInfo struct {
Name string
Desc string
ParamsOneOf *ParamsOneOf
}
ToolInfo contains tool metadata