ollama-ruby 1.17.0 → 1.19.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: 11d1c6bcf5eaea08074bbba02d8f7044f6b4c234287dde118443f4f886f275ae
4
- data.tar.gz: 9004c648dd62e4a71b0f35ddd31d3944123e10dfae856314e6c8f57ed3dbdb34
3
+ metadata.gz: dcb4d954bc66b999983fbb02192c600d1ee1f5e052ae7808e5d287268cc54eb3
4
+ data.tar.gz: 3c7a867320432d99f091b11c3955a3ca9f2b66888340effae91bf34f21768e8c
5
5
  SHA512:
6
- metadata.gz: 8cab524ff7ecee59b700184b5194cc207ff54bfb22ff00467e80df37433822cee2cf19ddaefc75f7f41a269b538f9bb6fb617d1846c1d3f11176d8ffc9838e37
7
- data.tar.gz: 7e7a30b30c2b581f34f30ccef4caa3f52a40ab9bf6e9a2f3e57c2830741cf6a3057d8f77db338213e15a9a54bcf4a0645739f3bf4dc41d8a422f8cee1c0bbd35
6
+ metadata.gz: f0d81e6b9df50f005efed07afc8dfc82fad1f072a293276526ff35f075bfc6c06d526e49a0a15d340ed84d1b470a27ee62ecd4754a776ceacc8890f7a6cc08c6
7
+ data.tar.gz: a9f0c6c8cf62f75dea4f92a02f1c40b1f7b92034b69e83ba34a6282fd01df6126c14f2abd14987bd4d996023314675ede5cbbec8ca04b106d53807c971f710a4
data/CHANGES.md CHANGED
@@ -1,8 +1,46 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-04 v1.19.0
4
+
5
+ - Added API key handling to the Ollama client: introduced a private `api_key`
6
+ attribute, interpolated it into request headers as `"Bearer #@api_key"`, and
7
+ merged the field into the client configuration. Updated `bin/ollama_cli` and
8
+ `bin/ollama_console` to accept an optional `api_key` from environment
9
+ variables, and extended `spec/ollama/client_spec.rb` to test this
10
+ functionality.
11
+ - Implemented an interval option for `ollama_ps`: added `require
12
+ 'term/ansicolor'`, updated help text to include the flag `-i INTERVAL`,
13
+ parsed the `?i` option, and added a loop that clears the terminal with
14
+ `Term::ANSIColor.clear_screen`, prints the model table via
15
+ `ps_table(models)`, sleeps for the specified interval, and repeats while the
16
+ interval is greater than zero.
17
+ - Improved progress output formatting: updated
18
+ `lib/ollama/handlers/progress.rb` to format progress bytes using
19
+ `Tins::Unit.format(_1, format: '%.2f %U', unit: ?B, prefix: :iec_uc)` and
20
+ adjusted the `message` method to include `unit` and `prefix` options.
21
+ - Updated dependencies and test harness: removed system‑wide gem updates from
22
+ `.all_images.yml`, replaced `bundle update --all` with `bundle exec rake
23
+ spec`, added `before:` and `after:` hooks to delete `Gemfile.lock` and echo
24
+ test results, bumped the `all_images` dev dependency to `~> **0.12**`,
25
+ updated the `gem_hadar` dev dependency to `>= **2.17.0**`, and set
26
+ `rubygems_version` to **4.0.3** in `ollama-ruby.gemspec`.
27
+ - Added changelog configuration to the Rakefile: created a `changelog` block
28
+ with `filename` set to `'CHANGES.md'` to enable automated changelog
29
+ generation.
30
+ - Updated Ruby image build matrix: enabled the `ruby:4.0-rc-alpine` image in
31
+ the build matrix with the `*script` template, and later switched the Ruby
32
+ version from **4.0-rc-alpine** to **4.0-alpine**.
33
+ - Updated the `gem_hadar` development dependency to **2.16.3** or higher to
34
+ maintain compatibility with newer features and bug fixes.
35
+
36
+ ## 2025-12-19 v1.18.0
37
+
38
+ - Updated `gem_hadar` development dependency from version **2.8** to **2.9**
39
+
3
40
  ## 2025-12-19 v1.17.0
4
41
 
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**
42
+ - Changed `s.required_ruby_version` in the gemspec from "~> 3.1" to ">= 3.1" to
43
+ allow usage with **Ruby 3.1** and higher, including **4.0**
6
44
  - Updated `s.rubygems_version` from **3.7.2** to **4.0.2**
7
45
  - Replaced `bundle update` with `bundle update --all` in the update command
8
46
  - Added **4.0-rc** release candidate to the Ruby version matrix (commented out)
@@ -68,10 +106,13 @@
68
106
  ## 2025-11-30 v1.12.0
69
107
 
70
108
  - `ollama_cli`
71
- - Added `-i` flag to display Ollama server version using `ollama.version.version`
72
- - Refactored model options handling to use `Ollama::Options.from_hash` or `Ollama::Options.new`
109
+ - Added `-i` flag to display Ollama server version using
110
+ `ollama.version.version`
111
+ - Refactored model options handling to use `Ollama::Options.from_hash` or
112
+ `Ollama::Options.new`
73
113
  - Stored client configuration in `ollama` variable for reuse
