Documentation
¶
Overview ¶
Package structs 定义请求相关的数据结构
包含 OpenAI 兼容的请求/响应结构体与相关类型定义
Index ¶
- Constants
- type APIError
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionStream
- type ChatCompletionStreamOptions
- type ChatCompletionThinkingType
- type Choice
- type Embedding
- type EmbeddingRequest
- type EmbeddingResponse
- type ErrorResponse
- type Message
- type StreamChoice
- type StreamDelta
- type Usage
Constants ¶
View Source
const ( RoleUser = "user" RoleAssistant = "assistant" RoleSystem = "system" )
消息角色常量
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Message string `json:"message"`
Type string `json:"type"`
Param any `json:"param,omitempty"`
Code string `json:"code,omitempty"`
}
APIError API 错误信息
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
User string `json:"user,omitempty"`
Stream bool `json:"stream"`
StreamOptions *ChatCompletionStreamOptions `json:"stream_options,omitempty"`
Thinking *ChatCompletionThinkingType `json:"thinking,omitempty"` // enabled | disabled
ReasoningEffort *string `json:"reasoning_effort,omitempty"` // low | medium | high | max | xhigh
}
ChatCompletionRequest OpenAI ChatCompletion 请求结构体
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []Choice `json:"choices"`
Usage *Usage `json:"usage,omitempty"`
}
ChatCompletionResponse OpenAI ChatCompletion 响应结构体
type ChatCompletionStream ¶
type ChatCompletionStream struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []StreamChoice `json:"choices"`
Usage *Usage `json:"usage,omitempty"`
}
ChatCompletionStream 流式响应块
type ChatCompletionStreamOptions ¶
type ChatCompletionStreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
ChatCompletionStreamOptions 流式响应选项
type ChatCompletionThinkingType ¶
type ChatCompletionThinkingType struct {
Type string `json:"type"`
}
ChatCompletionThinkingType 设置thinking类型
type Choice ¶
type Choice struct {
Index int `json:"index"`
Delta Message `json:"delta"`
FinishReason string `json:"finish_reason"`
}
Choice 选择项
type Embedding ¶
type Embedding struct {
Object string `json:"object"`
Embedding []float32 `json:"embedding"`
Index int `json:"index"`
}
Embedding 单个嵌入
type EmbeddingRequest ¶
type EmbeddingRequest struct {
Input []string `json:"input"` // 字符串数组
Model string `json:"model"`
EncodingFormat string `json:"encoding_format,omitempty"` // float, base64
User string `json:"user,omitempty"`
}
EmbeddingRequest 嵌入请求
type EmbeddingResponse ¶
type EmbeddingResponse struct {
Object string `json:"object"`
Data []Embedding `json:"data"`
Model string `json:"model"`
Usage Usage `json:"usage"`
}
EmbeddingResponse 嵌入响应
type ErrorResponse ¶
type ErrorResponse struct {
Error APIError `json:"error"`
}
ErrorResponse API 错误响应
type Message ¶
type Message struct {
Role string `json:"role"` // RoleUser | RoleAssistant | RoleSystem
Content string `json:"content"`
ReasoningContent *string `json:"reasoning_content,omitempty"`
}
Message 消息结构体
type StreamChoice ¶
type StreamChoice struct {
Index int `json:"index"`
Delta StreamDelta `json:"delta"`
FinishReason *string `json:"finish_reason"`
}
StreamChoice 流式选择项
type StreamDelta ¶
type StreamDelta struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
}
StreamDelta 流式增量消息
Click to show internal directories.
Click to hide internal directories.