feat(openai): 完善 Chat 与 Responses 参数转发
原生 Chat/Responses 改为透明转发,保留标准工具结构并保护调用方显式参数。补齐 Responses 到 Chat 的兼容转换、协议路由边界、完整响应和流式事件,并同步更新 Swagger、回归测试与真实验收脚本。 验证: - cd apps/api && env -u AI_GATEWAY_TEST_DATABASE_URL go test ./... -count=1 - pnpm openapi - pnpm lint - pnpm test - pnpm build - gofmt -l 无输出 - git diff --check 通过 风险: - Chat 回退无法等价表达的 Responses 原生能力现在会返回 unsupported_response_parameter - 真实供应商 E2E 因本地没有已启用的平台模型候选而未完成
This commit is contained in:
@@ -470,12 +470,14 @@ type ChatMessage struct {
|
||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||
ToolCalls interface{} `json:"tool_calls,omitempty"`
|
||||
FunctionCall interface{} `json:"function_call,omitempty"`
|
||||
Audio interface{} `json:"audio,omitempty"`
|
||||
Refusal string `json:"refusal,omitempty"`
|
||||
}
|
||||
|
||||
type ResponsesRequest struct {
|
||||
Model string `json:"model" example:"Doubao Seed 2.0 Pro"`
|
||||
Background *bool `json:"background,omitempty"`
|
||||
ContextManagement []map[string]interface{} `json:"context_management,omitempty"`
|
||||
ContextManagement interface{} `json:"context_management,omitempty"`
|
||||
Conversation interface{} `json:"conversation,omitempty"`
|
||||
Include []string `json:"include,omitempty"`
|
||||
Input interface{} `json:"input"`
|
||||
@@ -507,15 +509,41 @@ type ResponsesRequest struct {
|
||||
}
|
||||
|
||||
type ResponsesCompatibleResponse struct {
|
||||
ID string `json:"id" example:"resp_0123456789abcdef0123456789abcdef"`
|
||||
Object string `json:"object" example:"response"`
|
||||
CreatedAt int64 `json:"created_at" example:"1710000000"`
|
||||
Status string `json:"status" example:"completed"`
|
||||
Model string `json:"model" example:"Doubao Seed 2.0 Pro"`
|
||||
PreviousResponseID string `json:"previous_response_id,omitempty" example:"resp_abcdef0123456789abcdef0123456789"`
|
||||
Output []map[string]interface{} `json:"output"`
|
||||
OutputText string `json:"output_text,omitempty" example:"Hello"`
|
||||
Usage map[string]interface{} `json:"usage,omitempty"`
|
||||
ID string `json:"id" example:"resp_0123456789abcdef0123456789abcdef"`
|
||||
Object string `json:"object" example:"response"`
|
||||
CreatedAt int64 `json:"created_at" example:"1710000000"`
|
||||
Status string `json:"status" example:"completed" enums:"queued,in_progress,completed,incomplete,failed,cancelled"`
|
||||
CompletedAt *int64 `json:"completed_at"`
|
||||
Error interface{} `json:"error"`
|
||||
IncompleteDetails interface{} `json:"incomplete_details"`
|
||||
Instructions interface{} `json:"instructions"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
Model string `json:"model" example:"Doubao Seed 2.0 Pro"`
|
||||
Output []map[string]interface{} `json:"output"`
|
||||
ParallelToolCalls bool `json:"parallel_tool_calls"`
|
||||
Temperature interface{} `json:"temperature"`
|
||||
ToolChoice interface{} `json:"tool_choice"`
|
||||
Tools []map[string]interface{} `json:"tools"`
|
||||
TopP interface{} `json:"top_p"`
|
||||
Background bool `json:"background"`
|
||||
Conversation interface{} `json:"conversation"`
|
||||
MaxOutputTokens interface{} `json:"max_output_tokens"`
|
||||
MaxToolCalls interface{} `json:"max_tool_calls"`
|
||||
Moderation interface{} `json:"moderation"`
|
||||
OutputText string `json:"output_text" example:"Hello"`
|
||||
PreviousResponseID interface{} `json:"previous_response_id"`
|
||||
Prompt interface{} `json:"prompt"`
|
||||
PromptCacheKey interface{} `json:"prompt_cache_key"`
|
||||
PromptCacheOptions interface{} `json:"prompt_cache_options"`
|
||||
PromptCacheRetention interface{} `json:"prompt_cache_retention"`
|
||||
Reasoning interface{} `json:"reasoning"`
|
||||
SafetyIdentifier interface{} `json:"safety_identifier"`
|
||||
ServiceTier interface{} `json:"service_tier"`
|
||||
Text interface{} `json:"text"`
|
||||
TopLogprobs interface{} `json:"top_logprobs"`
|
||||
Truncation interface{} `json:"truncation"`
|
||||
Usage map[string]interface{} `json:"usage"`
|
||||
User interface{} `json:"user"`
|
||||
}
|
||||
|
||||
type ImageGenerationRequest struct {
|
||||
@@ -586,23 +614,31 @@ type CompatibleResponse struct {
|
||||
}
|
||||
|
||||
type ChatCompletionCompatibleResponse struct {
|
||||
ID string `json:"id" example:"chatcmpl-123"`
|
||||
Object string `json:"object" example:"chat.completion"`
|
||||
Created int64 `json:"created,omitempty" example:"1710000000"`
|
||||
Model string `json:"model" example:"gpt-4o-mini"`
|
||||
Choices []ChatCompletionChoice `json:"choices"`
|
||||
Usage *ChatCompletionUsage `json:"usage,omitempty"`
|
||||
ID string `json:"id" example:"chatcmpl-123"`
|
||||
Object string `json:"object" example:"chat.completion"`
|
||||
Created int64 `json:"created,omitempty" example:"1710000000"`
|
||||
Model string `json:"model" example:"gpt-4o-mini"`
|
||||
Choices []ChatCompletionChoice `json:"choices"`
|
||||
Usage *ChatCompletionUsage `json:"usage,omitempty"`
|
||||
ServiceTier string `json:"service_tier,omitempty"`
|
||||
SystemFingerprint string `json:"system_fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
type ChatCompletionChoice struct {
|
||||
Index int `json:"index" example:"0"`
|
||||
Message ChatCompletionChoiceMessage `json:"message"`
|
||||
FinishReason string `json:"finish_reason,omitempty" example:"stop"`
|
||||
Logprobs interface{} `json:"logprobs,omitempty"`
|
||||
}
|
||||
|
||||
type ChatCompletionChoiceMessage struct {
|
||||
Role string `json:"role" example:"assistant"`
|
||||
Content string `json:"content" example:"Hello"`
|
||||
Role string `json:"role" example:"assistant"`
|
||||
Content interface{} `json:"content"`
|
||||
Refusal string `json:"refusal,omitempty"`
|
||||
Audio interface{} `json:"audio,omitempty"`
|
||||
Annotations interface{} `json:"annotations,omitempty"`
|
||||
ToolCalls interface{} `json:"tool_calls,omitempty"`
|
||||
FunctionCall interface{} `json:"function_call,omitempty"`
|
||||
}
|
||||
|
||||
type ChatCompletionUsage struct {
|
||||
|
||||
Reference in New Issue
Block a user