Documentation
¶
Index ¶
- func ParseSSEResponse(reader io.Reader, responseCh chan<- string) error
- func SetProxy(proxyURL string) error
- type ChatRequest
- type ChatResponse
- type Client
- func (c *Client) Chat(ctx context.Context, messages []Message) (string, error)
- func (c *Client) ChatStream(ctx context.Context, messages []Message) (<-chan string, error)
- func (c *Client) ChatWithMCPTools(ctx context.Context, userMessage string) (<-chan string, error)
- func (c *Client) ChatWithToolsAndStream(ctx context.Context, userMessage string) (<-chan string, error)
- func (c *Client) ChatWithToolsAndStreamMessages(ctx context.Context, historyMessages []Message) (<-chan string, error)
- type Config
- type Function
- type LLMResponse
- type MCPServer
- type Message
- type OpenAIClient
- func (c *OpenAIClient) Chat(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
- func (c *OpenAIClient) ChatStream(ctx context.Context, req *ChatRequest) (<-chan string, <-chan error, error)
- func (c *OpenAIClient) ChatWithTools(ctx context.Context, messages []Message, tools []Tool) (*ChatResponse, error)
- type StreamResult
- type Tool
- type ToolCall
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSSEResponse ¶
ParseSSEResponse 解析 SSE 响应流
Types ¶
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Stream bool `json:"stream"`
Temperature float64 `json:"temperature,omitempty"`
Tools []Tool `json:"tools,omitempty"`
}
ChatRequest 聊天请求
type ChatResponse ¶
type ChatResponse 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"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
} `json:"message"`
Delta struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
} `json:"delta"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
}
ChatResponse 聊天响应
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client LLM 客户端
func (*Client) ChatStream ¶
ChatStream 与 LLM 流式对话
func (*Client) ChatWithMCPTools ¶
ChatWithMCPTools 使用 MCP 工具与 LLM 对话
type Config ¶
type Config struct {
Model string `mapstructure:"model"`
APIKey string `mapstructure:"api_key"`
BaseURL string `mapstructure:"base_url"`
}
Config LLM 配置
type Function ¶
type Function struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]any `json:"parameters"`
}
Function 函数定义
type LLMResponse ¶
LLMResponse LLM 响应结构
type MCPServer ¶
type MCPServer interface {
ListTools(ctx context.Context) (*mcp.ListToolsResult, error)
ListEnabledTools(ctx context.Context) (*mcp.ListToolsResult, error)
CallTool(ctx context.Context, name string, arguments map[string]any) (*mcp.CallToolResult, error)
}
MCPServer MCP服务器接口(避免循环导入)
type Message ¶
type Message struct {
Role string `json:"role"`
Content any `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // 用于 assistant 角色的工具调用
ToolCallID string `json:"tool_call_id,omitempty"` // 用于 tool 角色的响应
Name string `json:"name,omitempty"` // 用于 tool 角色的函数名
}
Message 消息结构
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
OpenAIClient OpenAI 兼容的客户端
func NewOpenAIClient ¶
func NewOpenAIClient(config *Config) *OpenAIClient
NewOpenAIClient 创建新的 OpenAI 客户端
func (*OpenAIClient) Chat ¶
func (c *OpenAIClient) Chat(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
Chat 普通对话(非流式)
func (*OpenAIClient) ChatStream ¶
func (c *OpenAIClient) ChatStream(ctx context.Context, req *ChatRequest) (<-chan string, <-chan error, error)
ChatStream 流式对话
func (*OpenAIClient) ChatWithTools ¶
func (c *OpenAIClient) ChatWithTools(ctx context.Context, messages []Message, tools []Tool) (*ChatResponse, error)
ChatWithTools 支持工具调用的对话(非流式)
type StreamResult ¶
StreamResult 流式响应的累积结果
Click to show internal directories.
Click to hide internal directories.