summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authoricebaker <113217272+icebaker@users.noreply.github.com>2023-12-16 21:20:59 -0300
committerGitHub <noreply@github.com>2023-12-16 21:20:59 -0300
commit21ebbebc06b5f8605ef5841849421f0fddfee72d (patch)
tree1f9b121ca28db627d079ad488adca41bc2ddaaa3 /components
parent3cfd5ee507ead55322cebe514b383ffc50c41728 (diff)
parent55a717a548375e7fed0b02fbd9d69aae167d98ec (diff)
Merge pull request #11 from icebaker/ib-repl
Improving REPL Experience
Diffstat (limited to 'components')
-rw-r--r--components/providers/google.rb58
1 files changed, 23 insertions, 35 deletions
diff --git a/components/providers/google.rb b/components/providers/google.rb
index a522d06..25ffbde 100644
--- a/components/providers/google.rb
+++ b/components/providers/google.rb
@@ -130,46 +130,34 @@ module NanoBot
end
end
- begin
- @client.stream_generate_content(
- 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
+ @client.stream_generate_content(
+ Logic::Google::Tokens.apply_policies!(cartridge, payload),
+ stream: true, &stream_call_back
+ )
+ if tools&.size&.positive?
feedback.call(
- { should_be_stored: !(content.nil? || content == ''),
- interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
- finished: true }
+ { should_be_stored: true,
+ needs_another_round: true,
+ interaction: { who: 'AI', message: nil, meta: { tool_calls: tools } } }
)
- rescue StandardError => e
- raise e.class, e.response[:body] if e.response && e.response[:body]
-
- raise e
+ 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
- else
- begin
- result = @client.stream_generate_content(
- Logic::Google::Tokens.apply_policies!(cartridge, payload),
- stream: false
- )
- rescue StandardError => e
- raise e.class, e.response[:body] if e.response && e.response[:body]
- raise e
- end
+ feedback.call(
+ { should_be_stored: !(content.nil? || content == ''),
+ interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
+ finished: true }
+ )
+ else
+ result = @client.stream_generate_content(
+ Logic::Google::Tokens.apply_policies!(cartridge, payload),
+ stream: false
+ )
tools = result.dig(0, 'candidates', 0, 'content', 'parts').filter do |part|
part.key?('functionCall')