Class: Prescient::Configuration
- Inherits:
-
Object
- Object
- Prescient::Configuration
- Defined in:
- lib/prescient.rb
Overview
Configuration class for managing Prescient settings and providers
Handles global settings like timeouts and retry behavior, as well as provider registration and instantiation.
Constant Summary collapse
- DEFAULT_SENSITIVE_KEYS =
Returns Built-in provider option keys removed from output.
[:api_key, :password, :token, :secret].freeze
Instance Attribute Summary collapse
-
#default_provider ⇒ Symbol
The default provider to use when none specified.
-
#fallback_providers ⇒ Array<Symbol>
List of fallback providers to try when primary fails.
-
#providers ⇒ Hash
readonly
Registered providers configuration.
-
#retry_attempts ⇒ Integer
Number of retry attempts for failed requests.
-
#retry_delay ⇒ Float
Delay between retry attempts in seconds.
-
#sensitive_keys ⇒ Array<Symbol>
Additional keys removed from provider information.
-
#timeout ⇒ Integer
Default timeout in seconds for API requests.
Instance Method Summary collapse
-
#add_provider(name, provider_class, **options) ⇒ void
Register a new AI provider.
-
#available_providers ⇒ Array<Symbol>
Get list of providers that currently pass Base#available?.
-
#initialize ⇒ Configuration
constructor
Initialize configuration with default values.
-
#provider(name) ⇒ Base?
Instantiate a provider by name.
Constructor Details
#initialize ⇒ Configuration
Initialize configuration with default values
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/prescient.rb', line 93 def initialize @default_provider = :ollama @timeout = 30 @retry_attempts = 3 @retry_delay = 1.0 @fallback_providers = [] @sensitive_keys = [] @providers = {} @provider_instances = {} # : Hash[Symbol, untyped] end |
Instance Attribute Details
#default_provider ⇒ Symbol
Returns The default provider to use when none specified.
72 73 74 |
# File 'lib/prescient.rb', line 72 def default_provider @default_provider end |
#fallback_providers ⇒ Array<Symbol>
Returns List of fallback providers to try when primary fails.
84 85 86 |
# File 'lib/prescient.rb', line 84 def fallback_providers @fallback_providers end |
#providers ⇒ Hash (readonly)
Returns Registered providers configuration.
90 91 92 |
# File 'lib/prescient.rb', line 90 def providers @providers end |
#retry_attempts ⇒ Integer
Returns Number of retry attempts for failed requests.
78 79 80 |
# File 'lib/prescient.rb', line 78 def retry_attempts @retry_attempts end |
#retry_delay ⇒ Float
Returns Delay between retry attempts in seconds.
81 82 83 |
# File 'lib/prescient.rb', line 81 def retry_delay @retry_delay end |
#sensitive_keys ⇒ Array<Symbol>
Returns Additional keys removed from provider information.
87 88 89 |
# File 'lib/prescient.rb', line 87 def sensitive_keys @sensitive_keys end |
#timeout ⇒ Integer
Returns Default timeout in seconds for API requests.
75 76 77 |
# File 'lib/prescient.rb', line 75 def timeout @timeout end |
Instance Method Details
#add_provider(name, provider_class, **options) ⇒ void
This method returns an undefined value.
Register a new AI provider
128 129 130 131 132 133 134 135 |
# File 'lib/prescient.rb', line 128 def add_provider(name, provider_class, **) provider_name = name.to_sym @providers[provider_name] = { class: provider_class, options: , } @provider_instances.delete(provider_name) end |
#available_providers ⇒ Array<Symbol>
Get list of providers that currently pass Base#available?.
Providers are included when their health check reports reachable: true,
or, for legacy adapters, status == "healthy".
156 157 158 159 160 161 162 |
# File 'lib/prescient.rb', line 156 def available_providers @providers.keys.select do |name| provider(name)&.available? rescue StandardError false end end |
#provider(name) ⇒ Base?
Instantiate a provider by name
141 142 143 144 145 146 147 148 |
# File 'lib/prescient.rb', line 141 def provider(name) provider_name = name.to_sym provider_config = @providers[provider_name] return nil unless provider_config = provider_config[:options] # : Hash[Symbol, untyped] @provider_instances[provider_name] ||= provider_config[:class].new(**) end |