Documentation
¶
Index ¶
- func AccountMiddleware(pool *balancer.AccountPool) gin.HandlerFunc
- 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 CleanupTemporaryChats(ctx context.Context, pool *balancer.AccountPool)
- func CompletionHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func ConfigureSessionTTL(ttl time.Duration)
- func DecompressMiddleware() gin.HandlerFunc
- func DeleteTemporaryChats(ctx context.Context, pool *balancer.AccountPool)
- 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 FirstEventP95(model string) (p95 time.Duration, samples int, ready bool)
- func GeminiCacheCreateHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func GeminiCacheDeleteHandler() gin.HandlerFunc
- func GeminiCacheGetHandler() gin.HandlerFunc
- func GeminiCacheListHandler() gin.HandlerFunc
- func GeminiCacheUpdateHandler() 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 GeminiOr(gemini, openAI gin.HandlerFunc) 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 InteractionCancelHandler(store *requestdb.Store) gin.HandlerFunc
- func InteractionDeleteHandler(store *requestdb.Store) gin.HandlerFunc
- func InteractionRetrieveHandler(store *requestdb.Store) gin.HandlerFunc
- func InteractionsHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
- func IsGeminiRequest(c *gin.Context) bool
- func ListModelsHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func LoopbackHost(host string) bool
- func RequestBaseURL(c *gin.Context) string
- 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, store *requestdb.Store) gin.HandlerFunc
- func RetrieveModelHandler(pool *balancer.AccountPool) gin.HandlerFunc
- func SetContinueSession(enabled bool)
- func SetFirstEventHedge(value FirstEventHedge)
- func SetResponseModes(keepalive, fake bool)
- 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 AccountMiddleware ¶ added in v0.2.0
func AccountMiddleware(pool *balancer.AccountPool) gin.HandlerFunc
AccountMiddleware 读取指定处理账号的请求头:账号不存在返回 400,不在 API key 绑定的账号中返回 403,其余请求只由该账号处理
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 CleanupTemporaryChats ¶ added in v0.1.9
func CleanupTemporaryChats(ctx context.Context, pool *balancer.AccountPool)
CleanupTemporaryChats 每分钟从网页历史删除不再被续接的临时会话,直到 ctx 结束
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 DecompressMiddleware ¶ added in v0.2.1
func DecompressMiddleware() gin.HandlerFunc
DecompressMiddleware 按 Content-Encoding 解压 gzip 与 zstd 请求体,解压在处理函数读取请求体时同步进行,请求体上限作用于解压后的字节,请求结束时关闭解压器
func DeleteTemporaryChats ¶ added in v0.1.9
func DeleteTemporaryChats(ctx context.Context, pool *balancer.AccountPool)
DeleteTemporaryChats 从网页历史删除全部临时会话,服务停止时调用
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 FirstEventP95 ¶ added in v0.2.0
FirstEventP95 返回模型近 24 小时原请求首事件等待的 p95 与样本数,ready 表示样本数已够自动模式按它发起备用请求
func GeminiCacheCreateHandler ¶ added in v0.2.0
func GeminiCacheCreateHandler(pool *balancer.AccountPool) gin.HandlerFunc
GeminiCacheCreateHandler 保存缓存内容并以生成时的提示词编码统计缓存的 token 数
func GeminiCacheDeleteHandler ¶ added in v0.2.0
func GeminiCacheDeleteHandler() gin.HandlerFunc
GeminiCacheDeleteHandler 删除缓存
func GeminiCacheGetHandler ¶ added in v0.2.0
func GeminiCacheGetHandler() gin.HandlerFunc
GeminiCacheGetHandler 返回缓存资源的元数据
func GeminiCacheListHandler ¶ added in v0.2.0
func GeminiCacheListHandler() gin.HandlerFunc
GeminiCacheListHandler 按创建时间从新到旧分页列出未过期的缓存
func GeminiCacheUpdateHandler ¶ added in v0.2.0
func GeminiCacheUpdateHandler() gin.HandlerFunc
GeminiCacheUpdateHandler 按 updateMask 列出的字段更新缓存的过期时间与显示名称,没有 updateMask 时更新请求中出现的这些字段
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 GeminiOr ¶ added in v0.1.8
func GeminiOr(gemini, openAI gin.HandlerFunc) gin.HandlerFunc
GeminiOr 在 Gemini 与 OpenAI 共用的路径上按请求协议选择处理函数
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 InteractionCancelHandler ¶ added in v0.2.0
func InteractionCancelHandler(store *requestdb.Store) gin.HandlerFunc
InteractionCancelHandler 取消后台交互:进行中的交互停止生成并标为 cancelled,已结束的交互原样返回
func InteractionDeleteHandler ¶ added in v0.2.0
func InteractionDeleteHandler(store *requestdb.Store) gin.HandlerFunc
InteractionDeleteHandler 删除保存的交互,进行中的后台交互同时停止
func InteractionRetrieveHandler ¶ added in v0.2.0
func InteractionRetrieveHandler(store *requestdb.Store) gin.HandlerFunc
InteractionRetrieveHandler 返回保存的交互:include_input 时在步骤前加入请求输入;stream 时等后台交互结束,再按创建时的流式事件回放 last_event_id 之后的事件
func InteractionsHandler ¶ added in v0.2.0
func InteractionsHandler(pool *balancer.AccountPool, store *requestdb.Store) gin.HandlerFunc
InteractionsHandler 处理 Interactions 创建请求:previous_interaction_id 续接已保存的交互,cached_content 展开显式缓存,store 不为 false 时保存交互,background 为 true 时立即返回 in_progress 的交互、生成在后台继续
func IsGeminiRequest ¶ added in v0.1.8
IsGeminiRequest 判断请求是否属于 Gemini 协议,/v1 上的请求以模型方法路径、x-goog-api-key 头识别,与 OpenAI 共用的模型与文件查询路由上另以不带 Authorization 与 anthropic-version 头的 key 查询参数识别
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 RequestBaseURL ¶ added in v0.2.1
RequestBaseURL 返回客户端访问本服务所用的协议与主机
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, store *requestdb.Store) gin.HandlerFunc
ResponsesInputTokensHandler 以与生成相同的提示词编码计算 Responses 请求的输入 token,续接时计入会话已有上下文,不续接会话时计入已保存的前文
func RetrieveModelHandler ¶ added in v0.1.3
func RetrieveModelHandler(pool *balancer.AccountPool) gin.HandlerFunc
RetrieveModelHandler 返回单个模型,带 anthropic-version 头时返回 Anthropic 格式
func SetContinueSession ¶ added in v0.2.0
func SetContinueSession(enabled bool)
SetContinueSession 设置续接官网会话开关
func SetFirstEventHedge ¶ added in v0.1.7
func SetFirstEventHedge(value FirstEventHedge)
SetFirstEventHedge 替换首事件备用请求设置,下一个请求生效
func SetResponseModes ¶ added in v0.1.8
func SetResponseModes(keepalive, fake bool)
SetResponseModes 设置非流式保活与假流式开关
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 指向的模型 ID
AliasOf string
}
CatalogModel 是公开目录中的一个模型及其在账号间的上下文窗口范围
func Catalog ¶ added in v0.1.3
func Catalog(pool *balancer.AccountPool) []CatalogModel
Catalog 汇总已就绪或已读取目录的账号的模型目录,追加 gemini-default、MODEL_MAPPING 中指向已有模型的别名与改名前的旧 ID
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"`
Refusal string `json:"refusal,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"`
ParallelToolCalls *bool `json:"parallel_tool_calls,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"`
// TruncateTo 大于 0 时提示词超过这个 token 数就从最早的轮次删起
TruncateTo int `json:"-"`
// 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 json.RawMessage `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"`
// CachedContent 为引用的显式缓存资源名
CachedContent string `json:"cachedContent,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"`
AspectRatio string `json:"aspect_ratio,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"`
Filters json.RawMessage `json:"filters,omitempty"`
UserLocation json.RawMessage `json:"user_location,omitempty"`
DisplayWidth int `json:"display_width,omitempty"`
DisplayHeight int `json:"display_height,omitempty"`
Environment json.RawMessage `json:"environment,omitempty"`
}
ResponsesTool 表示 Responses API 函数工具
type ToolBridge ¶
type ToolBridge struct {
Definitions []ToolDefinition
Choice string
JSONSchema json.RawMessage
CodeExecution bool
WebSearch bool
URLContext bool
ImageGeneration bool
RequireCodeExecution bool
RequireWebSearch bool
RequireImageGeneration bool
RequireHostedTool 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
// SingleCall 表示一次回答只调用一个工具
SingleCall bool
// MaxTokens 是请求的输出上限,思考与正文合计超过时在本地截断,0 表示不限
MaxTokens int
// SearchDomains 是搜索来源限定的域名,SearchBlocked 是搜索来源排除的域名,SearchLocation 是搜索按其所在的用户位置
SearchDomains []string
SearchBlocked []string
SearchLocation string
// Truncated 表示回答达到输出上限而截断,解析时不要求必需的工具调用,正文不按枚举与 JSON Schema 校验
Truncated bool
// Corrected 表示上一次回答声称工具不可用而作废,本次生成在提示词末尾附带纠正说明
Corrected 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"`
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_context.go
- claude_handler.go
- claude_tools.go
- client_prompt.go
- completions.go
- conversation.go
- errors.go
- events.go
- files.go
- gemini_caches.go
- gemini_format.go
- gemini_handler.go
- hedge.go
- history.go
- image_handler.go
- interaction_stream.go
- interactions.go
- keepalive.go
- media_output.go
- media_tokens.go
- middleware.go
- model_availability.go
- models.go
- openai_chat.go
- output_limit.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_claim.go
- tool_protocol.go
- unsupported.go
- url_context.go
- video_variants.go
- videos.go