ollama-ruby 1.4.0 → 1.6.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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.contexts/code_comment.rb +25 -0
  3. data/.contexts/full.rb +43 -0
  4. data/.contexts/info.rb +17 -0
  5. data/.contexts/lib.rb +27 -0
  6. data/.contexts/yard.md +93 -0
  7. data/CHANGES.md +39 -0
  8. data/README.md +74 -23
  9. data/Rakefile +4 -3
  10. data/bin/ollama_cli +41 -9
  11. data/bin/ollama_console +18 -0
  12. data/lib/ollama/client/command.rb +29 -3
  13. data/lib/ollama/client/configuration/config.rb +114 -3
  14. data/lib/ollama/client/doc.rb +18 -0
  15. data/lib/ollama/client.rb +131 -2
  16. data/lib/ollama/commands/chat.rb +96 -1
  17. data/lib/ollama/commands/copy.rb +59 -1
  18. data/lib/ollama/commands/create.rb +112 -1
  19. data/lib/ollama/commands/delete.rb +53 -1
  20. data/lib/ollama/commands/embed.rb +82 -1
  21. data/lib/ollama/commands/embeddings.rb +72 -1
  22. data/lib/ollama/commands/generate.rb +118 -2
  23. data/lib/ollama/commands/ps.rb +55 -0
  24. data/lib/ollama/commands/pull.rb +72 -1
  25. data/lib/ollama/commands/push.rb +65 -1
  26. data/lib/ollama/commands/show.rb +64 -1
  27. data/lib/ollama/commands/tags.rb +50 -0
  28. data/lib/ollama/commands/version.rb +50 -1
  29. data/lib/ollama/dto.rb +98 -1
  30. data/lib/ollama/errors.rb +50 -0
  31. data/lib/ollama/handlers/collector.rb +34 -0
  32. data/lib/ollama/handlers/concern.rb +60 -2
  33. data/lib/ollama/handlers/dump_json.rb +20 -0
  34. data/lib/ollama/handlers/dump_yaml.rb +22 -0
  35. data/lib/ollama/handlers/markdown.rb +28 -0
  36. data/lib/ollama/handlers/nop.rb +20 -0
  37. data/lib/ollama/handlers/print.rb +27 -0
  38. data/lib/ollama/handlers/progress.rb +38 -0
  39. data/lib/ollama/handlers/say.rb +66 -0
  40. data/lib/ollama/handlers/single.rb +35 -0
  41. data/lib/ollama/handlers.rb +9 -0
  42. data/lib/ollama/image.rb +67 -0
  43. data/lib/ollama/json_loader.rb +17 -0
  44. data/lib/ollama/message.rb +46 -1
  45. data/lib/ollama/options.rb +27 -2
  46. data/lib/ollama/response.rb +17 -0
  47. data/lib/ollama/tool/function/parameters/property.rb +41 -1
  48. data/lib/ollama/tool/function/parameters.rb +40 -1
  49. data/lib/ollama/tool/function.rb +44 -1
  50. data/lib/ollama/tool.rb +37 -1
  51. data/lib/ollama/version.rb +1 -1
  52. data/lib/ollama.rb +26 -0
  53. data/ollama-ruby.gemspec +7 -6
  54. data/spec/ollama/client/doc_spec.rb +1 -1
  55. data/spec/ollama/client_spec.rb +19 -1
  56. data/spec/ollama/commands/chat_spec.rb +1 -1
  57. data/spec/ollama/commands/copy_spec.rb +1 -1
  58. data/spec/ollama/commands/create_spec.rb +1 -1
  59. data/spec/ollama/commands/delete_spec.rb +1 -1
  60. data/spec/ollama/commands/embed_spec.rb +1 -1
  61. data/spec/ollama/commands/embeddings_spec.rb +1 -1
  62. data/spec/ollama/commands/generate_spec.rb +1 -1
  63. data/spec/ollama/commands/ps_spec.rb +1 -1
  64. data/spec/ollama/commands/pull_spec.rb +1 -1
  65. data/spec/ollama/commands/push_spec.rb +1 -1
  66. data/spec/ollama/commands/show_spec.rb +1 -1
  67. data/spec/ollama/commands/tags_spec.rb +1 -1
  68. data/spec/ollama/commands/version_spec.rb +1 -1
  69. data/spec/ollama/handlers/collector_spec.rb +1 -1
  70. data/spec/ollama/handlers/dump_json_spec.rb +1 -1
  71. data/spec/ollama/handlers/dump_yaml_spec.rb +1 -1
  72. data/spec/ollama/handlers/markdown_spec.rb +1 -1
  73. data/spec/ollama/handlers/nop_spec.rb +2 -2
  74. data/spec/ollama/handlers/print_spec.rb +1 -1
  75. data/spec/ollama/handlers/progress_spec.rb +1 -1
  76. data/spec/ollama/handlers/say_spec.rb +1 -1
  77. data/spec/ollama/handlers/single_spec.rb +1 -1
  78. data/spec/ollama/image_spec.rb +1 -1
  79. data/spec/ollama/message_spec.rb +1 -1
  80. data/spec/ollama/options_spec.rb +1 -1
  81. data/spec/ollama/tool_spec.rb +1 -1
  82. data/spec/spec_helper.rb +2 -6
  83. metadata +25 -5
