summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2023-11-18 19:29:03 -0300
committericebaker <icebaker@proton.me>2023-11-18 19:29:03 -0300
commit989c276b6acf9d0e2b584d980b72a4eb9564a77c (patch)
tree0bc0d849fad940f1aa041e42fbf14a031062acc0
parent2cc2aef7011036e16dae89212455a504132d49c1 (diff)
fixing TODOs
-rw-r--r--components/providers/openai.rb1
-rw-r--r--controllers/interfaces/cli.rb2
-rw-r--r--controllers/session.rb28
-rw-r--r--logic/providers/openai/tools.rb4
4 files changed, 20 insertions, 15 deletions
diff --git a/components/providers/openai.rb b/components/providers/openai.rb
index 437114c..bf5ae73 100644
--- a/components/providers/openai.rb
+++ b/components/providers/openai.rb
@@ -40,7 +40,6 @@ module NanoBot
def stream(input)
provider = @settings.key?(:stream) ? @settings[:stream] : true
- # TODO: There's a bug here...
interface = input[:interface].key?(:stream) ? input[:interface][:stream] : true
provider && interface
diff --git a/controllers/interfaces/cli.rb b/controllers/interfaces/cli.rb
index ae066cd..5b39c2a 100644
--- a/controllers/interfaces/cli.rb
+++ b/controllers/interfaces/cli.rb
@@ -81,7 +81,7 @@ module NanoBot
when 'cartridge'
puts YAML.dump(bot.cartridge)
else
- raise "TODO: [#{params[:command]}]"
+ raise "Command not found: [#{params[:command]}]"
end
end
end
diff --git a/controllers/session.rb b/controllers/session.rb
index d20deb2..10d0194 100644
--- a/controllers/session.rb
+++ b/controllers/session.rb
@@ -17,6 +17,7 @@ require_relative '../components/crypto'
module NanoBot
module Controllers
STREAM_TIMEOUT_IN_SECONDS = 5
+ INFINITE_LOOP_PREVENTION = 10
class Session
attr_accessor :stream
@@ -88,8 +89,13 @@ module NanoBot
needs_another_round = true
- # TODO: Improve infinite loop prevention.
- needs_another_round = process_interaction(input, mode:) while needs_another_round
+ rounds = 0
+
+ while needs_another_round
+ needs_another_round = process_interaction(input, mode:)
+ rounds += 1
+ raise StandardError, 'infinite loop prevention' if rounds > INFINITE_LOOP_PREVENTION
+ end
end
def process_interaction(input, mode:)
@@ -137,22 +143,20 @@ module NanoBot
end
@state[:history] << event if feedback[:should_be_stored]
- if event[:output] && ((!feedback[:finished] && streaming) || (!streaming && feedback[:finished]))
- # TODO: Color?
- if color
- self.print(Rainbow(event[:output]).send(color))
- else
- self.print(event[:output])
- end
- flush if feedback[:finished]
+ if event[:output] && ((!feedback[:finished] && streaming) || (!streaming && feedback[:finished]))
+ self.print(color ? Rainbow(event[:output]).send(color) : event[:output])
end
- # `.print` already adds a prefix and suffix, so we add them after printing to avoid duplications.
+ # The `print` function already outputs a prefix and a suffix, so
+ # we should add them afterwards to avoid printing them twice.
event[:output] = "#{prefix}#{event[:output]}#{suffix}"
end
- ready = true if feedback[:finished]
+ if feedback[:finished]
+ flush
+ ready = true
+ end
end
until ready
diff --git a/logic/providers/openai/tools.rb b/logic/providers/openai/tools.rb
index 080d81e..1aa9029 100644
--- a/logic/providers/openai/tools.rb
+++ b/logic/providers/openai/tools.rb
@@ -10,8 +10,10 @@ module NanoBot
module Tools
def self.prepare(cartridge, tools)
applies = []
+
+ tools = Marshal.load(Marshal.dump(tools))
+
tools.each do |tool|
- # TODO: Does this mutate the hash?
tool = Helpers::Hash.symbolize_keys(tool)
cartridge.each do |candidate|