summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2023-11-18 21:45:16 -0300
committericebaker <icebaker@proton.me>2023-11-18 21:45:16 -0300
commitc470d63b169058d81f44569a5f1c4c1fb222279f (patch)
tree8d2f520d4eb73e65a44e3815f36e38ff09943d52 /components
parent89962f27a75183947fc44cd051a1061ce157221d (diff)
adding support for confirm
Diffstat (limited to 'components')
-rw-r--r--components/embedding.rb2
-rw-r--r--components/providers/openai/tools.rb26
2 files changed, 25 insertions, 3 deletions
diff --git a/components/embedding.rb b/components/embedding.rb
index 46d0fba..f08ff3d 100644
--- a/components/embedding.rb
+++ b/components/embedding.rb
@@ -33,7 +33,7 @@ module NanoBot
path = "#{File.expand_path('../static/fennel', __dir__)}/?.lua"
state = SweetMoon::State.new(package_path: path).fennel
- # TODO: global is deprecated...
+ # TODO: `global` is deprecated.
state.fennel.eval(
"(global embedded (fn [#{parameters.join(' ')}] #{source}))", 1,
safety[:sandboxed] ? { allowedGlobals: %w[math string table] } : nil
diff --git a/components/providers/openai/tools.rb b/components/providers/openai/tools.rb
index 50eead9..10c2709 100644
--- a/components/providers/openai/tools.rb
+++ b/components/providers/openai/tools.rb
@@ -10,12 +10,34 @@ module NanoBot
module Providers
class OpenAI < Base
module Tools
+ def self.confirm(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] }
+ } } }
+ )
+ end
+
def self.apply(cartridge, function_cartridge, tools, feedback)
prepared_tools = NanoBot::Logic::OpenAI::Tools.prepare(function_cartridge, tools)
- # TODO: Confirm before starting futures.
+ if Logic::Cartridge::Safety.confirmable?(cartridge)
+ prepared_tools.each { |tool| tool[:allowed] = confirm(tool, feedback) }
+ else
+ prepared_tools.each { |tool| tool[:allowed] = true }
+ end
+
futures = prepared_tools.map do |tool|
- Concurrent::Promises.future { process!(tool, feedback, function_cartridge, cartridge) }
+ Concurrent::Promises.future do
+ if tool[:allowed]
+ process!(tool, feedback, function_cartridge, cartridge)
+ else
+ tool[:output] =
+ "We asked the user you're chatting with for permission, but the user did not allow you to run this tool or function."
+ tool
+ end
+ end
end
results = Concurrent::Promises.zip(*futures).value!