nano-bots 2.2.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -5
- data/README.md +275 -139
- data/components/provider.rb +7 -1
- data/components/providers/cohere.rb +121 -0
- data/components/providers/google.rb +18 -3
- data/components/providers/mistral.rb +115 -0
- data/controllers/session.rb +0 -1
- data/docker-compose.example.yml +1 -1
- data/logic/cartridge/streaming.rb +1 -1
- data/logic/providers/cohere/tokens.rb +17 -0
- data/logic/providers/google/tokens.rb +0 -2
- data/logic/providers/mistral/tokens.rb +14 -0
- data/logic/providers/openai/tokens.rb +0 -2
- data/nano-bots.gemspec +3 -1
- data/static/gem.rb +4 -4
- metadata +45 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d1d868de99fe9fb6dc0a3bd399b2176d84ede8aa41bcf33c576d71533729302
|
4
|
+
data.tar.gz: 56744e7f48cb8976312b22bc8f2727a2ea9aed1f19d5f3c7739a61e3dac4aee9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31c01535614c68844d122096854e0f396dd979281345f9deb10ffc9f8d279351c8dcd32fab8c93682765bee901bde313c3afb20cfb0a90415b2fa821d5171d43
|
7
|
+
data.tar.gz: 84afd1d2a06e1253a8c49e4f0b23020a5ac76d23ea0602534854ebbd4969ff6c80c22eede6744915d606261cf9433b66367f6adad6a0009108a3a4bcc4be8f75
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nano-bots (2.
|
4
|
+
nano-bots (2.4.0)
|
5
5
|
babosa (~> 2.0)
|
6
|
+
cohere-ai (~> 1.0, >= 1.0.1)
|
6
7
|
concurrent-ruby (~> 1.2, >= 1.2.2)
|
7
8
|
dotenv (~> 2.8, >= 2.8.1)
|
8
|
-
gemini-ai (~>
|
9
|
+
gemini-ai (~> 3.1)
|
10
|
+
mistral-ai (~> 1.1)
|
9
11
|
pry (~> 0.14.2)
|
10
12
|
rainbow (~> 3.1, >= 3.1.1)
|
11
13
|
rbnacl (~> 7.1, >= 7.1.1)
|
@@ -22,11 +24,13 @@ GEM
|
|
22
24
|
base64 (0.2.0)
|
23
25
|
byebug (11.1.3)
|
24
26
|
coderay (1.1.3)
|
27
|
+
cohere-ai (1.0.1)
|
28
|
+
faraday (~> 2.8, >= 2.8.1)
|
25
29
|
concurrent-ruby (1.2.2)
|
26
30
|
diff-lcs (1.5.0)
|
27
31
|
dotenv (2.8.1)
|
28
32
|
event_stream_parser (1.0.0)
|
29
|
-
faraday (2.
|
33
|
+
faraday (2.8.1)
|
30
34
|
base64
|
31
35
|
faraday-net_http (>= 2.0, < 3.1)
|
32
36
|
ruby2_keywords (>= 0.0.4)
|
@@ -34,9 +38,9 @@ GEM
|
|
34
38
|
multipart-post (~> 2)
|
35
39
|
faraday-net_http (3.0.2)
|
36
40
|
ffi (1.16.3)
|
37
|
-
gemini-ai (
|
41
|
+
gemini-ai (3.1.0)
|
38
42
|
event_stream_parser (~> 1.0)
|
39
|
-
faraday (~> 2.
|
43
|
+
faraday (~> 2.8, >= 2.8.1)
|
40
44
|
googleauth (~> 1.9, >= 1.9.1)
|
41
45
|
google-cloud-env (2.1.0)
|
42
46
|
faraday (>= 1.0, < 3.a)
|
@@ -51,6 +55,9 @@ GEM
|
|
51
55
|
jwt (2.7.1)
|
52
56
|
language_server-protocol (3.17.0.3)
|
53
57
|
method_source (1.0.0)
|
58
|
+
mistral-ai (1.1.0)
|
59
|
+
event_stream_parser (~> 1.0)
|
60
|
+
faraday (~> 2.8, >= 2.8.1)
|
54
61
|
multi_json (1.15.0)
|
55
62
|
multipart-post (2.3.0)
|
56
63
|
os (1.1.4)
|
data/README.md
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
# Nano Bots 💎 🤖
|
2
2
|
|
3
|
-
A Ruby implementation of the [Nano Bots](https://github.com/icebaker/nano-bots) specification.
|
3
|
+
A Ruby implementation of the [Nano Bots](https://github.com/icebaker/nano-bots) specification with support for [OpenAI ChatGPT](https://openai.com/chatgpt), [Mistral AI](https://mistral.ai), [Cohere Command](https://cohere.com), and [Google Gemini](https://deepmind.google/technologies/gemini).
|
4
4
|
|
5
|
-
![Ruby Nano Bots](https://
|
6
|
-
_Image artificially created by Midjourney through a prompt generated by a Nano Bot specialized in Midjourney._
|
5
|
+
![Ruby Nano Bots](https://raw.githubusercontent.com/icebaker/assets/main/nano-bots/ruby-nano-bots-canvas.png)
|
7
6
|
|
8
7
|
https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b-864a-0f49bbf6e22f.mp4
|
9
8
|
|
10
9
|
- [Setup](#setup)
|
11
|
-
- [
|
10
|
+
- [Cohere Command](#cohere-command)
|
12
11
|
- [Google Gemini](#google-gemini)
|
13
|
-
- [
|
14
|
-
|
15
|
-
- [Google Gemini](#google-gemini-1)
|
12
|
+
- [Mistral AI](#mistral-ai)
|
13
|
+
- [OpenAI ChatGPT](#openai-chatgpt)
|
16
14
|
- [Usage](#usage)
|
17
15
|
- [Command Line](#command-line)
|
18
16
|
- [Library](#library)
|
19
17
|
- [Cartridges](#cartridges)
|
20
|
-
- [
|
21
|
-
- [Google Gemini](#google-gemini-
|
18
|
+
- [Cohere Command](#cohere-command-1)
|
19
|
+
- [Google Gemini](#google-gemini-1)
|
20
|
+
- [Mistral AI](#mistral-ai-1)
|
21
|
+
- [OpenAI ChatGPT](#openai-chatgpt-1)
|
22
22
|
- [Tools (Functions)](#tools-functions)
|
23
23
|
- [Experimental Clojure Support](#experimental-clojure-support)
|
24
24
|
- [Marketplace](#marketplace)
|
25
|
+
- [Docker](#docker)
|
26
|
+
- [Cohere Command](#cohere-command-2)
|
27
|
+
- [Google Gemini](#google-gemini-2)
|
28
|
+
- [Mistral AI](#mistral-ai-2)
|
29
|
+
- [OpenAI ChatGPT](#openai-chatgpt-2)
|
25
30
|
- [Security and Privacy](#security-and-privacy)
|
26
31
|
- [Cryptography](#cryptography)
|
27
32
|
- [End-user IDs](#end-user-ids)
|
@@ -36,13 +41,13 @@ https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b
|
|
36
41
|
For a system usage:
|
37
42
|
|
38
43
|
```sh
|
39
|
-
gem install nano-bots -v 2.
|
44
|
+
gem install nano-bots -v 2.4.0
|
40
45
|
```
|
41
46
|
|
42
47
|
To use it in a project, add it to your `Gemfile`:
|
43
48
|
|
44
49
|
```ruby
|
45
|
-
gem 'nano-bots', '~> 2.
|
50
|
+
gem 'nano-bots', '~> 2.4.0'
|
46
51
|
```
|
47
52
|
|
48
53
|
```sh
|
@@ -51,12 +56,7 @@ bundle install
|
|
51
56
|
|
52
57
|
For credentials and configurations, relevant environment variables can be set in your `.bashrc`, `.zshrc`, or equivalent files, as well as in your Docker Container or System Environment. Example:
|
53
58
|
|
54
|
-
### OpenAI ChatGPT
|
55
|
-
|
56
59
|
```sh
|
57
|
-
export OPENAI_API_ADDRESS=https://api.openai.com
|
58
|
-
export OPENAI_API_KEY=your-access-token
|
59
|
-
|
60
60
|
export NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
|
61
61
|
export NANO_BOTS_END_USER=your-user
|
62
62
|
|
@@ -67,9 +67,6 @@ export NANO_BOTS_END_USER=your-user
|
|
67
67
|
Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
|
68
68
|
|
69
69
|
```sh
|
70
|
-
OPENAI_API_ADDRESS=https://api.openai.com
|
71
|
-
OPENAI_API_KEY=your-access-token
|
72
|
-
|
73
70
|
NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
|
74
71
|
NANO_BOTS_END_USER=your-user
|
75
72
|
|
@@ -77,6 +74,54 @@ NANO_BOTS_END_USER=your-user
|
|
77
74
|
# NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
|
78
75
|
```
|
79
76
|
|
77
|
+
### Cohere Command
|
78
|
+
|
79
|
+
You can obtain your credentials on the [Cohere Platform](https://dashboard.cohere.com).
|
80
|
+
|
81
|
+
```sh
|
82
|
+
export COHERE_API_ADDRESS=https://api.cohere.ai
|
83
|
+
export COHERE_API_KEY=your-api-key
|
84
|
+
```
|
85
|
+
|
86
|
+
Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
|
87
|
+
|
88
|
+
```sh
|
89
|
+
COHERE_API_ADDRESS=https://api.cohere.ai
|
90
|
+
COHERE_API_KEY=your-api-key
|
91
|
+
```
|
92
|
+
|
93
|
+
### Mistral AI
|
94
|
+
|
95
|
+
You can obtain your credentials on the [Mistral Platform](https://console.mistral.ai).
|
96
|
+
|
97
|
+
```sh
|
98
|
+
export MISTRAL_API_ADDRESS=https://api.mistral.ai
|
99
|
+
export MISTRAL_API_KEY=your-api-key
|
100
|
+
```
|
101
|
+
|
102
|
+
Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
|
103
|
+
|
104
|
+
```sh
|
105
|
+
MISTRAL_API_ADDRESS=https://api.mistral.ai
|
106
|
+
MISTRAL_API_KEY=your-api-key
|
107
|
+
```
|
108
|
+
|
109
|
+
### OpenAI ChatGPT
|
110
|
+
|
111
|
+
You can obtain your credentials on the [OpenAI Platform](https://platform.openai.com).
|
112
|
+
|
113
|
+
```sh
|
114
|
+
export OPENAI_API_ADDRESS=https://api.openai.com
|
115
|
+
export OPENAI_API_KEY=your-access-token
|
116
|
+
```
|
117
|
+
|
118
|
+
Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
|
119
|
+
|
120
|
+
```sh
|
121
|
+
OPENAI_API_ADDRESS=https://api.openai.com
|
122
|
+
OPENAI_API_KEY=your-access-token
|
123
|
+
```
|
124
|
+
|
80
125
|
### Google Gemini
|
81
126
|
|
82
127
|
Click [here](https://github.com/gbaptista/gemini-ai#credentials) to learn how to obtain your credentials.
|
@@ -169,117 +214,6 @@ Alternatively, if your current directory has a `.env` file with the environment
|
|
169
214
|
GOOGLE_PROJECT_ID=your-project-id
|
170
215
|
```
|
171
216
|
|
172
|
-
## Docker
|
173
|
-
|
174
|
-
Clone the repository and copy the Docker Compose template:
|
175
|
-
|
176
|
-
```
|
177
|
-
git clone https://github.com/icebaker/ruby-nano-bots.git
|
178
|
-
cd ruby-nano-bots
|
179
|
-
cp docker-compose.example.yml docker-compose.yml
|
180
|
-
```
|
181
|
-
|
182
|
-
Set your provider credentials and choose your desired directory for the cartridges files:
|
183
|
-
|
184
|
-
### OpenAI ChatGPT
|
185
|
-
|
186
|
-
```yaml
|
187
|
-
---
|
188
|
-
services:
|
189
|
-
nano-bots:
|
190
|
-
image: ruby:3.2.2-slim-bookworm
|
191
|
-
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 2.2.0 && bash"
|
192
|
-
environment:
|
193
|
-
OPENAI_API_ADDRESS: https://api.openai.com
|
194
|
-
OPENAI_API_KEY: your-access-token
|
195
|
-
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
196
|
-
NANO_BOTS_END_USER: your-user
|
197
|
-
volumes:
|
198
|
-
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
199
|
-
- ./your-state-path:/root/.local/state/nano-bots
|
200
|
-
```
|
201
|
-
|
202
|
-
### Google Gemini
|
203
|
-
|
204
|
-
#### Option 1: API Key (Generative Language API)
|
205
|
-
|
206
|
-
```yaml
|
207
|
-
---
|
208
|
-
services:
|
209
|
-
nano-bots:
|
210
|
-
image: ruby:3.2.2-slim-bookworm
|
211
|
-
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 2.2.0 && bash"
|
212
|
-
environment:
|
213
|
-
GOOGLE_API_KEY: your-api-key
|
214
|
-
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
215
|
-
NANO_BOTS_END_USER: your-user
|
216
|
-
volumes:
|
217
|
-
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
218
|
-
- ./your-state-path:/root/.local/state/nano-bots
|
219
|
-
```
|
220
|
-
|
221
|
-
#### Option 2: Service Account Credentials File (Vertex AI API)
|
222
|
-
|
223
|
-
```yaml
|
224
|
-
---
|
225
|
-
services:
|
226
|
-
nano-bots:
|
227
|
-
image: ruby:3.2.2-slim-bookworm
|
228
|
-
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 2.2.0 && bash"
|
229
|
-
environment:
|
230
|
-
GOOGLE_CREDENTIALS_FILE_PATH: /root/.config/google-credentials.json
|
231
|
-
GOOGLE_REGION: us-east4
|
232
|
-
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
233
|
-
NANO_BOTS_END_USER: your-user
|
234
|
-
volumes:
|
235
|
-
- ./google-credentials.json:/root/.config/google-credentials.json
|
236
|
-
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
237
|
-
- ./your-state-path:/root/.local/state/nano-bots
|
238
|
-
```
|
239
|
-
|
240
|
-
#### Option 3: Application Default Credentials (Vertex AI API)
|
241
|
-
|
242
|
-
```yaml
|
243
|
-
---
|
244
|
-
services:
|
245
|
-
nano-bots:
|
246
|
-
image: ruby:3.2.2-slim-bookworm
|
247
|
-
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 2.2.0 && bash"
|
248
|
-
environment:
|
249
|
-
GOOGLE_REGION: us-east4
|
250
|
-
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
251
|
-
NANO_BOTS_END_USER: your-user
|
252
|
-
volumes:
|
253
|
-
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
254
|
-
- ./your-state-path:/root/.local/state/nano-bots
|
255
|
-
```
|
256
|
-
|
257
|
-
#### Custom Project ID
|
258
|
-
If you need to manually set a Google Project ID:
|
259
|
-
|
260
|
-
```yaml
|
261
|
-
environment:
|
262
|
-
GOOGLE_PROJECT_ID=your-project-id
|
263
|
-
```
|
264
|
-
|
265
|
-
### Container
|
266
|
-
|
267
|
-
Enter the container:
|
268
|
-
```sh
|
269
|
-
docker compose run nano-bots
|
270
|
-
```
|
271
|
-
|
272
|
-
Start playing:
|
273
|
-
```sh
|
274
|
-
nb - - eval "hello"
|
275
|
-
nb - - repl
|
276
|
-
|
277
|
-
nb assistant.yml - eval "hello"
|
278
|
-
nb assistant.yml - repl
|
279
|
-
```
|
280
|
-
|
281
|
-
You can exit the REPL by typing `exit`.
|
282
|
-
|
283
217
|
## Usage
|
284
218
|
|
285
219
|
### Command Line
|
@@ -419,9 +353,61 @@ Try the [Nano Bots Clinic (Live Editor)](https://clinic.nbots.io) to learn about
|
|
419
353
|
|
420
354
|
Here's what a Nano Bot Cartridge looks like:
|
421
355
|
|
356
|
+
### Cohere Command
|
357
|
+
|
358
|
+
Read the [full specification](https://spec.nbots.io/#/README?id=cohere-command) for Cohere Command.
|
359
|
+
|
360
|
+
```yaml
|
361
|
+
---
|
362
|
+
meta:
|
363
|
+
symbol: 🤖
|
364
|
+
name: Nano Bot Name
|
365
|
+
author: Your Name
|
366
|
+
version: 1.0.0
|
367
|
+
license: CC0-1.0
|
368
|
+
description: A helpful assistant.
|
369
|
+
|
370
|
+
behaviors:
|
371
|
+
interaction:
|
372
|
+
directive: You are a helpful assistant.
|
373
|
+
|
374
|
+
provider:
|
375
|
+
id: cohere
|
376
|
+
credentials:
|
377
|
+
api-key: ENV/COHERE_API_KEY
|
378
|
+
settings:
|
379
|
+
model: command
|
380
|
+
```
|
381
|
+
|
382
|
+
### Mistral AI
|
383
|
+
|
384
|
+
Read the [full specification](https://spec.nbots.io/#/README?id=mistral-ai) for Mistral AI.
|
385
|
+
|
386
|
+
```yaml
|
387
|
+
---
|
388
|
+
meta:
|
389
|
+
symbol: 🤖
|
390
|
+
name: Nano Bot Name
|
391
|
+
author: Your Name
|
392
|
+
version: 1.0.0
|
393
|
+
license: CC0-1.0
|
394
|
+
description: A helpful assistant.
|
395
|
+
|
396
|
+
behaviors:
|
397
|
+
interaction:
|
398
|
+
directive: You are a helpful assistant.
|
399
|
+
|
400
|
+
provider:
|
401
|
+
id: mistral
|
402
|
+
credentials:
|
403
|
+
api-key: ENV/MISTRAL_API_KEY
|
404
|
+
settings:
|
405
|
+
model: mistral-medium
|
406
|
+
```
|
407
|
+
|
422
408
|
### OpenAI ChatGPT
|
423
409
|
|
424
|
-
Read the [full specification](https://spec.nbots.io/#/README?id=
|
410
|
+
Read the [full specification](https://spec.nbots.io/#/README?id=openai-chatgpt) for OpenAI ChatGPT.
|
425
411
|
|
426
412
|
```yaml
|
427
413
|
---
|
@@ -564,7 +550,7 @@ The randomly generated number is 59.
|
|
564
550
|
|
565
551
|
🤖> |
|
566
552
|
```
|
567
|
-
To successfully use Tools (Functions), you need to specify a provider and a model that supports 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`, and [Google](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling#supported_models), with the `vertex-ai-api` service and the model `gemini-pro`.
|
553
|
+
To successfully use Tools (Functions), you need to specify a provider and a model that supports 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`, and [Google](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling#supported_models), with the `vertex-ai-api` service and the model `gemini-pro`. Mistral AI does not support tools.
|
568
554
|
|
569
555
|
Check the [Nano Bots specification](https://spec.nbots.io/#/README?id=tools-functions-2) to learn more about Tools (Functions).
|
570
556
|
|
@@ -609,6 +595,153 @@ safety:
|
|
609
595
|
|
610
596
|
You can explore the Nano Bots [Marketplace](https://nbots.io) to discover new Cartridges that can help you.
|
611
597
|
|
598
|
+
## Docker
|
599
|
+
|
600
|
+
Clone the repository and copy the Docker Compose template:
|
601
|
+
|
602
|
+
```
|
603
|
+
git clone https://github.com/icebaker/ruby-nano-bots.git
|
604
|
+
cd ruby-nano-bots
|
605
|
+
cp docker-compose.example.yml docker-compose.yml
|
606
|
+
```
|
607
|
+
|
608
|
+
Set your provider credentials and choose your desired directory for the cartridges files:
|
609
|
+
|
610
|
+
### Cohere Command
|
611
|
+
|
612
|
+
```yaml
|
613
|
+
---
|
614
|
+
services:
|
615
|
+
nano-bots:
|
616
|
+
image: ruby:3.2.2-slim-bookworm
|
617
|
+
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 2.4.0 && bash"
|
618
|
+
environment:
|
619
|
+
COHERE_API_ADDRESS: https://api.cohere.ai
|
620
|
+
COHERE_API_KEY: your-api-key
|
621
|
+
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
622
|
+
NANO_BOTS_END_USER: your-user
|
623
|
+
volumes:
|
624
|
+
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
625
|
+
- ./your-state-path:/root/.local/state/nano-bots
|
626
|
+
```
|
627
|
+
|
628
|
+
### Mistral AI
|
629
|
+
|
630
|
+
```yaml
|
631
|
+
---
|
632
|
+
services:
|
633
|
+
nano-bots:
|
634
|
+
image: ruby:3.2.2-slim-bookworm
|
635
|
+
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 2.4.0 && bash"
|
636
|
+
environment:
|
637
|
+
MISTRAL_API_ADDRESS: https://api.mistral.ai
|
638
|
+
MISTRAL_API_KEY: your-api-key
|
639
|
+
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
640
|
+
NANO_BOTS_END_USER: your-user
|
641
|
+
volumes:
|
642
|
+
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
643
|
+
- ./your-state-path:/root/.local/state/nano-bots
|
644
|
+
```
|
645
|
+
|
646
|
+
### OpenAI ChatGPT
|
647
|
+
|
648
|
+
```yaml
|
649
|
+
---
|
650
|
+
services:
|
651
|
+
nano-bots:
|
652
|
+
image: ruby:3.2.2-slim-bookworm
|
653
|
+
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 2.4.0 && bash"
|
654
|
+
environment:
|
655
|
+
OPENAI_API_ADDRESS: https://api.openai.com
|
656
|
+
OPENAI_API_KEY: your-access-token
|
657
|
+
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
658
|
+
NANO_BOTS_END_USER: your-user
|
659
|
+
volumes:
|
660
|
+
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
661
|
+
- ./your-state-path:/root/.local/state/nano-bots
|
662
|
+
```
|
663
|
+
|
664
|
+
### Google Gemini
|
665
|
+
|
666
|
+
#### Option 1: API Key (Generative Language API)
|
667
|
+
|
668
|
+
```yaml
|
669
|
+
---
|
670
|
+
services:
|
671
|
+
nano-bots:
|
672
|
+
image: ruby:3.2.2-slim-bookworm
|
673
|
+
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 2.4.0 && bash"
|
674
|
+
environment:
|
675
|
+
GOOGLE_API_KEY: your-api-key
|
676
|
+
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
677
|
+
NANO_BOTS_END_USER: your-user
|
678
|
+
volumes:
|
679
|
+
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
680
|
+
- ./your-state-path:/root/.local/state/nano-bots
|
681
|
+
```
|
682
|
+
|
683
|
+
#### Option 2: Service Account Credentials File (Vertex AI API)
|
684
|
+
|
685
|
+
```yaml
|
686
|
+
---
|
687
|
+
services:
|
688
|
+
nano-bots:
|
689
|
+
image: ruby:3.2.2-slim-bookworm
|
690
|
+
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 2.4.0 && bash"
|
691
|
+
environment:
|
692
|
+
GOOGLE_CREDENTIALS_FILE_PATH: /root/.config/google-credentials.json
|
693
|
+
GOOGLE_REGION: us-east4
|
694
|
+
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
695
|
+
NANO_BOTS_END_USER: your-user
|
696
|
+
volumes:
|
697
|
+
- ./google-credentials.json:/root/.config/google-credentials.json
|
698
|
+
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
699
|
+
- ./your-state-path:/root/.local/state/nano-bots
|
700
|
+
```
|
701
|
+
|
702
|
+
#### Option 3: Application Default Credentials (Vertex AI API)
|
703
|
+
|
704
|
+
```yaml
|
705
|
+
---
|
706
|
+
services:
|
707
|
+
nano-bots:
|
708
|
+
image: ruby:3.2.2-slim-bookworm
|
709
|
+
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 2.4.0 && bash"
|
710
|
+
environment:
|
711
|
+
GOOGLE_REGION: us-east4
|
712
|
+
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
713
|
+
NANO_BOTS_END_USER: your-user
|
714
|
+
volumes:
|
715
|
+
- ./your-cartridges:/root/.local/share/nano-bots/cartridges
|
716
|
+
- ./your-state-path:/root/.local/state/nano-bots
|
717
|
+
```
|
718
|
+
|
719
|
+
#### Custom Project ID
|
720
|
+
If you need to manually set a Google Project ID:
|
721
|
+
|
722
|
+
```yaml
|
723
|
+
environment:
|
724
|
+
GOOGLE_PROJECT_ID=your-project-id
|
725
|
+
```
|
726
|
+
|
727
|
+
### Container
|
728
|
+
|
729
|
+
Enter the container:
|
730
|
+
```sh
|
731
|
+
docker compose run nano-bots
|
732
|
+
```
|
733
|
+
|
734
|
+
Start playing:
|
735
|
+
```sh
|
736
|
+
nb - - eval "hello"
|
737
|
+
nb - - repl
|
738
|
+
|
739
|
+
nb assistant.yml - eval "hello"
|
740
|
+
nb assistant.yml - repl
|
741
|
+
```
|
742
|
+
|
743
|
+
You can exit the REPL by typing `exit`.
|
744
|
+
|
612
745
|
## Security and Privacy
|
613
746
|
|
614
747
|
Each provider will have its own security and privacy policies (e.g. [OpenAI Policy](https://openai.com/policies/api-data-usage-policies)), so you must consult them to understand their implications.
|
@@ -719,16 +852,17 @@ If you lose your password, you lose your data. It is not possible to recover it
|
|
719
852
|
|
720
853
|
Currently supported providers:
|
721
854
|
|
722
|
-
- [
|
723
|
-
- [x] [Google Gemini](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini)
|
855
|
+
- [ ] [01.AI Yi](https://01.ai)
|
724
856
|
- [ ] [Anthropic Claude](https://www.anthropic.com)
|
725
|
-
- [
|
857
|
+
- [x] [Cohere Command](https://docs.cohere.com/reference/about)
|
858
|
+
- [x] [Google Gemini](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini)
|
859
|
+
- [ ] [LMSYS Org FastChat Vicuna](https://github.com/lm-sys/FastChat)
|
726
860
|
- [ ] [Meta Llama](https://ai.meta.com/llama/)
|
727
|
-
- [
|
861
|
+
- [x] [Mistral AI](https://docs.mistral.ai/api/)
|
862
|
+
- [x] [Open AI ChatGPT](https://platform.openai.com/docs/api-reference)
|
728
863
|
- [ ] [WizardLM](https://wizardlm.github.io)
|
729
|
-
- [ ] [LMSYS Org FastChat Vicuna](https://github.com/lm-sys/FastChat)
|
730
864
|
|
731
|
-
|
865
|
+
Some providers offer APIs that are compatible with, for example, 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.
|
732
866
|
|
733
867
|
## Development
|
734
868
|
|
@@ -736,6 +870,8 @@ Although only OpenAI ChatGPT and Google Gemini have been officially tested, some
|
|
736
870
|
bundle
|
737
871
|
rubocop -A
|
738
872
|
rspec
|
873
|
+
|
874
|
+
bundle exec ruby spec/tasks/run-all-models.rb
|
739
875
|
```
|
740
876
|
|
741
877
|
### Publish to RubyGems
|
@@ -745,5 +881,5 @@ gem build nano-bots.gemspec
|
|
745
881
|
|
746
882
|
gem signin
|
747
883
|
|
748
|
-
gem push nano-bots-2.
|
884
|
+
gem push nano-bots-2.4.0.gem
|
749
885
|
```
|
data/components/provider.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'providers/openai'
|
4
3
|
require_relative 'providers/google'
|
4
|
+
require_relative 'providers/mistral'
|
5
|
+
require_relative 'providers/openai'
|
6
|
+
require_relative 'providers/cohere'
|
5
7
|
|
6
8
|
module NanoBot
|
7
9
|
module Components
|
@@ -12,6 +14,10 @@ module NanoBot
|
|
12
14
|
Providers::OpenAI.new(nil, provider[:settings], provider[:credentials], environment:)
|
13
15
|
when 'google'
|
14
16
|
Providers::Google.new(provider[:options], provider[:settings], provider[:credentials], environment:)
|
17
|
+
when 'mistral'
|
18
|
+
Providers::Mistral.new(provider[:options], provider[:settings], provider[:credentials], environment:)
|
19
|
+
when 'cohere'
|
20
|
+
Providers::Cohere.new(provider[:options], provider[:settings], provider[:credentials], environment:)
|
15
21
|
else
|
16
22
|
raise "Unsupported provider \"#{provider[:id]}\""
|
17
23
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cohere-ai'
|
4
|
+
|
5
|
+
require_relative 'base'
|
6
|
+
|
7
|
+
require_relative '../../logic/providers/cohere/tokens'
|
8
|
+
require_relative '../../logic/helpers/hash'
|
9
|
+
require_relative '../../logic/cartridge/default'
|
10
|
+
|
11
|
+
module NanoBot
|
12
|
+
module Components
|
13
|
+
module Providers
|
14
|
+
class Cohere < Base
|
15
|
+
attr_reader :settings
|
16
|
+
|
17
|
+
CHAT_SETTINGS = %i[
|
18
|
+
model stream prompt_truncation connectors
|
19
|
+
search_queries_only documents citation_quality
|
20
|
+
temperature
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
def initialize(options, settings, credentials, _environment)
|
24
|
+
@settings = settings
|
25
|
+
|
26
|
+
cohere_options = if options
|
27
|
+
options.transform_keys { |key| key.to_s.gsub('-', '_').to_sym }
|
28
|
+
else
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
|
32
|
+
unless @settings.key?(:stream)
|
33
|
+
@settings = Marshal.load(Marshal.dump(@settings))
|
34
|
+
@settings[:stream] = Logic::Helpers::Hash.fetch(
|
35
|
+
Logic::Cartridge::Default.instance.values, %i[provider settings stream]
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
cohere_options[:server_sent_events] = @settings[:stream]
|
40
|
+
|
41
|
+
@client = ::Cohere.new(
|
42
|
+
credentials: credentials.transform_keys { |key| key.to_s.gsub('-', '_').to_sym },
|
43
|
+
options: cohere_options
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def evaluate(input, streaming, cartridge, &feedback)
|
48
|
+
messages = input[:history].map do |event|
|
49
|
+
{ role: event[:who] == 'user' ? 'USER' : 'CHATBOT',
|
50
|
+
message: event[:message],
|
51
|
+
_meta: { at: event[:at] } }
|
52
|
+
end
|
53
|
+
|
54
|
+
if input[:behavior][:backdrop]
|
55
|
+
messages.prepend(
|
56
|
+
{ role: 'USER',
|
57
|
+
message: input[:behavior][:backdrop],
|
58
|
+
_meta: { at: Time.now } }
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
payload = { chat_history: messages }
|
63
|
+
|
64
|
+
payload[:message] = payload[:chat_history].pop[:message]
|
65
|
+
|
66
|
+
payload.delete(:chat_history) if payload[:chat_history].empty?
|
67
|
+
|
68
|
+
payload[:preamble_override] = input[:behavior][:directive] if input[:behavior][:directive]
|
69
|
+
|
70
|
+
CHAT_SETTINGS.each do |key|
|
71
|
+
payload[key] = @settings[key] unless payload.key?(key) || !@settings.key?(key)
|
72
|
+
end
|
73
|
+
|
74
|
+
raise 'Cohere does not support tools.' if input[:tools]
|
75
|
+
|
76
|
+
if streaming
|
77
|
+
content = ''
|
78
|
+
|
79
|
+
stream_call_back = proc do |event, _parsed, _raw|
|
80
|
+
partial_content = event['text']
|
81
|
+
|
82
|
+
if partial_content && event['event_type'] == 'text-generation'
|
83
|
+
content += partial_content
|
84
|
+
feedback.call(
|
85
|
+
{ should_be_stored: false,
|
86
|
+
interaction: { who: 'AI', message: partial_content } }
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
if event['is_finished']
|
91
|
+
feedback.call(
|
92
|
+
{ should_be_stored: !(content.nil? || content == ''),
|
93
|
+
interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
|
94
|
+
finished: true }
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
@client.chat(
|
100
|
+
Logic::Cohere::Tokens.apply_policies!(cartridge, payload),
|
101
|
+
server_sent_events: true, &stream_call_back
|
102
|
+
)
|
103
|
+
else
|
104
|
+
result = @client.chat(
|
105
|
+
Logic::Cohere::Tokens.apply_policies!(cartridge, payload),
|
106
|
+
server_sent_events: false
|
107
|
+
)
|
108
|
+
|
109
|
+
content = result['text']
|
110
|
+
|
111
|
+
feedback.call(
|
112
|
+
{ should_be_stored: !(content.nil? || content.to_s.strip == ''),
|
113
|
+
interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
|
114
|
+
finished: true }
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -6,6 +6,8 @@ require_relative 'base'
|
|
6
6
|
|
7
7
|
require_relative '../../logic/providers/google/tools'
|
8
8
|
require_relative '../../logic/providers/google/tokens'
|
9
|
+
require_relative '../../logic/helpers/hash'
|
10
|
+
require_relative '../../logic/cartridge/default'
|
9
11
|
|
10
12
|
require_relative 'tools'
|
11
13
|
|
@@ -26,9 +28,19 @@ module NanoBot
|
|
26
28
|
def initialize(options, settings, credentials, _environment)
|
27
29
|
@settings = settings
|
28
30
|
|
31
|
+
gemini_options = options.transform_keys { |key| key.to_s.gsub('-', '_').to_sym }
|
32
|
+
|
33
|
+
unless gemini_options.key?(:stream)
|
34
|
+
gemini_options[:stream] = Logic::Helpers::Hash.fetch(
|
35
|
+
Logic::Cartridge::Default.instance.values, %i[provider settings stream]
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
gemini_options[:server_sent_events] = gemini_options.delete(:stream)
|
40
|
+
|
29
41
|
@client = Gemini.new(
|
30
42
|
credentials: credentials.transform_keys { |key| key.to_s.gsub('-', '_').to_sym },
|
31
|
-
options:
|
43
|
+
options: gemini_options
|
32
44
|
)
|
33
45
|
end
|
34
46
|
|
@@ -105,6 +117,9 @@ module NanoBot
|
|
105
117
|
tools = []
|
106
118
|
|
107
119
|
stream_call_back = proc do |event, _parsed, _raw|
|
120
|
+
# TODO: How to better handle finishReason == 'OTHER'?
|
121
|
+
return if event.dig('candidates', 0, 'finishReason') == 'OTHER'
|
122
|
+
|
108
123
|
partial_content = event.dig('candidates', 0, 'content', 'parts').filter do |part|
|
109
124
|
part.key?('text')
|
110
125
|
end.map { |part| part['text'] }.join
|
@@ -132,7 +147,7 @@ module NanoBot
|
|
132
147
|
|
133
148
|
@client.stream_generate_content(
|
134
149
|
Logic::Google::Tokens.apply_policies!(cartridge, payload),
|
135
|
-
|
150
|
+
server_sent_events: true, &stream_call_back
|
136
151
|
)
|
137
152
|
|
138
153
|
if tools&.size&.positive?
|
@@ -156,7 +171,7 @@ module NanoBot
|
|
156
171
|
else
|
157
172
|
result = @client.stream_generate_content(
|
158
173
|
Logic::Google::Tokens.apply_policies!(cartridge, payload),
|
159
|
-
|
174
|
+
server_sent_events: false
|
160
175
|
)
|
161
176
|
|
162
177
|
tools = result.dig(0, 'candidates', 0, 'content', 'parts').filter do |part|
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mistral-ai'
|
4
|
+
|
5
|
+
require_relative 'base'
|
6
|
+
|
7
|
+
require_relative '../../logic/providers/mistral/tokens'
|
8
|
+
require_relative '../../logic/helpers/hash'
|
9
|
+
require_relative '../../logic/cartridge/default'
|
10
|
+
|
11
|
+
module NanoBot
|
12
|
+
module Components
|
13
|
+
module Providers
|
14
|
+
class Mistral < Base
|
15
|
+
attr_reader :settings
|
16
|
+
|
17
|
+
CHAT_SETTINGS = %i[
|
18
|
+
model temperature top_p max_tokens stream safe_mode random_seed
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
def initialize(options, settings, credentials, _environment)
|
22
|
+
@settings = settings
|
23
|
+
|
24
|
+
mistral_options = if options
|
25
|
+
options.transform_keys { |key| key.to_s.gsub('-', '_').to_sym }
|
26
|
+
else
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
|
30
|
+
unless @settings.key?(:stream)
|
31
|
+
@settings = Marshal.load(Marshal.dump(@settings))
|
32
|
+
@settings[:stream] = Logic::Helpers::Hash.fetch(
|
33
|
+
Logic::Cartridge::Default.instance.values, %i[provider settings stream]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
mistral_options[:server_sent_events] = @settings[:stream]
|
38
|
+
|
39
|
+
@client = ::Mistral.new(
|
40
|
+
credentials: credentials.transform_keys { |key| key.to_s.gsub('-', '_').to_sym },
|
41
|
+
options: mistral_options
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def evaluate(input, streaming, cartridge, &feedback)
|
46
|
+
messages = input[:history].map do |event|
|
47
|
+
{ role: event[:who] == 'user' ? 'user' : 'assistant',
|
48
|
+
content: event[:message],
|
49
|
+
_meta: { at: event[:at] } }
|
50
|
+
end
|
51
|
+
|
52
|
+
%i[backdrop directive].each do |key|
|
53
|
+
next unless input[:behavior][key]
|
54
|
+
|
55
|
+
messages.prepend(
|
56
|
+
{ role: key == :directive ? 'system' : 'user',
|
57
|
+
content: input[:behavior][key],
|
58
|
+
_meta: { at: Time.now } }
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
payload = { messages: }
|
63
|
+
|
64
|
+
CHAT_SETTINGS.each do |key|
|
65
|
+
payload[key] = @settings[key] unless payload.key?(key) || !@settings.key?(key)
|
66
|
+
end
|
67
|
+
|
68
|
+
raise 'Mistral does not support tools.' if input[:tools]
|
69
|
+
|
70
|
+
if streaming
|
71
|
+
content = ''
|
72
|
+
|
73
|
+
stream_call_back = proc do |event, _parsed, _raw|
|
74
|
+
partial_content = event.dig('choices', 0, 'delta', 'content')
|
75
|
+
|
76
|
+
if partial_content
|
77
|
+
content += partial_content
|
78
|
+
feedback.call(
|
79
|
+
{ should_be_stored: false,
|
80
|
+
interaction: { who: 'AI', message: partial_content } }
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
if event.dig('choices', 0, 'finish_reason')
|
85
|
+
feedback.call(
|
86
|
+
{ should_be_stored: !(content.nil? || content == ''),
|
87
|
+
interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
|
88
|
+
finished: true }
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
@client.chat_completions(
|
94
|
+
Logic::Mistral::Tokens.apply_policies!(cartridge, payload),
|
95
|
+
server_sent_events: true, &stream_call_back
|
96
|
+
)
|
97
|
+
else
|
98
|
+
result = @client.chat_completions(
|
99
|
+
Logic::Mistral::Tokens.apply_policies!(cartridge, payload),
|
100
|
+
server_sent_events: false
|
101
|
+
)
|
102
|
+
|
103
|
+
content = result.dig('choices', 0, 'message', 'content')
|
104
|
+
|
105
|
+
feedback.call(
|
106
|
+
{ should_be_stored: !(content.nil? || content.to_s.strip == ''),
|
107
|
+
interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
|
108
|
+
finished: true }
|
109
|
+
)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/controllers/session.rb
CHANGED
@@ -138,7 +138,6 @@ module NanoBot
|
|
138
138
|
feedback[:interaction][:meta][:tool][:action] == 'confirming'
|
139
139
|
Interfaces::Tool.confirming(self, @cartridge, mode, feedback[:interaction][:meta][:tool])
|
140
140
|
else
|
141
|
-
|
142
141
|
if feedback[:interaction] && feedback.dig(:interaction, :meta, :tool, :action)
|
143
142
|
Interfaces::Tool.dispatch_feedback(
|
144
143
|
self, @cartridge, mode, feedback[:interaction][:meta][:tool]
|
data/docker-compose.example.yml
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
services:
|
3
3
|
nano-bots:
|
4
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 2.
|
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 2.4.0 && bash"
|
6
6
|
environment:
|
7
7
|
OPENAI_API_ADDRESS: https://api.openai.com
|
8
8
|
OPENAI_API_KEY: your-access-token
|
@@ -8,7 +8,7 @@ module NanoBot
|
|
8
8
|
module Streaming
|
9
9
|
def self.enabled?(cartridge, interface)
|
10
10
|
provider_stream = case Helpers::Hash.fetch(cartridge, %i[provider id])
|
11
|
-
when 'openai'
|
11
|
+
when 'openai', 'mistral', 'cohere'
|
12
12
|
Helpers::Hash.fetch(cartridge, %i[provider settings stream])
|
13
13
|
when 'google'
|
14
14
|
Helpers::Hash.fetch(cartridge, %i[provider options stream])
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NanoBot
|
4
|
+
module Logic
|
5
|
+
module Cohere
|
6
|
+
module Tokens
|
7
|
+
def self.apply_policies!(_cartridge, payload)
|
8
|
+
if payload[:chat_history]
|
9
|
+
payload[:chat_history] = payload[:chat_history].map { |message| message.except(:_meta) }
|
10
|
+
end
|
11
|
+
|
12
|
+
payload
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NanoBot
|
4
|
+
module Logic
|
5
|
+
module Mistral
|
6
|
+
module Tokens
|
7
|
+
def self.apply_policies!(_cartridge, payload)
|
8
|
+
payload[:messages] = payload[:messages].map { |message| message.except(:_meta) }
|
9
|
+
payload
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/nano-bots.gemspec
CHANGED
@@ -32,9 +32,11 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.executables = ['nb']
|
33
33
|
|
34
34
|
spec.add_dependency 'babosa', '~> 2.0'
|
35
|
+
spec.add_dependency 'cohere-ai', '~> 1.0', '>= 1.0.1'
|
35
36
|
spec.add_dependency 'concurrent-ruby', '~> 1.2', '>= 1.2.2'
|
36
37
|
spec.add_dependency 'dotenv', '~> 2.8', '>= 2.8.1'
|
37
|
-
spec.add_dependency 'gemini-ai', '~>
|
38
|
+
spec.add_dependency 'gemini-ai', '~> 3.1'
|
39
|
+
spec.add_dependency 'mistral-ai', '~> 1.1'
|
38
40
|
spec.add_dependency 'pry', '~> 0.14.2'
|
39
41
|
spec.add_dependency 'rainbow', '~> 3.1', '>= 3.1.1'
|
40
42
|
spec.add_dependency 'rbnacl', '~> 7.1', '>= 7.1.1'
|
data/static/gem.rb
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
module NanoBot
|
4
4
|
GEM = {
|
5
5
|
name: 'nano-bots',
|
6
|
-
version: '2.
|
7
|
-
specification: '2.0
|
6
|
+
version: '2.4.0',
|
7
|
+
specification: '2.1.0',
|
8
8
|
author: 'icebaker',
|
9
|
-
summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT and Google Gemini.',
|
10
|
-
description: 'Ruby Implementation of Nano Bots: small, AI-powered bots that can be easily shared as a single file, designed to support multiple providers such as OpenAI ChatGPT and Google Gemini, with support for calling Tools (Functions).',
|
9
|
+
summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT, Mistral AI, and Google Gemini.',
|
10
|
+
description: 'Ruby Implementation of Nano Bots: small, AI-powered bots that can be easily shared as a single file, designed to support multiple providers such as OpenAI ChatGPT, Mistral AI, and Google Gemini, with support for calling Tools (Functions).',
|
11
11
|
github: 'https://github.com/icebaker/ruby-nano-bots',
|
12
12
|
gem_server: 'https://rubygems.org',
|
13
13
|
license: 'MIT',
|
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: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- icebaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: babosa
|
@@ -24,6 +24,26 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cohere-ai
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.1
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: concurrent-ruby
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,14 +90,28 @@ dependencies:
|
|
70
90
|
requirements:
|
71
91
|
- - "~>"
|
72
92
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
93
|
+
version: '3.1'
|
94
|
+
type: :runtime
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '3.1'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: mistral-ai
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '1.1'
|
74
108
|
type: :runtime
|
75
109
|
prerelease: false
|
76
110
|
version_requirements: !ruby/object:Gem::Requirement
|
77
111
|
requirements:
|
78
112
|
- - "~>"
|
79
113
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
114
|
+
version: '1.1'
|
81
115
|
- !ruby/object:Gem::Dependency
|
82
116
|
name: pry
|
83
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,7 +202,7 @@ dependencies:
|
|
168
202
|
version: 0.0.7
|
169
203
|
description: 'Ruby Implementation of Nano Bots: small, AI-powered bots that can be
|
170
204
|
easily shared as a single file, designed to support multiple providers such as OpenAI
|
171
|
-
ChatGPT and Google Gemini, with support for calling Tools (Functions).'
|
205
|
+
ChatGPT, Mistral AI, and Google Gemini, with support for calling Tools (Functions).'
|
172
206
|
email:
|
173
207
|
executables:
|
174
208
|
- nb
|
@@ -189,7 +223,9 @@ files:
|
|
189
223
|
- components/embedding.rb
|
190
224
|
- components/provider.rb
|
191
225
|
- components/providers/base.rb
|
226
|
+
- components/providers/cohere.rb
|
192
227
|
- components/providers/google.rb
|
228
|
+
- components/providers/mistral.rb
|
193
229
|
- components/providers/openai.rb
|
194
230
|
- components/providers/tools.rb
|
195
231
|
- components/storage.rb
|
@@ -212,8 +248,10 @@ files:
|
|
212
248
|
- logic/cartridge/streaming.rb
|
213
249
|
- logic/cartridge/tools.rb
|
214
250
|
- logic/helpers/hash.rb
|
251
|
+
- logic/providers/cohere/tokens.rb
|
215
252
|
- logic/providers/google/tokens.rb
|
216
253
|
- logic/providers/google/tools.rb
|
254
|
+
- logic/providers/mistral/tokens.rb
|
217
255
|
- logic/providers/openai.rb
|
218
256
|
- logic/providers/openai/tokens.rb
|
219
257
|
- logic/providers/openai/tools.rb
|
@@ -251,6 +289,6 @@ requirements: []
|
|
251
289
|
rubygems_version: 3.4.22
|
252
290
|
signing_key:
|
253
291
|
specification_version: 4
|
254
|
-
summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT
|
255
|
-
and Google Gemini.'
|
292
|
+
summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT,
|
293
|
+
Mistral AI, and Google Gemini.'
|
256
294
|
test_files: []
|