summaryrefslogtreecommitdiff
path: root/components/providers
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2023-11-19 13:35:54 -0300
committericebaker <icebaker@proton.me>2023-11-19 13:35:54 -0300
commite89a1d57c49c94c16c37a8ee3a69b52a9e2b341b (patch)
treee82a7579534003f02de32d058f4a60d1d076240c /components/providers
parentc470d63b169058d81f44569a5f1c4c1fb222279f (diff)
improving tool specifications
Diffstat (limited to 'components/providers')
-rw-r--r--components/providers/openai.rb28
-rw-r--r--components/providers/openai/tools.rb10
2 files changed, 21 insertions, 17 deletions
diff --git a/components/providers/openai.rb b/components/providers/openai.rb
index 996f7f6..a7e7abe 100644
--- a/components/providers/openai.rb
+++ b/components/providers/openai.rb
@@ -37,15 +37,7 @@ module NanoBot
@client = ::OpenAI::Client.new(uri_base:, access_token: @credentials[:'access-token'])
end
- def stream(input)
- provider = @settings.key?(:stream) ? @settings[:stream] : true
-
- interface = input[:interface].key?(:stream) ? input[:interface][:stream] : true
-
- provider && interface
- end
-
- def evaluate(input, cartridge, &feedback)
+ def evaluate(input, streaming, cartridge, &feedback)
messages = input[:history].map do |event|
if event[:message].nil? && event[:meta] && event[:meta][:tool_calls]
{ role: 'assistant', content: nil, tool_calls: event[:meta][:tool_calls] }
@@ -76,7 +68,7 @@ module NanoBot
payload[:tools] = input[:tools].map { |raw| NanoBot::Logic::OpenAI::Tools.adapt(raw) } if input[:tools]
- if stream(input)
+ if streaming
content = ''
tools = []
@@ -135,9 +127,21 @@ module NanoBot
end
end
- @client.chat(parameters: payload)
+ begin
+ @client.chat(parameters: payload)
+ rescue StandardError => e
+ raise e.class, e.response[:body] if e.response && e.response[:body]
+
+ raise e
+ end
else
- result = @client.chat(parameters: payload)
+ begin
+ result = @client.chat(parameters: payload)
+ rescue StandardError => e
+ raise e.class, e.response[:body] if e.response && e.response[:body]
+
+ raise e
+ end
raise StandardError, result['error'] if result['error']
diff --git a/components/providers/openai/tools.rb b/components/providers/openai/tools.rb
index 10c2709..cd35e80 100644
--- a/components/providers/openai/tools.rb
+++ b/components/providers/openai/tools.rb
@@ -10,11 +10,11 @@ module NanoBot
module Providers
class OpenAI < Base
module Tools
- def self.confirm(tool, feedback)
+ def self.confirming(tool, feedback)
feedback.call(
{ should_be_stored: false,
interaction: { who: 'AI', message: nil, meta: {
- tool: { action: 'confirm', id: tool[:id], name: tool[:name], parameters: tool[:parameters] }
+ tool: { action: 'confirming', id: tool[:id], name: tool[:name], parameters: tool[:parameters] }
} } }
)
end
@@ -23,7 +23,7 @@ module NanoBot
prepared_tools = NanoBot::Logic::OpenAI::Tools.prepare(function_cartridge, tools)
if Logic::Cartridge::Safety.confirmable?(cartridge)
- prepared_tools.each { |tool| tool[:allowed] = confirm(tool, feedback) }
+ prepared_tools.each { |tool| tool[:allowed] = confirming(tool, feedback) }
else
prepared_tools.each { |tool| tool[:allowed] = true }
end
@@ -55,7 +55,7 @@ module NanoBot
feedback.call(
{ should_be_stored: false,
interaction: { who: 'AI', message: nil, meta: {
- tool: { action: 'call', id: tool[:id], name: tool[:name], parameters: tool[:parameters] }
+ tool: { action: 'executing', id: tool[:id], name: tool[:name], parameters: tool[:parameters] }
} } }
)
@@ -86,7 +86,7 @@ module NanoBot
{ should_be_stored: false,
interaction: { who: 'AI', message: nil, meta: {
tool: {
- action: 'response', id: tool[:id], name: tool[:name],
+ action: 'responding', id: tool[:id], name: tool[:name],
parameters: tool[:parameters], output: tool[:output]
}
} } }