Class: RSpec::Llama::OpenaiModelConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/llama/model_configurations/openai_model_configuration.rb

Constant Summary collapse

DEFAULT_MODEL =
'gpt-3.5-turbo'
DEFAULT_TEMPERATURE =
0.5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model: DEFAULT_MODEL, temperature: DEFAULT_TEMPERATURE, **additional_options) ⇒ OpenaiModelConfiguration

Initializes a new configuration for the OpenAI model.

Examples:

Basic usage with default model and temperature

config = RSpec::Llama::OpenaiModelConfiguration.new

Passing custom options

config = RSpec::Llama::OpenaiModelConfiguration.new(
  model: 'gpt-4',
  temperature: 0.8,
  max_tokens: 150,
  stop: ['\n']
)

Parameters:

  • model (String) (defaults to: DEFAULT_MODEL)

    The model to use. Defaults to ‘gpt-3.5-turbo’.

  • temperature (Float) (defaults to: DEFAULT_TEMPERATURE)

    The sampling temperature for the model, between 0 and 2.0. Higher values make output more random, while lower values make it more focused. Defaults to 0.5.

  • additional_options (Hash)

    Additional configuration options to pass to the API, such as max_tokens, top_p, stop, and others. This allows flexibility for adding any supported parameters without modifying the class. The keys should be symbols.

See Also:



32
33
34
35
36
# File 'lib/rspec/llama/model_configurations/openai_model_configuration.rb', line 32

def initialize(model: DEFAULT_MODEL, temperature: DEFAULT_TEMPERATURE, **additional_options)
  @model = model
  @temperature = temperature
  @additional_options = additional_options
end

Instance Attribute Details

#additional_optionsObject (readonly)

Returns the value of attribute additional_options.



9
10
11
# File 'lib/rspec/llama/model_configurations/openai_model_configuration.rb', line 9

def additional_options
  @additional_options
end

#modelObject (readonly)

Returns the value of attribute model.



9
10
11
# File 'lib/rspec/llama/model_configurations/openai_model_configuration.rb', line 9

def model
  @model
end

#temperatureObject (readonly)

Returns the value of attribute temperature.



9
10
11
# File 'lib/rspec/llama/model_configurations/openai_model_configuration.rb', line 9

def temperature
  @temperature
end

Instance Method Details

#to_hHash

Converts the configuration into a hash format for making API requests.

Returns:

  • (Hash)

    A hash representation of the model configuration. This hash includes the model, temperature, and any additional options provided during initialization. Nil values are omitted from the hash.



43
44
45
# File 'lib/rspec/llama/model_configurations/openai_model_configuration.rb', line 43

def to_h
  { model:, temperature:, **additional_options }.compact
end