Module: Raif::Concerns::Llms::OpenAiCompletions::ResponseToolCalls
- Extended by:
- ActiveSupport::Concern
- Included in:
- Llms::OpenAiCompletions, Llms::OpenRouter
- Defined in:
- app/models/raif/concerns/llms/open_ai_completions/response_tool_calls.rb
Instance Method Summary collapse
Instance Method Details
#extract_response_tool_calls(resp) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/raif/concerns/llms/open_ai_completions/response_tool_calls.rb', line 6 def extract_response_tool_calls(resp) tool_calls = resp.dig("choices", 0, "message", "tool_calls") return if tool_calls.blank? tool_calls.map do |tool_call| { "provider_tool_call_id" => tool_call["id"], "name" => tool_call["function"]["name"], "arguments" => begin JSON.parse(tool_call["function"]["arguments"]) rescue JSON::ParserError tool_call["function"]["arguments"] end } end end |