mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-04-24 06:20:27 +00:00
Merge pull request #2444 from 0oAstro/fix/codex-nonstream-finish-reason-tool-calls
fix(codex): set finish_reason to "tool_calls" in non-streaming response when tool calls are present
This commit is contained in:
@@ -284,12 +284,12 @@ func ConvertCodexResponseToOpenAINonStream(_ context.Context, _ string, original
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the output array for content and function calls
|
// Process the output array for content and function calls
|
||||||
|
var toolCalls [][]byte
|
||||||
outputResult := responseResult.Get("output")
|
outputResult := responseResult.Get("output")
|
||||||
if outputResult.IsArray() {
|
if outputResult.IsArray() {
|
||||||
outputArray := outputResult.Array()
|
outputArray := outputResult.Array()
|
||||||
var contentText string
|
var contentText string
|
||||||
var reasoningText string
|
var reasoningText string
|
||||||
var toolCalls [][]byte
|
|
||||||
|
|
||||||
for _, outputItem := range outputArray {
|
for _, outputItem := range outputArray {
|
||||||
outputType := outputItem.Get("type").String()
|
outputType := outputItem.Get("type").String()
|
||||||
@@ -367,8 +367,12 @@ func ConvertCodexResponseToOpenAINonStream(_ context.Context, _ string, original
|
|||||||
if statusResult := responseResult.Get("status"); statusResult.Exists() {
|
if statusResult := responseResult.Get("status"); statusResult.Exists() {
|
||||||
status := statusResult.String()
|
status := statusResult.String()
|
||||||
if status == "completed" {
|
if status == "completed" {
|
||||||
template, _ = sjson.SetBytes(template, "choices.0.finish_reason", "stop")
|
finishReason := "stop"
|
||||||
template, _ = sjson.SetBytes(template, "choices.0.native_finish_reason", "stop")
|
if len(toolCalls) > 0 {
|
||||||
|
finishReason = "tool_calls"
|
||||||
|
}
|
||||||
|
template, _ = sjson.SetBytes(template, "choices.0.finish_reason", finishReason)
|
||||||
|
template, _ = sjson.SetBytes(template, "choices.0.native_finish_reason", finishReason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user