From ec77f4a4f5f9d9155163e58e50a17d07ad41a1bc Mon Sep 17 00:00:00 2001 From: 0oAstro <79555780+0oAstro@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:55:01 +0530 Subject: [PATCH] fix(codex): set finish_reason to tool_calls in non-streaming response when tool calls are present --- .../openai/chat-completions/codex_openai_response.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/translator/codex/openai/chat-completions/codex_openai_response.go b/internal/translator/codex/openai/chat-completions/codex_openai_response.go index ab728a24..afae35d4 100644 --- a/internal/translator/codex/openai/chat-completions/codex_openai_response.go +++ b/internal/translator/codex/openai/chat-completions/codex_openai_response.go @@ -284,12 +284,12 @@ func ConvertCodexResponseToOpenAINonStream(_ context.Context, _ string, original } // Process the output array for content and function calls + var toolCalls [][]byte outputResult := responseResult.Get("output") if outputResult.IsArray() { outputArray := outputResult.Array() var contentText string var reasoningText string - var toolCalls [][]byte for _, outputItem := range outputArray { outputType := outputItem.Get("type").String() @@ -367,8 +367,12 @@ func ConvertCodexResponseToOpenAINonStream(_ context.Context, _ string, original if statusResult := responseResult.Get("status"); statusResult.Exists() { status := statusResult.String() if status == "completed" { - template, _ = sjson.SetBytes(template, "choices.0.finish_reason", "stop") - template, _ = sjson.SetBytes(template, "choices.0.native_finish_reason", "stop") + finishReason := "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) } }