nano-bots 1.2.0 → 2.0.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: 32f9bfa761f2b8f34c638d86f207b804a1861873b6ff09dc09202e815fb60943
4
- data.tar.gz: 274c62930860eef8ba3bedff9d169513627160539fd7c30077e883b882fb5330
3
+ metadata.gz: 2597a22180cd4e9feb55c7780fa831b682485c7158c4a562833856a87822f679
4
+ data.tar.gz: 22c3bcaf6d5c61525b2e26ecc5f70e82d723cf022e7c218ffa1f3e7ce2052a58
5
5
  SHA512:
6
- metadata.gz: 7eb6dd2df0d4cbc9a7d7ad880b7ffa633a8ed3ebb52367f1e379efbc78f142a9675603bbcb26c05aa8a2533f3ca9aa5b120faea83843bcc4120a4f01895fa38f
7
- data.tar.gz: a7451773e12f9c25362ffcb04f1c8ce78f7aff0988fec4178d0456d4f91bf70feffa631232a7e182b0cefd6d015ee5fd52ab19448eeeefb77ff821bf2f34d4ea
6
+ metadata.gz: 1afd6b0ddb4918b7cc38a1a4db8355653dad04023791c04b5ef5c69b0e69ff42298bbc903972179ebe21e2bb1a8d429928f59df64903ad5d068fa38059a89d21
7
+ data.tar.gz: 719a91a7351ea0557780ce06a436e1fee35824281c921f74a866a4c51bce8f9605157b7ef5bd27763a693885856bad87499164bb32f742a59a1130bf8879f597
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nano-bots (1.2.0)
4
+ nano-bots (2.0.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 (~> 1.0)
8
+ gemini-ai (~> 2.0)
9
9
  pry (~> 0.14.2)
10
10
  rainbow (~> 3.1, >= 3.1.1)
11
11
  rbnacl (~> 7.1, >= 7.1.1)
@@ -34,7 +34,7 @@ GEM
34
34
  multipart-post (~> 2)
35
35
  faraday-net_http (3.0.2)
36
36
  ffi (1.16.3)
37
- gemini-ai (1.0.0)
37
+ gemini-ai (2.0.0)
38
38
  event_stream_parser (~> 1.0)
39
39
  faraday (~> 2.7, >= 2.7.12)
40
40
  googleauth (~> 1.9, >= 1.9.1)
data/README.md CHANGED
@@ -36,13 +36,13 @@ https://user-images.githubusercontent.com/113217272/238141567-c58a240c-7b67-4b3b
36
36
  For a system usage:
37
37
 
38
38
  ```sh
39
- gem install nano-bots -v 1.2.0
39
+ gem install nano-bots -v 2.0.0
40
40
  ```
41
41
 
42
42
  To use it in a project, add it to your `Gemfile`:
43
43
 
44
44
  ```ruby
45
- gem 'nano-bots', '~> 1.2.0'
45
+ gem 'nano-bots', '~> 2.0.0'
46
46
  ```
47
47
 
48
48
  ```sh
@@ -81,6 +81,32 @@ NANO_BOTS_END_USER=your-user
81
81
 
82
82
  Click [here](https://github.com/gbaptista/gemini-ai#credentials) to learn how to obtain your credentials.
83
83
 
84
+ #### Option 1: API Key (Generative Language API)
85
+
86
+ ```sh
87
+ export GOOGLE_API_KEY=your-api-key
88
+
89
+ export NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
90
+ export NANO_BOTS_END_USER=your-user
91
+
92
+ # export NANO_BOTS_STATE_DIRECTORY=/home/user/.local/state/nano-bots
93
+ # export NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
94
+ ```
95
+
96
+ Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
97
+
98
+ ```sh
99
+ GOOGLE_API_KEY=your-api-key
100
+
101
+ NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
102
+ NANO_BOTS_END_USER=your-user
103
+
104
+ # NANO_BOTS_STATE_DIRECTORY=/home/user/.local/state/nano-bots
105
+ # NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
106
+ ```
107
+
108
+ #### Option 2: Service Account (Vertex AI API)
109
+
84
110
  ```sh
85
111
  export GOOGLE_CREDENTIALS_FILE_PATH=google-credentials.json
86
112
  export GOOGLE_PROJECT_ID=your-project-id
@@ -126,7 +152,7 @@ Set your provider credentials and choose your desired directory for the cartridg
126
152
  services:
127
153
  nano-bots:
128
154
  image: ruby:3.2.2-slim-bookworm
129
- command: sh -c "apt-get update && apt-get install -y --no-install-recommends build-essential libffi-dev libsodium-dev lua5.4-dev curl && curl -s https://raw.githubusercontent.com/babashka/babashka/master/install | bash && gem install nano-bots -v 1.2.0 && bash"
155
+ 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.0.0 && bash"
130
156
  environment:
131
157
  OPENAI_API_ADDRESS: https://api.openai.com
132
158
  OPENAI_API_KEY: your-access-token
@@ -139,12 +165,31 @@ services:
139
165
 
140
166
  ### Google Gemini
141
167
 
168
+ #### Option 1: API Key (Generative Language API)
169
+
170
+ ```yaml
171
+ ---
172
+ services:
173
+ nano-bots:
174
+ image: ruby:3.2.2-slim-bookworm
175
+ 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.0.0 && bash"
176
+ environment:
177
+ GOOGLE_API_KEY: your-api-key
178
+ NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
179
+ NANO_BOTS_END_USER: your-user
180
+ volumes:
181
+ - ./your-cartridges:/root/.local/share/nano-bots/cartridges
182
+ - ./your-state-path:/root/.local/state/nano-bots
183
+ ```
184
+
185
+ #### Option 2: Service Account (Vertex AI API)
186
+
142
187
  ```yaml
143
188
  ---
144
189
  services:
145
190
  nano-bots:
146
191
  image: ruby:3.2.2-slim-bookworm
147
- command: sh -c "apt-get update && apt-get install -y --no-install-recommends build-essential libffi-dev libsodium-dev lua5.4-dev curl && curl -s https://raw.githubusercontent.com/babashka/babashka/master/install | bash && gem install nano-bots -v 1.2.0 && bash"
192
+ 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.0.0 && bash"
148
193
  environment:
149
194
  GOOGLE_CREDENTIALS_FILE_PATH: /root/.config/google-credentials.json
150
195
  GOOGLE_PROJECT_ID: your-project-id
@@ -346,6 +391,8 @@ provider:
346
391
 
347
392
  Read the [full specification](https://spec.nbots.io/#/README?id=google-gemini) for Google Gemini.
348
393
 
394
+ #### Option 1: API Key (Generative Language API)
395
+
349
396
  ```yaml
350
397
  ---
351
398
  meta:
@@ -363,8 +410,34 @@ behaviors:
363
410
  provider:
364
411
  id: google
365
412
  credentials:
366
- project-id: ENV/GOOGLE_PROJECT_ID
413
+ service: generative-language-api
414
+ api-key: ENV/GOOGLE_API_KEY
415
+ options:
416
+ model: gemini-pro
417
+ ```
418
+
419
+ #### Option 2: Service Account (Vertex AI API)
420
+
421
+ ```yaml
422
+ ---
423
+ meta:
424
+ symbol: 🤖
425
+ name: Nano Bot Name
426
+ author: Your Name
427
+ version: 1.0.0
428
+ license: CC0-1.0
429
+ description: A helpful assistant.
430
+
431
+ behaviors:
432
+ interaction:
433
+ directive: You are a helpful assistant.
434
+
435
+ provider:
436
+ id: google
437
+ credentials:
438
+ service: vertex-ai-api
367
439
  file-path: ENV/GOOGLE_CREDENTIALS_FILE_PATH
440
+ project-id: ENV/GOOGLE_PROJECT_ID
368
441
  region: ENV/GOOGLE_REGION
369
442
  options:
370
443
  model: gemini-pro
@@ -395,7 +468,7 @@ The randomly generated number is 59.
395
468
 
396
469
  🤖> |
397
470
  ```
398
- 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 model `gemini-pro`.
471
+ 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`.
399
472
 
400
473
  Check the [Nano Bots specification](https://spec.nbots.io/#/README?id=tools-functions-2) to learn more about Tools (Functions).
401
474
 
@@ -418,7 +491,7 @@ Unlike Lua and Fennel, Clojure support is not _embedded_ in this implementation.
418
491
  Here's [how to install Babashka](https://github.com/babashka/babashka#quickstart):
419
492
 
420
493
  ```sh
421
- curl -s https://raw.githubusercontent.com/babashka/babashka/master/install | bash
494
+ curl -s https://raw.githubusercontent.com/babashka/babashka/master/install | sudo bash
422
495
  ```
423
496
 
424
497
  This is a quick check to ensure that it is available and working:
@@ -576,5 +649,5 @@ gem build nano-bots.gemspec
576
649
 
577
650
  gem signin
578
651
 
579
- gem push nano-bots-1.2.0.gem
652
+ gem push nano-bots-2.0.0.gem
580
653
  ```
@@ -9,7 +9,7 @@ module NanoBot
9
9
  def self.new(provider, environment: {})
10
10
  case provider[:id]
11
11
  when 'openai'
12
- Providers::OpenAI.new(provider[:settings], provider[:credentials], environment:)
12
+ Providers::OpenAI.new(nil, provider[:settings], provider[:credentials], environment:)
13
13
  when 'google'
14
14
  Providers::Google.new(provider[:options], provider[:settings], provider[:credentials], environment:)
15
15
  else
@@ -6,7 +6,7 @@ module NanoBot
6
6
  module Components
7
7
  module Providers
8
8
  class Base
9
- def initialize(_settings, _credentials, _environment: {})
9
+ def initialize(_options, _settings, _credentials, _environment: {})
10
10
  raise NoMethodError, "The 'initialize' method is not implemented for the current provider."
11
11
  end
12
12
 
@@ -13,26 +13,38 @@ module NanoBot
13
13
  module Components
14
14
  module Providers
15
15
  class Google < Base
16
+ SAFETY_SETTINGS = %i[category threshold].freeze
17
+
16
18
  SETTINGS = {
17
19
  generationConfig: %i[
18
20
  temperature topP topK candidateCount maxOutputTokens stopSequences
19
21
  ].freeze
20
22
  }.freeze
21
23
 
22
- SAFETY_SETTINGS = %i[category threshold].freeze
23
-
24
24
  attr_reader :settings
25
25
 
26
26
  def initialize(options, settings, credentials, _environment)
27
27
  @settings = settings
28
28
 
29
+ gemini_credentials = if credentials[:'api-key']
30
+ {
31
+ service: credentials[:service],
32
+ api_key: credentials[:'api-key'],
33
+ project_id: credentials[:'project-id'],
34
+ region: credentials[:region]
35
+ }
36
+ else
37
+ {
38
+ service: credentials[:service],
39
+ file_path: credentials[:'file-path'],
40
+ project_id: credentials[:'project-id'],
41
+ region: credentials[:region]
42
+ }
43
+ end
44
+
29
45
  @client = Gemini.new(
30
- credentials: {
31
- file_path: credentials[:'file-path'],
32
- project_id: credentials[:'project-id'],
33
- region: credentials[:region]
34
- },
35
- settings: { model: options[:model], stream: options[:stream] }
46
+ credentials: gemini_credentials,
47
+ options: { model: options[:model], stream: options[:stream] }
36
48
  )
37
49
  end
38
50
 
@@ -61,9 +73,15 @@ module NanoBot
61
73
  %i[backdrop directive].each do |key|
62
74
  next unless input[:behavior][key]
63
75
 
76
+ messages.prepend(
77
+ { role: 'model',
78
+ parts: { text: 'Understood.' },
79
+ _meta: { at: Time.now } }
80
+ )
81
+
64
82
  # TODO: Does Gemini have system messages?
65
83
  messages.prepend(
66
- { role: key == :directive ? 'user' : 'user',
84
+ { role: 'user',
67
85
  parts: { text: input[:behavior][key] },
68
86
  _meta: { at: Time.now } }
69
87
  )
@@ -17,13 +17,14 @@ module NanoBot
17
17
  DEFAULT_ADDRESS = 'https://api.openai.com'
18
18
 
19
19
  CHAT_SETTINGS = %i[
20
- model stream temperature top_p n stop max_tokens
21
- presence_penalty frequency_penalty logit_bias seed response_format
20
+ model stream frequency_penalty logit_bias logprobs top_logprobs
21
+ max_tokens n presence_penalty response_format seed stop temperature
22
+ top_p tool_choice
22
23
  ].freeze
23
24
 
24
25
  attr_reader :settings
25
26
 
26
- def initialize(settings, credentials, environment: {})
27
+ def initialize(_options, settings, credentials, environment: {})
27
28
  @settings = settings
28
29
  @credentials = credentials
29
30
  @environment = environment
@@ -2,12 +2,21 @@
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 1.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.0.0 && bash"
6
6
  environment:
7
7
  OPENAI_API_ADDRESS: https://api.openai.com
8
8
  OPENAI_API_KEY: your-access-token
9
+
10
+ GOOGLE_API_KEY: your-api-key
11
+
12
+ GOOGLE_CREDENTIALS_FILE_PATH: /root/.config/google-credentials.json
13
+ GOOGLE_PROJECT_ID: your-project-id
14
+ GOOGLE_REGION: us-east4
15
+
9
16
  NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
10
17
  NANO_BOTS_END_USER: your-user
18
+
11
19
  volumes:
20
+ - ./google-credentials.json:/root/.config/google-credentials.json
12
21
  - ./your-cartridges:/root/.local/share/nano-bots/cartridges
13
22
  - ./your-state-path:/root/.local/state/nano-bots
data/nano-bots.gemspec CHANGED
@@ -34,7 +34,7 @@ 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', '~> 1.0'
37
+ spec.add_dependency 'gemini-ai', '~> 2.0'
38
38
  spec.add_dependency 'pry', '~> 0.14.2'
39
39
  spec.add_dependency 'rainbow', '~> 3.1', '>= 3.1.1'
40
40
  spec.add_dependency 'rbnacl', '~> 7.1', '>= 7.1.1'
data/static/gem.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module NanoBot
4
4
  GEM = {
5
5
  name: 'nano-bots',
6
- version: '1.2.0',
6
+ version: '2.0.0',
7
7
  author: 'icebaker',
8
8
  summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT and Google Gemini.',
9
9
  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).',
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: 1.2.0
4
+ version: 2.0.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-15 00:00:00.000000000 Z
11
+ date: 2023-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: babosa
@@ -70,14 +70,14 @@ dependencies:
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '1.0'
73
+ version: '2.0'
74
74
  type: :runtime
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: '1.0'
80
+ version: '2.0'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: pry
83
83
  requirement: !ruby/object:Gem::Requirement