nano-bots 2.3.0 → 2.4.0
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 +6 -3
- data/README.md +103 -38
- data/components/provider.rb +3 -0
- data/components/providers/cohere.rb +121 -0
- data/docker-compose.example.yml +1 -1
- data/logic/cartridge/streaming.rb +1 -1
- data/logic/providers/cohere/tokens.rb +17 -0
- data/nano-bots.gemspec +2 -1
- data/static/gem.rb +1 -1
- metadata +25 -3
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,12 +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
9
|
gemini-ai (~> 3.1)
|
|
9
|
-
mistral-ai (~> 1.
|
|
10
|
+
mistral-ai (~> 1.1)
|
|
10
11
|
pry (~> 0.14.2)
|
|
11
12
|
rainbow (~> 3.1, >= 3.1.1)
|
|
12
13
|
rbnacl (~> 7.1, >= 7.1.1)
|
|
@@ -23,6 +24,8 @@ GEM
|
|
|
23
24
|
base64 (0.2.0)
|
|
24
25
|
byebug (11.1.3)
|
|
25
26
|
coderay (1.1.3)
|
|
27
|
+
cohere-ai (1.0.1)
|
|
28
|
+
faraday (~> 2.8, >= 2.8.1)
|
|
26
29
|
concurrent-ruby (1.2.2)
|
|
27
30
|
diff-lcs (1.5.0)
|
|
28
31
|
dotenv (2.8.1)
|
|
@@ -52,7 +55,7 @@ GEM
|
|
|
52
55
|
jwt (2.7.1)
|
|
53
56
|
language_server-protocol (3.17.0.3)
|
|
54
57
|
method_source (1.0.0)
|
|
55
|
-
mistral-ai (1.
|
|
58
|
+
mistral-ai (1.1.0)
|
|
56
59
|
event_stream_parser (~> 1.0)
|
|
57
60
|
faraday (~> 2.8, >= 2.8.1)
|
|
58
61
|
multi_json (1.15.0)
|
data/README.md
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
# Nano Bots 💎 🤖
|
|
2
2
|
|
|
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).
|
|
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
5
|

|
|
6
6
|
|
|
7
7
|
https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b-864a-0f49bbf6e22f.mp4
|
|
8
8
|
|
|
9
9
|
- [Setup](#setup)
|
|
10
|
-
- [
|
|
11
|
-
- [Mistral AI](#mistral-ai)
|
|
10
|
+
- [Cohere Command](#cohere-command)
|
|
12
11
|
- [Google Gemini](#google-gemini)
|
|
12
|
+
- [Mistral AI](#mistral-ai)
|
|
13
|
+
- [OpenAI ChatGPT](#openai-chatgpt)
|
|
13
14
|
- [Usage](#usage)
|
|
14
15
|
- [Command Line](#command-line)
|
|
15
16
|
- [Library](#library)
|
|
16
17
|
- [Cartridges](#cartridges)
|
|
17
|
-
- [
|
|
18
|
-
- [Mistral AI](#mistral-ai-1)
|
|
18
|
+
- [Cohere Command](#cohere-command-1)
|
|
19
19
|
- [Google Gemini](#google-gemini-1)
|
|
20
|
+
- [Mistral AI](#mistral-ai-1)
|
|
21
|
+
- [OpenAI ChatGPT](#openai-chatgpt-1)
|
|
20
22
|
- [Tools (Functions)](#tools-functions)
|
|
21
23
|
- [Experimental Clojure Support](#experimental-clojure-support)
|
|
22
24
|
- [Marketplace](#marketplace)
|
|
23
25
|
- [Docker](#docker)
|
|
24
|
-
- [
|
|
25
|
-
- [Mistral AI](#mistral-ai-2)
|
|
26
|
+
- [Cohere Command](#cohere-command-2)
|
|
26
27
|
- [Google Gemini](#google-gemini-2)
|
|
28
|
+
- [Mistral AI](#mistral-ai-2)
|
|
29
|
+
- [OpenAI ChatGPT](#openai-chatgpt-2)
|
|
27
30
|
- [Security and Privacy](#security-and-privacy)
|
|
28
31
|
- [Cryptography](#cryptography)
|
|
29
32
|
- [End-user IDs](#end-user-ids)
|
|
@@ -38,13 +41,13 @@ https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b
|
|
|
38
41
|
For a system usage:
|
|
39
42
|
|
|
40
43
|
```sh
|
|
41
|
-
gem install nano-bots -v 2.
|
|
44
|
+
gem install nano-bots -v 2.4.0
|
|
42
45
|
```
|
|
43
46
|
|
|
44
47
|
To use it in a project, add it to your `Gemfile`:
|
|
45
48
|
|
|
46
49
|
```ruby
|
|
47
|
-
gem 'nano-bots', '~> 2.
|
|
50
|
+
gem 'nano-bots', '~> 2.4.0'
|
|
48
51
|
```
|
|
49
52
|
|
|
50
53
|
```sh
|
|
@@ -71,20 +74,20 @@ NANO_BOTS_END_USER=your-user
|
|
|
71
74
|
# NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
|
|
72
75
|
```
|
|
73
76
|
|
|
74
|
-
###
|
|
77
|
+
### Cohere Command
|
|
75
78
|
|
|
76
|
-
You can obtain your credentials on the [
|
|
79
|
+
You can obtain your credentials on the [Cohere Platform](https://dashboard.cohere.com).
|
|
77
80
|
|
|
78
81
|
```sh
|
|
79
|
-
export
|
|
80
|
-
export
|
|
82
|
+
export COHERE_API_ADDRESS=https://api.cohere.ai
|
|
83
|
+
export COHERE_API_KEY=your-api-key
|
|
81
84
|
```
|
|
82
85
|
|
|
83
86
|
Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
|
|
84
87
|
|
|
85
88
|
```sh
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
COHERE_API_ADDRESS=https://api.cohere.ai
|
|
90
|
+
COHERE_API_KEY=your-api-key
|
|
88
91
|
```
|
|
89
92
|
|
|
90
93
|
### Mistral AI
|
|
@@ -103,6 +106,22 @@ MISTRAL_API_ADDRESS=https://api.mistral.ai
|
|
|
103
106
|
MISTRAL_API_KEY=your-api-key
|
|
104
107
|
```
|
|
105
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
|
+
|
|
106
125
|
### Google Gemini
|
|
107
126
|
|
|
108
127
|
Click [here](https://github.com/gbaptista/gemini-ai#credentials) to learn how to obtain your credentials.
|
|
@@ -334,9 +353,9 @@ Try the [Nano Bots Clinic (Live Editor)](https://clinic.nbots.io) to learn about
|
|
|
334
353
|
|
|
335
354
|
Here's what a Nano Bot Cartridge looks like:
|
|
336
355
|
|
|
337
|
-
###
|
|
356
|
+
### Cohere Command
|
|
338
357
|
|
|
339
|
-
Read the [full specification](https://spec.nbots.io/#/README?id=
|
|
358
|
+
Read the [full specification](https://spec.nbots.io/#/README?id=cohere-command) for Cohere Command.
|
|
340
359
|
|
|
341
360
|
```yaml
|
|
342
361
|
---
|
|
@@ -353,13 +372,11 @@ behaviors:
|
|
|
353
372
|
directive: You are a helpful assistant.
|
|
354
373
|
|
|
355
374
|
provider:
|
|
356
|
-
id:
|
|
375
|
+
id: cohere
|
|
357
376
|
credentials:
|
|
358
|
-
|
|
359
|
-
access-token: ENV/OPENAI_API_KEY
|
|
377
|
+
api-key: ENV/COHERE_API_KEY
|
|
360
378
|
settings:
|
|
361
|
-
|
|
362
|
-
model: gpt-4-1106-preview
|
|
379
|
+
model: command
|
|
363
380
|
```
|
|
364
381
|
|
|
365
382
|
### Mistral AI
|
|
@@ -388,6 +405,34 @@ provider:
|
|
|
388
405
|
model: mistral-medium
|
|
389
406
|
```
|
|
390
407
|
|
|
408
|
+
### OpenAI ChatGPT
|
|
409
|
+
|
|
410
|
+
Read the [full specification](https://spec.nbots.io/#/README?id=openai-chatgpt) for OpenAI ChatGPT.
|
|
411
|
+
|
|
412
|
+
```yaml
|
|
413
|
+
---
|
|
414
|
+
meta:
|
|
415
|
+
symbol: 🤖
|
|
416
|
+
name: Nano Bot Name
|
|
417
|
+
author: Your Name
|
|
418
|
+
version: 1.0.0
|
|
419
|
+
license: CC0-1.0
|
|
420
|
+
description: A helpful assistant.
|
|
421
|
+
|
|
422
|
+
behaviors:
|
|
423
|
+
interaction:
|
|
424
|
+
directive: You are a helpful assistant.
|
|
425
|
+
|
|
426
|
+
provider:
|
|
427
|
+
id: openai
|
|
428
|
+
credentials:
|
|
429
|
+
address: ENV/OPENAI_API_ADDRESS
|
|
430
|
+
access-token: ENV/OPENAI_API_KEY
|
|
431
|
+
settings:
|
|
432
|
+
user: ENV/NANO_BOTS_END_USER
|
|
433
|
+
model: gpt-4-1106-preview
|
|
434
|
+
```
|
|
435
|
+
|
|
391
436
|
### Google Gemini
|
|
392
437
|
|
|
393
438
|
Read the [full specification](https://spec.nbots.io/#/README?id=google-gemini) for Google Gemini.
|
|
@@ -562,17 +607,17 @@ cp docker-compose.example.yml docker-compose.yml
|
|
|
562
607
|
|
|
563
608
|
Set your provider credentials and choose your desired directory for the cartridges files:
|
|
564
609
|
|
|
565
|
-
###
|
|
610
|
+
### Cohere Command
|
|
566
611
|
|
|
567
612
|
```yaml
|
|
568
613
|
---
|
|
569
614
|
services:
|
|
570
615
|
nano-bots:
|
|
571
616
|
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.
|
|
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"
|
|
573
618
|
environment:
|
|
574
|
-
|
|
575
|
-
|
|
619
|
+
COHERE_API_ADDRESS: https://api.cohere.ai
|
|
620
|
+
COHERE_API_KEY: your-api-key
|
|
576
621
|
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
|
577
622
|
NANO_BOTS_END_USER: your-user
|
|
578
623
|
volumes:
|
|
@@ -587,7 +632,7 @@ services:
|
|
|
587
632
|
services:
|
|
588
633
|
nano-bots:
|
|
589
634
|
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.
|
|
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"
|
|
591
636
|
environment:
|
|
592
637
|
MISTRAL_API_ADDRESS: https://api.mistral.ai
|
|
593
638
|
MISTRAL_API_KEY: your-api-key
|
|
@@ -598,6 +643,24 @@ services:
|
|
|
598
643
|
- ./your-state-path:/root/.local/state/nano-bots
|
|
599
644
|
```
|
|
600
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
|
+
|
|
601
664
|
### Google Gemini
|
|
602
665
|
|
|
603
666
|
#### Option 1: API Key (Generative Language API)
|
|
@@ -607,7 +670,7 @@ services:
|
|
|
607
670
|
services:
|
|
608
671
|
nano-bots:
|
|
609
672
|
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.
|
|
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"
|
|
611
674
|
environment:
|
|
612
675
|
GOOGLE_API_KEY: your-api-key
|
|
613
676
|
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
|
@@ -624,7 +687,7 @@ services:
|
|
|
624
687
|
services:
|
|
625
688
|
nano-bots:
|
|
626
689
|
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.
|
|
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"
|
|
628
691
|
environment:
|
|
629
692
|
GOOGLE_CREDENTIALS_FILE_PATH: /root/.config/google-credentials.json
|
|
630
693
|
GOOGLE_REGION: us-east4
|
|
@@ -643,7 +706,7 @@ services:
|
|
|
643
706
|
services:
|
|
644
707
|
nano-bots:
|
|
645
708
|
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.
|
|
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"
|
|
647
710
|
environment:
|
|
648
711
|
GOOGLE_REGION: us-east4
|
|
649
712
|
NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
|
|
@@ -789,17 +852,17 @@ If you lose your password, you lose your data. It is not possible to recover it
|
|
|
789
852
|
|
|
790
853
|
Currently supported providers:
|
|
791
854
|
|
|
792
|
-
- [
|
|
793
|
-
- [x] [Mistral AI](https://docs.mistral.ai/api/)
|
|
794
|
-
- [x] [Google Gemini](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini)
|
|
855
|
+
- [ ] [01.AI Yi](https://01.ai)
|
|
795
856
|
- [ ] [Anthropic Claude](https://www.anthropic.com)
|
|
796
|
-
- [
|
|
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)
|
|
797
860
|
- [ ] [Meta Llama](https://ai.meta.com/llama/)
|
|
798
|
-
- [
|
|
861
|
+
- [x] [Mistral AI](https://docs.mistral.ai/api/)
|
|
862
|
+
- [x] [Open AI ChatGPT](https://platform.openai.com/docs/api-reference)
|
|
799
863
|
- [ ] [WizardLM](https://wizardlm.github.io)
|
|
800
|
-
- [ ] [LMSYS Org FastChat Vicuna](https://github.com/lm-sys/FastChat)
|
|
801
864
|
|
|
802
|
-
|
|
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.
|
|
803
866
|
|
|
804
867
|
## Development
|
|
805
868
|
|
|
@@ -807,6 +870,8 @@ Although only OpenAI ChatGPT and Google Gemini have been officially tested, some
|
|
|
807
870
|
bundle
|
|
808
871
|
rubocop -A
|
|
809
872
|
rspec
|
|
873
|
+
|
|
874
|
+
bundle exec ruby spec/tasks/run-all-models.rb
|
|
810
875
|
```
|
|
811
876
|
|
|
812
877
|
### Publish to RubyGems
|
|
@@ -816,5 +881,5 @@ gem build nano-bots.gemspec
|
|
|
816
881
|
|
|
817
882
|
gem signin
|
|
818
883
|
|
|
819
|
-
gem push nano-bots-2.
|
|
884
|
+
gem push nano-bots-2.4.0.gem
|
|
820
885
|
```
|
data/components/provider.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative 'providers/google'
|
|
4
4
|
require_relative 'providers/mistral'
|
|
5
5
|
require_relative 'providers/openai'
|
|
6
|
+
require_relative 'providers/cohere'
|
|
6
7
|
|
|
7
8
|
module NanoBot
|
|
8
9
|
module Components
|
|
@@ -15,6 +16,8 @@ module NanoBot
|
|
|
15
16
|
Providers::Google.new(provider[:options], provider[:settings], provider[:credentials], environment:)
|
|
16
17
|
when 'mistral'
|
|
17
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:)
|
|
18
21
|
else
|
|
19
22
|
raise "Unsupported provider \"#{provider[:id]}\""
|
|
20
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
|
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', 'mistral'
|
|
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
|
data/nano-bots.gemspec
CHANGED
|
@@ -32,10 +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
38
|
spec.add_dependency 'gemini-ai', '~> 3.1'
|
|
38
|
-
spec.add_dependency 'mistral-ai', '~> 1.
|
|
39
|
+
spec.add_dependency 'mistral-ai', '~> 1.1'
|
|
39
40
|
spec.add_dependency 'pry', '~> 0.14.2'
|
|
40
41
|
spec.add_dependency 'rainbow', '~> 3.1', '>= 3.1.1'
|
|
41
42
|
spec.add_dependency 'rbnacl', '~> 7.1', '>= 7.1.1'
|
data/static/gem.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
|
@@ -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
|
|
@@ -84,14 +104,14 @@ dependencies:
|
|
|
84
104
|
requirements:
|
|
85
105
|
- - "~>"
|
|
86
106
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: '1.
|
|
107
|
+
version: '1.1'
|
|
88
108
|
type: :runtime
|
|
89
109
|
prerelease: false
|
|
90
110
|
version_requirements: !ruby/object:Gem::Requirement
|
|
91
111
|
requirements:
|
|
92
112
|
- - "~>"
|
|
93
113
|
- !ruby/object:Gem::Version
|
|
94
|
-
version: '1.
|
|
114
|
+
version: '1.1'
|
|
95
115
|
- !ruby/object:Gem::Dependency
|
|
96
116
|
name: pry
|
|
97
117
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -203,6 +223,7 @@ files:
|
|
|
203
223
|
- components/embedding.rb
|
|
204
224
|
- components/provider.rb
|
|
205
225
|
- components/providers/base.rb
|
|
226
|
+
- components/providers/cohere.rb
|
|
206
227
|
- components/providers/google.rb
|
|
207
228
|
- components/providers/mistral.rb
|
|
208
229
|
- components/providers/openai.rb
|
|
@@ -227,6 +248,7 @@ files:
|
|
|
227
248
|
- logic/cartridge/streaming.rb
|
|
228
249
|
- logic/cartridge/tools.rb
|
|
229
250
|
- logic/helpers/hash.rb
|
|
251
|
+
- logic/providers/cohere/tokens.rb
|
|
230
252
|
- logic/providers/google/tokens.rb
|
|
231
253
|
- logic/providers/google/tools.rb
|
|
232
254
|
- logic/providers/mistral/tokens.rb
|