Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5492f19f
authored
Jul 20, 2025
by
t0ng7u
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'alpha' into refactor/layout-Ⅱ
parents
4eeea5ae
dfc826a3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
68 deletions
+73
-68
dto/openai_request.go
+42
-39
dto/openai_response.go
+22
-22
relay/channel/openai/relay_responses.go
+1
-1
relay/common/relay_info.go
+8
-6
No files found.
dto/openai_request.go
View file @
5492f19f
...
...
@@ -603,26 +603,29 @@ type WebSearchOptions struct {
UserLocation
json
.
RawMessage
`json:"user_location,omitempty"`
}
// https://platform.openai.com/docs/api-reference/responses/create
type
OpenAIResponsesRequest
struct
{
Model
string
`json:"model"`
Input
json
.
RawMessage
`json:"input,omitempty"`
Include
json
.
RawMessage
`json:"include,omitempty"`
Instructions
json
.
RawMessage
`json:"instructions,omitempty"`
MaxOutputTokens
uint
`json:"max_output_tokens,omitempty"`
Metadata
json
.
RawMessage
`json:"metadata,omitempty"`
ParallelToolCalls
bool
`json:"parallel_tool_calls,omitempty"`
PreviousResponseID
string
`json:"previous_response_id,omitempty"`
Reasoning
*
Reasoning
`json:"reasoning,omitempty"`
ServiceTier
string
`json:"service_tier,omitempty"`
Store
bool
`json:"store,omitempty"`
Stream
bool
`json:"stream,omitempty"`
Temperature
float64
`json:"temperature,omitempty"`
Text
json
.
RawMessage
`json:"text,omitempty"`
ToolChoice
json
.
RawMessage
`json:"tool_choice,omitempty"`
Tools
[]
ResponsesToolsCall
`json:"tools,omitempty"`
TopP
float64
`json:"top_p,omitempty"`
Truncation
string
`json:"truncation,omitempty"`
User
string
`json:"user,omitempty"`
Model
string
`json:"model"`
Input
json
.
RawMessage
`json:"input,omitempty"`
Include
json
.
RawMessage
`json:"include,omitempty"`
Instructions
json
.
RawMessage
`json:"instructions,omitempty"`
MaxOutputTokens
uint
`json:"max_output_tokens,omitempty"`
Metadata
json
.
RawMessage
`json:"metadata,omitempty"`
ParallelToolCalls
bool
`json:"parallel_tool_calls,omitempty"`
PreviousResponseID
string
`json:"previous_response_id,omitempty"`
Reasoning
*
Reasoning
`json:"reasoning,omitempty"`
ServiceTier
string
`json:"service_tier,omitempty"`
Store
bool
`json:"store,omitempty"`
Stream
bool
`json:"stream,omitempty"`
Temperature
float64
`json:"temperature,omitempty"`
Text
json
.
RawMessage
`json:"text,omitempty"`
ToolChoice
json
.
RawMessage
`json:"tool_choice,omitempty"`
Tools
[]
map
[
string
]
any
`json:"tools,omitempty"`
// 需要处理的参数很少,MCP 参数太多不确定,所以用 map
TopP
float64
`json:"top_p,omitempty"`
Truncation
string
`json:"truncation,omitempty"`
User
string
`json:"user,omitempty"`
MaxToolCalls
uint
`json:"max_tool_calls,omitempty"`
Prompt
json
.
RawMessage
`json:"prompt,omitempty"`
}
type
Reasoning
struct
{
...
...
@@ -630,23 +633,23 @@ type Reasoning struct {
Summary
string
`json:"summary,omitempty"`
}
type
ResponsesToolsCall
struct
{
Type
string
`json:"type"`
// Web Search
UserLocation
json
.
RawMessage
`json:"user_location,omitempty"`
SearchContextSize
string
`json:"search_context_size,omitempty"`
// File Search
VectorStoreIds
[]
string
`json:"vector_store_ids,omitempty"`
MaxNumResults
uint
`json:"max_num_results,omitempty"`
Filters
json
.
RawMessage
`json:"filters,omitempty"`
// Computer Use
DisplayWidth
uint
`json:"display_width,omitempty"`
DisplayHeight
uint
`json:"display_height,omitempty"`
Environment
string
`json:"environment,omitempty"`
// Function
Name
string
`json:"name,omitempty"`
Description
string
`json:"description,omitempty"`
Parameters
json
.
RawMessage
`json:"parameters,omitempty"`
Function
json
.
RawMessage
`json:"function,omitempty"`
Container
json
.
RawMessage
`json:"container,omitempty"`
}
//
type ResponsesToolsCall struct {
//
Type string `json:"type"`
//
// Web Search
//
UserLocation json.RawMessage `json:"user_location,omitempty"`
//
SearchContextSize string `json:"search_context_size,omitempty"`
//
// File Search
//
VectorStoreIds []string `json:"vector_store_ids,omitempty"`
//
MaxNumResults uint `json:"max_num_results,omitempty"`
//
Filters json.RawMessage `json:"filters,omitempty"`
//
// Computer Use
//
DisplayWidth uint `json:"display_width,omitempty"`
//
DisplayHeight uint `json:"display_height,omitempty"`
//
Environment string `json:"environment,omitempty"`
//
// Function
//
Name string `json:"name,omitempty"`
//
Description string `json:"description,omitempty"`
//
Parameters json.RawMessage `json:"parameters,omitempty"`
//
Function json.RawMessage `json:"function,omitempty"`
//
Container json.RawMessage `json:"container,omitempty"`
//
}
dto/openai_response.go
View file @
5492f19f
...
...
@@ -200,28 +200,28 @@ type OutputTokenDetails struct {
}
type
OpenAIResponsesResponse
struct
{
ID
string
`json:"id"`
Object
string
`json:"object"`
CreatedAt
int
`json:"created_at"`
Status
string
`json:"status"`
Error
*
types
.
OpenAIError
`json:"error,omitempty"`
IncompleteDetails
*
IncompleteDetails
`json:"incomplete_details,omitempty"`
Instructions
string
`json:"instructions"`
MaxOutputTokens
int
`json:"max_output_tokens"`
Model
string
`json:"model"`
Output
[]
ResponsesOutput
`json:"output"`
ParallelToolCalls
bool
`json:"parallel_tool_calls"`
PreviousResponseID
string
`json:"previous_response_id"`
Reasoning
*
Reasoning
`json:"reasoning"`
Store
bool
`json:"store"`
Temperature
float64
`json:"temperature"`
ToolChoice
string
`json:"tool_choice"`
Tools
[]
ResponsesToolsCall
`json:"tools"`
TopP
float64
`json:"top_p"`
Truncation
string
`json:"truncation"`
Usage
*
Usage
`json:"usage"`
User
json
.
RawMessage
`json:"user"`
Metadata
json
.
RawMessage
`json:"metadata"`
ID
string
`json:"id"`
Object
string
`json:"object"`
CreatedAt
int
`json:"created_at"`
Status
string
`json:"status"`
Error
*
types
.
OpenAIError
`json:"error,omitempty"`
IncompleteDetails
*
IncompleteDetails
`json:"incomplete_details,omitempty"`
Instructions
string
`json:"instructions"`
MaxOutputTokens
int
`json:"max_output_tokens"`
Model
string
`json:"model"`
Output
[]
ResponsesOutput
`json:"output"`
ParallelToolCalls
bool
`json:"parallel_tool_calls"`
PreviousResponseID
string
`json:"previous_response_id"`
Reasoning
*
Reasoning
`json:"reasoning"`
Store
bool
`json:"store"`
Temperature
float64
`json:"temperature"`
ToolChoice
string
`json:"tool_choice"`
Tools
[]
map
[
string
]
any
`json:"tools"`
TopP
float64
`json:"top_p"`
Truncation
string
`json:"truncation"`
Usage
*
Usage
`json:"usage"`
User
json
.
RawMessage
`json:"user"`
Metadata
json
.
RawMessage
`json:"metadata"`
}
type
IncompleteDetails
struct
{
...
...
relay/channel/openai/relay_responses.go
View file @
5492f19f
...
...
@@ -42,7 +42,7 @@ func OaiResponsesHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http
usage
.
TotalTokens
=
responsesResponse
.
Usage
.
TotalTokens
// 解析 Tools 用量
for
_
,
tool
:=
range
responsesResponse
.
Tools
{
info
.
ResponsesUsageInfo
.
BuiltInTools
[
tool
.
Type
]
.
CallCount
++
info
.
ResponsesUsageInfo
.
BuiltInTools
[
common
.
Interface2String
(
tool
[
"type"
])
]
.
CallCount
++
}
return
&
usage
,
nil
}
...
...
relay/common/relay_info.go
View file @
5492f19f
...
...
@@ -180,16 +180,18 @@ func GenRelayInfoResponses(c *gin.Context, req *dto.OpenAIResponsesRequest) *Rel
}
if
len
(
req
.
Tools
)
>
0
{
for
_
,
tool
:=
range
req
.
Tools
{
info
.
ResponsesUsageInfo
.
BuiltInTools
[
tool
.
Type
]
=
&
BuildInToolInfo
{
ToolName
:
tool
.
Type
,
toolType
:=
common
.
Interface2String
(
tool
[
"type"
])
info
.
ResponsesUsageInfo
.
BuiltInTools
[
toolType
]
=
&
BuildInToolInfo
{
ToolName
:
toolType
,
CallCount
:
0
,
}
switch
tool
.
Type
{
switch
toolType
{
case
dto
.
BuildInToolWebSearchPreview
:
if
tool
.
SearchContextSize
==
""
{
tool
.
SearchContextSize
=
"medium"
searchContextSize
:=
common
.
Interface2String
(
tool
[
"search_context_size"
])
if
searchContextSize
==
""
{
searchContextSize
=
"medium"
}
info
.
ResponsesUsageInfo
.
BuiltInTools
[
tool
.
Type
]
.
SearchContextSize
=
tool
.
S
earchContextSize
info
.
ResponsesUsageInfo
.
BuiltInTools
[
tool
Type
]
.
SearchContextSize
=
s
earchContextSize
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment