Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIMessage ¶
type APIMessage struct {
Role string `json:"role"`
Content any `json:"content"` // string 或 []schema.ContentPart
ReasoningContent string `json:"reasoning_content,omitempty"`
Name string `json:"name,omitempty"`
ToolCalls []schema.ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
}
APIMessage 发送给 OpenAI 的消息格式
type ChatModel ¶
type ChatModel struct {
// contains filtered or unexported fields
}
ChatModel OpenAI 兼容聊天模型(实现 chatmodel.BaseModel)
func NewChatModel ¶
func NewChatModel(config *ChatModelConfig) (*ChatModel, error)
NewChatModel 创建 OpenAI 兼容聊天模型
func (*ChatModel) GetModelName ¶
type ChatModelConfig ¶
type ChatModelConfig struct {
BaseURL string
APIKey string
Model string
MaxCompletionTokens uint64 `json:"max_completion_tokens,omitempty"`
ResponseFormat ResponseFormatType `json:"response_format,omitempty"`
Stop string `json:"stop,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
N uint8 `json:"n,omitempty"`
PresencePenalty float64 `json:"presence_penalty,omitempty"`
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
Tools []schema.Tool `json:"-"`
Thinking Thinking `json:"thinking,omitempty"`
PromptCacheKey string `json:"prompt_cache_key,omitempty"`
SafetyIdentifier string `json:"safety_identifier,omitempty"`
Debug bool // 启用请求日志(输出到 stderr)
TimeOut time.Duration
HTTPClient *http.Client `json:"-"`
}
ChatModelConfig OpenAI 兼容 API 配置
type ChatModelResponse ¶
type ChatModelResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []Choice `json:"choices"`
Usage schema.Usage `json:"usage"`
}
ChatModelResponse OpenAI 非流式响应
type Choice ¶
type Choice struct {
Index int `json:"index"`
Message schema.Message `json:"message"`
FinishReason string `json:"finish_reason"`
}
Choice 响应选项
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client OpenAI 兼容 HTTP 客户端
type Delta ¶
type Delta struct {
Role string `json:"role,omitempty"`
Content string `json:"content"`
ReasoningContent string `json:"reasoning_content,omitempty"`
ToolCalls []schema.ToolCall `json:"tool_calls,omitempty"`
}
Delta 流式增量
type RequestBody ¶
type RequestBody struct {
Model string `json:"model"`
Messages []APIMessage `json:"messages"`
MaxCompletionTokens uint64 `json:"max_completion_tokens,omitempty"`
ResponseFormat ResponseFormatType `json:"response_format,omitempty"`
Stream bool `json:"stream,omitempty"`
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
Tools []Tool `json:"tools,omitempty"`
PromptCacheKey string `json:"prompt_cache_key,omitempty"`
SafetyIdentifier string `json:"safety_identifier,omitempty"`
Thinking Thinking `json:"thinking,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
N uint8 `json:"n,omitempty"`
PresencePenalty float64 `json:"presence_penalty,omitempty"`
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
}
RequestBody OpenAI API 请求体
type ResponseFormatType ¶
type ResponseFormatType string
ResponseFormatType 响应格式类型
const ( Text ResponseFormatType = "text" JsonObject ResponseFormatType = "json_object" )
type StreamChoice ¶
type StreamChoice struct {
Index int `json:"index"`
Delta Delta `json:"delta"`
FinishReason string `json:"finish_reason"`
}
StreamChoice 流式选项
type StreamOptions ¶
type StreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
StreamOptions 流式响应选项
type StreamResponse ¶
type StreamResponse struct {
Choices []StreamChoice `json:"choices"`
Usage *schema.Usage `json:"usage,omitempty"`
}
StreamResponse 流式响应
type Thinking ¶
type Thinking struct {
Type ThinkingType `json:"type,omitempty"`
Keep ThinkingKeepEnum `json:"keep,omitempty"`
}
Thinking 思考能力配置
type ThinkingKeepEnum ¶
type ThinkingKeepEnum string
ThinkingKeepEnum 历史思考内容保留策略
const ( Null ThinkingKeepEnum = "null" All ThinkingKeepEnum = "all" )
type ThinkingType ¶
type ThinkingType string
ThinkingType 思考能力开关
const ( Enabled ThinkingType = "enabled" Disabled ThinkingType = "disabled" )
Click to show internal directories.
Click to hide internal directories.