Documentation
¶
Index ¶
- func AuthMiddleware(apiKey func() string) gin.HandlerFunc
- func CORSMiddleware() gin.HandlerFunc
- func ChatCompletionHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ClaudeCountTokensHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ClaudeMessagesHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func CompletionHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ConfigureSessionTTL(ttl time.Duration)
- func FileContentHandler(store *requestdb.Store) gin.HandlerFunc
- func FileDeleteHandler(store *requestdb.Store) gin.HandlerFunc
- func FileListHandler(store *requestdb.Store) gin.HandlerFunc
- func FileRetrieveHandler(store *requestdb.Store) gin.HandlerFunc
- func FileUploadHandler(store *requestdb.Store) gin.HandlerFunc
- func GeminiFileDeleteHandler(store *requestdb.Store) gin.HandlerFunc
- func GeminiFileGetHandler(store *requestdb.Store) gin.HandlerFunc
- func GeminiFileListHandler(store *requestdb.Store) gin.HandlerFunc
- func GeminiFileUploadHandler(store *requestdb.Store) gin.HandlerFunc
- func GeminiGetModelHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func GeminiListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func GeminiLiveHandler(c *gin.Context)
- func GeminiOperationHandler(store *requestdb.Store) gin.HandlerFunc
- func GeminiRouterHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
- func ImageEditHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ImageGenerationHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func LoopbackHost(host string) bool
- func RequestMiddleware(store *requestdb.Store) gin.HandlerFunc
- func ResponseCancelHandler(store *requestdb.Store) gin.HandlerFunc
- func ResponseDeleteHandler(store *requestdb.Store) gin.HandlerFunc
- func ResponseInputItemsHandler(store *requestdb.Store) gin.HandlerFunc
- func ResponseRetrieveHandler(store *requestdb.Store) gin.HandlerFunc
- func ResponsesCompactHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
- func ResponsesHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
- func ResponsesInputTokensHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func RetrieveModelHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func SetFirstEventHedge(value FirstEventHedge)
- func SpeechHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func TranscriptionHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func TranslationHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func UnavailableOpenAIHandler(protocol string, capability string) gin.HandlerFunc
- func VideoContentHandler(store *requestdb.Store) gin.HandlerFunc
- func VideoCreateHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
- func VideoDeleteHandler(store *requestdb.Store) gin.HandlerFunc
- func VideoExtensionHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
- func VideoListHandler(store *requestdb.Store) gin.HandlerFunc
- func VideoRemixHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
- func VideoRetrieveHandler(store *requestdb.Store) gin.HandlerFunc
- func WriteGeminiNotFound(c *gin.Context)
- func WriteOpenAINotFound(c *gin.Context)
- type CandidateOutput
- type CatalogModel
- type ChatAudioOptions
- type ChatExtraBody
- type ChatMessage
- type ChatRequest
- type ChatStreamOptions
- type ChatThinkingConfig
- type CodeOutput
- type CompletionRequest
- type EventAccumulator
- type FirstEventHedge
- type GeminiCodeExecutionResult
- type GeminiContent
- type GeminiExecutableCode
- type GeminiFileData
- type GeminiFunctionCall
- type GeminiFunctionResponse
- type GeminiGenerateContentRequest
- type GeminiInlineData
- type GeminiPart
- type ImageGenerationRequest
- type OpenAICustomCall
- type OpenAIFunction
- 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(apiKey func() string) gin.HandlerFunc
AuthMiddleware 校验服务公开 API key,apiKey 返回当前生效的密钥,多个 key 以逗号分隔,任一匹配即通过,账号池按匹配的 key 绑定的账号选号;未设密钥时拒绝 null 来源与非本机网页发起的请求,以 IP 地址打开的本服务页面照常访问,断点续传的后续请求凭 upload_id 授权
func CORSMiddleware ¶
func CORSMiddleware() gin.HandlerFunc
CORSMiddleware 允许任意网页跨域调用公开 API,预检回显请求的请求头并暴露全部响应头,管理端 /api 不允许跨域
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 ClaudeMessagesHandler ¶
func ClaudeMessagesHandler(pool *balancer.AccountPool) gin.HandlerFunc
ClaudeMessagesHandler 处理 Anthropic Messages
func CompletionHandler ¶ added in v0.1.3
func CompletionHandler(pool *balancer.AccountPool) gin.HandlerFunc
CompletionHandler 处理 OpenAI /v1/completions:prompt 与 suffix 作为会话发送,每个 prompt 逐个生成 n 个 choice
func ConfigureSessionTTL ¶
ConfigureSessionTTL 设置显式会话状态的有效期
func FileContentHandler ¶ added in v0.1.3
func FileContentHandler(store *requestdb.Store) gin.HandlerFunc
FileContentHandler 返回文件内容
func FileDeleteHandler ¶ added in v0.1.3
func FileDeleteHandler(store *requestdb.Store) gin.HandlerFunc
FileDeleteHandler 删除文件,Anthropic 返回 file_deleted 对象
func FileListHandler ¶ added in v0.1.3
func FileListHandler(store *requestdb.Store) gin.HandlerFunc
FileListHandler 列出文件:OpenAI 按 purpose、order、after、limit 分页,未知的 after 返回空页;Anthropic 见 listAnthropicFiles
func FileRetrieveHandler ¶ added in v0.1.3
func FileRetrieveHandler(store *requestdb.Store) gin.HandlerFunc
FileRetrieveHandler 返回 OpenAI 或 Anthropic 文件元数据
func FileUploadHandler ¶ added in v0.1.3
func FileUploadHandler(store *requestdb.Store) gin.HandlerFunc
FileUploadHandler 处理 OpenAI 与 Anthropic 文件上传,带 anthropic-version 头时返回 Anthropic 文件对象
func GeminiFileDeleteHandler ¶ added in v0.1.3
func GeminiFileDeleteHandler(store *requestdb.Store) gin.HandlerFunc
GeminiFileDeleteHandler 删除 Gemini 文件并返回空对象
func GeminiFileGetHandler ¶ added in v0.1.3
func GeminiFileGetHandler(store *requestdb.Store) gin.HandlerFunc
GeminiFileGetHandler 返回 Gemini 文件资源,files/{name}:download 返回内容
func GeminiFileListHandler ¶ added in v0.1.3
func GeminiFileListHandler(store *requestdb.Store) gin.HandlerFunc
GeminiFileListHandler 按 pageSize 与 pageToken 列出 Gemini 文件
func GeminiFileUploadHandler ¶ added in v0.1.3
func GeminiFileUploadHandler(store *requestdb.Store) gin.HandlerFunc
GeminiFileUploadHandler 处理 /upload/v1beta/files 的断点续传、multipart 与单次媒体上传,创建时删除上次运行遗留的续传临时文件
func GeminiGetModelHandler ¶ added in v0.1.3
func GeminiGetModelHandler(pool *balancer.AccountPool) gin.HandlerFunc
GeminiGetModelHandler 返回单个 Gemini 模型
func GeminiListModelsHandler ¶
func GeminiListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
GeminiListModelsHandler 按 pageSize 与 pageToken 分页返回 Gemini 模型目录,没有任何目录时返回 503
func GeminiLiveHandler ¶ added in v0.1.3
GeminiLiveHandler 处理 Gemini Live API 的 BidiGenerateContent 连接,Gemini Web 没有该能力时返回 404 NOT_FOUND
func GeminiOperationHandler ¶ added in v0.1.3
func GeminiOperationHandler(store *requestdb.Store) gin.HandlerFunc
GeminiOperationHandler 返回 predictLongRunning 的长时操作,路径为 models/{model}/operations/{id} 或 operations/{id}
func GeminiRouterHandler ¶
func GeminiRouterHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
GeminiRouterHandler 处理 Gemini 原生 models/{model}:{method},生成、流式生成、计数与视频长时操作之外的方法返回 404
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 模型目录,带 anthropic-version 头时返回 Anthropic 格式,没有任何目录时返回 503
func LoopbackHost ¶ added in v0.1.3
LoopbackHost 报告 Host 或 Origin 主机名为 localhost 或回环地址
func RequestMiddleware ¶ added in v0.1.3
func RequestMiddleware(store *requestdb.Store) gin.HandlerFunc
RequestMiddleware 为公开 API 请求分配 ID、跟踪生成请求的阶段,结束时输出结果并把生成请求写入账本,首次创建时从账本补入首事件样本
func ResponseCancelHandler ¶ added in v0.1.3
func ResponseCancelHandler(store *requestdb.Store) gin.HandlerFunc
ResponseCancelHandler 取消后台响应:进行中的响应停止生成并标为 cancelled,已结束的响应原样返回
func ResponseDeleteHandler ¶ added in v0.1.3
func ResponseDeleteHandler(store *requestdb.Store) gin.HandlerFunc
ResponseDeleteHandler 删除保存的响应,进行中的后台响应同时停止
func ResponseInputItemsHandler ¶ added in v0.1.3
func ResponseInputItemsHandler(store *requestdb.Store) gin.HandlerFunc
ResponseInputItemsHandler 按 after、before、limit 与 order 分页返回生成该响应时的输入项,未知的游标返回空页
func ResponseRetrieveHandler ¶ added in v0.1.3
func ResponseRetrieveHandler(store *requestdb.Store) gin.HandlerFunc
ResponseRetrieveHandler 返回保存的响应对象;stream=true 时等后台响应结束,再按创建时的流式事件回放,starting_after 之前的事件不输出
func ResponsesCompactHandler ¶ added in v0.1.3
func ResponsesCompactHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
ResponsesCompactHandler 处理 /v1/responses/compact:较早的条目由模型摘要,最近的条目原样保留,返回保留的 user 消息与一个 compaction 项
func ResponsesHandler ¶
func ResponsesHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
ResponsesHandler 处理 OpenAI Responses API,store 不为 false 的响应写入账本库,background 为 true 时立即返回 queued
func ResponsesInputTokensHandler ¶ added in v0.1.3
func ResponsesInputTokensHandler(pool *balancer.AccountPool) gin.HandlerFunc
ResponsesInputTokensHandler 以与生成相同的提示词编码计算 Responses 请求的输入 token,续接时计入会话已有上下文
func RetrieveModelHandler ¶ added in v0.1.3
func RetrieveModelHandler(pool *balancer.AccountPool) gin.HandlerFunc
RetrieveModelHandler 返回单个模型,带 anthropic-version 头时返回 Anthropic 格式
func SetFirstEventHedge ¶ added in v0.1.7
func SetFirstEventHedge(value FirstEventHedge)
SetFirstEventHedge 替换首事件备用请求设置,下一个请求生效
func SpeechHandler ¶ added in v0.1.3
func SpeechHandler(pool *balancer.AccountPool) gin.HandlerFunc
SpeechHandler 处理 OpenAI /v1/audio/speech:以官网回答菜单的 Listen 朗读合成音频,model 选择执行朗读的账号
func TranscriptionHandler ¶ added in v0.1.3
func TranscriptionHandler(pool *balancer.AccountPool) gin.HandlerFunc
TranscriptionHandler 处理 OpenAI /v1/audio/transcriptions
func TranslationHandler ¶ added in v0.1.3
func TranslationHandler(pool *balancer.AccountPool) gin.HandlerFunc
TranslationHandler 处理 OpenAI /v1/audio/translations:把音频中的语音翻译为英文
func UnavailableOpenAIHandler ¶ added in v0.1.3
func UnavailableOpenAIHandler(protocol string, capability string) gin.HandlerFunc
UnavailableOpenAIHandler 处理 Gemini Web 没有对应能力的 OpenAI 端点,按官方模型不可用错误返回 404 model_not_found
func VideoContentHandler ¶ added in v0.1.3
func VideoContentHandler(store *requestdb.Store) gin.HandlerFunc
VideoContentHandler 按 variant 返回已完成视频的 MP4 或缩略图
func VideoCreateHandler ¶ added in v0.1.3
func VideoCreateHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
VideoCreateHandler 处理 OpenAI POST /v1/videos:立即返回 queued 视频对象,由官网 Create video 在后台生成
func VideoDeleteHandler ¶ added in v0.1.3
func VideoDeleteHandler(store *requestdb.Store) gin.HandlerFunc
VideoDeleteHandler 删除视频任务与成品,进行中的生成同时停止
func VideoExtensionHandler ¶ added in v0.1.7
func VideoExtensionHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
VideoExtensionHandler 处理 OpenAI POST /v1/videos/extensions:在源视频的网页会话中续写,成品为拼接后的完整视频
func VideoListHandler ¶ added in v0.1.3
func VideoListHandler(store *requestdb.Store) gin.HandlerFunc
VideoListHandler 按 after、limit 与 order 分页列出 OpenAI 视频对象,未知的 after 返回空页
func VideoRemixHandler ¶ added in v0.1.7
func VideoRemixHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
VideoRemixHandler 处理 OpenAI POST /v1/videos/{id}/remix:在源视频的网页会话中按新提示词生成
func VideoRetrieveHandler ¶ added in v0.1.3
func VideoRetrieveHandler(store *requestdb.Store) gin.HandlerFunc
VideoRetrieveHandler 返回 OpenAI 视频对象
func WriteGeminiNotFound ¶ added in v0.1.3
WriteGeminiNotFound 以 Google 错误体返回未知路由
func WriteOpenAINotFound ¶ added in v0.1.3
WriteOpenAINotFound 以 OpenAI 错误体返回未知路由
Types ¶
type CandidateOutput ¶
type CandidateOutput struct {
Text string
Thought string
Codes []CodeOutput
Citations []gemini.Citation
Media []gemini.Media
}
CandidateOutput 保存单个候选项的权威累计输出
type CatalogModel ¶ added in v0.1.3
type CatalogModel struct {
gemini.Model
MinInputTokenLimit int
MaxInputTokenLimit int
AccountCount int
// Accounts 为提供该模型的已就绪账号
Accounts []string
// AliasOf 为 MODEL_MAPPING 别名指向的模型 ID
AliasOf string
}
CatalogModel 是公开目录中的一个模型及其在账号间的上下文窗口范围
func Catalog ¶ added in v0.1.3
func Catalog(pool *balancer.AccountPool) []CatalogModel
Catalog 返回公开模型目录
type ChatAudioOptions ¶ added in v0.1.3
ChatAudioOptions 表示 OpenAI Chat 的音频输出参数
type ChatExtraBody ¶ added in v0.1.6
type ChatExtraBody struct {
Google struct {
ThinkingConfig *ChatThinkingConfig `json:"thinking_config"`
} `json:"google"`
}
ChatExtraBody 表示 Gemini OpenAI 兼容层的 extra_body 扩展
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"`
FunctionCall *OpenAIFunction `json:"function_call,omitempty"`
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"`
Functions json.RawMessage `json:"functions,omitempty"`
FunctionCall json.RawMessage `json:"function_call,omitempty"`
ResponseFormat json.RawMessage `json:"response_format,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
Reasoning json.RawMessage `json:"reasoning,omitempty"`
IncludeReasoning *bool `json:"include_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"`
WebSearchOptions json.RawMessage `json:"web_search_options,omitempty"`
Audio *ChatAudioOptions `json:"audio,omitempty"`
ExtraBody ChatExtraBody `json:"extra_body,omitempty"`
// contains filtered or unexported fields
}
ChatRequest 表示 OpenAI Chat 请求
type ChatStreamOptions ¶
type ChatStreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
ChatStreamOptions 表示 OpenAI Chat 流选项
type ChatThinkingConfig ¶ added in v0.1.6
type ChatThinkingConfig struct {
ThinkingLevel string `json:"thinking_level"`
ThinkingBudget *int `json:"thinking_budget"`
IncludeThoughts *bool `json:"include_thoughts"`
}
ChatThinkingConfig 表示 extra_body.google.thinking_config
type CodeOutput ¶
type CodeOutput struct {
Index int
Type gemini.CodeEventType
Language string
Offset int
Complete bool
Content string
Order int
}
CodeOutput 保存一段 Google 已执行代码的权威快照
type CompletionRequest ¶ added in v0.1.3
type CompletionRequest struct {
Model string `json:"model"`
Prompt json.RawMessage `json:"prompt"`
Suffix string `json:"suffix"`
Stream bool `json:"stream"`
StreamOptions *ChatStreamOptions `json:"stream_options"`
Echo bool `json:"echo"`
N *int `json:"n"`
BestOf *int `json:"best_of"`
MaxTokens *int `json:"max_tokens"`
Temperature *float64 `json:"temperature"`
TopP *float64 `json:"top_p"`
Stop json.RawMessage `json:"stop"`
PresencePenalty *float64 `json:"presence_penalty"`
FrequencyPenalty *float64 `json:"frequency_penalty"`
Logprobs *int `json:"logprobs"`
LogitBias json.RawMessage `json:"logit_bias"`
Seed *int `json:"seed"`
}
CompletionRequest 表示 OpenAI 旧版 Completions 请求
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 FirstEventHedge ¶ added in v0.1.7
FirstEventHedge 是首事件备用请求设置:Auto 按各模型近 24 小时原请求首事件等待的 p95 发起,否则 After 大于 0 时为固定等待阈值、为 0 时关闭;Models 为发起备用请求的模型 ID
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"`
Parts []GeminiPart `json:"parts,omitempty"`
}
GeminiFunctionResponse 表示 Gemini 函数结果,parts 为结果中的图片与文件
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:"conversationId,omitempty"`
PreviousResponseID string `json:"previousResponseId,omitempty"`
// GenerateContentRequest 为 countTokens 请求包装的完整生成请求
GenerateContentRequest *GeminiGenerateContentRequest `json:"generateContentRequest,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 OpenAICustomCall ¶ added in v0.1.6
OpenAICustomCall 表示 custom 工具调用的名称与原始输入
type OpenAIFunction ¶ added in v0.1.6
OpenAIFunction 表示函数调用的名称与参数,也是旧式 function_call 的结构
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"`
Custom struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Format json.RawMessage `json:"format,omitempty"`
} `json:"custom"`
}
OpenAITool 表示 OpenAI 函数定义
type OpenAIToolCall ¶
type OpenAIToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function OpenAIFunction `json:"function"`
Custom *OpenAICustomCall `json:"custom,omitempty"`
}
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"`
Store *bool `json:"store,omitempty"`
Background bool `json:"background,omitempty"`
Metadata json.RawMessage `json:"metadata,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"`
Format json.RawMessage `json:"format,omitempty"`
Tools []ResponsesTool `json:"tools,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
// AspectRatio 为生图请求的宽高比
AspectRatio string
// Enum 为 text/x.enum 响应可选的取值
Enum []string
// LegacyFunctions 表示工具来自 Chat 旧式 functions,调用以 function_call 返回
LegacyFunctions bool
// Declared 表示工具定义与 JSON Schema 已在本网页会话的前几轮发送,提示词只重申规则
Declared bool
// SchemaUnchecked 表示结构化输出不按 JSON Schema 校验,OpenAI json_schema 的 strict 为 false 或缺省时为 true
SchemaUnchecked bool
// Stop 是请求的停止序列,正文在首个命中处截断
Stop []string
}
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"`
Namespace string `json:"-"`
// Kind 为 Responses 客户端工具类型:custom、local_shell、shell、apply_patch,普通函数为空
Kind string `json:"-"`
}
ToolDefinition 描述公开协议中的函数工具
Source Files
¶
- audio.go
- audio_codec.go
- audio_diarize.go
- claude_handler.go
- claude_tools.go
- completions.go
- conversation.go
- errors.go
- events.go
- files.go
- gemini_format.go
- gemini_handler.go
- hedge.go
- history.go
- image_handler.go
- keepalive.go
- media_output.go
- media_tokens.go
- middleware.go
- model_availability.go
- models.go
- openai_chat.go
- prompt.go
- remote_media.go
- request_decode.go
- request_summary.go
- responses_client_tools.go
- responses_compact.go
- responses_handler.go
- responses_store.go
- stop_sequence.go
- stream.go
- thinking.go
- tool_bridge.go
- tool_protocol.go
- unsupported.go
- video_variants.go
- videos.go