Class: Agentic::LlmConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/agentic/llm_config.rb

Overview

Configuration object for LLM API calls

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model: "gpt-4o-2024-08-06", max_tokens: nil, temperature: 0.7, top_p: 1.0, frequency_penalty: 0.0, presence_penalty: 0.0, additional_options: {}) ⇒ LlmConfig

Initializes a new LLM configuration

Parameters:

  • model (String) (defaults to: "gpt-4o-2024-08-06")

    The model to use

  • max_tokens (Integer, nil) (defaults to: nil)

    The maximum number of tokens to generate

  • temperature (Float) (defaults to: 0.7)

    The temperature parameter (0.0-2.0)

  • top_p (Float) (defaults to: 1.0)

    The top_p parameter (0.0-1.0)

  • frequency_penalty (Float) (defaults to: 0.0)

    The frequency penalty (-2.0-2.0)

  • presence_penalty (Float) (defaults to: 0.0)

    The presence penalty (-2.0-2.0)

  • additional_options (Hash) (defaults to: {})

    Additional options to pass to the API



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/agentic/llm_config.rb', line 35

def initialize(
  model: "gpt-4o-2024-08-06",
  max_tokens: nil,
  temperature: 0.7,
  top_p: 1.0,
  frequency_penalty: 0.0,
  presence_penalty: 0.0,
  additional_options: {}
)
  @model = model
  @max_tokens = max_tokens
  @temperature = temperature
  @top_p = top_p
  @frequency_penalty = frequency_penalty
  @presence_penalty = presence_penalty
  @additional_options = additional_options
end

Instance Attribute Details

#additional_optionsHash

Returns Additional options to pass to the API.

Returns:

  • (Hash)

    Additional options to pass to the API



25
26
27
# File 'lib/agentic/llm_config.rb', line 25

def additional_options
  @additional_options
end

#frequency_penaltyInteger

Returns The frequency penalty.

Returns:

  • (Integer)

    The frequency penalty



19
20
21
# File 'lib/agentic/llm_config.rb', line 19

def frequency_penalty
  @frequency_penalty
end

#max_tokensInteger

Returns The maximum number of tokens to generate.

Returns:

  • (Integer)

    The maximum number of tokens to generate



10
11
12
# File 'lib/agentic/llm_config.rb', line 10

def max_tokens
  @max_tokens
end

#modelString

Returns The model to use for LLM requests.

Returns:

  • (String)

    The model to use for LLM requests



7
8
9
# File 'lib/agentic/llm_config.rb', line 7

def model
  @model
end

#presence_penaltyInteger

Returns The presence penalty.

Returns:

  • (Integer)

    The presence penalty



22
23
24
# File 'lib/agentic/llm_config.rb', line 22

def presence_penalty
  @presence_penalty
end

#temperatureFloat

Returns The temperature parameter (controls randomness).

Returns:

  • (Float)

    The temperature parameter (controls randomness)



13
14
15
# File 'lib/agentic/llm_config.rb', line 13

def temperature
  @temperature
end

#top_pFloat

Returns The top_p parameter (nucleus sampling).

Returns:

  • (Float)

    The top_p parameter (nucleus sampling)



16
17
18
# File 'lib/agentic/llm_config.rb', line 16

def top_p
  @top_p
end

Instance Method Details

#to_api_parameters(base_params = {}) ⇒ Hash

Returns a hash of parameters for the API call

Parameters:

  • base_params (Hash) (defaults to: {})

    Base parameters to include

Returns:

  • (Hash)

    Parameters for the API call



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/agentic/llm_config.rb', line 56

def to_api_parameters(base_params = {})
  params = {
    model: @model,
    temperature: @temperature,
    top_p: @top_p,
    frequency_penalty: @frequency_penalty,
    presence_penalty: @presence_penalty
  }

  # Add max_tokens if specified
  params[:max_tokens] = @max_tokens if @max_tokens

  # Merge any additional options
  params.merge!(@additional_options)

  # Merge with base parameters
  base_params.merge(params)
end