From 0d52566cc1ff2bb7adb9baee82893efa150f4925 Mon Sep 17 00:00:00 2001 From: soky srm Date: Fri, 19 Dec 2025 13:18:43 +0100 Subject: [PATCH] Fix api call for cloudflare API (#467) --- app/models/provider/openai.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/provider/openai.rb b/app/models/provider/openai.rb index 17a1e0bd7..23c9f0d0d 100644 --- a/app/models/provider/openai.rb +++ b/app/models/provider/openai.rb @@ -339,19 +339,23 @@ class Provider::Openai < Provider if function_results.any? # Build assistant message with tool_calls tool_calls = function_results.map do |fn_result| + # Convert arguments to JSON string if it's not already a string + arguments = fn_result[:arguments] + arguments_str = arguments.is_a?(String) ? arguments : arguments.to_json + { id: fn_result[:call_id], type: "function", function: { name: fn_result[:name], - arguments: fn_result[:arguments] + arguments: arguments_str } } end messages << { role: "assistant", - content: nil, + content: "", # Some OpenAI-compatible APIs require string, not null tool_calls: tool_calls }