ollama-ruby 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +153 -110
- data/README.md +168 -166
- data/bin/ollama_chat +134 -76
- data/docker-compose.yml +1 -1
- data/lib/ollama/documents.rb +2 -1
- data/lib/ollama/handlers/markdown.rb +1 -2
- data/lib/ollama/utils/fetcher.rb +2 -0
- data/lib/ollama/version.rb +1 -1
- data/ollama-ruby.gemspec +4 -4
- data/spec/ollama/client_spec.rb +3 -3
- data/spec/ollama/documents/redis_backed_memory_cache_spec.rb +1 -1
- data/spec/ollama/documents/redis_cache_spec.rb +1 -1
- data/spec/ollama/documents_spec.rb +5 -5
- data/spec/ollama/handlers/markdown_spec.rb +0 -2
- data/spec/ollama/utils/fetcher_spec.rb +1 -1
- metadata +4 -4
data/docker-compose.yml
CHANGED
data/lib/ollama/documents.rb
CHANGED
@@ -55,8 +55,9 @@ class Ollama::Documents
|
|
55
55
|
@cache.prefix = prefix
|
56
56
|
end
|
57
57
|
|
58
|
-
def add(inputs, batch_size:
|
58
|
+
def add(inputs, batch_size: nil, source: nil, tags: [])
|
59
59
|
inputs = Array(inputs)
|
60
|
+
batch_size ||= 10
|
60
61
|
tags = Ollama::Utils::Tags.new(tags, source:)
|
61
62
|
if source
|
62
63
|
tags.add(File.basename(source).gsub(/\?.*/, ''), source:)
|
@@ -7,7 +7,7 @@ class Ollama::Handlers::Markdown
|
|
7
7
|
def initialize(output: $stdout)
|
8
8
|
super
|
9
9
|
@output.sync = true
|
10
|
-
@content
|
10
|
+
@content = ''
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(response)
|
@@ -16,7 +16,6 @@ class Ollama::Handlers::Markdown
|
|
16
16
|
markdown_content = Ollama::Utils::ANSIMarkdown.parse(@content)
|
17
17
|
@output.print clear_screen, move_home, markdown_content
|
18
18
|
end
|
19
|
-
response.done and @output.puts
|
20
19
|
self
|
21
20
|
end
|
22
21
|
end
|
data/lib/ollama/utils/fetcher.rb
CHANGED
data/lib/ollama/version.rb
CHANGED
data/ollama-ruby.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: ollama-ruby 0.
|
2
|
+
# stub: ollama-ruby 0.9.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.9.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-10-
|
11
|
+
s.date = "2024-10-18"
|
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]
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.specification_version = 4
|
26
26
|
|
27
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.
|
27
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.19".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
30
|
s.add_development_dependency(%q<webmock>.freeze, [">= 0".freeze])
|
data/spec/ollama/client_spec.rb
CHANGED
@@ -54,21 +54,21 @@ RSpec.describe Ollama::Client do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'can raise error on connection error' do
|
57
|
-
|
57
|
+
expect(excon).to receive(:post).and_raise Excon::Error::Socket
|
58
58
|
expect {
|
59
59
|
ollama.generate(model: 'llama3.1', prompt: 'Hello World')
|
60
60
|
}.to raise_error(Ollama::Errors::SocketError)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'can raise error on timeout' do
|
64
|
-
|
64
|
+
expect(excon).to receive(:post).and_raise Excon::Errors::Timeout
|
65
65
|
expect {
|
66
66
|
ollama.generate(model: 'llama3.1', prompt: 'Hello World')
|
67
67
|
}.to raise_error(Ollama::Errors::TimeoutError)
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'can raise a generic error' do
|
71
|
-
|
71
|
+
expect(excon).to receive(:post).and_raise Excon::Errors::Error
|
72
72
|
expect {
|
73
73
|
ollama.generate(model: 'llama3.1', prompt: 'Hello World')
|
74
74
|
}.to raise_error(Ollama::Errors::Error)
|
@@ -57,7 +57,7 @@ RSpec.describe Ollama::Documents::RedisCache do
|
|
57
57
|
key, value = 'foo', { test: true }
|
58
58
|
expect(redis).to receive(:set).with('test-' + key, JSON(value), ex: 3_600)
|
59
59
|
cache[key] = value
|
60
|
-
|
60
|
+
expect(redis).to receive(:ttl).with('test-' + key).and_return 3_600
|
61
61
|
expect(cache.ttl(key)).to eq 3_600
|
62
62
|
end
|
63
63
|
|
@@ -42,7 +42,7 @@ RSpec.describe Ollama::Documents do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'can find strings' do
|
45
|
-
|
45
|
+
expect(ollama).to receive(:embed).
|
46
46
|
with(model:, input: [ 'foo' ], options: nil).
|
47
47
|
and_return(double(embeddings: [ [ 0.1 ] ]))
|
48
48
|
expect(documents << 'foo').to eq documents
|
@@ -57,7 +57,7 @@ RSpec.describe Ollama::Documents do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'can find only tagged strings' do
|
60
|
-
|
60
|
+
expect(ollama).to receive(:embed).
|
61
61
|
with(model:, input: [ 'foo' ], options: nil).
|
62
62
|
and_return(double(embeddings: [ [ 0.1 ] ]))
|
63
63
|
expect(documents.add('foo', tags: %i[ test ])).to eq documents
|
@@ -77,10 +77,10 @@ RSpec.describe Ollama::Documents do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'can find strings conditionally' do
|
80
|
-
|
80
|
+
expect(ollama).to receive(:embed).
|
81
81
|
with(model:, input: [ 'foobar' ], options: nil).
|
82
82
|
and_return(double(embeddings: [ [ 0.01 ] ]))
|
83
|
-
|
83
|
+
expect(ollama).to receive(:embed).
|
84
84
|
with(model:, input: [ 'foo' ], options: nil).
|
85
85
|
and_return(double(embeddings: [ [ 0.1 ] ]))
|
86
86
|
expect(documents << 'foobar').to eq documents
|
@@ -132,7 +132,7 @@ RSpec.describe Ollama::Documents do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'can clear texts with tags' do
|
135
|
-
|
135
|
+
expect(ollama).to receive(:embed).
|
136
136
|
with(model:, input: %w[ bar ], options: nil).
|
137
137
|
and_return(double(embeddings: [ [ 0.1 ] ]))
|
138
138
|
expect(documents.add('foo', tags: %i[ test ])).to eq documents
|
@@ -25,7 +25,6 @@ RSpec.describe Ollama::Handlers::Markdown do
|
|
25
25
|
it 'can markdown response as markdown' do
|
26
26
|
output = double('output', :sync= => true)
|
27
27
|
expect(output).to receive(:print).with("\e[2J", "\e[1;1H", ansi)
|
28
|
-
expect(output).to receive(:puts)
|
29
28
|
markdown = described_class.new(output:)
|
30
29
|
response = double('response', response: md, done: false)
|
31
30
|
markdown.call(response)
|
@@ -36,7 +35,6 @@ RSpec.describe Ollama::Handlers::Markdown do
|
|
36
35
|
it 'can markdown message content as markdown' do
|
37
36
|
output = double('output', :sync= => true)
|
38
37
|
expect(output).to receive(:print).with("\e[2J", "\e[1;1H", ansi)
|
39
|
-
expect(output).to receive(:puts)
|
40
38
|
markdown = described_class.new(output:)
|
41
39
|
response = double('response', response: nil, message: double(content: md), done: false)
|
42
40
|
markdown.call(response)
|
@@ -105,7 +105,7 @@ RSpec.describe Ollama::Utils::Fetcher do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'can .execute and fail' do
|
108
|
-
|
108
|
+
expect(IO).to receive(:popen).and_raise StandardError
|
109
109
|
described_class.execute('foobar') do |file|
|
110
110
|
expect(file).to be_a StringIO
|
111
111
|
expect(file.read).to be_empty
|
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.9.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-10-
|
11
|
+
date: 2024-10-18 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.
|
19
|
+
version: '1.19'
|
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.
|
26
|
+
version: '1.19'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: all_images
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|