Module: Prescient
- Defined in:
- lib/prescient.rb,
lib/prescient/client.rb,
lib/prescient/errors.rb,
lib/prescient/version.rb
Overview
Main Prescient module for AI provider abstraction
Prescient provides a unified interface for working with multiple AI providers including Ollama, OpenAI, Anthropic, and Hugging Face. It supports both embedding generation and text completion with configurable context handling.
Defined Under Namespace
Modules: Pgvector, Provider, Tool Classes: API, AuthenticationError, Base, CLI, Client, Configuration, ConfigurationLoader, ConnectionError, Error, InvalidResponseError, InvalidVectorError, ModelNotAvailableError, ProviderError, RateLimitError, ToolConfigurationError, ToolConnectionError, ToolError, ToolInvalidResponseError
Constant Summary collapse
- VERSION =
Current Prescient gem version.
'0.7.0'
Class Method Summary collapse
-
.client(provider_name = nil, enable_fallback: true, provider_options: {}) ⇒ Client
Convenience methods for quick access.
-
.configuration ⇒ Configuration
Get the current configuration instance.
-
.configure {|config| ... } ⇒ void
Configure Prescient with custom settings and providers.
-
.generate_embedding(text, provider: nil, enable_fallback: true, **options) ⇒ Array<Float>
Generate an embedding through a configured provider.
-
.generate_response(prompt, context_items = [], provider: nil, enable_fallback: true, **options) ⇒ Hash
Generate a response through a configured provider.
-
.health_check(provider: nil) ⇒ Hash
Return the health status of a configured provider.
-
.load_configuration(path = nil, env: ENV) ⇒ Configuration
Load configuration from a YAML file and replace the current configuration.
-
.reset_configuration! ⇒ Configuration
Reset configuration to defaults.
-
.search_and_generate(query, tool: :web_search, provider: nil, limit: nil, enable_fallback: true, provider_options: {}, **options) ⇒ Hash
Search with an explicit external tool and optionally use the normalized results as context for a configured AI provider.
-
.tool(name) ⇒ Prescient::Tool::Base?
Look up a configured external tool.
Class Method Details
.client(provider_name = nil, enable_fallback: true, provider_options: {}) ⇒ Client
Convenience methods for quick access
224 225 226 |
# File 'lib/prescient/client.rb', line 224 def self.client(provider_name = nil, enable_fallback: true, provider_options: {}) Client.new(provider_name, enable_fallback: enable_fallback, provider_options: ) end |
.configuration ⇒ Configuration
Get the current configuration instance
62 63 64 |
# File 'lib/prescient.rb', line 62 def self.configuration @_configuration ||= Configuration.new end |
.configure {|config| ... } ⇒ void
This method returns an undefined value.
Configure Prescient with custom settings and providers
55 56 57 |
# File 'lib/prescient.rb', line 55 def self.configure yield(configuration) end |
.generate_embedding(text, provider: nil, enable_fallback: true, **options) ⇒ Array<Float>
Generate an embedding through a configured provider.
234 235 236 |
# File 'lib/prescient/client.rb', line 234 def self.(text, provider: nil, enable_fallback: true, **) client(provider, enable_fallback: enable_fallback).(text, **) end |
.generate_response(prompt, context_items = [], provider: nil, enable_fallback: true, **options) ⇒ Hash
Generate a response through a configured provider.
246 247 248 |
# File 'lib/prescient/client.rb', line 246 def self.generate_response(prompt, context_items = [], provider: nil, enable_fallback: true, **) client(provider, enable_fallback: enable_fallback).generate_response(prompt, context_items, **) end |
.health_check(provider: nil) ⇒ Hash
Return the health status of a configured provider.
280 281 282 |
# File 'lib/prescient/client.rb', line 280 def self.health_check(provider: nil) client(provider, enable_fallback: false).health_check end |
.load_configuration(path = nil, env: ENV) ⇒ Configuration
Load configuration from a YAML file and replace the current configuration.
The loaded configuration starts from the current environment defaults, then applies the YAML file, environment-variable references, and any optional overrides.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/prescient.rb', line 89 def self.load_configuration(path = nil, env: ENV) effective_path = path || env['PRESCIENT_CONFIG'] configuration = if effective_path ConfigurationLoader.load_file(effective_path, env:) else Configuration.new.tap do |config| configure_default_providers(config, env) configure_default_tools(config, env) end end @_configuration = configuration end |
.reset_configuration! ⇒ Configuration
Reset configuration to defaults
76 77 78 |
# File 'lib/prescient.rb', line 76 def self.reset_configuration! @_configuration = Configuration.new end |
.search_and_generate(query, tool: :web_search, provider: nil, limit: nil, enable_fallback: true, provider_options: {}, **options) ⇒ Hash
Search with an explicit external tool and optionally use the normalized results as context for a configured AI provider.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/prescient/client.rb', line 260 def self.search_and_generate(query, tool: :web_search, provider: nil, limit: nil, enable_fallback: true, provider_options: {}, **) search_tool = self.tool(tool) raise Prescient::ToolConfigurationError, "tool not configured: #{tool}" unless search_tool search_result = search_tool.search(query, limit: limit) context_items = search_result[:results] raise Prescient::ToolInvalidResponseError, 'tool results must be an array' unless context_items.is_a?(Array) client(provider, enable_fallback:, provider_options:).generate_response( query, context_items, **, ) end |
.tool(name) ⇒ Prescient::Tool::Base?
Look up a configured external tool.
69 70 71 |
# File 'lib/prescient.rb', line 69 def self.tool(name) configuration.tool(name) end |