nano-bots 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 158748eddde7df19233111d423ade5a4ce8d5eccc0e846fefa3c83aa02bdb1f0
4
- data.tar.gz: 57451266dd04a90fd0df74f49886ad940d58543dc3d0225ceeb548c08bdc93e8
3
+ metadata.gz: ed836839edfabe16e119f3f7e52ad82fbef851885d5adbb5b3097620d0491bfb
4
+ data.tar.gz: a4f909df92cb62b9d5882ad3c9419e0c4560a15f251fa37aae92814b0e586143
5
5
  SHA512:
6
- metadata.gz: 3e73d11ccd1d49abfb54779069a4a6a802ad21041ce09832221840353a799f358141db46f54e5eccd0416ea3f5ccda7c65c657022a3e6dd0e41ba1fcab91a429
7
- data.tar.gz: ec1bf4b5d26f57a95f931f23e98db0288af2883cb27d7bc1447ac4c65ab1052d7a4e9779b947c522e3f4c6a91ae1ca9f2f9a7c6c5ec8c0001c6019d2efa848ad
6
+ metadata.gz: 2c8f39d6d1b0362fb936b0ee0d3df73a6efb77ee3cb86c17c754f1a129d38c01034c2deff7f37f16143a17c28446fc4ebd868e047aaf616ab298b61d0310fa4e
7
+ data.tar.gz: 61ec7033e15173f2c74aeb830b48dcfaac676f7be282f3ebede3c198e710c7b92caad92649ddc84b7e3e665de2a74b4417c260aebb63caa0e0d0a3b7cdfb6fa6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nano-bots (0.0.2)
4
+ nano-bots (0.0.3)
5
5
  babosa (~> 2.0)
6
6
  dotenv (~> 2.8, >= 2.8.1)
7
7
  faraday (~> 2.7, >= 2.7.4)
@@ -48,7 +48,7 @@ GEM
48
48
  diff-lcs (>= 1.2.0, < 2.0)
49
49
  rspec-support (~> 3.12.0)
50
50
  rspec-support (3.12.0)
51
- rubocop (1.50.2)
51
+ rubocop (1.51.0)
52
52
  json (~> 2.3)
53
53
  parallel (~> 1.10)
54
54
  parser (>= 3.2.0.0)
