ollama-ruby 0.9.1 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3976b4254bbedc3655a6a737000903217eff8b4b941971eb6ae4fda630ba40c3
4
- data.tar.gz: 29187dded0f2748e8e684648ab374d027aaff18a6f85ede48df78dc34b705645
3
+ metadata.gz: fda5b55631024d2e7367400032462d87244daaa44dac2835aae7f7dad3f3f885
4
+ data.tar.gz: b085138d8de3daa61cc5f7f2cdfc17ff14c7a17737675452ce8e9ea5be002113
5
5
  SHA512:
6
- metadata.gz: 69ad552c73c297d23db6a65681008c79329de3d4a02a07f28b027a94820f9505488870e4bce6b43c1ae6a6fb64c6107ce4cc3d28b307f07573987464e6eaed84
7
- data.tar.gz: 79dd0a71d48726900ed7df4508f2031191f00f15b3713cc562aa29112c4942e72836c5d487c8883b173dc760d8e815461b66e3c4b0fbdccd1226e6019af2419a
6
+ metadata.gz: dc3c61c2f9484d5d2a5e8b5fc97c357139d8326700ea83e6b61984c7b58d62fe2377a5c288a65a6aad7c98dcf4b3bb341772f0ff4fd9bf3b3bf9b23061040eb1
7
+ data.tar.gz: 4c14196cea496a866f50bd1e414620bc7441a1923a729cffe52a42ef8cc77b16982b4be2bc644b09601900d5b403b117dd3dfe462dd5d4c6e1f324699d7396d8
data/CHANGES.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changes
2
2
 
3
+ ## 2024-10-21 v0.9.3
4
+
5
+ * Update dependencies and date:
6
+ + dependency `complex_config` updated to `~> 0.22` and `>= 0.22.2`
7
+ + Date changed in ollama-ruby.gemspec from "2024-10-20" to "2024-10-21"
8
+
9
+ ## 2024-10-20 v0.9.2
10
+
11
+ * Added SourceParsing module and update `parse_source` method to use it:
12
+ + Added `SourceParsing` module with `parse_source` method that handles
13
+ different file types (e.g. HTML, XML, CSV, RSS)
14
+ + Added `parse_csv` method to `SourceParsing` module
15
+ + Updated `parse_source` method in main file to include new functionality
16
+ * Add colorize texts spec for Ollama::Utils::ColorizeTexts to test its
17
+ functionality.
18
+ * Added test for expected output of `documents.tags`
19
+ * Add test for empty Ollama options:
20
+ + Added test case for `Ollama::Options` being empty
21
+ * Display (embedding) model options in info output
22
+ * Only show `collection_stats` if embedding is performed
23
+ * Add empty? method to DTO class:
24
+ + Added `empty?` method to `Ollama::DTO` class using `to_hash.empty?`
25
+ + Method is used to check if the object's hash representation is empty.
26
+
3
27
  ## 2024-10-19 v0.9.1
4
28
 
5
29
  * Fixing string interpolation in `import_source` method:
data/Rakefile CHANGED
@@ -34,7 +34,7 @@ GemHadar do
34
34
  dependency 'more_math', '~> 1.1'
35
35
  dependency 'mime-types', '~> 3.0'
36
36
  dependency 'reverse_markdown', '~> 2.0'
37
- dependency 'complex_config', '~> 0.22'
37
+ dependency 'complex_config', '~> 0.22', '>= 0.22.2'
38
38
  dependency 'search_ui', '~> 0.0'
39
39
  dependency 'amatch', '~> 0.4.1'
40
40
  dependency 'pdf-reader', '~> 2.0'
data/bin/ollama_chat CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'ollama'
4
4
  include Ollama
5
+ include Tins::GO
5
6
  require 'term/ansicolor'
6
7
  include Term::ANSIColor
7
- include Tins::GO
8
8
  require 'reline'
9
9
  require 'reverse_markdown'
10
10
  require 'complex_config'
@@ -375,113 +375,120 @@ def list_conversation(messages, last = nil)
375
375
  end
376
376
  end
377
377
 
378
- def reverse_markdown(html)
379
- ReverseMarkdown.convert(
380
- html,
381
- unknown_tags: :bypass,
382
- github_flavored: true,
383
- tag_border: ''
384
- )
385
- end
378
+ module SourceParsing
379
+ def parse_source(source_io)
380
+ case source_io&.content_type
381
+ when 'text/html'
382
+ reverse_markdown(source_io.read)
383
+ when 'text/xml'
384
+ if source_io.readline =~ %r(^\s*<rss\s)
385
+ source_io.rewind
386
+ return parse_rss(source_io)
387
+ end
388
+ source_io.rewind
389
+ source_io.read
390
+ when 'text/csv' # TODO
391
+ parse_csv(source_io)
392
+ when 'application/rss+xml'
393
+ parse_rss(source_io)
394
+ when 'application/atom+xml'
395
+ parse_atom(source_io)
396
+ when 'application/postscript'
397
+ ps_read(source_io)
398
+ when 'application/pdf'
399
+ pdf_read(source_io)
400
+ when %r(\Aapplication/(json|ld\+json|x-ruby|x-perl|x-gawk|x-python|x-javascript|x-c?sh|x-dosexec|x-shellscript|x-tex|x-latex|x-lyx|x-bibtex)), %r(\Atext/), nil
401
+ source_io.read
402
+ else
403
+ STDERR.puts "Cannot embed #{source_io&.content_type} document."
404
+ return
405
+ end
406
+ end
407
+
408
+ def parse_csv(source_io)
409
+ result = +''
410
+ CSV.table(File.new(source_io), col_sep: ?,).each do |row|
411
+ next if row.fields.select(&:present?).size == 0
412
+ result << row.map { |pair|
413
+ pair.compact.map { _1.to_s.strip } * ': ' if pair.last.present?
414
+ }.select(&:present?).map { _1.prepend(' ') } * ?\n
415
+ result << "\n\n"
416
+ end
417
+ result
418
+ end
386
419
 
387
- def parse_rss(source_io)
388
- feed = RSS::Parser.parse(source_io, false, false)
389
- title = <<~EOT
390
- # #{feed&.channel&.title}
420
+ def parse_rss(source_io)
421
+ feed = RSS::Parser.parse(source_io, false, false)
422
+ title = <<~EOT
423
+ # #{feed&.channel&.title}
391
424
 
392
- EOT
393
- feed.items.inject(title) do |text, item|
394
- text << <<~EOT
395
- ## [#{item&.title}](#{item&.link})
425
+ EOT
426
+ feed.items.inject(title) do |text, item|
427
+ text << <<~EOT
428
+ ## [#{item&.title}](#{item&.link})
396
429
 
397
- updated on #{item&.pubDate}
430
+ updated on #{item&.pubDate}
398
431
 
399
- #{reverse_markdown(item&.description)}
432
+ #{reverse_markdown(item&.description)}
400
433
 
401
- EOT
434
+ EOT
435
+ end
402
436
  end
403
- end
404
437
 
405
- def parse_atom(source_io)
406
- feed = RSS::Parser.parse(source_io, false, false)
407
- title = <<~EOT
408
- # #{feed.title.content}
438
+ def parse_atom(source_io)
439
+ feed = RSS::Parser.parse(source_io, false, false)
440
+ title = <<~EOT
441
+ # #{feed.title.content}
409
442
 
410
- EOT
411
- feed.items.inject(title) do |text, item|
412
- text << <<~EOT
413
- ## [#{item&.title&.content}](#{item&.link&.href})
443
+ EOT
444
+ feed.items.inject(title) do |text, item|
445
+ text << <<~EOT
446
+ ## [#{item&.title&.content}](#{item&.link&.href})
414
447
 
415
- updated on #{item&.updated&.content}
448
+ updated on #{item&.updated&.content}
416
449
 
417
- #{reverse_markdown(item&.content&.content)}
450
+ #{reverse_markdown(item&.content&.content)}
418
451
 
419
- EOT
452
+ EOT
453
+ end
420
454
  end
421
- end
422
455
 
423
- def pdf_read(io)
424
- reader = PDF::Reader.new(io)
425
- reader.pages.inject(+'') { |result, page| result << page.text }
426
- end
456
+ def pdf_read(io)
457
+ reader = PDF::Reader.new(io)
458
+ reader.pages.inject(+'') { |result, page| result << page.text }
459
+ end
427
460
 
428
- def ps_read(io)
429
- gs = `which gs`.chomp
430
- if gs.present?
431
- Tempfile.create do |tmp|
432
- IO.popen("#{gs} -q -sDEVICE=pdfwrite -sOutputFile=#{tmp.path} -", 'wb') do |gs_io|
433
- until io.eof?
434
- buffer = io.read(1 << 17)
435
- IO.select(nil, [ gs_io ], nil)
436
- gs_io.write buffer
437
- end
438
- gs_io.close
439
- File.open(tmp.path, 'rb') do |pdf|
440
- pdf_read(pdf)
461
+ def ps_read(io)
462
+ gs = `which gs`.chomp
463
+ if gs.present?
464
+ Tempfile.create do |tmp|
465
+ IO.popen("#{gs} -q -sDEVICE=pdfwrite -sOutputFile=#{tmp.path} -", 'wb') do |gs_io|
466
+ until io.eof?
467
+ buffer = io.read(1 << 17)
468
+ IO.select(nil, [ gs_io ], nil)
469
+ gs_io.write buffer
470
+ end
471
+ gs_io.close
472
+ File.open(tmp.path, 'rb') do |pdf|
473
+ pdf_read(pdf)
474
+ end
441
475
  end
442
476
  end
477
+ else
478
+ STDERR.puts "Cannot convert #{io&.content_type} whith ghostscript, gs not in path."
443
479
  end
444
- else
445
- STDERR.puts "Cannot convert #{io&.content_type} whith ghostscript, gs not in path."
446
480
  end
447
- end
448
481
 
449
- def parse_source(source_io)
450
- case source_io&.content_type
451
- when 'text/html'
452
- reverse_markdown(source_io.read)
453
- when 'text/xml'
454
- if source_io.readline =~ %r(^\s*<rss\s)
455
- source_io.rewind
456
- return parse_rss(source_io)
457
- end
458
- source_io.rewind
459
- source_io.read
460
- when 'text/csv'
461
- result = +''
462
- CSV.table(File.new(source_io), col_sep: ?,).each do |row|
463
- next if row.fields.select(&:present?).size == 0
464
- result << row.map { |pair|
465
- pair.compact.map { _1.to_s.strip } * ': ' if pair.last.present?
466
- }.select(&:present?).map { _1.prepend(' ') } * ?\n
467
- result << "\n\n"
468
- end
469
- result
470
- when 'application/rss+xml'
471
- parse_rss(source_io)
472
- when 'application/atom+xml'
473
- parse_atom(source_io)
474
- when 'application/postscript'
475
- ps_read(source_io)
476
- when 'application/pdf'
477
- pdf_read(source_io)
478
- when %r(\Aapplication/(json|ld\+json|x-ruby|x-perl|x-gawk|x-python|x-javascript|x-c?sh|x-dosexec|x-shellscript|x-tex|x-latex|x-lyx|x-bibtex)), %r(\Atext/), nil
479
- source_io.read
480
- else
481
- STDERR.puts "Cannot embed #{source_io&.content_type} document."
482
- return
482
+ def reverse_markdown(html)
483
+ ReverseMarkdown.convert(
484
+ html,
485
+ unknown_tags: :bypass,
486
+ github_flavored: true,
487
+ tag_border: ''
488
+ )
483
489
  end
484
490
  end
491
+ include SourceParsing
485
492
 
486
493
  def http_options(url)
487
494
  options = {}
@@ -726,7 +733,6 @@ def collection_stats
726
733
  puts <<~EOT
727
734
  Current Collection
728
735
  Name: #{bold{$documents.collection}}
729
- Embedding model: #{bold{$embedding_model}}
730
736
  #Embeddings: #{$documents.size}
731
737
  #Tags: #{$documents.tags.size}
732
738
  Tags: #{$documents.tags}
@@ -789,10 +795,17 @@ end
789
795
 
790
796
  def info
791
797
  puts "Current model is #{bold{$model}}."
792
- collection_stats
798
+ if $model_options.present?
799
+ puts " Options: #{JSON.pretty_generate($model_options).gsub(/(?<!\A)^/, ' ')}"
800
+ end
793
801
  $embedding.show
794
802
  if $embedding.on?
803
+ puts "Embedding model is #{bold{$embedding_model}}"
804
+ if $embedding_model_options.present?
805
+ puts " Options: #{JSON.pretty_generate($embedding_model_options).gsub(/(?<!\A)^/, ' ')}"
806
+ end
795
807
  puts "Text splitter is #{bold{$config.embedding.splitter.name}}."
808
+ collection_stats
796
809
  end
797
810
  puts "Documents database cache is #{$documents.nil? ? 'n/a' : bold{$documents.cache.class}}"
798
811
  $markdown.show
@@ -876,7 +889,7 @@ def usage
876
889
  end
877
890
 
878
891
  def version
879
- puts "%s %s" % [ File.basename($0), VERSION ]
892
+ puts "%s %s" % [ File.basename($0), Ollama::VERSION ]
880
893
  exit 0
881
894
  end
882
895
 
@@ -895,12 +908,12 @@ $opts[?h] and usage
895
908
  $opts[?V] and version
896
909
 
897
910
  base_url = $opts[?u] || $config.url
898
- $ollama = Client.new(base_url:, debug: $config.debug)
911
+ $ollama = Client.new(base_url:, debug: $config.debug)
899
912
 
900
913
  $document_policy = $config.document_policy
901
914
  $model = choose_model($opts[?m], $config.model.name)
902
- options = Options[$config.model.options]
903
- model_system = pull_model_unless_present($model, options)
915
+ $model_options = Options[$config.model.options]
916
+ model_system = pull_model_unless_present($model, $model_options)
904
917
  messages = []
905
918
  $embedding_enabled.set($config.embedding.enabled && !$opts[?E])
906
919
 
@@ -918,8 +931,8 @@ end
918
931
 
919
932
  if $embedding.on?
920
933
  $embedding_model = $config.embedding.model.name
921
- embedding_model_options = Options[$config.embedding.model.options]
922
- pull_model_unless_present($embedding_model, embedding_model_options)
934
+ $embedding_model_options = Options[$config.embedding.model.options]
935
+ pull_model_unless_present($embedding_model, $embedding_model_options)
923
936
  collection = $opts[?C] || $config.embedding.collection
924
937
  $documents = Documents.new(
925
938
  ollama:,
@@ -1158,7 +1171,7 @@ loop do
1158
1171
  messages << Message.new(role: 'user', content:, images: images.dup)
1159
1172
  images.clear
1160
1173
  handler = FollowChat.new(messages:, markdown: $markdown.on?, voice: ($current_voice if $voice.on?))
1161
- ollama.chat(model: $model, messages:, options:, stream: $stream.on?, &handler)
1174
+ ollama.chat(model: $model, messages:, options: $model_options, stream: $stream.on?, &handler)
1162
1175
 
1163
1176
  if $embedding.on? && !records.empty?
1164
1177
  puts "", records.map { |record|
data/lib/ollama/dto.rb CHANGED
@@ -33,6 +33,10 @@ module Ollama::DTO
33
33
 
34
34
  alias to_hash as_json
35
35
 
36
+ def empty?
37
+ to_hash.empty?
38
+ end
39
+
36
40
  def to_json(*)
37
41
  as_json.to_json(*)
38
42
  end
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '0.9.1'
3
+ VERSION = '0.9.3'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/ollama-ruby.gemspec CHANGED
@@ -1,26 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama-ruby 0.9.1 ruby lib
2
+ # stub: ollama-ruby 0.9.3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "0.9.1".freeze
6
+ s.version = "0.9.3".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-10-19"
11
+ s.date = "2024-10-21"
12
12
  s.description = "Library that allows interacting with the Ollama API".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["ollama_console".freeze, "ollama_chat".freeze, "ollama_update".freeze, "ollama_cli".freeze]
15
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/cache/common.rb".freeze, "lib/ollama/documents/cache/memory_cache.rb".freeze, "lib/ollama/documents/cache/redis_backed_memory_cache.rb".freeze, "lib/ollama/documents/cache/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/cache_fetcher.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/cache/common.rb".freeze, "lib/ollama/documents/cache/memory_cache.rb".freeze, "lib/ollama/documents/cache/redis_backed_memory_cache.rb".freeze, "lib/ollama/documents/cache/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/cache_fetcher.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/assets/prompt.txt".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_backed_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/cache_fetcher_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/file_argument_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/ollama/utils/width_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".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/cache/common.rb".freeze, "lib/ollama/documents/cache/memory_cache.rb".freeze, "lib/ollama/documents/cache/redis_backed_memory_cache.rb".freeze, "lib/ollama/documents/cache/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/cache_fetcher.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/assets/prompt.txt".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_backed_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/cache_fetcher_spec.rb".freeze, "spec/ollama/utils/colorize_texts_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/file_argument_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/ollama/utils/width_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.18".freeze
21
+ s.rubygems_version = "3.5.22".freeze
22
22
  s.summary = "Interacting with the Ollama API".freeze
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_backed_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/cache_fetcher_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/file_argument_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/ollama/utils/width_spec.rb".freeze, "spec/spec_helper.rb".freeze]
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_backed_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/cache_fetcher_spec.rb".freeze, "spec/ollama/utils/colorize_texts_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/file_argument_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/ollama/utils/width_spec.rb".freeze, "spec/spec_helper.rb".freeze]
24
24
 
25
25
  s.specification_version = 4
26
26
 
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_runtime_dependency(%q<more_math>.freeze, ["~> 1.1".freeze])
41
41
  s.add_runtime_dependency(%q<mime-types>.freeze, ["~> 3.0".freeze])
42
42
  s.add_runtime_dependency(%q<reverse_markdown>.freeze, ["~> 2.0".freeze])
43
- s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.22".freeze])
43
+ s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.22".freeze, ">= 0.22.2".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
46
  s.add_runtime_dependency(%q<pdf-reader>.freeze, ["~> 2.0".freeze])
@@ -60,16 +60,16 @@ RSpec.describe Ollama::Documents do
60
60
  expect(ollama).to receive(:embed).
61
61
  with(model:, input: [ 'foo' ], options: nil).
62
62
  and_return(double(embeddings: [ [ 0.1 ] ]))
63
- expect(documents.add('foo', tags: %i[ test ])).to eq documents
63
+ expect(documents.add('foo', tags: %w[ test ])).to eq documents
64
64
  expect(ollama).to receive(:embed).
65
65
  with(model:, input: 'foo', options: nil).
66
66
  and_return(double(embeddings: [ [ 0.1 ] ]))
67
- records = documents.find('foo', tags: %i[ nix ])
67
+ records = documents.find('foo', tags: %w[ nix ])
68
68
  expect(records).to eq []
69
69
  expect(ollama).to receive(:embed).
70
70
  with(model:, input: 'foo', options: nil).
71
71
  and_return(double(embeddings: [ [ 0.1 ] ]))
72
- records = documents.find('foo', tags: %i[ test ])
72
+ records = documents.find('foo', tags: %w[ test ])
73
73
  expect(records).to eq [
74
74
  Ollama::Documents::Record[text: 'foo', embedding: [ 0.1 ], similarity: 1.0 ]
75
75
  ]
@@ -135,8 +135,9 @@ RSpec.describe Ollama::Documents do
135
135
  expect(ollama).to receive(:embed).
136
136
  with(model:, input: %w[ bar ], options: nil).
137
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
138
+ expect(documents.add('foo', tags: %w[ test ])).to eq documents
139
+ expect(documents.add('bar', tags: %w[ test2 ])).to eq documents
140
+ expect(documents.tags.to_a).to eq %w[ test test2 ]
140
141
  expect {
141
142
  documents.clear tags: 'test'
142
143
  }.to change { documents.size }.from(2).to(1)
@@ -13,6 +13,10 @@ RSpec.describe Ollama::Options do
13
13
  expect(options).to be_a described_class
14
14
  end
15
15
 
16
+ it 'can be empty' do
17
+ expect(described_class.new).to be_empty
18
+ end
19
+
16
20
  it 'can be used to cast hashes' do
17
21
  expect(described_class[{
18
22
  penalize_newline: true,
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ollama::Utils::ColorizeTexts do
4
+ it 'colorizes texts' do
5
+ ct = described_class.new(%w[ foo bar ])
6
+ colored = ct.to_s
7
+ uncolored = Term::ANSIColor.uncolor(ct.to_s)
8
+ expect(colored.size).to be > uncolored.size
9
+ expect(uncolored).to eq(
10
+ "foo\n#3 \n\nbar\n#3 \n\n"
11
+ )
12
+ end
13
+ 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.9.1
4
+ version: 0.9.3
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-10-19 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -241,6 +241,9 @@ dependencies:
241
241
  - - "~>"
242
242
  - !ruby/object:Gem::Version
243
243
  version: '0.22'
244
+ - - ">="
245
+ - !ruby/object:Gem::Version
246
+ version: 0.22.2
244
247
  type: :runtime
245
248
  prerelease: false
246
249
  version_requirements: !ruby/object:Gem::Requirement
@@ -248,6 +251,9 @@ dependencies:
248
251
  - - "~>"
249
252
  - !ruby/object:Gem::Version
250
253
  version: '0.22'
254
+ - - ">="
255
+ - !ruby/object:Gem::Version
256
+ version: 0.22.2
251
257
  - !ruby/object:Gem::Dependency
252
258
  name: search_ui
253
259
  requirement: !ruby/object:Gem::Requirement
@@ -516,6 +522,7 @@ files:
516
522
  - spec/ollama/tool_spec.rb
517
523
  - spec/ollama/utils/ansi_markdown_spec.rb
518
524
  - spec/ollama/utils/cache_fetcher_spec.rb
525
+ - spec/ollama/utils/colorize_texts_spec.rb
519
526
  - spec/ollama/utils/fetcher_spec.rb
520
527
  - spec/ollama/utils/file_argument_spec.rb
521
528
  - spec/ollama/utils/tags_spec.rb
@@ -545,7 +552,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
545
552
  - !ruby/object:Gem::Version
546
553
  version: '0'
547
554
  requirements: []
548
- rubygems_version: 3.5.18
555
+ rubygems_version: 3.5.22
549
556
  signing_key:
550
557
  specification_version: 4
551
558
  summary: Interacting with the Ollama API
@@ -585,6 +592,7 @@ test_files:
585
592
  - spec/ollama/tool_spec.rb
586
593
  - spec/ollama/utils/ansi_markdown_spec.rb
587
594
  - spec/ollama/utils/cache_fetcher_spec.rb
595
+ - spec/ollama/utils/colorize_texts_spec.rb
588
596
  - spec/ollama/utils/fetcher_spec.rb
589
597
  - spec/ollama/utils/file_argument_spec.rb
590
598
  - spec/ollama/utils/tags_spec.rb