llm

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindClaudeCodeCLIPath added in v0.5.5

func FindClaudeCodeCLIPath() (string, error)

Types

type AnthropicClient

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

func NewAnthropicClient

func NewAnthropicClient(baseURL, apiKey, model string, maxTokens int) (*AnthropicClient, error)

func (*AnthropicClient) Ask

func (c *AnthropicClient) Ask(ctx context.Context, prompt string) (string, error)

func (*AnthropicClient) Chat

func (c *AnthropicClient) Chat(ctx context.Context, messages []ChatMessage, opts ChatOptions) (ChatResponse, error)

type ChatMessage

type ChatMessage struct {
	Role          string         `json:"role"` // system, user, assistant, tool
	Content       string         `json:"content"`
	ContentBlocks []ContentBlock `json:"content_blocks,omitempty"` // multimodal content (takes priority over Content when non-empty)
	ToolCalls     []ToolCall     `json:"tool_calls,omitempty"`
	ToolCallID    string         `json:"tool_call_id,omitempty"`
}

type ChatOptions

type ChatOptions struct {
	OnDelta func(text string) // SSE streaming callback (nil = no streaming)
	Tools   []ToolSchema
	// ToolChoice follows OpenAI-compatible values like "auto", "none", "required".
	ToolChoice string
	// ReasoningEffort is a provider-agnostic hint. Supported values are
	// none, minimal, low, medium, high.
	ReasoningEffort string
	// ThinkingBudget enables provider-native thinking when budgeted tokens are supported.
	ThinkingBudget int
	// ServiceTier controls provider-side latency tier when supported.
	ServiceTier string
}

type ChatResponse

type ChatResponse struct {
	Message    ChatMessage
	Usage      Usage
	StopReason string
}

type ClaudeCodeCLIClient added in v0.5.5

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

func NewClaudeCodeCLIClient added in v0.5.5

func NewClaudeCodeCLIClient(workDir, model string) (*ClaudeCodeCLIClient, error)

func (*ClaudeCodeCLIClient) Ask added in v0.5.5

func (c *ClaudeCodeCLIClient) Ask(ctx context.Context, prompt string) (string, error)

func (*ClaudeCodeCLIClient) Chat added in v0.5.5

func (c *ClaudeCodeCLIClient) Chat(ctx context.Context, messages []ChatMessage, opts ChatOptions) (ChatResponse, error)

type Client

type Client interface {
	Ask(ctx context.Context, prompt string) (string, error)
	Chat(ctx context.Context, messages []ChatMessage, opts ChatOptions) (ChatResponse, error)
}

func NewProvider

func NewProvider(opts ProviderOptions) (Client, error)

type ClientConfig

type ClientConfig struct {
	HTTPTimeout     time.Duration
	MaxTokens       int
	ReasoningEffort string
	ThinkingBudget  int
	ServiceTier     string
}

func DefaultClientConfig

func DefaultClientConfig() ClientConfig

type ContentBlock added in v0.14.0

type ContentBlock struct {
	Type      string `json:"type"`                 // "text", "image", "document"
	Text      string `json:"text,omitempty"`       // for type=text
	MediaType string `json:"media_type,omitempty"` // e.g. "image/png", "application/pdf"
	Data      string `json:"data,omitempty"`       // base64-encoded binary
}

ContentBlock represents a single block in a multimodal message. Type is "text", "image", or "document".

type GeminiNativeClient

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

func NewGeminiNativeClient

func NewGeminiNativeClient(baseURL, apiKey, model string) (*GeminiNativeClient, error)

func (*GeminiNativeClient) Ask

func (c *GeminiNativeClient) Ask(ctx context.Context, prompt string) (string, error)

func (*GeminiNativeClient) Chat

func (c *GeminiNativeClient) Chat(ctx context.Context, messages []ChatMessage, opts ChatOptions) (ChatResponse, error)

type ModelFetcher

type ModelFetcher interface {
	FetchModels(ctx context.Context, opts ProviderOptions) ([]string, error)
}

ModelFetcher resolves provider model ids via provider-specific live APIs.

func NewModelFetcher

func NewModelFetcher() ModelFetcher

type OpenAICodexClient

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

func NewOpenAICodexClient

func NewOpenAICodexClient(baseURL, model, authMode, oauthProvider, apiKey string) (*OpenAICodexClient, error)

func (*OpenAICodexClient) Ask

func (c *OpenAICodexClient) Ask(ctx context.Context, prompt string) (string, error)

func (*OpenAICodexClient) Chat

func (c *OpenAICodexClient) Chat(ctx context.Context, messages []ChatMessage, opts ChatOptions) (ChatResponse, error)

type OpenAICompatibleClient

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

OpenAICompatibleClient works with any OpenAI-compatible /chat/completions API (OpenAI, Azure OpenAI, etc.).

func NewGeminiClient

func NewGeminiClient(baseURL, apiKey, model string) (*OpenAICompatibleClient, error)

func NewOpenAIClient

func NewOpenAIClient(baseURL, apiKey, model string) (*OpenAICompatibleClient, error)

func (*OpenAICompatibleClient) Ask

func (c *OpenAICompatibleClient) Ask(ctx context.Context, prompt string) (string, error)

func (*OpenAICompatibleClient) Chat

type ProviderError

type ProviderError struct {
	Provider   string
	Operation  string
	StatusCode int
	Message    string
	Cause      error
}

ProviderError is a structured error for LLM provider failures.

func (*ProviderError) Error

func (e *ProviderError) Error() string

func (*ProviderError) Unwrap

func (e *ProviderError) Unwrap() error

type ProviderOptions

type ProviderOptions struct {
	Provider        string
	AuthMode        string
	OAuthProvider   string
	AuthConfig      auth.ProviderAuthConfig
	BaseURL         string
	WorkDir         string
	Model           string
	APIKey          string
	MaxTokens       int
	ReasoningEffort string
	ThinkingBudget  int
	ServiceTier     string
}

type ToolCall

type ToolCall struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
	// ThoughtSignature is provider-specific metadata used by Gemini Native
	// to preserve tool-calling context across turns.
	ThoughtSignature string `json:"thought_signature,omitempty"`
}

type ToolFunctionSchema

type ToolFunctionSchema struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters,omitempty"`
}

type ToolSchema

type ToolSchema struct {
	Type     string             `json:"type"`
	Function ToolFunctionSchema `json:"function"`
}

type Usage

type Usage struct {
	InputTokens      int `json:"input_tokens"`
	OutputTokens     int `json:"output_tokens"`
	CachedTokens     int `json:"cached_tokens,omitempty"`
	CacheReadTokens  int `json:"cache_read_tokens,omitempty"`
	CacheWriteTokens int `json:"cache_write_tokens,omitempty"`
}

Jump to

Keyboard shortcuts

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