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.
@@ -6,7 +6,7 @@ RSpec.describe Ollama::Utils::Fetcher do
6
6
  end
7
7
 
8
8
  let :fetcher do
9
- described_class.new
9
+ described_class.new.expose
10
10
  end
11
11
 
12
12
  it 'can be instantiated' do
@@ -36,7 +36,7 @@ RSpec.describe Ollama::Utils::Fetcher do
36
36
  it 'can #get without ssl peer verification' do
37
37
  fetcher = described_class.new(
38
38
  http_options: { ssl_verify_peer: false }
39
- )
39
+ ).expose
40
40
  stub_request(:get, 'https://www.example.com/hello').
41
41
  with(headers: fetcher.headers).
42
42
  to_return(
@@ -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
- tags.merge %w[ baz baz2 ]
18
- expect(tags.to_a).to eq %w[ bar baz baz2 foo ]
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
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,7 @@ if ENV['START_SIMPLECOV'].to_i == 1
5
5
  end
6
6
  end
7
7
  require 'rspec'
8
+ require 'tins/xt/expose'
8
9
  begin
9
10
  require 'debug'
10
11
  rescue LoadError
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.5.0
4
+ version: 0.7.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-09-26 00:00:00.000000000 Z
11
+ date: 2024-10-02 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
@@ -332,6 +318,34 @@ dependencies:
332
318
  - - "~>"
333
319
  - !ruby/object:Gem::Version
334
320
  version: '2.0'
321
+ - !ruby/object:Gem::Dependency
322
+ name: xdg
323
+ requirement: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - "~>"
326
+ - !ruby/object:Gem::Version
327
+ version: '7.0'
328
+ type: :runtime
329
+ prerelease: false
330
+ version_requirements: !ruby/object:Gem::Requirement
331
+ requirements:
332
+ - - "~>"
333
+ - !ruby/object:Gem::Version
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'
335
349
  description: Library that allows interacting with the Ollama API
336
350
  email: flori@ping.de
337
351
  executables:
@@ -387,6 +401,7 @@ extra_rdoc_files:
387
401
  - lib/ollama/tool/function/parameters.rb
388
402
  - lib/ollama/tool/function/parameters/property.rb
389
403
  - lib/ollama/utils/ansi_markdown.rb
404
+ - lib/ollama/utils/cache_fetcher.rb
390
405
  - lib/ollama/utils/chooser.rb
391
406
  - lib/ollama/utils/colorize_texts.rb
392
407
  - lib/ollama/utils/fetcher.rb
@@ -453,6 +468,7 @@ files:
453
468
  - lib/ollama/tool/function/parameters.rb
454
469
  - lib/ollama/tool/function/parameters/property.rb
455
470
  - lib/ollama/utils/ansi_markdown.rb
471
+ - lib/ollama/utils/cache_fetcher.rb
456
472
  - lib/ollama/utils/chooser.rb
457
473
  - lib/ollama/utils/colorize_texts.rb
458
474
  - lib/ollama/utils/fetcher.rb
@@ -499,9 +515,11 @@ files:
499
515
  - spec/ollama/options_spec.rb
500
516
  - spec/ollama/tool_spec.rb
501
517
  - spec/ollama/utils/ansi_markdown_spec.rb
518
+ - spec/ollama/utils/cache_fetcher_spec.rb
502
519
  - spec/ollama/utils/fetcher_spec.rb
503
520
  - spec/ollama/utils/file_argument_spec.rb
504
521
  - spec/ollama/utils/tags_spec.rb
522
+ - spec/ollama/utils/width_spec.rb
505
523
  - spec/spec_helper.rb
506
524
  - tmp/.keep
507
525
  homepage: https://github.com/flori/ollama-ruby
@@ -566,7 +584,9 @@ test_files:
566
584
  - spec/ollama/options_spec.rb
567
585
  - spec/ollama/tool_spec.rb
568
586
  - spec/ollama/utils/ansi_markdown_spec.rb
587
+ - spec/ollama/utils/cache_fetcher_spec.rb
569
588
  - spec/ollama/utils/fetcher_spec.rb
570
589
  - spec/ollama/utils/file_argument_spec.rb
571
590
  - spec/ollama/utils/tags_spec.rb
591
+ - spec/ollama/utils/width_spec.rb
572
592
  - spec/spec_helper.rb