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.
%i[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.
-
#tools ⇒ Hash
readonly
Registered tools configuration.
Instance Method Summary collapse
-
#add_provider(name, provider_class, **options) ⇒ void
Register a new AI provider.
-
#add_tool(name, tool_class, **options) ⇒ void
Register an external tool.
-
#add_tool_group(name, adapters) ⇒ void
Register ordered implementations for one logical external tool.
-
#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.
-
#tool(name) ⇒ Prescient::Tool::Base?
Instantiate a tool by name.
Constructor Details
#initialize ⇒ Configuration
Initialize configuration with default values
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/prescient.rb', line 141 def initialize @default_provider = :ollama @timeout = 30 @retry_attempts = 3 @retry_delay = 1.0 @fallback_providers = [] @sensitive_keys = [] @providers = {} @provider_instances = {} # : Hash[Symbol, untyped] @tools = {} @tool_instances = {} # : Hash[Symbol, untyped] end |
Instance Attribute Details
#default_provider ⇒ Symbol
Returns The default provider to use when none specified.
117 118 119 |
# File 'lib/prescient.rb', line 117 def default_provider @default_provider end |
#fallback_providers ⇒ Array<Symbol>
Returns List of fallback providers to try when primary fails.
129 130 131 |
# File 'lib/prescient.rb', line 129 def fallback_providers @fallback_providers end |
#providers ⇒ Hash (readonly)
Returns Registered providers configuration.
135 136 137 |
# File 'lib/prescient.rb', line 135 def providers @providers end |
#retry_attempts ⇒ Integer
Returns Number of retry attempts for failed requests.
123 124 125 |
# File 'lib/prescient.rb', line 123 def retry_attempts @retry_attempts end |
#retry_delay ⇒ Float
Returns Delay between retry attempts in seconds.
126 127 128 |
# File 'lib/prescient.rb', line 126 def retry_delay @retry_delay end |
#sensitive_keys ⇒ Array<Symbol>
Returns Additional keys removed from provider information.
132 133 134 |
# File 'lib/prescient.rb', line 132 def sensitive_keys @sensitive_keys end |
#timeout ⇒ Integer
Returns Default timeout in seconds for API requests.
120 121 122 |
# File 'lib/prescient.rb', line 120 def timeout @timeout end |
#tools ⇒ Hash (readonly)
Returns Registered tools configuration.
138 139 140 |
# File 'lib/prescient.rb', line 138 def tools @tools end |
Instance Method Details
#add_provider(name, provider_class, **options) ⇒ void
This method returns an undefined value.
Register a new AI provider
178 179 180 181 182 183 184 185 |
# File 'lib/prescient.rb', line 178 def add_provider(name, provider_class, **) provider_name = name.to_sym @providers[provider_name] = { class: provider_class, options: } @provider_instances.delete(provider_name) end |
#add_tool(name, tool_class, **options) ⇒ void
This method returns an undefined value.
Register an external tool.
205 206 207 208 209 210 211 212 |
# File 'lib/prescient.rb', line 205 def add_tool(name, tool_class, **) tool_name = name.to_sym @tools[tool_name] = { class: tool_class, options: } @tool_instances.delete(tool_name) end |
#add_tool_group(name, adapters) ⇒ void
This method returns an undefined value.
Register ordered implementations for one logical external tool.
218 219 220 221 222 |
# File 'lib/prescient.rb', line 218 def add_tool_group(name, adapters) tool_name = name.to_sym @tools[tool_name] = { adapters: adapters } @tool_instances.delete(tool_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".
252 253 254 255 256 257 258 |
# File 'lib/prescient.rb', line 252 def available_providers @providers.keys.select do |name| provider(name)&.available? rescue StandardError false end end |
#provider(name) ⇒ Base?
Instantiate a provider by name
191 192 193 194 195 196 197 198 |
# File 'lib/prescient.rb', line 191 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 |
#tool(name) ⇒ Prescient::Tool::Base?
Instantiate a tool by name.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/prescient.rb', line 227 def tool(name) tool_name = name.to_sym tool_config = @tools[tool_name] return nil unless tool_config if tool_config[:adapters] @tool_instances[tool_name] ||= Prescient::Tool::Group.new( adapters: tool_config[:adapters].map do |adapter| = adapter[:options] # : Hash[Symbol, untyped] adapter[:class].new(**) end ) return @tool_instances[tool_name] end = tool_config[:options] # : Hash[Symbol, untyped] @tool_instances[tool_name] ||= tool_config[:class].new(**) end |