Class: Prescient::Configuration

Inherits:
Object
  • Object
show all
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.

Returns:

  • (Array<Symbol>)

    Built-in provider option keys removed from output

[:api_key, :password, :token, :secret].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize configuration with default values



94
95
96
97
98
99
100
101
102
103
# File 'lib/prescient.rb', line 94

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_providerSymbol

Returns The default provider to use when none specified.

Returns:

  • (Symbol)

    The default provider to use when none specified



73
74
75
# File 'lib/prescient.rb', line 73

def default_provider
  @default_provider
end

#fallback_providersArray<Symbol>

Returns List of fallback providers to try when primary fails.

Returns:

  • (Array<Symbol>)

    List of fallback providers to try when primary fails



85
86
87
# File 'lib/prescient.rb', line 85

def fallback_providers
  @fallback_providers
end

#providersHash (readonly)

Returns Registered providers configuration.

Returns:

  • (Hash)

    Registered providers configuration



91
92
93
# File 'lib/prescient.rb', line 91

def providers
  @providers
end

#retry_attemptsInteger

Returns Number of retry attempts for failed requests.

Returns:

  • (Integer)

    Number of retry attempts for failed requests



79
80
81
# File 'lib/prescient.rb', line 79

def retry_attempts
  @retry_attempts
end

#retry_delayFloat

Returns Delay between retry attempts in seconds.

Returns:

  • (Float)

    Delay between retry attempts in seconds



82
83
84
# File 'lib/prescient.rb', line 82

def retry_delay
  @retry_delay
end

#sensitive_keysArray<Symbol>

Returns Additional keys removed from provider information.

Returns:

  • (Array<Symbol>)

    Additional keys removed from provider information



88
89
90
# File 'lib/prescient.rb', line 88

def sensitive_keys
  @sensitive_keys
end

#timeoutInteger

Returns Default timeout in seconds for API requests.

Returns:

  • (Integer)

    Default timeout in seconds for API requests



76
77
78
# File 'lib/prescient.rb', line 76

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

Examples:

Add OpenAI provider

config.add_provider(:openai, Prescient::Provider::OpenAI,
                    api_key: 'sk-...',
                    chat_model: 'gpt-4.1-mini')

Parameters:

  • name (Symbol)

    Unique identifier for the provider

  • provider_class (Class)

    Provider class that inherits from Base

  • options (Hash)

    Configuration options for the provider

Options Hash (**options):

  • :api_key (String)

    API key for authenticated providers

  • :url (String)

    Base URL for self-hosted providers

  • :model, (String)

    :chat_model Model name for text generation

  • :embedding_model (String)

    Model name for embeddings



129
130
131
132
133
134
135
136
# File 'lib/prescient.rb', line 129

def add_provider(name, provider_class, **options)
  provider_name = name.to_sym
  @providers[provider_name] = {
    class:   provider_class,
    options: options,
  }
  @provider_instances.delete(provider_name)
end

#available_providersArray<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".

Returns:

  • (Array<Symbol>)

    List of reachable provider names



157
158
159
160
161
162
163
# File 'lib/prescient.rb', line 157

def available_providers
  @providers.keys.select do |name|
    provider(name)&.available?
  rescue StandardError
    false
  end
end

#provider(name) ⇒ Base?

Instantiate a provider by name

Parameters:

  • name (Symbol)

    The provider name

Returns:

  • (Base, nil)

    Provider instance or nil if not found



142
143
144
145
146
147
148
149
# File 'lib/prescient.rb', line 142

def provider(name)
  provider_name = name.to_sym
  provider_config = @providers[provider_name]
  return nil unless provider_config

  provider_options = provider_config[:options] # : Hash[Symbol, untyped]
  @provider_instances[provider_name] ||= provider_config[:class].new(**provider_options)
end