Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/ruby_llm/providers/openai/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def format_tool_calls(tool_calls)
end
end

def parse_tool_call_arguments(tool_call)
arguments = tool_call.dig('function', 'arguments')

if arguments.nil? || arguments.empty?
{}
else
JSON.parse(arguments)
end
end

def parse_tool_calls(tool_calls, parse_arguments: true)
return nil unless tool_calls&.any?

Expand All @@ -54,12 +64,7 @@ def parse_tool_calls(tool_calls, parse_arguments: true)
id: tc['id'],
name: tc.dig('function', 'name'),
arguments: if parse_arguments
if tc.dig('function', 'arguments').empty?
{}
else
JSON.parse(tc.dig('function',
'arguments'))
end
parse_tool_call_arguments(tc)
else
tc.dig('function', 'arguments')
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading