nano-bots 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2597a22180cd4e9feb55c7780fa831b682485c7158c4a562833856a87822f679
4
- data.tar.gz: 22c3bcaf6d5c61525b2e26ecc5f70e82d723cf022e7c218ffa1f3e7ce2052a58
3
+ metadata.gz: 1cfd38c6461b14483fc0478d31b73ed3e4890f1c534b3c7a4ead6f9412466674
4
+ data.tar.gz: 11f3e82a196f8b27ac1313ee2e653c93521ed7c081ef68bacf15015c8392db34
5
5
  SHA512:
6
- metadata.gz: 1afd6b0ddb4918b7cc38a1a4db8355653dad04023791c04b5ef5c69b0e69ff42298bbc903972179ebe21e2bb1a8d429928f59df64903ad5d068fa38059a89d21
7
- data.tar.gz: 719a91a7351ea0557780ce06a436e1fee35824281c921f74a866a4c51bce8f9605157b7ef5bd27763a693885856bad87499164bb32f742a59a1130bf8879f597
6
+ metadata.gz: b6a7dbb69afead0f718e2b3c688edb35dfce6f68f138ddd5168c9d72b5eaaedbdcf973b99be873709c4f6b63f71a3f35c9a5d06a0ca4efd32800c52b6de3ccc0
7
+ data.tar.gz: 24bf5641942d008e7afbad2ae37fec1a4f37d28c68b3ab0ab3f560849f8b427a246f5c9c29ddc9221852bbb3cd5e86bb958c9fbff392a0cca0fab81d9c3b0171
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nano-bots (2.0.0)
4
+ nano-bots (2.1.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.0)
8
+ gemini-ai (~> 2.1)
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 (2.0.0)
37
+ gemini-ai (2.1.0)
38
38
  event_stream_parser (~> 1.0)
39
39
  faraday (~> 2.7, >= 2.7.12)
40
40
  googleauth (~> 1.9, >= 1.9.1)
@@ -54,7 +54,7 @@ GEM
54
54
  multi_json (1.15.0)
55
55
  multipart-post (2.3.0)
56
56
  os (1.1.4)
57
- parallel (1.23.0)
57
+ parallel (1.24.0)
58
58
  parser (3.2.2.4)
59
59
  ast (~> 2.4.1)
60
60
  racc
@@ -131,4 +131,4 @@ DEPENDENCIES
131
131
  rubocop-rspec (~> 2.25)
132
132
 
133
133
  BUNDLED WITH
134
- 2.4.13
134
+ 2.4.22
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 2.0.0
39
+ gem install nano-bots -v 2.1.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', '~> 2.0.0'
45
+ gem 'nano-bots', '~> 2.1.0'
46
46
  ```
47
47
 
48
48
  ```sh
@@ -105,11 +105,10 @@ NANO_BOTS_END_USER=your-user
105
105
  # NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
106
106
  ```
107
107
 
108
- #### Option 2: Service Account (Vertex AI API)
108
+ #### Option 2: Service Account Credentials File (Vertex AI API)
109
109
 
110
110
  ```sh
111
111
  export GOOGLE_CREDENTIALS_FILE_PATH=google-credentials.json
112
- export GOOGLE_PROJECT_ID=your-project-id
113
112
  export GOOGLE_REGION=us-east4
114
113
 
115
114
  export NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
@@ -123,7 +122,6 @@ Alternatively, if your current directory has a `.env` file with the environment
123
122
 
124
123
  ```sh
125
124
  GOOGLE_CREDENTIALS_FILE_PATH=google-credentials.json
126
- GOOGLE_PROJECT_ID=your-project-id
127
125
  GOOGLE_REGION=us-east4
128
126
 
129
127
  NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
@@ -133,6 +131,44 @@ NANO_BOTS_END_USER=your-user
133
131
  # NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
134
132
  ```
135
133
 
134
+ #### Option 3: Application Default Credentials (Vertex AI API)
135
+
136
+ ```sh
137
+ export GOOGLE_REGION=us-east4
138
+
139
+ export NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
140
+ export NANO_BOTS_END_USER=your-user
141
+
142
+ # export NANO_BOTS_STATE_DIRECTORY=/home/user/.local/state/nano-bots
143
+ # export NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
144
+ ```
145
+
146
+ Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
147
+
148
+ ```sh
149
+ GOOGLE_REGION=us-east4
150
+
151
+ NANO_BOTS_ENCRYPTION_PASSWORD=UNSAFE
152
+ NANO_BOTS_END_USER=your-user
153
+
154
+ # NANO_BOTS_STATE_DIRECTORY=/home/user/.local/state/nano-bots
155
+ # NANO_BOTS_CARTRIDGES_DIRECTORY=/home/user/.local/share/nano-bots/cartridges
156
+ ```
157
+
158
+ #### Custom Project ID
159
+
160
+ If you need to manually set a Google Project ID:
161
+
162
+ ```sh
163
+ export GOOGLE_PROJECT_ID=your-project-id
164
+ ```
165
+
166
+ Alternatively, if your current directory has a `.env` file with the environment variables, they will be automatically loaded:
167
+
168
+ ```sh
169
+ GOOGLE_PROJECT_ID=your-project-id
170
+ ```
171
+
136
172
  ## Docker
137
173
 
138
174
  Clone the repository and copy the Docker Compose template:
@@ -152,7 +188,7 @@ Set your provider credentials and choose your desired directory for the cartridg
152
188
  services:
153
189
  nano-bots:
154
190
  image: ruby:3.2.2-slim-bookworm
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"
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.1.0 && bash"
156
192
  environment:
157
193
  OPENAI_API_ADDRESS: https://api.openai.com
158
194
  OPENAI_API_KEY: your-access-token
@@ -172,7 +208,7 @@ services:
172
208
  services:
173
209
  nano-bots:
174
210
  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"
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.1.0 && bash"
176
212
  environment:
177
213
  GOOGLE_API_KEY: your-api-key
178
214
  NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
@@ -182,17 +218,16 @@ services:
182
218
  - ./your-state-path:/root/.local/state/nano-bots
183
219
  ```
184
220
 
185
- #### Option 2: Service Account (Vertex AI API)
221
+ #### Option 2: Service Account Credentials File (Vertex AI API)
186
222
 
187
223
  ```yaml
188
224
  ---
189
225
  services:
190
226
  nano-bots:
191
227
  image: ruby:3.2.2-slim-bookworm
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"
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.1.0 && bash"
193
229
  environment:
194
230
  GOOGLE_CREDENTIALS_FILE_PATH: /root/.config/google-credentials.json
195
- GOOGLE_PROJECT_ID: your-project-id
196
231
  GOOGLE_REGION: us-east4
197
232
  NANO_BOTS_ENCRYPTION_PASSWORD: UNSAFE
198
233
  NANO_BOTS_END_USER: your-user
@@ -202,6 +237,31 @@ services:
202
237
  - ./your-state-path:/root/.local/state/nano-bots
203
238
  ```
204
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.1.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
+
205
265
  ### Container
206
266
 
207
267
  Enter the container:
@@ -416,7 +476,7 @@ provider:
416
476
  model: gemini-pro
417
477
  ```
418
478
 
419
- #### Option 2: Service Account (Vertex AI API)
479
+ #### Option 2: Service Account Credentials File (Vertex AI API)
420
480
 
421
481
  ```yaml
422
482
  ---
@@ -437,12 +497,48 @@ provider:
437
497
  credentials:
438
498
  service: vertex-ai-api
439
499
  file-path: ENV/GOOGLE_CREDENTIALS_FILE_PATH
440
- project-id: ENV/GOOGLE_PROJECT_ID
441
500
  region: ENV/GOOGLE_REGION
442
501
  options:
443
502
  model: gemini-pro
444
503
  ```
445
504
 
505
+ #### Option 3: Application Default Credentials (Vertex AI API)
506
+
507
+ ```yaml
508
+ ---
509
+ meta:
510
+ symbol: 🤖
511
+ name: Nano Bot Name
512
+ author: Your Name
513
+ version: 1.0.0
514
+ license: CC0-1.0
515
+ description: A helpful assistant.
516
+
517
+ behaviors:
518
+ interaction:
519
+ directive: You are a helpful assistant.
520
+
521
+ provider:
522
+ id: google
523
+ credentials:
524
+ service: vertex-ai-api
525
+ region: ENV/GOOGLE_REGION
526
+ options:
527
+ model: gemini-pro
528
+ ```
529
+
530
+ #### Custom Project ID
531
+
532
+ If you need to manually set a Google Project ID:
533
+
534
+ ```yaml
535
+ ---
536
+ provider:
537
+ id: google
538
+ credentials:
539
+ project-id: ENV/GOOGLE_PROJECT_ID
540
+ ```
541
+
446
542
  ### Tools (Functions)
447
543
 
448
544
  Nano Bots can also be powered by _Tools_ (Functions):
@@ -649,5 +745,5 @@ gem build nano-bots.gemspec
649
745
 
650
746
  gem signin
651
747
 
652
- gem push nano-bots-2.0.0.gem
748
+ gem push nano-bots-2.1.0.gem
653
749
  ```
@@ -26,25 +26,9 @@ module NanoBot
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
-
45
29
  @client = Gemini.new(
46
- credentials: gemini_credentials,
47
- options: { model: options[:model], stream: options[:stream] }
30
+ credentials: credentials.transform_keys { |key| key.to_s.gsub('-', '_').to_sym },
31
+ options: options.transform_keys { |key| key.to_s.gsub('-', '_').to_sym }
48
32
  )
49
33
  end
50
34
 
@@ -70,6 +54,7 @@ module NanoBot
70
54
  end
71
55
  end
72
56
 
57
+ # TODO: Does Gemini have system messages?
73
58
  %i[backdrop directive].each do |key|
74
59
  next unless input[:behavior][key]
75
60
 
@@ -79,7 +64,6 @@ module NanoBot
79
64
  _meta: { at: Time.now } }
80
65
  )
81
66
 
82
- # TODO: Does Gemini have system messages?
83
67
  messages.prepend(
84
68
  { role: 'user',
85
69
  parts: { text: input[:behavior][key] },
@@ -140,24 +124,9 @@ module NanoBot
140
124
  end
141
125
 
142
126
  if event.dig('candidates', 0, 'finishReason')
143
- if tools&.size&.positive?
144
- feedback.call(
145
- { should_be_stored: true,
146
- needs_another_round: true,
147
- interaction: { who: 'AI', message: nil, meta: { tool_calls: tools } } }
148
- )
149
- Tools.apply(
150
- cartridge, input[:tools], tools, feedback, Logic::Google::Tools
151
- ).each do |interaction|
152
- feedback.call({ should_be_stored: true, needs_another_round: true, interaction: })
153
- end
154
- end
155
-
156
- feedback.call(
157
- { should_be_stored: !(content.nil? || content == ''),
158
- interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
159
- finished: true }
160
- )
127
+ # TODO: This does not have the same behavior as OpenAI, so you should
128
+ # not use it as a reference for the end of the streaming.
129
+ # Is this a bug from the Google Gemini REST API or expected behavior?
161
130
  end
162
131
  end
163
132
 
@@ -166,6 +135,25 @@ module NanoBot
166
135
  Logic::Google::Tokens.apply_policies!(cartridge, payload),
167
136
  stream: true, &stream_call_back
168
137
  )
138
+
139
+ if tools&.size&.positive?
140
+ feedback.call(
141
+ { should_be_stored: true,
142
+ needs_another_round: true,
143
+ interaction: { who: 'AI', message: nil, meta: { tool_calls: tools } } }
144
+ )
145
+ Tools.apply(
146
+ cartridge, input[:tools], tools, feedback, Logic::Google::Tools
147
+ ).each do |interaction|
148
+ feedback.call({ should_be_stored: true, needs_another_round: true, interaction: })
149
+ end
150
+ end
151
+
152
+ feedback.call(
153
+ { should_be_stored: !(content.nil? || content == ''),
154
+ interaction: content.nil? || content == '' ? nil : { who: 'AI', message: content },
155
+ finished: true }
156
+ )
169
157
  rescue StandardError => e
170
158
  raise e.class, e.response[:body] if e.response && e.response[:body]
171
159
 
@@ -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.0.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.1.0 && bash"
6
6
  environment:
7
7
  OPENAI_API_ADDRESS: https://api.openai.com
8
8
  OPENAI_API_KEY: your-access-token
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', '~> 2.0'
37
+ spec.add_dependency 'gemini-ai', '~> 2.1'
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'
@@ -40,4 +40,8 @@ module NanoBot
40
40
  def self.version
41
41
  NanoBot::GEM[:version]
42
42
  end
43
+
44
+ def self.specification
45
+ NanoBot::GEM[:specification]
46
+ end
43
47
  end
data/static/gem.rb CHANGED
@@ -3,7 +3,8 @@
3
3
  module NanoBot
4
4
  GEM = {
5
5
  name: 'nano-bots',
6
- version: '2.0.0',
6
+ version: '2.1.0',
7
+ specification: '2.0.1',
7
8
  author: 'icebaker',
8
9
  summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT and Google Gemini.',
9
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).',
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.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - icebaker
@@ -70,14 +70,14 @@ dependencies:
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '2.0'
73
+ version: '2.1'
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: '2.0'
80
+ version: '2.1'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: pry
83
83
  requirement: !ruby/object:Gem::Requirement
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
248
  - !ruby/object:Gem::Version
249
249
  version: '0'
250
250
  requirements: []
251
- rubygems_version: 3.4.22
251
+ rubygems_version: 3.3.3
252
252
  signing_key:
253
253
  specification_version: 4
254
254
  summary: 'Ruby Implementation of Nano Bots: small, AI-powered bots for OpenAI ChatGPT