ruby_llm 0.1.0.pre40 → 0.1.0.pre42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLLM
4
+ module Providers
5
+ module Gemini
6
+ # Tools methods for the Gemini API implementation
7
+ module Tools
8
+ # Format tools for Gemini API
9
+ def format_tools(tools)
10
+ return [] if tools.empty?
11
+
12
+ [{
13
+ functionDeclarations: tools.values.map { |tool| function_declaration_for(tool) }
14
+ }]
15
+ end
16
+
17
+ # Extract tool calls from response data
18
+ def extract_tool_calls(data) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
19
+ return nil unless data
20
+
21
+ # Get the first candidate
22
+ candidate = data.is_a?(Hash) ? data.dig('candidates', 0) : nil
23
+ return nil unless candidate
24
+
25
+ # Get the parts array from content
26
+ parts = candidate.dig('content', 'parts')
27
+ return nil unless parts.is_a?(Array)
28
+
29
+ # Find the function call part
30
+ function_call_part = parts.find { |p| p['functionCall'] }
31
+ return nil unless function_call_part
32
+
33
+ # Get the function call data
34
+ function_data = function_call_part['functionCall']
35
+ return nil unless function_data
36
+
37
+ # Create a unique ID for the tool call
38
+ id = SecureRandom.uuid
39
+
40
+ # Return the tool call in the expected format
41
+ {
42
+ id => ToolCall.new(
43
+ id: id,
44
+ name: function_data['name'],
45
+ arguments: function_data['args']
46
+ )
47
+ }
48
+ end
49
+
50
+ private
51
+
52
+ # Format a single tool for Gemini API
53
+ def function_declaration_for(tool)
54
+ {
55
+ name: tool.name,
56
+ description: tool.description,
57
+ parameters: {
58
+ type: 'OBJECT',
59
+ properties: format_parameters(tool.parameters),
60
+ required: tool.parameters.select { |_, p| p.required }.keys.map(&:to_s)
61
+ }
62
+ }
63
+ end
64
+
65
+ # Format tool parameters for Gemini API
66
+ def format_parameters(parameters)
67
+ parameters.transform_values do |param|
68
+ {
69
+ type: param_type_for_gemini(param.type),
70
+ description: param.description
71
+ }.compact
72
+ end
73
+ end
74
+
75
+ # Convert RubyLLM param types to Gemini API types
76
+ def param_type_for_gemini(type)
77
+ case type.to_s.downcase
78
+ when 'integer', 'number', 'float' then 'NUMBER'
79
+ when 'boolean' then 'BOOLEAN'
80
+ when 'array' then 'ARRAY'
81
+ when 'object' then 'OBJECT'
82
+ else 'STRING'
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -2,20 +2,26 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Providers
5
- # Gemini API integration.
5
+ # Native Gemini API implementation
6
6
  module Gemini
7
- extend OpenAI
7
+ extend Provider
8
+ extend Gemini::Chat
9
+ extend Gemini::Embeddings
10
+ extend Gemini::Images
8
11
  extend Gemini::Models
12
+ extend Gemini::Streaming
13
+ extend Gemini::Tools
14
+ extend Gemini::Media
9
15
 
10
16
  module_function
11
17
 
12
18
  def api_base
13
- 'https://generativelanguage.googleapis.com/v1beta/openai'
19
+ 'https://generativelanguage.googleapis.com/v1beta'
14
20
  end
15
21
 
16
22
  def headers
17
23
  {
18
- 'Authorization' => "Bearer #{RubyLLM.config.gemini_api_key}"
24
+ 'x-goog-api-key' => RubyLLM.config.gemini_api_key
19
25
  }
20
26
  end
21
27
 
@@ -20,8 +20,6 @@ module RubyLLM
20
20
  }
21
21
  end
22
22
 
23
- private
24
-
25
23
  def parse_image_response(response)
26
24
  data = response.body
27
25
  image_data = data['data'].first
@@ -47,7 +47,7 @@ module RubyLLM
47
47
  ToolCall.new(
48
48
  id: tc.id,
49
49
  name: tc.name,
50
- arguments: JSON.parse(tc.arguments)
50
+ arguments: tc.arguments.is_a?(String) ? JSON.parse(tc.arguments) : tc.arguments
51
51
  )
52
52
  end
53
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLLM
4
- VERSION = '0.1.0.pre40'
4
+ VERSION = '0.1.0.pre42'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre40
4
+ version: 0.1.0.pre42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carmine Paolino
@@ -129,6 +129,7 @@ files:
129
129
  - lib/ruby_llm/providers/anthropic/capabilities.rb
130
130
  - lib/ruby_llm/providers/anthropic/chat.rb
131
131
  - lib/ruby_llm/providers/anthropic/embeddings.rb
132
+ - lib/ruby_llm/providers/anthropic/media.rb
132
133
  - lib/ruby_llm/providers/anthropic/models.rb
133
134
  - lib/ruby_llm/providers/anthropic/streaming.rb
134
135
  - lib/ruby_llm/providers/anthropic/tools.rb
@@ -136,7 +137,13 @@ files:
136
137
  - lib/ruby_llm/providers/deepseek/capabilities.rb
137
138
  - lib/ruby_llm/providers/gemini.rb
138
139
  - lib/ruby_llm/providers/gemini/capabilities.rb
140
+ - lib/ruby_llm/providers/gemini/chat.rb
141
+ - lib/ruby_llm/providers/gemini/embeddings.rb
142
+ - lib/ruby_llm/providers/gemini/images.rb
143
+ - lib/ruby_llm/providers/gemini/media.rb
139
144
  - lib/ruby_llm/providers/gemini/models.rb
145
+ - lib/ruby_llm/providers/gemini/streaming.rb
146
+ - lib/ruby_llm/providers/gemini/tools.rb
140
147
  - lib/ruby_llm/providers/openai.rb
141
148
  - lib/ruby_llm/providers/openai/capabilities.rb
142
149
  - lib/ruby_llm/providers/openai/chat.rb