ollama-ruby 1.15.0 → 1.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e83f50382169132ae2774add6050e16e36bd9af29b5aca839007c0d48f0c51c0
4
- data.tar.gz: 5b1d915ea8bbf426d4f2ae08556533e1c78e4483857a8d649b96e9f668857491
3
+ metadata.gz: 11d1c6bcf5eaea08074bbba02d8f7044f6b4c234287dde118443f4f886f275ae
4
+ data.tar.gz: 9004c648dd62e4a71b0f35ddd31d3944123e10dfae856314e6c8f57ed3dbdb34
5
5
  SHA512:
6
- metadata.gz: 9b0e7e583bcf8baa2fa5050ba84e1b94b890ed3d2fa8b871c72bb3a4dcf15f64ecebb6e665a6e7e49dc0f08e030cf5f5db5d0874f42f7f2f917572e03ed24672
7
- data.tar.gz: edae6c2a87f761b36fa0615073a999ba16451a3558a67d1d114f7cf510cdafaf44062ced275d21f1ea807c3badd0e3ae9d5fa4fc0b62cb8358bdf78bcbca9f44
6
+ metadata.gz: 8cab524ff7ecee59b700184b5194cc207ff54bfb22ff00467e80df37433822cee2cf19ddaefc75f7f41a269b538f9bb6fb617d1846c1d3f11176d8ffc9838e37
7
+ data.tar.gz: 7e7a30b30c2b581f34f30ccef4caa3f52a40ab9bf6e9a2f3e57c2830741cf6a3057d8f77db338213e15a9a54bcf4a0645739f3bf4dc41d8a422f8cee1c0bbd35
data/CHANGES.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-12-19 v1.17.0
4
+
5
+ - Changed `s.required_ruby_version` in the gemspec from "~> 3.1" to ">= 3.1" to allow usage with **Ruby 3.1** and higher, including **4.0**
6
+ - Updated `s.rubygems_version` from **3.7.2** to **4.0.2**
7
+ - Replaced `bundle update` with `bundle update --all` in the update command
8
+ - Added **4.0-rc** release candidate to the Ruby version matrix (commented out)
9
+ - Enhanced `Ollama::Options` class with detailed inline comments for all
10
+ configuration parameters including `numa`, `num_ctx`, `num_batch`, `num_gpu`,
11
+ `main_gpu`, `low_vram`, `f16_kv`, `logits_all`, `vocab_only`, `use_mmap`,
12
+ `use_mlock`, `num_thread`, `num_keep`, `seed`, `num_predict`, `top_k`,
13
+ `top_p`, `min_p`, `tfs_z`, `typical_p`, `repeat_last_n`, `temperature`,
14
+ `repeat_penalty`, `presence_penalty`, `frequency_penalty`, `mirostat`,
15
+ `mirostat_tau`, `mirostat_eta`, `penalize_newline`, and `stop`
16
+ - Updated documentation link format from `.md` to `.mdx`
17
+
18
+ ## 2025-12-09 v1.16.0
19
+
20
+ - Added support for handling HTTP 400 Bad Request errors
21
+ - Introduced new error class `Ollama::Errors::BadRequestError` for 400 status
22
+ codes
23
+ - Updated `Ollama::Client#request` method to raise `BadRequestError` for 400
24
+ responses
25
+ - Added test case in `spec/ollama/client_spec.rb` to verify 400 status code
26
+ handling
27
+ - Documented the new error class with example usage for think mode errors
28
+ - Maintained existing error handling for 404 and other status codes
29
+
3
30
  ## 2025-12-04 v1.15.0
4
31
 
5
32
  - Added documentation for `ollama_ps` executable utility in README
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ GemHadar do
25
25
  'static.yml' => {}
26
26
  )
27
27
 
28
- required_ruby_version '~> 3.1'
28
+ required_ruby_version '>= 3.1'
29
29
 
30
30
  dependency 'excon', '~> 1.0'
