summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2023-12-07 20:38:49 -0300
committericebaker <icebaker@proton.me>2023-12-07 20:38:49 -0300
commit9d9702b39db67ab66894e5483a267a05ea0f6a2d (patch)
tree165e52d98ade38c10eb7de91120208f0293a140c
parent6a6b154f0453875d09bbf86127c475a2b9020aa7 (diff)
adding tools medatada
-rw-r--r--Gemfile.lock8
-rw-r--r--README.md4
-rw-r--r--components/providers/openai.rb2
-rw-r--r--components/stream.rb4
-rw-r--r--controllers/interfaces/tools.rb5
-rw-r--r--controllers/session.rb21
-rw-r--r--nano-bots.gemspec2
-rw-r--r--static/cartridges/default.yml2
8 files changed, 32 insertions, 16 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index b390ae7..a095e90 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -9,7 +9,7 @@ PATH
pry (~> 0.14.2)
rainbow (~> 3.1, >= 3.1.1)
rbnacl (~> 7.1, >= 7.1.1)
- ruby-openai (~> 6.3)
+ ruby-openai (~> 6.3, >= 6.3.1)
sweet-moon (~> 0.0.7)
GEM
@@ -32,7 +32,7 @@ GEM
multipart-post (~> 2)
faraday-net_http (3.0.2)
ffi (1.16.3)
- json (2.7.0)
+ json (2.7.1)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
multipart-post (2.3.0)
@@ -50,7 +50,7 @@ GEM
rainbow (3.1.1)
rbnacl (7.1.1)
ffi
- regexp_parser (2.8.2)
+ regexp_parser (2.8.3)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
@@ -86,7 +86,7 @@ GEM
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
- ruby-openai (6.3.0)
+ ruby-openai (6.3.1)
event_stream_parser (>= 0.3.0, < 2.0.0)
faraday (>= 1)
faraday-multipart (>= 1)
diff --git a/README.md b/README.md
index bcb3b61..d16b0d2 100644
--- a/README.md
+++ b/README.md
@@ -218,7 +218,7 @@ bot.eval('Hello', as: 'eval')
bot.eval('Hello', as: 'repl')
# When stream is enabled and available:
-bot.eval('Hi!') do |content, fragment, finished|
+bot.eval('Hi!') do |content, fragment, finished, meta|
print fragment unless fragment.nil?
end
@@ -235,7 +235,7 @@ bot.boot
bot.boot(as: 'eval')
bot.boot(as: 'repl')
-bot.boot do |content, fragment, finished|
+bot.boot do |content, fragment, finished, meta|
print fragment unless fragment.nil?
end
```
diff --git a/components/providers/openai.rb b/components/providers/openai.rb
index 87f2bc5..6384181 100644
--- a/components/providers/openai.rb
+++ b/components/providers/openai.rb
@@ -49,7 +49,7 @@ module NanoBot
end
end
- %i[instruction backdrop directive].each do |key|
+ %i[backdrop directive].each do |key|
next unless input[:behavior][key]
messages.prepend(
diff --git a/components/stream.rb b/components/stream.rb
index 347eb87..73da8b0 100644
--- a/components/stream.rb
+++ b/components/stream.rb
@@ -13,9 +13,9 @@ module NanoBot
@accumulated = "#{@accumulated.force_encoding('UTF-8')}#{args.first.force_encoding('UTF-8')}"
end
- @callback.call(@accumulated, args.first, false)
+ @callback.call(@accumulated, args.first, false, args[1])
end
- super
+ super(args.first)
end
def callback=(block)
diff --git a/controllers/interfaces/tools.rb b/controllers/interfaces/tools.rb
index f079a2b..0f33105 100644
--- a/controllers/interfaces/tools.rb
+++ b/controllers/interfaces/tools.rb
@@ -72,7 +72,10 @@ module NanoBot
message = "#{adapter[:prefix]}#{message}#{adapter[:suffix]}"
- session.print(color.nil? ? message : Rainbow(message).send(color))
+ session.print(
+ color.nil? ? message : Rainbow(message).send(color),
+ { tool: { action: feedback[:action].to_s } }
+ )
end
def self.adapter(cartridge, mode, feedback)
diff --git a/controllers/session.rb b/controllers/session.rb
index 378a11d..aabcb41 100644
--- a/controllers/session.rb
+++ b/controllers/session.rb
@@ -11,6 +11,7 @@ require_relative '../logic/cartridge/streaming'
require_relative '../logic/cartridge/interaction'
require_relative '../logic/cartridge/fetch'
require_relative 'interfaces/tools'
+require_relative '../components/stream'
require_relative '../components/storage'
require_relative '../components/adapter'
require_relative '../components/crypto'
@@ -56,11 +57,19 @@ module NanoBot
end
def boot(mode:)
- return unless Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors boot instruction])
+ instruction = Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors boot instruction])
+ return unless instruction
behavior = Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors boot]) || {}
- input = { behavior:, history: [] }
+ @state[:history] << {
+ who: 'user',
+ mode: mode.to_s,
+ input: instruction,
+ message: instruction
+ }
+
+ input = { behavior:, history: @state[:history] }
process(input, mode:)
end
@@ -182,8 +191,12 @@ module NanoBot
@stream.flush
end
- def print(content)
- @stream.write(content)
+ def print(content, meta = nil)
+ if @stream.is_a?(NanoBot::Components::Stream)
+ @stream.write(content, meta)
+ else
+ @stream.write(content)
+ end
end
end
end
diff --git a/nano-bots.gemspec b/nano-bots.gemspec
index 281b1b2..8cd70d3 100644
--- a/nano-bots.gemspec
+++ b/nano-bots.gemspec
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'pry', '~> 0.14.2'
spec.add_dependency 'rainbow', '~> 3.1', '>= 3.1.1'
spec.add_dependency 'rbnacl', '~> 7.1', '>= 7.1.1'
- spec.add_dependency 'ruby-openai', '~> 6.3'
+ spec.add_dependency 'ruby-openai', '~> 6.3', '>= 6.3.1'
spec.add_dependency 'sweet-moon', '~> 0.0.7'
spec.metadata['rubygems_mfa_required'] = 'true'
diff --git a/static/cartridges/default.yml b/static/cartridges/default.yml
index 864d62b..98dd47b 100644
--- a/static/cartridges/default.yml
+++ b/static/cartridges/default.yml
@@ -9,8 +9,8 @@ interfaces:
repl:
output:
stream: true
- suffix: "\n"
prefix: "\n"
+ suffix: "\n"
prompt:
- text: '🤖'
- text: '> '