ollama-ruby 1.18.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 +4 -4
- data/CHANGES.md +79 -30
- data/Rakefile +5 -1
- data/bin/ollama_cli +4 -3
- data/bin/ollama_console +11 -1
- data/bin/ollama_ps +10 -2
- data/lib/ollama/client/command.rb +1 -1
- data/lib/ollama/client/configuration/config.rb +10 -3
- data/lib/ollama/client.rb +12 -4
- data/lib/ollama/commands/chat.rb +1 -1
- data/lib/ollama/commands/copy.rb +1 -1
- data/lib/ollama/commands/create.rb +1 -1
- data/lib/ollama/commands/delete.rb +1 -1
- data/lib/ollama/commands/embed.rb +1 -1
- data/lib/ollama/commands/embeddings.rb +1 -1
- data/lib/ollama/commands/ps.rb +1 -1
- data/lib/ollama/commands/pull.rb +2 -2
- data/lib/ollama/commands/tags.rb +1 -1
- data/lib/ollama/commands/version.rb +2 -2
- data/lib/ollama/handlers/collector.rb +1 -1
- data/lib/ollama/handlers/concern.rb +3 -3
- data/lib/ollama/handlers/dump_yaml.rb +2 -2
- data/lib/ollama/handlers/markdown.rb +2 -2
- data/lib/ollama/handlers/progress.rb +3 -3
- data/lib/ollama/handlers/say.rb +3 -3
- data/lib/ollama/handlers/single.rb +1 -1
- data/lib/ollama/image.rb +5 -5
- data/lib/ollama/options.rb +1 -1
- data/lib/ollama/tool/function/parameters/property.rb +1 -1
- data/lib/ollama/tool/function/parameters.rb +1 -1
- data/lib/ollama/tool.rb +3 -3
- data/lib/ollama/version.rb +1 -1
- data/ollama-ruby.gemspec +5 -5
- data/spec/ollama/client_spec.rb +12 -4
- data/spec/spec_helper.rb +31 -0
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dcb4d954bc66b999983fbb02192c600d1ee1f5e052ae7808e5d287268cc54eb3
|
|
4
|
+
data.tar.gz: 3c7a867320432d99f091b11c3955a3ca9f2b66888340effae91bf34f21768e8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0d81e6b9df50f005efed07afc8dfc82fad1f072a293276526ff35f075bfc6c06d526e49a0a15d340ed84d1b470a27ee62ecd4754a776ceacc8890f7a6cc08c6
|
|
7
|
+
data.tar.gz: a9f0c6c8cf62f75dea4f92a02f1c40b1f7b92034b69e83ba34a6282fd01df6126c14f2abd14987bd4d996023314675ede5cbbec8ca04b106d53807c971f710a4
|
data/CHANGES.md
CHANGED
|
@@ -1,12 +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
|
+
|
|
3
36
|
## 2025-12-19 v1.18.0
|
|
4
37
|
|
|
5
38
|
- Updated `gem_hadar` development dependency from version **2.8** to **2.9**
|
|
6
39
|
|
|
7
40
|
## 2025-12-19 v1.17.0
|
|
8
41
|
|
|
9
|
-
- Changed `s.required_ruby_version` in the gemspec from "~> 3.1" to ">= 3.1" to
|
|
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**
|
|
10
44
|
- Updated `s.rubygems_version` from **3.7.2** to **4.0.2**
|
|
11
45
|
- Replaced `bundle update` with `bundle update --all` in the update command
|
|
12
46
|
- Added **4.0-rc** release candidate to the Ruby version matrix (commented out)
|
|
@@ -72,10 +106,13 @@
|
|
|
72
106
|
## 2025-11-30 v1.12.0
|
|
73
107
|
|
|
74
108
|
- `ollama_cli`
|
|
75
|
-
- Added `-i` flag to display Ollama server version using
|
|
76
|
-
|
|
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`
|
|
77
113
|
- Stored client configuration in `ollama` variable for reuse
|
|
78
|
-
- Added `-d` flag for debug mode in `ollama_cli` instead of using
|
|
114
|
+
- Added `-d` flag for debug mode in `ollama_cli` instead of using
|
|
115
|
+
environment variable
|
|
79
116
|
- Included `Ollama::DTO` in `Client::Config` class for consistent behavior
|
|
80
117
|
- Improved documentation formatting in `dto.rb` file
|
|
81
118
|
- Added documentation that `think` can be "high", "medium", "low" instead of just `true`
|
|
@@ -502,7 +539,7 @@ and introduced new context files for project structure documentation in
|
|
|
502
539
|
+ Normalizes URL by decoding URI components, removing anchors, and escaping special characters
|
|
503
540
|
+ `excon` method now calls `normalize_url` on the provided URL
|
|
504
541
|
+ Added specs for `normalize_url` in `fetcher_spec.rb`
|
|
505
|
-
* 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`:
|
|
506
543
|
+ Removed the top-level namespace
|
|
507
544
|
|
|
508
545
|
## 2024-10-18 v0.9.0
|
|
@@ -554,7 +591,7 @@ and introduced new context files for project structure documentation in
|
|
|
554
591
|
+ Moved case order
|
|
555
592
|
+ Renamed `/collection clear [tag]|change` to `/collection (clear|change)`
|
|
556
593
|
+ Improved help message, added /info
|
|
557
|
-
* **Update README.md**
|
|
594
|
+
* **Update README.md**
|
|
558
595
|
+ Update README.md to reflect changed/added commands
|
|
559
596
|
* **Add support for reading PostScript**
|
|
560
597
|
+ Extracted `pdf_read` method to read PDF files using `PDF::Reader`
|
|
@@ -572,7 +609,7 @@ and introduced new context files for project structure documentation in
|
|
|
572
609
|
+ Updated `choose` method to handle cases better where no entry was chosen
|
|
573
610
|
* **Fix Redis cache expiration logic**
|
|
574
611
|
+ Update `set` method to delete key expiration time is less than 1 second.
|
|
575
|
-
* **Update dependencies and add source tracking**
|
|
612
|
+
* **Update dependencies and add source tracking**
|
|
576
613
|
- Remove `sorted_set` dependency from Rakefile
|
|
577
614
|
- Modify `Ollama::Documents` class to track source of tags
|
|
578
615
|
- Update `Ollama::Utils::Tags` class to include source in tag output and add methods for tracking source
|
|
@@ -787,28 +824,28 @@ and introduced new context files for project structure documentation in
|
|
|
787
824
|
|
|
788
825
|
* Update dependencies and date in gemspec files:
|
|
789
826
|
- Updated `complex_config` dependency to '~> 0.22'
|
|
790
|
-
* Refactor FollowChat#eval_stats to add bold eval rates
|
|
791
|
-
* 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
|
|
792
829
|
readability.
|
|
793
|
-
* Update import_document and add_image methods to handle nil values
|
|
830
|
+
* Update `import_document` and `add_image` methods to handle nil values
|
|
794
831
|
correctly.
|
|
795
832
|
* Update width method in utils/width.rb to use uncolor when checking line
|
|
796
833
|
length.
|
|
797
834
|
* Refactor eval stats output in FollowChat class
|
|
798
835
|
- Add indentation to eval stats output for better readability
|
|
799
836
|
* FollowChat evaluation stats refactored
|
|
800
|
-
- Removed hardcoded eval_stats hash and replaced with method call
|
|
837
|
+
- Removed hardcoded `eval_stats` hash and replaced with method call
|
|
801
838
|
`eval_stats(response)`
|
|
802
839
|
- Added new method `eval_stats(response)` to calculate evaluation statistics
|
|
803
840
|
- Calculates eval duration, prompt eval duration, total duration, and load
|
|
804
841
|
duration
|
|
805
842
|
- Adds eval count, prompt eval count, eval rate, and prompt eval rate
|
|
806
|
-
* Use default to_s tree representation of config.
|
|
807
|
-
* Update complex_config dependency to ~> 0.21, >= 0.21.1 in Rakefile
|
|
808
|
-
* 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
|
|
809
846
|
ollama-ruby.gemspec
|
|
810
847
|
* Update dependencies and configuration display
|
|
811
|
-
* Update
|
|
848
|
+
* Update `complex_config` dependency to '~> 0.21'
|
|
812
849
|
* Change OllamaChatConfig to display configuration as a tree instead of yaml
|
|
813
850
|
* Improve /web search command
|
|
814
851
|
* Update infobar dependency to ~> 0.8
|
|
@@ -858,9 +895,10 @@ and introduced new context files for project structure documentation in
|
|
|
858
895
|
+ Updated `/summarize` command to handle cases where summarization fails
|
|
859
896
|
+ Fix bug in parsing content type of source document
|
|
860
897
|
* **Refactored Options Class and Usage**
|
|
861
|
-
+ Renamed `options` variable to use `Options[]` method in ollama_chat
|
|
898
|
+
+ Renamed `options` variable to use `Options[]` method in `ollama_chat`
|
|
899
|
+
script
|
|
862
900
|
+ Added `[](value)` method to Ollama::Options class for casting hashes
|
|
863
|
-
+ 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
|
|
864
902
|
* **Refactored Web Search Command**
|
|
865
903
|
+ Added support for specifying a page number in `/web` command
|
|
866
904
|
+ Updated regular expression to match new format
|
|
@@ -870,10 +908,11 @@ and introduced new context files for project structure documentation in
|
|
|
870
908
|
+ Renamed `json_create` method to `from_hash` in Ollama::DTO class
|
|
871
909
|
+ Updated `as_json` method to remove now unnecessary hash creation
|
|
872
910
|
* **Message and Tool Spec Changes**
|
|
873
|
-
+ Removed `json_class` from JSON serialization in message_spec
|
|
874
|
-
+ 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`
|
|
875
913
|
* **Command Spec Changes**
|
|
876
|
-
+ Removed `json_class` from JSON serialization in various command specs (e.g.
|
|
914
|
+
+ Removed `json_class` from JSON serialization in various command specs (e.g.
|
|
915
|
+
`generate_spec`, `pull_spec`, etc.)
|
|
877
916
|
* **Miscellaneous Changes**
|
|
878
917
|
+ Improved width calculation for text truncation
|
|
879
918
|
+ Updated FollowChat class to display evaluation statistics
|
|
@@ -886,26 +925,36 @@ and introduced new context files for project structure documentation in
|
|
|
886
925
|
|
|
887
926
|
#### Significant Changes
|
|
888
927
|
|
|
889
|
-
* **Document Splitting and Embedding Functionality**: Added `Ollama::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.
|
|
890
931
|
+ Introduced two types of caches: `MemoryCache` and `RedisCache`
|
|
891
|
-
+ Implemented `SemanticSplitter` class to split text into sentences based on
|
|
892
|
-
|
|
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
|
|
893
936
|
+ Allowed configuration per yaml file
|
|
894
937
|
+ Parse user input for URLs or files to send images to multimodal models
|
|
895
|
-
* **Redis Docker Service**: Set `REDIS_URL` environment variable to
|
|
938
|
+
* **Redis Docker Service**: Set `REDIS_URL` environment variable to
|
|
939
|
+
`redis://localhost:9736`
|
|
896
940
|
+ Added Redis service to `docker-compose.yml`
|
|
897
|
-
* **Status Display and Progress Updates**: Added infobar.label =
|
|
898
|
-
|
|
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
|
|
899
945
|
+ Display error message from response.error if present
|
|
900
|
-
* **Refactored Chat Commands**: Simplified regular expression patterns for
|
|
946
|
+
* **Refactored Chat Commands**: Simplified regular expression patterns for
|
|
947
|
+
`/pop`, `/save`, `/load`, and `/image` commands
|
|
901
948
|
+ Added whitespace to some command patterns for better readability
|
|
902
949
|
|
|
903
950
|
#### Other Changes
|
|
904
951
|
|
|
905
|
-
* Added `Character` and `RecursiveCharacter` splitter classes to split text
|
|
952
|
+
* Added `Character` and `RecursiveCharacter` splitter classes to split text
|
|
953
|
+
into chunks based on character separators
|
|
906
954
|
* Added RSpec tests for the Ollama::Documents class(es)
|
|
907
|
-
* Updated dependencies and added new methods for calculating breakpoint
|
|
908
|
-
|
|
955
|
+
* Updated dependencies and added new methods for calculating breakpoint
|
|
956
|
+
thresholds and sentence embeddings
|
|
957
|
+
* Added `ollama_update` to executables in Rakefile
|
|
909
958
|
* Started using webmock
|
|
910
959
|
* Refactored chooser and add fetcher specs
|
|
911
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.
|
|
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
|
-
#
|
|
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
|
|
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[
|
|
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
|
-
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
135
|
+
# object containing client settings
|
|
130
136
|
#
|
|
131
137
|
# @return [ Ollama::Client ] a new client instance configured with the
|
|
132
|
-
#
|
|
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.
|
data/lib/ollama/commands/chat.rb
CHANGED
|
@@ -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
|
-
#
|
|
110
|
+
# responses
|
|
111
111
|
#
|
|
112
112
|
# @return [ self ] returns the current instance after initiating the request
|
|
113
113
|
def perform(handler)
|
data/lib/ollama/commands/copy.rb
CHANGED
|
@@ -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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
85
|
+
# responses
|
|
86
86
|
#
|
|
87
87
|
# @return [ self ] returns the current instance after initiating the request
|
|
88
88
|
def perform(handler)
|
data/lib/ollama/commands/ps.rb
CHANGED
|
@@ -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
|
-
#
|
|
68
|
+
# responses
|
|
69
69
|
#
|
|
70
70
|
# @return [ self ] returns the current instance after initiating the request
|
|
71
71
|
def perform(handler)
|
data/lib/ollama/commands/pull.rb
CHANGED
|
@@ -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
|
-
#
|
|
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
|
-
#
|
|
84
|
+
# responses
|
|
85
85
|
#
|
|
86
86
|
# @return [ self ] returns the current instance after initiating the request
|
|
87
87
|
def perform(handler)
|
data/lib/ollama/commands/tags.rb
CHANGED
|
@@ -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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
70
|
+
# handler
|
|
71
71
|
#
|
|
72
72
|
# @return [ self ] returns the handler instance itself after processing the
|
|
73
|
-
#
|
|
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
|
-
#
|
|
22
|
+
# and output
|
|
23
23
|
#
|
|
24
24
|
# @return [ self ] returns the handler instance itself after processing the
|
|
25
|
-
#
|
|
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
|
-
#
|
|
39
|
+
# to be rendered
|
|
40
40
|
#
|
|
41
41
|
# @return [ self ] returns the handler instance itself after processing the
|
|
42
|
-
#
|
|
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
|
-
#
|
|
38
|
+
# progress information
|
|
39
39
|
#
|
|
40
40
|
# @return [ self ] returns the handler instance itself after processing the
|
|
41
|
-
#
|
|
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
|
data/lib/ollama/handlers/say.rb
CHANGED
|
@@ -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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
98
|
+
# data, false otherwise
|
|
99
99
|
def ==(other)
|
|
100
100
|
@data == other.data
|
|
101
101
|
end
|
data/lib/ollama/options.rb
CHANGED
|
@@ -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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
41
|
+
# associated with the tool
|
|
42
42
|
def initialize(type:, function:)
|
|
43
43
|
@type, @function = type, function.to_hash
|
|
44
44
|
end
|
data/lib/ollama/version.rb
CHANGED
data/ollama-ruby.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: ollama-ruby 1.
|
|
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.
|
|
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.
|
|
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, ["
|
|
28
|
-
s.add_development_dependency(%q<all_images>.freeze, ["~> 0.
|
|
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])
|
data/spec/ollama/client_spec.rb
CHANGED
|
@@ -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.
|
|
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:
|
|
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:
|
|
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.
|
|
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.
|
|
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.
|
|
416
|
+
rubygems_version: 4.0.3
|
|
417
417
|
specification_version: 4
|
|
418
418
|
summary: Interacting with the Ollama API
|
|
419
419
|
test_files:
|