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 {
...
@@ -603,26 +603,29 @@ 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"`
Include
json
.
RawMessage
`json:"include,omitempty"`
Include
json
.
RawMessage
`json:"include,omitempty"`
Instructions
json
.
RawMessage
`json:"instructions,omitempty"`
Instructions
json
.
RawMessage
`json:"instructions,omitempty"`
MaxOutputTokens
uint
`json:"max_output_tokens,omitempty"`
MaxOutputTokens
uint
`json:"max_output_tokens,omitempty"`
Metadata
json
.
RawMessage
`json:"metadata,omitempty"`
Metadata
json
.
RawMessage
`json:"metadata,omitempty"`
ParallelToolCalls
bool
`json:"parallel_tool_calls,omitempty"`
ParallelToolCalls
bool
`json:"parallel_tool_calls,omitempty"`
PreviousResponseID
string
`json:"previous_response_id,omitempty"`
PreviousResponseID
string
`json:"previous_response_id,omitempty"`
Reasoning
*
Reasoning
`json:"reasoning,omitempty"`
Reasoning
*
Reasoning
`json:"reasoning,omitempty"`
ServiceTier
string
`json:"service_tier,omitempty"`
ServiceTier
string
`json:"service_tier,omitempty"`
Store
bool
`json:"store,omitempty"`
Store
bool
`json:"store,omitempty"`
Stream
bool
`json:"stream,omitempty"`
Stream
bool
`json:"stream,omitempty"`
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 {
...
@@ -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"`
}
//
}
dto/openai_response.go
View file @
5492f19f
...
@@ -200,28 +200,28 @@ type OutputTokenDetails struct {
...
@@ -200,28 +200,28 @@ type OutputTokenDetails struct {
}
}
type
OpenAIResponsesResponse
struct
{
type
OpenAIResponsesResponse
struct
{
ID
string
`json:"id"`
ID
string
`json:"id"`
Object
string
`json:"object"`
Object
string
`json:"object"`
CreatedAt
int
`json:"created_at"`
CreatedAt
int
`json:"created_at"`
Status
string
`json:"status"`
Status
string
`json:"status"`
Error
*
types
.
OpenAIError
`json:"error,omitempty"`
Error
*
types
.
OpenAIError
`json:"error,omitempty"`
IncompleteDetails
*
IncompleteDetails
`json:"incomplete_details,omitempty"`
IncompleteDetails
*
IncompleteDetails
`json:"incomplete_details,omitempty"`
Instructions
string
`json:"instructions"`
Instructions
string
`json:"instructions"`
MaxOutputTokens
int
`json:"max_output_tokens"`
MaxOutputTokens
int
`json:"max_output_tokens"`
Model
string
`json:"model"`
Model
string
`json:"model"`
Output
[]
ResponsesOutput
`json:"output"`
Output
[]
ResponsesOutput
`json:"output"`
ParallelToolCalls
bool
`json:"parallel_tool_calls"`
ParallelToolCalls
bool
`json:"parallel_tool_calls"`
PreviousResponseID
string
`json:"previous_response_id"`
PreviousResponseID
string
`json:"previous_response_id"`
Reasoning
*
Reasoning
`json:"reasoning"`
Reasoning
*
Reasoning
`json:"reasoning"`
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"`
User
json
.
RawMessage
`json:"user"`
User
json
.
RawMessage
`json:"user"`
Metadata
json
.
RawMessage
`json:"metadata"`
Metadata
json
.
RawMessage
`json:"metadata"`
}
}
type
IncompleteDetails
struct
{
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
...
@@ -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
}
}
...
...
relay/common/relay_info.go
View file @
5492f19f
...
@@ -180,16 +180,18 @@ func GenRelayInfoResponses(c *gin.Context, req *dto.OpenAIResponsesRequest) *Rel
...
@@ -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
.
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