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.
- checksums.yaml +4 -4
- data/.rspec_status +7 -4
- data/README.md +24 -1
- data/lib/ruby_llm/content.rb +24 -1
- data/lib/ruby_llm/models.json +345 -452
- data/lib/ruby_llm/provider.rb +1 -2
- data/lib/ruby_llm/providers/anthropic/chat.rb +1 -1
- data/lib/ruby_llm/providers/anthropic/media.rb +66 -0
- data/lib/ruby_llm/providers/anthropic.rb +1 -0
- data/lib/ruby_llm/providers/gemini/chat.rb +140 -0
- data/lib/ruby_llm/providers/gemini/embeddings.rb +53 -0
- data/lib/ruby_llm/providers/gemini/images.rb +51 -0
- data/lib/ruby_llm/providers/gemini/media.rb +136 -0
- data/lib/ruby_llm/providers/gemini/models.rb +41 -6
- data/lib/ruby_llm/providers/gemini/streaming.rb +99 -0
- data/lib/ruby_llm/providers/gemini/tools.rb +88 -0
- data/lib/ruby_llm/providers/gemini.rb +10 -4
- data/lib/ruby_llm/providers/openai/images.rb +0 -2
- data/lib/ruby_llm/stream_accumulator.rb +1 -1
- data/lib/ruby_llm/version.rb +1 -1
- metadata +8 -1
@@ -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
|
5
|
+
# Native Gemini API implementation
|
6
6
|
module Gemini
|
7
|
-
extend
|
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
|
19
|
+
'https://generativelanguage.googleapis.com/v1beta'
|
14
20
|
end
|
15
21
|
|
16
22
|
def headers
|
17
23
|
{
|
18
|
-
'
|
24
|
+
'x-goog-api-key' => RubyLLM.config.gemini_api_key
|
19
25
|
}
|
20
26
|
end
|
21
27
|
|
data/lib/ruby_llm/version.rb
CHANGED
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.
|
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
|