ollama-ruby 0.3.0 → 0.3.2

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: 510c31683b2251118a7c3b469620400016b29fd1ea6f17cc86e4f99f62ecea2f
4
- data.tar.gz: a00c4275e42002a01a99f874a855386c83e502551360c1f4146eee0b74f2fd08
3
+ metadata.gz: 9304634c783477787792071f039d6941222bcca0577cd59cdbc5103f820ea299
4
+ data.tar.gz: 9edc7eaf98c0601e08bb5cde23fc2d46b745982172caea349982d8867790166a
5
5
  SHA512:
6
- metadata.gz: 17e50d40e4c24b56b5c2923f0b73f3e4294587b61a302fbaf4cd8f891e879eb435541e1f7e195a4f88352fd99aa80ff44c8577b8c195d7ef31af1c33229018b7
7
- data.tar.gz: a18bcef82e9481b75fee4a4c88598a7a374c48f841e9870b39174c0d1f5f235f1173bdbff939182481d431e4e9c8c85501be4f5ef917ca02865692cfc39fde5a
6
+ metadata.gz: 0bda727610f0793d6c360a63c76b2c42e032109f34011ed7cbd54df5663102c3738498be836adcb00645e4ce407cab1f422737970b83a3fa757ea0b4d90d8453
7
+ data.tar.gz: b9df134561b2a44accfdc1ec6da68eb0b3b9b5ce64c2d64c744834a0b74cbfde8018e270977440224d0433c681e7a203d272453e391b85a3d32f34e3b0c790ca
data/CHANGES.md CHANGED
@@ -1,5 +1,64 @@
1
1
  # Changes
2
2
 
3
+ ## 2024-09-15 v0.3.2
4
+
5
+ * Add color support to chooser module:
6
+ + Include `Term::ANSIColor` in `Ollama::Utils::Chooser` module
7
+ + Use `blue`, `on_blue` ANSI color for selected item in query method
8
+ * Refactor summarize method to also import sources:
9
+ + Added `content` variable to store result of `parse_source`
10
+ + Replaced `or return` with explicit assignment and return
11
+ + Added calls to `source_io.rewind` and `import_document`
12
+ * Add new test for `file_argument_spec.rb`
13
+ * Refactor tag list initialization and merging:
14
+ + Use array literals for initializing tags lists
15
+ + Use array literals for passing to merge method
16
+ * Update dependencies and dates in Rakefile and gemspec:
17
+ + Removed '.utilsrc' from ignored files in Rakefile
18
+ + Updated date in `ollama-ruby.gemspec` to "2024-09-13"
19
+ + Removed 'utils' development dependency from `ollama-ruby.gemspec`
20
+ * Refactor `search_web` method to allow n parameter to be optional and default
21
+ to 1.
22
+
23
+ ## 2024-09-12 v0.3.1
24
+
25
+ * Update dependencies and date in gemspec files:
26
+ - Updated `complex_config` dependency to '~> 0.22'
27
+ * Refactor FollowChat#eval_stats to add bold eval rates
28
+ * Improve formatting in eval_stats using bold and color for better
29
+ readability.
30
+ * Update import_document and add_image methods to handle nil values
31
+ correctly.
32
+ * Update width method in utils/width.rb to use uncolor when checking line
33
+ length.
34
+ * Refactor eval stats output in FollowChat class
35
+ - Add indentation to eval stats output for better readability
36
+ * FollowChat evaluation stats refactored
37
+ - Removed hardcoded eval_stats hash and replaced with method call
38
+ `eval_stats(response)`
39
+ - Added new method `eval_stats(response)` to calculate evaluation statistics
40
+ - Calculates eval duration, prompt eval duration, total duration, and load
41
+ duration
42
+ - Adds eval count, prompt eval count, eval rate, and prompt eval rate
43
+ * Use default to_s tree representation of config.
44
+ * Update complex_config dependency to ~> 0.21, >= 0.21.1 in Rakefile
45
+ * Update complex_config dependency to ~> 0.21, >= 0.21.1 in
46
+ ollama-ruby.gemspec
47
+ * Update dependencies and configuration display
48
+ * Update 'complex_config' dependency to '~> 0.21'
49
+ * Change OllamaChatConfig to display configuration as a tree instead of yaml
50
+ * Improve /web search command
51
+ * Update infobar dependency to ~> 0.8
52
+ * Update /web command to summarize web sources as well as importing them
53
+ directly
54
+ * Add /clobber command to clear conversation messages and collection
55
+ * Refactor Ollama chat configuration and summary generation.
56
+ * Update `OllamaChatConfig` to use `prompts.system` instead of `system`.
57
+ * Introduce `prompts.summarize` config as template for generating abstract
58
+ summaries.
59
+ * Replace hardcoded summary generation with call to `prompts.summarize`.
60
+ * Display /help for all unknown chat commands starting wit `/`
61
+
3
62
  ## 2024-09-05 v0.3.0
4
63
 
5
64
  * **New Features**
data/README.md CHANGED
@@ -156,6 +156,7 @@ The following commands can be given inside the chat, if prefixed by a `/`:
156
156
  /markdown toggle markdown output
157
157
  /list list the messages of the conversation
158
158
  /clear clear the conversation messages
159
+ /clobber clear conversation messages and collection
159
160
  /pop [n] pop the last n exchanges, defaults to 1
160
161
  /model change the model
161
162
  /regenerate the last answer message
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ GemHadar do
15
15
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.AppleDouble', '.bundle',
16
16
  '.yardoc', 'tags', 'errors.lst', 'cscope.out', 'coverage', 'tmp', 'corpus'
17
17
  package_ignore '.all_images.yml', '.tool-versions', '.gitignore', 'VERSION',
18
- '.utilsrc', '.rspec', *Dir.glob('.github/**/*', File::FNM_DOTMATCH)
18
+ '.rspec', *Dir.glob('.github/**/*', File::FNM_DOTMATCH)
19
19
  readme 'README.md'
20
20
 
21
21
  executables << 'ollama_console' << 'ollama_chat' <<
@@ -24,7 +24,7 @@ GemHadar do
24
24
  required_ruby_version '~> 3.1'
25
25
 
26
26
  dependency 'excon', '~> 0.111'
27
- dependency 'infobar', '~> 0.7'
27
+ dependency 'infobar', '~> 0.8'
28
28
  dependency 'term-ansicolor', '~> 1.11'
29
29
  dependency 'kramdown-parser-gfm', '~> 1.1'
30
30
  dependency 'terminal-table', '~> 3.0'
@@ -34,13 +34,12 @@ GemHadar do
34
34
  dependency 'sorted_set', '~> 1.0'
35
35
  dependency 'mime-types', '~> 3.0'
36
36
  dependency 'reverse_markdown', '~> 2.0'
37
- dependency 'complex_config', '~> 0.20'
37
+ dependency 'complex_config', '~> 0.22'
38
38
  dependency 'search_ui', '~> 0.0'
39
39
  dependency 'amatch', '~> 0.4.1'
40
40
  dependency 'pdf-reader', '~> 2.0'
41
41
  development_dependency 'all_images', '~> 0.4'
42
42
  development_dependency 'rspec', '~> 3.2'
43
- development_dependency 'utils'
44
43
  development_dependency 'webmock'
45
44
 
46
45
  licenses << 'MIT'
data/bin/ollama_chat CHANGED
@@ -26,7 +26,12 @@ class OllamaChatConfig
26
26
  name: <%= ENV.fetch('OLLAMA_CHAT_MODEL', 'llama3.1') %>
27
27
  options:
28
28
  num_ctx: 8192
29
- system: <%= ENV.fetch('OLLAMA_CHAT_SYSTEM', 'null') %>
29
+ prompts:
30
+ system: <%= ENV.fetch('OLLAMA_CHAT_SYSTEM', 'null') %>
31
+ summarize: |
32
+ Generate an abstract summary of the content in this document:
33
+
34
+ %s
30
35
  voice: Samantha
31
36
  markdown: true
32
37
  embedding:
@@ -50,7 +55,7 @@ class OllamaChatConfig
50
55
 
51
56
  def initialize(filename = nil)
52
57
  @filename = filename || default_path
53
- @config = Provider.config(@filename)
58
+ @config = Provider.config(@filename, '⚙️')
54
59
  retried = false
55
60
  rescue ConfigurationFileMissing
56
61
  if @filename == default_path && !retried
@@ -115,22 +120,33 @@ class FollowChat
115
120
  @say.call(response)
116
121
  end
117
122
  if response.done
118
- @output.puts
119
- eval_stats = {
120
- eval_duration: Tins::Duration.new(response.eval_duration / 1e9),
121
- eval_count: response.eval_count,
122
- prompt_eval_duration: Tins::Duration.new(response.prompt_eval_duration / 1e9),
123
- prompt_eval_count: response.prompt_eval_count,
124
- total_duration: Tins::Duration.new(response.total_duration / 1e9),
125
- load_duration: Tins::Duration.new(response.load_duration / 1e9),
126
- }.map { _1 * '=' } * ' '
127
- @output.puts '📊 ' + color(111) { Utils::Width.wrap(eval_stats, percentage: 90) }
123
+ @output.puts "", eval_stats(response)
128
124
  end
129
125
  self
130
126
  end
127
+
128
+ def eval_stats(response)
129
+ eval_duration = response.eval_duration / 1e9
130
+ prompt_eval_duration = response.prompt_eval_duration / 1e9
131
+ stats_text = {
132
+ eval_duration: Tins::Duration.new(eval_duration),
133
+ eval_count: response.eval_count,
134
+ eval_rate: bold { "%.2f c/s" % (response.eval_count / eval_duration) } + color(111),
135
+ prompt_eval_duration: Tins::Duration.new(prompt_eval_duration),
136
+ prompt_eval_count: response.prompt_eval_count,
137
+ prompt_eval_rate: bold { "%.2f c/s" % (response.prompt_eval_count / prompt_eval_duration) } + color(111),
138
+ total_duration: Tins::Duration.new(response.total_duration / 1e9),
139
+ load_duration: Tins::Duration.new(response.load_duration / 1e9),
140
+ }.map { _1 * '=' } * ' '
141
+ '📊 ' + color(111) {
142
+ Utils::Width.wrap(stats_text, percentage: 90).gsub(/(?<!\A)^/, ' ')
143
+ }
144
+ end
131
145
  end
132
146
 
133
- def search_web(query, n = 5)
147
+ def search_web(query, n = nil)
148
+ n = n.to_i
149
+ n < 1 and n = 1
134
150
  query = URI.encode_uri_component(query)
135
151
  url = "https://www.duckduckgo.com/html/?q=#{query}"
136
152
  Ollama::Utils::Fetcher.new.get(url) do |tmp|
@@ -312,7 +328,7 @@ def import_document(source_io, source)
312
328
  STDOUT.puts "Embedding disabled, I won't import any documents, try: /summarize"
313
329
  return
314
330
  end
315
- infobar.puts "Importing #{italic { source_io.content_type }} document #{source.to_s.inspect}."
331
+ puts "Importing #{italic { source_io&.content_type }} document #{source.to_s.inspect}."
316
332
  text = parse_source(source_io) or return
317
333
  text.downcase!
318
334
  splitter_config = $config.embedding.splitter
@@ -340,7 +356,7 @@ def import_document(source_io, source)
340
356
  end
341
357
 
342
358
  def add_image(images, source_io, source)
343
- STDERR.puts "Adding #{source_io.content_type} image #{source.to_s.inspect}."
359
+ STDERR.puts "Adding #{source_io&.content_type} image #{source.to_s.inspect}."
344
360
  image = Image.for_io(source_io, path: source.to_s)
345
361
  (images << image).uniq!
346
362
  end
@@ -365,16 +381,15 @@ rescue => e
365
381
  end
366
382
 
367
383
  def summarize(source)
368
- puts "Now summarizing #{source.inspect}."
384
+ puts "Now summarizing #{source.to_s.inspect}."
369
385
  source_content =
370
386
  fetch_source(source) do |source_io|
371
- parse_source(source_io) or return
387
+ content = parse_source(source_io) or return
388
+ source_io.rewind
389
+ import_document(source_io, source)
390
+ content
372
391
  end
373
- <<~end
374
- # Generate an abstract summary of the content in this document:
375
-
376
- #{source_content}
377
- end
392
+ $config.prompts.summarize % source_content
378
393
  end
379
394
 
380
395
  def parse_content(content, images)
@@ -459,6 +474,7 @@ def display_chat_help
459
474
  /markdown toggle markdown output
460
475
  /list list the messages of the conversation
461
476
  /clear clear the conversation messages
477
+ /clobber clear conversation messages and collection
462
478
  /pop [n] pop the last n exchanges, defaults to 1
463
479
  /model change the model
464
480
  /regenerate the last answer message
@@ -501,8 +517,7 @@ $config = config.config
501
517
 
502
518
  opts[?h] and usage
503
519
 
504
- puts "Configuration read from #{config.filename.inspect} is:"
505
- y $config.to_h
520
+ puts "Configuration read from #{config.filename.inspect} is:", $config
506
521
 
507
522
  base_url = opts[?u] || $config.url
508
523
  $ollama = Client.new(base_url:, debug: $config.debug)
@@ -540,7 +555,7 @@ if $config.embedding.enabled
540
555
  File.expand_path(doc)
541
556
  end
542
557
  end
543
- infobar.puts "Collection #{bold{collection}}: Adding #{document_list.size} documents…"
558
+ puts "Collection #{bold{collection}}: Adding #{document_list.size} documents…"
544
559
  document_list.each_slice(25) do |docs|
545
560
  docs.each do |doc|
546
561
  fetch_source(doc) do |doc_io|
@@ -563,7 +578,7 @@ if opts[?c]
563
578
  messages.concat load_conversation(opts[?c])
564
579
  else
565
580
  if system = Ollama::Utils::FileArgument.
566
- get_file_argument(opts[?s], default: $config.system? || model_system)
581
+ get_file_argument(opts[?s], default: $config.prompts.system? || model_system)
567
582
  messages << Message.new(role: 'system', content: system)
568
583
  puts "Configured system prompt is:\n#{italic { system }}"
569
584
  end
@@ -584,7 +599,7 @@ loop do
584
599
  when %r(^/quit$)
585
600
  puts "Goodbye."
586
601
  exit 0
587
- when %r(^/markdown)
602
+ when %r(^/markdown$)
588
603
  markdown = set_markdown(!markdown)
589
604
  next
590
605
  when %r(^/list$)
@@ -594,6 +609,11 @@ loop do
594
609
  messages.clear
595
610
  puts "Cleared messages."
596
611
  next
612
+ when %r(^/clobber$)
613
+ messages.clear
614
+ $documents.clear
615
+ puts "Cleared messages and collection."
616
+ next
597
617
  when %r(^/collection\s+(clear|stats|change|new)(?:\s+(.+))?$)
598
618
  command, arg = $1, $2
599
619
  case command
@@ -633,16 +653,24 @@ loop do
633
653
  puts "Not enough messages in this conversation."
634
654
  redo
635
655
  end
656
+ parse_content = false
657
+ content
636
658
  when %r(^/summarize\s+(.+))
637
659
  parse_content = false
638
660
  content = summarize($1) or next
639
- when %r(^/web\s+(?:(\d+)\s+)?(.+)$)
640
- parse_content = true
641
- urls = search_web($2, $1.to_i)
661
+ when %r(^/web\s+(?:(\d+)\s+)?(.+))
662
+ parse_content = false
663
+ urls = search_web($2, $1.to_i)
664
+ urls.each do |url|
665
+ fetch_source(url) do |url_io|
666
+ import_document(url_io, url)
667
+ end
668
+ end
669
+ urls_summarized = urls.map { summarize(_1) }
642
670
  content = <<~end
643
- Answer the the query #{$2.inspect} using these sources:
671
+ Answer the the query #{$2.inspect} using these sources and summaries:
644
672
 
645
- #{urls * ?\n}
673
+ #{urls.zip(urls_summarized).map { |u, s| "%s as \n:%s" % [ u, s ] } * "\n\n"}
646
674
  end
647
675
  when %r(^/save\s+(.+)$)
648
676
  save_conversation($1, messages)
@@ -652,12 +680,15 @@ loop do
652
680
  messages = load_conversation($1)
653
681
  puts "Loaded conversation from #$1."
654
682
  next
655
- when %r(^/help$)
683
+ when %r(^/)
656
684
  display_chat_help
657
685
  next
658
- when nil, ''
686
+ when ''
659
687
  puts "Type /quit to quit."
660
688
  next
689
+ when nil
690
+ puts "Goodbye."
691
+ exit 0
661
692
  end
662
693
 
663
694
  content, tags = if parse_content
@@ -1,8 +1,10 @@
1
1
  require 'amatch'
2
2
  require 'search_ui'
3
+ require 'term/ansicolor'
3
4
 
4
5
  module Ollama::Utils::Chooser
5
6
  include SearchUI
7
+ include Term::ANSIColor
6
8
 
7
9
  module_function
8
10
 
@@ -17,7 +19,7 @@ module Ollama::Utils::Chooser
17
19
  },
18
20
  query: -> _answer, matches, selector {
19
21
  matches.each_with_index.map { |m, i|
20
- i == selector ? "#{Term::ANSIColor.blue{?⮕}} #{m.on_blue}" : " #{m}"
22
+ i == selector ? "#{blue{?⮕}} #{on_blue{m}}" : " #{m}"
21
23
  } * ?\n
22
24
  },
23
25
  found: -> _answer, matches, selector {
@@ -1,14 +1,14 @@
1
1
  module Ollama::Utils::FileArgument
2
2
  module_function
3
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)
4
+ def get_file_argument(path_or_content, default: nil)
5
+ if path_or_content.present? && path_or_content.size < 2 ** 15 &&
6
+ File.basename(path_or_content).size < 2 ** 8 &&
7
+ File.exist?(path_or_content)
8
8
  then
9
- File.read(prompt)
10
- elsif prompt.present?
11
- prompt
9
+ File.read(path_or_content)
10
+ elsif path_or_content.present?
11
+ path_or_content
12
12
  else
13
13
  default
14
14
  end
@@ -1,6 +1,8 @@
1
1
  require 'tins/terminal'
2
2
 
3
3
  module Ollama::Utils::Width
4
+ include Term::ANSIColor
5
+
4
6
  module_function
5
7
 
6
8
  def width(percentage: 100.0)
@@ -12,7 +14,7 @@ module Ollama::Utils::Width
12
14
  raise ArgumentError, "either pass percentage or length argument"
13
15
  percentage and length ||= width(percentage:)
14
16
  text.gsub(/(?<!\n)\n(?!\n)/, ' ').lines.map do |line|
15
- if length >= 1 && line.length > length
17
+ if length >= 1 && uncolor { line }.length > length
16
18
  line.gsub(/(.{1,#{length}})(\s+|$)/, "\\1\n").strip
17
19
  else
18
20
  line.strip
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.2'
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,36 +1,35 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama-ruby 0.3.0 ruby lib
2
+ # stub: ollama-ruby 0.3.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "0.3.0".freeze
6
+ s.version = "0.3.2".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-06"
11
+ s.date = "2024-09-15"
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/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]
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/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_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/file_argument_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
21
  s.rubygems_version = "3.5.18".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_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]
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/file_argument_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze]
24
24
 
25
25
  s.specification_version = 4
26
26
 
27
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.17.0".freeze])
27
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.17.1".freeze])
28
28
  s.add_development_dependency(%q<all_images>.freeze, ["~> 0.4".freeze])
29
29
  s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2".freeze])
30
- s.add_development_dependency(%q<utils>.freeze, [">= 0".freeze])
31
30
  s.add_development_dependency(%q<webmock>.freeze, [">= 0".freeze])
32
31
  s.add_runtime_dependency(%q<excon>.freeze, ["~> 0.111".freeze])
33
- s.add_runtime_dependency(%q<infobar>.freeze, ["~> 0.7".freeze])
32
+ s.add_runtime_dependency(%q<infobar>.freeze, ["~> 0.8".freeze])
34
33
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
35
34
  s.add_runtime_dependency(%q<kramdown-parser-gfm>.freeze, ["~> 1.1".freeze])
36
35
  s.add_runtime_dependency(%q<terminal-table>.freeze, ["~> 3.0".freeze])
@@ -40,7 +39,7 @@ Gem::Specification.new do |s|
40
39
  s.add_runtime_dependency(%q<sorted_set>.freeze, ["~> 1.0".freeze])
41
40
  s.add_runtime_dependency(%q<mime-types>.freeze, ["~> 3.0".freeze])
42
41
  s.add_runtime_dependency(%q<reverse_markdown>.freeze, ["~> 2.0".freeze])
43
- s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.20".freeze])
42
+ s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.22".freeze])
44
43
  s.add_runtime_dependency(%q<search_ui>.freeze, ["~> 0.0".freeze])
45
44
  s.add_runtime_dependency(%q<amatch>.freeze, ["~> 0.4.1".freeze])
46
45
  s.add_runtime_dependency(%q<pdf-reader>.freeze, ["~> 2.0".freeze])
@@ -0,0 +1 @@
1
+ You are a test prompt just used for testing.
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ollama::Utils::FileArgument do
4
+ it 'it can return content' do
5
+ expect(described_class.get_file_argument('foo')).to eq 'foo'
6
+ end
7
+
8
+ it 'it can return content at path' do
9
+ expect(described_class.get_file_argument(asset('prompt.txt'))).to include\
10
+ 'test prompt'
11
+ end
12
+
13
+ it 'it can return default content' do
14
+ expect(described_class.get_file_argument('', default: 'foo')).to eq 'foo'
15
+ expect(described_class.get_file_argument(nil, default: 'foo')).to eq 'foo'
16
+ end
17
+ end
@@ -6,7 +6,7 @@ RSpec.describe Ollama::Utils::Tags do
6
6
  end
7
7
 
8
8
  it 'can contain unique tags and is sorted' do
9
- tags = described_class.new([ 'bar', 'foo'])
9
+ tags = described_class.new(%w[ bar foo ])
10
10
  expect(tags.to_a).to eq %w[ bar foo ]
11
11
  end
12
12
 
@@ -14,11 +14,11 @@ RSpec.describe Ollama::Utils::Tags do
14
14
  tags = described_class.new([ 'foo' ])
15
15
  tags.add 'bar'
16
16
  expect(tags.to_a).to eq %w[ bar foo ]
17
- tags.merge [ 'baz', 'baz2' ]
17
+ tags.merge %w[ baz baz2 ]
18
18
  expect(tags.to_a).to eq %w[ bar baz baz2 foo ]
19
19
  end
20
20
 
21
21
  it 'can be output nicely' do
22
- expect(described_class.new(%w[foo bar]).to_s).to eq '#bar #foo'
22
+ expect(described_class.new(%w[ foo bar ]).to_s).to eq '#bar #foo'
23
23
  end
24
24
  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.3.0
4
+ version: 0.3.2
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-06 00:00:00.000000000 Z
11
+ date: 2024-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.17.0
19
+ version: 1.17.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.17.0
26
+ version: 1.17.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: all_images
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.2'
55
- - !ruby/object:Gem::Dependency
56
- name: utils
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: webmock
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +86,14 @@ dependencies:
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: '0.7'
89
+ version: '0.8'
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: '0.7'
96
+ version: '0.8'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: term-ansicolor
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -240,14 +226,14 @@ dependencies:
240
226
  requirements:
241
227
  - - "~>"
242
228
  - !ruby/object:Gem::Version
243
- version: '0.20'
229
+ version: '0.22'
244
230
  type: :runtime
245
231
  prerelease: false
246
232
  version_requirements: !ruby/object:Gem::Requirement
247
233
  requirements:
248
234
  - - "~>"
249
235
  - !ruby/object:Gem::Version
250
- version: '0.20'
236
+ version: '0.22'
251
237
  - !ruby/object:Gem::Dependency
252
238
  name: search_ui
253
239
  requirement: !ruby/object:Gem::Requirement
@@ -418,6 +404,7 @@ files:
418
404
  - ollama-ruby.gemspec
419
405
  - spec/assets/embeddings.json
420
406
  - spec/assets/kitten.jpg
407
+ - spec/assets/prompt.txt
421
408
  - spec/ollama/client/doc_spec.rb
422
409
  - spec/ollama/client_spec.rb
423
410
  - spec/ollama/commands/chat_spec.rb
@@ -452,6 +439,7 @@ files:
452
439
  - spec/ollama/tool_spec.rb
453
440
  - spec/ollama/utils/ansi_markdown_spec.rb
454
441
  - spec/ollama/utils/fetcher_spec.rb
442
+ - spec/ollama/utils/file_argument_spec.rb
455
443
  - spec/ollama/utils/tags_spec.rb
456
444
  - spec/spec_helper.rb
457
445
  - tmp/.keep
@@ -517,5 +505,6 @@ test_files:
517
505
  - spec/ollama/tool_spec.rb
518
506
  - spec/ollama/utils/ansi_markdown_spec.rb
519
507
  - spec/ollama/utils/fetcher_spec.rb
508
+ - spec/ollama/utils/file_argument_spec.rb
520
509
  - spec/ollama/utils/tags_spec.rb
521
510
  - spec/spec_helper.rb