module RubyLLM::Providers::Gemini::Tools
Public Instance Methods
Source
# File lib/ruby_llm/providers/gemini/tools.rb, line 65 def extract_tool_calls(data) # rubocop:disable Metrics/PerceivedComplexity return nil unless data candidate = data.is_a?(Hash) ? data.dig('candidates', 0) : nil return nil unless candidate parts = candidate.dig('content', 'parts') return nil unless parts.is_a?(Array) tool_calls = parts.each_with_object({}) do |part, result| function_data = part['functionCall'] next unless function_data id = SecureRandom.uuid thought_signature = part['thoughtSignature'] || part['thought_signature'] result[id] = ToolCall.new( id:, name: function_data['name'], arguments: function_data['args'] || {}, thought_signature: thought_signature ) end tool_calls.empty? ? nil : tool_calls end
Source
# File lib/ruby_llm/providers/gemini/tools.rb, line 18 def format_tool_call(msg) # rubocop:disable Metrics/PerceivedComplexity parts = [] if msg.content && !(msg.content.respond_to?(:empty?) && msg.content.empty?) formatted_content = Media.format_content(msg.content) parts.concat(formatted_content.is_a?(Array) ? formatted_content : [formatted_content]) end fallback_signature = msg.thinking&.signature used_fallback = false msg.tool_calls.each_value do |tool_call| part = { functionCall: { name: tool_call.name, args: tool_call.arguments } } signature = tool_call.thought_signature if signature.nil? && fallback_signature && !used_fallback signature = fallback_signature used_fallback = true end part[:thoughtSignature] = signature if signature parts << part end parts end
# File lib/ruby_llm/providers/gemini/tools.rb, line 49 def format_tool_result(msg, function_name = nil) function_name ||= msg.tool_call_id content = msg.content content = '(no output)' if content.nil? || (content.respond_to?(:empty?) && content.empty?) [{ functionResponse: { name: function_name, response: { name: function_name, content: Media.format_content(content) } } }] end
Source
# File lib/ruby_llm/providers/gemini/tools.rb, line 10 def format_tools(tools) return [] if tools.empty? [{ functionDeclarations: tools.values.map { |tool| function_declaration_for(tool) } }] end