74
- - Added `-d` flag for debug mode in `ollama_cli` instead of using environment variable
114
+ - Added `-d` flag for debug mode in `ollama_cli` instead of using
115
+ environment variable
75
116
  - Included `Ollama::DTO` in `Client::Config` class for consistent behavior
76
117
  - Improved documentation formatting in `dto.rb` file
77
118
  - Added documentation that `think` can be "high", "medium", "low" instead of just `true`
@@ -498,7 +539,7 @@ and introduced new context files for project structure documentation in
498
539
  + Normalizes URL by decoding URI components, removing anchors, and escaping special characters
499
540
  + `excon` method now calls `normalize_url` on the provided URL
500
541
  + Added specs for `normalize_url` in `fetcher_spec.rb`
501
- * Remove Ollama top level Namespace b/c we include it from `ollama_chat`:
542
+ * Remove Ollama top level Namespace b/c we include it from `ollama_chat`:
502
543
  + Removed the top-level namespace
503
544
 
504
545
  ## 2024-10-18 v0.9.0
@@ -550,7 +591,7 @@ and introduced new context files for project structure documentation in
550
591
  + Moved case order
551
592
  + Renamed `/collection clear [tag]|change` to `/collection (clear|change)`
552
593
  + Improved help message, added /info
553
- * **Update README.md**
594
+ * **Update README.md**
554
595
  + Update README.md to reflect changed/added commands
555
596
  * **Add support for reading PostScript**
556
597
  + Extracted `pdf_read` method to read PDF files using `PDF::Reader`
@@ -568,7 +609,7 @@ and introduced new context files for project structure documentation in
568
609
  + Updated `choose` method to handle cases better where no entry was chosen
569
610
  * **Fix Redis cache expiration logic**
570
611
  + Update `set` method to delete key expiration time is less than 1 second.
571
- * **Update dependencies and add source tracking**
612
+ * **Update dependencies and add source tracking**
572
613
  - Remove `sorted_set` dependency from Rakefile
573
614
  - Modify `Ollama::Documents` class to track source of tags
574
615
  - Update `Ollama::Utils::Tags` class to include source in tag output and add methods for tracking source
@@ -783,28 +824,28 @@ and introduced new context files for project structure documentation in
783
824
 
784
825
  * Update dependencies and date in gemspec files:
785
826
  - Updated `complex_config` dependency to '~> 0.22'
786
- * Refactor FollowChat#eval_stats to add bold eval rates
787
- * Improve formatting in eval_stats using bold and color for better
827
+ * Refactor `FollowChat#eval_stats` to add bold eval rates
828
+ * Improve formatting in `eval_stats` using bold and color for better
788
829
  readability.
789
- * Update import_document and add_image methods to handle nil values
830
+ * Update `import_document` and `add_image` methods to handle nil values
790
831
  correctly.
791
832
  * Update width method in utils/width.rb to use uncolor when checking line
792
833
  length.
793
834
  * Refactor eval stats output in FollowChat class
794
835
  - Add indentation to eval stats output for better readability
795
836
  * FollowChat evaluation stats refactored
796
- - Removed hardcoded eval_stats hash and replaced with method call
837
+ - Removed hardcoded `eval_stats` hash and replaced with method call
797
838
  `eval_stats(response)`
798
839
  - Added new method `eval_stats(response)` to calculate evaluation statistics
799
840
  - Calculates eval duration, prompt eval duration, total duration, and load
800
841
  duration
801
842
  - Adds eval count, prompt eval count, eval rate, and prompt eval rate
802
- * Use default to_s tree representation of config.
803
- * Update complex_config dependency to ~> 0.21, >= 0.21.1 in Rakefile
804
- * Update complex_config dependency to ~> 0.21, >= 0.21.1 in
843
+ * Use default `to_s` tree representation of config.
844
+ * Update `complex_config` dependency to ~> 0.21, >= 0.21.1 in Rakefile
845
+ * Update `complex_config` dependency to ~> 0.21, >= 0.21.1 in
805
846
  ollama-ruby.gemspec
806
847
  * Update dependencies and configuration display
807
- * Update 'complex_config' dependency to '~> 0.21'
848
+ * Update `complex_config` dependency to '~> 0.21'
808
849
  * Change OllamaChatConfig to display configuration as a tree instead of yaml
809
850
  * Improve /web search command
810
851
  * Update infobar dependency to ~> 0.8
@@ -854,9 +895,10 @@ and introduced new context files for project structure documentation in
854
895
  + Updated `/summarize` command to handle cases where summarization fails
855
896
  + Fix bug in parsing content type of source document
856
897
  * **Refactored Options Class and Usage**
857
- + Renamed `options` variable to use `Options[]` method in ollama_chat script
898
+ + Renamed `options` variable to use `Options[]` method in `ollama_chat`
899
+ script
858
900
  + Added `[](value)` method to Ollama::Options class for casting hashes
859
- + Updated options_spec.rb with tests for casting hashes and error handling
901
+ + Updated `options_spec.rb` with tests for casting hashes and error handling
860
902
  * **Refactored Web Search Command**
861
903
  + Added support for specifying a page number in `/web` command
862
904
  + Updated regular expression to match new format
@@ -866,10 +908,11 @@ and introduced new context files for project structure documentation in
866
908
  + Renamed `json_create` method to `from_hash` in Ollama::DTO class
867
909
  + Updated `as_json` method to remove now unnecessary hash creation
