Class: Ollama::Client::Configuration::Config

Inherits:
Object
  • Object
show all
Extended by:
JSONLoader
Includes:
DTO
Defined in:
lib/ollama/client/configuration/config.rb

Overview

A class that encapsulates configuration settings for Ollama clients.

This class provides a structured way to define and manage various configuration options that can be used when initializing Ollama client instances. It includes properties for setting the base URL, output stream, and timeout values.

Examples:

Creating a configuration object

config = Ollama::Client::Config[
  base_url: 'http://localhost:11434',
  output: $stdout,
  connect_timeout: 15,
  read_timeout: 300
]

Loading configuration from a JSON file

config = Ollama::Client::Config.load_from_json('path/to/config.json')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JSONLoader

load_from_json

Methods included from DTO

#==, #as_array, #as_array_of_hashes, #as_hash, #as_json, #empty?, #to_json

Constructor Details

#initialize(**attributes) ⇒ Ollama::Client::Configuration::Config

The initialize method sets up a new configuration instance with the specified attributes.

This method is responsible for initializing a new Ollama::Client::Configuration::Config instance by processing various configuration options. It iterates through the provided attributes and assigns them to corresponding setter methods, then ensures that the output stream is set to $stdout if no output was specified.

Parameters:

  • attributes (Hash)

    a hash containing the configuration attributes to be set



53
54
55
56
# File 'lib/ollama/client/configuration/config.rb', line 53

def initialize(**attributes)
  attributes.each { |k, v| send("#{k}=", v) }
  self.output ||= $stdout
end

Instance Attribute Details

#base_urlObject

The base_url attribute accessor allows reading and setting the base URL of the Ollama API endpoint.



78
79
80
# File 'lib/ollama/client/configuration/config.rb', line 78

def base_url
  @base_url
end

#connect_timeoutObject

The connect_timeout attribute accessor allows reading and setting the connection timeout value.



90
91
92
# File 'lib/ollama/client/configuration/config.rb', line 90

def connect_timeout
  @connect_timeout
end

#debugObject

The debug attribute accessor allows reading and setting the debug flag.



107
108
109
# File 'lib/ollama/client/configuration/config.rb', line 107

def debug
  @debug
end

#outputObject

The output attribute accessor allows reading and setting the output stream used for handling responses and messages.



84
85
86
# File 'lib/ollama/client/configuration/config.rb', line 84

def output
  @output
end

#read_timeoutObject

The read_timeout attribute accessor allows reading and setting the read timeout value.



96
97
98
# File 'lib/ollama/client/configuration/config.rb', line 96

def read_timeout
  @read_timeout
end

#user_agentObject

The user_agent attribute accessor allows reading and setting the user agent string used for making requests to the Ollama API.



113
114
115
# File 'lib/ollama/client/configuration/config.rb', line 113

def user_agent
  @user_agent
end

#write_timeoutObject

The write_timeout attribute accessor allows reading and setting the write timeout value.



102
103
104
# File 'lib/ollama/client/configuration/config.rb', line 102

def write_timeout
  @write_timeout
end

Class Method Details

.[](value) ⇒ self

The [] method creates a new instance of the class using a hash of attributes.

This class method provides a convenient way to instantiate an object by passing a hash containing the desired attribute values. It converts the hash keys to symbols and forwards them as keyword arguments to the constructor.

attributes

Parameters:

  • value (Hash)

    a hash containing the attribute names and their values

Returns:

  • (self)

    a new instance of the class initialized with the provided



70
71
72
# File 'lib/ollama/client/configuration/config.rb', line 70

def self.[](value)
  new(**value.to_h)
end