ollama-ruby 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/ollama_cli CHANGED
@@ -8,8 +8,8 @@ include Tins::GO
8
8
  require 'json'
9
9
 
10
10
  def usage
11
- puts <<~end
12
- #{File.basename($0)} [OPTIONS]
11
+ puts <<~EOT
12
+ Usage: #{File.basename($0)} [OPTIONS]
13
13
 
14
14
  -u URL the ollama base url, OLLAMA_URL
15
15
  -m MODEL the ollama model to chat with, OLLAMA_MODEL
@@ -22,7 +22,7 @@ def usage
22
22
  -S use streaming for generation
23
23
  -h this help
24
24
 
25
- end
25
+ EOT
26
26
  exit 0
27
27
  end
28
28
 
data/bin/ollama_update CHANGED
@@ -14,4 +14,6 @@ ollama.tags.models.each do |model|
14
14
  "Updating model #{bold {name}} (last modified at #{modified_at.iso8601}):"
15
15
  )
16
16
  ollama.pull(name:)
17
+ rescue Ollama::Errors::Error => e
18
+ infobar.puts "Caught #{e.class} for model #{bold { model.name }}: #{e} => Continuing."
17
19
  end
data/docker-compose.yml CHANGED
@@ -2,10 +2,9 @@ services:
2
2
  redis:
3
3
  image: redis:7.2.5-alpine
4
4
  restart: unless-stopped
5
- ports:
6
- - "9736:6379"
5
+ ports: [ "127.0.0.1:9736:6379" ]
7
6
  volumes:
8
- - "redis-data:/data:delegated"
9
- - "./config/redis.conf:/etc/redis.conf"
7
+ - "redis-data:/data:delegated"
8
+ - "./config/redis.conf:/etc/redis.conf"
10
9
  volumes:
11
10
  redis-data:
data/lib/ollama/client.rb CHANGED
@@ -1,6 +1,3 @@
1
- require 'tins/xt/string_camelize'
2
- require 'tins/annotate'
3
-
4
1
  class Ollama::Client
5
2
  end
6
3
  require 'ollama/client/doc'
@@ -19,8 +16,8 @@ class Ollama::Client
19
16
  'missing :base_url parameter or OLLAMA_URL environment variable'
20
17
  end
21
18
  base_url.is_a? URI or base_url = URI.parse(base_url)
22
- base_url.is_a?(URI::HTTP) || base_url.is_a?(URI::HTTPS) or
23
- raise ArgumentError, "require #{base_url.inspect} to be http/https-URI"
19
+ base_url.is_a?(URI::HTTP) || base_url.is_a?(URI::HTTPS) or
20
+ raise ArgumentError, "require #{base_url.inspect} to be http/https-URI"
24
21
  @ssl_verify_peer = base_url.query.to_s.split(?&).inject({}) { |h, l|
25
22
  h.merge Hash[*l.split(?=)]
26
23
  }['ssl_verify_peer'] != 'false'
@@ -23,7 +23,17 @@ class Ollama::Documents::RedisCache
23
23
  end
24
24
 
25
25
  def []=(key, value)
26
- redis.set(pre(key), JSON.generate(value), ex: @ex)
26
+ set(key, value)
27
+ end
28
+
29
+ def set(key, value, ex: nil)
30
+ ex ||= @ex
31
+ if !ex.nil? && ex < 1
32
+ redis.del(pre(key))
33
+ else
34
+ redis.set(pre(key), JSON.generate(value), ex:)
35
+ end
36
+ value
27
37
  end
28
38
 
29
39
  def ttl(key)
@@ -25,7 +25,7 @@ class Ollama::Documents
25
25
  end
26
26
 
27
27
  def tags_set
28
- Ollama::Utils::Tags.new(tags)
28
+ Ollama::Utils::Tags.new(tags, source:)
29
29
  end
30
30
 
31
31
  def ==(other)
@@ -35,12 +35,13 @@ class Ollama::Documents
35
35
  alias inspect to_s
36
36
  end
37
37
 
38
- def initialize(ollama:, model:, model_options: nil, collection: nil, cache: MemoryCache, redis_url: nil)
38
+ def initialize(ollama:, model:, model_options: nil, collection: nil, cache: MemoryCache, redis_url: nil, debug: false)
39
39
  collection ||= default_collection
40
40
  @ollama, @model, @model_options, @collection =
41
41
  ollama, model, model_options, collection.to_sym
42
42
  @redis_url = redis_url
43
- @cache = connect_cache(cache)
43
+ @cache = connect_cache(cache)
44
+ @debug = debug
44
45
  end
45
46
 
46
47
  def default_collection
@@ -56,17 +57,22 @@ class Ollama::Documents
56
57
 
57
58
  def add(inputs, batch_size: 10, source: nil, tags: [])
58
59
  inputs = Array(inputs)
59
- tags = Ollama::Utils::Tags.new(tags)
60
- source and tags.add File.basename(source).gsub(/\?.*/, '')
60
+ tags = Ollama::Utils::Tags.new(tags, source:)
61
+ if source
62
+ tags.add(File.basename(source).gsub(/\?.*/, ''), source:)
63
+ end
61
64
  inputs.map! { |i|
62
65
  text = i.respond_to?(:read) ? i.read : i.to_s
63
66
  text
64
67
  }
65
68
  inputs.reject! { |i| exist?(i) }
66
69
  inputs.empty? and return self
70
+ if @debug
71
+ puts Ollama::Utils::ColorizeTexts.new(inputs)
72
+ end
67
73
  batches = inputs.each_slice(batch_size).
68
74
  with_infobar(
69
- label: "Add #{truncate(tags.to_s, percentage: 25)}",
75
+ label: "Add #{truncate(tags.to_s(link: false), percentage: 25)}",
70
76
  total: inputs.size
71
77
  )
72
78
  batches.each do |batch|
@@ -155,7 +161,11 @@ class Ollama::Documents
155
161
  end
156
162
 
157
163
  def tags
158
- @cache.inject(Ollama::Utils::Tags.new) { |t, (_, record)| t.merge(record.tags) }
164
+ @cache.each_with_object(Ollama::Utils::Tags.new) do |(_, record), t|
165
+ record.tags.each do |tag|
166
+ t.add(tag, source: record.source)
167
+ end
168
+ end
159
169
  end
160
170
 
161
171
  private
data/lib/ollama/image.rb CHANGED
@@ -7,6 +7,8 @@ class Ollama::Image
7
7
 
8
8
  attr_accessor :path
9
9
 
10
+ attr_reader :data
11
+
10
12
  class << self
11
13
  def for_base64(data, path: nil)
12
14
  obj = new(data)
@@ -31,7 +33,7 @@ class Ollama::Image
31
33
  end
32
34
 
33
35
  def ==(other)
34
- @data == other..data
36
+ @data == other.data
35
37
  end
36
38
 
37
39
  def to_s
@@ -0,0 +1,38 @@
1
+ require 'digest/md5'
2
+
3
+ class Ollama::Utils::CacheFetcher
4
+ def initialize(cache)
5
+ @cache = cache
6
+ end
7
+
8
+ def get(url, &block)
9
+ block or raise ArgumentError, 'require block argument'
10
+ body = @cache[key(:body, url)]
11
+ content_type = @cache[key(:content_type, url)]
12
+ content_type = MIME::Types[content_type].first
13
+ if body && content_type
14
+ io = StringIO.new(body)
15
+ io.rewind
16
+ io.extend(Ollama::Utils::Fetcher::HeaderExtension)
17
+ io.content_type = content_type
18
+ block.(io)
19
+ end
20
+ end
21
+
22
+ def put(url, io)
23
+ io.rewind
24
+ body = io.read
25
+ body.empty? and return
26
+ content_type = io.content_type
27
+ content_type.nil? and return
28
+ @cache.set(key(:body, url), body, ex: io.ex)
29
+ @cache.set(key(:content_type, url), content_type.to_s, ex: io.ex)
30
+ self
31
+ end
32
+
33
+ private
34
+
35
+ def key(type, url)
36
+ [ type, Digest::MD5.hexdigest(url) ] * ?-
37
+ end
38
+ end
@@ -8,8 +8,9 @@ module Ollama::Utils::Chooser
8
8
 
9
9
  module_function
10
10
 
11
- def choose(entries)
11
+ def choose(entries, prompt: 'Search? %s')
12
12
  entry = Search.new(
13
+ prompt:,
13
14
  match: -> answer {
14
15
  matcher = Amatch::PairDistance.new(answer.downcase)
15
16
  matches = entries.map { |n| [ n, -matcher.similar(n.to_s.downcase) ] }.
@@ -19,7 +20,7 @@ module Ollama::Utils::Chooser
19
20
  },
20
21
  query: -> _answer, matches, selector {
21
22
  matches.each_with_index.map { |m, i|
22
- i == selector ? "#{blue{?⮕}} #{on_blue{m}}" : " #{m}"
23
+ i == selector ? "#{blue{?⮕}} #{on_blue{m}}" : " #{m.to_s}"
23
24
  } * ?\n
24
25
  },
25
26
  found: -> _answer, matches, selector {
@@ -27,6 +28,11 @@ module Ollama::Utils::Chooser
27
28
  },
28
29
  output: STDOUT
29
30
  ).start
30
- return entry if entry
31
+ if entry
32
+ entry
33
+ else
34
+ print clear_screen, move_home
35
+ nil
36
+ end
31
37
  end
32
38
  end
@@ -3,11 +3,14 @@ require 'tins/unit'
3
3
  require 'infobar'
4
4
  require 'mime-types'
5
5
  require 'stringio'
6
+ require 'ollama/utils/cache_fetcher'
6
7
 
7
8
  class Ollama::Utils::Fetcher
8
- module ContentType
9
+ module HeaderExtension
9
10
  attr_accessor :content_type
10
11
 
12
+ attr_accessor :ex
13
+
11
14
  def self.failed
12
15
  object = StringIO.new.extend(self)
13
16
  object.content_type = MIME::Types['text/plain'].first
@@ -17,6 +20,54 @@ class Ollama::Utils::Fetcher
17
20
 
18
21
  class RetryWithoutStreaming < StandardError; end
19
22
 
23
+ def self.get(url, **options, &block)
24
+ cache = options.delete(:cache) and
25
+ cache = Ollama::Utils::CacheFetcher.new(cache)
26
+ if result = cache&.get(url, &block)
27
+ infobar.puts "Getting #{url.to_s.inspect} from cache."
28
+ return result
29
+ else
30
+ new(**options).send(:get, url) do |tmp|
31
+ result = block.(tmp)
32
+ if cache && !tmp.is_a?(StringIO)
33
+ tmp.rewind
34
+ cache.put(url, tmp)
35
+ end
36
+ result
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.read(filename, &block)
42
+ if File.exist?(filename)
43
+ File.open(filename) do |file|
44
+ file.extend(Ollama::Utils::Fetcher::HeaderExtension)
45
+ file.content_type = MIME::Types.type_for(filename).first
46
+ block.(file)
47
+ end
48
+ end
49
+ end
50
+
51
+ def self.execute(command, &block)
52
+ Tempfile.open do |tmp|
53
+ IO.popen(command) do |command|
54
+ until command.eof?
55
+ tmp.write command.read(1 << 14)
56
+ end
57
+ tmp.rewind
58
+ tmp.extend(Ollama::Utils::Fetcher::HeaderExtension)
59
+ tmp.content_type = MIME::Types['text/plain'].first
60
+ block.(tmp)
61
+ end
62
+ end
63
+ rescue => e
64
+ STDERR.puts "Cannot execute #{command.inspect} (#{e})"
65
+ if @debug && !e.is_a?(RuntimeError)
66
+ STDERR.puts "#{e.backtrace * ?\n}"
67
+ end
68
+ yield HeaderExtension.failed
69
+ end
70
+
20
71
  def initialize(debug: false, http_options: {})
21
72
  @debug = debug
22
73
  @started = false
@@ -24,9 +75,7 @@ class Ollama::Utils::Fetcher
24
75
  @http_options = http_options
25
76
  end
26
77
 
27
- def self.get(url, **options, &block)
28
- new(**options).get(url, &block)
29
- end
78
+ private
30
79
 
31
80
  def excon(url, **options)
32
81
  Excon.new(url, options.merge(@http_options))
@@ -63,7 +112,7 @@ class Ollama::Utils::Fetcher
63
112
  if @debug && !e.is_a?(RuntimeError)
64
113
  STDERR.puts "#{e.backtrace * ?\n}"
65
114
  end
66
- yield ContentType.failed
115
+ yield HeaderExtension.failed
67
116
  end
68
117
 
69
118
  def headers
@@ -76,12 +125,20 @@ class Ollama::Utils::Fetcher
76
125
  (Excon.defaults[:middlewares] + [ Excon::Middleware::RedirectFollower ]).uniq
77
126
  end
78
127
 
128
+ private
129
+
79
130
  def decorate_io(tmp, response)
80
131
  tmp.rewind
81
- tmp.extend(ContentType)
132
+ tmp.extend(HeaderExtension)
82
133
  if content_type = MIME::Types[response.headers['content-type']].first
83
134
  tmp.content_type = content_type
84
135
  end
136
+ if cache_control = response.headers['cache-control'] and
137
+ cache_control !~ /no-store|no-cache/ and
138
+ ex = cache_control[/s-maxage\s*=\s*(\d+)/, 1] || cache_control[/max-age\s*=\s*(\d+)/, 1]
139
+ then
140
+ tmp.ex = ex.to_i
141
+ end
85
142
  end
86
143
 
87
144
  def callback(tmp)
@@ -105,34 +162,4 @@ class Ollama::Utils::Fetcher
105
162
  }
106
163
  '%l ' + progress + ' in %te, ETA %e @%E'
107
164
  end
108
-
109
- def self.read(filename, &block)
110
- if File.exist?(filename)
111
- File.open(filename) do |file|
112
- file.extend(Ollama::Utils::Fetcher::ContentType)
113
- file.content_type = MIME::Types.type_for(filename).first
114
- block.(file)
115
- end
116
- end
117
- end
118
-
119
- def self.execute(command, &block)
120
- Tempfile.open do |tmp|
121
- IO.popen(command) do |command|
122
- until command.eof?
123
- tmp.write command.read(4096)
124
- end
125
- tmp.rewind
126
- tmp.extend(Ollama::Utils::Fetcher::ContentType)
127
- tmp.content_type = MIME::Types['text/plain'].first
128
- block.(tmp)
129
- end
130
- end
131
- rescue => e
132
- STDERR.puts "Cannot execute #{command.inspect} (#{e})"
133
- if @debug && !e.is_a?(RuntimeError)
134
- STDERR.puts "#{e.backtrace * ?\n}"
135
- end
136
- yield ContentType.failed
137
- end
138
165
  end
@@ -25,8 +25,10 @@ module Ollama::Utils::FileArgument
25
25
  File.exist?(path_or_content)
26
26
  then
27
27
  File.read(path_or_content)
28
+ elsif path_or_content.present?
29
+ path_or_content
28
30
  else
29
- path_or_content.full? || default
31
+ default
30
32
  end
31
33
  end
32
34
  end
@@ -1,12 +1,66 @@
1
- require 'sorted_set'
1
+ class Ollama::Utils::Tags
2
+ class Tag < String
3
+ include Term::ANSIColor
2
4
 
5
+ def initialize(tag, source: nil)
6
+ super(tag.to_s)
7
+ self.source = source
8
+ end
3
9
 
4
- class Ollama::Utils::Tags < SortedSet
5
- def to_a
6
- super.map(&:to_s)
10
+ attr_accessor :source
11
+
12
+ alias_method :internal, :to_s
13
+
14
+ def to_s(link: true)
15
+ tag_string = start_with?(?#) ? super() : ?# + super()
16
+ my_source = source
17
+ if link && my_source
18
+ unless my_source =~ %r(\A(https?|file)://)
19
+ my_source = 'file://%s' % File.expand_path(my_source)
20
+ end
21
+ hyperlink(my_source) { tag_string }
22
+ else
23
+ tag_string
24
+ end
25
+ end
26
+ end
27
+
28
+ def initialize(tags = [], source: nil)
29
+ @set = []
30
+ tags.each { |tag| add(tag, source:) }
31
+ end
32
+
33
+ def add(tag, source: nil)
34
+ unless tag.is_a?(Tag)
35
+ tag = Tag.new(tag, source:)
36
+ end
37
+ index = @set.bsearch_index { _1 >= tag }
38
+ if index == nil
39
+ @set.push(tag)
40
+ elsif @set.at(index) != tag
41
+ @set.insert(index, tag)
42
+ end
43
+ self
44
+ end
45
+
46
+ def empty?
47
+ @set.empty?
48
+ end
49
+
50
+ def size
51
+ @set.size
52
+ end
53
+
54
+ def clear
55
+ @set.clear
56
+ end
57
+
58
+ def each(&block)
59
+ @set.each(&block)
7
60
  end
61
+ include Enumerable
8
62
 
9
- def to_s
10
- map { |t| '#%s' % t } * ' '
63
+ def to_s(link: true)
64
+ @set.map { |tag| tag.to_s(link:) } * ' '
11
65
  end
12
66
  end
@@ -2,6 +2,7 @@ require 'tins/terminal'
2
2
 
3
3
  module Ollama::Utils::Width
4
4
  include Term::ANSIColor
5
+ extend Term::ANSIColor
5
6
 
6
7
  module_function
7
8
 
@@ -26,10 +27,11 @@ module Ollama::Utils::Width
26
27
  percentage.nil? ^ length.nil? or
27
28
  raise ArgumentError, "either pass percentage or length argument"
28
29
  percentage and length ||= width(percentage:)
29
- if length < 1
30
+ ellipsis_length = ellipsis.size
31
+ if length < ellipsis_length
30
32
  +''
31
- elsif text.size > length
32
- text[0, length - 1] + ?…
33
+ elsif text.size >= length + ellipsis_length
34
+ text[0, length - ellipsis_length] + ellipsis
33
35
  else
34
36
  text
35
37
  end
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '0.5.0'
3
+ VERSION = '0.7.0'
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/lib/ollama.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require 'json'
2
2
  require 'logger'
3
3
  require 'excon'
4
+ require 'tins'
5
+ require 'tins/xt/full'
6
+ require 'tins/xt/hash_union'
7
+ require 'tins/xt/string_camelize'
4
8
 
5
9
  module Ollama
6
10
  end
data/ollama-ruby.gemspec CHANGED
@@ -1,26 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama-ruby 0.5.0 ruby lib
2
+ # stub: ollama-ruby 0.7.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "0.5.0".freeze
6
+ s.version = "0.7.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-26"
11
+ s.date = "2024-10-02"
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
- 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/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/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/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]
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]
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_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/fetcher_spec.rb".freeze, "spec/ollama/utils/file_argument_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_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]
24
24
 
25
25
  s.specification_version = 4
26
26
 
@@ -38,7 +38,6 @@ Gem::Specification.new do |s|
38
38
  s.add_runtime_dependency(%q<redis>.freeze, ["~> 5.0".freeze])
39
39
  s.add_runtime_dependency(%q<numo-narray>.freeze, ["~> 0.9".freeze])
40
40
  s.add_runtime_dependency(%q<more_math>.freeze, ["~> 1.1".freeze])
41
- s.add_runtime_dependency(%q<sorted_set>.freeze, ["~> 1.0".freeze])
42
41
  s.add_runtime_dependency(%q<mime-types>.freeze, ["~> 3.0".freeze])
43
42
  s.add_runtime_dependency(%q<reverse_markdown>.freeze, ["~> 2.0".freeze])
44
43
  s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.22".freeze])
@@ -47,4 +46,6 @@ Gem::Specification.new do |s|
47
46
  s.add_runtime_dependency(%q<pdf-reader>.freeze, ["~> 2.0".freeze])
48
47
  s.add_runtime_dependency(%q<logger>.freeze, ["~> 1.0".freeze])
49
48
  s.add_runtime_dependency(%q<json>.freeze, ["~> 2.0".freeze])
49
+ s.add_runtime_dependency(%q<xdg>.freeze, ["~> 7.0".freeze])
50
+ s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.34".freeze])
50
51
  end
@@ -9,6 +9,11 @@ RSpec.describe Ollama::Image do
9
9
  expect(image).to be_a described_class
10
10
  end
11
11
 
12
+ it 'can be equal or not' do
13
+ expect(image).not_to eq described_class.for_string('')
14
+ expect(image).to eq described_class.for_filename(asset('kitten.jpg'))
15
+ end
16
+
12
17
  it 'cannot be created via .new' do
13
18
  expect {
14
19
  described_class.new('nix')
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ollama::Utils::CacheFetcher do
4
+ let :url do
5
+ 'https://www.example.com/hello'
6
+ end
7
+
8
+ let :cache do
9
+ double('RedisCache')
10
+ end
11
+
12
+ let :fetcher do
13
+ described_class.new(cache).expose
14
+ end
15
+
16
+ it 'can be instantiated' do
17
+ expect(fetcher).to be_a described_class
18
+ end
19
+
20
+ it 'has #get' do
21
+ expect(cache).to receive(:[]).with('body-69ce405ab83f42dffa9fd22bbd47783f').and_return 'world'
22
+ expect(cache).to receive(:[]).with('content_type-69ce405ab83f42dffa9fd22bbd47783f').and_return 'text/plain'
23
+ yielded_io = nil
24
+ block = -> io { yielded_io = io }
25
+ fetcher.get(url, &block)
26
+ expect(yielded_io).to be_a StringIO
27
+ expect(yielded_io.read).to eq 'world'
28
+ end
29
+
30
+ it '#get needs block' do
31
+ expect { fetcher.get(url) }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it 'has #put' do
35
+ io = StringIO.new('world')
36
+ io.extend(Ollama::Utils::Fetcher::HeaderExtension)
37
+ io.content_type = MIME::Types['text/plain'].first
38
+ io.ex = 666
39
+ expect(cache).to receive(:set).with('body-69ce405ab83f42dffa9fd22bbd47783f', 'world', ex: 666)
40
+ expect(cache).to receive(:set).with('content_type-69ce405ab83f42dffa9fd22bbd47783f', 'text/plain', ex: 666)
41
+ fetcher.put(url, io)
42
+ end
43
+ end