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
acd7fc9d
authored
Feb 06, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: /v1/chat/completions -> /v1/responses json_schema
parent
cb34e239
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
6 deletions
+43
-6
service/openaicompat/chat_to_responses.go
+43
-6
No files found.
service/openaicompat/chat_to_responses.go
View file @
acd7fc9d
...
@@ -34,6 +34,44 @@ func normalizeChatImageURLToString(v any) any {
...
@@ -34,6 +34,44 @@ func normalizeChatImageURLToString(v any) any {
}
}
}
}
func
convertChatResponseFormatToResponsesText
(
reqFormat
*
dto
.
ResponseFormat
)
json
.
RawMessage
{
if
reqFormat
==
nil
||
strings
.
TrimSpace
(
reqFormat
.
Type
)
==
""
{
return
nil
}
format
:=
map
[
string
]
any
{
"type"
:
reqFormat
.
Type
,
}
if
reqFormat
.
Type
==
"json_schema"
&&
len
(
reqFormat
.
JsonSchema
)
>
0
{
var
chatSchema
map
[
string
]
any
if
err
:=
common
.
Unmarshal
(
reqFormat
.
JsonSchema
,
&
chatSchema
);
err
==
nil
{
for
key
,
value
:=
range
chatSchema
{
if
key
==
"type"
{
continue
}
format
[
key
]
=
value
}
if
nested
,
ok
:=
format
[
"json_schema"
]
.
(
map
[
string
]
any
);
ok
{
for
key
,
value
:=
range
nested
{
if
_
,
exists
:=
format
[
key
];
!
exists
{
format
[
key
]
=
value
}
}
delete
(
format
,
"json_schema"
)
}
}
else
{
format
[
"json_schema"
]
=
reqFormat
.
JsonSchema
}
}
textRaw
,
_
:=
common
.
Marshal
(
map
[
string
]
any
{
"format"
:
format
,
})
return
textRaw
}
func
ChatCompletionsRequestToResponsesRequest
(
req
*
dto
.
GeneralOpenAIRequest
)
(
*
dto
.
OpenAIResponsesRequest
,
error
)
{
func
ChatCompletionsRequestToResponsesRequest
(
req
*
dto
.
GeneralOpenAIRequest
)
(
*
dto
.
OpenAIResponsesRequest
,
error
)
{
if
req
==
nil
{
if
req
==
nil
{
return
nil
,
errors
.
New
(
"request is nil"
)
return
nil
,
errors
.
New
(
"request is nil"
)
...
@@ -312,17 +350,16 @@ func ChatCompletionsRequestToResponsesRequest(req *dto.GeneralOpenAIRequest) (*d
...
@@ -312,17 +350,16 @@ func ChatCompletionsRequestToResponsesRequest(req *dto.GeneralOpenAIRequest) (*d
parallelToolCallsRaw
,
_
=
common
.
Marshal
(
*
req
.
ParallelTooCalls
)
parallelToolCallsRaw
,
_
=
common
.
Marshal
(
*
req
.
ParallelTooCalls
)
}
}
var
textRaw
json
.
RawMessage
textRaw
:=
convertChatResponseFormatToResponsesText
(
req
.
ResponseFormat
)
if
req
.
ResponseFormat
!=
nil
&&
req
.
ResponseFormat
.
Type
!=
""
{
textRaw
,
_
=
common
.
Marshal
(
map
[
string
]
any
{
"format"
:
req
.
ResponseFormat
,
})
}
maxOutputTokens
:=
req
.
MaxTokens
maxOutputTokens
:=
req
.
MaxTokens
if
req
.
MaxCompletionTokens
>
maxOutputTokens
{
if
req
.
MaxCompletionTokens
>
maxOutputTokens
{
maxOutputTokens
=
req
.
MaxCompletionTokens
maxOutputTokens
=
req
.
MaxCompletionTokens
}
}
// OpenAI Responses API rejects max_output_tokens < 16 when explicitly provided.
//if maxOutputTokens > 0 && maxOutputTokens < 16 {
// maxOutputTokens = 16
//}
var
topP
*
float64
var
topP
*
float64
if
req
.
TopP
!=
0
{
if
req
.
TopP
!=
0
{
...
...
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