Documentation
¶
Overview ¶
Package llm provides an OpenAI-compatible HTTP client using only stdlib.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallParams ¶
type CallParams struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Tools []ToolDef `json:"tools,omitempty"`
Stream bool `json:"stream"`
Thinking *ThinkingConfig `json:"thinking,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
}
CallParams is the request body for /chat/completions.
type CallResult ¶
type CallResult struct {
Content string // assistant text
ToolCalls []ToolCall // tool calls requested by the model
InputTokens int // prompt_tokens from API usage (0 = not reported)
OutputTokens int // completion_tokens from API usage (0 = not reported)
}
CallResult is the parsed response from /chat/completions.
type Client ¶
type Client struct {
BaseURL string
APIKey string
Model string
Thinking string // "enabled", "disabled", "low", "medium", "high", or empty
// contains filtered or unexported fields
}
Client sends chat completion requests to any OpenAI-compatible endpoint.
func New ¶
New creates a Client with the given timeout. Pass 0 to use the default (120s). The timeout applies per HTTP request — the agent loop may have multiple requests; set a generous timeout for deep-reasoning models.
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, messages []Message, tools []ToolDef) (*CallResult, error)
Call sends a chat completion request and returns the result.
func (*Client) SimpleCall ¶
SimpleCall sends a single-turn chat completion request and returns the text response. No tools, no streaming, no thinking config. Used for lightweight LLM calls like skill risk assessment.
type FunctionDef ¶
type FunctionDef struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters any `json:"parameters"`
}
FunctionDef defines a single tool's function signature.
type Message ¶
type Message struct {
Role string `json:"role"` // "system", "user", "assistant", "tool"
Content string `json:"content"` // text content
Name string `json:"name,omitempty"` // tool name (for tool role)
ToolCallID string `json:"tool_call_id,omitempty"` // required for tool role
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // required for assistant role with tool calls
}
Message represents a chat message.
type ThinkingConfig ¶
type ThinkingConfig struct {
Type string `json:"type"` // "enabled" or "disabled"
}
ThinkingConfig controls Deepseek's extended thinking feature.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"` // always "function"
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
}
ToolCall represents a single tool invocation requested by the model. Matches the OpenAI API format exactly.
type ToolDef ¶
type ToolDef struct {
Type string `json:"type"`
Function FunctionDef `json:"function"`
}
ToolDef is the JSON Schema definition of a tool.