868
910
  * **Message and Tool Spec Changes**
869
- + Removed `json_class` from JSON serialization in message_spec
870
- + Removed `json_class` from JSON serialization in tool_spec
911
+ + Removed `json_class` from JSON serialization in `message_spec`
912
+ + Removed `json_class` from JSON serialization in `tool_spec`
871
913
  * **Command Spec Changes**
872
- + Removed `json_class` from JSON serialization in various command specs (e.g. generate_spec, pull_spec, etc.)
914
+ + Removed `json_class` from JSON serialization in various command specs (e.g.
915
+ `generate_spec`, `pull_spec`, etc.)
873
916
  * **Miscellaneous Changes**
874
917
  + Improved width calculation for text truncation
875
918
  + Updated FollowChat class to display evaluation statistics
@@ -882,26 +925,36 @@ and introduced new context files for project structure documentation in
882
925
 
883
926
  #### Significant Changes
884
927
 
885
- * **Document Splitting and Embedding Functionality**: Added `Ollama::Documents` class with methods for adding documents, checking existence, deleting documents, and finding similar documents.
928
+ * **Document Splitting and Embedding Functionality**: Added `Ollama::Documents`
929
+ class with methods for adding documents, checking existence, deleting
930
+ documents, and finding similar documents.
886
931
  + Introduced two types of caches: `MemoryCache` and `RedisCache`
887
- + Implemented `SemanticSplitter` class to split text into sentences based on semantic similarity
888
- * **Improved Ollama Chat Client**: Added support for document embeddings and web/file RAG
932
+ + Implemented `SemanticSplitter` class to split text into sentences based on
933
+ semantic similarity
934
+ * **Improved Ollama Chat Client**: Added support for document embeddings and
935
+ web/file RAG
889
936
  + Allowed configuration per yaml file
890
937
  + Parse user input for URLs or files to send images to multimodal models
891
- * **Redis Docker Service**: Set `REDIS_URL` environment variable to `redis://localhost:9736`
938
+ * **Redis Docker Service**: Set `REDIS_URL` environment variable to
939
+ `redis://localhost:9736`
892
940
  + Added Redis service to `docker-compose.yml`
893
- * **Status Display and Progress Updates**: Added infobar.label = response.status when available
894
- + Updated infobar with progress message on each call if total and completed are set
941
+ * **Status Display and Progress Updates**: Added infobar.label =
942
+ response.status when available
943
+ + Updated infobar with progress message on each call if total and completed
944
+ are set
895
945
  + Display error message from response.error if present
896
- * **Refactored Chat Commands**: Simplified regular expression patterns for `/pop`, `/save`, `/load`, and `/image` commands
946
+ * **Refactored Chat Commands**: Simplified regular expression patterns for
947
+ `/pop`, `/save`, `/load`, and `/image` commands
897
948
  + Added whitespace to some command patterns for better readability
898
949
 
899
950
  #### Other Changes
900
951
 
901
- * Added `Character` and `RecursiveCharacter` splitter classes to split text into chunks based on character separators
952
+ * Added `Character` and `RecursiveCharacter` splitter classes to split text
953
+ into chunks based on character separators
902
954
  * Added RSpec tests for the Ollama::Documents class(es)
903
- * Updated dependencies and added new methods for calculating breakpoint thresholds and sentence embeddings
904
- * Added 'ollama_update' to executables in Rakefile
955
+ * Updated dependencies and added new methods for calculating breakpoint
956
+ thresholds and sentence embeddings
957
+ * Added `ollama_update` to executables in Rakefile
905
958
  * Started using webmock
906
959
  * Refactored chooser and add fetcher specs
907
960
  * Added tests for Ollama::Utils::Fetcher
data/Rakefile CHANGED
@@ -21,6 +21,10 @@ GemHadar do
21
21
  executables << 'ollama_console' << 'ollama_update' << 'ollama_cli' <<
22
22
  'ollama_browse' << 'ollama_ps'
23
23
 
24
+ changelog do
25
+ filename 'CHANGES.md'
26
+ end
27
+
24
28
  github_workflows(
25
29
  'static.yml' => {}
26
30
  )
@@ -36,7 +40,7 @@ GemHadar do
36
40
  dependency 'ostruct', '~> 0.0'
37
41
  dependency 'terminal-table', '~> 3.0'
38
42
  dependency 'nokogiri', '~> 1.0'
39
- development_dependency 'all_images', '~> 0.6'
43
+ development_dependency 'all_images', '~> 0.12'
40
44
  development_dependency 'rspec', '~> 3.2'
41
45
  development_dependency 'kramdown', '~> 2.0'
42
46
  development_dependency 'webmock'
data/bin/ollama_cli CHANGED
@@ -44,7 +44,7 @@ module Ollama::Handlers
44
44
  # specified output.
45
45
  #
46
46
  # @param output [IO] the output stream to write markdown content to,
47
- # defaults to $stdout
47
+ # defaults to $stdout
48
48
  def initialize(output: $stdout)
49
49
  super
50
50
  @output.sync = true
@@ -137,9 +137,10 @@ opts = go 'u:m:M:s:p:P:H:c:I:STdih', defaults: { ?H => 'ChatStart' }
137
137
 
138
138
  opts[?h] and usage
139
139
 
