ollama-ai 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ollama AI
2
2
 
3
- A Ruby gem for interacting with [Ollama](https://github.com/jmorganca/ollama)'s API that allows you to run open source AI LLMs (Large Language Models) locally.
3
+ A Ruby gem for interacting with [Ollama](https://ollama.ai)'s API that allows you to run open source AI LLMs (Large Language Models) locally.
4
4
 
5
5
  ![The image presents a llama's head merged with a red ruby gemstone against a light beige background. The red facets form both the ruby and the contours of the llama, creating a clever visual fusion.](https://raw.githubusercontent.com/gbaptista/assets/main/ollama-ai/ollama-ai-canvas.png)
6
6
 
@@ -9,7 +9,7 @@ A Ruby gem for interacting with [Ollama](https://github.com/jmorganca/ollama)'s
9
9
  ## TL;DR and Quick Start
10
10
 
11
11
  ```ruby
12
- gem 'ollama-ai', '~> 1.0.0'
12
+ gem 'ollama-ai', '~> 1.0.1'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -21,40 +21,40 @@ client = Ollama.new(
21
21
  )
22
22
 
23
23
  result = client.generate(
24
- { model: 'dolphin-phi',
24
+ { model: 'llama2',
25
25
  prompt: 'Hi!' }
26
26
  )
27
27
  ```
28
28
 
29
29
  Result:
30
30
  ```ruby
31
- [{ 'model' => 'dolphin-phi',
32
- 'created_at' => '2024-01-06T16:53:21.357816652Z',
31
+ [{ 'model' => 'llama2',
32
+ 'created_at' => '2024-01-07T01:34:02.088810408Z',
33
33
  'response' => 'Hello',
34
34
  'done' => false },
35
- { 'model' => 'dolphin-phi',
36
- 'created_at' => '2024-01-06T16:53:21.490053654Z',
35
+ { 'model' => 'llama2',
36
+ 'created_at' => '2024-01-07T01:34:02.419045606Z',
37
37
  'response' => '!',
38
38
  'done' => false },
39
- # ...
40
- { 'model' => 'dolphin-phi',
41
- 'created_at' => '2024-01-06T16:53:24.82505599Z',
42
- 'response' => '.',
39
+ # ..
40
+ { 'model' => 'llama2',
41
+ 'created_at' => '2024-01-07T01:34:07.680049831Z',
42
+ 'response' => '?',
43
43
  'done' => false },
44
- { 'model' => 'dolphin-phi',
45
- 'created_at' => '2024-01-06T16:53:24.956774721Z',
44
+ { 'model' => 'llama2',
45
+ 'created_at' => '2024-01-07T01:34:07.872170352Z',
46
46
  'response' => '',
47
47
  'done' => true,
48
48
  'context' =>
49
- [50_296, 10_057,
49
+ [518, 25_580,
50
50
  # ...
51
- 1037, 13],
52
- 'total_duration' => 5_702_027_026,
53
- 'load_duration' => 649_711,
54
- 'prompt_eval_count' => 25,
55
- 'prompt_eval_duration' => 2_227_159_000,
56
- 'eval_count' => 39,
57
- 'eval_duration' => 3_466_593_000 }]
51
+ 13_563, 29_973],
52
+ 'total_duration' => 11_653_781_127,
53
+ 'load_duration' => 1_186_200_439,
54
+ 'prompt_eval_count' => 22,
55
+ 'prompt_eval_duration' => 5_006_751_000,
56
+ 'eval_count' => 25,
57
+ 'eval_duration' => 5_453_058_000 }]
58
58
  ```
59
59
 
60
60
  ## Index
@@ -80,6 +80,9 @@ Result:
80
80
  - [delete: Delete a Model](#delete-delete-a-model)
81
81
  - [pull: Pull a Model](#pull-pull-a-model)
82
82
  - [push: Push a Model](#push-push-a-model)
83
+ - [Modes](#modes)
84
+ - [Text](#text)
85
+ - [Image](#image)
83
86
  - [Streaming and Server-Sent Events (SSE)](#streaming-and-server-sent-events-sse)
84
87
  - [Server-Sent Events (SSE) Hang](#server-sent-events-sse-hang)
85
88
  - [New Functionalities and APIs](#new-functionalities-and-apis)
@@ -101,11 +104,11 @@ Result:
101
104
  ### Installing
102
105
 
103
106
  ```sh
104
- gem install ollama-ai -v 1.0.0
107
+ gem install ollama-ai -v 1.0.1
105
108
  ```
106
109
 
107
110
  ```sh
108
- gem 'ollama-ai', '~> 1.0.0'
111
+ gem 'ollama-ai', '~> 1.0.1'
109
112
  ```
110
113
 
111
114
  ## Usage
@@ -148,7 +151,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#gen
148
151
 
149
152
  ```ruby
150
153
  result = client.generate(
151
- { model: 'dolphin-phi',
154
+ { model: 'llama2',
152
155
  prompt: 'Hi!',
153
156
  stream: false }
154
157
  )
@@ -156,21 +159,20 @@ result = client.generate(
156
159
 
157
160
  Result:
158
161
  ```ruby
159
- [{ 'model' => 'dolphin-phi',
160
- 'created_at' => '2024-01-06T17:47:26.443128626Z',
161
- 'response' =>
162
- "Hello! How can I assist you today? Do you have any questions or problems that you'd like help with?",
162
+ [{ 'model' => 'llama2',
163
+ 'created_at' => '2024-01-07T01:35:41.951371247Z',
164
+ 'response' => "Hi there! It's nice to meet you. How are you today?",
163
165
  'done' => true,
164
166
  'context' =>
165
- [50_296, 10_057,
167
+ [518, 25_580,
166
168
  # ...
167
- 351, 30],
168
- 'total_duration' => 6_495_278_960,
169
- 'load_duration' => 1_434_052_851,
170
- 'prompt_eval_count' => 25,
171
- 'prompt_eval_duration' => 1_938_861_000,
172
- 'eval_count' => 23,
173
- 'eval_duration' => 3_119_030_000 }]
169
+ 9826, 29_973],
170
+ 'total_duration' => 6_981_097_576,
171
+ 'load_duration' => 625_053,
172
+ 'prompt_eval_count' => 22,
173
+ 'prompt_eval_duration' => 4_075_171_000,
174
+ 'eval_count' => 16,
175
+ 'eval_duration' => 2_900_325_000 }]
174
176
  ```
175
177
 
176
178
  ##### Receiving Stream Events
@@ -181,7 +183,7 @@ Ensure that you have enabled [Server-Sent Events](#streaming-and-server-sent-eve
181
183
 
182
184
  ```ruby
183
185
  client.generate(
184
- { model: 'dolphin-phi',
186
+ { model: 'llama2',
185
187
  prompt: 'Hi!' }
186
188
  ) do |event, raw|
187
189
  puts event
@@ -190,8 +192,8 @@ end
190
192
 
191
193
  Event:
192
194
  ```ruby
193
- { 'model' => 'dolphin-phi',
194
- 'created_at' => '2024-01-06T17:27:29.366879586Z',
195
+ { 'model' => 'llama2',
196
+ 'created_at' => '2024-01-07T01:36:30.665245712Z',
195
197
  'response' => 'Hello',
196
198
  'done' => false }
197
199
  ```
@@ -199,46 +201,46 @@ Event:
199
201
  You can get all the receive events at once as an array:
200
202
  ```ruby
201
203
  result = client.generate(
202
- { model: 'dolphin-phi',
204
+ { model: 'llama2',
203
205
  prompt: 'Hi!' }
204
206
  )
205
207
  ```
206
208
 
207
209
  Result:
208
210
  ```ruby
209
- [{ 'model' => 'dolphin-phi',
210
- 'created_at' => '2024-01-06T16:53:21.357816652Z',
211
+ [{ 'model' => 'llama2',
212
+ 'created_at' => '2024-01-07T01:36:30.665245712Z',
211
213
  'response' => 'Hello',
212
214
  'done' => false },
213
- { 'model' => 'dolphin-phi',
214
- 'created_at' => '2024-01-06T16:53:21.490053654Z',
215
+ { 'model' => 'llama2',
216
+ 'created_at' => '2024-01-07T01:36:30.927337136Z',
215
217
  'response' => '!',
216
218
  'done' => false },
217
219
  # ...
218
- { 'model' => 'dolphin-phi',
219
- 'created_at' => '2024-01-06T16:53:24.82505599Z',
220
- 'response' => '.',
220
+ { 'model' => 'llama2',
221
+ 'created_at' => '2024-01-07T01:36:37.249416767Z',
222
+ 'response' => '?',
221
223
  'done' => false },
222
- { 'model' => 'dolphin-phi',
223
- 'created_at' => '2024-01-06T16:53:24.956774721Z',
224
+ { 'model' => 'llama2',
225
+ 'created_at' => '2024-01-07T01:36:37.44041283Z',
224
226
  'response' => '',
225
227
  'done' => true,
226
228
  'context' =>
227
- [50_296, 10_057,
229
+ [518, 25_580,
228
230
  # ...
229
- 1037, 13],
230
- 'total_duration' => 5_702_027_026,
231
- 'load_duration' => 649_711,
232
- 'prompt_eval_count' => 25,
233
- 'prompt_eval_duration' => 2_227_159_000,
234
- 'eval_count' => 39,
235
- 'eval_duration' => 3_466_593_000 }]
231
+ 13_563, 29_973],
232
+ 'total_duration' => 10_551_395_645,
233
+ 'load_duration' => 966_631,
234
+ 'prompt_eval_count' => 22,
235
+ 'prompt_eval_duration' => 4_034_990_000,
236
+ 'eval_count' => 25,
237
+ 'eval_duration' => 6_512_954_000 }]
236
238
  ```
237
239
 
238
240
  You can mix both as well:
239
241
  ```ruby
240
242
  result = client.generate(
241
- { model: 'dolphin-phi',
243
+ { model: 'llama2',
242
244
  prompt: 'Hi!' }
243
245
  ) do |event, raw|
244
246
  puts event
@@ -251,7 +253,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#gen
251
253
 
252
254
  ```ruby
253
255
  result = client.chat(
254
- { model: 'dolphin-phi',
256
+ { model: 'llama2',
255
257
  messages: [
256
258
  { role: 'user', content: 'Hi! My name is Purple.' }
257
259
  ] }
@@ -262,37 +264,37 @@ end
262
264
 
263
265
  Event:
264
266
  ```ruby
265
- { 'model' => 'dolphin-phi',
266
- 'created_at' => '2024-01-06T18:17:22.468231988Z',
267
- 'message' => { 'role' => 'assistant', 'content' => 'Hello' },
267
+ { 'model' => 'llama2',
268
+ 'created_at' => '2024-01-07T01:38:01.729897311Z',
269
+ 'message' => { 'role' => 'assistant', 'content' => "\n" },
268
270
  'done' => false }
269
271
  ```
270
272
 
271
273
  Result:
272
274
  ```ruby
273
- [{ 'model' => 'dolphin-phi',
274
- 'created_at' => '2024-01-06T18:17:22.468231988Z',
275
- 'message' => { 'role' => 'assistant', 'content' => 'Hello' },
275
+ [{ 'model' => 'llama2',
276
+ 'created_at' => '2024-01-07T01:38:01.729897311Z',
277
+ 'message' => { 'role' => 'assistant', 'content' => "\n" },
276
278
  'done' => false },
277
- { 'model' => 'dolphin-phi',
278
- 'created_at' => '2024-01-06T18:17:22.594414415Z',
279
- 'message' => { 'role' => 'assistant', 'content' => ' Purple' },
279
+ { 'model' => 'llama2',
280
+ 'created_at' => '2024-01-07T01:38:02.081494506Z',
281
+ 'message' => { 'role' => 'assistant', 'content' => '*' },
280
282
  'done' => false },
281
283
  # ...
282
- { 'model' => 'dolphin-phi',
283
- 'created_at' => '2024-01-06T18:17:25.491597233Z',
284
+ { 'model' => 'llama2',
285
+ 'created_at' => '2024-01-07T01:38:17.855905499Z',
284
286
  'message' => { 'role' => 'assistant', 'content' => '?' },
285
287
  'done' => false },
286
- { 'model' => 'dolphin-phi',
287
- 'created_at' => '2024-01-06T18:17:25.578463723Z',
288
+ { 'model' => 'llama2',
289
+ 'created_at' => '2024-01-07T01:38:18.07331245Z',
288
290
  'message' => { 'role' => 'assistant', 'content' => '' },
289
291
  'done' => true,
290
- 'total_duration' => 5_274_177_696,
291
- 'load_duration' => 1_565_325,
292
- 'prompt_eval_count' => 30,
293
- 'prompt_eval_duration' => 2_284_638_000,
294
- 'eval_count' => 29,
295
- 'eval_duration' => 2_983_962_000 }]
292
+ 'total_duration' => 22_494_544_502,
293
+ 'load_duration' => 4_224_600,
294
+ 'prompt_eval_count' => 28,
295
+ 'prompt_eval_duration' => 6_496_583_000,
296
+ 'eval_count' => 61,
297
+ 'eval_duration' => 15_991_728_000 }]
296
298
  ```
297
299
 
298
300
  ##### Back-and-Forth Conversations
@@ -303,11 +305,11 @@ To maintain a back-and-forth conversation, you need to append the received respo
303
305
 
304
306
  ```ruby
305
307
  result = client.chat(
306
- { model: 'dolphin-phi',
308
+ { model: 'llama2',
307
309
  messages: [
308
310
  { role: 'user', content: 'Hi! My name is Purple.' },
309
311
  { role: 'assistant',
310
- content: "Hi, Purple! It's nice to meet you. I am Dolphin. How can I help you today?" },
312
+ content: 'Hi, Purple!' },
311
313
  { role: 'user', content: "What's my name?" }
312
314
  ] }
313
315
  ) do |event, raw|
@@ -318,37 +320,41 @@ end
318
320
  Event:
319
321
 
320
322
  ```ruby
321
- { 'model' => 'dolphin-phi',
322
- 'created_at' => '2024-01-06T19:07:51.05465997Z',
323
- 'message' => { 'role' => 'assistant', 'content' => 'Your' },
323
+ { 'model' => 'llama2',
324
+ 'created_at' => '2024-01-07T01:40:07.352998498Z',
325
+ 'message' => { 'role' => 'assistant', 'content' => ' Pur' },
324
326
  'done' => false }
325
327
  ```
326
328
 
327
329
  Result:
328
330
  ```ruby
329
- [{ 'model' => 'dolphin-phi',
330
- 'created_at' => '2024-01-06T19:07:51.05465997Z',
331
+ [{ 'model' => 'llama2',
332
+ 'created_at' => '2024-01-07T01:40:06.562939469Z',
331
333
  'message' => { 'role' => 'assistant', 'content' => 'Your' },
332
334
  'done' => false },
333
- { 'model' => 'dolphin-phi',
334
- 'created_at' => '2024-01-06T19:07:51.184476541Z',
335
- 'message' => { 'role' => 'assistant', 'content' => ' name' },
336
- 'done' => false },
337
335
  # ...
338
- { 'model' => 'dolphin-phi',
339
- 'created_at' => '2024-01-06T19:07:56.526297223Z',
340
- 'message' => { 'role' => 'assistant', 'content' => '.' },
336
+ { 'model' => 'llama2',
337
+ 'created_at' => '2024-01-07T01:40:07.352998498Z',
338
+ 'message' => { 'role' => 'assistant', 'content' => ' Pur' },
339
+ 'done' => false },
340
+ { 'model' => 'llama2',
341
+ 'created_at' => '2024-01-07T01:40:07.545323584Z',
342
+ 'message' => { 'role' => 'assistant', 'content' => 'ple' },
341
343
  'done' => false },
342
- { 'model' => 'dolphin-phi',
343
- 'created_at' => '2024-01-06T19:07:56.667809424Z',
344
+ { 'model' => 'llama2',
345
+ 'created_at' => '2024-01-07T01:40:07.77769408Z',
346
+ 'message' => { 'role' => 'assistant', 'content' => '!' },
347
+ 'done' => false },
348
+ { 'model' => 'llama2',
349
+ 'created_at' => '2024-01-07T01:40:07.974165849Z',
344
350
  'message' => { 'role' => 'assistant', 'content' => '' },
345
351
  'done' => true,
346
- 'total_duration' => 12_169_557_266,
347
- 'load_duration' => 4_486_689,
348
- 'prompt_eval_count' => 95,
349
- 'prompt_eval_duration' => 6_678_566_000,
350
- 'eval_count' => 40,
351
- 'eval_duration' => 5_483_133_000 }]
352
+ 'total_duration' => 11_482_012_681,
353
+ 'load_duration' => 4_246_882,
354
+ 'prompt_eval_count' => 57,
355
+ 'prompt_eval_duration' => 10_387_150_000,
356
+ 'eval_count' => 6,
357
+ 'eval_duration' => 1_089_249_000 }]
352
358
  ```
353
359
 
354
360
  #### embeddings: Generate Embeddings
@@ -357,7 +363,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#gen
357
363
 
358
364
  ```ruby
359
365
  result = client.embeddings(
360
- { model: 'dolphin-phi',
366
+ { model: 'llama2',
361
367
  prompt: 'Hi!' }
362
368
  )
363
369
  ```
@@ -365,11 +371,9 @@ result = client.embeddings(
365
371
  Result:
366
372
  ```ruby
367
373
  [{ 'embedding' =>
368
- [1.0372048616409302,
369
- 1.0635842084884644,
374
+ [0.6970467567443848, -2.248202085494995,
370
375
  # ...
371
- -0.5416496396064758,
372
- 0.051569778472185135] }]
376
+ -1.5994540452957153, -0.3464218080043793] }]
373
377
  ```
374
378
 
375
379
  #### Models
@@ -381,7 +385,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#cre
381
385
  ```ruby
382
386
  result = client.create(
383
387
  { name: 'mario',
384
- modelfile: "FROM dolphin-phi\nSYSTEM You are mario from Super Mario Bros." }
388
+ modelfile: "FROM llama2\nSYSTEM You are mario from Super Mario Bros." }
385
389
  ) do |event, raw|
386
390
  puts event
387
391
  end
@@ -422,9 +426,7 @@ client.generate(
422
426
  end
423
427
  ```
424
428
 
425
- > _Hello! I'm Mario, a character from the popular video game series Super Mario Bros. My goal is to rescue Princess Peach from the evil Bowser and his minions, so we can live happily ever after in the Mushroom Kingdom! 🍄🐥_
426
- >
427
- > _What brings you here? How can I help you on your journey?_
429
+ > _Woah! *adjusts sunglasses* It's-a me, Mario! *winks* You must be a new friend I've-a met here in the Mushroom Kingdom. *tips top hat* What brings you to this neck of the woods? Maybe you're looking for-a some help on your adventure? *nods* Just let me know, and I'll do my best to-a assist ya! 😃_
428
430
 
429
431
  ##### tags: List Local Models
430
432
 
@@ -437,28 +439,28 @@ result = client.tags
437
439
  Result:
438
440
  ```ruby
439
441
  [{ 'models' =>
440
- [{ 'name' => 'dolphin-phi:latest',
441
- 'modified_at' => '2024-01-06T12:20:42.778120982-03:00',
442
- 'size' => 1_602_473_850,
442
+ [{ 'name' => 'llama2:latest',
443
+ 'modified_at' => '2024-01-06T15:06:23.6349195-03:00',
444
+ 'size' => 3_826_793_677,
443
445
  'digest' =>
444
- 'c5761fc772409945787240af89a5cce01dd39dc52f1b7b80d080a1163e8dbe10',
446
+ '78e26419b4469263f75331927a00a0284ef6544c1975b826b15abdaef17bb962',
445
447
  'details' =>
446
- { 'format' => 'gguf',
447
- 'family' => 'phi2',
448
- 'families' => ['phi2'],
449
- 'parameter_size' => '3B',
450
- 'quantization_level' => 'Q4_0' } },
448
+ { 'format' => 'gguf',
449
+ 'family' => 'llama',
450
+ 'families' => ['llama'],
451
+ 'parameter_size' => '7B',
452
+ 'quantization_level' => 'Q4_0' } },
451
453
  { 'name' => 'mario:latest',
452
- 'modified_at' => '2024-01-06T16:19:11.340234644-03:00',
453
- 'size' => 1_602_473_846,
454
+ 'modified_at' => '2024-01-06T22:41:59.495298101-03:00',
455
+ 'size' => 3_826_793_787,
454
456
  'digest' =>
455
- '582e668feaba3fcb6add3cee26046a1d6a0c940b86a692ea30d5100aec90135f',
457
+ '291f46d2fa687dfaff45de96a8cb6e32707bc16ec1e1dfe8d65e9634c34c660c',
456
458
  'details' =>
457
- { 'format' => 'gguf',
458
- 'family' => 'phi2',
459
- 'families' => ['phi2'],
460
- 'parameter_size' => '3B',
461
- 'quantization_level' => 'Q4_0' } }] }]
459
+ { 'format' => 'gguf',
460
+ 'family' => 'llama',
461
+ 'families' => ['llama'],
462
+ 'parameter_size' => '7B',
463
+ 'quantization_level' => 'Q4_0' } }] }]
462
464
  ```
463
465
 
464
466
  ##### show: Show Model Information
@@ -467,35 +469,33 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#sho
467
469
 
468
470
  ```ruby
469
471
  result = client.show(
470
- { name: 'dolphin-phi' }
472
+ { name: 'llama2' }
471
473
  )
472
474
  ```
473
475
 
474
476
  Result:
475
477
  ```ruby
476
478
  [{ 'license' =>
477
- "MICROSOFT RESEARCH LICENSE TERMS\n" \
479
+ "LLAMA 2 COMMUNITY LICENSE AGREEMENT\t\n" \
478
480
  # ...
479
- 'It also applies even if Microsoft knew or should have known about the possibility...',
481
+ "* Reporting violations of the Acceptable Use Policy or unlicensed uses of Llama..." \
482
+ "\n",
480
483
  'modelfile' =>
481
484
  "# Modelfile generated by \"ollama show\"\n" \
482
485
  # ...
483
- 'PARAMETER stop "<|im_end|>"',
486
+ 'PARAMETER stop "<</SYS>>"',
484
487
  'parameters' =>
485
- "stop <|im_start|>\n" \
486
- 'stop <|im_end|>',
487
- 'template' =>
488
- "<|im_start|>system\n" \
489
- "{{ .System }}<|im_end|>\n" \
490
- "<|im_start|>user\n" \
491
- "{{ .Prompt }}<|im_end|>\n" \
492
- "<|im_start|>assistant\n",
493
- 'system' => 'You are Dolphin, a helpful AI assistant.',
488
+ "stop [INST]\n" \
489
+ "stop [/INST]\n" \
490
+ "stop <<SYS>>\n" \
491
+ 'stop <</SYS>>',
492
+ 'template' =>
493
+ "[INST] <<SYS>>{{ .System }}<</SYS>>\n\n{{ .Prompt }} [/INST]\n",
494
494
  'details' =>
495
495
  { 'format' => 'gguf',
496
- 'family' => 'phi2',
497
- 'families' => ['phi2'],
498
- 'parameter_size' => '3B',
496
+ 'family' => 'llama',
497
+ 'families' => ['llama'],
498
+ 'parameter_size' => '7B',
499
499
  'quantization_level' => 'Q4_0' } }]
500
500
  ```
501
501
 
@@ -505,8 +505,8 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#cop
505
505
 
506
506
  ```ruby
507
507
  result = client.copy(
508
- { source: 'dolphin-phi',
509
- destination: 'dolphin-phi-backup' }
508
+ { source: 'llama2',
509
+ destination: 'llama2-backup' }
510
510
  )
511
511
  ```
512
512
 
@@ -543,7 +543,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#del
543
543
 
544
544
  ```ruby
545
545
  result = client.delete(
546
- { name: 'dolphin-phi' }
546
+ { name: 'llama2' }
547
547
  )
548
548
  ```
549
549
 
@@ -556,14 +556,14 @@ If the model does not exist:
556
556
  ```ruby
557
557
  begin
558
558
  result = client.delete(
559
- { name: 'dolphin-phi' }
559
+ { name: 'llama2' }
560
560
  )
561
561
  rescue Ollama::Errors::OllamaError => error
562
562
  puts error.class # Ollama::Errors::RequestError
563
563
  puts error.message # 'the server responded with status 404'
564
564
 
565
565
  puts error.payload
566
- # { name: 'dolphin-phi',
566
+ # { name: 'llama2',
567
567
  # ...
568
568
  # }
569
569
 
@@ -578,7 +578,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#pul
578
578
 
579
579
  ```ruby
580
580
  result = client.pull(
581
- { name: 'dolphin-phi' }
581
+ { name: 'llama2' }
582
582
  ) do |event, raw|
583
583
  puts event
584
584
  end
@@ -660,6 +660,69 @@ Result:
660
660
  { 'status' => 'success' }]
661
661
  ```
662
662
 
663
+ ### Modes
664
+
665
+ #### Text
666
+
667
+ You can use the [generate](#generate-generate-a-completion) or [chat](#chat-generate-a-chat-completion) methods for text.
668
+
669
+ #### Image
670
+
671
+ ![A black and white image of an old piano. The piano is an upright model, with the keys on the right side of the image. The piano is sitting on a tiled floor. There is a small round object on the top of the piano.](https://raw.githubusercontent.com/gbaptista/assets/main/gemini-ai/piano.jpg)
672
+
673
+ > _Courtesy of [Unsplash](https://unsplash.com/photos/greyscale-photo-of-grand-piano-czPs0z3-Ggg)_
674
+
675
+ You need to choose a model that supports images, like [LLaVA](https://ollama.ai/library/llava) or [bakllava](https://ollama.ai/library/bakllava), and encode the image as [Base64](https://en.wikipedia.org/wiki/Base64).
676
+
677
+ Depending on your hardware, some models that support images can be slow, so you may want to increase the client [timeout](#timeout):
678
+
679
+ ```ruby
680
+ client = Ollama.new(
681
+ credentials: { address: 'http://localhost:11434' },
682
+ options: {
683
+ server_sent_events: true,
684
+ connection: { request: { timeout: 120, read_timeout: 120 } } }
685
+ )
686
+ ```
687
+
688
+ Using the `generate` method:
689
+
690
+ ```ruby
691
+ require 'base64'
692
+
693
+ client.generate(
694
+ { model: 'llava',
695
+ prompt: 'Please describe this image.',
696
+ images: [Base64.strict_encode64(File.read('piano.jpg'))] }
697
+ ) do |event, raw|
698
+ print event['response']
699
+ end
700
+ ```
701
+
702
+ Output:
703
+ > _The image is a black and white photo of an old piano, which appears to be in need of maintenance. A chair is situated right next to the piano. Apart from that, there are no other objects or people visible in the scene._
704
+
705
+ Using the `chat` method:
706
+ ```ruby
707
+ require 'base64'
708
+
709
+ result = client.chat(
710
+ { model: 'llava',
711
+ messages: [
712
+ { role: 'user',
713
+ content: 'Please describe this image.',
714
+ images: [Base64.strict_encode64(File.read('piano.jpg'))] }
715
+ ] }
716
+ ) do |event, raw|
717
+ puts event
718
+ end
719
+ ```
720
+
721
+ Output:
722
+ > _The image displays an old piano, sitting on a wooden floor with black keys. Next to the piano, there is another keyboard in the scene, possibly used for playing music._
723
+ >
724
+ > _On top of the piano, there are two mice placed in different locations within its frame. These mice might be meant for controlling the music being played or simply as decorative items. The overall atmosphere seems to be focused on artistic expression through this unique instrument._
725
+
663
726
  ### Streaming and Server-Sent Events (SSE)
664
727
 
665
728
  [Server-Sent Events (SSE)](https://en.wikipedia.org/wiki/Server-sent_events) is a technology that allows certain endpoints to offer streaming capabilities, such as creating the impression that "the model is typing along with you," rather than delivering the entire answer all at once.
@@ -675,7 +738,7 @@ client = Ollama.new(
675
738
  Or, you can decide on a request basis:
676
739
  ```ruby
677
740
  result = client.generate(
678
- { model: 'dolphin-phi',
741
+ { model: 'llama2',
679
742
  prompt: 'Hi!' },
680
743
  server_sent_events: true
681
744
  ) do |event, raw|
@@ -696,7 +759,7 @@ Ollama may launch a new endpoint that we haven't covered in the Gem yet. If that
696
759
  ```ruby
697
760
  result = client.request(
698
761
  'api/generate',
699
- { model: 'dolphin-phi',
762
+ { model: 'llama2',
700
763
  prompt: 'Hi!' },
701
764
  request_method: 'POST', server_sent_events: true
702
765
  )
@@ -742,7 +805,7 @@ require 'ollama-ai'
742
805
 
743
806
  begin
744
807
  client.chat_completions(
745
- { model: 'dolphin-phi',
808
+ { model: 'llama2',
746
809
  prompt: 'Hi!' }
747
810
  )
748
811
  rescue Ollama::Errors::OllamaError => error
@@ -750,7 +813,7 @@ rescue Ollama::Errors::OllamaError => error
750
813
  puts error.message # 'the server responded with status 500'
751
814
 
752
815
  puts error.payload
753
- # { model: 'dolphin-phi',
816
+ # { model: 'llama2',
754
817
  # prompt: 'Hi!',
755
818
  # ...
756
819
  # }
@@ -767,7 +830,7 @@ require 'ollama-ai/errors'
767
830
 
768
831
  begin
769
832
  client.chat_completions(
770
- { model: 'dolphin-phi',
833
+ { model: 'llama2',
771
834
  prompt: 'Hi!' }
772
835
  )
773
836
  rescue OllamaError => error
@@ -790,6 +853,8 @@ RequestError
790
853
  ```bash
791
854
  bundle
792
855
  rubocop -A
856
+
857
+ bundle exec ruby spec/tasks/run-client.rb
793
858
  ```
794
859
 
795
860
  ### Purpose
@@ -803,7 +868,7 @@ gem build ollama-ai.gemspec
803
868
 
804
869
  gem signin
805
870
 
806
- gem push ollama-ai-1.0.0.gem
871
+ gem push ollama-ai-1.0.1.gem
807
872
  ```
808
873
 
809
874
  ### Updating the README