Class: Roast::Cogs::Chat::Config
- Inherits:
-
Roast::Cog::Config
- Object
- Roast::Cog::Config
- Roast::Cogs::Chat::Config
- Defined in:
- lib/roast/cogs/chat/config.rb
Constant Summary collapse
- PROVIDERS =
{ openai: { api_key_env_var: "OPENAI_API_KEY", base_url_env_var: "OPENAI_API_BASE", default_base_url: "https://api.openai.com/v1", default_model: "gpt-4o-mini", }, anthropic: { api_key_env_var: "ANTHROPIC_API_KEY", base_url_env_var: "ANTHROPIC_API_BASE", default_base_url: "https://api.anthropic.com", default_model: "claude-haiku-4-5", }, perplexity: { api_key_env_var: "PERPLEXITY_API_KEY", default_model: "sonar", }, gemini: { api_key_env_var: "GEMINI_API_KEY", base_url_env_var: "GEMINI_API_BASE", default_base_url: "https://generativelanguage.googleapis.com/v1beta", default_model: "gemini-3.1-flash-lite", }, }.freeze
Instance Attribute Summary
Attributes inherited from Roast::Cog::Config
Instance Method Summary collapse
-
#api_key(key) ⇒ Object
Configure the cog to use a specific API key when invoking the llm.
-
#base_url(key) ⇒ Object
Configure the cog to use a specific API base URL when invoking the llm.
-
#display! ⇒ Object
Configure the cog to display all llm output.
-
#display? ⇒ Boolean
Check if the cog is configured to display any output while running.
-
#model(model) ⇒ Object
Configure the cog to use a specific model when invoking the agent.
-
#no_display! ⇒ Object
(also: #quiet!)
Configure the cog to hide all llm output.
-
#no_show_prompt! ⇒ Object
Configure the cog not to display the prompt when invoking the llm.
-
#no_show_response! ⇒ Object
Configure the cog not to display the llm's final response.
-
#no_show_stats! ⇒ Object
Configure the cog not to display statistics about the llm's operation.
-
#no_verify_model_exists! ⇒ Object
(also: #assume_model_exists!)
Configure the cog not to verify that the model exists on the provider before attempting to invoke it.
-
#provider(provider) ⇒ Object
Configure the cog to use a specified API provider when invoking the llm.
-
#show_prompt! ⇒ Object
Configure the cog to display the prompt when invoking the llm.
-
#show_prompt? ⇒ Boolean
Check if the cog is configured to display the prompt when invoking the llm.
-
#show_response! ⇒ Object
Configure the cog to display the llm's final response.
-
#show_response? ⇒ Boolean
Check if the cog is configured to display the llm's final response.
-
#show_stats! ⇒ Object
Configure the cog to display statistics about the llm's operation.
-
#show_stats? ⇒ Boolean
Check if the cog is configured to display statistics about the llm's operation.
-
#temperature(value) ⇒ Object
Configure the cog to use a specific temperature when invoking the llm.
-
#use_api_key_from_environment! ⇒ Object
Remove any explicit api key that the cog was configured to use when invoking the llm.
-
#use_default_base_url! ⇒ Object
Remove any explicit API base URL that the cog was configured to use when invoking the llm.
-
#use_default_model! ⇒ Object
Configure the cog to use the provider's default model when invoking the agent.
-
#use_default_provider! ⇒ Object
Configure the cog to use the default provider when invoking the llm.
-
#use_default_temperature! ⇒ Object
Remove any explicit temperature configuration.
-
#valid_api_key! ⇒ Object
Get the validated, configured value of the API key the cog is configured to use when invoking the llm.
-
#valid_base_url ⇒ Object
Get the validated, configured value of the API base URL the cog is configured to use when invoking the llm.
-
#valid_model ⇒ Object
Get the validated, configured value of the model the cog is configured to use when running the agent.
-
#valid_provider! ⇒ Object
Get the validated provider name that the cog is configured to use when invoking the llm.
-
#valid_temperature ⇒ Object
Get the validated, configured temperature value.
-
#verify_model_exists! ⇒ Object
Configure the cog to verify that the model exists on the provider before attempting to invoke it.
-
#verify_model_exists? ⇒ Boolean
Check if the cog is configured to verify that the model exists on the provider.
Methods inherited from Roast::Cog::Config
#[], #[]=, #abort_on_failure!, #abort_on_failure?, #async!, #async?, field, #initialize, #merge, #no_abort_on_failure!, #no_async!, #use_current_working_directory!, #valid_working_directory, #validate!, #working_directory
Constructor Details
This class inherits a constructor from Roast::Cog::Config
Instance Method Details
#api_key(key) ⇒ Object
Configure the cog to use a specific API key when invoking the llm
By default, the cog will use the value specified in a provider-specific environment variable, if present.
See Also
use_api_key_from_environment!
: (String) -> void
84 85 86 |
# File 'lib/roast/cogs/chat/config.rb', line 84 def api_key(key) @values[:api_key] = key end |
#base_url(key) ⇒ Object
Configure the cog to use a specific API base URL when invoking the llm
Default value:
- The value specified in provider-specific environment variable, if present;
- A provider-specific default, otherwise.
See Also
use_default_base_url!
: (String) -> void
139 140 141 |
# File 'lib/roast/cogs/chat/config.rb', line 139 def base_url(key) @values[:base_url] = key end |
#display! ⇒ Object
Configure the cog to display all llm output
This enables show_prompt!, show_response!, and show_stats!.
See Also
no_display!quiet!show_prompt!show_response!show_stats!
: () -> void
430 431 432 433 434 |
# File 'lib/roast/cogs/chat/config.rb', line 430 def display! show_prompt! show_response! show_stats! end |
#display? ⇒ Boolean
Check if the cog is configured to display any output while running
See Also
display!no_display!show_prompt?show_response?show_stats?
: () -> bool
468 469 470 |
# File 'lib/roast/cogs/chat/config.rb', line 468 def display? show_prompt? || show_response? || show_stats? end |
#model(model) ⇒ Object
Configure the cog to use a specific model when invoking the agent
The model name format is provider-specific.
See Also
use_default_model!
: (String) -> void
187 188 189 |
# File 'lib/roast/cogs/chat/config.rb', line 187 def model(model) @values[:model] = model end |
#no_display! ⇒ Object Also known as: quiet!
Configure the cog to hide all llm output
This enables no_show_prompt!, no_show_response!, and no_show_stats!.
Alias Methods
no_display!quiet!
See Also
display!quiet!no_show_prompt!no_show_response!no_show_stats!
: () -> void
452 453 454 455 456 |
# File 'lib/roast/cogs/chat/config.rb', line 452 def no_display! no_show_prompt! no_show_response! no_show_stats! end |
#no_show_prompt! ⇒ Object
Configure the cog not to display the prompt when invoking the llm
This is the default behaviour.
See Also
show_prompt!show_prompt?no_display!quiet!
: () -> void
327 328 329 |
# File 'lib/roast/cogs/chat/config.rb', line 327 def no_show_prompt! @values[:show_prompt] = false end |
#no_show_response! ⇒ Object
Configure the cog not to display the llm's final response
See Also
show_response!show_response?no_display!quiet!
: () -> void
365 366 367 |
# File 'lib/roast/cogs/chat/config.rb', line 365 def no_show_response! @values[:show_response] = false end |
#no_show_stats! ⇒ Object
Configure the cog not to display statistics about the llm's operation
See Also
show_stats!show_stats?no_display!quiet!
: () -> void
403 404 405 |
# File 'lib/roast/cogs/chat/config.rb', line 403 def no_show_stats! @values[:show_stats] = false end |
#no_verify_model_exists! ⇒ Object Also known as: assume_model_exists!
Configure the cog not to verify that the model exists on the provider before attempting to invoke it
This is the default behaviour.
See Also
verify_model_exists!assume_model_exists!verify_model_exists?
: () -> void
285 286 287 |
# File 'lib/roast/cogs/chat/config.rb', line 285 def no_verify_model_exists! @values[:verify_model_exists] = false end |
#provider(provider) ⇒ Object
Configure the cog to use a specified API provider when invoking the llm
See Also
use_default_provider!
: (Symbol) -> void
39 40 41 |
# File 'lib/roast/cogs/chat/config.rb', line 39 def provider(provider) @values[:provider] = provider end |
#show_prompt! ⇒ Object
Configure the cog to display the prompt when invoking the llm
Disabled by default.
See Also
no_show_prompt!show_prompt?display!
: () -> void
312 313 314 |
# File 'lib/roast/cogs/chat/config.rb', line 312 def show_prompt! @values[:show_prompt] = true end |
#show_prompt? ⇒ Boolean
Check if the cog is configured to display the prompt when invoking the llm
See Also
show_prompt!no_show_prompt!
: () -> bool
338 339 340 |
# File 'lib/roast/cogs/chat/config.rb', line 338 def show_prompt? @values.fetch(:show_prompt, false) end |
#show_response! ⇒ Object
Configure the cog to display the llm's final response
Enabled by default.
See Also
no_show_response!show_response?display!
: () -> void
352 353 354 |
# File 'lib/roast/cogs/chat/config.rb', line 352 def show_response! @values[:show_response] = true end |
#show_response? ⇒ Boolean
Check if the cog is configured to display the llm's final response
See Also
show_response!no_show_response!
: () -> bool
376 377 378 |
# File 'lib/roast/cogs/chat/config.rb', line 376 def show_response? @values.fetch(:show_response, true) end |
#show_stats! ⇒ Object
Configure the cog to display statistics about the llm's operation
Enabled by default.
See Also
no_show_stats!show_stats?display!
: () -> void
390 391 392 |
# File 'lib/roast/cogs/chat/config.rb', line 390 def show_stats! @values[:show_stats] = true end |
#show_stats? ⇒ Boolean
Check if the cog is configured to display statistics about the llm's operation
See Also
show_stats!no_show_stats!
: () -> bool
414 415 416 |
# File 'lib/roast/cogs/chat/config.rb', line 414 def show_stats? @values.fetch(:show_stats, true) end |
#temperature(value) ⇒ Object
Configure the cog to use a specific temperature when invoking the llm
Temperature controls the randomness of the model's responses:
- Low (0.0-0.3): More deterministic and focused responses
- Medium (0.4-0.7): Balanced creativity and coherence
- High (0.8-1.0): More creative and varied responses
See Also
use_default_temperature!
: (Float) -> void
227 228 229 230 231 232 233 |
# File 'lib/roast/cogs/chat/config.rb', line 227 def temperature(value) if value < 0.0 || value > 1.0 raise ArgumentError, "temperature must be between 0.0 and 1.0, got #{value}" end @values[:temperature] = value.to_f end |
#use_api_key_from_environment! ⇒ Object
Remove any explicit api key that the cog was configured to use when invoking the llm
The cog will fall back to the value specified in a provider-specific environment variable, if present.
Environment Variables
- OpenAI Provider: OPENAI_API_KEY
- Anthropic Provider: ANTHROPIC_API_KEY
- Perplexity Provider: PERPLEXITY_API_KEY
- Gemini Provider: GEMINI_API_KEY
See Also
api_key
: () -> void
102 103 104 |
# File 'lib/roast/cogs/chat/config.rb', line 102 def use_api_key_from_environment! @values.delete(:api_key) end |
#use_default_base_url! ⇒ Object
Remove any explicit API base URL that the cog was configured to use when invoking the llm
The cog will fall back to a default value determined as follows:
- The value specified in provider-specific environment variable, if present;
- A provider-specific default, otherwise.
Environment Variables
- OpenAI Provider: OPENAI_API_BASE
- Anthropic Provider: ANTHROPIC_API_BASE
- Gemini Provider: GEMINI_API_BASE
See Also
base_url
: () -> void
158 159 160 |
# File 'lib/roast/cogs/chat/config.rb', line 158 def use_default_base_url! @values[:base_url] = nil end |
#use_default_model! ⇒ Object
Configure the cog to use the provider's default model when invoking the agent
Note: the default model will be different for different providers.
See Also
model
: () -> void
199 200 201 |
# File 'lib/roast/cogs/chat/config.rb', line 199 def use_default_model! @values.delete(:model) end |
#use_default_provider! ⇒ Object
Configure the cog to use the default provider when invoking the llm
The default LLM provider used by Roast is OpenAI (:openai).
See Also
provider
: () -> void
51 52 53 |
# File 'lib/roast/cogs/chat/config.rb', line 51 def use_default_provider! @values[:provider] = nil end |
#use_default_temperature! ⇒ Object
Remove any explicit temperature configuration
The cog will fall back to the provider's default temperature.
See Also
temperature
: () -> void
243 244 245 |
# File 'lib/roast/cogs/chat/config.rb', line 243 def use_default_temperature! @values.delete(:temperature) end |
#valid_api_key! ⇒ Object
Get the validated, configured value of the API key the cog is configured to use when invoking the llm
This method will raise InvalidConfigError if no api key was provided, neither explicitly nor via a provider-specific environment variable.
Environment Variables
- OpenAI Provider: OPENAI_API_KEY
- Anthropic Provider: ANTHROPIC_API_KEY
- Perplexity Provider: PERPLEXITY_API_KEY
- Gemini Provider: GEMINI_API_KEY
See Also
api_keyuse_api_key_from_environment!
: () -> String
122 123 124 125 126 127 |
# File 'lib/roast/cogs/chat/config.rb', line 122 def valid_api_key! value = @values.fetch(:api_key, ENV[PROVIDERS.dig(valid_provider!, :api_key_env_var).not_nil!]) raise InvalidConfigError, "no api key provided" unless value value end |
#valid_base_url ⇒ Object
Get the validated, configured value of the API base URL the cog is configured to use when invoking the llm
Environment Variables
- OpenAI Provider: OPENAI_API_BASE
- Anthropic Provider: ANTHROPIC_API_BASE
- Gemini Provider: GEMINI_API_BASE
See Also
base_urluse_default_base_url!
: () -> String
174 175 176 177 |
# File 'lib/roast/cogs/chat/config.rb', line 174 def valid_base_url @values.fetch(:base_url, ENV[PROVIDERS.dig(valid_provider!, :base_url_env_var).not_nil!]) || PROVIDERS.dig(valid_provider!, :default_base_url) end |
#valid_model ⇒ Object
Get the validated, configured value of the model the cog is configured to use when running the agent
Returns the provider's default model if no model was explicitly configured.
See Also
modeluse_default_model!
: () -> String?
212 213 214 |
# File 'lib/roast/cogs/chat/config.rb', line 212 def valid_model @values.fetch(:model, PROVIDERS.dig(valid_provider!, :default_model)) end |
#valid_provider! ⇒ Object
Get the validated provider name that the cog is configured to use when invoking the llm
Note: this method will return the name of a valid provider or raise an InvalidConfigError.
It will not, however, validate that the you have access to the provider's API.
If you have not correctly configured API access, you will likely experience a failure when Roast attempts to
run your workflow.
See Also
provideruse_default_provider!
: () -> Symbol
67 68 69 70 71 72 73 74 |
# File 'lib/roast/cogs/chat/config.rb', line 67 def valid_provider! provider = @values[:provider] || PROVIDERS.keys.first unless PROVIDERS.include?(provider) raise InvalidConfigError, "'#{provider}' is not a valid provider. Available providers include: #{PROVIDERS.keys.join(", ")}" end provider end |
#valid_temperature ⇒ Object
Get the validated, configured temperature value
Returns nil if no temperature was explicitly configured,
which means the provider will use its default.
See Also
temperatureuse_default_temperature!
: () -> Float?
257 258 259 |
# File 'lib/roast/cogs/chat/config.rb', line 257 def valid_temperature @values[:temperature] end |
#verify_model_exists! ⇒ Object
Configure the cog to verify that the model exists on the provider before attempting to invoke it
Disabled by default.
See Also
no_verify_model_exists!assume_model_exists!verify_model_exists?
: () -> void
271 272 273 |
# File 'lib/roast/cogs/chat/config.rb', line 271 def verify_model_exists! @values[:verify_model_exists] = true end |
#verify_model_exists? ⇒ Boolean
Check if the cog is configured to verify that the model exists on the provider
See Also
verify_model_exists!no_verify_model_exists!assume_model_exists!verify_model_exists?
: () -> bool
298 299 300 |
# File 'lib/roast/cogs/chat/config.rb', line 298 def verify_model_exists? @values.fetch(:verify_model_exists, false) end |