From 2c0b9c6349af3f5f441dced7cdf22864c1912f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Freitas?= Date: Fri, 12 Sep 2025 04:13:23 +0900 Subject: [PATCH] fix(chat): use proper finish_reason for tool/function calling (#6243) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mário Freitas --- core/http/endpoints/openai/chat.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/core/http/endpoints/openai/chat.go b/core/http/endpoints/openai/chat.go index 17baed364..5dc2310fd 100644 --- a/core/http/endpoints/openai/chat.go +++ b/core/http/endpoints/openai/chat.go @@ -398,9 +398,9 @@ func ChatEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, evaluator } finishReason := "stop" - if toolsCalled { + if toolsCalled && len(input.Tools) > 0 { finishReason = "tool_calls" - } else if toolsCalled && len(input.Tools) == 0 { + } else if toolsCalled { finishReason = "function_call" } @@ -443,11 +443,6 @@ func ChatEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, evaluator log.Debug().Msgf("Text content to return: %s", textContentToReturn) noActionsToRun := len(results) > 0 && results[0].Name == noActionName || len(results) == 0 - finishReason := "stop" - if len(input.Tools) > 0 { - finishReason = "tool_calls" - } - switch { case noActionsToRun: result, err := handleQuestion(config, cl, input, ml, startupOptions, results, s, predInput) @@ -457,11 +452,11 @@ func ChatEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, evaluator } *c = append(*c, schema.Choice{ - FinishReason: finishReason, + FinishReason: "stop", Message: &schema.Message{Role: "assistant", Content: &result}}) default: toolChoice := schema.Choice{ - FinishReason: finishReason, + FinishReason: "tool_calls", Message: &schema.Message{ Role: "assistant", },