llm

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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"`
	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 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 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 (Bifrost, OpenAI, Azure OpenAI, etc.).

func NewBifrostClient

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

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
	BaseURL         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