@@ -1,7 +1,21 @@
1
1
  require 'ollama/json_loader'
2
2
 
3
- # Options are explained in the parameters for the modelfile:
4
- # https://github.com/ollama/ollama/blob/main/docs/modelfile.md#parameter
3
+ # A class that encapsulates configuration options for Ollama models.
4
+ #
5
+ # This class provides a structured way to define and manage various parameters
6
+ # that can be passed to Ollama models during generation or chat operations. It
7
+ # includes type validation to ensure that option values conform to expected
8
+ # data types, making it easier to work with model configurations
9
+ # programmatically.
10
+ #
11
+ # @example Creating an Options object with specific settings
12
+ # options = Ollama::Options.new(
13
+ # temperature: 0.7,
14
+ # num_ctx: 8192,
15
+ # top_p: 0.9
16
+ # )
17
+ #
18
+ # [Options are explained in the parameters for the modelfile.](https://github.com/ollama/ollama/blob/main/docs/modelfile.md#parameter)
5
19
  class Ollama::Options
6
20
  include Ollama::DTO
7
21
  extend Ollama::JSONLoader
@@ -69,6 +83,17 @@ class Ollama::Options
69
83
  end
70
84
  }
71
85
 
86
+ # The [] method creates a new instance of the class using a hash of attributes.
87
+ #
88
+ # This class method provides a convenient way to instantiate an object by
89
+ # passing a hash containing the desired attribute values. It converts the
90
+ # hash keys to symbols and forwards them as keyword arguments to the
91
+ # constructor.
92
+ #
93
+ # @param value [ Hash ] a hash containing the attribute names and their values
94
+ #
95
+ # @return [ self ] a new instance of the class initialized with the provided
96
+ # attributes
72
97
  def self.[](value)
73
98
  new(**value.to_h)
74
99
  end
@@ -1,4 +1,21 @@
1
+ # A subclass of JSON::GenericObject that represents responses from the Ollama API.
2
+ #
3
+ # This class serves as a specialized response object that extends
4
+ # JSON::GenericObject to provide structured access to API response data. It
5
+ # maintains the ability to convert to JSON format while preserving the response
6
+ # data in a hash-like structure.
7
+ #
8
+ # @example Accessing response data
9
+ # response = Ollama::Response.new(key: 'value')
10
+ # response[:key] # => 'value'
1
11
  class Ollama::Response < JSON::GenericObject
12
+ # The as_json method converts the object's attributes into a JSON-compatible hash.
13
+ #
14
+ # This method gathers all defined attributes of the object and constructs a
15
+ # hash representation, excluding any nil values or empty collections.
16
+ #
17
+ # @note This removes "json_class" attribute from hash for responses.
18
+ # @return [ Hash ] a hash containing the object's non-nil and non-empty attributes
2
19
  def as_json(*)
3
20
  to_hash
4
21
  end
@@ -1,8 +1,48 @@
1
+ # A class that represents a single property within the parameters specification
2
+ # for a tool function.
3
+ #
4
+ # This class encapsulates the definition of an individual parameter, including
5
+ # its data type, descriptive text, and optional enumeration values that define
6
+ # valid inputs.
7
+ #
8
+ # @example Creating a property with type and description
9
+ # property = Ollama::Tool::Function::Parameters::Property.new(
10
+ # type: 'string',
11
+ # description: 'The location to get weather for'
12
+ # )
13
+ #
14
+ # @example Creating a property with an enumeration of valid values
15
+ # property = Ollama::Tool::Function::Parameters::Property.new(
16
+ # type: 'string',
17
+ # description: 'Temperature unit',
18
+ # enum: %w[celsius fahrenheit]
19
+ # )
1
20
  class Ollama::Tool::Function::Parameters::Property