140
- base_url = opts[?u] || ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
140
+ base_url = opts[?u] || ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
141
+ api_key = ENV['OLLAMA_API_KEY']
141
142
  client_config = Client::Config[
142
- { base_url:, debug: !!opts[?d] } |
143
+ { base_url:, api_key:, debug: !!opts[?d] } |
143
144
  JSON(get_file_argument(opts[?c], default: ENV['OLLAMA_CLIENT']).full? || '{}')
144
145
  ]
145
146
  model = (opts[?m] || ENV['OLLAMA_MODEL']).full? || 'llama3.1'
data/bin/ollama_console CHANGED
@@ -40,7 +40,17 @@ end
40
40
  #
41
41
  # @return [ Hash ] a hash containing the merged configuration settings
42
42
  def client_config
43
- Client::Config[ { base_url: } | JSON(ENV.fetch('OLLAMA_CLIENT', '{}')) ]
43
+ Client::Config[
44
+ { base_url:, api_key: } | JSON(ENV.fetch('OLLAMA_CLIENT', '{}')).transform_keys(&:to_sym)
45
+ ]
46
+ end
47
+
48
+ # Retrieves the Ollama API key from the environment variable OLLAMA_API_KEY.
49
+ #
50
+ # @return [ String, nil ] the API key value or nil if the environment variable
51
+ # is not set
52
+ def api_key
53
+ ENV['OLLAMA_API_KEY']
44
54
  end
45
55
 
46
56
  # The ollama method provides access to a configured Ollama client instance.
data/bin/ollama_ps CHANGED
@@ -34,6 +34,7 @@
34
34
  require 'ollama'
35
35
  include Ollama
36
36
  require 'terminal-table'
37
+ require 'term/ansicolor'
37
38
  require 'tins'
38
39
  include Tins::GO
39
40
 
@@ -49,6 +50,7 @@ def usage
49
50
  Usage: #{File.basename($0)} [OPTIONS]
50
51
 
51
52
  -f FORMAT output format: json, yaml, or table (default)
53
+ -i INTERVAL output the ps table every INTERVAL seconds
52
54
  -h this help
53
55
 
54
56
  EOT
@@ -188,7 +190,7 @@ def ps_table(models)
188
190
  puts table
189
191
  end
190
192
 
191
- opts = go 'f:h'
193
+ opts = go 'f:i:h'
192
194
 
193
195
  opts[?h] and usage
194
196
 
@@ -200,5 +202,11 @@ when 'json'
200
202
  when 'yaml'
201
203
  YAML.dump(interpret_models(models), STDOUT)
202
204
  else
203
- ps_table(interpret_models(models))
205
+ n = opts[?i].to_i
206
+ begin
207
+ print Term::ANSIColor.clear_screen, Term::ANSIColor.move_home if n > 0
208
+ ps_table(interpret_models(models))
209
+ n == 0 and break
210
+ sleep n
211
+ end while n
204
212
  end
@@ -27,7 +27,7 @@ module Ollama::Client::Command
27
27
  # @param stream_handler [ Class, nil ] the handler class to use for streaming responses, if applicable
28
28
  #
29
29
  # @note Create Command `name`, if `stream` was true, set `stream_handler`
30
- # as default, otherwise `default_handler`.
30
+ # as default, otherwise `default_handler`.
31
31
  #
32
32
  # @return [ self ] returns the receiver after defining the command method
33
33
  def command(name, default_handler:, stream_handler: nil)
@@ -66,7 +66,7 @@ module Ollama::Client::Configuration
66
66
  # @param value [ Hash ] a hash containing the attribute names and their values
67
67
  #
68
68
  # @return [ self ] a new instance of the class initialized with the provided
69
- # attributes
69
+ # attributes
70
70
  def self.[](value)
71
71
  new(**value.to_h)
72
72
  end
@@ -77,6 +77,12 @@ module Ollama::Client::Configuration
77
77
  # @attr [ URI ] the new base URL to be set for API requests
78
78
  attr_accessor :base_url
79
79
 
80
+ # The api_key attribute allows setting and retrieving the API key for
81
+ # Ollama API authentication.
82
+ #
83
+ # @attr [ String, nil ] the API key used for authenticating requests
84
+ attr_accessor :api_key
85
+
80
86
  # The output attribute accessor allows reading and setting the output stream
81
87
  # used for handling responses and messages.
82
88
  #
@@ -126,13 +132,14 @@ module Ollama::Client::Configuration
126
132
  # settings.
127
133
 
128
134
  # @param config [ Ollama::Client::Configuration::Config ] the configuration
129
- # object containing client settings
135
+ # object containing client settings
130
136
  #
131
137
  # @return [ Ollama::Client ] a new client instance configured with the
132
- # provided settings
138
+ # provided settings
133
139
  def configure_with(config)
134
140
  new(
135
141
  base_url: config.base_url,
142
+ api_key: config.api_key,
136
143
  output: config.output,
137
144
  connect_timeout: config.connect_timeout,
138
145
  read_timeout: config.read_timeout,
data/lib/ollama/client.rb CHANGED
@@ -35,13 +35,14 @@ class Ollama::Client
35
35
  # configuration options, making them available for use in subsequent client operations.
36
36
  #
37
37
  # @param base_url [ String, nil ] the base URL of the Ollama API endpoint, defaults to nil
38
+ # @param api_key [ String, nil ] the API key for the Ollama API, defaults to nil
38
39
  # @param output [ IO ] the output stream to be used for handling responses, defaults to $stdout
39
40
  # @param connect_timeout [ Integer, nil ] the connection timeout value in seconds, defaults to nil
40
41
  # @param read_timeout [ Integer, nil ] the read timeout value in seconds, defaults to nil
41
42
  # @param write_timeout [ Integer, nil ] the write timeout value in seconds, defaults to nil
42
43
  # @param debug [ Boolean, nil ] the debug flag indicating whether debug output is enabled, defaults to nil
43
44
  # @param user_agent [ String, nil ] the user agent string to be used for API requests, defaults to nil
44
- def initialize(base_url: nil, output: $stdout, connect_timeout: nil, read_timeout: nil, write_timeout: nil, debug: nil, user_agent: nil)
45
+ def initialize(base_url: nil, api_key: nil, output: $stdout, connect_timeout: nil, read_timeout: nil, write_timeout: nil, debug: nil, user_agent: nil)
45
46
  base_url.nil? and base_url = ENV.fetch('OLLAMA_URL') do
46
47
  raise ArgumentError,
47
48
  'missing :base_url parameter or OLLAMA_URL environment variable'
@@ -52,8 +53,8 @@ class Ollama::Client
52
53
  @ssl_verify_peer = base_url.query.to_s.split(?&).inject({}) { |h, l|
53
54
  h.merge Hash[*l.split(?=)]
54
55
  }['ssl_verify_peer'] != 'false'
55
- @base_url, @output, @connect_timeout, @read_timeout, @write_timeout, @debug, @user_agent =
56
- base_url, output, connect_timeout, read_timeout, write_timeout, debug, user_agent
56
+ @base_url, @api_key, @output, @connect_timeout, @read_timeout, @write_timeout, @debug, @user_agent =
57
+ base_url, api_key, output, connect_timeout, read_timeout, write_timeout, debug, user_agent
57
58
  end
58
59
 
59
60
  # The output attribute accessor allows reading and setting the output stream
@@ -68,6 +69,13 @@ class Ollama::Client
68
69
  # @return [ URI ] the base URL configured for API requests
69
70
  attr_reader :base_url
70
71
 
72
+ # The api_key attribute reader returns the API key used for authenticating
73
+ # requests.
74
+ #
75
+ # @attr_reader :api_key
76
+ attr_reader :api_key
77
+ private :api_key
78
+
71
79
  # The ssl_verify_peer? method checks whether SSL peer verification is enabled.
72
80
  #
73
81
  # This method returns a boolean value indicating if the client should verify
@@ -217,7 +225,7 @@ class Ollama::Client
217
225
  {
218
226
  'User-Agent' => @user_agent || self.class.user_agent,
219
227
  'Content-Type' => 'application/json; charset=utf-8',
220
- }
228
+ } | @api_key.full? { { 'Authorization' => "Bearer #@api_key" } }
221
229
  end
222
230
 
223
231
  # The user_agent method generates a formatted user agent string for API requests.
@@ -107,7 +107,7 @@ class Ollama::Commands::Chat
107
107
  # scenarios based on the command's configuration.
108
108
  #
109
109
  # @param handler [ Ollama::Handler ] the handler object responsible for processing API
110
- # responses
110
+ # responses
111
111
  #
112
112
  # @return [ self ] returns the current instance after initiating the request
113
113
  def perform(handler)
@@ -68,7 +68,7 @@ class Ollama::Commands::Copy
68
68
  # copy commands do not support streaming.
69
69
  #
70
70
  # @param handler [ Ollama::Handler ] the handler object responsible for processing API
71
- # responses
71
+ # responses
72
72
  #
73
73
  # @return [ self ] returns the current instance after initiating the request
74
74
  def perform(handler)
@@ -123,7 +123,7 @@ class Ollama::Commands::Create
123
123
  # scenarios based on the command's configuration.
124
124
  #
125
125
  # @param handler [ Ollama::Handler ] the handler object responsible for processing API
126
- # responses
126
+ # responses
127
127
  #
128
128
  # @return [ self ] returns the current instance after initiating the request
129
129
  def perform(handler)
@@ -62,7 +62,7 @@ class Ollama::Commands::Delete
62
62
  # delete commands do not support streaming.
63
63
  #
64
64
  # @param handler [ Ollama::Handler ] the handler object responsible for processing API
65
- # responses
65
+ # responses
66
66
  #
67
67
  # @return [ self ] returns the current instance after initiating the request
68
68
  def perform(handler)
@@ -99,7 +99,7 @@ class Ollama::Commands::Embed
99
99
  # embedding commands do not support streaming.
100
100
  #
101
101
  # @param handler [ Ollama::Handler ] the handler object responsible for processing API
102
- # responses
102
+ # responses
103
103
  #
104
104
  # @return [ self ] returns the current instance after initiating the request
105
105
  def perform(handler)
@@ -82,7 +82,7 @@ class Ollama::Commands::Embeddings
82
82
  # embeddings commands do not support streaming.
83
83
  #
84
84
  # @param handler [ Ollama::Handler ] the handler object responsible for processing API
85
- # responses
85
+ # responses
86
86
  #
87
87
  # @return [ self ] returns the current instance after initiating the request
88
88
  def perform(handler)
@@ -65,7 +65,7 @@ class Ollama::Commands::Ps
65
65
  # ps commands do not support streaming.
66
66
  #
67
67
  # @param handler [ Ollama::Handler ] the handler object responsible for processing API
68
- # responses
68
+ # responses
69
69
  #
70
70
  # @return [ self ] returns the current instance after initiating the request
71
71
  def perform(handler)
@@ -10,7 +10,7 @@
10
10
  # @param stream_handler [ Class, nil ] the handler class to use for streaming responses, if applicable
11
11
  #
12
12
  # @note Create Command `name`, if `stream` was true, set `stream_handler`
13
- # as default, otherwise `default_handler`.
13
+ # as default, otherwise `default_handler`.
14
14
  #
15
15
  # @return [ self ] returns the receiver after defining the command method
16
16
  class Ollama::Commands::Pull
@@ -81,7 +81,7 @@ class Ollama::Commands::Pull
81
81
  # non-streaming scenarios based on the command's configuration.
82
82
  #
83
83
  # @param handler [ Ollama::Handler ] the handler object responsible for processing API
84
- # responses
84
+ # responses
85
85
  #
86
86
  # @return [ self ] returns the current instance after initiating the request
87
87
  def perform(handler)
@@ -40,7 +40,7 @@ class Ollama::Commands::Tags
40
40
  # associated with the object.
41
41
  #
42
42
  # @return [ TrueClass, FalseClass ] the streaming behavior flag, indicating
43
- # whether streaming is enabled for the command execution
43
+ # whether streaming is enabled for the command execution
44
44
  attr_reader :stream
45
45
 
46
46
  # The client attribute writer allows setting the client instance associated
@@ -18,7 +18,7 @@ class Ollama::Commands::Version
18
18
  # operations.
19
19
  #
20
20
  # @return [ String ] the API endpoint path '/api/version' for version
21
- # requests
21
+ # requests
22
22
  def self.path
23
23
  '/api/version'
24
24
  end
@@ -37,7 +37,7 @@ class Ollama::Commands::Version
37
37
  # associated with the object.
38
38
  #
39
39
  # @return [ TrueClass, FalseClass ] the streaming behavior flag, indicating
40
- # whether streaming is enabled for the command execution
40
+ # whether streaming is enabled for the command execution
41
41
  attr_reader :stream
42
42
 
43
43
  # The client attribute writer allows setting the client instance associated
@@ -15,7 +15,7 @@ class Ollama::Handlers::Collector
15
15
  # output destination and initializes an empty array for collecting responses.
16
16
  #
17
17
  # @param output [ IO ] the output stream to be used for handling responses,
18
- # defaults to $stdout
18
+ # defaults to $stdout
19
19
  def initialize(output: $stdout)
20
20
  super
21
21
  @array = []
@@ -57,7 +57,7 @@ module Ollama::Handlers::Concern
57
57
  # in contexts where a proc is expected.
58
58
  #
59
59
  # @return [ Proc ] a proc that wraps the handler's call method for response
60
- # processing
60
+ # processing
61
61
  def to_proc
62
62
  -> response { call(response) }
63
63
  end
@@ -67,10 +67,10 @@ module Ollama::Handlers::Concern
67
67
  # response.
68
68
  #
69
69
  # @param response [ Ollama::Response ] the response object to be processed by the
70
- # handler
70
+ # handler
71
71
  #
72
72
  # @return [ self ] returns the handler instance itself after processing the
73
- # response
73
+ # response
74
74
  def call(response)
75
75
  new.call(response)
76
76
  end
@@ -19,10 +19,10 @@ class Ollama::Handlers::DumpYAML
19
19
  # YAML format for debugging or inspection purposes.
20
20
  #
21
21
  # @param response [ Ollama::Response ] the response object to be serialized
22
- # and output
22
+ # and output
23
23
  #
24
24
  # @return [ self ] returns the handler instance itself after processing the
25
- # response
25
+ # response
26
26
  def call(response)
27
27
  @output.puts Psych.dump(response)
28
28
  self
@@ -36,10 +36,10 @@ class Ollama::Handlers::Markdown
36
36
  # single-message display.
37
37
  #
38
38
  # @param response [ Ollama::Response ] the response object containing content
39
- # to be rendered
39
+ # to be rendered
40
40
  #
41
41
  # @return [ self ] returns the handler instance itself after processing the
42
- # response
42
+ # response
43
43
  def call(response)
44
44
  if content = response.response || response.message&.content
45
45
  if @stream
@@ -35,10 +35,10 @@ class Ollama::Handlers::Progress
35
35
  # ensures proper formatting of output.
36
36
  #
37
37
  # @param response [ Ollama::Response ] the response object containing
38
- # progress information
38
+ # progress information
39
39
  #
40
40
  # @return [ self ] returns the handler instance itself after processing the
41
- # response
41
+ # response
42
42
  def call(response)
43
43
  infobar.display.output = @output
44
44
  if status = response.status
@@ -80,7 +80,7 @@ class Ollama::Handlers::Progress
80
80
  # time information, and estimated completion details
81
81
  def message(current, total)
82
82
  progress = '%s/%s' % [ current, total ].map {
83
- Tins::Unit.format(_1, format: '%.2f %U')
83
+ Tins::Unit.format(_1, format: '%.2f %U', unit: ?B, prefix: :iec_uc)
84
84
  }
85
85
  '%l ' + progress + ' in %te, ETA %e @%E'
86
86
  end
@@ -23,7 +23,7 @@ class Ollama::Handlers::Say
23
23
  # @param output [ IO, nil ] the output stream to be used for handling responses, defaults to nil
24
24
  # @param voice [ String ] the voice to be used for speech synthesis, defaults to 'Samantha'
25
25
  # @param interactive [ TrueClass, FalseClass, String, nil ] the interactive
26
- # mode setting for speech synthesis, defaults to nil
26
+ # mode setting for speech synthesis, defaults to nil
27
27
  def initialize(output: nil, voice: 'Samantha', interactive: nil)
28
28
  @voice = voice
29
29
  @interactive = interactive
@@ -43,7 +43,7 @@ class Ollama::Handlers::Say
43
43
  # associated with the object.
44
44
  #
45
45
  # @return [ TrueClass, FalseClass, String, nil ] the interactive mode value
46
- # stored in the instance variable
46
+ # stored in the instance variable
47
47
  attr_reader :interactive
48
48
 
49
49
  # The call method processes a response by printing its content to the output stream.
@@ -107,7 +107,7 @@ class Ollama::Handlers::Say
107
107
  #
108
108
  # @param voice [ String ] the voice to be used for speech synthesis
109
109
  # @param interactive [ TrueClass, FalseClass, String, nil ] the interactive
110
- # mode setting for speech synthesis
110
+ # mode setting for speech synthesis
111
111
  #
112
112
  # @return [ Array<String> ] an array containing the command and its arguments
113
113
  def command(voice:, interactive:)
@@ -15,7 +15,7 @@ class Ollama::Handlers::Single
15
15
  # output destination and initializes an empty array for collecting responses.
16
16
  #
17
17
  # @param output [ IO ] the output stream to be used for handling responses,
18
- # defaults to $stdout
18
+ # defaults to $stdout
19
19
  def initialize(output: $stdout)
20
20
  super
21
21
  @array = []
data/lib/ollama/image.rb CHANGED
@@ -44,7 +44,7 @@ class Ollama::Image
44
44
  # @param path [ String, nil ] the optional file path associated with the image
45
45
  #
46
46
  # @return [ Ollama::Image ] a new Image instance initialized with the
47
- # provided data and path
47
+ # provided data and path
48
48
  def for_base64(data, path: nil)
49
49
  obj = new(data)
50
50
  obj.path = path
@@ -57,7 +57,7 @@ class Ollama::Image
57
57
  # @param path [ String, nil ] the optional file path associated with the image
58
58
  #
59
59
  # @return [ Ollama::Image ] a new Image instance initialized with the
60
- # encoded string data and optional path
60
+ # encoded string data and optional path
61
61
  def for_string(string, path: nil)
62
62
  for_base64(Base64.strict_encode64(string), path:)
63
63
  end
@@ -69,7 +69,7 @@ class Ollama::Image
69
69
  # @param path [ String, nil ] the optional file path associated with the image
70
70
  #
71
71
  # @return [ Ollama::Image ] a new Image instance initialized with the IO
72
- # object's data and optional path
72
+ # object's data and optional path
73
73
  def for_io(io, path: nil)
74
74
  path ||= io.path
75
75
  for_string(io.read, path:)
@@ -81,7 +81,7 @@ class Ollama::Image
81
81
  # @param path [ String ] the file system path to the image file
82
82
  #
83
83
  # @return [ Ollama::Image ] a new Image instance initialized with the
84
- # contents of the file at the specified path
84
+ # contents of the file at the specified path
85
85
  def for_filename(path)
86
86
  File.open(path, 'rb') { |io| for_io(io, path:) }
87
87
  end
@@ -95,7 +95,7 @@ class Ollama::Image
95
95
  # @param other [ Ollama::Image ] the other Image object to compare against
96
96
  #
97
97
  # @return [ TrueClass, FalseClass ] true if both Image objects have identical
98
- # data, false otherwise
98
+ # data, false otherwise
99
99
  def ==(other)
100
100
  @data == other.data
101
101
  end
@@ -154,7 +154,7 @@ class Ollama::Options
154
154
  # @param value [ Hash ] a hash containing the attribute names and their values
155
155
  #
156
156
  # @return [ self ] a new instance of the class initialized with the provided
157
- # attributes
157
+ # attributes
158
158
  def self.[](value)
159
159
  new(**value.to_h)
160
160
  end
@@ -34,7 +34,7 @@ class Ollama::Tool::Function::Parameters::Property
34
34
  # The enum attribute reader returns the enumeration values associated with the object.
35
35
  #
36
36
  # @return [ Array<String>, nil ] an array of valid string values that the
37
- # property can take, or nil if not set
37
+ # property can take, or nil if not set
38
38
  attr_reader :enum
39
39
 
40
40
  # The initialize method sets up a new Property instance with the specified
@@ -33,7 +33,7 @@ class Ollama::Tool::Function::Parameters
33
33
  # associated with the object.
34
34
  #
35
35
  # @return [ Array<String>, nil ] an array of required parameter names, or nil
36
- # if not set
36
+ # if not set
37
37
  attr_reader :required
38
38
 
39
39
  # The initialize method sets up a new Parameters instance with the specified
data/lib/ollama/tool.rb CHANGED
@@ -23,14 +23,14 @@ class Ollama::Tool
23
23
  # The type attribute reader returns the type associated with the tool.
