Documentation
¶
Overview ¶
Package llm provides shared LLM data types for agent-go consumers.
Index ¶
- func BuildAnthropicRequest(req *ChatRequest) map[string]any
- func BuildGeminiRequest(req *ChatRequest) map[string]any
- func BuildOpenAIRequest(req *ChatRequest) (map[string]any, error)
- func BuildOpenAIStreamRequest(req *ChatRequest, tools []OpenAIToolDefinition) (map[string]any, error)
- type AnthropicMessage
- type ChatMessage
- type ChatRequest
- type ChatResponse
- type GeminiContent
- type LLMService
- type ModelInfo
- type OpenAIChatMessage
- type OpenAIChatRequest
- type OpenAIChatResponse
- type OpenAIFunctionDef
- type OpenAIStreamOptions
- type OpenAIToolCallDelta
- type OpenAIToolDefinition
- type StreamEvent
- type ToolCall
- type ToolCallInfo
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAnthropicRequest ¶
func BuildAnthropicRequest(req *ChatRequest) map[string]any
func BuildGeminiRequest ¶
func BuildGeminiRequest(req *ChatRequest) map[string]any
func BuildOpenAIRequest ¶
func BuildOpenAIRequest(req *ChatRequest) (map[string]any, error)
BuildOpenAIRequest 构建 OpenAI 兼容的非流式请求体
func BuildOpenAIStreamRequest ¶
func BuildOpenAIStreamRequest(req *ChatRequest, tools []OpenAIToolDefinition) (map[string]any, error)
BuildOpenAIStreamRequest 构建流式请求体
Types ¶
type AnthropicMessage ¶
type ChatMessage ¶
type ChatMessage struct {
Role, Content, ReasoningContent, ToolCallID string
ToolCalls []ToolCallInfo
}
type ChatRequest ¶
type ChatResponse ¶
func ParseAnthropicResponse ¶
func ParseAnthropicResponse(body []byte) (*ChatResponse, error)
func ParseGeminiResponse ¶
func ParseGeminiResponse(body []byte) (*ChatResponse, error)
func ParseOpenAIResponse ¶
func ParseOpenAIResponse(body []byte) (*ChatResponse, error)
type GeminiContent ¶
type LLMService ¶ added in v0.2.0
type LLMService struct {
// contains filtered or unexported fields
}
LLMService provides multi-provider LLM chat and model listing. It supports OpenAI-compatible, Anthropic, and Gemini providers.
func NewLLMService ¶ added in v0.2.0
func NewLLMService(timeout time.Duration) *LLMService
NewLLMService creates an LLMService with configurable timeout.
func (*LLMService) Chat ¶ added in v0.2.0
func (s *LLMService) Chat(req *ChatRequest) (*ChatResponse, error)
Chat performs a non-streaming chat completion.
func (*LLMService) ChatStream ¶ added in v0.2.0
func (s *LLMService) ChatStream( req *ChatRequest, onContent func(string), onReasoning func(string), onToolCallStart func(string, string), onToolCallDelta func(string, string), onToolCallEnd func(string, string, string), onDone func(), onError func(error), )
ChatStream performs a streaming chat completion with delta callbacks. onContent: called for each content delta. onReasoning: called for each reasoning_content delta. onToolCallStart: called when a tool call begins. onToolCallDelta: called for each tool call arguments delta. onToolCallEnd: called when a tool call completes. onDone: called when the stream completes. onError: called when an error occurs.
func (*LLMService) ListModels ¶ added in v0.2.0
func (s *LLMService) ListModels(baseURL, apiKey string) ([]ModelInfo, error)
ListModels fetches available models from an OpenAI-compatible endpoint.
type OpenAIChatMessage ¶
type OpenAIChatMessage struct {
Role string `json:"role"`
Content string `json:"content"`
ReasoningContent string `json:"reasoning_content,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCalls []ToolCallInfo `json:"tool_calls,omitempty"`
}
type OpenAIChatRequest ¶
type OpenAIChatRequest struct {
Model string `json:"model"`
Messages []OpenAIChatMessage `json:"messages"`
Temperature float64 `json:"temperature,omitempty"`
Stream bool `json:"stream,omitempty"`
StreamOptions *OpenAIStreamOptions `json:"stream_options,omitempty"`
Tools []OpenAIToolDefinition `json:"tools,omitempty"`
}
type OpenAIChatResponse ¶
type OpenAIChatResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []struct {
Index int `json:"index"`
Message struct {
Role string `json:"role"`
Content string `json:"content"`
} `json:"message"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
Usage *Usage `json:"usage,omitempty"`
}
type OpenAIFunctionDef ¶
type OpenAIStreamOptions ¶
type OpenAIStreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
type OpenAIToolCallDelta ¶
type OpenAIToolDefinition ¶
type OpenAIToolDefinition struct {
Type string `json:"type"`
Function OpenAIFunctionDef `json:"function"`
}
type StreamEvent ¶
type StreamEvent string
const ( StreamEventContent StreamEvent = "content" StreamEventReasoning StreamEvent = "reasoning" StreamEventToolCall StreamEvent = "tool_call" StreamEventDone StreamEvent = "done" StreamEventError StreamEvent = "error" )