summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/providers/google.rb62
1 files changed, 25 insertions, 37 deletions
diff --git a/components/providers/google.rb b/components/providers/google.rb
index b15dd1b..a522d06 100644
--- a/components/providers/google.rb
+++ b/components/providers/google.rb
@@ -26,25 +26,9 @@ module NanoBot
def initialize(options, settings, credentials, _environment)
@settings = settings
- gemini_credentials = if credentials[:'api-key']
- {
- service: credentials[:service],
- api_key: credentials[:'api-key'],
- project_id: credentials[:'project-id'],
- region: credentials[:region]
- }
- else
- {
- service: credentials[:service],
- file_path: credentials[:'file-path'],
- project_id: credentials[:'project-id'],
- region: credentials[:region]
- }
- end
-
@client = Gemini.new(
- credentials: gemini_credentials,
- options: { model: options[:model], stream: options[:stream] }
+ credentials: credentials.transform_keys { |key| key.to_s.gsub('-', '_').to_sym },
+ options: options.transform_keys { |key| key.to_s.gsub('-', '_').to_sym }
)
end
@@ -70,6 +54,7 @@ module NanoBot
end
end
+ # TODO: Does Gemini have system messages?
%i[backdrop directive].each do |key|
next unless input[:behavior][key]
@@ -79,7 +64,6 @@ module NanoBot
_meta: { at: Time.now } }
)
- # TODO: Does Gemini have system messages?
messages.prepend(
{ role: 'user',
parts: { text: input[:behavior][key] },
@@ -140,24 +124,9 @@ module NanoBot
end
if event.dig('candidates', 0, 'finishReason')
- if tools&.size&.positive?
- feedback.call(
- { should_be_stored: true,
- needs_another_round: true,
- interaction: { who: 'AI', message: nil, meta: { tool_calls: tools } } }
- )
- Tools.apply(
- cartridge, input[:tools], tools, feedback, Logic::Google::Tools
- ).each do |interaction|
- feedback.call({ should_be_stored: true, needs_another_round: true, interaction: })
- end
- end
-
- feedback.call(
- { should_be_stored: !(content.nil? || content == ''),
- interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
- finished: true }
- )
+ # TODO: This does not have the same behavior as OpenAI, so you should
+ # not use it as a reference for the end of the streaming.
+ # Is this a bug from the Google Gemini REST API or expected behavior?
end
end
@@ -166,6 +135,25 @@ module NanoBot
Logic::Google::Tokens.apply_policies!(cartridge, payload),
stream: true, &stream_call_back
)
+
+ if tools&.size&.positive?
+ feedback.call(
+ { should_be_stored: true,
+ needs_another_round: true,
+ interaction: { who: 'AI', message: nil, meta: { tool_calls: tools } } }
+ )
+ Tools.apply(
+ cartridge, input[:tools], tools, feedback, Logic::Google::Tools
+ ).each do |interaction|
+ feedback.call({ should_be_stored: true, needs_another_round: true, interaction: })
+ end
+ end
+
+ feedback.call(
+ { should_be_stored: !(content.nil? || content == ''),
+ interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
+ finished: true }
+ )
rescue StandardError => e
raise e.class, e.response[:body] if e.response && e.response[:body]