ollama-ruby 1.3.0 → 1.5.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: e26fc8b8ae9847d35f0422d1b4d8915c496b3a0d96b8ac202b7928c0f9ae7bd0
4
- data.tar.gz: 802709860c8611397faf70b4f4fa7af41a0bebc2c5a642d97163b6337e6326e1
3
+ metadata.gz: 6f22498af2b68b25f11d486872f46a42ad16b94244d3f0a9cb7df9e436056894
4
+ data.tar.gz: aa154d720f3df668020bdf39d38c7964e7081cabcfa4daec761ebb3809bfa57f
5
5
  SHA512:
6
- metadata.gz: 26c44972749476a2fe6af10c97f7c18482d0ecca058e4ef3b416ec7e019d0109d6f5d24f7266cb37ddb420f59cd2c939a21bed44ab5db0180b1988bc4a8350de
7
- data.tar.gz: 6be99709d688a678a4d6bbb12501cb0d758a5e794f76cb8310ce315c7956c53af456e8148bf05962fd4a8801c9f17f06187d84631182d03609920870aa8a84d4
6
+ metadata.gz: a32fb5d1bd7dd225c8917c8e43b43f9983eb85c971fbe01f4993f9b0131761d467a93658d2cf50ca5db1d44da6ea20ad6885aded8a5747ea259ab3d4c261c6b2
7
+ data.tar.gz: 067ca2f5c9c7de901732aae837dc151e023751a935952e4c0533dd50124610c367fc6149e16c096724077bb0c8f9f0781028f7dd108a32dfd4cdf1b533af9040
data/CHANGES.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-07-21 v1.5.0
4
+
5
+ * Update `ollama_cli` script to handle client configuration via JSON and
6
+ clarify argument types:
7
+ * Added support for `-c ` option to specify client configuration as JSON
8
+ * Updated documentation to clarify which arguments expect JSON input
9
+ * Replaced direct client initialization with `configure_with` method for
10
+ better maintainability
11
+ * Update documentation for `ollama_cli` script:
12
+ * Reorganized usage instructions for clarity
13
+ * Added descriptions for new options: `-c ` and `-H `
14
+ * Clarified which arguments expect JSON input:
15
+ - `-M OPTIONS`: model options in JSON format
16
+ - `-s SYSTEM` and `-p PROMPT`: plain text inputs
17
+ * Improved formatting for better readability
18
+ * Add `ollama_browse` to Rakefile executable tasks
19
+
20
+ ## 2025-07-17 v1.4.0
21
+
22
+ * **New CLI Tool**: Added `bin/ollama_browse` for exploring model tags and
23
+ metadata.
24
+ * **JSON Configuration Support**:
25
+ - Introduced `lib/ollama/json_loader.rb` to load configurations from JSON
26
+ files.
27
+ - Enhanced `Config` and `Options` classes with JSON parsing capabilities.
28
+ * **Client Customization**:
29
+ - Added `configure_with` method in `Ollama::Client` for initializing clients
30
+ using `Config` objects.
31
+ * **Documentation Updates**: Included detailed usage examples for basic setups
32
+ and configurations.
33
+ * **Testing Improvements**: Expanded test coverage for JSON file parsing and
34
+ configuration handling.
35
+ * **Output Enhancements**: Refined formatting in `ollama_browse` to display
36
+ file size and context size.
37
+
3
38
  ## 2025-07-06 v1.3.0
4
39
 
5
40
  * Added toggleable streaming in Markdown handler:
data/README.md CHANGED
@@ -28,18 +28,41 @@ to your Gemfile and run `bundle install` in your terminal.
28
28
 
29
29
  ## Usage
30
30
 
31
- In your own software the library can be used as shown in this example:
31
+ In your own software the library can be used as shown in these examples:
32
+
33
+ ### Basic Usage
32
34
 
