Class: Prescient::Client
- Inherits:
-
Object
- Object
- Prescient::Client
- Defined in:
- lib/prescient/client.rb
Overview
Client class for interacting with AI providers
The Client provides a high-level interface for working with AI providers, handling error recovery, retries, and method delegation. It acts as a facade over the configured providers.
Instance Attribute Summary collapse
-
#provider ⇒ Prescient::Base
readonly
The underlying provider instance.
-
#provider_name ⇒ Symbol
readonly
The name of the provider being used.
Instance Method Summary collapse
-
#available? ⇒ Boolean
Check if the provider is currently available.
-
#generate_embedding(text, **options) ⇒ Array<Float>
Generate embeddings for the given text.
-
#generate_response(prompt, context_items = [], **options) ⇒ Hash
Generate text response for the given prompt.
-
#health_check ⇒ Hash
Check the health status of the provider.
-
#initialize(provider_name = nil, enable_fallback: true, provider_options: {}) ⇒ Client
constructor
Initialize a new client with the specified provider.
-
#provider_info ⇒ Hash
Get comprehensive information about the provider.
Constructor Details
#initialize(provider_name = nil, enable_fallback: true, provider_options: {}) ⇒ Client
Initialize a new client with the specified provider
33 34 35 36 37 38 39 |
# File 'lib/prescient/client.rb', line 33 def initialize(provider_name = nil, enable_fallback: true, provider_options: {}) @provider_name = provider_name || Prescient.configuration.default_provider @provider = (@provider_name, ) @enable_fallback = enable_fallback raise Prescient::Error, "Provider not configured: #{@provider_name}" unless @provider end |
Instance Attribute Details
#provider ⇒ Prescient::Base (readonly)
Returns The underlying provider instance.
25 26 27 |
# File 'lib/prescient/client.rb', line 25 def provider @provider end |
#provider_name ⇒ Symbol (readonly)
Returns The name of the provider being used.
22 23 24 |
# File 'lib/prescient/client.rb', line 22 def provider_name @provider_name end |
Instance Method Details
#available? ⇒ Boolean
Check if the provider is currently available
95 96 97 |
# File 'lib/prescient/client.rb', line 95 def available? @provider.available? end |
#generate_embedding(text, **options) ⇒ Array<Float>
Generate embeddings for the given text
Delegates to the underlying provider with automatic retry logic for transient failures. If fallback is enabled, tries other providers on persistent failures.
51 52 53 54 55 56 57 58 59 |
# File 'lib/prescient/client.rb', line 51 def (text, **) if @enable_fallback with_fallback_handling(:generate_embedding, text, **) else with_error_handling do @provider.(text, **) end end end |
#generate_response(prompt, context_items = [], **options) ⇒ Hash
Generate text response for the given prompt
Delegates to the underlying provider with automatic retry logic for transient failures. Supports optional context items for RAG. If fallback is enabled, tries other providers on persistent failures.
75 76 77 78 79 80 81 82 83 |
# File 'lib/prescient/client.rb', line 75 def generate_response(prompt, context_items = [], **) if @enable_fallback with_fallback_handling(:generate_response, prompt, context_items, **) else with_error_handling do @provider.generate_response(prompt, context_items, **) end end end |
#health_check ⇒ Hash
Check the health status of the provider
88 89 90 |
# File 'lib/prescient/client.rb', line 88 def health_check @provider.health_check end |
#provider_info ⇒ Hash
Get comprehensive information about the provider
Returns details about the provider including its availability and configuration options (with sensitive data removed).
106 107 108 109 110 111 112 113 |
# File 'lib/prescient/client.rb', line 106 def provider_info { name: @provider_name, class: @provider.class.name.split("::").last, available: available?, options: (@provider.) } end |