nano-bots 2.2.0 → 2.3.0

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: d87686427ed075d44e4c4b21e41de70047adf4ce56eb73c50f77fb695e63a562
4
- data.tar.gz: 8bc004c9dfe2a004fa8e6f7bbcc946e461c54daf7b9b58b7e416c9f3c8ebe734
3
+ metadata.gz: 24116f0116f8579c111230b6aa4917891c6c30c07d7d515f176196ea46ea387e
4
+ data.tar.gz: ff29d36311931cba518560ad4bbf2ca39b71c77f3db40114107b0cc208cf2b63
5
5
  SHA512:
6
- metadata.gz: 0ce8acc93fbd5eedaaaae2dc271ab64998fad38e3e2f5f40e9a0a51e4cbed01e25787ff77ebf02663e88786c01ede5a70127052aeb2fcf6dfcb58c22bb004620
7
- data.tar.gz: c46e9cfcbbb2d871191153c48760cd4625216b6dbbff598c2921635df7af02fdca8923b806fc9fdbe35ee86ab6c6217a63b287b3bf65c42d5281aff9c91e8878
6
+ metadata.gz: 7d3737b8496efcc2a0f4407cce1a9aee097f996b2c0150b72b494036a86ed434fb8a0aae5348d127d0562e7ba28636e499d3df4eeee039a15da9ffe5b0611e80
7
+ data.tar.gz: '0318d81ce592a24bf116bcabd555ed53fcf5a7dbbe745f5c571c27fe05b4b656776c50b6d29300d58844da51eb45e5e56ee91b1ca86690e65af42140105c4879'
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nano-bots (2.2.0)
4
+ nano-bots (2.3.0)
5
5
  babosa (~> 2.0)
6
6
  concurrent-ruby (~> 1.2, >= 1.2.2)
7
7
  dotenv (~> 2.8, >= 2.8.1)
8
- gemini-ai (~> 2.2)
8
+ gemini-ai (~> 3.1)
9
+ mistral-ai (~> 1.0)
9
10
  pry (~> 0.14.2)
10
11
  rainbow (~> 3.1, >= 3.1.1)
11
12
  rbnacl (~> 7.1, >= 7.1.1)
@@ -26,7 +27,7 @@ GEM
26
27
  diff-lcs (1.5.0)
27
28
  dotenv (2.8.1)
28
29
  event_stream_parser (1.0.0)
29
- faraday (2.7.12)
30
+ faraday (2.8.1)
30
31
  base64
31
32
  faraday-net_http (>= 2.0, < 3.1)
32
33
  ruby2_keywords (>= 0.0.4)
@@ -34,9 +35,9 @@ GEM
34
35
  multipart-post (~> 2)
35
36
  faraday-net_http (3.0.2)
36
37
  ffi (1.16.3)
37
- gemini-ai (2.2.0)
38
+ gemini-ai (3.1.0)
38
39
  event_stream_parser (~> 1.0)
39
- faraday (~> 2.7, >= 2.7.12)
40
+ faraday (~> 2.8, >= 2.8.1)
40
41
  googleauth (~> 1.9, >= 1.9.1)
41
42
  google-cloud-env (2.1.0)
42
43
  faraday (>= 1.0, < 3.a)
@@ -51,6 +52,9 @@ GEM
51
52
  jwt (2.7.1)
52
53
  language_server-protocol (3.17.0.3)
53
54
  method_source (1.0.0)
55
+ mistral-ai (1.0.0)
56
+ event_stream_parser (~> 1.0)
57
+ faraday (~> 2.8, >= 2.8.1)
54
58
  multi_json (1.15.0)
55
59
  multipart-post (2.3.0)
56
60
  os (1.1.4)
data/README.md CHANGED
@@ -1,27 +1,29 @@
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), and [Google Gemini](https://deepmind.google/technologies/gemini).
4
4
 
5
- ![Ruby Nano Bots](https://user-images.githubusercontent.com/113217272/237839690-7880915a-b287-4484-a75e-0b96284b8a32.png)
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
  - [OpenAI ChatGPT](#openai-chatgpt)
11
+ - [Mistral AI](#mistral-ai)
12
12
  - [Google Gemini](#google-gemini)
13
- - [Docker](#docker)
14
- - [OpenAI ChatGPT](#openai-chatgpt-1)
15
- - [Google Gemini](#google-gemini-1)
16
13
  - [Usage](#usage)
17
14
  - [Command Line](#command-line)
18
15
  - [Library](#library)
19
16
  - [Cartridges](#cartridges)
20
- - [OpenAI ChatGPT](#openai-chatgpt-2)
21
- - [Google Gemini](#google-gemini-2)
17
+ - [OpenAI ChatGPT](#openai-chatgpt-1)
18
+ - [Mistral AI](#mistral-ai-1)
19
+ - [Google Gemini](#google-gemini-1)
22
20
  - [Tools (Functions)](#tools-functions)
23
21
  - [Experimental Clojure Support](#experimental-clojure-support)
24
22
  - [Marketplace](#marketplace)
23
+ - [Docker](#docker)
24
+ - [OpenAI ChatGPT](#openai-chatgpt-2)
25
+ - [Mistral AI](#mistral-ai-2)
26
+ - [Google Gemini](#google-gemini-2)
25
27
  - [Security and Privacy](#security-and-privacy)
26
28
  - [Cryptography](#cryptography)
27
29
  - [End-user IDs](#end-user-ids)
@@ -36,13 +38,13 @@ https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b
36
38
  For a system usage:
37
39
 
38
40
  ```sh
39
- gem install nano-bots -v 2.2.0
41
+ gem install nano-bots -v 2.3.0
40
42
  ```
41
43
 
42
44
  To use it in a project, add it to your `Gemfile`:
43
45
 
44
46
  ```ruby
45
- gem 'nano-bots', '~> 2.2.0'
47
+ gem 'nano-bots', '~> 2.3.0'
46
48
  ```
47
49
 
48
50
  ```sh
@@ -51,12 +53,7 @@ bundle install
51
53
 
52
54
  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
55
 
54
- ### OpenAI ChatGPT
55
-
56
56
  ```sh
57
- export OPENAI_API_ADDRESS=https://api.openai.com
58
- export OPENAI_API_KEY=your-access-token
59
-
60
57
  export NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
61
58
  export NANO_BOTS_END_USER=your-user
62
59
 
@@ -67,9 +64,6 @@ export NANO_BOTS_END_USER=your-user
67
64
  Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
68
65
 
69
66
  ```sh
70
- OPENAI_API_ADDRESS=https://api.openai.com
71
- OPENAI_API_KEY=your-access-token
72
-
73
67
  NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
74
68
  NANO_BOTS_END_USER=your-user
75
69
 
@@ -77,6 +71,38 @@ NANO_BOTS_END_USER=your-user
77
71
  # NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
78
72
  ```
79
73
 
74
+ ### OpenAI ChatGPT
75
+
76
+ You can obtain your credentials on the [OpenAI Platform](https://platform.openai.com).
77
+
78
+ ```sh
79
+ export OPENAI_API_ADDRESS=https://api.openai.com
80
+ export OPENAI_API_KEY=your-access-token
81
+ ```
82
+
83
+ Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
84
+
85
+ ```sh
86
+ OPENAI_API_ADDRESS=https://api.openai.com
87
+ OPENAI_API_KEY=your-access-token
88
+ ```
89
+
90
+ ### Mistral AI
91
+
92
+ You can obtain your credentials on the [Mistral Platform](https://console.mistral.ai).
93
+
94
+ ```sh
95
+ export MISTRAL_API_ADDRESS=https://api.mistral.ai
96
+ export MISTRAL_API_KEY=your-api-key
97
+ ```
98
+
99
+ Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
100
+
101
+ ```sh
102
+ MISTRAL_API_ADDRESS=https://api.mistral.ai
103
+ MISTRAL_API_KEY=your-api-key
104
+ ```
105
+
80
106
  ### Google Gemini
81
107
 
82
108
  Click [here](https://github.com/gbaptista/gemini-ai#credentials) to learn how to obtain your credentials.
@@ -169,117 +195,6 @@ Alternatively, if your current directory has a `.env` file with the environment
169
195
  GOOGLE_PROJECT_ID=your-project-id
170
196
  ```
171
197
 
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
198
  ## Usage
284
199
 
285
200
  ### Command Line
@@ -447,6 +362,32 @@ provider:
447
362
  model: gpt-4-1106-preview
448
363
  ```
449
364
 
365
+ ### Mistral AI
366
+
367
+ Read the [full specification](https://spec.nbots.io/#/README?id=mistral-ai) for Mistral AI.
368
+
369
+ ```yaml
370
+ ---
371
+ meta:
372
+ symbol: 🤖
373
+ name: Nano Bot Name
374
+ author: Your Name
375
+ version: 1.0.0
376
+ license: CC0-1.0
377
+ description: A helpful assistant.
378
+
379
+ behaviors:
380
+ interaction:
381
+ directive: You are a helpful assistant.
382
+
383
+ provider:
384
+ id: mistral
385
+ credentials:
386
+ api-key: ENV/MISTRAL_API_KEY
387
+ settings:
388
+ model: mistral-medium
389
+ ```
390
+
450
391
  ### Google Gemini
451
392
 
452
393
  Read the [full specification](https://spec.nbots.io/#/README?id=google-gemini) for Google Gemini.
@@ -564,7 +505,7 @@ The randomly generated number is 59.
564
505
 
565
506
  🤖> |
566
507
  ```
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`.
508
+ 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
509
 
569
510
  Check the [Nano Bots specification](https://spec.nbots.io/#/README?id=tools-functions-2) to learn more about Tools (Functions).
570
511
 
@@ -609,6 +550,135 @@ safety:
609
550
 
610
551
  You can explore the Nano Bots [Marketplace](https://nbots.io) to discover new Cartridges that can help you.
611
552
 
553
+ ## Docker
554
+
555
+ Clone the repository and copy the Docker Compose template:
556
+
557
+ ```
558
+ git clone https://github.com/icebaker/ruby-nano-bots.git
559
+ cd ruby-nano-bots
560
+ cp docker-compose.example.yml docker-compose.yml
561
+ ```
562
+
563
+ Set your provider credentials and choose your desired directory for the cartridges files:
564
+
565
+ ### OpenAI ChatGPT
566
+
567
+ ```yaml
568
+ ---
569
+ services:
570
+ nano-bots:
571
+ image: ruby:3.2.2-slim-bookworm
572
+ 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.3.0 && bash"
573
+ environment:
574
+ OPENAI_API_ADDRESS: https://api.openai.com
575
+ OPENAI_API_KEY: your-access-token
576
+ NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
577
+ NANO_BOTS_END_USER: your-user
578
+ volumes:
579
+ - ./your-cartridges:/root/.local/share/nano-bots/cartridges
580
+ - ./your-state-path:/root/.local/state/nano-bots
581
+ ```
582
+
583
+ ### Mistral AI
584
+
585
+ ```yaml
586
+ ---
587
+ services:
588
+ nano-bots:
589
+ image: ruby:3.2.2-slim-bookworm
590
+ 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.3.0 && bash"
591
+ environment:
592
+ MISTRAL_API_ADDRESS: https://api.mistral.ai
593
+ MISTRAL_API_KEY: your-api-key
594
+ NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
595
+ NANO_BOTS_END_USER: your-user
596
+ volumes:
597
+ - ./your-cartridges:/root/.local/share/nano-bots/cartridges
598
+ - ./your-state-path:/root/.local/state/nano-bots
599
+ ```
600
+
601
+ ### Google Gemini
602
+
603
+ #### Option 1: API Key (Generative Language API)
604
+
605
+ ```yaml
606
+ ---
607
+ services:
608
+ nano-bots:
609
+ image: ruby:3.2.2-slim-bookworm
610
+ 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.3.0 && bash"
611
+ environment:
612
+ GOOGLE_API_KEY: your-api-key
613
+ NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
614
+ NANO_BOTS_END_USER: your-user
615
+ volumes:
616
+ - ./your-cartridges:/root/.local/share/nano-bots/cartridges
617
+ - ./your-state-path:/root/.local/state/nano-bots
618
+ ```
619
+
620
+ #### Option 2: Service Account Credentials File (Vertex AI API)
621
+
622
+ ```yaml
623
+ ---
624
+ services:
625
+ nano-bots:
626
+ image: ruby:3.2.2-slim-bookworm
627
+ 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.3.0 && bash"
628
+ environment:
629
+ GOOGLE_CREDENTIALS_FILE_PATH: /root/.config/google-credentials.json
630
+ GOOGLE_REGION: us-east4
631
+ NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
632
+ NANO_BOTS_END_USER: your-user
633
+ volumes:
634
+ - ./google-credentials.json:/root/.config/google-credentials.json
635
+ - ./your-cartridges:/root/.local/share/nano-bots/cartridges
636
+ - ./your-state-path:/root/.local/state/nano-bots
637
+ ```
638
+
639
+ #### Option 3: Application Default Credentials (Vertex AI API)
640
+
641
+ ```yaml
642
+ ---
643
+ services:
644
+ nano-bots:
645
+ image: ruby:3.2.2-slim-bookworm
646
+ 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.3.0 && bash"
647
+ environment:
648
+ GOOGLE_REGION: us-east4
649
+ NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
650
+ NANO_BOTS_END_USER: your-user
651
+ volumes:
652
+ - ./your-cartridges:/root/.local/share/nano-bots/cartridges
653
+ - ./your-state-path:/root/.local/state/nano-bots
654
+ ```
655
+
656
+ #### Custom Project ID
657
+ If you need to manually set a Google Project ID:
658
+
659
+ ```yaml
660
+ environment:
661
+ GOOGLE_PROJECT_ID=your-project-id
662
+ ```
663
+
664
+ ### Container
665
+
666
+ Enter the container:
667
+ ```sh
668
+ docker compose run nano-bots
669
+ ```
670
+
671
+ Start playing:
672
+ ```sh
673
+ nb - - eval "hello"
674
+ nb - - repl
675
+
676
+ nb assistant.yml - eval "hello"
677
+ nb assistant.yml - repl
678
+ ```
679
+
680
+ You can exit the REPL by typing `exit`.
681
+
612
682
  ## Security and Privacy
613
683
 
614
684
  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.
@@ -720,6 +790,7 @@ If you lose your password, you lose your data. It is not possible to recover it
720
790
  Currently supported providers:
721
791
 
722
792
  - [x] [Open AI ChatGPT](https://platform.openai.com/docs/api-reference)
793
+ - [x] [Mistral AI](https://docs.mistral.ai/api/)
723
794
  - [x] [Google Gemini](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini)
724
795
  - [ ] [Anthropic Claude](https://www.anthropic.com)
725
796
  - [ ] [Cohere Command](https://cohere.com)
@@ -745,5 +816,5 @@ gem build nano-bots.gemspec
745
816
 
746
817
  gem signin
747
818
 
748
- gem push nano-bots-2.2.0.gem
819
+ gem push nano-bots-2.3.0.gem
749
820
  ```
@@ -1,7 +1,8 @@
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'
5
6
 
6
7
  module NanoBot
7
8
  module Components
@@ -12,6 +13,8 @@ module NanoBot
12
13
  Providers::OpenAI.new(nil, provider[:settings], provider[:credentials], environment:)
13
14
  when 'google'
14
15
  Providers::Google.new(provider[:options], provider[:settings], provider[:credentials], environment:)
16
+ when 'mistral'
17
+ Providers::Mistral.new(provider[:options], provider[:settings], provider[:credentials], environment:)
15
18
  else
16
19
  raise "Unsupported provider \"#{provider[:id]}\""
17
20
  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: options.transform_keys { |key| key.to_s.gsub('-', '_').to_sym }
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
- stream: true, &stream_call_back
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
- stream: false
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
@@ -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]
@@ -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.2.0 && bash"
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.3.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'
12
12
  Helpers::Hash.fetch(cartridge, %i[provider settings stream])
13
13
  when 'google'
14
14
  Helpers::Hash.fetch(cartridge, %i[provider options stream])
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'openai'
4
-
5
3
  module NanoBot
6
4
  module Logic
7
5
  module Google
@@ -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
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'openai'
4
-
5
3
  module NanoBot
6
4
  module Logic
7
5
  module OpenAI
data/nano-bots.gemspec CHANGED
@@ -34,7 +34,8 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency 'babosa', '~> 2.0'
35
35
  spec.add_dependency 'concurrent-ruby', '~> 1.2', '>= 1.2.2'
36
36
  spec.add_dependency 'dotenv', '~> 2.8', '>= 2.8.1'
37
- spec.add_dependency 'gemini-ai', '~> 2.2'
37
+ spec.add_dependency 'gemini-ai', '~> 3.1'
38
+ spec.add_dependency 'mistral-ai', '~> 1.0'
38
39
  spec.add_dependency 'pry', '~> 0.14.2'
39
40
  spec.add_dependency 'rainbow', '~> 3.1', '>= 3.1.1'
40
41
  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.2.0',
7
- specification: '2.0.1',
6
+ version: '2.3.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.2.0
4
+ version: 2.3.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-17 00:00:00.000000000 Z
11
+ date: 2023-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: babosa
@@ -70,14 +70,28 @@ dependencies:
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '2.2'
73
+ version: '3.1'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '3.1'
81
+ - !ruby/object:Gem::Dependency
82
+ name: mistral-ai
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '1.0'
74
88
  type: :runtime
75
89
  prerelease: false
76
90
  version_requirements: !ruby/object:Gem::Requirement
77
91
  requirements:
78
92
  - - "~>"
79
93
  - !ruby/object:Gem::Version
80
- version: '2.2'
94
+ version: '1.0'
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: pry
83
97
  requirement: !ruby/object:Gem::Requirement
@@ -168,7 +182,7 @@ dependencies:
168
182
  version: 0.0.7
169
183
  description: 'Ruby Implementation of Nano Bots: small, AI-powered bots that can be
170
184
  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).'
185
+ ChatGPT, Mistral AI, and Google Gemini, with support for calling Tools (Functions).'
172
186
  email:
173
187
  executables:
174
188
  - nb
@@ -190,6 +204,7 @@ files:
190
204
  - components/provider.rb
191
205
  - components/providers/base.rb
192
206
  - components/providers/google.rb
207
+ - components/providers/mistral.rb
193
208
  - components/providers/openai.rb
194
209
  - components/providers/tools.rb
195
210
  - components/storage.rb
@@ -214,6 +229,7 @@ files:
214
229
  - logic/helpers/hash.rb
215
230
  - logic/providers/google/tokens.rb
216
231
  - logic/providers/google/tools.rb
232
+ - logic/providers/mistral/tokens.rb
217
233
  - logic/providers/openai.rb
218
234
  - logic/providers/openai/tokens.rb
219
235
  - logic/providers/openai/tools.rb
@@ -251,6 +267,6 @@ requirements: []
251
267
  rubygems_version: 3.4.22
252
268
  signing_key:
253
269
  specification_version: 4
254
- summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT
255
- and Google Gemini.'
270
+ summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT,
271
+ Mistral AI, and Google Gemini.'
256
272
  test_files: []