data/README.md CHANGED
@@ -13,6 +13,8 @@ https://user-images.githubusercontent.com/113217272/237840989-1e29a5cc-6644-48d0
13
13
  - [Command Line](#command-line)
14
14
  - [Library](#library)
15
15
  - [Cartridges](#cartridges)
16
+ - [Providers](#providers)
17
+ - [Debugging](#debugging)
16
18
  - [Development](#development)
17
19
  - [Publish to RubyGems](#publish-to-rubygems)
18
20
 
@@ -21,13 +23,13 @@ https://user-images.githubusercontent.com/113217272/237840989-1e29a5cc-6644-48d0
21
23
  For a system usage:
22
24
 
23
25
  ```sh
24
- gem install nano-bots -v 0.0.2
26
+ gem install nano-bots -v 0.0.3
25
27
  ```
26
28
 
27
29
  To use it in a project, add it to your `Gemfile`:
28
30
 
29
31
  ```ruby
30
- gem 'nano-bots', '~> 0.0.2'
32
+ gem 'nano-bots', '~> 0.0.3'
31
33
  ```
32
34
 
33
35
  ```sh
@@ -41,11 +43,20 @@ export OPENAI_API_ADDRESS=https://api.openai.com
41
43
  export OPENAI_API_ACCESS_TOKEN=your-token
42
44
  export OPENAI_API_USER_IDENTIFIER=your-user
43
45
 
44
- export NANO_BOTS_STATE_DIRECTORY=/home/user/.local/state/nano-bots
45
- export NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
46
+ # export NANO_BOTS_STATE_DIRECTORY=/home/user/.local/state/nano-bots
47
+ # export NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
46
48
  ```
47
49
 
48
- Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded.
50
+ Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
51
+
52
+ ```sh
53
+ OPENAI_API_ADDRESS=https://api.openai.com
54
+ OPENAI_API_ACCESS_TOKEN=your-token
55
+ OPENAI_API_USER_IDENTIFIER=your-user
56
+
57
+ # NANO_BOTS_STATE_DIRECTORY=/home/user/.local/state/nano-bots
58
+ # NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
59
+ ```
49
60
 
50
61
  ## Docker
51
62
 
@@ -65,13 +76,14 @@ version: '3.7'
65
76
  services:
66
77
  nano-bots:
67
78
  image: ruby:3.2.2-slim-bullseye
68
- command: sh -c "gem install nano-bots -v 0.0.2 && bash"
79
+ command: sh -c "gem install nano-bots -v 0.0.3 && bash"
69
80
  environment:
70
81
  OPENAI_API_ADDRESS: https://api.openai.com
71
82
  OPENAI_API_ACCESS_TOKEN: your-token
72
83
  OPENAI_API_USER_IDENTIFIER: your-user
73
84
  volumes:
74
85
  - ./your-cartridges:/cartridges
86
+ # - ./your-data:/data
75
87
  ```
76
88
 
77
89
  Enter the container:
@@ -81,6 +93,10 @@ docker compose run nano-bots
81
93
 
82
94
  Start playing:
83
95
  ```sh
96
+ nb - - eval "hello"
97
+ nb - - repl
98
+
99
+ nb cartridges/assistant.yml - eval "hello"
84
100
  nb cartridges/assistant.yml - repl
85
101
  ```
86
102
 
@@ -93,6 +109,9 @@ After installing the gem, the `nb` binary command will be available for your pro
93
109
  Examples of usage:
94
110
 
95
111
  ```bash
112
+ nb - - eval "hello"
113
+ # => Hello! How may I assist you today?
114
+
96
115
  nb to-en-us-translator.yml - eval "Salut, comment ça va?"
97
116
  # => Hello, how are you doing?
98
117
 
@@ -115,6 +134,8 @@ cat article.txt |
115
134
  ```
116
135
 
117
136
  ```bash
137
+ nb - - repl
138
+
118
139
  nb assistant.yml - repl
119
140
  ```
120
141
 
@@ -145,6 +166,16 @@ require 'securerandom'
145
166
  SecureRandom.hex # => 6ea6c43c42a1c076b1e3c36fa349ac2c
146
167
  ```
147
168
 
169
+ ### Debugging
170
+
171
+ ```sh
172
+ nb - - cartridge
173
+ nb cartridge.yml - cartridge
174
+
175
+ nb - STATE-KEY state
176
+ nb cartridge.yml STATE-KEY state
177
+ ```
178
+
148
179
  ### Library
149
180
 
150
181
  To use it as a library:
@@ -198,6 +229,16 @@ provider:
198
229
 
199
230
  Check the Nano Bots specification to learn more about [how to build cartridges](https://icebaker.github.io/nano-bots/#/README?id=cartridges).
200
231
 
232
+ ## Providers
233
+
234
+ Currently supported providers:
235
+
236
+ - [ ] [Vicuna](https://github.com/lm-sys/FastChat)
237
+ - [x] [Open AI](https://platform.openai.com/docs/api-reference)
238
+ - [ ] [Google PaLM](https://developers.generativeai.google/)
239
+ - [ ] [Alpaca](https://github.com/tatsu-lab/stanford_alpaca)
240
+ - [ ] [LLaMA](https://github.com/facebookresearch/llama)
241
+
201
242
  ## Development
202
243
 
203
244
  ```bash
@@ -213,5 +254,5 @@ gem build nano-bots.gemspec
213
254
 
214
255
  gem signin
215
256
 
216
- gem push nano-bots-0.0.2.gem
257
+ gem push nano-bots-0.0.3.gem
217
258
  ```
@@ -19,7 +19,7 @@ module NanoBot
19
19
 
20
20
  path = "#{path.sub(%r{/$}, '')}/ruby-nano-bots/#{cartridge[:meta][:author].to_slug.normalize}"
21
21
  path = "#{path}/#{cartridge[:meta][:name].to_slug.normalize}"
22
- path = "#{path}/#{cartridge[:meta][:version].to_s.gsub('.', '-').to_slug.normalize}/#{key.to_slug.normalize}"
22
+ path = "#{path}/#{cartridge[:meta][:version].to_s.gsub('.', '-').to_slug.normalize}/#{key}"
23
23
  path = "#{path}/state.json"
24
24
 
25
25
  FileUtils.mkdir_p(File.dirname(path))
@@ -12,35 +12,64 @@ require_relative './session'
12
12
  module NanoBot
13
13
  module Controllers
14
14
  class Instance
15
- def initialize(cartridge_path:, state: nil)
15
+ def initialize(cartridge_path:, stream:, state: nil)
16
+ @stream = stream
17
+
16
18
  load_cartridge!(cartridge_path)
17
19
 
18
20
  provider = Components::Provider.new(@cartridge[:provider])
19
21
 
20
- @session = Session.new(provider:, cartridge: @cartridge, state:)
22
+ @session = Session.new(provider:, cartridge: @cartridge, state:, stream: @stream)
23
+ end
24
+
25
+ def cartridge
26
+ puts YAML.dump(@safe_cartridge)
21
27
  end
22
28
 
23
- def debug
24
- @session.debug
29
+ def state
30
+ @session.state
25
31
  end
26
32
 
27
33
  def eval(input)
28
34
  Interfaces::Eval.evaluate(input, @cartridge, @session)
35
+
36
+ return unless @stream.is_a?(StringIO)
37
+
38
+ @stream.flush
39
+ result = @stream.string.clone
40
+ @stream.truncate(0)
41
+ @stream.rewind
42
+ result
29
43
  end
30
44
 
31
45
  def repl
46
+ if @stream.is_a?(StringIO)
47
+ @stream.flush
48
+ @stream = $stdout
49
+ @session.stream = @stream
50
+ end
32
51
  Interfaces::REPL.start(@cartridge, @session)
33
52
  end
34
53
 
35
54
  private
36
55
 
37
56
  def load_cartridge!(path)
38
- @cartridge = Logic::Helpers::Hash.symbolize_keys(
39
- YAML.safe_load(
40
- File.read(Components::Storage.cartridge_path(path)),
41
- permitted_classes: [Symbol]
42
- )
43
- )
57
+ elected_path = if path.strip == '-'
58
+ File.expand_path('../static/cartridges/default.yml', __dir__)
59
+ else
60
+ Components::Storage.cartridge_path(path)
61
+ end
62
+
63
+ if elected_path.nil?
64
+ @stream.write("Cartridge file not found: \"#{path}\"\n")
65
+ raise StandardError, "Cartridge file not found: \"#{path}\""
66
+ end
67
+
68
+ @cartridge = YAML.safe_load(File.read(elected_path), permitted_classes: [Symbol])
69
+
70
+ @safe_cartridge = Marshal.load(Marshal.dump(@cartridge))
71
+
72
+ @cartridge = Logic::Helpers::Hash.symbolize_keys(@cartridge)
44
73
 
45
74
  inject_environment_variables!(@cartridge)
46
75
  end
@@ -13,20 +13,38 @@ module NanoBot
13
13
  puts NanoBot::GEM[:version]
14
14
  exit
15
15
  when 'help', '', nil
16
+ puts ''
16
17
  puts "Nano Bots #{NanoBot::GEM[:version]}"
17
- puts ' nb cartridge.yml - eval "Hello"'
18
+ puts ''
19
+ puts ' nb - - eval "hello"'
20
+ puts ' nb - - repl'
21
+ puts ''
22
+ puts ' nb cartridge.yml - eval "hello"'
18
23
  puts ' nb cartridge.yml - repl'
19
- puts ' nb cartridge.yml - debug'
20
- puts ' nb cartridge.yml STATE-KEY eval "Hello"'
24
+ puts ''
25
+ puts ' nb - STATE-KEY eval "hello"'
26
+ puts ' nb - STATE-KEY repl'
27
+ puts ''
28
+ puts ' nb cartridge.yml STATE-KEY eval "hello"'
21
29
  puts ' nb cartridge.yml STATE-KEY repl'
22
- puts ' nb cartridge.yml STATE-KEY debug'
30
+ puts ''
31
+ puts ' nb - - cartridge'
32
+ puts ' nb cartridge.yml - cartridge'
33
+ puts ''
34
+ puts ' nb - STATE-KEY state'
35
+ puts ' nb cartridge.yml STATE-KEY state'
36
+ puts ''
23
37
  puts ' nb version'
38
+ puts ' nb help'
39
+ puts ''
24
40
  exit
25
41
  end
26
42
 
27
43
  params = { cartridge_path: ARGV[0], state: ARGV[1], command: ARGV[2] }
28
44
 
29
- bot = Instance.new(cartridge_path: params[:cartridge_path], state: params[:state])
45
+ bot = Instance.new(
46
+ cartridge_path: params[:cartridge_path], state: params[:state], stream: $stdout
47
+ )
30
48
 
31
49
  case params[:command]
32
50
  when 'eval'
@@ -35,8 +53,10 @@ module NanoBot
35
53
  bot.eval(params[:input])
36
54
  when 'repl'
37
55
  bot.repl
38
- when 'debug'
39
- bot.debug
56
+ when 'state'
57
+ bot.state
58
+ when 'cartridge'
59
+ bot.cartridge
40
60
  else
41
61
  raise "TODO: [#{params[:command]}]"
42
62
  end
@@ -12,12 +12,13 @@ module NanoBot
12
12
  STREAM_TIMEOUT_IN_SECONDS = 5
13
13
 
14
14
  class Session
15
- def initialize(provider:, cartridge:, state: nil)
15
+ attr_accessor :stream
16
+
17
+ def initialize(provider:, cartridge:, state: nil, stream: $stdout)
18
+ @stream = stream
16
19
  @provider = provider
17
20
  @cartridge = cartridge
18
21
 
19
- @output = $stdout
20
-
21
22
  @stateless = state.nil? || state.strip == '-' || state.strip.empty?
22
23
 
23
24
  if @stateless
@@ -30,7 +31,7 @@ module NanoBot
30
31
  end
31
32
  end
32
33
 
33
- def debug
34
+ def state
34
35
  pp({
35
36
  state: {
36
37
  path: @state_path,
@@ -67,7 +68,7 @@ module NanoBot
67
68
  process(input, mode:)
68
69
  end
69
70
 
70
- def stream(interface)
71
+ def streaming(interface)
71
72
  provider = @provider.settings.key?(:stream) ? @provider.settings[:stream] : true
72
73
  interface = interface.key?(:stream) ? interface[:stream] : true
73
74
 
@@ -77,7 +78,7 @@ module NanoBot
77
78
  def process(input, mode:)
78
79
  interface = Logic::Helpers::Hash.fetch(@cartridge, [:interfaces, mode.to_sym]) || {}
79
80
 
80
- streaming = stream(interface)
81
+ streaming = streaming(interface)
81
82
 
82
83
  input[:interface] = interface
83
84
 
@@ -105,11 +106,11 @@ module NanoBot
105
106
  end
106
107
 
107
108
  def flush
108
- @output.flush
109
+ @stream.flush
109
110
  end
110
111
 
111
112
  def print(content)
112
- @output.write(content)
113
+ @stream.write(content)
113
114
  end
114
115
  end
115
116
  end
@@ -3,10 +3,11 @@ version: '3.7'
3
3
  services:
4
4
  nano-bots:
5
5
  image: ruby:3.2.2-slim-bullseye
6
- command: sh -c "gem install nano-bots -v 0.0.2 && bash"
6
+ command: sh -c "gem install nano-bots -v 0.0.3 && bash"
7
7
  environment:
8
8
  OPENAI_API_ADDRESS: https://api.openai.com
9
9
  OPENAI_API_ACCESS_TOKEN: your-token
10
10
  OPENAI_API_USER_IDENTIFIER: your-user
11
11
  volumes:
12
12
  - ./your-cartridges:/cartridges
13
+ # - ./your-data:/data
@@ -7,16 +7,16 @@ require_relative '../../controllers/instance'
7
7
  require_relative '../../controllers/interfaces/cli'
8
8
 
9
9
  module NanoBot
10
- def self.new(cartridge:, state: '-')
11
- Controllers::Instance.new(cartridge_path: cartridge, state:)
10
+ def self.new(cartridge: '-', state: '-')
11
+ Controllers::Instance.new(cartridge_path: cartridge, state:, stream: StringIO.new)
12
12
  end
13
13
 
14
14
  def self.cli
15
15
  Controllers::Interfaces::CLI.handle!
16
16
  end
17
17
 
18
- def self.repl(cartridge:, state: '-')
19
- Controllers::Instance.new(cartridge_path: cartridge, state:).repl
18
+ def self.repl(cartridge: '-', state: '-')
19
+ Controllers::Instance.new(cartridge_path: cartridge, state:, stream: $stdout).repl
20
20
  end
21
21
 
22
22
  def self.version
@@ -0,0 +1,14 @@
1
+ ---
2
+ meta:
3
+ name: Unknown
4
+ author: Nobody
5
+ version: 0.0.0
6
+
7
+ provider:
8
+ name: openai
9
+ settings:
10
+ model: gpt-3.5-turbo
11
+ credentials:
12
+ address: ENV/OPENAI_API_ADDRESS
13
+ access-token: ENV/OPENAI_API_ACCESS_TOKEN
14
+ user-identifier: ENV/OPENAI_API_USER_IDENTIFIER
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.2',
6
+ version: '0.0.3',
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.2
4
+ version: 0.0.3
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-12 00:00:00.000000000 Z
11
+ date: 2023-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: babosa
@@ -143,6 +143,7 @@ files:
143
143
  - nano-bots.gemspec
144
144
  - ports/dsl/nano-bots.rb
145
145
  - ports/dsl/nano-bots/cli.rb
146
+ - static/cartridges/default.yml
146
147
  - static/gem.rb
147
148
  homepage: https://github.com/icebaker/ruby-nano-bots
148
149
  licenses: