Skip to content

Commit 30921d7

Browse files
committed
fix(chat): use proper finish_reason for tool/function calling
1 parent ffa934b commit 30921d7

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

core/http/endpoints/openai/chat.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ func ChatEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, evaluator
398398
}
399399

400400
finishReason := "stop"
401-
if toolsCalled {
401+
if toolsCalled && len(input.Tools) > 0 {
402402
finishReason = "tool_calls"
403-
} else if toolsCalled && len(input.Tools) == 0 {
403+
} else if toolsCalled {
404404
finishReason = "function_call"
405405
}
406406

@@ -443,11 +443,6 @@ func ChatEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, evaluator
443443
log.Debug().Msgf("Text content to return: %s", textContentToReturn)
444444
noActionsToRun := len(results) > 0 && results[0].Name == noActionName || len(results) == 0
445445

446-
finishReason := "stop"
447-
if len(input.Tools) > 0 {
448-
finishReason = "tool_calls"
449-
}
450-
451446
switch {
452447
case noActionsToRun:
453448
result, err := handleQuestion(config, cl, input, ml, startupOptions, results, s, predInput)
@@ -457,11 +452,11 @@ func ChatEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, evaluator
457452
}
458453

459454
*c = append(*c, schema.Choice{
460-
FinishReason: finishReason,
455+
FinishReason: "stop",
461456
Message: &schema.Message{Role: "assistant", Content: &result}})
462457
default:
463458
toolChoice := schema.Choice{
464-
FinishReason: finishReason,
459+
finishReason: "tool_calls",
465460
Message: &schema.Message{
466461
Role: "assistant",
467462
},

0 commit comments

Comments
 (0)