2
21
  include Ollama::DTO
3
22
 
4
- attr_reader :type, :description, :enum
23
+ # The type attribute reader returns the type associated with the object.
24
+ #
25
+ # @return [ String ] the type value stored in the instance variable
26
+ attr_reader :type
5
27
 
28
+ # The description attribute reader returns the description associated with
29
+ # the object.
30
+ #
31
+ # @return [ String ] the description value stored in the instance variable
32
+ attr_reader :description
33
+
34
+ # The enum attribute reader returns the enumeration values associated with the object.
35
+ #
36
+ # @return [ Array<String>, nil ] an array of valid string values that the
37
+ # property can take, or nil if not set
38
+ attr_reader :enum
39
+
40
+ # The initialize method sets up a new Property instance with the specified
41
+ # attributes.
42
+ #
43
+ # @param type [ String ] the data type of the property
44
+ # @param description [ String ] a detailed explanation of what the property represents
45
+ # @param enum [ Array<String>, nil ] an optional array of valid values that the property can take
6
46
  def initialize(type:, description:, enum: nil)
7
47
  @type, @description, @enum = type, description, Array(enum)
8
48
  end
@@ -1,8 +1,47 @@
1
+ # A class that represents the parameters specification for a tool function in
2
+ # Ollama API interactions.
3
+ #
4
+ # This class encapsulates the structure required for defining the parameters
5
+ # that a function tool accepts. It includes the type of parameter object, the
6
+ # properties of each parameter, and which parameters are required.
7
+ #
8
+ # @example Creating a parameters specification for a tool function
9
+ # property = Ollama::Tool::Function::Parameters::Property.new(
10
+ # type: 'string',
11
+ # description: 'The location to get weather for'
12
+ # )
13
+ # parameters = Ollama::Tool::Function::Parameters.new(
14
+ # type: 'object',
15
+ # properties: { location: property },
16
+ # required: %w[location]
17
+ # )
1
18
  class Ollama::Tool::Function::Parameters
2
19
  include Ollama::DTO
3
20
 
4
- attr_reader :type, :properties, :required
21
+ # The type attribute reader returns the type associated with the object.
22
+ #
23
+ # @return [ String ] the type value stored in the instance variable
24
+ attr_reader :type
5
25
 
26
+ # The properties attribute reader returns the properties associated with the
27
+ # object.
28
+ #
29
+ # @return [ Hash ] the properties hash, or nil if not set
30
+ attr_reader :properties
31
+
32
+ # The required attribute reader returns the required parameter values
33
+ # associated with the object.
34
+ #
35
+ # @return [ Array<String>, nil ] an array of required parameter names, or nil
36
+ # if not set
37
+ attr_reader :required
38
+
39
+ # The initialize method sets up a new Parameters instance with the specified
40
+ # attributes.
41
+ #
42
+ # @param type [ String ] the type of parameter object
43
+ # @param properties [ Hash ] the properties of each parameter
44
+ # @param required [ Array<String> ] the names of required parameters
6
45
  def initialize(type:, properties:, required:)
7
46
  @type, @properties, @required =
8
47
  type, Hash(properties).transform_values(&:to_hash), Array(required)
@@ -1,8 +1,51 @@
1
+ # A class that represents a function definition for tool usage in Ollama API
2
+ # interactions.
3
+ #
4
+ # This class encapsulates the structure required for defining functions that
5
+ # can be passed to models to enable function calling capabilities. It includes
6
+ # the function's name, description, parameters specification, and list of
7
+ # required parameters.
8
+ #
9
+ # @example Creating a function definition for a tool
10
+ # function = Ollama::Tool::Function.new(
11
+ # name: 'get_current_weather',
12
+ # description: 'Get the current weather for a location',
13
+ # parameters: parameters,
14
+ # required: %w[location]
15
+ # )
1
16
  class Ollama::Tool::Function
2
17
  include Ollama::DTO
3
18
 
4
- attr_reader :name, :description, :parameters, :required
19
+ # The name attribute reader returns the name associated with the object.
20
+ #
21
+ # @return [ String ] the name value stored in the instance variable
22
+ attr_reader :name
5
23
 
24
+ # The description attribute reader returns the description associated with
25
+ # the object.
26
+ #
27
+ # @return [ String ] the description value stored in the instance variable
28
+ attr_reader :description
29
+
30
+ # The parameters attribute reader returns the parameters associated with the
31
+ # object.
32
+ #
33
+ # @return [ Hash, nil ] the parameters hash, or nil if not set
34
+ attr_reader :parameters
35
+
36
+ # The required attribute reader returns the required parameter values
37
+ # associated with the object.
38
+ #
39
+ # @return [ Array<String>, nil ] an array of required parameter names, or nil if not set
40
+ attr_reader :required
41
+
42
+ # The initialize method sets up a new Tool::Function instance with the
43
+ # specified attributes.
44
+ #
45
+ # @param name [ String ] the name of the function
46
+ # @param description [ String ] a brief description of what the function does
47
+ # @param parameters [ Hash, nil ] optional parameters specification for the function
48
+ # @param required [ Array<String>, nil ] optional array of required parameter names
6
49
  def initialize(name:, description:, parameters: nil, required: nil)
7
50
  @name, @description, @parameters, @required =
8
51
  name, description, (Hash(parameters) if parameters),
data/lib/ollama/tool.rb CHANGED
@@ -1,8 +1,44 @@
1
+ # Represents a tool definition used in interactions with the Ollama API.
2
+ # This class encapsulates the structure required for defining tools that can be
3
+ # passed to models to enable function calling capabilities. It includes the type
4
+ # of tool and the associated function definition, which specifies the tool's name,
5
+ # description, parameters, and required fields.
6
+ #
7
+ # @example Creating a tool with a function definition
8
+ # tool = Ollama::Tool.new(
9
+ # type: 'function',
10
+ # function: Ollama::Tool::Function.new(
11
+ # name: 'get_current_weather',
12
+ # description: 'Get the current weather for a location',
13
+ # parameters: Ollama::Tool::Function::Parameters.new(
14
+ # type: 'object',
15
+ # properties: { location: property },
16
+ # required: %w[location]
17
+ # )
18
+ # )
19
+ # )
1
20
  class Ollama::Tool
2
21
  include Ollama::DTO
3
22
 
4
- attr_reader :type, :function
23
+ # The type attribute reader returns the type associated with the tool.
24
+ #
25
+ # @return [ String ] the type of tool, typically 'function' for function
26
+ # calling capabilities
27
+ attr_reader :type
5
28
 
29
+ # The function attribute reader returns the function definition associated
30
+ # with the tool.
31
+ #
32
+ # @return [ Hash ] the function definition as a hash, containing details such
33
+ # as the function's name, description, parameters, and required fields
34
+ attr_reader :function
35
+
36
+ # The initialize method sets up a new Tool instance with the specified type
37
+ # and function.
38
+ #
39
+ # @param type [ String ] the type of tool being created
40
+ # @param function [ Ollama::Tool::Function ] the function definition
41
+ # associated with the tool
6
42
  def initialize(type:, function:)
7
43
  @type, @function = type, function.to_hash
8
44
  end
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '1.4.0'
3
+ VERSION = '1.6.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/lib/ollama.rb CHANGED
@@ -5,6 +5,19 @@ require 'tins/xt/full'
5
5
  require 'tins/xt/hash_union'
6
6
  require 'tins/xt/string_camelize'
7
7
 
8
+ # The main module for the Ollama Ruby client library.
9
+ #
10
+ # This module serves as the root namespace for all components of the Ollama
11
+ # client library, providing access to core classes and functionality for
12
+ # interacting with the Ollama API. It includes handlers, commands, data
13
+ # transfer objects, and utility classes that enable communication with
14
+ # Ollama servers.
15
+ #
16
+ # @example Accessing core components
17
+ # Ollama::Client
18
+ # Ollama::Handlers
19
+ # Ollama::Commands
20
+ # Ollama::DTO
8
21
  module Ollama
9
22
  end
10
23
 
@@ -25,6 +38,19 @@ require 'ollama/tool/function/parameters/property'
25
38
  require 'ollama/response'
26
39
  require 'ollama/options'
27
40
 
41
+ # A module that groups together various command classes used to interact with
42
+ # the Ollama API.
43
+ #
44
+ # This module serves as a namespace for all command implementations that
45
+ # correspond to specific Ollama API endpoints. It provides the structure and
46
+ # functionality needed to define and execute different types of operations such
47
+ # as chat conversations, model generation, model management, and other
48
+ # interactions with the Ollama server.
49
+ #
50
+ # @example Accessing command classes
51
+ # Ollama::Commands::Chat
52
+ # Ollama::Commands::Generate
53
+ # Ollama::Commands::Create
28
54
  class Ollama::Commands
