ollama-ruby 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +27 -0
- data/README.md +14 -13
- data/Rakefile +3 -1
- data/bin/ollama_chat +108 -45
- data/bin/ollama_cli +68 -0
- data/bin/ollama_console +7 -2
- data/lib/ollama/documents/memory_cache.rb +4 -2
- data/lib/ollama/documents/redis_cache.rb +4 -3
- data/lib/ollama/documents.rb +30 -5
- data/lib/ollama/utils/file_argument.rb +16 -0
- data/lib/ollama/utils/tags.rb +4 -0
- data/lib/ollama/utils/width.rb +13 -0
- data/lib/ollama/version.rb +1 -1
- data/lib/ollama.rb +1 -0
- data/ollama-ruby.gemspec +8 -7
- data/spec/ollama/documents/redis_cache_spec.rb +8 -0
- data/spec/ollama/documents_spec.rb +42 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 510c31683b2251118a7c3b469620400016b29fd1ea6f17cc86e4f99f62ecea2f
|
4
|
+
data.tar.gz: a00c4275e42002a01a99f874a855386c83e502551360c1f4146eee0b74f2fd08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17e50d40e4c24b56b5c2923f0b73f3e4294587b61a302fbaf4cd8f891e879eb435541e1f7e195a4f88352fd99aa80ff44c8577b8c195d7ef31af1c33229018b7
|
7
|
+
data.tar.gz: a18bcef82e9481b75fee4a4c88598a7a374c48f841e9870b39174c0d1f5f235f1173bdbff939182481d431e4e9c8c85501be4f5ef917ca02865692cfc39fde5a
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2024-09-05 v0.3.0
|
4
|
+
|
5
|
+
* **New Features**
|
6
|
+
* Created new file `ollama_cli` with Ollama CLI functionality.
|
7
|
+
* Added executable `ollama_cli` to s.executables in ollama-ruby.gemspec.
|
8
|
+
* Added `find_where` method in `documents.rb` to filter records by text size
|
9
|
+
and count.
|
10
|
+
* Added test for `find_where` method in `documents_spec.rb`.
|
11
|
+
* Features for `ollama_chat`
|
12
|
+
* Added `found_texts_count` option to `OllamaChatConfig`.
|
13
|
+
* Implemented `parse_rss` method for RSS feeds and `parse_atom` method
|
14
|
+
for Atom feeds.
|
15
|
+
* Added links to titles in RSS feed item summaries and Atom feed item
|
16
|
+
summaries.
|
17
|
+
* Updated `parse_source` method to handle different content types,
|
18
|
+
including HTML, XML, and RSS/Atom feeds.
|
19
|
+
* Added `/web [n] query` command to search web and return n or 1 results
|
20
|
+
in chat interface.
|
21
|
+
* **Improvements**
|
22
|
+
* Improved validation for system prompts
|
23
|
+
* Extracted file argument handling into a separate module and method
|
24
|
+
* Added default value for config or model system prompt
|
25
|
+
* Improved input validation for `system_prompt` path
|
26
|
+
* Updated collection clearing logic to accept optional tags parameter
|
27
|
+
* Updated `Tags` class to overload `to_a` method for converting to array of
|
28
|
+
strings
|
29
|
+
|
3
30
|
## 2024-09-03 v0.2.0
|
4
31
|
|
5
32
|
### Changes
|
data/README.md
CHANGED
@@ -152,19 +152,20 @@ subject - the young, blue-eyed cat.
|
|
152
152
|
The following commands can be given inside the chat, if prefixed by a `/`:
|
153
153
|
|
154
154
|
```
|
155
|
-
/paste
|
156
|
-
/markdown
|
157
|
-
/list
|
158
|
-
/clear
|
159
|
-
/pop [n]
|
160
|
-
/model
|
161
|
-
/regenerate
|
162
|
-
/collection clear|stats|change|new clear or show stats of current collection
|
163
|
-
/summarize source
|
164
|
-
/
|
165
|
-
/
|
166
|
-
/
|
167
|
-
/
|
155
|
+
/paste to paste content
|
156
|
+
/markdown toggle markdown output
|
157
|
+
/list list the messages of the conversation
|
158
|
+
/clear clear the conversation messages
|
159
|
+
/pop [n] pop the last n exchanges, defaults to 1
|
160
|
+
/model change the model
|
161
|
+
/regenerate the last answer message
|
162
|
+
/collection clear [tag]|stats|change|new clear or show stats of current collection
|
163
|
+
/summarize source summarize the URL/file source's content
|
164
|
+
/web [n] query query web search & return n or 1 results
|
165
|
+
/save filename store conversation messages
|
166
|
+
/load filename load conversation messages
|
167
|
+
/quit to quit
|
168
|
+
/help to view this help
|
168
169
|
```
|
169
170
|
|
170
171
|
### ollama\_console
|
data/Rakefile
CHANGED
@@ -18,7 +18,8 @@ GemHadar do
|
|
18
18
|
'.utilsrc', '.rspec', *Dir.glob('.github/**/*', File::FNM_DOTMATCH)
|
19
19
|
readme 'README.md'
|
20
20
|
|
21
|
-
executables << 'ollama_console' << 'ollama_chat' <<
|
21
|
+
executables << 'ollama_console' << 'ollama_chat' <<
|
22
|
+
'ollama_update' << 'ollama_cli'
|
22
23
|
|
23
24
|
required_ruby_version '~> 3.1'
|
24
25
|
|
@@ -36,6 +37,7 @@ GemHadar do
|
|
36
37
|
dependency 'complex_config', '~> 0.20'
|
37
38
|
dependency 'search_ui', '~> 0.0'
|
38
39
|
dependency 'amatch', '~> 0.4.1'
|
40
|
+
dependency 'pdf-reader', '~> 2.0'
|
39
41
|
development_dependency 'all_images', '~> 0.4'
|
40
42
|
development_dependency 'rspec', '~> 3.2'
|
41
43
|
development_dependency 'utils'
|
data/bin/ollama_chat
CHANGED
@@ -12,6 +12,8 @@ require 'complex_config'
|
|
12
12
|
require 'fileutils'
|
13
13
|
require 'uri'
|
14
14
|
require 'nokogiri'
|
15
|
+
require 'rss'
|
16
|
+
require 'pdf/reader'
|
15
17
|
|
16
18
|
class OllamaChatConfig
|
17
19
|
include ComplexConfig
|
@@ -36,6 +38,7 @@ class OllamaChatConfig
|
|
36
38
|
prompt: 'Represent this sentence for searching relevant passages: %s'
|
37
39
|
collection: <%= ENV.fetch('OLLAMA_CHAT_COLLECTION', 'ollama_chat') %>
|
38
40
|
found_texts_size: 4096
|
41
|
+
found_texts_count: null
|
39
42
|
splitter:
|
40
43
|
name: RecursiveCharacter
|
41
44
|
chunk_size: 1024
|
@@ -153,7 +156,8 @@ end
|
|
153
156
|
|
154
157
|
def pull_model_unless_present(model, options, retried = false)
|
155
158
|
ollama.show(name: model) { |response|
|
156
|
-
puts "Model #{bold{model}} with architecture
|
159
|
+
puts "Model #{bold{model}} with architecture "\
|
160
|
+
"#{response.model_info['general.architecture']} found."
|
157
161
|
if system = response.system
|
158
162
|
puts "Configured model system prompt is:\n#{italic { system }}"
|
159
163
|
return system
|
@@ -226,17 +230,77 @@ def list_conversation(messages, markdown)
|
|
226
230
|
end
|
227
231
|
end
|
228
232
|
|
233
|
+
def reverse_markdown(html)
|
234
|
+
ReverseMarkdown.convert(
|
235
|
+
html,
|
236
|
+
unknown_tags: :bypass,
|
237
|
+
github_flavored: true,
|
238
|
+
tag_border: ''
|
239
|
+
)
|
240
|
+
end
|
241
|
+
|
242
|
+
def parse_rss(source_io)
|
243
|
+
feed = RSS::Parser.parse(source_io, false, false)
|
244
|
+
title = <<~end
|
245
|
+
# #{feed&.channel&.title}
|
246
|
+
|
247
|
+
end
|
248
|
+
feed.items.inject(title) do |text, item|
|
249
|
+
text << <<~end
|
250
|
+
## [#{item&.title}](#{item&.link})
|
251
|
+
|
252
|
+
updated on #{item&.pubDate}
|
253
|
+
|
254
|
+
#{reverse_markdown(item&.description)}
|
255
|
+
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def parse_atom(source_io)
|
261
|
+
feed = RSS::Parser.parse(source_io, false, false)
|
262
|
+
title = <<~end
|
263
|
+
# #{feed.title.content}
|
264
|
+
|
265
|
+
end
|
266
|
+
feed.items.inject(title) do |text, item|
|
267
|
+
text << <<~end
|
268
|
+
## [#{item&.title&.content}](#{item&.link&.href})
|
269
|
+
|
270
|
+
updated on #{item&.updated&.content}
|
271
|
+
|
272
|
+
#{reverse_markdown(item&.content&.content)}
|
273
|
+
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
229
278
|
def parse_source(source_io)
|
230
|
-
case source_io&.content_type
|
231
|
-
when 'html'
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
279
|
+
case source_io&.content_type
|
280
|
+
when 'text/html'
|
281
|
+
reverse_markdown(source_io.read)
|
282
|
+
when 'text/xml'
|
283
|
+
if source_io.readline =~ %r(^\s*<rss\s)
|
284
|
+
source_io.rewind
|
285
|
+
return parse_rss(source_io)
|
286
|
+
end
|
287
|
+
source_io.rewind
|
288
|
+
source_io.read
|
289
|
+
when %r(\Atext/)
|
239
290
|
source_io.read
|
291
|
+
when 'application/rss+xml'
|
292
|
+
parse_rss(source_io)
|
293
|
+
when 'application/atom+xml'
|
294
|
+
parse_atom(source_io)
|
295
|
+
when 'application/json'
|
296
|
+
source_io.read
|
297
|
+
when 'application/pdf'
|
298
|
+
reader = PDF::Reader.new(source_io)
|
299
|
+
result = +''
|
300
|
+
reader.pages.each do |page|
|
301
|
+
result << page.text
|
302
|
+
end
|
303
|
+
result
|
240
304
|
else
|
241
305
|
STDERR.puts "Cannot import #{source_io&.content_type} document."
|
242
306
|
return
|
@@ -327,7 +391,7 @@ def parse_content(content, images)
|
|
327
391
|
case source_io&.content_type&.media_type
|
328
392
|
when 'image'
|
329
393
|
add_image(images, source_io, source)
|
330
|
-
when 'text'
|
394
|
+
when 'text', 'application'
|
331
395
|
import_document(source_io, source)
|
332
396
|
else
|
333
397
|
STDERR.puts(
|
@@ -391,19 +455,20 @@ end
|
|
391
455
|
|
392
456
|
def display_chat_help
|
393
457
|
puts <<~end
|
394
|
-
/paste
|
395
|
-
/markdown
|
396
|
-
/list
|
397
|
-
/clear
|
398
|
-
/pop [n]
|
399
|
-
/model
|
400
|
-
/regenerate
|
401
|
-
/collection clear|stats|change|new clear or show stats of current collection
|
402
|
-
/summarize source
|
403
|
-
/
|
404
|
-
/
|
405
|
-
/
|
406
|
-
/
|
458
|
+
/paste to paste content
|
459
|
+
/markdown toggle markdown output
|
460
|
+
/list list the messages of the conversation
|
461
|
+
/clear clear the conversation messages
|
462
|
+
/pop [n] pop the last n exchanges, defaults to 1
|
463
|
+
/model change the model
|
464
|
+
/regenerate the last answer message
|
465
|
+
/collection clear [tag]|stats|change|new clear or show stats of current collection
|
466
|
+
/summarize source summarize the URL/file source's content
|
467
|
+
/web [n] query query web search & return n or 1 results
|
468
|
+
/save filename store conversation messages
|
469
|
+
/load filename load conversation messages
|
470
|
+
/quit to quit
|
471
|
+
/help to view this help
|
407
472
|
end
|
408
473
|
end
|
409
474
|
|
@@ -497,23 +562,16 @@ markdown = set_markdown($config.markdown)
|
|
497
562
|
if opts[?c]
|
498
563
|
messages.concat load_conversation(opts[?c])
|
499
564
|
else
|
500
|
-
system =
|
501
|
-
|
502
|
-
system = File.read(system_prompt_file)
|
503
|
-
end
|
504
|
-
system ||= $config.system
|
505
|
-
|
506
|
-
if system
|
565
|
+
if system = Ollama::Utils::FileArgument.
|
566
|
+
get_file_argument(opts[?s], default: $config.system? || model_system)
|
507
567
|
messages << Message.new(role: 'system', content: system)
|
508
568
|
puts "Configured system prompt is:\n#{italic { system }}"
|
509
|
-
elsif model_system.present?
|
510
|
-
puts "Using model system prompt."
|
511
569
|
end
|
512
570
|
end
|
513
571
|
|
514
572
|
puts "\nType /help to display the chat help."
|
515
573
|
|
516
|
-
images
|
574
|
+
images = []
|
517
575
|
loop do
|
518
576
|
parse_content = true
|
519
577
|
input_prompt = bold { color(172) { message_type(images) + " user" } } + bold { "> " }
|
@@ -536,11 +594,18 @@ loop do
|
|
536
594
|
messages.clear
|
537
595
|
puts "Cleared messages."
|
538
596
|
next
|
539
|
-
when %r(^/collection
|
540
|
-
|
597
|
+
when %r(^/collection\s+(clear|stats|change|new)(?:\s+(.+))?$)
|
598
|
+
command, arg = $1, $2
|
599
|
+
case command
|
541
600
|
when 'clear'
|
542
|
-
|
543
|
-
|
601
|
+
tags = arg.present? ? arg.sub(/\A#*/, '') : nil
|
602
|
+
if tags
|
603
|
+
$documents.clear(tags:)
|
604
|
+
puts "Cleared tag ##{tags} from collection #{bold{collection}}."
|
605
|
+
else
|
606
|
+
$documents.clear
|
607
|
+
puts "Cleared collection #{bold{collection}}."
|
608
|
+
end
|
544
609
|
when 'stats'
|
545
610
|
collection_stats
|
546
611
|
when 'change'
|
@@ -571,7 +636,7 @@ loop do
|
|
571
636
|
when %r(^/summarize\s+(.+))
|
572
637
|
parse_content = false
|
573
638
|
content = summarize($1) or next
|
574
|
-
when %r(^/web\s+(?:(\d+)\s+)(.+)$)
|
639
|
+
when %r(^/web\s+(?:(\d+)\s+)?(.+)$)
|
575
640
|
parse_content = true
|
576
641
|
urls = search_web($2, $1.to_i)
|
577
642
|
content = <<~end
|
@@ -602,15 +667,13 @@ loop do
|
|
602
667
|
end
|
603
668
|
|
604
669
|
if $config.embedding.enabled && content
|
605
|
-
records = $documents.
|
670
|
+
records = $documents.find_where(
|
606
671
|
content.downcase,
|
607
672
|
tags:,
|
608
|
-
prompt:
|
673
|
+
prompt: $config.embedding.model.prompt?,
|
674
|
+
text_size: $config.embedding.found_texts_size?,
|
675
|
+
text_count: $config.embedding.found_texts_count?,
|
609
676
|
)
|
610
|
-
s, found_texts_size = 0, $config.embedding.found_texts_size
|
611
|
-
records = records.take_while {
|
612
|
-
(s += _1.text.size) <= found_texts_size
|
613
|
-
}
|
614
677
|
found_texts = records.map(&:text)
|
615
678
|
unless found_texts.empty?
|
616
679
|
content += "\nConsider these chunks for your answer:\n"\
|
data/bin/ollama_cli
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'ollama'
|
4
|
+
include Ollama
|
5
|
+
include Ollama::Utils::FileArgument
|
6
|
+
require 'tins'
|
7
|
+
include Tins::GO
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
def usage
|
11
|
+
puts <<~end
|
12
|
+
#{File.basename($0)} [OPTIONS]
|
13
|
+
|
14
|
+
-u URL the ollama base url, OLLAMA_URL
|
15
|
+
-m MODEL the ollama model to chat with, OLLAMA_MODEL
|
16
|
+
-M OPTIONS the ollama model options to use, OLLAMA_MODEL_OPTIONS
|
17
|
+
-s SYSTEM the system prompt to use as a file, OLLAMA_SYSTEM
|
18
|
+
-p PROMPT the user prompt to use as a file, OLLAMA_PROMPT
|
19
|
+
-H HANDLER the handler to use for the response, defaults to Print
|
20
|
+
-S use streaming for generation
|
21
|
+
-h this help
|
22
|
+
|
23
|
+
end
|
24
|
+
exit 0
|
25
|
+
end
|
26
|
+
|
27
|
+
opts = go 'u:m:M:s:p:H:Sh', defaults: { ?H => 'Print', ?M => '{}' }
|
28
|
+
|
29
|
+
opts[?h] and usage
|
30
|
+
|
31
|
+
base_url = opts[?u] || ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
|
32
|
+
model = opts[?m] || ENV.fetch('OLLAMA_MODEL', 'llama3.1')
|
33
|
+
options = Ollama::Options.from_hash(JSON(
|
34
|
+
get_file_argument(opts[?M], default: ENV['OLLAMA_MODEL_OPTIONS'])
|
35
|
+
))
|
36
|
+
system = get_file_argument(opts[?s], default: ENV['OLLAMA_SYSTEM'])
|
37
|
+
prompt = get_file_argument(opts[?p], default: ENV['OLLAMA_PROMPT'])
|
38
|
+
|
39
|
+
if prompt.nil?
|
40
|
+
prompt = STDIN.read
|
41
|
+
elsif c = prompt.scan('%s').size
|
42
|
+
case c
|
43
|
+
when 0
|
44
|
+
when 1
|
45
|
+
prompt = prompt % STDIN.read
|
46
|
+
else
|
47
|
+
STDERR.puts "Found more than one plaeceholder %s. => Ignoring."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if ENV['DEBUG'].to_i == 1
|
52
|
+
puts <<~EOT
|
53
|
+
base_url = #{base_url.inspect}
|
54
|
+
model = #{model.inspect}
|
55
|
+
system = #{system.inspect}
|
56
|
+
prompt = #{prompt.inspect}
|
57
|
+
options = #{options.to_json}
|
58
|
+
EOT
|
59
|
+
end
|
60
|
+
|
61
|
+
Client.new(base_url:, read_timeout: 120).generate(
|
62
|
+
model:,
|
63
|
+
system:,
|
64
|
+
prompt:,
|
65
|
+
options:,
|
66
|
+
stream: !!opts[?S],
|
67
|
+
&Object.const_get(opts[?H])
|
68
|
+
)
|
data/bin/ollama_console
CHANGED
@@ -5,8 +5,13 @@ include Ollama
|
|
5
5
|
require 'irb'
|
6
6
|
require 'irb/history'
|
7
7
|
|
8
|
-
base_url
|
9
|
-
|
8
|
+
def base_url
|
9
|
+
ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
|
10
|
+
end
|
11
|
+
|
12
|
+
def ollama
|
13
|
+
$ollama ||= Client.new(base_url:)
|
14
|
+
end
|
10
15
|
IRB.setup nil
|
11
16
|
IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
|
12
17
|
IRB.conf[:HISTORY_FILE] = File.join(ENV.fetch('HOME'), '.ollama_console-history')
|
@@ -13,7 +13,10 @@ class Ollama::Documents::RedisCache
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def [](key)
|
16
|
-
|
16
|
+
value = redis.get(pre(key))
|
17
|
+
unless value.nil?
|
18
|
+
JSON(value, object_class: Ollama::Documents::Record)
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
22
|
def []=(key, value)
|
@@ -45,8 +48,6 @@ class Ollama::Documents::RedisCache
|
|
45
48
|
end
|
46
49
|
include Enumerable
|
47
50
|
|
48
|
-
private
|
49
|
-
|
50
51
|
def pre(key)
|
51
52
|
[ @prefix, key ].join
|
52
53
|
end
|
data/lib/ollama/documents.rb
CHANGED
@@ -12,6 +12,7 @@ require 'ollama/documents/splitters/semantic'
|
|
12
12
|
|
13
13
|
class Ollama::Documents
|
14
14
|
include Ollama::Utils::Math
|
15
|
+
include Ollama::Utils::Width
|
15
16
|
|
16
17
|
class Record < JSON::GenericObject
|
17
18
|
def to_s
|
@@ -42,7 +43,7 @@ class Ollama::Documents
|
|
42
43
|
def add(inputs, batch_size: 10, source: nil, tags: [])
|
43
44
|
inputs = Array(inputs)
|
44
45
|
tags = Ollama::Utils::Tags.new(tags)
|
45
|
-
source and tags.add File.basename(source)
|
46
|
+
source and tags.add File.basename(source).gsub(/\?.*/, '')
|
46
47
|
inputs.map! { |i|
|
47
48
|
text = i.respond_to?(:read) ? i.read : i.to_s
|
48
49
|
text
|
@@ -51,7 +52,7 @@ class Ollama::Documents
|
|
51
52
|
inputs.empty? and return self
|
52
53
|
batches = inputs.each_slice(batch_size).
|
53
54
|
with_infobar(
|
54
|
-
label: "Add #{tags}",
|
55
|
+
label: "Add #{truncate(tags.to_s, percentage: 25)}",
|
55
56
|
total: inputs.size
|
56
57
|
)
|
57
58
|
batches.each do |batch|
|
@@ -87,8 +88,18 @@ class Ollama::Documents
|
|
87
88
|
@cache.size
|
88
89
|
end
|
89
90
|
|
90
|
-
def clear
|
91
|
-
|
91
|
+
def clear(tags: nil)
|
92
|
+
if tags
|
93
|
+
tags = Ollama::Utils::Tags.new(Array(tags)).to_a
|
94
|
+
@cache.each do |key, record|
|
95
|
+
if (tags & record.tags).size >= 1
|
96
|
+
@cache.delete(@cache.unpre(key))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
else
|
100
|
+
@cache.clear
|
101
|
+
end
|
102
|
+
self
|
92
103
|
end
|
93
104
|
|
94
105
|
def find(string, tags: nil, prompt: nil)
|
@@ -96,7 +107,7 @@ class Ollama::Documents
|
|
96
107
|
needle_norm = norm(needle)
|
97
108
|
records = @cache
|
98
109
|
if tags
|
99
|
-
tags = Ollama::Utils::Tags.new(tags)
|
110
|
+
tags = Ollama::Utils::Tags.new(tags).to_a
|
100
111
|
records = records.select { |_key, record| (tags & record.tags).size >= 1 }
|
101
112
|
end
|
102
113
|
records = records.sort_by { |key, record|
|
@@ -111,6 +122,20 @@ class Ollama::Documents
|
|
111
122
|
records.transpose.last&.reverse.to_a
|
112
123
|
end
|
113
124
|
|
125
|
+
def find_where(string, text_size: nil, text_count: nil, **opts)
|
126
|
+
records = find(string, **opts)
|
127
|
+
size, count = 0, 0
|
128
|
+
records.take_while do |record|
|
129
|
+
if text_size and (size += record.text.size) > text_size
|
130
|
+
next false
|
131
|
+
end
|
132
|
+
if text_count and (count += 1) > text_count
|
133
|
+
next false
|
134
|
+
end
|
135
|
+
true
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
114
139
|
def collections
|
115
140
|
case @cache
|
116
141
|
when MemoryCache
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ollama::Utils::FileArgument
|
2
|
+
module_function
|
3
|
+
|
4
|
+
def get_file_argument(prompt, default: nil)
|
5
|
+
if prompt.present? && prompt.size < 2 ** 15 &&
|
6
|
+
File.basename(prompt).size < 2 ** 8 &&
|
7
|
+
File.exist?(prompt)
|
8
|
+
then
|
9
|
+
File.read(prompt)
|
10
|
+
elsif prompt.present?
|
11
|
+
prompt
|
12
|
+
else
|
13
|
+
default
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ollama/utils/tags.rb
CHANGED
data/lib/ollama/utils/width.rb
CHANGED
@@ -19,4 +19,17 @@ module Ollama::Utils::Width
|
|
19
19
|
end
|
20
20
|
end * ?\n
|
21
21
|
end
|
22
|
+
|
23
|
+
def truncate(text, percentage: nil, length: nil, ellipsis: ?…)
|
24
|
+
percentage.nil? ^ length.nil? or
|
25
|
+
raise ArgumentError, "either pass percentage or length argument"
|
26
|
+
percentage and length ||= width(percentage:)
|
27
|
+
if length < 1
|
28
|
+
+''
|
29
|
+
elsif text.size > length
|
30
|
+
text[0, length - 1] + ?…
|
31
|
+
else
|
32
|
+
text
|
33
|
+
end
|
34
|
+
end
|
22
35
|
end
|
data/lib/ollama/version.rb
CHANGED
data/lib/ollama.rb
CHANGED
data/ollama-ruby.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: ollama-ruby 0.
|
2
|
+
# stub: ollama-ruby 0.3.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "ollama-ruby".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.3.0".freeze
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2024-09-
|
11
|
+
s.date = "2024-09-06"
|
12
12
|
s.description = "Library that allows interacting with the Ollama API".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
|
-
s.executables = ["ollama_console".freeze, "ollama_chat".freeze, "ollama_update".freeze]
|
15
|
-
s.extra_rdoc_files = ["README.md".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/memory_cache.rb".freeze, "lib/ollama/documents/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze]
|
16
|
-
s.files = [".envrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_console".freeze, "bin/ollama_update".freeze, "config/redis.conf".freeze, "docker-compose.yml".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/memory_cache.rb".freeze, "lib/ollama/documents/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze, "ollama-ruby.gemspec".freeze, "spec/assets/embeddings.json".freeze, "spec/assets/kitten.jpg".freeze, "spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
|
14
|
+
s.executables = ["ollama_console".freeze, "ollama_chat".freeze, "ollama_update".freeze, "ollama_cli".freeze]
|
15
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/memory_cache.rb".freeze, "lib/ollama/documents/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/file_argument.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze]
|
16
|
+
s.files = [".envrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_cli".freeze, "bin/ollama_console".freeze, "bin/ollama_update".freeze, "config/redis.conf".freeze, "docker-compose.yml".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/memory_cache.rb".freeze, "lib/ollama/documents/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/file_argument.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze, "ollama-ruby.gemspec".freeze, "spec/assets/embeddings.json".freeze, "spec/assets/kitten.jpg".freeze, "spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
|
17
17
|
s.homepage = "https://github.com/flori/ollama-ruby".freeze
|
18
18
|
s.licenses = ["MIT".freeze]
|
19
19
|
s.rdoc_options = ["--title".freeze, "Ollama-ruby - Interacting with the Ollama API".freeze, "--main".freeze, "README.md".freeze]
|
20
20
|
s.required_ruby_version = Gem::Requirement.new("~> 3.1".freeze)
|
21
|
-
s.rubygems_version = "3.5.
|
21
|
+
s.rubygems_version = "3.5.18".freeze
|
22
22
|
s.summary = "Interacting with the Ollama API".freeze
|
23
23
|
s.test_files = ["spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
24
24
|
|
@@ -43,4 +43,5 @@ Gem::Specification.new do |s|
|
|
43
43
|
s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.20".freeze])
|
44
44
|
s.add_runtime_dependency(%q<search_ui>.freeze, ["~> 0.0".freeze])
|
45
45
|
s.add_runtime_dependency(%q<amatch>.freeze, ["~> 0.4.1".freeze])
|
46
|
+
s.add_runtime_dependency(%q<pdf-reader>.freeze, ["~> 2.0".freeze])
|
46
47
|
end
|
@@ -74,5 +74,13 @@ RSpec.describe Ollama::Documents::RedisCache do
|
|
74
74
|
expect(redis).to receive(:scan_each).with(match: 'test-*')
|
75
75
|
redis_cache.to_a
|
76
76
|
end
|
77
|
+
|
78
|
+
it 'can compute prefix with pre' do
|
79
|
+
expect(redis_cache.pre('foo')).to eq 'test-foo'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'can remove prefix with unpre' do
|
83
|
+
expect(redis_cache.unpre('test-foo')).to eq 'foo'
|
84
|
+
end
|
77
85
|
end
|
78
86
|
end
|
@@ -76,6 +76,34 @@ RSpec.describe Ollama::Documents do
|
|
76
76
|
expect(records[0].to_s).to eq '#<Ollama::Documents::Record "foo" #test 1.0>'
|
77
77
|
end
|
78
78
|
|
79
|
+
it 'can find strings conditionally' do
|
80
|
+
allow(ollama).to receive(:embed).
|
81
|
+
with(model:, input: [ 'foobar' ], options: nil).
|
82
|
+
and_return(double(embeddings: [ [ 0.01 ] ]))
|
83
|
+
allow(ollama).to receive(:embed).
|
84
|
+
with(model:, input: [ 'foo' ], options: nil).
|
85
|
+
and_return(double(embeddings: [ [ 0.1 ] ]))
|
86
|
+
expect(documents << 'foobar').to eq documents
|
87
|
+
expect(documents << 'foo').to eq documents
|
88
|
+
expect(ollama).to receive(:embed).at_least(:once).
|
89
|
+
with(model:, input: 'foo', options: nil).
|
90
|
+
and_return(double(embeddings: [ [ 0.1 ] ]))
|
91
|
+
records = documents.find_where('foo', text_count: 1)
|
92
|
+
expect(records).to eq [
|
93
|
+
Ollama::Documents::Record[text: 'foo', embedding: [ 0.1 ], similarity: 1.0 ],
|
94
|
+
]
|
95
|
+
records = documents.find_where('foo', text_size: 3)
|
96
|
+
expect(records).to eq [
|
97
|
+
Ollama::Documents::Record[text: 'foo', embedding: [ 0.1 ], similarity: 1.0 ],
|
98
|
+
]
|
99
|
+
records = documents.find_where('foo')
|
100
|
+
expect(records).to eq [
|
101
|
+
Ollama::Documents::Record[text: 'foo', embedding: [ 0.1 ], similarity: 1.0 ],
|
102
|
+
Ollama::Documents::Record[text: 'foobar', embedding: [ 0.1 ], similarity: 1.0 ],
|
103
|
+
]
|
104
|
+
end
|
105
|
+
|
106
|
+
|
79
107
|
context 'it uses cache' do
|
80
108
|
before do
|
81
109
|
allow(ollama).to receive(:embed).
|
@@ -103,6 +131,20 @@ RSpec.describe Ollama::Documents do
|
|
103
131
|
}.to change { documents.size }.from(1).to(0)
|
104
132
|
end
|
105
133
|
|
134
|
+
it 'can clear texts with tags' do
|
135
|
+
allow(ollama).to receive(:embed).
|
136
|
+
with(model:, input: %w[ bar ], options: nil).
|
137
|
+
and_return(double(embeddings: [ [ 0.1 ] ]))
|
138
|
+
expect(documents.add('foo', tags: %i[ test ])).to eq documents
|
139
|
+
expect(documents.add('bar', tags: %i[ test2 ])).to eq documents
|
140
|
+
expect {
|
141
|
+
documents.clear tags: 'test'
|
142
|
+
}.to change { documents.size }.from(2).to(1)
|
143
|
+
expect {
|
144
|
+
documents.clear tags: :test2
|
145
|
+
}.to change { documents.size }.from(1).to(0)
|
146
|
+
end
|
147
|
+
|
106
148
|
it 'returns collections' do
|
107
149
|
expect(documents.collections).to eq [ :default ]
|
108
150
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ollama-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -276,12 +276,27 @@ dependencies:
|
|
276
276
|
- - "~>"
|
277
277
|
- !ruby/object:Gem::Version
|
278
278
|
version: 0.4.1
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: pdf-reader
|
281
|
+
requirement: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - "~>"
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '2.0'
|
286
|
+
type: :runtime
|
287
|
+
prerelease: false
|
288
|
+
version_requirements: !ruby/object:Gem::Requirement
|
289
|
+
requirements:
|
290
|
+
- - "~>"
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: '2.0'
|
279
293
|
description: Library that allows interacting with the Ollama API
|
280
294
|
email: flori@ping.de
|
281
295
|
executables:
|
282
296
|
- ollama_console
|
283
297
|
- ollama_chat
|
284
298
|
- ollama_update
|
299
|
+
- ollama_cli
|
285
300
|
extensions: []
|
286
301
|
extra_rdoc_files:
|
287
302
|
- README.md
|
@@ -331,6 +346,7 @@ extra_rdoc_files:
|
|
331
346
|
- lib/ollama/utils/chooser.rb
|
332
347
|
- lib/ollama/utils/colorize_texts.rb
|
333
348
|
- lib/ollama/utils/fetcher.rb
|
349
|
+
- lib/ollama/utils/file_argument.rb
|
334
350
|
- lib/ollama/utils/math.rb
|
335
351
|
- lib/ollama/utils/tags.rb
|
336
352
|
- lib/ollama/utils/width.rb
|
@@ -343,6 +359,7 @@ files:
|
|
343
359
|
- README.md
|
344
360
|
- Rakefile
|
345
361
|
- bin/ollama_chat
|
362
|
+
- bin/ollama_cli
|
346
363
|
- bin/ollama_console
|
347
364
|
- bin/ollama_update
|
348
365
|
- config/redis.conf
|
@@ -393,6 +410,7 @@ files:
|
|
393
410
|
- lib/ollama/utils/chooser.rb
|
394
411
|
- lib/ollama/utils/colorize_texts.rb
|
395
412
|
- lib/ollama/utils/fetcher.rb
|
413
|
+
- lib/ollama/utils/file_argument.rb
|
396
414
|
- lib/ollama/utils/math.rb
|
397
415
|
- lib/ollama/utils/tags.rb
|
398
416
|
- lib/ollama/utils/width.rb
|
@@ -460,7 +478,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
460
478
|
- !ruby/object:Gem::Version
|
461
479
|
version: '0'
|
462
480
|
requirements: []
|
463
|
-
rubygems_version: 3.5.
|
481
|
+
rubygems_version: 3.5.18
|
464
482
|
signing_key:
|
465
483
|
specification_version: 4
|
466
484
|
summary: Interacting with the Ollama API
|