Module: Prescient

Defined in:
lib/prescient.rb,
lib/prescient.rb,
lib/prescient/client.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 HuggingFace. It supports both embedding generation and text completion with configurable context handling.

Examples:

Basic usage

Prescient.configure do |config|
  config.add_provider(:openai, Prescient::Provider::OpenAI,
                      api_key: 'your-api-key')
end

client = Prescient.client(:openai)
response = client.generate_response("Hello, world!")

Embedding generation

embedding = client.generate_embedding("Some text to embed")
puts embedding.length # => 1536 (for OpenAI text-embedding-3-small)

Author:

  • Claude Code

Since:

  • 1.0.0

Defined Under Namespace

Modules: Provider Classes: AuthenticationError, Base, Client, Configuration, ConnectionError, Error, InvalidResponseError, ModelNotAvailableError, RateLimitError

Constant Summary collapse

VERSION =

Since:

  • 1.0.0

'0.2.0'

Class Method Summary collapse

Class Method Details

.client(provider_name = nil, enable_fallback: true) ⇒ Object

Convenience methods for quick access

Since:

  • 1.0.0



196
197
198
# File 'lib/prescient/client.rb', line 196

def self.client(provider_name = nil, enable_fallback: true)
  Client.new(provider_name, enable_fallback: enable_fallback)
end

.configurationConfiguration

Get the current configuration instance

Returns:

Since:

  • 1.0.0



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

def self.configuration
  @_configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Configure Prescient with custom settings and providers

Examples:

Configure with custom provider

Prescient.configure do |config|
  config.default_provider = :openai
  config.timeout = 60
  config.add_provider(:openai, Prescient::Provider::OpenAI,
                      api_key: 'your-key')
end

Yields:

  • (config)

    Configuration block

Yield Parameters:

Since:

  • 1.0.0



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

def self.configure
  yield(configuration)
end

.generate_embedding(text, provider: nil, enable_fallback: true, **options) ⇒ Object

Since:

  • 1.0.0



200
201
202
# File 'lib/prescient/client.rb', line 200

def self.generate_embedding(text, provider: nil, enable_fallback: true, **options)
  client(provider, enable_fallback: enable_fallback).generate_embedding(text, **options)
end

.generate_response(prompt, context_items = [], provider: nil, enable_fallback: true, **options) ⇒ Object

Since:

  • 1.0.0



204
205
206
# File 'lib/prescient/client.rb', line 204

def self.generate_response(prompt, context_items = [], provider: nil, enable_fallback: true, **options)
  client(provider, enable_fallback: enable_fallback).generate_response(prompt, context_items, **options)
end

.health_check(provider: nil) ⇒ Object

Since:

  • 1.0.0



208
209
210
# File 'lib/prescient/client.rb', line 208

def self.health_check(provider: nil)
  client(provider, enable_fallback: false).health_check
end

.reset_configuration!Configuration

Reset configuration to defaults

Returns:

Since:

  • 1.0.0



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

def self.reset_configuration!
  @_configuration = Configuration.new
end