ollama-ruby 0.8.0 → 0.9.1
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/CHANGES.md +34 -0
- data/README.md +168 -166
- data/bin/ollama_chat +252 -204
- data/lib/ollama/handlers/markdown.rb +1 -2
- data/lib/ollama/utils/fetcher.rb +8 -0
- data/lib/ollama/version.rb +1 -1
- data/ollama-ruby.gemspec +4 -4
- data/spec/ollama/client_spec.rb +3 -3
- data/spec/ollama/documents/redis_backed_memory_cache_spec.rb +1 -1
- data/spec/ollama/documents/redis_cache_spec.rb +1 -1
- data/spec/ollama/documents_spec.rb +5 -5
- data/spec/ollama/handlers/markdown_spec.rb +0 -2
- data/spec/ollama/utils/fetcher_spec.rb +28 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3976b4254bbedc3655a6a737000903217eff8b4b941971eb6ae4fda630ba40c3
|
4
|
+
data.tar.gz: 29187dded0f2748e8e684648ab374d027aaff18a6f85ede48df78dc34b705645
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69ad552c73c297d23db6a65681008c79329de3d4a02a07f28b027a94820f9505488870e4bce6b43c1ae6a6fb64c6107ce4cc3d28b307f07573987464e6eaed84
|
7
|
+
data.tar.gz: 79dd0a71d48726900ed7df4508f2031191f00f15b3713cc562aa29112c4942e72836c5d487c8883b173dc760d8e815461b66e3c4b0fbdccd1226e6019af2419a
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2024-10-19 v0.9.1
|
4
|
+
|
5
|
+
* Fixing string interpolation in `import_source` method:
|
6
|
+
+ Changed result to use `#{}` instead of `%{}` for string interpolation
|
7
|
+
* Move `pull_model_unless_present` method:
|
8
|
+
+ Moved the method before other methods
|
9
|
+
* Moved Switch classes and `setup_switches` method into Switches module:
|
10
|
+
+ Moved the classes and method into a new module
|
11
|
+
* Utils::Fetcher: Normalize URL in fetcher utility:
|
12
|
+
+ Added `normalize_url` method to class Ollama::Utils::Fetcher
|
13
|
+
+ Normalizes URL by decoding URI components, removing anchors, and escaping special characters
|
14
|
+
+ `excon` method now calls `normalize_url` on the provided URL
|
15
|
+
+ Added specs for `normalize_url` in `fetcher_spec.rb`
|
16
|
+
* Remove Ollama top level Namespace b/c we include it from `ollama_chat`:
|
17
|
+
+ Removed the top-level namespace
|
18
|
+
|
19
|
+
## 2024-10-18 v0.9.0
|
20
|
+
|
21
|
+
* Add document policy chooser and modify embedding/importing/summarizing
|
22
|
+
behavior:
|
23
|
+
+ Add `/document_policy` command to choose a scan policy for document
|
24
|
+
references
|
25
|
+
+ Modify `embed_source`, `import_source`, and `summarize_source` methods to
|
26
|
+
use the chosen document policy
|
27
|
+
+ Update `choose_model` method to set `$document_policy` based on
|
28
|
+
configuration or chat command
|
29
|
+
* Fix regular expression in `ollama_chat` script:
|
30
|
+
+ Updated regular expression for `/info` to `/^/info$`
|
31
|
+
* Improve ask prompt to ask about clearing messages and collection.
|
32
|
+
* Update specs to use `expect` instead of `allow`
|
33
|
+
* Fix library homepage URL in README.md
|
34
|
+
* Refactor Markdown handler to remove unnecessary puts statement
|
35
|
+
* Reorder chapters in README.md a bit
|
36
|
+
|
3
37
|
## 2024-10-07 v0.8.0
|
4
38
|
|
5
39
|
* **Refactor source handling in Ollama chat**:
|
data/README.md
CHANGED
@@ -26,161 +26,23 @@ gem 'ollama-ruby'
|
|
26
26
|
|
27
27
|
to your Gemfile and run `bundle install` in your terminal.
|
28
28
|
|
29
|
-
##
|
30
|
-
|
31
|
-
### ollama\_chat
|
32
|
-
|
33
|
-
This a chat client, that can be used to connect to an ollama server and enter a
|
34
|
-
chat converstation with a LLM. It can be called with the following arguments:
|
35
|
-
|
36
|
-
```
|
37
|
-
Usage: ollama_chat [OPTIONS]
|
38
|
-
|
39
|
-
-f CONFIG config file to read
|
40
|
-
-u URL the ollama base url, OLLAMA_URL
|
41
|
-
-m MODEL the ollama model to chat with, OLLAMA_CHAT_MODEL
|
42
|
-
-s SYSTEM the system prompt to use as a file, OLLAMA_CHAT_SYSTEM
|
43
|
-
-c CHAT a saved chat conversation to load
|
44
|
-
-C COLLECTION name of the collection used in this conversation
|
45
|
-
-D DOCUMENT load document and add to embeddings collection (multiple)
|
46
|
-
-M use (empty) MemoryCache for this chat session
|
47
|
-
-E disable embeddings for this chat session
|
48
|
-
-V display the current version number and quit
|
49
|
-
-h this help
|
50
|
-
```
|
51
|
-
|
52
|
-
The base URL can be either set by the environment variable `OLLAMA_URL` or it
|
53
|
-
is derived from the environment variable `OLLAMA_HOST`. The default model to
|
54
|
-
connect can be configured in the environment variable `OLLAMA_MODEL`.
|
55
|
-
|
56
|
-
The YAML config file in `$XDG_CONFIG_HOME/ollama_chat/config.yml`, that you can
|
57
|
-
use for more complex settings, it looks like this:
|
58
|
-
|
59
|
-
```
|
60
|
-
---
|
61
|
-
url: <%= ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST') %>
|
62
|
-
model:
|
63
|
-
name: <%= ENV.fetch('OLLAMA_CHAT_MODEL', 'llama3.1') %>
|
64
|
-
options:
|
65
|
-
num_ctx: 8192
|
66
|
-
system: <%= ENV.fetch('OLLAMA_CHAT_SYSTEM', 'null') %>
|
67
|
-
voice: Samantha
|
68
|
-
markdown: true
|
69
|
-
embedding:
|
70
|
-
enabled: true
|
71
|
-
model:
|
72
|
-
name: mxbai-embed-large
|
73
|
-
options: {}
|
74
|
-
collection: <%= ENV.fetch('OLLAMA_CHAT_COLLECTION', 'ollama_chat') %>
|
75
|
-
found_texts_size: 4096
|
76
|
-
splitter:
|
77
|
-
name: RecursiveCharacter
|
78
|
-
chunk_size: 1024
|
79
|
-
cache: Ollama::Documents::RedisCache
|
80
|
-
redis:
|
81
|
-
url: <%= ENV.fetch('REDIS_URL', 'null') %>
|
82
|
-
debug: <%= ENV['OLLAMA_CHAT_DEBUG'].to_i == 1 ? true : false %>
|
83
|
-
```
|
84
|
-
|
85
|
-
If you want to store embeddings persistently, set an environment variable
|
86
|
-
`REDIS_URL` or update the `redis.url` setting in your `config.yml` file to
|
87
|
-
connect to a Redis server. Without this setup, embeddings will only be stored
|
88
|
-
in process memory, which is less durable.
|
89
|
-
|
90
|
-
Some settings can be passed as arguments as well, e. g. if you want to choose a
|
91
|
-
specific system prompt:
|
92
|
-
|
93
|
-
```
|
94
|
-
$ ollama_chat -s sherlock.txt
|
95
|
-
Model with architecture llama found.
|
96
|
-
Connecting to llama3.1@http://ollama.local.net:11434 now…
|
97
|
-
Configured system prompt is:
|
98
|
-
You are Sherlock Holmes and the user is your new client, Dr. Watson is also in
|
99
|
-
the room. You will talk and act in the typical manner of Sherlock Holmes do and
|
100
|
-
try to solve the user's case using logic and deduction.
|
101
|
-
|
102
|
-
Type /help to display the chat help.
|
103
|
-
📨 user:
|
104
|
-
Good morning.
|
105
|
-
📨 assistant:
|
106
|
-
Ah, good morning, my dear fellow! It is a pleasure to make your acquaintance. I
|
107
|
-
am Sherlock Holmes, the renowned detective, and this is my trusty sidekick, Dr.
|
108
|
-
Watson. Please, have a seat and tell us about the nature of your visit. What
|
109
|
-
seems to be the problem that has brought you to our humble abode at 221B Baker
|
110
|
-
Street?
|
111
|
-
|
112
|
-
(Watson nods in encouragement as he takes notes)
|
113
|
-
|
114
|
-
Now, pray tell, what is it that puzzles you, my dear client? A missing item,
|
115
|
-
perhaps? Or a mysterious occurrence that requires clarification? The game, as
|
116
|
-
they say, is afoot!
|
117
|
-
```
|
118
|
-
|
119
|
-
This example shows how an image like this can be sent to a vision model for
|
120
|
-
analysis:
|
121
|
-
|
122
|
-

|
123
|
-
|
124
|
-
```
|
125
|
-
$ ollama_chat -m llava-llama3
|
126
|
-
Model with architecture llama found.
|
127
|
-
Connecting to llava-llama3@http://localhost:11434 now…
|
128
|
-
Type /help to display the chat help.
|
129
|
-
📸 user> What's on this image? ./spec/assets/kitten.jpg
|
130
|
-
📨 assistant:
|
131
|
-
The image captures a moment of tranquility featuring a young cat. The cat,
|
132
|
-
adorned with gray and white fur marked by black stripes on its face and legs,
|
133
|
-
is the central figure in this scene. Its eyes, a striking shade of blue, are
|
134
|
-
wide open and directed towards the camera, giving an impression of curiosity or
|
135
|
-
alertness.
|
136
|
-
|
137
|
-
The cat is comfortably nestled on a red blanket, which contrasts vividly with
|
138
|
-
its fur. The blanket, soft and inviting, provides a sense of warmth to the
|
139
|
-
image. In the background, partially obscured by the cat's head, is another
|
140
|
-
blanket of similar red hue. The repetition of the color adds a sense of harmony
|
141
|
-
to the composition.
|
142
|
-
|
143
|
-
The cat's position on the right side of the photo creates an interesting
|
144
|
-
asymmetry with the camera lens, which occupies the left side of the frame. This
|
145
|
-
visual balance enhances the overall composition of the image.
|
29
|
+
## Usage
|
146
30
|
|
147
|
-
|
148
|
-
solely on the cat and its immediate surroundings. The image does not provide
|
149
|
-
any information about the location or setting beyond what has been described.
|
150
|
-
The simplicity of the scene allows the viewer to concentrate on the main
|
151
|
-
subject - the young, blue-eyed cat.
|
152
|
-
```
|
31
|
+
In your own software the library can be used as shown in this example:
|
153
32
|
|
154
|
-
|
33
|
+
```ruby
|
34
|
+
require "ollama"
|
35
|
+
include Ollama
|
155
36
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
/voice( change) toggle voice output or change the voice
|
163
|
-
/list [n] list the last n / all conversation exchanges
|
164
|
-
/clear clear the whole conversation
|
165
|
-
/clobber clear the conversation and collection
|
166
|
-
/pop [n] pop the last n exchanges, defaults to 1
|
167
|
-
/model change the model
|
168
|
-
/system change system prompt (clears conversation)
|
169
|
-
/regenerate the last answer message
|
170
|
-
/collection( clear|change) change (default) collection or clear
|
171
|
-
/info show information for current session
|
172
|
-
/import source import the source's content
|
173
|
-
/summarize [n] source summarize the source's content in n words
|
174
|
-
/embedding toggle embedding paused or not
|
175
|
-
/embed source embed the source's content
|
176
|
-
/web [n] query query web search & return n or 1 results
|
177
|
-
/save filename store conversation messages
|
178
|
-
/load filename load conversation messages
|
179
|
-
/quit to quit
|
180
|
-
/help to view this help
|
37
|
+
ollama = Client.new(base_url: 'http://localhost:11434')
|
38
|
+
messages = Message.new(role: 'user', content: 'Why is the sky blue?')
|
39
|
+
ollama.chat(model: 'llama3.1', stream: true, messages:, &Print) # or
|
40
|
+
print ollama.chat(model: 'llama3.1', stream: true, messages:).lazy.map { |response|
|
41
|
+
response.message.content
|
42
|
+
}
|
181
43
|
```
|
182
44
|
|
183
|
-
|
45
|
+
## Try out things in ollama\_console
|
184
46
|
|
185
47
|
This is an interactive console, that can be used to try the different commands
|
186
48
|
provided by an `Ollama::Client` instance. For example this command generate a
|
@@ -197,21 +59,6 @@ Commands: chat,copy,create,delete,embeddings,generate,help,ps,pull,push,show,tag
|
|
197
59
|
> In a small village nestled between two great palm trees 🌳, there lived a
|
198
60
|
> brave adventurer named Alex 👦. […]
|
199
61
|
|
200
|
-
## Usage
|
201
|
-
|
202
|
-
In your own software the library can be used as shown in this example:
|
203
|
-
|
204
|
-
```ruby
|
205
|
-
require "ollama"
|
206
|
-
include Ollama
|
207
|
-
|
208
|
-
ollama = Client.new(base_url: 'http://localhost:11434')
|
209
|
-
messages = Message.new(role: 'user', content: 'Why is the sky blue?')
|
210
|
-
ollama.chat(model: 'llama3.1', stream: true, messages:, &Print) # or
|
211
|
-
print ollama.chat(model: 'llama3.1', stream: true, messages:).lazy.map { |response|
|
212
|
-
response.message.content
|
213
|
-
}
|
214
|
-
```
|
215
62
|
|
216
63
|
## API
|
217
64
|
|
@@ -463,11 +310,166 @@ If `Ollama::Errors::TimeoutError` is raised, it might help to increase the
|
|
463
310
|
|
464
311
|
For more generic errors an `Ollama::Errors::Error` is raised.
|
465
312
|
|
313
|
+
## Other executables
|
314
|
+
|
315
|
+
### ollama\_chat
|
316
|
+
|
317
|
+
This a chat client, that can be used to connect to an ollama server and enter a
|
318
|
+
chat converstation with a LLM. It can be called with the following arguments:
|
319
|
+
|
320
|
+
```
|
321
|
+
Usage: ollama_chat [OPTIONS]
|
322
|
+
|
323
|
+
-f CONFIG config file to read
|
324
|
+
-u URL the ollama base url, OLLAMA_URL
|
325
|
+
-m MODEL the ollama model to chat with, OLLAMA_CHAT_MODEL
|
326
|
+
-s SYSTEM the system prompt to use as a file, OLLAMA_CHAT_SYSTEM
|
327
|
+
-c CHAT a saved chat conversation to load
|
328
|
+
-C COLLECTION name of the collection used in this conversation
|
329
|
+
-D DOCUMENT load document and add to embeddings collection (multiple)
|
330
|
+
-M use (empty) MemoryCache for this chat session
|
331
|
+
-E disable embeddings for this chat session
|
332
|
+
-V display the current version number and quit
|
333
|
+
-h this help
|
334
|
+
```
|
335
|
+
|
336
|
+
The base URL can be either set by the environment variable `OLLAMA_URL` or it
|
337
|
+
is derived from the environment variable `OLLAMA_HOST`. The default model to
|
338
|
+
connect can be configured in the environment variable `OLLAMA_MODEL`.
|
339
|
+
|
340
|
+
The YAML config file in `$XDG_CONFIG_HOME/ollama_chat/config.yml`, that you can
|
341
|
+
use for more complex settings, it looks like this:
|
342
|
+
|
343
|
+
```
|
344
|
+
---
|
345
|
+
url: <%= ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST') %>
|
346
|
+
model:
|
347
|
+
name: <%= ENV.fetch('OLLAMA_CHAT_MODEL', 'llama3.1') %>
|
348
|
+
options:
|
349
|
+
num_ctx: 8192
|
350
|
+
system: <%= ENV.fetch('OLLAMA_CHAT_SYSTEM', 'null') %>
|
351
|
+
voice: Samantha
|
352
|
+
markdown: true
|
353
|
+
embedding:
|
354
|
+
enabled: true
|
355
|
+
model:
|
356
|
+
name: mxbai-embed-large
|
357
|
+
options: {}
|
358
|
+
collection: <%= ENV.fetch('OLLAMA_CHAT_COLLECTION', 'ollama_chat') %>
|
359
|
+
found_texts_size: 4096
|
360
|
+
splitter:
|
361
|
+
name: RecursiveCharacter
|
362
|
+
chunk_size: 1024
|
363
|
+
cache: Ollama::Documents::RedisCache
|
364
|
+
redis:
|
365
|
+
url: <%= ENV.fetch('REDIS_URL', 'null') %>
|
366
|
+
debug: <%= ENV['OLLAMA_CHAT_DEBUG'].to_i == 1 ? true : false %>
|
367
|
+
```
|
368
|
+
|
369
|
+
If you want to store embeddings persistently, set an environment variable
|
370
|
+
`REDIS_URL` or update the `redis.url` setting in your `config.yml` file to
|
371
|
+
connect to a Redis server. Without this setup, embeddings will only be stored
|
372
|
+
in process memory, which is less durable.
|
373
|
+
|
374
|
+
Some settings can be passed as arguments as well, e. g. if you want to choose a
|
375
|
+
specific system prompt:
|
376
|
+
|
377
|
+
```
|
378
|
+
$ ollama_chat -s sherlock.txt
|
379
|
+
Model with architecture llama found.
|
380
|
+
Connecting to llama3.1@http://ollama.local.net:11434 now…
|
381
|
+
Configured system prompt is:
|
382
|
+
You are Sherlock Holmes and the user is your new client, Dr. Watson is also in
|
383
|
+
the room. You will talk and act in the typical manner of Sherlock Holmes do and
|
384
|
+
try to solve the user's case using logic and deduction.
|
385
|
+
|
386
|
+
Type /help to display the chat help.
|
387
|
+
📨 user:
|
388
|
+
Good morning.
|
389
|
+
📨 assistant:
|
390
|
+
Ah, good morning, my dear fellow! It is a pleasure to make your acquaintance. I
|
391
|
+
am Sherlock Holmes, the renowned detective, and this is my trusty sidekick, Dr.
|
392
|
+
Watson. Please, have a seat and tell us about the nature of your visit. What
|
393
|
+
seems to be the problem that has brought you to our humble abode at 221B Baker
|
394
|
+
Street?
|
395
|
+
|
396
|
+
(Watson nods in encouragement as he takes notes)
|
397
|
+
|
398
|
+
Now, pray tell, what is it that puzzles you, my dear client? A missing item,
|
399
|
+
perhaps? Or a mysterious occurrence that requires clarification? The game, as
|
400
|
+
they say, is afoot!
|
401
|
+
```
|
402
|
+
|
403
|
+
This example shows how an image like this can be sent to a vision model for
|
404
|
+
analysis:
|
405
|
+
|
406
|
+

|
407
|
+
|
408
|
+
```
|
409
|
+
$ ollama_chat -m llava-llama3
|
410
|
+
Model with architecture llama found.
|
411
|
+
Connecting to llava-llama3@http://localhost:11434 now…
|
412
|
+
Type /help to display the chat help.
|
413
|
+
📸 user> What's on this image? ./spec/assets/kitten.jpg
|
414
|
+
📨 assistant:
|
415
|
+
The image captures a moment of tranquility featuring a young cat. The cat,
|
416
|
+
adorned with gray and white fur marked by black stripes on its face and legs,
|
417
|
+
is the central figure in this scene. Its eyes, a striking shade of blue, are
|
418
|
+
wide open and directed towards the camera, giving an impression of curiosity or
|
419
|
+
alertness.
|
420
|
+
|
421
|
+
The cat is comfortably nestled on a red blanket, which contrasts vividly with
|
422
|
+
its fur. The blanket, soft and inviting, provides a sense of warmth to the
|
423
|
+
image. In the background, partially obscured by the cat's head, is another
|
424
|
+
blanket of similar red hue. The repetition of the color adds a sense of harmony
|
425
|
+
to the composition.
|
426
|
+
|
427
|
+
The cat's position on the right side of the photo creates an interesting
|
428
|
+
asymmetry with the camera lens, which occupies the left side of the frame. This
|
429
|
+
visual balance enhances the overall composition of the image.
|
430
|
+
|
431
|
+
There are no discernible texts or other objects in the image. The focus is
|
432
|
+
solely on the cat and its immediate surroundings. The image does not provide
|
433
|
+
any information about the location or setting beyond what has been described.
|
434
|
+
The simplicity of the scene allows the viewer to concentrate on the main
|
435
|
+
subject - the young, blue-eyed cat.
|
436
|
+
```
|
437
|
+
|
438
|
+
The following commands can be given inside the chat, if prefixed by a `/`:
|
439
|
+
|
440
|
+
```
|
441
|
+
/copy to copy last response to clipboard
|
442
|
+
/paste to paste content
|
443
|
+
/markdown toggle markdown output
|
444
|
+
/stream toggle stream output
|
445
|
+
/location toggle location submission
|
446
|
+
/voice( change) toggle voice output or change the voice
|
447
|
+
/list [n] list the last n / all conversation exchanges
|
448
|
+
/clear clear the whole conversation
|
449
|
+
/clobber clear the conversation and collection
|
450
|
+
/pop [n] pop the last n exchanges, defaults to 1
|
451
|
+
/model change the model
|
452
|
+
/system change system prompt (clears conversation)
|
453
|
+
/regenerate the last answer message
|
454
|
+
/collection( clear|change) change (default) collection or clear
|
455
|
+
/info show information for current session
|
456
|
+
/document_policy pick a scan policy for document references
|
457
|
+
/import source import the source's content
|
458
|
+
/summarize [n] source summarize the source's content in n words
|
459
|
+
/embedding toggle embedding paused or not
|
460
|
+
/embed source embed the source's content
|
461
|
+
/web [n] query query web search & return n or 1 results
|
462
|
+
/save filename store conversation messages
|
463
|
+
/load filename load conversation messages
|
464
|
+
/quit to quit
|
465
|
+
/help to view this help
|
466
|
+
```
|
467
|
+
|
466
468
|
## Download
|
467
469
|
|
468
470
|
The homepage of this library is located at
|
469
471
|
|
470
|
-
* https://github.com/flori/ollama
|
472
|
+
* https://github.com/flori/ollama-ruby
|
471
473
|
|
472
474
|
## Author
|
473
475
|
|