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

Inherits:
Object
  • Object
show all
Extended by:
JSONLoader
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

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



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

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.



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

def base_url
  @base_url
end

#connect_timeoutObject

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



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

def connect_timeout
  @connect_timeout
end

#debugObject

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



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

def debug
  @debug
end

#outputObject

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



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

def output
  @output
end

#read_timeoutObject

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



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

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.



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

def user_agent
  @user_agent
end

#write_timeoutObject

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



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

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



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

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