33
35
  ```ruby
34
36
  require 'ollama'
35
37
  include Ollama
36
38
 
39
+ # Call directly with settings as keywords
37
40
  ollama = Client.new(base_url: 'http://localhost:11434')
41
+
42
+ messages = Message.new(role: 'user', content: 'Why is the sky blue?')
43
+ ollama.chat(model: 'llama3.1', stream: true, messages:, &Print)
44
+ ```
45
+
46
+ ### Using Configuration Object
47
+
48
+ ```ruby
49
+ require 'ollama'
50
+ include Ollama
51
+
52
+ # Create a configuration object with desired settings
53
+ config = Client::Config[
54
+ base_url: 'http://localhost:11434',
55
+ output: $stdout,
56
+ connect_timeout: 15,
57
+ read_timeout: 300
58
+ ]
59
+ # Or config = Client::Config.load_from_json('path/to/client.json')
60
+
61
+ # Initialize client using the configuration
62
+ ollama = Client.configure_with(config)
63
+
38
64
  messages = Message.new(role: 'user', content: 'Why is the sky blue?')
39
- ollama.chat(model: 'llama3.1', stream: true, messages:, &Print) # or
40
- print ollama.chat(model: 'llama3.1', stream: true, messages:).lazy.map { |response|
41
- response.message.content
42
- }
65
+ ollama.chat(model: 'llama3.1', stream: true, messages:, &Print)
43
66
  ```
44
67
 
45
68
  ## Try out things in ollama\_console
@@ -327,26 +350,22 @@ To use `ollama_cli`, simply run it from the command line and follow the usage
327
350
  instructions:
328
351
 
329
352
  ```bash
330
- ollama_cli [OPTIONS]
331
- ```
353
+ Usage: ollama_cli [OPTIONS]
354
+
355
+ -u URL the ollama base url, $OLLAMA_URL
356
+ -c CLIENT the ollama client config (JSON), $OLLAMA_CLIENT
357
+ -m MODEL the ollama model to chat with, $OLLAMA_MODEL
358
+ -M OPTIONS the ollama model options (JSON), $OLLAMA_MODEL_OPTIONS
359
+ -s SYSTEM the system prompt as plain text, $OLLAMA_SYSTEM
360
+ -p PROMPT the user prompt as plain text, $OLLAMA_PROMPT
361
+ if it contains %{stdin} it is substituted by stdin input
362
+ -P VARIABLE sets prompt var %{foo} to "bar" if VARIABLE is foo=bar
363
+ -H HANDLER the handler to use for the response, defaults to ChatStart
364
+ -S use streaming for generation
365
+ -T use thinking for generation
366
+ -h this help
332
367
 
333
- The available options are:
334
-
335
- * `-u URL`: The Ollama base URL. Can be set as an environment variable
336
- `OLLAMA_URL`.
337
- * `-m MODEL`: The Ollama model to chat with. Defaults to `llama3.1` if not
338
- specified.
339
- * `-M OPTIONS`: The Ollama model options to use. Can be set as an environment
340
- variable `OLLAMA_MODEL_OPTIONS`.
341
- * `-s SYSTEM`: The system prompt to use as a file. Can be set as an environment
342
- variable `OLLAMA_SYSTEM`.
343
- * `-p PROMPT`: The user prompt to use as a file. If it contains `%{stdin}`, it
344
- will be substituted with the standard input. If not given, stdin will be used
345
- as the prompt.
346
- * `-P VARIABLE`: Sets a prompt variable, e.g. `foo=bar`. Can be used multiple
347
- times.
348
- * `-H HANDLER`: The handler to use for the response. Defaults to `Print`.
349
- * `-S`: Use streaming for generation.
368
+ ```
350
369
 
351
370
  #### Environment Variables
352
371
 
@@ -354,10 +373,11 @@ The following environment variables can be set to customize the behavior of
354
373
  `ollama_cli`:
355
374
 
356
375
  * `OLLAMA_URL`: The Ollama base URL.
376
+ * `OLLAMA_CLIENT`: The client config (JSON).
357
377
  * `OLLAMA_MODEL`: The Ollama model to chat with.
358
- * `OLLAMA_MODEL_OPTIONS`: The Ollama model options to use.
359
- * `OLLAMA_SYSTEM`: The system prompt to use as a file.
360
- * `OLLAMA_PROMPT`: The user prompt to use as a file.
378
+ * `OLLAMA_MODEL_OPTIONS`: The Ollama model options (JSON).
379
+ * `OLLAMA_SYSTEM`: The system prompt to use as plain text.
380
+ * `OLLAMA_PROMPT`: The user prompt to use as plain text.
361
381
 
362
382
  #### Debug Mode
363
383
 
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ GemHadar do
19
19
  '.rspec', *Dir.glob('.github/**/*', File::FNM_DOTMATCH)
20
20
  readme 'README.md'
21
21
 
22
- executables << 'ollama_console' << 'ollama_update' << 'ollama_cli'
22
+ executables << 'ollama_console' << 'ollama_update' << 'ollama_cli' << 'ollama_browse'
23
23
 
24
24
  required_ruby_version '~> 3.1'
25
25
 
data/bin/ollama_browse ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'term/ansicolor'
4
+ include Term::ANSIColor
5
+ require 'ollama'
6
+ include Ollama
7
+ require 'excon'
8
+ require 'nokogiri'
9
+
10
+ model = ARGV.shift or fail 'model name as first argument is required'
11
+ url_prefix = 'https://ollama.com/library'
12
+ tags_url = '%s/%s/tags' % [ url_prefix, model ]
13
+ result = Excon.get(tags_url)
14
+ if result.status >= 400
15
+ STDERR.puts 'Model %s cannot be browsed, HTTP result code %u' % [ model, result.status ]
16
+ exit 1
17
+ end
18
+ body = result.body
19
+ doc = Nokogiri::HTML(body)
20
+
21
+ # They are never permitted to change the structure of this HTML…
22
+ css = 'section div div .group.px-4.py-3'
23
+ tags = (doc / css).map do |element|
24
+ tagged_name = (element / 'a div div div span').text
25
+ file_size, context_size = (element / 'p').map(&:text)
26
+ hash = (element / 'a .text-neutral-500 span .font-mono').text
27
+ [ tagged_name, file_size, context_size, hash ]
28
+ end.group_by(&:last)
29
+
30
+ puts bold('Model: ') + hyperlink(tags_url) { model }
31
+ tags.each do |hash, tagged_blobs|
32
+ print bold(hash)
33
+ first_blob = true
34
+ tagged_blobs.each do |(tag, _), file_size, context_size|
35
+ if first_blob
36
+ puts ' ' + [ file_size, context_size ] * ' '
37
+ first_blob = false
38
+ end
39
+ puts ' · ' + hyperlink('%s/%s' % [ url_prefix, tag ]) { blue(tag) }
40
+ end
41
+ end
data/bin/ollama_cli CHANGED
@@ -68,10 +68,11 @@ def usage
68
68
  Usage: #{File.basename($0)} [OPTIONS]
69
69
 
70
70
  -u URL the ollama base url, $OLLAMA_URL
71
+ -c CLIENT the ollama client config (JSON), $OLLAMA_CLIENT
71
72
  -m MODEL the ollama model to chat with, $OLLAMA_MODEL
72
- -M OPTIONS the ollama model options to use, $OLLAMA_MODEL_OPTIONS
73
- -s SYSTEM the system prompt to use as a file, $OLLAMA_SYSTEM
74
- -p PROMPT the user prompt to use as a file, $OLLAMA_PROMPT
73
+ -M OPTIONS the ollama model options (JSON), $OLLAMA_MODEL_OPTIONS
74
+ -s SYSTEM the system prompt as plain text, $OLLAMA_SYSTEM
75
+ -p PROMPT the user prompt as plain text, $OLLAMA_PROMPT
75
76
  if it contains %{stdin} it is substituted by stdin input
76
77
  -P VARIABLE sets prompt var %{foo} to "bar" if VARIABLE is foo=bar
77
78
  -H HANDLER the handler to use for the response, defaults to ChatStart
@@ -83,11 +84,15 @@ def usage
83
84
  exit 0
84
85
  end
85
86
 
86
- opts = go 'u:m:M:s:p:P:H:STh', defaults: { ?H => 'ChatStart', ?M => '{}' }
87
+ opts = go 'u:m:M:s:p:P:H:c:STh', defaults: { ?H => 'ChatStart', ?M => '{}' }
87
88
 
88
89
  opts[?h] and usage
89
90
 
90
- base_url = opts[?u] || ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
91
+ base_url = opts[?u] || ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
92
+ client_config = Client::Config[
93
+ { base_url: } |
94
+ JSON(get_file_argument(opts[?c], default: ENV['OLLAMA_CLIENT']).full? || '{}')
95
+ ]
91
96
  model = opts[?m] || ENV.fetch('OLLAMA_MODEL', 'llama3.1')
92
97
  options = Ollama::Options.from_hash(JSON(
93
98
  get_file_argument(opts[?M], default: ENV['OLLAMA_MODEL_OPTIONS'])
@@ -127,7 +132,7 @@ handler = case
127
132
  handler
128
133
  end
129
134
 
130
- Client.new(base_url:, read_timeout: 120).generate(
135
+ Client.configure_with(client_config).generate(
131
136
  model:,
132
137
  system:,
133
138
  prompt:,
@@ -0,0 +1,35 @@
1
+ require 'ollama/json_loader'
2
+
3
+ module Ollama::Client::Configuration
4
+ class Config
5
+ extend Ollama::JSONLoader
6
+
7
+ def initialize(**attributes)
8
+ attributes.each { |k, v| send("#{k}=", v) }
9
+ self.output ||= $stdout
10
+ end
11
+
12
+ def self.[](value)
13
+ new(**value.to_h)
14
+ end
15
+
16
+ attr_accessor :base_url, :output, :connect_timeout, :read_timeout,
17
+ :write_timeout, :debug, :user_agent
18
+ end
19
+
20
+ extend Tins::Concern
21
+
22
+ module ClassMethods
23
+ def configure_with(config)
24
+ new(
25
+ base_url: config.base_url,
26
+ output: config.output,
27
+ connect_timeout: config.connect_timeout,
28
+ read_timeout: config.read_timeout,
29
+ write_timeout: config.write_timeout,
30
+ debug: config.debug,
31
+ user_agent: config.user_agent
32
+ )
33
+ end
34
+ end
35
+ end
data/lib/ollama/client.rb CHANGED
@@ -2,10 +2,12 @@ class Ollama::Client
2
2
  end
3
3
  require 'ollama/client/doc'
4
4
  require 'ollama/client/command'
5
+ require 'ollama/client/configuration/config'
5
6
 
6
7
  class Ollama::Client
7
8
  include Tins::Annotate
8
9
  include Ollama::Handlers
10
+ include Ollama::Client::Configuration
9
11
  include Ollama::Client::Command
10
12
 
11
13
  annotate :doc
@@ -0,0 +1,6 @@
1
+ module Ollama::JSONLoader
2
+ def load_from_json(path)
3
+ json = File.read(path)
4
+ new(**config_hash = JSON.parse(json, symbolize_names: true))
5
+ end
6
+ end
@@ -1,7 +1,10 @@
1
+ require 'ollama/json_loader'
2
+
1
3
  # Options are explained in the parameters for the modelfile:
2
4
  # https://github.com/ollama/ollama/blob/main/docs/modelfile.md#parameter
3
5
  class Ollama::Options
4
6
  include Ollama::DTO
7
+ extend Ollama::JSONLoader
5
8
 
6
9
  @@types = {
7
10
  numa: [ false, true ],
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '1.3.0'
3
+ VERSION = '1.5.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.3.0 ruby lib
2
+ # stub: ollama-ruby 1.5.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "1.3.0".freeze
6
+ s.version = "1.5.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]
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
11
11
  s.date = "1980-01-02"
12
12
  s.description = "Library that allows interacting with the Ollama API".freeze
13
13
  s.email = "flori@ping.de".freeze
14
- s.executables = ["ollama_console".freeze, "ollama_update".freeze, "ollama_cli".freeze]
15
- s.extra_rdoc_files = ["README.md".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/commands/version.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/version.rb".freeze]
16
- s.files = [".yardopts".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_cli".freeze, "bin/ollama_console".freeze, "bin/ollama_update".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/commands/version.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/version.rb".freeze, "ollama-ruby.gemspec".freeze, "spec/assets/kitten.jpg".freeze, "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, "tmp/.keep".freeze]
14
+ s.executables = ["ollama_console".freeze, "ollama_update".freeze, "ollama_cli".freeze, "ollama_browse".freeze]
15
+ s.extra_rdoc_files = ["README.md".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/configuration/config.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/commands/version.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/json_loader.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/version.rb".freeze]
16
+ s.files = [".yardopts".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_browse".freeze, "bin/ollama_cli".freeze, "bin/ollama_console".freeze, "bin/ollama_update".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/configuration/config.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/commands/version.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/json_loader.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/version.rb".freeze, "ollama-ruby.gemspec".freeze, "spec/assets/client.json".freeze, "spec/assets/kitten.jpg".freeze, "spec/assets/options.json".freeze, "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, "tmp/.keep".freeze]
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]
@@ -0,0 +1,4 @@
1
+ {
2
+ "connect_timeout": 60,
3
+ "read_timeout": 3600
4
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "num_ctx": 16384,
3
+ "seed": -1,
4
+ "num_predict": 1024,
5
+ "temperature": 0.666,
6
+ "top_p": 0.95,
7
+ "min_p": 0.1
8
+ }
@@ -13,6 +13,27 @@ RSpec.describe Ollama::Client do
13
13
  expect(ollama).to be_a described_class
14
14
  end
15
15
 
16
+ it 'can be instantiated with config' do
17
+ config = Ollama::Client::Config[base_url: base_url]
18
+ client = described_class.configure_with(config)
19
+ expect(client).to be_a described_class
20
+ expect(client.base_url.to_s).to eq base_url
21
+ expect(client.output).to be $stdout
22
+ end
23
+
24
+ it 'can be instantiated with config loaded from JSON' do
25
+ config = Ollama::Client::Config.load_from_json(asset('client.json'))
26
+ config.base_url = base_url
27
+ expect(config.read_timeout).to eq 3_600
28
+ expect(config.connect_timeout).to eq 60
29
+ client = described_class.configure_with(config)
30
+ expect(client).to be_a described_class
31
+ expect(client.base_url.to_s).to eq base_url
32
+ expect(client.output).to be $stdout
33
+ expect(client.instance_variable_get(:@connect_timeout)).to eq 60
34
+ expect(client.instance_variable_get(:@read_timeout)).to eq 3_600
35
+ end
36
+
16
37
  it 'can be configured via environment variable' do
17
38
  expect { described_class.new }.to raise_error(ArgumentError)
18
39
  ENV['OLLAMA_URL'] = base_url
@@ -13,6 +13,17 @@ RSpec.describe Ollama::Options do
13
13
  expect(options).to be_a described_class
14
14
  end
15
15
 
16
+ it 'can be configured by loading from JSON' do
17
+ options = described_class.load_from_json(asset('options.json'))
18
+ expect(options).to be_a described_class
19
+ expect(options.num_ctx).to eq(16384)
20
+ expect(options.seed).to eq(-1)
21
+ expect(options.num_predict).to eq(1024)
22
+ expect(options.temperature).to be_within(1E-6).of(0.666)
23
+ expect(options.top_p).to be_within(0.001).of(0.95)
24
+ expect(options.min_p).to be_within(0.001).of(0.1)
25
+ end
26
+
16
27
  it 'can be empty' do
17
28
  expect(described_class.new).to be_empty
18
29
  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.3.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -214,6 +214,7 @@ dependencies:
214
214
  description: Library that allows interacting with the Ollama API
215
215
  email: flori@ping.de
216
216
  executables:
217
+ - ollama_browse
217
218
  - ollama_cli
218
219
  - ollama_console
219
220
  - ollama_update
@@ -223,6 +224,7 @@ extra_rdoc_files:
223
224
  - lib/ollama.rb
224
225
  - lib/ollama/client.rb
225
226
  - lib/ollama/client/command.rb
227
+ - lib/ollama/client/configuration/config.rb
226
228
  - lib/ollama/client/doc.rb
227
229
  - lib/ollama/commands/chat.rb
228
230
  - lib/ollama/commands/copy.rb
@@ -251,6 +253,7 @@ extra_rdoc_files:
251
253
  - lib/ollama/handlers/say.rb
252
254
  - lib/ollama/handlers/single.rb
253
255
  - lib/ollama/image.rb
256
+ - lib/ollama/json_loader.rb
254
257
  - lib/ollama/message.rb
255
258
  - lib/ollama/options.rb
256
259
  - lib/ollama/response.rb
@@ -266,12 +269,14 @@ files:
266
269
  - LICENSE
267
270
  - README.md
268
271
  - Rakefile
272
+ - bin/ollama_browse
269
273
  - bin/ollama_cli
270
274
  - bin/ollama_console
271
275
  - bin/ollama_update
272
276
  - lib/ollama.rb
273
277
  - lib/ollama/client.rb
274
278
  - lib/ollama/client/command.rb
279
+ - lib/ollama/client/configuration/config.rb
275
280
  - lib/ollama/client/doc.rb
276
281
  - lib/ollama/commands/chat.rb
277
282
  - lib/ollama/commands/copy.rb
@@ -300,6 +305,7 @@ files:
300
305
  - lib/ollama/handlers/say.rb
301
306
  - lib/ollama/handlers/single.rb
302
307
  - lib/ollama/image.rb
308
+ - lib/ollama/json_loader.rb
303
309
  - lib/ollama/message.rb
304
310
  - lib/ollama/options.rb
305
311
  - lib/ollama/response.rb
@@ -309,7 +315,9 @@ files:
309
315
  - lib/ollama/tool/function/parameters/property.rb
310
316
  - lib/ollama/version.rb
311
317
  - ollama-ruby.gemspec
318
+ - spec/assets/client.json
312
319
  - spec/assets/kitten.jpg
320
+ - spec/assets/options.json
313
321
  - spec/ollama/client/doc_spec.rb
314
322
  - spec/ollama/client_spec.rb
315
323
  - spec/ollama/commands/chat_spec.rb