29
55
  end
30
56
  require 'ollama/commands/generate'
data/ollama-ruby.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama-ruby 1.4.0 ruby lib
2
+ # stub: ollama-ruby 1.6.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "1.4.0".freeze
6
+ s.version = "1.6.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]
14
+ s.executables = ["ollama_console".freeze, "ollama_update".freeze, "ollama_cli".freeze, "ollama_browse".freeze]
15
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]
16
+ s.files = [".contexts/code_comment.rb".freeze, ".contexts/full.rb".freeze, ".contexts/info.rb".freeze, ".contexts/lib.rb".freeze, ".contexts/yard.md".freeze, ".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]
@@ -24,17 +24,18 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.specification_version = 4
26
26
 
27
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.20".freeze])
27
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.0".freeze])
28
28
  s.add_development_dependency(%q<all_images>.freeze, ["~> 0.6".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])
32
32
  s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
33
33
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
34
+ s.add_development_dependency(%q<context_spook>.freeze, [">= 0".freeze])
34
35
  s.add_runtime_dependency(%q<excon>.freeze, ["~> 1.0".freeze])
35
36
  s.add_runtime_dependency(%q<infobar>.freeze, ["~> 0.8".freeze])
36
37
  s.add_runtime_dependency(%q<json>.freeze, ["~> 2.0".freeze])
37
- s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.34".freeze])
38
+ s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.41".freeze])
38
39
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
39
40
  s.add_runtime_dependency(%q<kramdown-ansi>.freeze, ["~> 0.0".freeze, ">= 0.0.1".freeze])
40
41
  s.add_runtime_dependency(%q<ostruct>.freeze, ["~> 0.0".freeze])
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Client::Doc do
3
+ describe Ollama::Client::Doc do
4
4
  it 'can document commands' do
5
5
  expect(Ollama::Client::Doc.new(:generate).to_s).to match(/generate-a-completion/)
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Client do
3
+ describe Ollama::Client do
4
4
  let :base_url do
5
5
  'https://ai.foo.bar'
6
6
  end
@@ -35,9 +35,13 @@ RSpec.describe Ollama::Client do
35
35
  end
36
36
 
37
37
  it 'can be configured via environment variable' do
38
+ old_base_url = ENV['OLLAMA_URL']
39
+ ENV.delete('OLLAMA_URL')
38
40
  expect { described_class.new }.to raise_error(ArgumentError)
39
41
  ENV['OLLAMA_URL'] = base_url
40
42
  expect(described_class.new).to be_a described_class
43
+ ensure
44
+ ENV['OLLAMA_URL'] = old_base_url
41
45
  end
42
46
 
43
47
  it 'can disable ssl peer verification' do
@@ -145,6 +149,20 @@ RSpec.describe Ollama::Client do
145
149
  ollama.generate(model: 'llama3.1', prompt: 'Hello World')
146
150
  end
147
151
 
152
+ it 'can soldier on with parse errors and output warning' do
153
+ expect(excon).to receive(:send).with(
154
+ :post,
155
+ body: '{"model":"llama3.1","prompt":"Hello World"}',
156
+ headers: hash_including(
157
+ 'Content-Type' => 'application/json; charset=utf-8',
158
+ )
159
+ ).and_return(double(status: 200, body: '{i am so broken}'))
160
+ expect(ollama).to receive(:warn).with(
161
+ "Caught JSON::ParserError: expected object key, got 'i' at line 1 column 2"
162
+ )
163
+ expect(ollama.generate(model: 'llama3.1', prompt: 'Hello World')).to be nil
164
+ end
165
+
148
166
  it 'can generate with stream' do
149
167
  expect(excon).to receive(:send).with(
150
168
  :post,
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Chat do
3
+ describe Ollama::Commands::Chat do
4
4
  it 'can be instantiated' do
5
5
  messages = [
6
6
  Ollama::Message.new(role: 'user', content: "Let's play Global Thermonuclear War.")
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Copy do
3
+ describe Ollama::Commands::Copy do
4
4
  it 'can be instantiated' do
5
5
  copy = described_class.new(source: 'llama3.1', destination: 'camell3')
6
6
  expect(copy).to be_a described_class
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Create do
3
+ describe Ollama::Commands::Create do
4
4
  it 'can be instantiated' do
5
5
  create = described_class.new(model: 'llama3.1', stream: true)
6
6
  expect(create).to be_a described_class
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Delete do
3
+ describe Ollama::Commands::Delete do
4
4
  it 'can be instantiated' do
5
5
  delete = described_class.new(model: 'llama3.1')
6
6
  expect(delete).to be_a described_class
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Embed do
3
+ describe Ollama::Commands::Embed do
4
4
  it 'can be instantiated' do
5
5
  embed = described_class.new(
6
6
  model: 'all-minilm',
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Embeddings do
3
+ describe Ollama::Commands::Embeddings do
4
4
  it 'can be instantiated' do
5
5
  embeddings = described_class.new(
6
6
  model: 'mxbai-embed-large',
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Generate do
3
+ describe Ollama::Commands::Generate do
4
4
  it 'can be instantiated' do
5
5
  generate = described_class.new(model: 'llama3.1', prompt: 'Hello World')
6
6
  expect(generate).to be_a described_class
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Ps do
3
+ describe Ollama::Commands::Ps do
4
4
  let :ps do
5
5
  described_class.new
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Pull do
3
+ describe Ollama::Commands::Pull do
4
4
  it 'can be instantiated' do
5
5
  pull = described_class.new(model: 'llama3.1')
6
6
  expect(pull).to be_a described_class
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Push do
3
+ describe Ollama::Commands::Push do
4
4
  it 'can be instantiated' do
5
5
  push = described_class.new(model: 'llama3.1')
6
6
  expect(push).to be_a described_class
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Show do
3
+ describe Ollama::Commands::Show do
4
4
  it 'can be instantiated' do
5
5
  show = described_class.new(model: 'llama3.1')
6
6
  expect(show).to be_a described_class
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Tags do
3
+ describe Ollama::Commands::Tags do
4
4
  let :tags do
5
5
  described_class.new
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Commands::Version do
3
+ describe Ollama::Commands::Version do
4
4
  let :version do
5
5
  described_class.new
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::Collector do
3
+ describe Ollama::Handlers::Collector do
4
4
  it 'has .call' do
5
5
  expect_any_instance_of(described_class).to receive(:call).with(:foo)
6
6
  described_class.call(:foo)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::DumpJSON do
3
+ describe Ollama::Handlers::DumpJSON do
4
4
  it 'has .call' do
5
5
  expect_any_instance_of(described_class).to receive(:call).with(:foo)
6
6
  described_class.call(:foo)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::DumpYAML do
3
+ describe Ollama::Handlers::DumpYAML do
4
4
  it 'has .call' do
5
5
  expect_any_instance_of(described_class).to receive(:call).with(:foo)
6
6
  described_class.call(:foo)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::Markdown do
3
+ describe Ollama::Handlers::Markdown do
4
4
  it 'has .call' do
5
5
  expect_any_instance_of(described_class).to receive(:call).with(:foo)
6
6
  described_class.call(:foo)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::NOP do
3
+ describe Ollama::Handlers::NOP do
4
4
  it 'has .to_proc' do
5
5
  expect_any_instance_of(described_class).to receive(:call).with(:foo)
6
6
  described_class.call(:foo)
@@ -10,6 +10,6 @@ RSpec.describe Ollama::Handlers::NOP do
10
10
  nop = described_class.new(output:)
11
11
  response = Ollama::Response[foo: 'testing']
12
12
  nop.call(response)
13
- expect(nop.result).to be_nil
13
+ expect(nop.result).to be nil
14
14
  end
15
15
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::Print do
3
+ describe Ollama::Handlers::Print do
4
4
  it 'has .to_proc' do
5
5
  expect_any_instance_of(described_class).to receive(:call).with(:foo)
6
6
  described_class.call(:foo)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::Progress do
3
+ describe Ollama::Handlers::Progress do
4
4
  it 'has .to_proc' do
5
5
  expect_any_instance_of(described_class).to receive(:call).with(:foo)
6
6
  described_class.call(:foo)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::Say do
3
+ describe Ollama::Handlers::Say do
4
4
  let :say do
5
5
  described_class.new
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Handlers::Single do
3
+ describe Ollama::Handlers::Single do
4
4
  it 'has .call' do
5
5
  expect_any_instance_of(described_class).to receive(:call).with(:foo)
6
6
  described_class.call(:foo)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Ollama::Image do
3
+ describe Ollama::Image do
4
4
  let :image do
5
5
  described_class.for_filename(asset('kitten.jpg'))
6
6
  end