nano-bots 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ef7d964a5303c4cf07054210b720b5e57eede718ce549cb697331911577e884
4
- data.tar.gz: bcfad5aec3b82903fc144d58d37640458bb97e957bddd5deabf46bc890d3a1e7
3
+ metadata.gz: 58071f1bd32ba3fb2bfe58b64b392139724f3cd97ab72e8822b3db7ebd4779bc
4
+ data.tar.gz: 60f24c528ced7f151996431288fee4c08b49e099d4fba46181d530ca2fa34581
5
5
  SHA512:
6
- metadata.gz: 816c65f1d09e912d76dfd5e651e9ae17fa9e0bb4fcbfd0932ef6498922c2c4d20422c329dfd239af90ccdd00dc8d1eb03a15ac723f0907e19fbecc79b4fcb2ad
7
- data.tar.gz: b3254fb89ddfc4d69139130388150e986b2f750a3f56e6a068d211bff6db7413ed47b536dcbc84b04fde1c1679ea5968c7cf63e4ba62d72f07c436d64d21b611
6
+ metadata.gz: 02ed6e915d64df284189cfb599e868364ffacffb3b4e5323c77ec284173d0c74f58a925eb292b834184dac523d150bac8670b1414041872c545f51867ea1690d
7
+ data.tar.gz: da8c4426fb19e1f1516eb76647bd179669cfae3640b9d83df4d3f1ed1157127efccee58704fa88870129666f19b211c43558a64ce68cd4b86ca6249b2cc63ae8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nano-bots (0.0.5)
4
+ nano-bots (0.0.6)
5
5
  babosa (~> 2.0)
6
6
  dotenv (~> 2.8, >= 2.8.1)
7
7
  faraday (~> 2.7, >= 2.7.4)
@@ -64,13 +64,13 @@ GEM
64
64
  parser (>= 3.2.1.0)
65
65
  rubocop-capybara (2.18.0)
66
66
  rubocop (~> 1.41)
67
- rubocop-factory_bot (2.22.0)
67
+ rubocop-factory_bot (2.23.1)
68
68
  rubocop (~> 1.33)
69
69
  rubocop-rspec (2.22.0)
70
70
  rubocop (~> 1.33)
71
71
  rubocop-capybara (~> 2.17)
72
72
  rubocop-factory_bot (~> 2.22)
73
- ruby-openai (4.0.0)
73
+ ruby-openai (4.1.0)
74
74
  faraday (>= 1)
75
75
  faraday-multipart (>= 1)
76
76
  ruby-progressbar (1.13.0)
data/README.md CHANGED
@@ -23,13 +23,13 @@ https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b
23
23
  For a system usage:
24
24
 
25
25
  ```sh
26
- gem install nano-bots -v 0.0.5
26
+ gem install nano-bots -v 0.0.6
27
27
  ```
28
28
 
29
29
  To use it in a project, add it to your `Gemfile`:
30
30
 
31
31
  ```ruby
32
- gem 'nano-bots', '~> 0.0.5'
32
+ gem 'nano-bots', '~> 0.0.6'
33
33
  ```
34
34
 
35
35
  ```sh
@@ -76,7 +76,7 @@ version: '3.7'
76
76
  services:
77
77
  nano-bots:
78
78
  image: ruby:3.2.2-slim-bullseye
79
- command: sh -c "gem install nano-bots -v 0.0.5 && bash"
79
+ command: sh -c "gem install nano-bots -v 0.0.6 && bash"
80
80
  environment:
81
81
  OPENAI_API_ADDRESS: https://api.openai.com
82
82
  OPENAI_API_ACCESS_TOKEN: your-token
@@ -254,5 +254,5 @@ gem build nano-bots.gemspec
254
254
 
255
255
  gem signin
256
256
 
257
- gem push nano-bots-0.0.5.gem
257
+ gem push nano-bots-0.0.6.gem
258
258
  ```
@@ -29,6 +29,13 @@ module NanoBot
29
29
  path
30
30
  end
31
31
 
32
+ def self.cartridges_path
33
+ [
34
+ ENV.fetch('NANO_BOTS_CARTRIDGES_DIRECTORY', nil),
35
+ "#{user_home!.sub(%r{/$}, '')}/.local/share/nano-bots/cartridges"
36
+ ].uniq.filter { |path| File.directory?(path) }.compact.first
37
+ end
38
+
32
39
  def self.cartridge_path(path)
33
40
  partial = File.join(File.dirname(path), File.basename(path, File.extname(path)))
34
41
 
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+
5
+ module NanoBot
6
+ module Components
7
+ class Stream < StringIO
8
+ def write(*args)
9
+ if @callback
10
+ @accumulated += args.first
11
+ @callback.call(@accumulated, args.first, false)
12
+ end
13
+ super
14
+ end
15
+
16
+ def callback=(block)
17
+ @accumulated = ''
18
+ @callback = block
19
+ end
20
+
21
+ def finish
22
+ flush
23
+ result = string.clone
24
+ truncate(0)
25
+ rewind
26
+
27
+ if @callback
28
+ @callback.call(@accumulated, nil, true)
29
+ @callback = nil
30
+ @accumulated = nil
31
+ end
32
+
33
+ result
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../components/storage'
4
+ require_relative '../logic/helpers/hash'
5
+ require_relative '../logic/cartridge/default'
6
+
7
+ module NanoBot
8
+ module Controllers
9
+ class Cartridges
10
+ def self.all
11
+ files = {}
12
+
13
+ path = Components::Storage.cartridges_path
14
+
15
+ Dir.glob("#{path}/**/*.{yml,yaml}").each do |file|
16
+ files[Pathname.new(file).realpath] = {
17
+ base: path,
18
+ path: Pathname.new(file).realpath
19
+ }
20
+ end
21
+
22
+ cartridges = []
23
+
24
+ files.values.uniq.map do |file|
25
+ cartridge = Logic::Helpers::Hash.symbolize_keys(
26
+ YAML.safe_load(File.read(file[:path]), permitted_classes: [Symbol])
27
+ ).merge({
28
+ system: {
29
+ id: file[:path].to_s.sub(/^#{Regexp.escape(file[:base])}/, '').sub(%r{^/}, '').sub(/\.[^.]+\z/,
30
+ ''),
31
+ path: file[:path],
32
+ base: file[:base]
33
+ }
34
+ })
35
+
36
+ next if cartridge[:meta][:name].nil?
37
+
38
+ cartridges << cartridge
39
+ rescue StandardError => _e
40
+ end
41
+
42
+ cartridges.sort_by { |cartridge| cartridge[:meta][:name] }
43
+
44
+ cartridges.prepend(
45
+ { system: { id: '-' }, meta: { name: 'Default', symbol: '🤖' } }
46
+ )
47
+
48
+ cartridges
49
+ end
50
+ end
51
+ end
52
+ end
@@ -5,6 +5,7 @@ require 'yaml'
5
5
  require_relative '../logic/helpers/hash'
6
6
  require_relative '../components/provider'
7
7
  require_relative '../components/storage'
8
+ require_relative '../components/stream'
8
9
  require_relative './interfaces/repl'
9
10
  require_relative './interfaces/eval'
10
11
  require_relative './session'
@@ -30,16 +31,14 @@ module NanoBot
30
31
  @session.state
31
32
  end
32
33
 
33
- def eval(input)
34
+ def eval(input, &block)
35
+ @stream.callback = block if block && @stream.is_a?(Components::Stream)
36
+
34
37
  Interfaces::Eval.evaluate(input, @cartridge, @session)
35
38
 
36
- return unless @stream.is_a?(StringIO)
39
+ return unless @stream.is_a?(Components::Stream)
37
40
 
38
- @stream.flush
39
- result = @stream.string.clone
40
- @stream.truncate(0)
41
- @stream.rewind
42
- result
41
+ @stream.finish
43
42
  end
44
43
 
45
44
  def repl
@@ -3,7 +3,7 @@ version: '3.7'
3
3
  services:
4
4
  nano-bots:
5
5
  image: ruby:3.2.2-slim-bullseye
6
- command: sh -c "apt-get update && apt-get install -y --no-install-recommends build-essential libffi-dev lua5.4-dev && gem install nano-bots -v 0.0.5 && bash"
6
+ command: sh -c "apt-get update && apt-get install -y --no-install-recommends build-essential libffi-dev lua5.4-dev && gem install nano-bots -v 0.0.6 && bash"
7
7
  environment:
8
8
  OPENAI_API_ADDRESS: https://api.openai.com
9
9
  OPENAI_API_ACCESS_TOKEN: your-token
@@ -3,12 +3,18 @@
3
3
  require 'dotenv/load'
4
4
 
5
5
  require_relative '../../static/gem'
6
+ require_relative '../../controllers/cartridges'
6
7
  require_relative '../../controllers/instance'
7
8
  require_relative '../../controllers/interfaces/cli'
9
+ require_relative '../../components/stream'
8
10
 
9
11
  module NanoBot
10
12
  def self.new(cartridge: '-', state: '-')
11
- Controllers::Instance.new(cartridge_path: cartridge, state:, stream: StringIO.new)
13
+ Controllers::Instance.new(cartridge_path: cartridge, state:, stream: Components::Stream.new)
14
+ end
15
+
16
+ def self.cartridges
17
+ Controllers::Cartridges.all
12
18
  end
13
19
 
14
20
  def self.cli
data/static/gem.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module NanoBot
4
4
  GEM = {
5
5
  name: 'nano-bots',
6
- version: '0.0.5',
6
+ version: '0.0.6',
7
7
  author: 'icebaker',
8
8
  summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots',
9
9
  description: 'Ruby Implementation of Nano Bots: small, AI-powered bots easily shared as a single file, designed to support multiple providers such as Vicuna, OpenAI ChatGPT, Google PaLM, Alpaca, and LLaMA.',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nano-bots
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - icebaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-13 00:00:00.000000000 Z
11
+ date: 2023-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: babosa
@@ -148,6 +148,8 @@ files:
148
148
  - components/providers/base.rb
149
149
  - components/providers/openai.rb
150
150
  - components/storage.rb
151
+ - components/stream.rb
152
+ - controllers/cartridges.rb
151
153
  - controllers/instance.rb
152
154
  - controllers/interfaces/cli.rb
153
155
  - controllers/interfaces/eval.rb