nano-bots 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -8
- data/README.md +89 -9
- data/components/providers/openai.rb +1 -1
- data/components/stream.rb +2 -2
- data/controllers/interfaces/tools.rb +4 -1
- data/controllers/security.rb +3 -4
- data/controllers/session.rb +17 -4
- data/docker-compose.example.yml +3 -4
- data/nano-bots.gemspec +1 -1
- data/static/cartridges/default.yml +1 -1
- data/static/fennel/LICENSE +0 -2
- data/static/fennel/fennel.lua +791 -703
- data/static/gem.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b15d457541548f43fcc6d1c7cf7724c2e22a6505c0ca82e95681617e70259bd
|
4
|
+
data.tar.gz: c5b20938128e993273a0759e6c0e5571a90f67fe59d7b43a36967254dab3bf40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2915fddd84a82616a2457bb6ef6d2acb6c7e3ad83beb9fb162033326047b123d43ec3c80764e27b6dbf5b0827a5dc2e3ed9781de3d44d787a188e1724043ab4e
|
7
|
+
data.tar.gz: b9413865e968eddf7f38e506c7ed96760c2734dea25ddcacac504e58a8ed45f0573d8b1a42285fddd5ddacfe0acbf710d9e804af827338bb58e0e1cbc5163bc8
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nano-bots (1.
|
4
|
+
nano-bots (1.1.0)
|
5
5
|
babosa (~> 2.0)
|
6
6
|
concurrent-ruby (~> 1.2, >= 1.2.2)
|
7
7
|
dotenv (~> 2.8, >= 2.8.1)
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
pry (~> 0.14.2)
|
10
10
|
rainbow (~> 3.1, >= 3.1.1)
|
11
11
|
rbnacl (~> 7.1, >= 7.1.1)
|
12
|
-
ruby-openai (~> 6.3)
|
12
|
+
ruby-openai (~> 6.3, >= 6.3.1)
|
13
13
|
sweet-moon (~> 0.0.7)
|
14
14
|
|
15
15
|
GEM
|
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
multipart-post (~> 2)
|
33
33
|
faraday-net_http (3.0.2)
|
34
34
|
ffi (1.16.3)
|
35
|
-
json (2.
|
35
|
+
json (2.7.1)
|
36
36
|
language_server-protocol (3.17.0.3)
|
37
37
|
method_source (1.0.0)
|
38
38
|
multipart-post (2.3.0)
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
rainbow (3.1.1)
|
51
51
|
rbnacl (7.1.1)
|
52
52
|
ffi
|
53
|
-
regexp_parser (2.8.
|
53
|
+
regexp_parser (2.8.3)
|
54
54
|
rexml (3.2.6)
|
55
55
|
rspec (3.12.0)
|
56
56
|
rspec-core (~> 3.12.0)
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
diff-lcs (>= 1.2.0, < 2.0)
|
66
66
|
rspec-support (~> 3.12.0)
|
67
67
|
rspec-support (3.12.1)
|
68
|
-
rubocop (1.
|
68
|
+
rubocop (1.58.0)
|
69
69
|
json (~> 2.3)
|
70
70
|
language_server-protocol (>= 3.17.0)
|
71
71
|
parallel (~> 1.10)
|
@@ -73,7 +73,7 @@ GEM
|
|
73
73
|
rainbow (>= 2.2.2, < 4.0)
|
74
74
|
regexp_parser (>= 1.8, < 3.0)
|
75
75
|
rexml (>= 3.2.5, < 4.0)
|
76
|
-
rubocop-ast (>= 1.
|
76
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
77
77
|
ruby-progressbar (~> 1.7)
|
78
78
|
unicode-display_width (>= 2.4.0, < 3.0)
|
79
79
|
rubocop-ast (1.30.0)
|
@@ -86,7 +86,7 @@ GEM
|
|
86
86
|
rubocop (~> 1.40)
|
87
87
|
rubocop-capybara (~> 2.17)
|
88
88
|
rubocop-factory_bot (~> 2.22)
|
89
|
-
ruby-openai (6.3.
|
89
|
+
ruby-openai (6.3.1)
|
90
90
|
event_stream_parser (>= 0.3.0, < 2.0.0)
|
91
91
|
faraday (>= 1)
|
92
92
|
faraday-multipart (>= 1)
|
@@ -103,7 +103,7 @@ DEPENDENCIES
|
|
103
103
|
nano-bots!
|
104
104
|
pry-byebug (~> 3.10, >= 3.10.1)
|
105
105
|
rspec (~> 3.12)
|
106
|
-
rubocop (~> 1.
|
106
|
+
rubocop (~> 1.58)
|
107
107
|
rubocop-rspec (~> 2.25)
|
108
108
|
|
109
109
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -13,6 +13,8 @@ https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b
|
|
13
13
|
- [Command Line](#command-line)
|
14
14
|
- [Library](#library)
|
15
15
|
- [Cartridges](#cartridges)
|
16
|
+
- [Tools (Functions)](#tools-functions)
|
17
|
+
- [Experimental Clojure Support](#experimental-clojure-support)
|
16
18
|
- [Marketplace](#marketplace)
|
17
19
|
- [Security and Privacy](#security-and-privacy)
|
18
20
|
- [Cryptography](#cryptography)
|
@@ -28,13 +30,13 @@ https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b
|
|
28
30
|
For a system usage:
|
29
31
|
|
30
32
|
```sh
|
31
|
-
gem install nano-bots -v 1.
|
33
|
+
gem install nano-bots -v 1.1.0
|
32
34
|
```
|
33
35
|
|
34
36
|
To use it in a project, add it to your `Gemfile`:
|
35
37
|
|
36
38
|
```ruby
|
37
|
-
gem 'nano-bots', '~> 1.
|
39
|
+
gem 'nano-bots', '~> 1.1.0'
|
38
40
|
```
|
39
41
|
|
40
42
|
```sh
|
@@ -80,12 +82,11 @@ cp docker-compose.example.yml docker-compose.yml
|
|
80
82
|
Set your provider credentials and choose your desired directory for the cartridges files:
|
81
83
|
|
82
84
|
```yaml
|
83
|
-
|
84
|
-
|
85
|
+
---
|
85
86
|
services:
|
86
87
|
nano-bots:
|
87
|
-
image: ruby:3.2.2-slim-
|
88
|
-
command: sh -c "gem install nano-bots -v 1.
|
88
|
+
image: ruby:3.2.2-slim-bookworm
|
89
|
+
command: sh -c "apt-get update && apt-get install -y --no-install-recommends build-essential libffi-dev libsodium-dev lua5.4-dev curl && curl -s https://raw.githubusercontent.com/babashka/babashka/master/install | bash && gem install nano-bots -v 1.1.0 && bash"
|
89
90
|
environment:
|
90
91
|
OPENAI_API_ADDRESS: https://api.openai.com
|
91
92
|
OPENAI_API_KEY: your-access-token
|
@@ -217,7 +218,7 @@ bot.eval('Hello', as: 'eval')
|
|
217
218
|
bot.eval('Hello', as: 'repl')
|
218
219
|
|
219
220
|
# When stream is enabled and available:
|
220
|
-
bot.eval('Hi!') do |content, fragment, finished|
|
221
|
+
bot.eval('Hi!') do |content, fragment, finished, meta|
|
221
222
|
print fragment unless fragment.nil?
|
222
223
|
end
|
223
224
|
|
@@ -234,7 +235,7 @@ bot.boot
|
|
234
235
|
bot.boot(as: 'eval')
|
235
236
|
bot.boot(as: 'repl')
|
236
237
|
|
237
|
-
bot.boot do |content, fragment, finished|
|
238
|
+
bot.boot do |content, fragment, finished, meta|
|
238
239
|
print fragment unless fragment.nil?
|
239
240
|
end
|
240
241
|
```
|
@@ -271,6 +272,85 @@ Check the Nano Bots specification to learn more about [how to build cartridges](
|
|
271
272
|
|
272
273
|
Try the [Nano Bots Clinic (Live Editor)](https://clinic.nbots.io) to learn about creating Cartridges.
|
273
274
|
|
275
|
+
### Tools (Functions)
|
276
|
+
|
277
|
+
Nano Bots can also be powered by _Tools_ (Functions):
|
278
|
+
|
279
|
+
```yaml
|
280
|
+
---
|
281
|
+
tools:
|
282
|
+
- name: random-number
|
283
|
+
description: Generates a random number between 1 and 100.
|
284
|
+
fennel: |
|
285
|
+
(math.random 1 100)
|
286
|
+
```
|
287
|
+
|
288
|
+
```
|
289
|
+
🤖> please generate a random number
|
290
|
+
|
291
|
+
random-number {} [yN] y
|
292
|
+
|
293
|
+
random-number {}
|
294
|
+
59
|
295
|
+
|
296
|
+
The randomly generated number is 59.
|
297
|
+
|
298
|
+
🤖> |
|
299
|
+
```
|
300
|
+
|
301
|
+
To successfully use Tools (Functions), you need to specify a provider and a model that support them. As of the writing of this README, the provider that supports them is [OpenAI](https://platform.openai.com/docs/models), with models `gpt-3.5-turbo-1106` and `gpt-4-1106-preview`:
|
302
|
+
|
303
|
+
```yaml
|
304
|
+
---
|
305
|
+
provider:
|
306
|
+
id: openai
|
307
|
+
credentials:
|
308
|
+
address: ENV/OPENAI_API_ADDRESS
|
309
|
+
access-token: ENV/OPENAI_API_KEY
|
310
|
+
settings:
|
311
|
+
user: ENV/NANO_BOTS_END_USER
|
312
|
+
model: gpt-4-1106-preview
|
313
|
+
```
|
314
|
+
|
315
|
+
Check the [Nano Bots specification](https://spec.nbots.io/#/README?id=tools-functions-2) to learn more about them.
|
316
|
+
|
317
|
+
#### Experimental Clojure Support
|
318
|
+
|
319
|
+
We are exploring the use of [Clojure](https://clojure.org) through [Babashka](https://babashka.org), powered by [GraalVM](https://www.graalvm.org).
|
320
|
+
|
321
|
+
The experimental support for Clojure would be similar to Lua and Fennel, using the `clojure:` key:
|
322
|
+
|
323
|
+
```yaml
|
324
|
+
---
|
325
|
+
clojure: |
|
326
|
+
(-> (java.time.ZonedDateTime/now)
|
327
|
+
(.format (java.time.format.DateTimeFormatter/ofPattern "yyyy-MM-dd HH:mm"))
|
328
|
+
(clojure.string/trimr))
|
329
|
+
```
|
330
|
+
|
331
|
+
Unlike Lua and Fennel, Clojure support is not _embedded_ in this implementation. It relies on having the Babashka binary (`bb`) available in your environment where the Nano Bot is running.
|
332
|
+
|
333
|
+
Here's [how to install Babashka](https://github.com/babashka/babashka#quickstart):
|
334
|
+
|
335
|
+
```sh
|
336
|
+
curl -s https://raw.githubusercontent.com/babashka/babashka/master/install | bash
|
337
|
+
```
|
338
|
+
|
339
|
+
This is a quick check to ensure that it is available and working:
|
340
|
+
```sh
|
341
|
+
bb -e '{:hello "world"}'
|
342
|
+
# => {:hello "world"}
|
343
|
+
```
|
344
|
+
|
345
|
+
We don't have sandbox support for Clojure; this means that you need to disable it to be able to run Clojure code, which you do at your own risk:
|
346
|
+
|
347
|
+
```yaml
|
348
|
+
---
|
349
|
+
safety:
|
350
|
+
functions:
|
351
|
+
sandboxed: false
|
352
|
+
```
|
353
|
+
|
274
354
|
### Marketplace
|
275
355
|
|
276
356
|
You can explore the Nano Bots [Marketplace](https://nbots.io) to discover new Cartridges that can help you.
|
@@ -408,5 +488,5 @@ gem build nano-bots.gemspec
|
|
408
488
|
|
409
489
|
gem signin
|
410
490
|
|
411
|
-
gem push nano-bots-1.
|
491
|
+
gem push nano-bots-1.1.0.gem
|
412
492
|
```
|
data/components/stream.rb
CHANGED
@@ -13,9 +13,9 @@ module NanoBot
|
|
13
13
|
@accumulated = "#{@accumulated.force_encoding('UTF-8')}#{args.first.force_encoding('UTF-8')}"
|
14
14
|
end
|
15
15
|
|
16
|
-
@callback.call(@accumulated, args.first, false)
|
16
|
+
@callback.call(@accumulated, args.first, false, args[1])
|
17
17
|
end
|
18
|
-
super
|
18
|
+
super(args.first)
|
19
19
|
end
|
20
20
|
|
21
21
|
def callback=(block)
|
@@ -72,7 +72,10 @@ module NanoBot
|
|
72
72
|
|
73
73
|
message = "#{adapter[:prefix]}#{message}#{adapter[:suffix]}"
|
74
74
|
|
75
|
-
session.print(
|
75
|
+
session.print(
|
76
|
+
color.nil? ? message : Rainbow(message).send(color),
|
77
|
+
{ tool: { action: feedback[:action].to_s } }
|
78
|
+
)
|
76
79
|
end
|
77
80
|
|
78
81
|
def self.adapter(cartridge, mode, feedback)
|
data/controllers/security.rb
CHANGED
@@ -18,11 +18,10 @@ module NanoBot
|
|
18
18
|
password = 'UNSAFE' unless password && password != ''
|
19
19
|
|
20
20
|
{
|
21
|
-
encryption:
|
21
|
+
encryption:
|
22
22
|
Components::Crypto.encrypt('SAFE') != 'SAFE' &&
|
23
|
-
|
24
|
-
|
25
|
-
),
|
23
|
+
Components::Crypto.encrypt('SAFE') != Components::Crypto.encrypt('SAFE') &&
|
24
|
+
Components::Crypto.decrypt(Components::Crypto.encrypt('SAFE')) == 'SAFE',
|
26
25
|
password: password != 'UNSAFE'
|
27
26
|
}
|
28
27
|
end
|
data/controllers/session.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative '../logic/cartridge/streaming'
|
|
11
11
|
require_relative '../logic/cartridge/interaction'
|
12
12
|
require_relative '../logic/cartridge/fetch'
|
13
13
|
require_relative 'interfaces/tools'
|
14
|
+
require_relative '../components/stream'
|
14
15
|
require_relative '../components/storage'
|
15
16
|
require_relative '../components/adapter'
|
16
17
|
require_relative '../components/crypto'
|
@@ -56,11 +57,19 @@ module NanoBot
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def boot(mode:)
|
59
|
-
|
60
|
+
instruction = Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors boot instruction])
|
61
|
+
return unless instruction
|
60
62
|
|
61
63
|
behavior = Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors boot]) || {}
|
62
64
|
|
63
|
-
|
65
|
+
@state[:history] << {
|
66
|
+
who: 'user',
|
67
|
+
mode: mode.to_s,
|
68
|
+
input: instruction,
|
69
|
+
message: instruction
|
70
|
+
}
|
71
|
+
|
72
|
+
input = { behavior:, history: @state[:history] }
|
64
73
|
|
65
74
|
process(input, mode:)
|
66
75
|
end
|
@@ -182,8 +191,12 @@ module NanoBot
|
|
182
191
|
@stream.flush
|
183
192
|
end
|
184
193
|
|
185
|
-
def print(content)
|
186
|
-
@stream.
|
194
|
+
def print(content, meta = nil)
|
195
|
+
if @stream.is_a?(NanoBot::Components::Stream)
|
196
|
+
@stream.write(content, meta)
|
197
|
+
else
|
198
|
+
@stream.write(content)
|
199
|
+
end
|
187
200
|
end
|
188
201
|
end
|
189
202
|
end
|
data/docker-compose.example.yml
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
---
|
3
2
|
services:
|
4
3
|
nano-bots:
|
5
|
-
image: ruby:3.2.2-slim-
|
6
|
-
command: sh -c "apt-get update && apt-get install -y --no-install-recommends build-essential libffi-dev libsodium-dev lua5.4-dev && gem install nano-bots -v 1.
|
4
|
+
image: ruby:3.2.2-slim-bookworm
|
5
|
+
command: sh -c "apt-get update && apt-get install -y --no-install-recommends build-essential libffi-dev libsodium-dev lua5.4-dev curl && curl -s https://raw.githubusercontent.com/babashka/babashka/master/install | bash && gem install nano-bots -v 1.1.0 && bash"
|
7
6
|
environment:
|
8
7
|
OPENAI_API_ADDRESS: https://api.openai.com
|
9
8
|
OPENAI_API_KEY: your-access-token
|
data/nano-bots.gemspec
CHANGED
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_dependency 'pry', '~> 0.14.2'
|
39
39
|
spec.add_dependency 'rainbow', '~> 3.1', '>= 3.1.1'
|
40
40
|
spec.add_dependency 'rbnacl', '~> 7.1', '>= 7.1.1'
|
41
|
-
spec.add_dependency 'ruby-openai', '~> 6.3'
|
41
|
+
spec.add_dependency 'ruby-openai', '~> 6.3', '>= 6.3.1'
|
42
42
|
spec.add_dependency 'sweet-moon', '~> 0.0.7'
|
43
43
|
|
44
44
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
data/static/fennel/LICENSE
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright © 2016-2022 Calvin Rose and contributors
|
4
|
-
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
4
|
of this software and associated documentation files (the "Software"), to deal
|
7
5
|
in the Software without restriction, including without limitation the rights
|