31
31
  dependency 'infobar', '~> 0.8'
data/lib/ollama/client.rb CHANGED
@@ -173,6 +173,8 @@ class Ollama::Client
173
173
  response_line = parse_json(l)
174
174
  response_line and yielder.yield response_line
175
175
  end
176
+ when 400
177
+ raise Ollama::Errors::BadRequestError, "#{response.status} #{response.body.inspect}"
176
178
  when 404
177
179
  raise Ollama::Errors::NotFoundError, "#{response.status} #{response.body.inspect}"
178
180
  else
data/lib/ollama/errors.rb CHANGED
@@ -29,6 +29,22 @@ module Ollama
29
29
  class NotFoundError < Error
30
30
  end
31
31
 
32
+ # Ollama error class for handling cases where a requested resource is not
33
+ # found.
34
+ #
35
+ # This exception is raised when the Ollama API returns a 400 status code,
36
+ # indicating that the request was bad, e. g. think mode was requested from
37
+ # a non-thinking model.
38
+ #
39
+ # @example Handling a bad request error
40
+ # begin
41
+ # ollama.generate(model: 'llama3.1', prompt: 'Hello World', think: true)
42
+ # rescue Ollama::Errors::BadRequestError
43
+ # puts "Thinking not supported"
44
+ # end
45
+ class BadRequestError < Error
46
+ end
47
+
32
48
  # Ollama error class for handling timeout errors when communicating with
33
49
  # the Ollama API.
34
50
  #
@@ -15,41 +15,102 @@ require 'ollama/json_loader'
15
15
  # top_p: 0.9
16
16
  # )
17
17
  #
18
- # [Options are explained in the parameters for the modelfile.](https://github.com/ollama/ollama/blob/main/docs/modelfile.md#parameter)
18
+ # [Options are explained in the parameters for the modelfile.](https://github.com/ollama/ollama/blob/main/docs/modelfile.mdx)
19
19
  class Ollama::Options
20
20
  include Ollama::DTO
21
21
  extend Ollama::JSONLoader
22
22
 
23
+ # Hash defining the valid types for each configuration parameter
24
+ # This is used for type validation in the setter methods
23
25
  @@types = {
26
+ # NUMA (Non-Uniform Memory Access) support - enables NUMA awareness
24
27
  numa: [ false, true ],
28
+
29
+ # Context window size - maximum context length for the model
25
30
  num_ctx: Integer,
31
+
32
+ # Batch size for processing - number of tokens to process together
26
33
  num_batch: Integer,
34
+
35
+ # Number of GPUs to use - specifies how many GPU devices to utilize
27
36
  num_gpu: Integer,
37
+
38
+ # Main GPU index - specifies which GPU to use as the primary device
28
39
  main_gpu: Integer,
40
+
41
+ # Low VRAM mode - reduces memory usage at the cost of performance
29
42
  low_vram: [ false, true ],
43
+
44
+ # Use FP16 for KV cache - enables half-precision floating point for key-value cache
30
45
  f16_kv: [ false, true ],
46
+
47
+ # Output all logits - includes all token logits in the output (for debugging)
31
48
  logits_all: [ false, true ],
49
+
50
+ # Vocabulary only mode - only loads vocabulary without weights
32
51
  vocab_only: [ false, true ],
52
+
53
+ # Use memory mapping - enables memory mapping for model loading
33
54
  use_mmap: [ false, true ],
55
+
56
+ # Use memory locking - locks model in memory to prevent swapping
34
57
  use_mlock: [ false, true ],
58
+
59
+ # Number of threads to use - specifies CPU thread count for computation
35
60
  num_thread: Integer,
61
+
62
+ # Number of tokens to keep - keeps the first N tokens from the context
36
63
  num_keep: Integer,
64
+
65
+ # Random seed for reproducible results - sets the random seed for generation
37
66
  seed: Integer,
67
+
68
+ # Maximum number of tokens to predict - limits generation length
38
69
  num_predict: Integer,
70
+
71
+ # Top-K sampling - limits sampling to top K tokens
39
72
  top_k: Integer,
73
+
74
+ # Top-P (nucleus) sampling - limits sampling to tokens that sum to P probability
40
75
  top_p: Float,
76
+
77
+ # Minimum probability for token sampling - sets minimum token probability threshold
41
78
  min_p: Float,
79
+
80
+ # Tail Free Sampling - controls the tail free sampling parameter
42
81
  tfs_z: Float,
82
+
83
+ # Typical P sampling - controls the typical P sampling parameter
43
84
  typical_p: Float,
85
+
86
+ # Repeat last N tokens - prevents repetition of last N tokens
44
87
  repeat_last_n: Integer,
88
+
89
+ # Temperature - controls randomness in generation (0.0 = deterministic, 1.0 = default)
45
90
  temperature: Float,
91
+
92
+ # Repeat penalty - penalizes repeated tokens (higher values = more diversity)
46
93
  repeat_penalty: Float,
94
+
95
+ # Presence penalty - penalizes tokens that appear in the context
47
96
  presence_penalty: Float,
97
+
98
+ # Frequency penalty - penalizes tokens based on their frequency in the context
48
99
  frequency_penalty: Float,
100
+
101
+ # Mirostat sampling - controls the Mirostat sampling algorithm (0 = disabled)
49
102
  mirostat: Integer,
103
+
104
+ # Mirostat tau parameter - controls the target entropy for Mirostat
50
105
  mirostat_tau: Float,
106
+
107
+ # Mirostat eta parameter - controls the learning rate for Mirostat
51
108
  mirostat_eta: Float,
109
+
110
+ # Penalize newline tokens - whether to penalize newline tokens
52
111
  penalize_newline: [ false, true ],
112
+
113
+ # Stop sequences - array of strings that will stop generation
53
114
  stop: Array,
54
115
  }
55
116
 
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '1.15.0'
3
+ VERSION = '1.17.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,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama-ruby 1.15.0 ruby lib
2
+ # stub: ollama-ruby 1.17.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "1.15.0".freeze
6
+ s.version = "1.17.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]
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
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
- s.required_ruby_version = Gem::Requirement.new("~> 3.1".freeze)
21
- s.rubygems_version = "3.7.2".freeze
20
+ s.required_ruby_version = Gem::Requirement.new(">= 3.1".freeze)
21
+ s.rubygems_version = "4.0.2".freeze
22
22
  s.summary = "Interacting with the Ollama API".freeze
23
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/commands/version_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/spec_helper.rb".freeze]
24
24
 
@@ -71,6 +71,13 @@ describe Ollama::Client do
71
71
  }.to raise_error(Ollama::Errors::Error)
72
72
  end
73
73
 
74
+ it 'can raise error based on status code 400' do
75
+ expect(excon).to receive(:send).and_return(double(status: 400, body: '{}'))
76
+ expect {
77
+ ollama.generate(model: 'llama3.1', prompt: 'Hello World', think: true)
78
+ }.to raise_error(Ollama::Errors::BadRequestError)
79
+ end
80
+
74
81
  it 'can raise error based on status code 404' do
75
82
  expect(excon).to receive(:send).and_return(double(status: 404, body: '{}'))
76
83
  expect {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ollama-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -404,7 +404,7 @@ require_paths:
404
404
  - lib
405
405
  required_ruby_version: !ruby/object:Gem::Requirement
406
406
  requirements:
407
- - - "~>"
407
+ - - ">="
408
408
  - !ruby/object:Gem::Version
409
409
  version: '3.1'
410
410
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -413,7 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
413
413
  - !ruby/object:Gem::Version
414
414
  version: '0'
415
415
  requirements: []
416
- rubygems_version: 3.7.2
416
+ rubygems_version: 4.0.2
417
417
  specification_version: 4
418
418
  summary: Interacting with the Ollama API
419
419
  test_files: