ollama-ruby 1.2.1 → 1.4.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: 0b6a67a947af787d3a67180531d7afb1390a009adf38616b55f32bc6c9301942
4
- data.tar.gz: e7fb09439a06ede0a240f42f64048e88ac2d295fa50a8d3bc59dfed3bdb98b3a
3
+ metadata.gz: d7010b648d380dea2bb5fcfd89597af4abbb37e064905dce4e393162d9896ef5
4
+ data.tar.gz: ea8df217db7e0ddd70df548820c3abc73c7efa233af56ccde171dbaa087a9a92
5
5
  SHA512:
6
- metadata.gz: acc5e14fca8df34795a2cca585ff56157023b14dbd53c10995bf1751a39d2f137dbb9c5a26bbb2c58dc7a2ac1402d56ceea37eaf744189a5fc191f3532a0e57b
7
- data.tar.gz: b8f0357fa9734eed66dd7b9013df7f6e464d3a0af7bd00acd11552dfffb15951b18d12bd2ab7c2c45736a735f4ee4f9ae2900d96415cf30bf9ff6a401e4dd3f8
6
+ metadata.gz: 4ac32ac4fd527aa94f11b50fe72c0d22a4d326368d2d7655d090a4af9e3fea466f478574c2c0ce2d70ef1394e7f3da8709ee5f76fdbf9672004d91850d45245d
7
+ data.tar.gz: cfe22940814d91e3755cfc0d83b662db4ff505ac7b00980915eeaa51f63ff3b06a8a240cd926dbcf798d27c558c20c768a6f19e99119497e220c1e8fd1fd30f9
data/CHANGES.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-07-17 v1.4.0
4
+
5
+ * **New CLI Tool**: Added `bin/ollama_browse` for exploring model tags and
6
+ metadata.
7
+ * **JSON Configuration Support**:
8
+ - Introduced `lib/ollama/json_loader.rb` to load configurations from JSON
9
+ files.
10
+ - Enhanced `Config` and `Options` classes with JSON parsing capabilities.
11
+ * **Client Customization**:
12
+ - Added `configure_with` method in `Ollama::Client` for initializing clients
13
+ using `Config` objects.
14
+ * **Documentation Updates**: Included detailed usage examples for basic setups
15
+ and configurations.
16
+ * **Testing Improvements**: Expanded test coverage for JSON file parsing and
17
+ configuration handling.
18
+ * **Output Enhancements**: Refined formatting in `ollama_browse` to display
19
+ file size and context size.
20
+
21
+ ## 2025-07-06 v1.3.0
22
+
23
+ * Added toggleable streaming in Markdown handler:
24
+ * Added conditional handler initialization
25
+ * Implemented toggleable streaming in Markdown handler
26
+ * Tested non-streaming (`stream: false`) behavior
27
+
3
28
  ## 2025-06-02 v1.2.1
4
29
 
5
30
  * Added thinking mode option to CLI:
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
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
@@ -8,24 +8,26 @@ require 'tins/xt/secure_write'
8
8
  require 'json'
9
9
  require 'tmpdir'
10
10
 
11
- class ChatStart
12
- include Ollama::Handlers::Concern
13
-
14
- def initialize(output: $stdout)
15
- super
16
- @output.sync = true
17
- @content = ''
18
- end
11
+ module Ollama::Handlers
12
+ class ChatStart
13
+ include Ollama::Handlers::Concern
14
+
15
+ def initialize(output: $stdout)
16
+ super
17
+ @output.sync = true
18
+ @content = ''
19
+ end
19
20
 
20
- attr_reader :content
21
+ attr_reader :content
21
22
 
22
- def call(response)
23
- if content = response.response
24
- @content << content
25
- @output << content
23
+ def call(response)
24
+ if content = response.response
25
+ @content << content
26
+ @output << content
27
+ end
28
+ response.done and @output.puts
29
+ self
26
30
  end
27
- response.done and @output.puts
28
- self
29
31
  end
30
32
  end
31
33
 
@@ -115,8 +117,15 @@ if ENV['DEBUG'].to_i == 1
115
117
  EOT
116
118
  end
117
119
 
118
- handler = Object.const_get(opts[?H])
119
- handler == ChatStart and handler = handler.new
120
+ handler = Ollama::Handlers.const_get(opts[?H])
121
+ handler = case
122
+ when handler == Ollama::Handlers::ChatStart
123
+ handler.new
124
+ when handler == Ollama::Handlers::Markdown
125
+ handler.new(stream: !!opts[?S])
126
+ else
127
+ handler
128
+ end
120
129
 
121
130
  Client.new(base_url:, read_timeout: 120).generate(
122
131
  model:,
@@ -128,7 +137,7 @@ Client.new(base_url:, read_timeout: 120).generate(
128
137
  &handler
129
138
  )
130
139
 
131
- if handler.is_a?(ChatStart)
140
+ if handler.is_a?(Ollama::Handlers::ChatStart)
132
141
  filename = File.join(Dir.tmpdir, 'chat_start_%u.json' % $$)
133
142
  File.secure_write(filename) do |out|
134
143
  JSON.dump(
@@ -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
@@ -5,17 +5,23 @@ class Ollama::Handlers::Markdown
5
5
  include Ollama::Handlers::Concern
6
6
  include Term::ANSIColor
7
7
 
8
- def initialize(output: $stdout)
9
- super
10
- @output.sync = true
8
+ def initialize(output: $stdout, stream: true)
9
+ super(output:)
10
+ @stream = stream
11
+ @output.sync = @stream
11
12
  @content = ''
12
13
  end
13
14
 
14
15
  def call(response)
15
16
  if content = response.response || response.message&.content
16
- @content << content
17
- markdown_content = Kramdown::ANSI.parse(@content)
18
- @output.print clear_screen, move_home, markdown_content
17
+ if @stream
18
+ @content << content
19
+ markdown_content = Kramdown::ANSI.parse(@content)
20
+ @output.print clear_screen, move_home, markdown_content
21
+ else
22
+ markdown_content = Kramdown::ANSI.parse(content)
23
+ @output.print markdown_content
24
+ end
19
25
  end
20
26
  self
21
27
  end
@@ -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.2.1'
3
+ VERSION = '1.4.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.2.1 ruby lib
2
+ # stub: ollama-ruby 1.4.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "1.2.1".freeze
6
+ s.version = "1.4.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]
@@ -12,13 +12,13 @@ Gem::Specification.new do |s|
12
12
  s.description = "Library that allows interacting with the Ollama API".freeze
13
13
  s.email = "flori@ping.de".freeze
14
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]
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]
20
20
  s.required_ruby_version = Gem::Requirement.new("~> 3.1".freeze)
21
- s.rubygems_version = "3.6.7".freeze
21
+ s.rubygems_version = "3.6.9".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
 
@@ -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
@@ -41,4 +41,14 @@ RSpec.describe Ollama::Handlers::Markdown do
41
41
  response = double('response', response: nil, message: nil, done: true)
42
42
  markdown.call(response)
43
43
  end
44
+
45
+ it 'displays markdown response in one go when stream is false' do
46
+ output = double('output', :sync= => false)
47
+ expect(output).to receive(:print).with(ansi).once
48
+ markdown = described_class.new(output:, stream: false)
49
+ response = double('response', response: md, done: true)
50
+ markdown.call(response)
51
+ response = double('response', response: nil, message: nil, done: true)
52
+ markdown.call(response)
53
+ end
44
54
  end
@@ -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.2.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -223,6 +223,7 @@ extra_rdoc_files:
223
223
  - lib/ollama.rb
224
224
  - lib/ollama/client.rb
225
225
  - lib/ollama/client/command.rb
226
+ - lib/ollama/client/configuration/config.rb
226
227
  - lib/ollama/client/doc.rb
227
228
  - lib/ollama/commands/chat.rb
228
229
  - lib/ollama/commands/copy.rb
@@ -251,6 +252,7 @@ extra_rdoc_files:
251
252
  - lib/ollama/handlers/say.rb
252
253
  - lib/ollama/handlers/single.rb
253
254
  - lib/ollama/image.rb
255
+ - lib/ollama/json_loader.rb
254
256
  - lib/ollama/message.rb
255
257
  - lib/ollama/options.rb
256
258
  - lib/ollama/response.rb
@@ -266,12 +268,14 @@ files:
266
268
  - LICENSE
267
269
  - README.md
268
270
  - Rakefile
271
+ - bin/ollama_browse
269
272
  - bin/ollama_cli
270
273
  - bin/ollama_console
271
274
  - bin/ollama_update
272
275
  - lib/ollama.rb
273
276
  - lib/ollama/client.rb
274
277
  - lib/ollama/client/command.rb
278
+ - lib/ollama/client/configuration/config.rb
275
279
  - lib/ollama/client/doc.rb
276
280
  - lib/ollama/commands/chat.rb
277
281
  - lib/ollama/commands/copy.rb
@@ -300,6 +304,7 @@ files:
300
304
  - lib/ollama/handlers/say.rb
301
305
  - lib/ollama/handlers/single.rb
302
306
  - lib/ollama/image.rb
307
+ - lib/ollama/json_loader.rb
303
308
  - lib/ollama/message.rb
304
309
  - lib/ollama/options.rb
305
310
  - lib/ollama/response.rb
@@ -309,7 +314,9 @@ files:
309
314
  - lib/ollama/tool/function/parameters/property.rb
310
315
  - lib/ollama/version.rb
311
316
  - ollama-ruby.gemspec
317
+ - spec/assets/client.json
312
318
  - spec/assets/kitten.jpg
319
+ - spec/assets/options.json
313
320
  - spec/ollama/client/doc_spec.rb
314
321
  - spec/ollama/client_spec.rb
315
322
  - spec/ollama/commands/chat_spec.rb
@@ -362,7 +369,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
362
369
  - !ruby/object:Gem::Version
363
370
  version: '0'
364
371
  requirements: []
365
- rubygems_version: 3.6.7
372
+ rubygems_version: 3.6.9
366
373
  specification_version: 4
367
374
  summary: Interacting with the Ollama API
368
375
  test_files: