nano-bots 0.0.7 → 0.0.8
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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +41 -7
- data/controllers/instance.rb +16 -2
- data/controllers/interfaces/eval.rb +4 -4
- data/controllers/interfaces/repl.rb +17 -8
- data/controllers/session.rb +11 -1
- data/docker-compose.example.yml +1 -1
- data/nano-bots.gemspec +1 -1
- data/static/gem.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d496441fb846ecb3deb69ecfaee74d929ee7cfab8d8f7ad779da9ebc84dd970
|
4
|
+
data.tar.gz: 6d96a3b14b471f8b5f3e616c036a95e4fba9a36f1f608d0eddf263b4401a5b3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c04eec85e715e87030ae6b9e3f070ee760392b78719747215f12adf1ac0368452a4f9c6381a8382246ecc11b50830ede50a879c191212006b3593bf3e2bd92e
|
7
|
+
data.tar.gz: '08de387499a77c6e955d90d5f53f02a8fd5197b30df520952d9abbaa9731e324b3e73ccaae8f0c8da29325955319bb727a8790a68103273d12dd0953e7e64e5e'
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nano-bots (0.0.
|
4
|
+
nano-bots (0.0.8)
|
5
5
|
babosa (~> 2.0)
|
6
6
|
dotenv (~> 2.8, >= 2.8.1)
|
7
|
-
faraday (~> 2.7, >= 2.7.
|
7
|
+
faraday (~> 2.7, >= 2.7.5)
|
8
8
|
pry (~> 0.14.2)
|
9
9
|
rainbow (~> 3.1, >= 3.1.1)
|
10
10
|
ruby-openai (~> 4.0)
|
@@ -18,7 +18,7 @@ GEM
|
|
18
18
|
coderay (1.1.3)
|
19
19
|
diff-lcs (1.5.0)
|
20
20
|
dotenv (2.8.1)
|
21
|
-
faraday (2.7.
|
21
|
+
faraday (2.7.5)
|
22
22
|
faraday-net_http (>= 2.0, < 3.1)
|
23
23
|
ruby2_keywords (>= 0.0.4)
|
24
24
|
faraday-multipart (1.0.4)
|
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.
|
26
|
+
gem install nano-bots -v 0.0.8
|
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.
|
32
|
+
gem 'nano-bots', '~> 0.0.8'
|
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.
|
79
|
+
command: sh -c "gem install nano-bots -v 0.0.8 && bash"
|
80
80
|
environment:
|
81
81
|
OPENAI_API_ADDRESS: https://api.openai.com
|
82
82
|
OPENAI_API_ACCESS_TOKEN: your-token
|
@@ -193,13 +193,40 @@ NanoBot.repl(cartridge: 'cartridge.yml') # Starts a new REPL.
|
|
193
193
|
|
194
194
|
bot = NanoBot.new(cartridge: 'cartridge.yml')
|
195
195
|
|
196
|
+
bot = NanoBot.new(
|
197
|
+
cartridge: YAML.safe_load(File.read('cartridge.yml'), permitted_classes: [Symbol])
|
198
|
+
)
|
199
|
+
|
200
|
+
bot = NanoBot.new(
|
201
|
+
cartridge: { ... } # Parsed Cartridge Hash
|
202
|
+
)
|
203
|
+
|
196
204
|
bot.eval('Hello')
|
197
205
|
|
206
|
+
bot.eval('Hello', as: 'eval')
|
207
|
+
bot.eval('Hello', as: 'repl')
|
208
|
+
|
209
|
+
# When stream is enabled and available:
|
210
|
+
bot.eval('Hi!') do |content, fragment, finished|
|
211
|
+
print fragment unless fragment.nil?
|
212
|
+
end
|
213
|
+
|
198
214
|
bot.repl # Starts a new REPL.
|
199
215
|
|
200
216
|
NanoBot.repl(cartridge: 'cartridge.yml', state: '6ea6c43c42a1c076b1e3c36fa349ac2c')
|
201
217
|
|
202
218
|
bot = NanoBot.new(cartridge: 'cartridge.yml', state: '6ea6c43c42a1c076b1e3c36fa349ac2c')
|
219
|
+
|
220
|
+
bot.prompt # => "🤖\u001b[34m> \u001b[0m"
|
221
|
+
|
222
|
+
bot.boot
|
223
|
+
|
224
|
+
bot.boot(as: 'eval')
|
225
|
+
bot.boot(as: 'repl')
|
226
|
+
|
227
|
+
bot.boot do |content, fragment, finished|
|
228
|
+
print fragment unless fragment.nil?
|
229
|
+
end
|
203
230
|
```
|
204
231
|
|
205
232
|
## Cartridges
|
@@ -209,9 +236,12 @@ Here's what a Nano Bot Cartridge looks like:
|
|
209
236
|
```yaml
|
210
237
|
---
|
211
238
|
meta:
|
239
|
+
symbol: 🤖
|
212
240
|
name: Nano Bot Name
|
213
241
|
author: Your Name
|
214
|
-
version: 0.0
|
242
|
+
version: 1.0.0
|
243
|
+
license: CC0-1.0
|
244
|
+
description: A helpful assistant.
|
215
245
|
|
216
246
|
behaviors:
|
217
247
|
interaction:
|
@@ -227,18 +257,22 @@ provider:
|
|
227
257
|
user-identifier: ENV/OPENAI_API_USER_IDENTIFIER
|
228
258
|
```
|
229
259
|
|
230
|
-
Check the Nano Bots specification to learn more about [how to build cartridges](https://
|
260
|
+
Check the Nano Bots specification to learn more about [how to build cartridges](https://spec.nbots.io/#/README?id=cartridges).
|
261
|
+
|
262
|
+
Try the [Nano Bots Clinic (Live Editor)](https://clinic.nbots.io) to learn about creating Cartridges.
|
231
263
|
|
232
264
|
## Providers
|
233
265
|
|
234
266
|
Currently supported providers:
|
235
267
|
|
236
|
-
- [
|
268
|
+
- [x] [FastChat (Vicuna)](https://github.com/lm-sys/FastChat)
|
237
269
|
- [x] [Open AI](https://platform.openai.com/docs/api-reference)
|
238
270
|
- [ ] [Google PaLM](https://developers.generativeai.google/)
|
239
271
|
- [ ] [Alpaca](https://github.com/tatsu-lab/stanford_alpaca)
|
240
272
|
- [ ] [LLaMA](https://github.com/facebookresearch/llama)
|
241
273
|
|
274
|
+
Although only OpenAI has been officially tested, some of the open-source providers offer APIs that are compatible with OpenAI, such as [FastChat](https://github.com/lm-sys/FastChat#openai-compatible-restful-apis--sdk). Therefore, it is highly probable that they will work just fine.
|
275
|
+
|
242
276
|
## Development
|
243
277
|
|
244
278
|
```bash
|
@@ -254,5 +288,5 @@ gem build nano-bots.gemspec
|
|
254
288
|
|
255
289
|
gem signin
|
256
290
|
|
257
|
-
gem push nano-bots-0.0.
|
291
|
+
gem push nano-bots-0.0.8.gem
|
258
292
|
```
|
data/controllers/instance.rb
CHANGED
@@ -31,10 +31,24 @@ module NanoBot
|
|
31
31
|
@session.state
|
32
32
|
end
|
33
33
|
|
34
|
-
def eval
|
34
|
+
def boot(as: 'eval', &block)
|
35
35
|
@stream.callback = block if block && @stream.is_a?(Components::Stream)
|
36
36
|
|
37
|
-
Interfaces::
|
37
|
+
Interfaces::REPL.boot(@cartridge, @session, as:)
|
38
|
+
|
39
|
+
return unless @stream.is_a?(Components::Stream)
|
40
|
+
|
41
|
+
@stream.finish
|
42
|
+
end
|
43
|
+
|
44
|
+
def prompt
|
45
|
+
Interfaces::REPL.prompt(@cartridge)
|
46
|
+
end
|
47
|
+
|
48
|
+
def eval(input, as: 'eval', &block)
|
49
|
+
@stream.callback = block if block && @stream.is_a?(Components::Stream)
|
50
|
+
|
51
|
+
Interfaces::Eval.evaluate(input, @cartridge, @session, as)
|
38
52
|
|
39
53
|
return unless @stream.is_a?(Components::Stream)
|
40
54
|
|
@@ -10,13 +10,13 @@ module NanoBot
|
|
10
10
|
module Controllers
|
11
11
|
module Interfaces
|
12
12
|
module Eval
|
13
|
-
def self.evaluate(input, cartridge, session)
|
14
|
-
prefix = Logic::Cartridge::Affixes.get(cartridge,
|
15
|
-
suffix = Logic::Cartridge::Affixes.get(cartridge,
|
13
|
+
def self.evaluate(input, cartridge, session, mode)
|
14
|
+
prefix = Logic::Cartridge::Affixes.get(cartridge, mode.to_sym, :output, :prefix)
|
15
|
+
suffix = Logic::Cartridge::Affixes.get(cartridge, mode.to_sym, :output, :suffix)
|
16
16
|
|
17
17
|
session.print(prefix) unless prefix.nil?
|
18
18
|
|
19
|
-
session.evaluate_and_print(input, mode:
|
19
|
+
session.evaluate_and_print(input, mode:)
|
20
20
|
|
21
21
|
session.print(suffix) unless suffix.nil?
|
22
22
|
end
|
@@ -10,18 +10,26 @@ module NanoBot
|
|
10
10
|
module Controllers
|
11
11
|
module Interfaces
|
12
12
|
module REPL
|
13
|
+
def self.boot(cartridge, session, prefix = nil, suffix = nil, as: 'repl')
|
14
|
+
return unless Logic::Helpers::Hash.fetch(cartridge, %i[behaviors boot instruction])
|
15
|
+
|
16
|
+
prefix ||= Logic::Cartridge::Affixes.get(cartridge, as.to_sym, :output, :prefix)
|
17
|
+
suffix ||= Logic::Cartridge::Affixes.get(cartridge, as.to_sym, :output, :suffix)
|
18
|
+
|
19
|
+
session.print(prefix) unless prefix.nil?
|
20
|
+
session.boot(mode: as)
|
21
|
+
session.print(suffix) unless suffix.nil?
|
22
|
+
end
|
23
|
+
|
13
24
|
def self.start(cartridge, session)
|
14
25
|
prefix = Logic::Cartridge::Affixes.get(cartridge, :repl, :output, :prefix)
|
15
26
|
suffix = Logic::Cartridge::Affixes.get(cartridge, :repl, :output, :suffix)
|
16
27
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
session.print(suffix) unless suffix.nil?
|
21
|
-
session.print("\n")
|
22
|
-
end
|
28
|
+
boot(cartridge, session, prefix, suffix)
|
29
|
+
|
30
|
+
session.print("\n") if Logic::Helpers::Hash.fetch(cartridge, %i[behaviors boot instruction])
|
23
31
|
|
24
|
-
prompt =
|
32
|
+
prompt = self.prompt(cartridge)
|
25
33
|
|
26
34
|
Pry.config.prompt = Pry::Prompt.new(
|
27
35
|
'REPL',
|
@@ -40,7 +48,8 @@ module NanoBot
|
|
40
48
|
Pry.start
|
41
49
|
end
|
42
50
|
|
43
|
-
def self.
|
51
|
+
def self.prompt(cartridge)
|
52
|
+
prompt = Logic::Helpers::Hash.fetch(cartridge, %i[interfaces repl prompt])
|
44
53
|
result = ''
|
45
54
|
|
46
55
|
if prompt.is_a?(Array)
|
data/controllers/session.rb
CHANGED
@@ -61,6 +61,8 @@ module NanoBot
|
|
61
61
|
|
62
62
|
@state[:history] << {
|
63
63
|
who: 'user',
|
64
|
+
mode: mode.to_s,
|
65
|
+
input: message,
|
64
66
|
message: Components::Adapter.apply(
|
65
67
|
:input, Logic::Cartridge::Interaction.input(@cartridge, mode.to_sym, message)
|
66
68
|
)
|
@@ -72,6 +74,9 @@ module NanoBot
|
|
72
74
|
end
|
73
75
|
|
74
76
|
def process(input, mode:)
|
77
|
+
prefix = Logic::Cartridge::Affixes.get(@cartridge, mode.to_sym, :output, :prefix)
|
78
|
+
suffix = Logic::Cartridge::Affixes.get(@cartridge, mode.to_sym, :output, :suffix)
|
79
|
+
|
75
80
|
interface = Logic::Helpers::Hash.fetch(@cartridge, [:interfaces, mode.to_sym]) || {}
|
76
81
|
|
77
82
|
streaming = Logic::Cartridge::Streaming.enabled?(@cartridge, mode.to_sym)
|
@@ -85,7 +90,7 @@ module NanoBot
|
|
85
90
|
updated_at = Time.now
|
86
91
|
|
87
92
|
if finished
|
88
|
-
|
93
|
+
event = Marshal.load(Marshal.dump(output))
|
89
94
|
|
90
95
|
output = Logic::Cartridge::Interaction.output(
|
91
96
|
@cartridge, mode.to_sym, output, streaming, finished
|
@@ -93,6 +98,11 @@ module NanoBot
|
|
93
98
|
|
94
99
|
output[:message] = Components::Adapter.apply(:output, output[:message])
|
95
100
|
|
101
|
+
event[:mode] = mode.to_s
|
102
|
+
event[:output] = "#{prefix}#{output[:message]}#{suffix}"
|
103
|
+
|
104
|
+
@state[:history] << event
|
105
|
+
|
96
106
|
self.print(output[:message]) unless streaming
|
97
107
|
|
98
108
|
ready = true
|
data/docker-compose.example.yml
CHANGED
@@ -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.
|
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.8 && bash"
|
7
7
|
environment:
|
8
8
|
OPENAI_API_ADDRESS: https://api.openai.com
|
9
9
|
OPENAI_API_ACCESS_TOKEN: your-token
|
data/nano-bots.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
|
34
34
|
spec.add_dependency 'babosa', '~> 2.0'
|
35
35
|
spec.add_dependency 'dotenv', '~> 2.8', '>= 2.8.1'
|
36
|
-
spec.add_dependency 'faraday', '~> 2.7', '>= 2.7.
|
36
|
+
spec.add_dependency 'faraday', '~> 2.7', '>= 2.7.5'
|
37
37
|
spec.add_dependency 'pry', '~> 0.14.2'
|
38
38
|
spec.add_dependency 'rainbow', '~> 3.1', '>= 3.1.1'
|
39
39
|
spec.add_dependency 'ruby-openai', '~> 4.0'
|
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.
|
6
|
+
version: '0.0.8',
|
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.
|
4
|
+
version: 0.0.8
|
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-
|
11
|
+
date: 2023-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: babosa
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
version: '2.7'
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: 2.7.
|
56
|
+
version: 2.7.5
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -63,7 +63,7 @@ dependencies:
|
|
63
63
|
version: '2.7'
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 2.7.
|
66
|
+
version: 2.7.5
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: pry
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|