24
24
  #
25
25
  # @return [ String ] the type of tool, typically 'function' for function
26
- # calling capabilities
26
+ # calling capabilities
27
27
  attr_reader :type
28
28
 
29
29
  # The function attribute reader returns the function definition associated
30
30
  # with the tool.
31
31
  #
32
32
  # @return [ Hash ] the function definition as a hash, containing details such
33
- # as the function's name, description, parameters, and required fields
33
+ # as the function's name, description, parameters, and required fields
34
34
  attr_reader :function
35
35
 
36
36
  # The initialize method sets up a new Tool instance with the specified type
@@ -38,7 +38,7 @@ class Ollama::Tool
38
38
  #
39
39
  # @param type [ String ] the type of tool being created
40
40
  # @param function [ Ollama::Tool::Function ] the function definition
41
- # associated with the tool
41
+ # associated with the tool
42
42
  def initialize(type:, function:)
43
43
  @type, @function = type, function.to_hash
44
44
  end
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '1.17.0'
3
+ VERSION = '1.19.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.17.0 ruby lib
2
+ # stub: ollama-ruby 1.19.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "1.17.0".freeze
6
+ s.version = "1.19.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]
@@ -18,14 +18,14 @@ Gem::Specification.new do |s|
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
- s.rubygems_version = "4.0.2".freeze
21
+ s.rubygems_version = "4.0.3".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
 
25
25
  s.specification_version = 4
26
26
 
27
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.8".freeze])
28
- s.add_development_dependency(%q<all_images>.freeze, ["~> 0.6".freeze])
27
+ s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.17.0".freeze])
28
+ s.add_development_dependency(%q<all_images>.freeze, ["~> 0.12".freeze])
29
29
  s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2".freeze])
30
30
  s.add_development_dependency(%q<kramdown>.freeze, ["~> 2.0".freeze])
31
31
  s.add_development_dependency(%q<webmock>.freeze, [">= 0".freeze])
@@ -21,6 +21,17 @@ describe Ollama::Client do
21
21
  expect(client.output).to be $stdout
22
22
  end
23
23
 
24
+ it 'can be instantiated with config and api_key' do
25
+ config = Ollama::Client::Config[base_url: base_url, api_key: 'the-secret']
26
+ client = described_class.configure_with(config).expose
27
+ expect(client).to be_a described_class
28
+ expect(client.base_url.to_s).to eq base_url
29
+ expect(client.api_key).to eq 'the-secret'
30
+ expect(client.headers).to include(
31
+ 'Authorization' => 'Bearer the-secret'
32
+ )
33
+ end
34
+
24
35
  it 'can be instantiated with config loaded from JSON' do
25
36
  config = Ollama::Client::Config.load_from_json(asset('client.json'))
26
37
  config.base_url = base_url
@@ -34,14 +45,11 @@ describe Ollama::Client do
34
45
  expect(client.instance_variable_get(:@read_timeout)).to eq 3_600
35
46
  end
36
47
 
37
- it 'can be configured via environment variable' do
38
- old_base_url = ENV['OLLAMA_URL']
48
+ it 'can be configured via environment variable', protect_env: true do
39
49
  ENV.delete('OLLAMA_URL')
40
50
  expect { described_class.new }.to raise_error(ArgumentError)
41
51
  ENV['OLLAMA_URL'] = base_url
42
52
  expect(described_class.new).to be_a described_class
43
- ensure
44
- ENV['OLLAMA_URL'] = old_base_url
45
53
  end
46
54
 
47
55
  it 'can disable ssl peer verification' do
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,38 @@ def asset(name)
14
14
  File.join(__dir__, 'assets', name)
15
15
  end
16
16
 
17
+ # A module that provides functionality for protecting environment variables
18
+ # during tests.
19
+ #
20
+ # This module ensures that environment variable changes made during test
21
+ # execution are automatically restored to their original values after the test
22
+ # completes. It is designed to prevent side effects between tests that modify
23
+ # environment variables, maintaining a clean testing environment.
24
+ module ProtectEnvVars
25
+ # The apply method creates a lambda that protects environment variables
26
+ # during test execution.
27
+ #
28
+ # @return [Proc] a lambda that wraps test execution with environment variable
29
+ # preservation
30
+ def self.apply
31
+ -> example do
32
+ if example.metadata[:protect_env]
33
+ begin
34
+ stored_env = ENV.to_h
35
+ example.run
36
+ ensure
37
+ ENV.replace(stored_env)
38
+ end
39
+ else
40
+ example.run
41
+ end
42
+ end
43
+ end
44
+ end
45
+
17
46
  RSpec.configure do |config|
47
+ config.around(&ProtectEnvVars.apply)
48
+
18
49
  config.before(:suite) do
19
50
  infobar.show = nil
20
51
  end
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.17.0
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -13,30 +13,30 @@ dependencies:
13
13
  name: gem_hadar
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '2.8'
18
+ version: 2.17.0
19
19
  type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - "~>"
23
+ - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '2.8'
25
+ version: 2.17.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: all_images
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.6'
32
+ version: '0.12'
33
33
  type: :development
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.6'
39
+ version: '0.12'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rspec
42
42
  requirement: !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: 4.0.2
416
+ rubygems_version: 4.0.3
417
417
  specification_version: 4
418
418
  summary: Interacting with the Ollama API
419
419
  test_files: