Skip to content

Commit 167d667

Browse files
committed
Issue #384: Handle missing function.arguments in OpenAI tool_calls
1 parent c312b09 commit 167d667

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/ruby_llm/providers/openai/tools.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def format_tool_calls(tool_calls)
4444
end
4545
end
4646

47+
def parse_tool_call_arguments(tool_call)
48+
arguments = tool_call.dig('function', 'arguments')
49+
50+
if arguments.nil? || arguments.empty?
51+
{}
52+
else
53+
JSON.parse(arguments)
54+
end
55+
end
56+
4757
def parse_tool_calls(tool_calls, parse_arguments: true)
4858
return nil unless tool_calls&.any?
4959

@@ -54,12 +64,7 @@ def parse_tool_calls(tool_calls, parse_arguments: true)
5464
id: tc['id'],
5565
name: tc.dig('function', 'name'),
5666
arguments: if parse_arguments
57-
if tc.dig('function', 'arguments').empty?
58-
{}
59-
else
60-
JSON.parse(tc.dig('function',
61-
'arguments'))
62-
end
67+
parse_tool_call_arguments(tc)
6368
else
6469
tc.dig('function', 'arguments')
6570
end

0 commit comments

Comments
 (0)