ollama-ruby 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/docker-compose.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  services:
2
2
  redis:
3
- image: redis:7.2.5-alpine
3
+ image: valkey/valkey:7.2.7-alpine
4
4
  restart: unless-stopped
5
5
  ports: [ "127.0.0.1:9736:6379" ]
6
6
  volumes:
@@ -55,8 +55,9 @@ class Ollama::Documents
55
55
  @cache.prefix = prefix
56
56
  end
57
57
 
58
- def add(inputs, batch_size: 10, source: nil, tags: [])
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
@@ -45,6 +45,8 @@ class Ollama::Utils::Fetcher
45
45
  file.content_type = MIME::Types.type_for(filename).first
46
46
  block.(file)
47
47
  end
48
+ else
49
+ STDERR.puts "File #{filename.to_s.inspect} doesn't exist."
48
50
  end
49
51
  end
50
52
 
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '0.7.0'
3
+ VERSION = '0.9.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/ollama-ruby.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama-ruby 0.7.0 ruby lib
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.7.0".freeze
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-02"
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.18.0".freeze])
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])
@@ -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
- allow(excon).to receive(:post).and_raise Excon::Error::Socket
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
- allow(excon).to receive(:post).and_raise Excon::Errors::Timeout
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
- allow(excon).to receive(:post).and_raise Excon::Errors::Error
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)
@@ -78,7 +78,7 @@ RSpec.describe Ollama::Documents::RedisBackedMemoryCache do
78
78
  end
79
79
 
80
80
  it 'returns size' do
81
- allow(cache).to receive(:count).and_return 3
81
+ expect(cache).to receive(:count).and_return 3
82
82
  expect(cache.size).to eq 3
83
83
  end
84
84
 
@@ -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
- allow(redis).to receive(:ttl).with('test-' + key).and_return 3_600
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
- allow(ollama).to receive(:embed).
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
- allow(ollama).to receive(:embed).
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
- allow(ollama).to receive(:embed).
80
+ expect(ollama).to receive(:embed).
81
81
  with(model:, input: [ 'foobar' ], options: nil).
82
82
  and_return(double(embeddings: [ [ 0.01 ] ]))
83
- allow(ollama).to receive(:embed).
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
- allow(ollama).to receive(:embed).
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
- allow(IO).to receive(:popen).and_raise StandardError
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.7.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-02 00:00:00.000000000 Z
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.18.0
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.18.0
26
+ version: '1.19'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: all_images
29
29
  requirement: !ruby/object:Gem::Requirement