llm

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SuggestCommandsToolName = "suggest_commands"
	EditToolName            = "edit"
	UnifiedDiffToolName     = "unified_diff"
	WebSearchToolName       = "web_search"
)
View Source
const EditToolDescription = "" /* 215-byte string literal not displayed */

EditToolDescription is the description for the edit tool.

View Source
const (
	ReadURLToolName = "read_url"
)
View Source
const UnifiedDiffToolDescription = `` /* 929-byte string literal not displayed */

UnifiedDiffToolDescription is the description for the unified diff tool.

Variables

View Source
var ImageProviderModels = map[string][]string{
	"gemini": {"gemini-2.5-flash-image", "gemini-3-pro-image-preview"},
	"openai": {"gpt-image-1.5", "gpt-image-1-mini"},
	"flux":   {"flux-2-pro", "flux-kontext-pro", "flux-2-max"},
}
View Source
var ProviderModels = map[string][]string{
	"anthropic": {

		"claude-sonnet-4-5",
		"claude-sonnet-4-5-thinking",
		"claude-opus-4-5",
		"claude-opus-4-5-thinking",
		"claude-haiku-4-5",
		"claude-haiku-4-5-thinking",
	},
	"openai": {
		"gpt-5.2",
		"gpt-5.2-high",
		"gpt-5.2-codex",
		"gpt-5.2-codex-medium",
		"gpt-5.2-codex-high",
		"gpt-5.2-codex-xhigh",
		"gpt-4.1",
	},
	"openrouter": {
		"x-ai/grok-code-fast-1",
	},
	"gemini": {
		"gemini-3-pro-preview",
		"gemini-3-pro-preview-thinking",
		"gemini-3-flash-preview",
		"gemini-3-flash-preview-thinking",
		"gemini-2.5-flash",
		"gemini-2.5-flash-lite",
	},
	"zen": {
		"glm-4.7-free",
		"grok-code",
		"minimax-m2.1-free",
		"big-pickle",
		"gpt-5-nano",
	},
}

ProviderModels contains the curated list of common models per LLM provider

Functions

func DebugRawEvent added in v0.0.10

func DebugRawEvent(enabled bool, event Event)

DebugRawEvent prints each stream event with a timestamp.

func DebugRawRequest added in v0.0.10

func DebugRawRequest(enabled bool, providerName, credential string, req Request, label string)

DebugRawRequest prints the raw request with all message parts in debug mode.

func DebugRawSection added in v0.0.10

func DebugRawSection(enabled bool, label, body string)

DebugRawSection prints a timestamped debug section.

func DebugRawToolCall added in v0.0.10

func DebugRawToolCall(enabled bool, call ToolCall)

DebugRawToolCall prints a tool call with raw JSON arguments and a timestamp.

func DebugRawToolResult added in v0.0.10

func DebugRawToolResult(enabled bool, id, name, content string)

DebugRawToolResult prints a tool result payload with a timestamp.

func DebugToolCall added in v0.0.10

func DebugToolCall(enabled bool, call ToolCall)

DebugToolCall prints a tool call in debug mode with readable formatting.

func DebugToolResult added in v0.0.10

func DebugToolResult(enabled bool, id, name, content string)

DebugToolResult prints a tool result in debug mode with readable formatting.

func EditToolSchema added in v0.0.9

func EditToolSchema() map[string]interface{}

EditToolSchema returns the JSON schema for the edit tool.

func GetImageProviderNames added in v0.0.6

func GetImageProviderNames() []string

GetImageProviderNames returns valid provider names for image generation

func GetProviderCompletions added in v0.0.6

func GetProviderCompletions(toComplete string, isImage bool) []string

GetProviderCompletions returns completions for the --provider flag It handles both provider-only and provider:model completion scenarios

func GetProviderNames added in v0.0.6

func GetProviderNames() []string

GetProviderNames returns valid provider names for LLM

func IsCodexModel added in v0.0.6

func IsCodexModel(model string) bool

IsCodexModel returns true if the model name indicates a Codex model.

func ParseProviderModel added in v0.0.6

func ParseProviderModel(s string) (string, string, error)

ParseProviderModel parses "provider:model" or just "provider" from a flag value. Returns (provider, model, error). Model will be empty if not specified.

func ParseUnifiedDiff added in v0.0.9

func ParseUnifiedDiff(call ToolCall) (string, error)

ParseUnifiedDiff parses a unified_diff tool call payload.

func UnifiedDiffToolSchema added in v0.0.9

func UnifiedDiffToolSchema() map[string]interface{}

UnifiedDiffToolSchema returns the JSON schema for the unified diff tool.

Types

type AnthropicProvider

type AnthropicProvider struct {
	// contains filtered or unexported fields
}

AnthropicProvider implements Provider using the Anthropic API.

func NewAnthropicProvider

func NewAnthropicProvider(apiKey, model string) *AnthropicProvider

func (*AnthropicProvider) Capabilities added in v0.0.10

func (p *AnthropicProvider) Capabilities() Capabilities

func (*AnthropicProvider) Credential added in v0.0.10

func (p *AnthropicProvider) Credential() string

func (*AnthropicProvider) ListModels added in v0.0.8

func (p *AnthropicProvider) ListModels(ctx context.Context) ([]ModelInfo, error)

ListModels returns available models from Anthropic.

func (*AnthropicProvider) Name

func (p *AnthropicProvider) Name() string

func (*AnthropicProvider) Stream added in v0.0.10

func (p *AnthropicProvider) Stream(ctx context.Context, req Request) (Stream, error)

type Capabilities added in v0.0.10

type Capabilities struct {
	NativeWebSearch bool // Provider has native web search capability
	NativeWebFetch  bool // Provider has native URL fetch capability
	ToolCalls       bool
}

Capabilities describe optional provider features.

type CodeAssistProvider

type CodeAssistProvider struct {
	// contains filtered or unexported fields
}

CodeAssistProvider implements Provider using Google Code Assist API with OAuth

func NewCodeAssistProvider

func NewCodeAssistProvider(creds *credentials.GeminiOAuthCredentials, model string) *CodeAssistProvider

func (*CodeAssistProvider) Capabilities added in v0.0.10

func (p *CodeAssistProvider) Capabilities() Capabilities

func (*CodeAssistProvider) Credential added in v0.0.10

func (p *CodeAssistProvider) Credential() string

func (*CodeAssistProvider) Name

func (p *CodeAssistProvider) Name() string

func (*CodeAssistProvider) Stream added in v0.0.10

func (p *CodeAssistProvider) Stream(ctx context.Context, req Request) (Stream, error)

type CodexProvider

type CodexProvider struct {
	// contains filtered or unexported fields
}

CodexProvider implements Provider using the ChatGPT backend API with Codex OAuth.

func NewCodexProvider

func NewCodexProvider(accessToken, model, accountID string) *CodexProvider

func (*CodexProvider) Capabilities added in v0.0.10

func (p *CodexProvider) Capabilities() Capabilities

func (*CodexProvider) Credential added in v0.0.10

func (p *CodexProvider) Credential() string

func (*CodexProvider) Name

func (p *CodexProvider) Name() string

func (*CodexProvider) Stream added in v0.0.10

func (p *CodexProvider) Stream(ctx context.Context, req Request) (Stream, error)

type CommandSuggestion

type CommandSuggestion struct {
	Command     string `json:"command"`
	Explanation string `json:"explanation"`
	Likelihood  int    `json:"likelihood"` // 1-10, how likely this matches user intent
}

CommandSuggestion represents a single command suggestion from the LLM.

func ParseCommandSuggestions added in v0.0.10

func ParseCommandSuggestions(call ToolCall) ([]CommandSuggestion, error)

ParseCommandSuggestions parses a suggest_commands tool call.

type EditToolCall added in v0.0.5

type EditToolCall struct {
	FilePath  string `json:"file_path"`
	OldString string `json:"old_string"`
	NewString string `json:"new_string"`
}

EditToolCall represents a single edit tool call (find/replace).

func ParseEditToolCall added in v0.0.10

func ParseEditToolCall(call ToolCall) (EditToolCall, error)

ParseEditToolCall parses a single edit tool call payload.

type Engine added in v0.0.10

type Engine struct {
	// contains filtered or unexported fields
}

Engine orchestrates provider calls and external tool execution.

func NewEngine added in v0.0.10

func NewEngine(provider Provider, tools *ToolRegistry) *Engine

func (*Engine) Stream added in v0.0.10

func (e *Engine) Stream(ctx context.Context, req Request) (Stream, error)

Stream returns a stream, applying external tools when needed.

type Event added in v0.0.10

type Event struct {
	Type     EventType
	Text     string
	Tool     *ToolCall
	ToolName string // For EventToolExecStart: name of tool being executed
	ToolInfo string // For EventToolExecStart: additional info (e.g., URL being fetched)
	Use      *Usage
	Err      error
	// Retry fields (for EventRetry)
	RetryAttempt     int
	RetryMaxAttempts int
	RetryWaitSecs    float64
}

Event represents a streamed output update.

type EventType added in v0.0.10

type EventType string

EventType describes streaming events.

const (
	EventTextDelta     EventType = "text_delta"
	EventToolCall      EventType = "tool_call"
	EventToolExecStart EventType = "tool_exec_start" // Emitted when tool execution begins
	EventUsage         EventType = "usage"
	EventDone          EventType = "done"
	EventError         EventType = "error"
	EventRetry         EventType = "retry" // Emitted when retrying after rate limit
)

type GeminiProvider

type GeminiProvider struct {
	// contains filtered or unexported fields
}

GeminiProvider implements Provider using the Google Gemini API.

func NewGeminiProvider

func NewGeminiProvider(apiKey, model string) *GeminiProvider

func (*GeminiProvider) Capabilities added in v0.0.10

func (p *GeminiProvider) Capabilities() Capabilities

func (*GeminiProvider) Credential added in v0.0.10

func (p *GeminiProvider) Credential() string

func (*GeminiProvider) Name

func (p *GeminiProvider) Name() string

func (*GeminiProvider) Stream added in v0.0.10

func (p *GeminiProvider) Stream(ctx context.Context, req Request) (Stream, error)

type Message added in v0.0.10

type Message struct {
	Role  Role
	Parts []Part
}

Message holds a role with structured parts.

func AssistantText added in v0.0.10

func AssistantText(text string) Message

func SystemText added in v0.0.10

func SystemText(text string) Message

func ToolResultMessage added in v0.0.10

func ToolResultMessage(id, name, content string) Message

func UserText added in v0.0.10

func UserText(text string) Message

type ModelInfo added in v0.0.8

type ModelInfo struct {
	ID          string
	DisplayName string
	Created     int64
	OwnedBy     string
}

ModelInfo represents a model available from a provider.

type OpenAICompatProvider added in v0.0.8

type OpenAICompatProvider struct {
	// contains filtered or unexported fields
}

OpenAICompatProvider implements Provider for OpenAI-compatible APIs Used by Ollama, LM Studio, and other compatible servers.

func NewOpenAICompatProvider added in v0.0.8

func NewOpenAICompatProvider(baseURL, apiKey, model, name string) *OpenAICompatProvider

func NewOpenAICompatProviderWithHeaders added in v0.0.10

func NewOpenAICompatProviderWithHeaders(baseURL, apiKey, model, name string, headers map[string]string) *OpenAICompatProvider

func NewOpenRouterProvider added in v0.0.10

func NewOpenRouterProvider(apiKey, model, appURL, appTitle string) *OpenAICompatProvider

NewOpenRouterProvider creates an OpenRouter provider using OpenAI-compatible APIs.

func NewZenProvider added in v0.0.2

func NewZenProvider(apiKey, model string) *OpenAICompatProvider

NewZenProvider creates an OpenAICompatProvider preconfigured for OpenCode Zen. Zen provides free access to models like GLM 4.7 via opencode.ai. API key is optional: empty for free tier, or set ZEN_API_KEY for paid models.

func (*OpenAICompatProvider) Capabilities added in v0.0.10

func (p *OpenAICompatProvider) Capabilities() Capabilities

func (*OpenAICompatProvider) Credential added in v0.0.10

func (p *OpenAICompatProvider) Credential() string

func (*OpenAICompatProvider) ListModels added in v0.0.8

func (p *OpenAICompatProvider) ListModels(ctx context.Context) ([]ModelInfo, error)

ListModels returns available models from the server.

func (*OpenAICompatProvider) Name added in v0.0.8

func (p *OpenAICompatProvider) Name() string

func (*OpenAICompatProvider) Stream added in v0.0.10

func (p *OpenAICompatProvider) Stream(ctx context.Context, req Request) (Stream, error)

type OpenAIProvider

type OpenAIProvider struct {
	// contains filtered or unexported fields
}

OpenAIProvider implements Provider using the standard OpenAI API.

func NewOpenAIProvider

func NewOpenAIProvider(apiKey, model string) *OpenAIProvider

func (*OpenAIProvider) Capabilities added in v0.0.10

func (p *OpenAIProvider) Capabilities() Capabilities

func (*OpenAIProvider) Credential added in v0.0.10

func (p *OpenAIProvider) Credential() string

func (*OpenAIProvider) Name

func (p *OpenAIProvider) Name() string

func (*OpenAIProvider) Stream added in v0.0.10

func (p *OpenAIProvider) Stream(ctx context.Context, req Request) (Stream, error)

type Part added in v0.0.10

type Part struct {
	Type       PartType
	Text       string
	ToolCall   *ToolCall
	ToolResult *ToolResult
}

Part represents a single content part.

type PartType added in v0.0.10

type PartType string

PartType identifies a message content part.

const (
	PartText       PartType = "text"
	PartToolCall   PartType = "tool_call"
	PartToolResult PartType = "tool_result"
)

type Provider

type Provider interface {
	Name() string
	Credential() string // Returns credential type for debugging (e.g., "api_key", "codex", "claude-code")
	Capabilities() Capabilities
	Stream(ctx context.Context, req Request) (Stream, error)
}

Provider streams model output events for a request.

func NewProvider

func NewProvider(cfg *config.Config) (Provider, error)

NewProvider creates a new LLM provider based on the config. Providers are wrapped with automatic retry for rate limits (429) and transient errors.

func WrapWithRetry added in v0.0.12

func WrapWithRetry(p Provider, config RetryConfig) Provider

WrapWithRetry wraps a provider with retry logic.

type ReadURLTool added in v0.0.11

type ReadURLTool struct {
	// contains filtered or unexported fields
}

ReadURLTool fetches web pages using Jina AI Reader.

func NewReadURLTool added in v0.0.11

func NewReadURLTool() *ReadURLTool

func (*ReadURLTool) Execute added in v0.0.11

func (t *ReadURLTool) Execute(ctx context.Context, args json.RawMessage) (string, error)

func (*ReadURLTool) Spec added in v0.0.11

func (t *ReadURLTool) Spec() ToolSpec

type Request added in v0.0.10

type Request struct {
	Model             string
	Messages          []Message
	Tools             []ToolSpec
	ToolChoice        ToolChoice
	ParallelToolCalls bool
	Search            bool
	ReasoningEffort   string
	MaxOutputTokens   int
	Temperature       float32
	TopP              float32
	Debug             bool
	DebugRaw          bool
}

Request represents a single model turn.

type RetryConfig added in v0.0.12

type RetryConfig struct {
	MaxAttempts int
	BaseBackoff time.Duration
	MaxBackoff  time.Duration
}

RetryConfig configures retry behavior.

func DefaultRetryConfig added in v0.0.12

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns sensible defaults for rate limit retries.

type RetryProvider added in v0.0.12

type RetryProvider struct {
	// contains filtered or unexported fields
}

RetryProvider wraps a provider with automatic retry on transient errors.

func (*RetryProvider) Capabilities added in v0.0.12

func (r *RetryProvider) Capabilities() Capabilities

func (*RetryProvider) Credential added in v0.0.12

func (r *RetryProvider) Credential() string

func (*RetryProvider) Name added in v0.0.12

func (r *RetryProvider) Name() string

func (*RetryProvider) Stream added in v0.0.12

func (r *RetryProvider) Stream(ctx context.Context, req Request) (Stream, error)

type Role added in v0.0.10

type Role string

Role identifies a message role.

const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

type Stream added in v0.0.10

type Stream interface {
	Recv() (Event, error)
	Close() error
}

Stream yields events until io.EOF.

func WrapDebugStream added in v0.0.10

func WrapDebugStream(enabled bool, inner Stream) Stream

type Tool added in v0.0.10

type Tool interface {
	Spec() ToolSpec
	Execute(ctx context.Context, args json.RawMessage) (string, error)
}

Tool describes a callable external tool.

type ToolCall added in v0.0.10

type ToolCall struct {
	ID        string
	Name      string
	Arguments json.RawMessage
}

ToolCall is a model-requested tool invocation.

type ToolChoice added in v0.0.10

type ToolChoice struct {
	Mode ToolChoiceMode
	Name string
}

ToolChoice configures which tool the model should call.

type ToolChoiceMode added in v0.0.10

type ToolChoiceMode string

ToolChoiceMode controls tool selection behavior.

const (
	ToolChoiceAuto     ToolChoiceMode = "auto"
	ToolChoiceNone     ToolChoiceMode = "none"
	ToolChoiceRequired ToolChoiceMode = "required"
	ToolChoiceName     ToolChoiceMode = "name"
)

type ToolRegistry added in v0.0.10

type ToolRegistry struct {
	// contains filtered or unexported fields
}

ToolRegistry stores tools by name for execution.

func NewToolRegistry added in v0.0.10

func NewToolRegistry() *ToolRegistry

func (*ToolRegistry) Get added in v0.0.10

func (r *ToolRegistry) Get(name string) (Tool, bool)

func (*ToolRegistry) Register added in v0.0.10

func (r *ToolRegistry) Register(tool Tool)

type ToolResult added in v0.0.10

type ToolResult struct {
	ID      string
	Name    string
	Content string
}

ToolResult is the output from executing a tool call.

type ToolSpec added in v0.0.10

type ToolSpec struct {
	Name        string
	Description string
	Schema      map[string]interface{}
}

ToolSpec describes a callable tool.

func EditToolSpec added in v0.0.10

func EditToolSpec() ToolSpec

EditToolSpec returns the tool spec for the edit tool.

func ReadURLToolSpec added in v0.0.11

func ReadURLToolSpec() ToolSpec

ReadURLToolSpec returns the tool spec for reading web pages.

func SuggestCommandsToolSpec added in v0.0.10

func SuggestCommandsToolSpec(numSuggestions int) ToolSpec

SuggestCommandsToolSpec returns the tool spec for command suggestions.

func UnifiedDiffToolSpec added in v0.0.10

func UnifiedDiffToolSpec() ToolSpec

UnifiedDiffToolSpec returns the tool spec for unified diff edits.

func WebSearchToolSpec added in v0.0.10

func WebSearchToolSpec() ToolSpec

WebSearchToolSpec returns the tool spec for external web search.

type Usage added in v0.0.10

type Usage struct {
	InputTokens  int
	OutputTokens int
}

Usage captures token usage if available.

type WebSearchTool added in v0.0.10

type WebSearchTool struct {
	// contains filtered or unexported fields
}

WebSearchTool executes searches through a Searcher.

func NewWebSearchTool added in v0.0.10

func NewWebSearchTool(searcher search.Searcher) *WebSearchTool

func (*WebSearchTool) Execute added in v0.0.10

func (t *WebSearchTool) Execute(ctx context.Context, args json.RawMessage) (string, error)

func (*WebSearchTool) Spec added in v0.0.10

func (t *WebSearchTool) Spec() ToolSpec

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL