ollama-ruby 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +166 -57
- data/README.md +6 -3
- data/Rakefile +1 -1
- data/bin/ollama_chat +163 -63
- data/bin/ollama_cli +3 -3
- data/bin/ollama_update +2 -0
- data/docker-compose.yml +1 -1
- data/lib/ollama/client.rb +0 -3
- data/lib/ollama/documents/cache/redis_cache.rb +11 -1
- data/lib/ollama/documents.rb +13 -6
- data/lib/ollama/image.rb +3 -1
- data/lib/ollama/utils/cache_fetcher.rb +3 -3
- data/lib/ollama/utils/chooser.rb +9 -3
- data/lib/ollama/utils/fetcher.rb +20 -8
- data/lib/ollama/utils/tags.rb +60 -6
- data/lib/ollama/utils/width.rb +5 -3
- data/lib/ollama/version.rb +1 -1
- data/lib/ollama.rb +4 -0
- data/ollama-ruby.gemspec +6 -6
- data/spec/ollama/image_spec.rb +5 -0
- data/spec/ollama/utils/cache_fetcher_spec.rb +4 -3
- data/spec/ollama/utils/tags_spec.rb +26 -2
- data/spec/ollama/utils/width_spec.rb +82 -0
- metadata +18 -16
data/lib/ollama/utils/fetcher.rb
CHANGED
@@ -6,9 +6,11 @@ require 'stringio'
|
|
6
6
|
require 'ollama/utils/cache_fetcher'
|
7
7
|
|
8
8
|
class Ollama::Utils::Fetcher
|
9
|
-
module
|
9
|
+
module HeaderExtension
|
10
10
|
attr_accessor :content_type
|
11
11
|
|
12
|
+
attr_accessor :ex
|
13
|
+
|
12
14
|
def self.failed
|
13
15
|
object = StringIO.new.extend(self)
|
14
16
|
object.content_type = MIME::Types['text/plain'].first
|
@@ -22,7 +24,7 @@ class Ollama::Utils::Fetcher
|
|
22
24
|
cache = options.delete(:cache) and
|
23
25
|
cache = Ollama::Utils::CacheFetcher.new(cache)
|
24
26
|
if result = cache&.get(url, &block)
|
25
|
-
infobar.puts "Getting #{url.inspect} from cache."
|
27
|
+
infobar.puts "Getting #{url.to_s.inspect} from cache."
|
26
28
|
return result
|
27
29
|
else
|
28
30
|
new(**options).send(:get, url) do |tmp|
|
@@ -39,10 +41,12 @@ class Ollama::Utils::Fetcher
|
|
39
41
|
def self.read(filename, &block)
|
40
42
|
if File.exist?(filename)
|
41
43
|
File.open(filename) do |file|
|
42
|
-
file.extend(Ollama::Utils::Fetcher::
|
44
|
+
file.extend(Ollama::Utils::Fetcher::HeaderExtension)
|
43
45
|
file.content_type = MIME::Types.type_for(filename).first
|
44
46
|
block.(file)
|
45
47
|
end
|
48
|
+
else
|
49
|
+
STDERR.puts "File #{filename.to_s.inspect} doesn't exist."
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
@@ -50,10 +54,10 @@ class Ollama::Utils::Fetcher
|
|
50
54
|
Tempfile.open do |tmp|
|
51
55
|
IO.popen(command) do |command|
|
52
56
|
until command.eof?
|
53
|
-
tmp.write command.read(
|
57
|
+
tmp.write command.read(1 << 14)
|
54
58
|
end
|
55
59
|
tmp.rewind
|
56
|
-
tmp.extend(Ollama::Utils::Fetcher::
|
60
|
+
tmp.extend(Ollama::Utils::Fetcher::HeaderExtension)
|
57
61
|
tmp.content_type = MIME::Types['text/plain'].first
|
58
62
|
block.(tmp)
|
59
63
|
end
|
@@ -63,7 +67,7 @@ class Ollama::Utils::Fetcher
|
|
63
67
|
if @debug && !e.is_a?(RuntimeError)
|
64
68
|
STDERR.puts "#{e.backtrace * ?\n}"
|
65
69
|
end
|
66
|
-
yield
|
70
|
+
yield HeaderExtension.failed
|
67
71
|
end
|
68
72
|
|
69
73
|
def initialize(debug: false, http_options: {})
|
@@ -110,7 +114,7 @@ class Ollama::Utils::Fetcher
|
|
110
114
|
if @debug && !e.is_a?(RuntimeError)
|
111
115
|
STDERR.puts "#{e.backtrace * ?\n}"
|
112
116
|
end
|
113
|
-
yield
|
117
|
+
yield HeaderExtension.failed
|
114
118
|
end
|
115
119
|
|
116
120
|
def headers
|
@@ -123,12 +127,20 @@ class Ollama::Utils::Fetcher
|
|
123
127
|
(Excon.defaults[:middlewares] + [ Excon::Middleware::RedirectFollower ]).uniq
|
124
128
|
end
|
125
129
|
|
130
|
+
private
|
131
|
+
|
126
132
|
def decorate_io(tmp, response)
|
127
133
|
tmp.rewind
|
128
|
-
tmp.extend(
|
134
|
+
tmp.extend(HeaderExtension)
|
129
135
|
if content_type = MIME::Types[response.headers['content-type']].first
|
130
136
|
tmp.content_type = content_type
|
131
137
|
end
|
138
|
+
if cache_control = response.headers['cache-control'] and
|
139
|
+
cache_control !~ /no-store|no-cache/ and
|
140
|
+
ex = cache_control[/s-maxage\s*=\s*(\d+)/, 1] || cache_control[/max-age\s*=\s*(\d+)/, 1]
|
141
|
+
then
|
142
|
+
tmp.ex = ex.to_i
|
143
|
+
end
|
132
144
|
end
|
133
145
|
|
134
146
|
def callback(tmp)
|
data/lib/ollama/utils/tags.rb
CHANGED
@@ -1,12 +1,66 @@
|
|
1
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
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 { |
|
63
|
+
def to_s(link: true)
|
64
|
+
@set.map { |tag| tag.to_s(link:) } * ' '
|
11
65
|
end
|
12
66
|
end
|
data/lib/ollama/utils/width.rb
CHANGED
@@ -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
|
-
|
30
|
+
ellipsis_length = ellipsis.size
|
31
|
+
if length < ellipsis_length
|
30
32
|
+''
|
31
|
-
elsif text.size
|
32
|
-
text[0, length -
|
33
|
+
elsif text.size >= length + ellipsis_length
|
34
|
+
text[0, length - ellipsis_length] + ellipsis
|
33
35
|
else
|
34
36
|
text
|
35
37
|
end
|
data/lib/ollama/version.rb
CHANGED
data/lib/ollama.rb
CHANGED
data/ollama-ruby.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: ollama-ruby 0.
|
2
|
+
# stub: ollama-ruby 0.8.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "ollama-ruby".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.8.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-
|
11
|
+
s.date = "2024-10-06"
|
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/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/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/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/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])
|
@@ -48,4 +47,5 @@ Gem::Specification.new do |s|
|
|
48
47
|
s.add_runtime_dependency(%q<logger>.freeze, ["~> 1.0".freeze])
|
49
48
|
s.add_runtime_dependency(%q<json>.freeze, ["~> 2.0".freeze])
|
50
49
|
s.add_runtime_dependency(%q<xdg>.freeze, ["~> 7.0".freeze])
|
50
|
+
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.34".freeze])
|
51
51
|
end
|
data/spec/ollama/image_spec.rb
CHANGED
@@ -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')
|
@@ -33,10 +33,11 @@ RSpec.describe Ollama::Utils::CacheFetcher do
|
|
33
33
|
|
34
34
|
it 'has #put' do
|
35
35
|
io = StringIO.new('world')
|
36
|
-
io.extend(Ollama::Utils::Fetcher::
|
36
|
+
io.extend(Ollama::Utils::Fetcher::HeaderExtension)
|
37
37
|
io.content_type = MIME::Types['text/plain'].first
|
38
|
-
|
39
|
-
expect(cache).to receive(:
|
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)
|
40
41
|
fetcher.put(url, io)
|
41
42
|
end
|
42
43
|
end
|
@@ -14,11 +14,35 @@ 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
|
-
|
18
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can increase in size' do
|
20
|
+
tags = described_class.new
|
21
|
+
expect { tags.add 'foo' }.to change { tags.size }.from(0).to(1)
|
22
|
+
expect { tags.add 'bar' }.to change { tags.size }.from(1).to(2)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'can be cleared' do
|
26
|
+
tags = described_class.new([ 'foo', 'bar' ])
|
27
|
+
expect { tags.clear }.to change { tags.size }.from(2).to(0)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'tags can be empt' do
|
31
|
+
tags = described_class.new([ 'foo' ])
|
32
|
+
expect { tags.clear }.to change { tags.empty? }.from(false).to(true)
|
19
33
|
end
|
20
34
|
|
21
35
|
it 'can be output nicely' do
|
22
36
|
expect(described_class.new(%w[ foo bar ]).to_s).to eq '#bar #foo'
|
23
37
|
end
|
38
|
+
|
39
|
+
it 'can be output nicely with links to source' do
|
40
|
+
tags = described_class.new([ 'foo' ], source: 'https://foo.example.com')
|
41
|
+
tags.add 'bar', source: '/path/to/bar.html'
|
42
|
+
expect(tags.to_a).to eq %w[ bar foo ]
|
43
|
+
tags.all? { expect(_1).to be_a(Ollama::Utils::Tags::Tag) }
|
44
|
+
expect(tags.to_s).to eq(
|
45
|
+
"\e]8;;file:///path/to/bar.html\e\\#bar\e]8;;\e\\ \e]8;;https://foo.example.com\e\\#foo\e]8;;\e\\"
|
46
|
+
)
|
47
|
+
end
|
24
48
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Ollama::Utils::Width do
|
4
|
+
before do
|
5
|
+
allow(Tins::Terminal).to receive(:columns).and_return 80
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.width' do
|
9
|
+
it 'defaults to 100%' do
|
10
|
+
expect(described_class.width).to eq 80
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can be to 80%' do
|
14
|
+
expect(described_class.width(percentage: 80)).to eq 64
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.wrap' do
|
19
|
+
it 'can wrap with percentage' do
|
20
|
+
wrapped = described_class.wrap([ ?A * 10 ] * 10 * ' ', percentage: 80)
|
21
|
+
expect(wrapped).to eq(
|
22
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA\n"\
|
23
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA"
|
24
|
+
)
|
25
|
+
expect(wrapped.size).to eq 109
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'can wrap with length' do
|
29
|
+
wrapped = described_class.wrap([ ?A * 10 ] * 10 * ' ', length: 64)
|
30
|
+
expect(wrapped).to eq(
|
31
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA\n"\
|
32
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA"
|
33
|
+
)
|
34
|
+
expect(wrapped.size).to eq 109
|
35
|
+
end
|
36
|
+
|
37
|
+
it "doesn't wrap with length 0" do
|
38
|
+
wrapped = described_class.wrap([ ?A * 10 ] * 10 * ' ', length: 0)
|
39
|
+
expect(wrapped).to eq(
|
40
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA "\
|
41
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA"
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '.truncate' do
|
47
|
+
it 'can truncate with percentage' do
|
48
|
+
truncated = described_class.truncate([ ?A * 10 ] * 10 * ' ', percentage: 80)
|
49
|
+
expect(truncated).to eq(
|
50
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAA…"
|
51
|
+
)
|
52
|
+
expect(truncated.size).to eq 64
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can truncate with length' do
|
56
|
+
truncated = described_class.truncate([ ?A * 10 ] * 10 * ' ', length: 64)
|
57
|
+
expect(truncated).to eq(
|
58
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAA…"
|
59
|
+
)
|
60
|
+
expect(truncated.size).to eq 64
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'cannot truncate if not necessary' do
|
64
|
+
text = [ ?A * 10 ] * 5 * ' '
|
65
|
+
truncated = described_class.truncate(text, length: 54)
|
66
|
+
expect(truncated).to eq text
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'can truncate with length 0' do
|
70
|
+
truncated = described_class.truncate([ ?A * 10 ] * 10 * ' ', length: 0)
|
71
|
+
expect(truncated).to be_empty
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can truncate with ...' do
|
75
|
+
truncated = described_class.truncate([ ?A * 10 ] * 10 * ' ', length: 64, ellipsis: '...')
|
76
|
+
expect(truncated).to eq(
|
77
|
+
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAA..."
|
78
|
+
)
|
79
|
+
expect(truncated.size).to eq 64
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ollama-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -206,20 +206,6 @@ dependencies:
|
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '1.1'
|
209
|
-
- !ruby/object:Gem::Dependency
|
210
|
-
name: sorted_set
|
211
|
-
requirement: !ruby/object:Gem::Requirement
|
212
|
-
requirements:
|
213
|
-
- - "~>"
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
version: '1.0'
|
216
|
-
type: :runtime
|
217
|
-
prerelease: false
|
218
|
-
version_requirements: !ruby/object:Gem::Requirement
|
219
|
-
requirements:
|
220
|
-
- - "~>"
|
221
|
-
- !ruby/object:Gem::Version
|
222
|
-
version: '1.0'
|
223
209
|
- !ruby/object:Gem::Dependency
|
224
210
|
name: mime-types
|
225
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -346,6 +332,20 @@ dependencies:
|
|
346
332
|
- - "~>"
|
347
333
|
- !ruby/object:Gem::Version
|
348
334
|
version: '7.0'
|
335
|
+
- !ruby/object:Gem::Dependency
|
336
|
+
name: tins
|
337
|
+
requirement: !ruby/object:Gem::Requirement
|
338
|
+
requirements:
|
339
|
+
- - "~>"
|
340
|
+
- !ruby/object:Gem::Version
|
341
|
+
version: '1.34'
|
342
|
+
type: :runtime
|
343
|
+
prerelease: false
|
344
|
+
version_requirements: !ruby/object:Gem::Requirement
|
345
|
+
requirements:
|
346
|
+
- - "~>"
|
347
|
+
- !ruby/object:Gem::Version
|
348
|
+
version: '1.34'
|
349
349
|
description: Library that allows interacting with the Ollama API
|
350
350
|
email: flori@ping.de
|
351
351
|
executables:
|
@@ -519,6 +519,7 @@ files:
|
|
519
519
|
- spec/ollama/utils/fetcher_spec.rb
|
520
520
|
- spec/ollama/utils/file_argument_spec.rb
|
521
521
|
- spec/ollama/utils/tags_spec.rb
|
522
|
+
- spec/ollama/utils/width_spec.rb
|
522
523
|
- spec/spec_helper.rb
|
523
524
|
- tmp/.keep
|
524
525
|
homepage: https://github.com/flori/ollama-ruby
|
@@ -587,4 +588,5 @@ test_files:
|
|
587
588
|
- spec/ollama/utils/fetcher_spec.rb
|
588
589
|
- spec/ollama/utils/file_argument_spec.rb
|
589
590
|
- spec/ollama/utils/tags_spec.rb
|
591
|
+
- spec/ollama/utils/width_spec.rb
|
590
592
|
- spec/spec_helper.rb
|