Merge branch 'alpha' into refactor/layout-Ⅱ

This commit is contained in:
t0ng7u
2025-07-20 11:27:53 +08:00
4 changed files with 73 additions and 68 deletions

View File

@@ -603,6 +603,7 @@ type WebSearchOptions struct {
UserLocation json.RawMessage `json:"user_location,omitempty"` UserLocation json.RawMessage `json:"user_location,omitempty"`
} }
// https://platform.openai.com/docs/api-reference/responses/create
type OpenAIResponsesRequest struct { type OpenAIResponsesRequest struct {
Model string `json:"model"` Model string `json:"model"`
Input json.RawMessage `json:"input,omitempty"` Input json.RawMessage `json:"input,omitempty"`
@@ -619,10 +620,12 @@ type OpenAIResponsesRequest struct {
Temperature float64 `json:"temperature,omitempty"` Temperature float64 `json:"temperature,omitempty"`
Text json.RawMessage `json:"text,omitempty"` Text json.RawMessage `json:"text,omitempty"`
ToolChoice json.RawMessage `json:"tool_choice,omitempty"` ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
Tools []ResponsesToolsCall `json:"tools,omitempty"` Tools []map[string]any `json:"tools,omitempty"` // 需要处理的参数很少MCP 参数太多不确定,所以用 map
TopP float64 `json:"top_p,omitempty"` TopP float64 `json:"top_p,omitempty"`
Truncation string `json:"truncation,omitempty"` Truncation string `json:"truncation,omitempty"`
User string `json:"user,omitempty"` User string `json:"user,omitempty"`
MaxToolCalls uint `json:"max_tool_calls,omitempty"`
Prompt json.RawMessage `json:"prompt,omitempty"`
} }
type Reasoning struct { type Reasoning struct {
@@ -630,23 +633,23 @@ type Reasoning struct {
Summary string `json:"summary,omitempty"` Summary string `json:"summary,omitempty"`
} }
type ResponsesToolsCall struct { //type ResponsesToolsCall struct {
Type string `json:"type"` // Type string `json:"type"`
// Web Search // // Web Search
UserLocation json.RawMessage `json:"user_location,omitempty"` // UserLocation json.RawMessage `json:"user_location,omitempty"`
SearchContextSize string `json:"search_context_size,omitempty"` // SearchContextSize string `json:"search_context_size,omitempty"`
// File Search // // File Search
VectorStoreIds []string `json:"vector_store_ids,omitempty"` // VectorStoreIds []string `json:"vector_store_ids,omitempty"`
MaxNumResults uint `json:"max_num_results,omitempty"` // MaxNumResults uint `json:"max_num_results,omitempty"`
Filters json.RawMessage `json:"filters,omitempty"` // Filters json.RawMessage `json:"filters,omitempty"`
// Computer Use // // Computer Use
DisplayWidth uint `json:"display_width,omitempty"` // DisplayWidth uint `json:"display_width,omitempty"`
DisplayHeight uint `json:"display_height,omitempty"` // DisplayHeight uint `json:"display_height,omitempty"`
Environment string `json:"environment,omitempty"` // Environment string `json:"environment,omitempty"`
// Function // // Function
Name string `json:"name,omitempty"` // Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"` // Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters,omitempty"` // Parameters json.RawMessage `json:"parameters,omitempty"`
Function json.RawMessage `json:"function,omitempty"` // Function json.RawMessage `json:"function,omitempty"`
Container json.RawMessage `json:"container,omitempty"` // Container json.RawMessage `json:"container,omitempty"`
} //}

View File

@@ -216,7 +216,7 @@ type OpenAIResponsesResponse struct {
Store bool `json:"store"` Store bool `json:"store"`
Temperature float64 `json:"temperature"` Temperature float64 `json:"temperature"`
ToolChoice string `json:"tool_choice"` ToolChoice string `json:"tool_choice"`
Tools []ResponsesToolsCall `json:"tools"` Tools []map[string]any `json:"tools"`
TopP float64 `json:"top_p"` TopP float64 `json:"top_p"`
Truncation string `json:"truncation"` Truncation string `json:"truncation"`
Usage *Usage `json:"usage"` Usage *Usage `json:"usage"`

View File

@@ -42,7 +42,7 @@ func OaiResponsesHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http
usage.TotalTokens = responsesResponse.Usage.TotalTokens usage.TotalTokens = responsesResponse.Usage.TotalTokens
// 解析 Tools 用量 // 解析 Tools 用量
for _, tool := range responsesResponse.Tools { for _, tool := range responsesResponse.Tools {
info.ResponsesUsageInfo.BuiltInTools[tool.Type].CallCount++ info.ResponsesUsageInfo.BuiltInTools[common.Interface2String(tool["type"])].CallCount++
} }
return &usage, nil return &usage, nil
} }

View File

@@ -180,16 +180,18 @@ func GenRelayInfoResponses(c *gin.Context, req *dto.OpenAIResponsesRequest) *Rel
} }
if len(req.Tools) > 0 { if len(req.Tools) > 0 {
for _, tool := range req.Tools { for _, tool := range req.Tools {
info.ResponsesUsageInfo.BuiltInTools[tool.Type] = &BuildInToolInfo{ toolType := common.Interface2String(tool["type"])
ToolName: tool.Type, info.ResponsesUsageInfo.BuiltInTools[toolType] = &BuildInToolInfo{
ToolName: toolType,
CallCount: 0, CallCount: 0,
} }
switch tool.Type { switch toolType {
case dto.BuildInToolWebSearchPreview: case dto.BuildInToolWebSearchPreview:
if tool.SearchContextSize == "" { searchContextSize := common.Interface2String(tool["search_context_size"])
tool.SearchContextSize = "medium" if searchContextSize == "" {
searchContextSize = "medium"
} }
info.ResponsesUsageInfo.BuiltInTools[tool.Type].SearchContextSize = tool.SearchContextSize info.ResponsesUsageInfo.BuiltInTools[toolType].SearchContextSize = searchContextSize
} }
} }
} }