ollama-ai 1.0.0 → 1.2.0

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.2.0'
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
@@ -62,37 +62,41 @@ Result:
62
62
  - [TL;DR and Quick Start](#tldr-and-quick-start)
63
63
  - [Index](#index)
64
64
  - [Setup](#setup)
65
- - [Installing](#installing)
65
+ - [Installing](#installing)
66
66
  - [Usage](#usage)
67
- - [Client](#client)
68
- - [Methods](#methods)
69
- - [generate: Generate a completion](#generate-generate-a-completion)
70
- - [Without Streaming Events](#without-streaming-events)
71
- - [Receiving Stream Events](#receiving-stream-events)
72
- - [chat: Generate a chat completion](#chat-generate-a-chat-completion)
73
- - [Back-and-Forth Conversations](#back-and-forth-conversations)
74
- - [embeddings: Generate Embeddings](#embeddings-generate-embeddings)
75
- - [Models](#models)
76
- - [create: Create a Model](#create-create-a-model)
77
- - [tags: List Local Models](#tags-list-local-models)
78
- - [show: Show Model Information](#show-show-model-information)
79
- - [copy: Copy a Model](#copy-copy-a-model)
80
- - [delete: Delete a Model](#delete-delete-a-model)
81
- - [pull: Pull a Model](#pull-pull-a-model)
82
- - [push: Push a Model](#push-push-a-model)
83
- - [Streaming and Server-Sent Events (SSE)](#streaming-and-server-sent-events-sse)
84
- - [Server-Sent Events (SSE) Hang](#server-sent-events-sse-hang)
85
- - [New Functionalities and APIs](#new-functionalities-and-apis)
86
- - [Request Options](#request-options)
87
- - [Timeout](#timeout)
88
- - [Error Handling](#error-handling)
89
- - [Rescuing](#rescuing)
90
- - [For Short](#for-short)
91
- - [Errors](#errors)
67
+ - [Client](#client)
68
+ - [Methods](#methods)
69
+ - [generate: Generate a completion](#generate-generate-a-completion)
70
+ - [Without Streaming Events](#without-streaming-events)
71
+ - [Receiving Stream Events](#receiving-stream-events)
72
+ - [chat: Generate a chat completion](#chat-generate-a-chat-completion)
73
+ - [Back-and-Forth Conversations](#back-and-forth-conversations)
74
+ - [embeddings: Generate Embeddings](#embeddings-generate-embeddings)
75
+ - [Models](#models)
76
+ - [create: Create a Model](#create-create-a-model)
77
+ - [tags: List Local Models](#tags-list-local-models)
78
+ - [show: Show Model Information](#show-show-model-information)
79
+ - [copy: Copy a Model](#copy-copy-a-model)
80
+ - [delete: Delete a Model](#delete-delete-a-model)
81
+ - [pull: Pull a Model](#pull-pull-a-model)
82
+ - [push: Push a Model](#push-push-a-model)
83
+ - [Modes](#modes)
84
+ - [Text](#text)
85
+ - [Image](#image)
86
+ - [Streaming and Server-Sent Events (SSE)](#streaming-and-server-sent-events-sse)
87
+ - [Server-Sent Events (SSE) Hang](#server-sent-events-sse-hang)
88
+ - [New Functionalities and APIs](#new-functionalities-and-apis)
89
+ - [Request Options](#request-options)
90
+ - [Adapter](#adapter)
91
+ - [Timeout](#timeout)
92
+ - [Error Handling](#error-handling)
93
+ - [Rescuing](#rescuing)
94
+ - [For Short](#for-short)
95
+ - [Errors](#errors)
92
96
  - [Development](#development)
93
- - [Purpose](#purpose)
94
- - [Publish to RubyGems](#publish-to-rubygems)
95
- - [Updating the README](#updating-the-readme)
97
+ - [Purpose](#purpose)
98
+ - [Publish to RubyGems](#publish-to-rubygems)
99
+ - [Updating the README](#updating-the-readme)
96
100
  - [Resources and References](#resources-and-references)
97
101
  - [Disclaimer](#disclaimer)
98
102
 
@@ -101,11 +105,11 @@ Result:
101
105
  ### Installing
102
106
 
103
107
  ```sh
104
- gem install ollama-ai -v 1.0.0
108
+ gem install ollama-ai -v 1.2.0
105
109
  ```
106
110
 
107
111
  ```sh
108
- gem 'ollama-ai', '~> 1.0.0'
112
+ gem 'ollama-ai', '~> 1.2.0'
109
113
  ```
110
114
 
111
115
  ## Usage
@@ -148,7 +152,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#gen
148
152
 
149
153
  ```ruby
150
154
  result = client.generate(
151
- { model: 'dolphin-phi',
155
+ { model: 'llama2',
152
156
  prompt: 'Hi!',
153
157
  stream: false }
154
158
  )
@@ -156,21 +160,20 @@ result = client.generate(
156
160
 
157
161
  Result:
158
162
  ```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?",
163
+ [{ 'model' => 'llama2',
164
+ 'created_at' => '2024-01-07T01:35:41.951371247Z',
165
+ 'response' => "Hi there! It's nice to meet you. How are you today?",
163
166
  'done' => true,
164
167
  'context' =>
165
- [50_296, 10_057,
168
+ [518, 25_580,
166
169
  # ...
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 }]
170
+ 9826, 29_973],
171
+ 'total_duration' => 6_981_097_576,
172
+ 'load_duration' => 625_053,
173
+ 'prompt_eval_count' => 22,
174
+ 'prompt_eval_duration' => 4_075_171_000,
175
+ 'eval_count' => 16,
176
+ 'eval_duration' => 2_900_325_000 }]
174
177
  ```
175
178
 
176
179
  ##### Receiving Stream Events
@@ -181,7 +184,7 @@ Ensure that you have enabled [Server-Sent Events](#streaming-and-server-sent-eve
181
184
 
182
185
  ```ruby
183
186
  client.generate(
184
- { model: 'dolphin-phi',
187
+ { model: 'llama2',
185
188
  prompt: 'Hi!' }
186
189
  ) do |event, raw|
187
190
  puts event
@@ -190,8 +193,8 @@ end
190
193
 
191
194
  Event:
192
195
  ```ruby
193
- { 'model' => 'dolphin-phi',
194
- 'created_at' => '2024-01-06T17:27:29.366879586Z',
196
+ { 'model' => 'llama2',
197
+ 'created_at' => '2024-01-07T01:36:30.665245712Z',
195
198
  'response' => 'Hello',
196
199
  'done' => false }
197
200
  ```
@@ -199,46 +202,46 @@ Event:
199
202
  You can get all the receive events at once as an array:
200
203
  ```ruby
201
204
  result = client.generate(
202
- { model: 'dolphin-phi',
205
+ { model: 'llama2',
203
206
  prompt: 'Hi!' }
204
207
  )
205
208
  ```
206
209
 
207
210
  Result:
208
211
  ```ruby
209
- [{ 'model' => 'dolphin-phi',
210
- 'created_at' => '2024-01-06T16:53:21.357816652Z',
212
+ [{ 'model' => 'llama2',
213
+ 'created_at' => '2024-01-07T01:36:30.665245712Z',
211
214
  'response' => 'Hello',
212
215
  'done' => false },
213
- { 'model' => 'dolphin-phi',
214
- 'created_at' => '2024-01-06T16:53:21.490053654Z',
216
+ { 'model' => 'llama2',
217
+ 'created_at' => '2024-01-07T01:36:30.927337136Z',
215
218
  'response' => '!',
216
219
  'done' => false },
217
220
  # ...
218
- { 'model' => 'dolphin-phi',
219
- 'created_at' => '2024-01-06T16:53:24.82505599Z',
220
- 'response' => '.',
221
+ { 'model' => 'llama2',
222
+ 'created_at' => '2024-01-07T01:36:37.249416767Z',
223
+ 'response' => '?',
221
224
  'done' => false },
222
- { 'model' => 'dolphin-phi',
223
- 'created_at' => '2024-01-06T16:53:24.956774721Z',
225
+ { 'model' => 'llama2',
226
+ 'created_at' => '2024-01-07T01:36:37.44041283Z',
224
227
  'response' => '',
225
228
  'done' => true,
226
229
  'context' =>
227
- [50_296, 10_057,
230
+ [518, 25_580,
228
231
  # ...
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 }]
232
+ 13_563, 29_973],
233
+ 'total_duration' => 10_551_395_645,
234
+ 'load_duration' => 966_631,
235
+ 'prompt_eval_count' => 22,
236
+ 'prompt_eval_duration' => 4_034_990_000,
237
+ 'eval_count' => 25,
238
+ 'eval_duration' => 6_512_954_000 }]
236
239
  ```
237
240
 
238
241
  You can mix both as well:
239
242
  ```ruby
240
243
  result = client.generate(
241
- { model: 'dolphin-phi',
244
+ { model: 'llama2',
242
245
  prompt: 'Hi!' }
243
246
  ) do |event, raw|
244
247
  puts event
@@ -251,7 +254,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#gen
251
254
 
252
255
  ```ruby
253
256
  result = client.chat(
254
- { model: 'dolphin-phi',
257
+ { model: 'llama2',
255
258
  messages: [
256
259
  { role: 'user', content: 'Hi! My name is Purple.' }
257
260
  ] }
@@ -262,37 +265,37 @@ end
262
265
 
263
266
  Event:
264
267
  ```ruby
265
- { 'model' => 'dolphin-phi',
266
- 'created_at' => '2024-01-06T18:17:22.468231988Z',
267
- 'message' => { 'role' => 'assistant', 'content' => 'Hello' },
268
+ { 'model' => 'llama2',
269
+ 'created_at' => '2024-01-07T01:38:01.729897311Z',
270
+ 'message' => { 'role' => 'assistant', 'content' => "\n" },
268
271
  'done' => false }
269
272
  ```
270
273
 
271
274
  Result:
272
275
  ```ruby
273
- [{ 'model' => 'dolphin-phi',
274
- 'created_at' => '2024-01-06T18:17:22.468231988Z',
275
- 'message' => { 'role' => 'assistant', 'content' => 'Hello' },
276
+ [{ 'model' => 'llama2',
277
+ 'created_at' => '2024-01-07T01:38:01.729897311Z',
278
+ 'message' => { 'role' => 'assistant', 'content' => "\n" },
276
279
  'done' => false },
277
- { 'model' => 'dolphin-phi',
278
- 'created_at' => '2024-01-06T18:17:22.594414415Z',
279
- 'message' => { 'role' => 'assistant', 'content' => ' Purple' },
280
+ { 'model' => 'llama2',
281
+ 'created_at' => '2024-01-07T01:38:02.081494506Z',
282
+ 'message' => { 'role' => 'assistant', 'content' => '*' },
280
283
  'done' => false },
281
284
  # ...
282
- { 'model' => 'dolphin-phi',
283
- 'created_at' => '2024-01-06T18:17:25.491597233Z',
285
+ { 'model' => 'llama2',
286
+ 'created_at' => '2024-01-07T01:38:17.855905499Z',
284
287
  'message' => { 'role' => 'assistant', 'content' => '?' },
285
288
  'done' => false },
286
- { 'model' => 'dolphin-phi',
287
- 'created_at' => '2024-01-06T18:17:25.578463723Z',
289
+ { 'model' => 'llama2',
290
+ 'created_at' => '2024-01-07T01:38:18.07331245Z',
288
291
  'message' => { 'role' => 'assistant', 'content' => '' },
289
292
  '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 }]
293
+ 'total_duration' => 22_494_544_502,
294
+ 'load_duration' => 4_224_600,
295
+ 'prompt_eval_count' => 28,
296
+ 'prompt_eval_duration' => 6_496_583_000,
297
+ 'eval_count' => 61,
298
+ 'eval_duration' => 15_991_728_000 }]
296
299
  ```
297
300
 
298
301
  ##### Back-and-Forth Conversations
@@ -303,11 +306,11 @@ To maintain a back-and-forth conversation, you need to append the received respo
303
306
 
304
307
  ```ruby
305
308
  result = client.chat(
306
- { model: 'dolphin-phi',
309
+ { model: 'llama2',
307
310
  messages: [
308
311
  { role: 'user', content: 'Hi! My name is Purple.' },
309
312
  { role: 'assistant',
310
- content: "Hi, Purple! It's nice to meet you. I am Dolphin. How can I help you today?" },
313
+ content: 'Hi, Purple!' },
311
314
  { role: 'user', content: "What's my name?" }
312
315
  ] }
313
316
  ) do |event, raw|
@@ -318,37 +321,41 @@ end
318
321
  Event:
319
322
 
320
323
  ```ruby
321
- { 'model' => 'dolphin-phi',
322
- 'created_at' => '2024-01-06T19:07:51.05465997Z',
323
- 'message' => { 'role' => 'assistant', 'content' => 'Your' },
324
+ { 'model' => 'llama2',
325
+ 'created_at' => '2024-01-07T01:40:07.352998498Z',
326
+ 'message' => { 'role' => 'assistant', 'content' => ' Pur' },
324
327
  'done' => false }
325
328
  ```
326
329
 
327
330
  Result:
328
331
  ```ruby
329
- [{ 'model' => 'dolphin-phi',
330
- 'created_at' => '2024-01-06T19:07:51.05465997Z',
332
+ [{ 'model' => 'llama2',
333
+ 'created_at' => '2024-01-07T01:40:06.562939469Z',
331
334
  'message' => { 'role' => 'assistant', 'content' => 'Your' },
332
335
  '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
336
  # ...
338
- { 'model' => 'dolphin-phi',
339
- 'created_at' => '2024-01-06T19:07:56.526297223Z',
340
- 'message' => { 'role' => 'assistant', 'content' => '.' },
337
+ { 'model' => 'llama2',
338
+ 'created_at' => '2024-01-07T01:40:07.352998498Z',
339
+ 'message' => { 'role' => 'assistant', 'content' => ' Pur' },
340
+ 'done' => false },
341
+ { 'model' => 'llama2',
342
+ 'created_at' => '2024-01-07T01:40:07.545323584Z',
343
+ 'message' => { 'role' => 'assistant', 'content' => 'ple' },
344
+ 'done' => false },
345
+ { 'model' => 'llama2',
346
+ 'created_at' => '2024-01-07T01:40:07.77769408Z',
347
+ 'message' => { 'role' => 'assistant', 'content' => '!' },
341
348
  'done' => false },
342
- { 'model' => 'dolphin-phi',
343
- 'created_at' => '2024-01-06T19:07:56.667809424Z',
349
+ { 'model' => 'llama2',
350
+ 'created_at' => '2024-01-07T01:40:07.974165849Z',
344
351
  'message' => { 'role' => 'assistant', 'content' => '' },
345
352
  '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 }]
353
+ 'total_duration' => 11_482_012_681,
354
+ 'load_duration' => 4_246_882,
355
+ 'prompt_eval_count' => 57,
356
+ 'prompt_eval_duration' => 10_387_150_000,
357
+ 'eval_count' => 6,
358
+ 'eval_duration' => 1_089_249_000 }]
352
359
  ```
353
360
 
354
361
  #### embeddings: Generate Embeddings
@@ -357,7 +364,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#gen
357
364
 
358
365
  ```ruby
359
366
  result = client.embeddings(
360
- { model: 'dolphin-phi',
367
+ { model: 'llama2',
361
368
  prompt: 'Hi!' }
362
369
  )
363
370
  ```
@@ -365,11 +372,9 @@ result = client.embeddings(
365
372
  Result:
366
373
  ```ruby
367
374
  [{ 'embedding' =>
368
- [1.0372048616409302,
369
- 1.0635842084884644,
375
+ [0.6970467567443848, -2.248202085494995,
370
376
  # ...
371
- -0.5416496396064758,
372
- 0.051569778472185135] }]
377
+ -1.5994540452957153, -0.3464218080043793] }]
373
378
  ```
374
379
 
375
380
  #### Models
@@ -381,7 +386,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#cre
381
386
  ```ruby
382
387
  result = client.create(
383
388
  { name: 'mario',
384
- modelfile: "FROM dolphin-phi\nSYSTEM You are mario from Super Mario Bros." }
389
+ modelfile: "FROM llama2\nSYSTEM You are mario from Super Mario Bros." }
385
390
  ) do |event, raw|
386
391
  puts event
387
392
  end
@@ -422,9 +427,7 @@ client.generate(
422
427
  end
423
428
  ```
424
429
 
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?_
430
+ > _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
431
 
429
432
  ##### tags: List Local Models
430
433
 
@@ -437,28 +440,28 @@ result = client.tags
437
440
  Result:
438
441
  ```ruby
439
442
  [{ 'models' =>
440
- [{ 'name' => 'dolphin-phi:latest',
441
- 'modified_at' => '2024-01-06T12:20:42.778120982-03:00',
442
- 'size' => 1_602_473_850,
443
+ [{ 'name' => 'llama2:latest',
444
+ 'modified_at' => '2024-01-06T15:06:23.6349195-03:00',
445
+ 'size' => 3_826_793_677,
443
446
  'digest' =>
444
- 'c5761fc772409945787240af89a5cce01dd39dc52f1b7b80d080a1163e8dbe10',
447
+ '78e26419b4469263f75331927a00a0284ef6544c1975b826b15abdaef17bb962',
445
448
  'details' =>
446
- { 'format' => 'gguf',
447
- 'family' => 'phi2',
448
- 'families' => ['phi2'],
449
- 'parameter_size' => '3B',
450
- 'quantization_level' => 'Q4_0' } },
449
+ { 'format' => 'gguf',
450
+ 'family' => 'llama',
451
+ 'families' => ['llama'],
452
+ 'parameter_size' => '7B',
453
+ 'quantization_level' => 'Q4_0' } },
451
454
  { 'name' => 'mario:latest',
452
- 'modified_at' => '2024-01-06T16:19:11.340234644-03:00',
453
- 'size' => 1_602_473_846,
455
+ 'modified_at' => '2024-01-06T22:41:59.495298101-03:00',
456
+ 'size' => 3_826_793_787,
454
457
  'digest' =>
455
- '582e668feaba3fcb6add3cee26046a1d6a0c940b86a692ea30d5100aec90135f',
458
+ '291f46d2fa687dfaff45de96a8cb6e32707bc16ec1e1dfe8d65e9634c34c660c',
456
459
  'details' =>
457
- { 'format' => 'gguf',
458
- 'family' => 'phi2',
459
- 'families' => ['phi2'],
460
- 'parameter_size' => '3B',
461
- 'quantization_level' => 'Q4_0' } }] }]
460
+ { 'format' => 'gguf',
461
+ 'family' => 'llama',
462
+ 'families' => ['llama'],
463
+ 'parameter_size' => '7B',
464
+ 'quantization_level' => 'Q4_0' } }] }]
462
465
  ```
463
466
 
464
467
  ##### show: Show Model Information
@@ -467,35 +470,33 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#sho
467
470
 
468
471
  ```ruby
469
472
  result = client.show(
470
- { name: 'dolphin-phi' }
473
+ { name: 'llama2' }
471
474
  )
472
475
  ```
473
476
 
474
477
  Result:
475
478
  ```ruby
476
479
  [{ 'license' =>
477
- "MICROSOFT RESEARCH LICENSE TERMS\n" \
480
+ "LLAMA 2 COMMUNITY LICENSE AGREEMENT\t\n" \
478
481
  # ...
479
- 'It also applies even if Microsoft knew or should have known about the possibility...',
482
+ "* Reporting violations of the Acceptable Use Policy or unlicensed uses of Llama..." \
483
+ "\n",
480
484
  'modelfile' =>
481
485
  "# Modelfile generated by \"ollama show\"\n" \
482
486
  # ...
483
- 'PARAMETER stop "<|im_end|>"',
487
+ 'PARAMETER stop "<</SYS>>"',
484
488
  '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.',
489
+ "stop [INST]\n" \
490
+ "stop [/INST]\n" \
491
+ "stop <<SYS>>\n" \
492
+ 'stop <</SYS>>',
493
+ 'template' =>
494
+ "[INST] <<SYS>>{{ .System }}<</SYS>>\n\n{{ .Prompt }} [/INST]\n",
494
495
  'details' =>
495
496
  { 'format' => 'gguf',
496
- 'family' => 'phi2',
497
- 'families' => ['phi2'],
498
- 'parameter_size' => '3B',
497
+ 'family' => 'llama',
498
+ 'families' => ['llama'],
499
+ 'parameter_size' => '7B',
499
500
  'quantization_level' => 'Q4_0' } }]
500
501
  ```
501
502
 
@@ -505,8 +506,8 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#cop
505
506
 
506
507
  ```ruby
507
508
  result = client.copy(
508
- { source: 'dolphin-phi',
509
- destination: 'dolphin-phi-backup' }
509
+ { source: 'llama2',
510
+ destination: 'llama2-backup' }
510
511
  )
511
512
  ```
512
513
 
@@ -543,7 +544,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#del
543
544
 
544
545
  ```ruby
545
546
  result = client.delete(
546
- { name: 'dolphin-phi' }
547
+ { name: 'llama2' }
547
548
  )
548
549
  ```
549
550
 
@@ -556,14 +557,14 @@ If the model does not exist:
556
557
  ```ruby
557
558
  begin
558
559
  result = client.delete(
559
- { name: 'dolphin-phi' }
560
+ { name: 'llama2' }
560
561
  )
561
562
  rescue Ollama::Errors::OllamaError => error
562
563
  puts error.class # Ollama::Errors::RequestError
563
564
  puts error.message # 'the server responded with status 404'
564
565
 
565
566
  puts error.payload
566
- # { name: 'dolphin-phi',
567
+ # { name: 'llama2',
567
568
  # ...
568
569
  # }
569
570
 
@@ -578,7 +579,7 @@ API Documentation: https://github.com/jmorganca/ollama/blob/main/docs/api.md#pul
578
579
 
579
580
  ```ruby
580
581
  result = client.pull(
581
- { name: 'dolphin-phi' }
582
+ { name: 'llama2' }
582
583
  ) do |event, raw|
583
584
  puts event
584
585
  end
@@ -660,6 +661,69 @@ Result:
660
661
  { 'status' => 'success' }]
661
662
  ```
662
663
 
664
+ ### Modes
665
+
666
+ #### Text
667
+
668
+ You can use the [generate](#generate-generate-a-completion) or [chat](#chat-generate-a-chat-completion) methods for text.
669
+
670
+ #### Image
671
+
672
+ ![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)
673
+
674
+ > _Courtesy of [Unsplash](https://unsplash.com/photos/greyscale-photo-of-grand-piano-czPs0z3-Ggg)_
675
+
676
+ 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).
677
+
678
+ Depending on your hardware, some models that support images can be slow, so you may want to increase the client [timeout](#timeout):
679
+
680
+ ```ruby
681
+ client = Ollama.new(
682
+ credentials: { address: 'http://localhost:11434' },
683
+ options: {
684
+ server_sent_events: true,
685
+ connection: { request: { timeout: 120, read_timeout: 120 } } }
686
+ )
687
+ ```
688
+
689
+ Using the `generate` method:
690
+
691
+ ```ruby
692
+ require 'base64'
693
+
694
+ client.generate(
695
+ { model: 'llava',
696
+ prompt: 'Please describe this image.',
697
+ images: [Base64.strict_encode64(File.read('piano.jpg'))] }
698
+ ) do |event, raw|
699
+ print event['response']
700
+ end
701
+ ```
702
+
703
+ Output:
704
+ > _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._
705
+
706
+ Using the `chat` method:
707
+ ```ruby
708
+ require 'base64'
709
+
710
+ result = client.chat(
711
+ { model: 'llava',
712
+ messages: [
713
+ { role: 'user',
714
+ content: 'Please describe this image.',
715
+ images: [Base64.strict_encode64(File.read('piano.jpg'))] }
716
+ ] }
717
+ ) do |event, raw|
718
+ puts event
719
+ end
720
+ ```
721
+
722
+ Output:
723
+ > _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._
724
+ >
725
+ > _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._
726
+
663
727
  ### Streaming and Server-Sent Events (SSE)
664
728
 
665
729
  [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 +739,7 @@ client = Ollama.new(
675
739
  Or, you can decide on a request basis:
676
740
  ```ruby
677
741
  result = client.generate(
678
- { model: 'dolphin-phi',
742
+ { model: 'llama2',
679
743
  prompt: 'Hi!' },
680
744
  server_sent_events: true
681
745
  ) do |event, raw|
@@ -696,7 +760,7 @@ Ollama may launch a new endpoint that we haven't covered in the Gem yet. If that
696
760
  ```ruby
697
761
  result = client.request(
698
762
  'api/generate',
699
- { model: 'dolphin-phi',
763
+ { model: 'llama2',
700
764
  prompt: 'Hi!' },
701
765
  request_method: 'POST', server_sent_events: true
702
766
  )
@@ -704,6 +768,21 @@ result = client.request(
704
768
 
705
769
  ### Request Options
706
770
 
771
+ #### Adapter
772
+
773
+ The gem uses [Faraday](https://github.com/lostisland/faraday) with the [Typhoeus](https://github.com/typhoeus/typhoeus) adapter by default.
774
+
775
+ You can use a different adapter if you want:
776
+
777
+ ```ruby
778
+ require 'faraday/net_http'
779
+
780
+ client = Ollama.new(
781
+ credentials: { address: 'http://localhost:11434' },
782
+ options: { connection: { adapter: :net_http } }
783
+ )
784
+ ```
785
+
707
786
  #### Timeout
708
787
 
709
788
  You can set the maximum number of seconds to wait for the request to complete with the `timeout` option:
@@ -742,7 +821,7 @@ require 'ollama-ai'
742
821
 
743
822
  begin
744
823
  client.chat_completions(
745
- { model: 'dolphin-phi',
824
+ { model: 'llama2',
746
825
  prompt: 'Hi!' }
747
826
  )
748
827
  rescue Ollama::Errors::OllamaError => error
@@ -750,7 +829,7 @@ rescue Ollama::Errors::OllamaError => error
750
829
  puts error.message # 'the server responded with status 500'
751
830
 
752
831
  puts error.payload
753
- # { model: 'dolphin-phi',
832
+ # { model: 'llama2',
754
833
  # prompt: 'Hi!',
755
834
  # ...
756
835
  # }
@@ -767,7 +846,7 @@ require 'ollama-ai/errors'
767
846
 
768
847
  begin
769
848
  client.chat_completions(
770
- { model: 'dolphin-phi',
849
+ { model: 'llama2',
771
850
  prompt: 'Hi!' }
772
851
  )
773
852
  rescue OllamaError => error
@@ -790,6 +869,8 @@ RequestError
790
869
  ```bash
791
870
  bundle
792
871
  rubocop -A
872
+
873
+ bundle exec ruby spec/tasks/run-client.rb
793
874
  ```
794
875
 
795
876
  ### Purpose
@@ -803,7 +884,7 @@ gem build ollama-ai.gemspec
803
884
 
804
885
  gem signin
805
886
 
806
- gem push ollama-ai-1.0.0.gem
887
+ gem push ollama-ai-1.2.0.gem
807
888
  ```
808
889
 
809
890
  ### Updating the README