Documentation
¶
Index ¶
- func AuthMiddleware(requiredKey string) gin.HandlerFunc
- func CORSMiddleware() gin.HandlerFunc
- func ChatCompletionHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ClaudeCountTokensHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ClaudeListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ClaudeMessagesHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ConfigureSessionTTL(ttl time.Duration)
- func GeminiListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func GeminiRouterHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ImageEditHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ImageGenerationHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func LoggerMiddleware() gin.HandlerFunc
- func ResponsesHandler(pool *balancer.AccountPool) gin.HandlerFunc
- type CandidateOutput
- type ChatMessage
- type ChatRequest
- type ChatStreamOptions
- type CodeOutput
- type EventAccumulator
- type GeminiCodeExecutionResult
- type GeminiContent
- type GeminiExecutableCode
- type GeminiFileData
- type GeminiFunctionCall
- type GeminiFunctionResponse
- type GeminiGenerateContentRequest
- type GeminiInlineData
- type GeminiPart
- type ImageGenerationRequest
- type OpenAITool
- type OpenAIToolCall
- type ResponsesRequest
- type ResponsesTool
- type ToolBridge
- type ToolCall
- type ToolDefinition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(requiredKey string) gin.HandlerFunc
AuthMiddleware 校验服务公开 API key
func ChatCompletionHandler ¶
func ChatCompletionHandler(pool *balancer.AccountPool) gin.HandlerFunc
ChatCompletionHandler 处理 OpenAI Chat Completions
func ClaudeCountTokensHandler ¶
func ClaudeCountTokensHandler(pool *balancer.AccountPool) gin.HandlerFunc
ClaudeCountTokensHandler 处理 Anthropic 输入 token 计数
func ClaudeListModelsHandler ¶
func ClaudeListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
ClaudeListModelsHandler 返回 Anthropic 模型目录
func ClaudeMessagesHandler ¶
func ClaudeMessagesHandler(pool *balancer.AccountPool) gin.HandlerFunc
ClaudeMessagesHandler 处理 Anthropic Messages
func ConfigureSessionTTL ¶
ConfigureSessionTTL 设置显式会话状态的有效期
func GeminiListModelsHandler ¶
func GeminiListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
GeminiListModelsHandler 返回 Gemini 原生模型目录
func GeminiRouterHandler ¶
func GeminiRouterHandler(pool *balancer.AccountPool) gin.HandlerFunc
GeminiRouterHandler 处理 Gemini 原生生成接口
func ImageEditHandler ¶
func ImageEditHandler(pool *balancer.AccountPool) gin.HandlerFunc
ImageEditHandler 处理 OpenAI 图片编辑
func ImageGenerationHandler ¶
func ImageGenerationHandler(pool *balancer.AccountPool) gin.HandlerFunc
ImageGenerationHandler 处理 OpenAI 图片生成
func ListModelsHandler ¶
func ListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
ListModelsHandler 返回 OpenAI 模型目录
func ResponsesHandler ¶
func ResponsesHandler(pool *balancer.AccountPool) gin.HandlerFunc
ResponsesHandler 处理 OpenAI Responses API
Types ¶
type CandidateOutput ¶
type CandidateOutput struct {
Text string
Thought string
Codes []CodeOutput
Citations []gemini.Citation
Media []gemini.Media
}
CandidateOutput 保存单个候选项的权威累计输出
type ChatMessage ¶
type ChatMessage struct {
Role string `json:"role"`
Content json.RawMessage `json:"content"`
Name string `json:"name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCalls []OpenAIToolCall `json:"tool_calls,omitempty"`
ReasoningContent json.RawMessage `json:"reasoning_content,omitempty"`
TranscriptReasoning json.RawMessage `json:"-"`
TranscriptItems []json.RawMessage `json:"-"`
}
ChatMessage 表示 OpenAI Chat 消息
type ChatRequest ¶
type ChatRequest struct {
Messages []ChatMessage `json:"messages"`
Stream bool `json:"stream"`
StreamOptions *ChatStreamOptions `json:"stream_options,omitempty"`
Model string `json:"model"`
Tools []OpenAITool `json:"tools,omitempty"`
ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
ResponseFormat json.RawMessage `json:"response_format,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
Reasoning json.RawMessage `json:"reasoning,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
PreviousResponseID string `json:"previous_response_id,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
MaxCompletionTokens *int `json:"max_completion_tokens,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Stop json.RawMessage `json:"stop,omitempty"`
PresencePenalty *float64 `json:"presence_penalty,omitempty"`
FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
Seed *int `json:"seed,omitempty"`
N *int `json:"n,omitempty"`
}
ChatRequest 表示 OpenAI Chat 请求
type ChatStreamOptions ¶
type ChatStreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
ChatStreamOptions 表示 OpenAI Chat 流选项
type CodeOutput ¶
type CodeOutput struct {
Index int
Type gemini.CodeEventType
Language string
Offset int
Complete bool
Content string
Order int
}
CodeOutput 保存一段 Google 已执行代码的权威快照
type EventAccumulator ¶
type EventAccumulator struct {
Candidates map[int]*CandidateOutput
Session gemini.ConversationSnapshot
Metadata *gemini.EventMetadataData
Usage *gemini.Usage
FinishReason gemini.FinishReason
}
EventAccumulator 将规范事件还原为最终响应
func NewEventAccumulator ¶
func NewEventAccumulator() *EventAccumulator
NewEventAccumulator 创建规范事件累加器
func (*EventAccumulator) Apply ¶
func (a *EventAccumulator) Apply(event gemini.Event) error
Apply 应用一个规范事件
func (*EventAccumulator) Primary ¶
func (a *EventAccumulator) Primary() CandidateOutput
Primary 返回首个候选项
type GeminiCodeExecutionResult ¶
type GeminiCodeExecutionResult struct {
ID string `json:"id,omitempty"`
Outcome string `json:"outcome"`
Output string `json:"output"`
}
GeminiCodeExecutionResult 表示 Gemini 代码执行结果
type GeminiContent ¶
type GeminiContent struct {
Role string `json:"role,omitempty"`
Parts []GeminiPart `json:"parts"`
}
GeminiContent 表示 Gemini 消息
type GeminiExecutableCode ¶
type GeminiExecutableCode struct {
ID string `json:"id,omitempty"`
Language string `json:"language"`
Code string `json:"code"`
}
GeminiExecutableCode 表示 Gemini 已执行代码
type GeminiFileData ¶
GeminiFileData 表示 Gemini 远程文件
type GeminiFunctionCall ¶
type GeminiFunctionCall struct {
Name string `json:"name"`
ID string `json:"id,omitempty"`
Args map[string]interface{} `json:"args"`
}
GeminiFunctionCall 表示 Gemini 函数调用
type GeminiFunctionResponse ¶
type GeminiFunctionResponse struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Response map[string]interface{} `json:"response"`
}
GeminiFunctionResponse 表示 Gemini 函数结果
type GeminiGenerateContentRequest ¶
type GeminiGenerateContentRequest struct {
Contents []GeminiContent `json:"contents"`
SystemInstruction *GeminiContent `json:"systemInstruction,omitempty"`
GenerationConfig json.RawMessage `json:"generationConfig,omitempty"`
Tools json.RawMessage `json:"tools,omitempty"`
ToolConfig json.RawMessage `json:"toolConfig,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
PreviousResponseID string `json:"previous_response_id,omitempty"`
}
GeminiGenerateContentRequest 表示 Gemini 生成请求
type GeminiInlineData ¶
GeminiInlineData 表示 Gemini 内联文件
type GeminiPart ¶
type GeminiPart struct {
Text string `json:"text,omitempty"`
Thought bool `json:"thought,omitempty"`
ThoughtSignature string `json:"thoughtSignature,omitempty"`
InlineData *GeminiInlineData `json:"inlineData,omitempty"`
FileData *GeminiFileData `json:"fileData,omitempty"`
FunctionCall *GeminiFunctionCall `json:"functionCall,omitempty"`
FunctionResponse *GeminiFunctionResponse `json:"functionResponse,omitempty"`
ExecutableCode *GeminiExecutableCode `json:"executableCode,omitempty"`
CodeResult *GeminiCodeExecutionResult `json:"codeExecutionResult,omitempty"`
}
GeminiPart 表示 Gemini 内容段
type ImageGenerationRequest ¶
type ImageGenerationRequest struct {
Prompt string `json:"prompt"`
Model string `json:"model,omitempty"`
N int `json:"n,omitempty"`
Size string `json:"size,omitempty"`
ResponseFormat string `json:"response_format,omitempty"`
Quality string `json:"quality,omitempty"`
Style string `json:"style,omitempty"`
Stream bool `json:"stream,omitempty"`
PartialImages *int `json:"partial_images,omitempty"`
OutputFormat string `json:"output_format,omitempty"`
OutputCompression *int `json:"output_compression,omitempty"`
Background string `json:"background,omitempty"`
User string `json:"user,omitempty"`
InputFidelity string `json:"input_fidelity,omitempty"`
Moderation string `json:"moderation,omitempty"`
}
ImageGenerationRequest 表示 OpenAI 图片生成请求
type OpenAITool ¶
type OpenAITool struct {
Type string `json:"type"`
Function struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters"`
} `json:"function"`
}
OpenAITool 表示 OpenAI 函数定义
type OpenAIToolCall ¶
type OpenAIToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
}
OpenAIToolCall 表示 OpenAI 函数调用
type ResponsesRequest ¶
type ResponsesRequest struct {
Model string `json:"model"`
Input json.RawMessage `json:"input"`
Instructions string `json:"instructions,omitempty"`
Stream bool `json:"stream"`
Tools []ResponsesTool `json:"tools,omitempty"`
ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
Text json.RawMessage `json:"text,omitempty"`
Conversation json.RawMessage `json:"conversation,omitempty"`
PreviousResponseID string `json:"previous_response_id,omitempty"`
MaxOutputTokens *int `json:"max_output_tokens,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Reasoning json.RawMessage `json:"reasoning,omitempty"`
Truncation string `json:"truncation,omitempty"`
ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"`
}
ResponsesRequest 表示 OpenAI Responses 请求
type ResponsesTool ¶
type ResponsesTool struct {
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters"`
Action string `json:"action,omitempty"`
Background string `json:"background,omitempty"`
InputFidelity string `json:"input_fidelity,omitempty"`
InputImageMask json.RawMessage `json:"input_image_mask,omitempty"`
ImageModel string `json:"model,omitempty"`
Moderation string `json:"moderation,omitempty"`
OutputCompression *int `json:"output_compression,omitempty"`
OutputFormat string `json:"output_format,omitempty"`
PartialImages *int `json:"partial_images,omitempty"`
Quality string `json:"quality,omitempty"`
Size string `json:"size,omitempty"`
}
ResponsesTool 表示 Responses API 函数工具
type ToolBridge ¶
type ToolBridge struct {
Definitions []ToolDefinition
Choice string
JSONSchema json.RawMessage
CodeExecution bool
WebSearch bool
ImageGeneration bool
RequireCodeExecution bool
RequireWebSearch bool
RequireImageGeneration bool
}
ToolBridge 将函数工具和结构化输出转换为严格文本契约
func (ToolBridge) Parse ¶
func (b ToolBridge) Parse(text string) (string, []ToolCall, error)
Parse 解析严格工具调用并验证结构化输出
func (ToolBridge) PromptSuffix ¶
func (b ToolBridge) PromptSuffix() (string, error)
PromptSuffix 返回追加到用户提示词的协议约束
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments"`
}
ToolCall 描述模型选择执行的函数工具
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters"`
}
ToolDefinition 描述公开协议中的函数工具