prescient 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -2
- data/.yardopts +3 -6
- data/CHANGELOG.md +41 -4
- data/INTEGRATION_GUIDE.md +27 -29
- data/LICENSE.txt +1 -1
- data/README.md +133 -74
- data/Rakefile +82 -7
- data/Steepfile +17 -0
- data/VECTOR_SEARCH_GUIDE.md +32 -8
- data/docker-compose.yml +3 -5
- data/examples/README.md +45 -0
- data/examples/basic_usage.rb +2 -2
- data/examples/custom_contexts.rb +6 -6
- data/examples/custom_prompts.rb +5 -5
- data/examples/vector_search.rb +2 -2
- data/lib/prescient/base.rb +81 -26
- data/lib/prescient/client.rb +70 -36
- data/lib/prescient/errors.rb +51 -0
- data/lib/prescient/pgvector.rb +194 -0
- data/lib/prescient/provider/anthropic.rb +55 -54
- data/lib/prescient/provider/huggingface.rb +76 -76
- data/lib/prescient/provider/ollama.rb +46 -35
- data/lib/prescient/provider/openai.rb +38 -31
- data/lib/prescient/version.rb +2 -1
- data/lib/prescient.rb +85 -63
- data/scripts/setup-ollama-models.sh +2 -2
- data/sig/prescient.rbs +221 -1
- metadata +21 -217
- data/CHANGELOG.pdf +0 -0
- data/prescient.gemspec +0 -53
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a54256e23ba55fc2492fae38d687b275dcb2362df73449d3212bd03659150717
|
|
4
|
+
data.tar.gz: 73ab805b7a5781a1d03488605ae8d7890feda7344b41b1ac550343484b3b597a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e918a87b3e09affe9d5a002a3955051e7729ee565f84c42c534c99dc3fc70371fda930e63cc90801da07b4c4f5e48031c41e952088dfc3de24f0f38b579e9567
|
|
7
|
+
data.tar.gz: feb707947b7cc0b67d8bff933b4c584a69595b9b5e1dd3f214b4c4aa2d48c0577c996b542c238fbcef337f0f276a1bb995acc9653e8fad32262a6f6fa17caaf4
|
data/.rubocop.yml
CHANGED
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Unreleased
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
|
+
## [0.3.0] - 2025-08-14
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Added a development quality harness covering tests, RuboCop, YARD, and RBS tasks.
|
|
10
|
+
- Added 99% minimum line and branch coverage requirements with expanded provider and context coverage tests.
|
|
11
|
+
- Added an actionlint Rake task for GitHub Actions validation.
|
|
12
|
+
- Added Dependabot configuration for Bundler, Docker, and GitHub Actions updates.
|
|
13
|
+
- Added an opt-in `Prescient::Pgvector::Store` boundary for validated embedding storage and similarity search.
|
|
14
|
+
- Added configurable Ollama embedding dimensions while preserving strict validation when configured.
|
|
15
|
+
- Added a default example-syntax quality gate that validates Ruby examples without contacting providers.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Updated Ollama embeddings to use `/api/embed` with strict vector-dimension validation.
|
|
20
|
+
- Restricted fallback to transient/provider-service failures and added the public `ProviderError` exception for provider-side service errors.
|
|
21
|
+
- Reused registered provider instances and removed redundant health checks during fallback discovery.
|
|
22
|
+
- Updated default chat model names and README examples for current Ollama, Anthropic, OpenAI, and Hugging Face model selections.
|
|
23
|
+
- Updated Hugging Face inference to use the current router feature-extraction and OpenAI-compatible chat-completion APIs.
|
|
24
|
+
- Standardized provider reachability in health results and removed embedding padding/truncation across OpenAI and Hugging Face.
|
|
25
|
+
- Updated Anthropic model listing and health checks to use its `/v1/models` catalog endpoint.
|
|
26
|
+
- Retained OpenAI Chat Completions for the current normalized public response contract; Responses API migration remains a separately scoped compatibility change.
|
|
27
|
+
- Raised YARD API documentation coverage enforcement to 99% or higher and modernized gem development metadata.
|
|
28
|
+
- Compacted GitHub Actions into focused CI, Pages, release, and security workflows.
|
|
29
|
+
- Added credentialed, provider-selected live smoke tests that remain skipped by default.
|
|
30
|
+
- Restored the RBS/Steep development tasks with a committed Steepfile and curated core API signatures.
|
|
31
|
+
- Expanded Steep coverage to the base abstraction and all provider adapters, including their public operations and HTTP boundaries.
|
|
32
|
+
- Added configurable provider-info sensitive-key sanitization and configurable generic context-field exclusions.
|
|
33
|
+
- Audited README and documentation examples against the current codebase.
|
|
34
|
+
- Removed client `method_missing` delegation so provider-specific behavior is not exposed through the public client.
|
|
35
|
+
- Prevented default provider registration when required credentials are absent from the environment.
|
|
36
|
+
- Sanitized provider HTTP errors so raw response bodies are not exposed in exception messages.
|
|
37
|
+
- Removed fallback health probes before provider operations to avoid duplicate network requests and race conditions.
|
|
38
|
+
- Clarified health semantics: `reachable` reports transport availability and `ready` reports configured-model readiness.
|
|
39
|
+
- Added shared provider health-contract coverage for status, reachability, readiness, and provider identity.
|
|
40
|
+
|
|
41
|
+
### Removed
|
|
42
|
+
|
|
43
|
+
- Removed the obsolete PDF changelog and superseded workflow definitions.
|
|
44
|
+
|
|
45
|
+
## [0.2.0] - 2025-08-05
|
|
9
46
|
|
|
10
47
|
### Added
|
|
11
48
|
|
data/INTEGRATION_GUIDE.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# AI Providers Integration Guide
|
|
2
2
|
|
|
3
|
-
This guide explains how to integrate the
|
|
3
|
+
This guide explains how to integrate the Prescient gem into an existing Rails AI application.
|
|
4
|
+
|
|
5
|
+
For the canonical public API and runnable scripts, see the [README](README.md)
|
|
6
|
+
and [examples guide](examples/README.md).
|
|
4
7
|
|
|
5
8
|
## Integration Steps
|
|
6
9
|
|
|
@@ -10,7 +13,7 @@ This guide explains how to integrate the AI Providers gem into your existing Rai
|
|
|
10
13
|
# Add to your Gemfile
|
|
11
14
|
gem 'prescient', path: './prescient_gem' # Local development
|
|
12
15
|
# OR when published:
|
|
13
|
-
# gem 'prescient', '~> 0.
|
|
16
|
+
# gem 'prescient', '~> 0.3.0'
|
|
14
17
|
```
|
|
15
18
|
|
|
16
19
|
### 2. Replace Existing AI Service
|
|
@@ -30,7 +33,7 @@ class OllamaService
|
|
|
30
33
|
end
|
|
31
34
|
```
|
|
32
35
|
|
|
33
|
-
**After (Using
|
|
36
|
+
**After (Using Prescient):**
|
|
34
37
|
|
|
35
38
|
```ruby
|
|
36
39
|
# app/services/ai_service.rb
|
|
@@ -76,36 +79,36 @@ Prescient.configure do |config|
|
|
|
76
79
|
config.retry_delay = 1.0
|
|
77
80
|
|
|
78
81
|
# Ollama (Local/Development)
|
|
79
|
-
config.add_provider(:ollama, Prescient::Ollama
|
|
82
|
+
config.add_provider(:ollama, Prescient::Provider::Ollama,
|
|
80
83
|
url: ENV.fetch('OLLAMA_URL', 'http://localhost:11434'),
|
|
81
84
|
embedding_model: ENV.fetch('OLLAMA_EMBEDDING_MODEL', 'nomic-embed-text'),
|
|
82
|
-
chat_model: ENV.fetch('OLLAMA_CHAT_MODEL', 'llama3.
|
|
85
|
+
chat_model: ENV.fetch('OLLAMA_CHAT_MODEL', 'llama3.2:3b'),
|
|
83
86
|
timeout: 120
|
|
84
87
|
)
|
|
85
88
|
|
|
86
89
|
# OpenAI (Production)
|
|
87
90
|
if ENV['OPENAI_API_KEY'].present?
|
|
88
|
-
config.add_provider(:openai, Prescient::OpenAI
|
|
91
|
+
config.add_provider(:openai, Prescient::Provider::OpenAI,
|
|
89
92
|
api_key: ENV['OPENAI_API_KEY'],
|
|
90
93
|
embedding_model: ENV.fetch('OPENAI_EMBEDDING_MODEL', 'text-embedding-3-small'),
|
|
91
|
-
chat_model: ENV.fetch('OPENAI_CHAT_MODEL', 'gpt-
|
|
94
|
+
chat_model: ENV.fetch('OPENAI_CHAT_MODEL', 'gpt-4.1-mini')
|
|
92
95
|
)
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
# Anthropic (Alternative)
|
|
96
99
|
if ENV['ANTHROPIC_API_KEY'].present?
|
|
97
|
-
config.add_provider(:anthropic, Prescient::Anthropic
|
|
100
|
+
config.add_provider(:anthropic, Prescient::Provider::Anthropic,
|
|
98
101
|
api_key: ENV['ANTHROPIC_API_KEY'],
|
|
99
|
-
model: ENV.fetch('ANTHROPIC_MODEL', 'claude-
|
|
102
|
+
model: ENV.fetch('ANTHROPIC_MODEL', 'claude-sonnet-4-20250514')
|
|
100
103
|
)
|
|
101
104
|
end
|
|
102
105
|
|
|
103
106
|
# HuggingFace (Research/Open Source)
|
|
104
107
|
if ENV['HUGGINGFACE_API_KEY'].present?
|
|
105
|
-
config.add_provider(:huggingface, Prescient::HuggingFace
|
|
108
|
+
config.add_provider(:huggingface, Prescient::Provider::HuggingFace,
|
|
106
109
|
api_key: ENV['HUGGINGFACE_API_KEY'],
|
|
107
110
|
embedding_model: ENV.fetch('HUGGINGFACE_EMBEDDING_MODEL', 'sentence-transformers/all-MiniLM-L6-v2'),
|
|
108
|
-
chat_model: ENV.fetch('HUGGINGFACE_CHAT_MODEL', '
|
|
111
|
+
chat_model: ENV.fetch('HUGGINGFACE_CHAT_MODEL', 'google/gemma-2-2b-it')
|
|
109
112
|
)
|
|
110
113
|
end
|
|
111
114
|
end
|
|
@@ -122,21 +125,21 @@ Rails.application.config.default_ai_provider = :ollama
|
|
|
122
125
|
# Ollama (Local)
|
|
123
126
|
OLLAMA_URL=http://localhost:11434
|
|
124
127
|
OLLAMA_EMBEDDING_MODEL=nomic-embed-text
|
|
125
|
-
OLLAMA_CHAT_MODEL=llama3.
|
|
128
|
+
OLLAMA_CHAT_MODEL=llama3.2:3b
|
|
126
129
|
|
|
127
130
|
# OpenAI (Production)
|
|
128
131
|
OPENAI_API_KEY=your_openai_api_key
|
|
129
132
|
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
|
|
130
|
-
OPENAI_CHAT_MODEL=gpt-
|
|
133
|
+
OPENAI_CHAT_MODEL=gpt-4.1-mini
|
|
131
134
|
|
|
132
135
|
# Anthropic (Alternative)
|
|
133
136
|
ANTHROPIC_API_KEY=your_anthropic_api_key
|
|
134
|
-
ANTHROPIC_MODEL=claude-
|
|
137
|
+
ANTHROPIC_MODEL=claude-sonnet-4-20250514
|
|
135
138
|
|
|
136
139
|
# HuggingFace (Research)
|
|
137
140
|
HUGGINGFACE_API_KEY=your_huggingface_api_key
|
|
138
141
|
HUGGINGFACE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
|
|
139
|
-
HUGGINGFACE_CHAT_MODEL=
|
|
142
|
+
HUGGINGFACE_CHAT_MODEL=google/gemma-2-2b-it
|
|
140
143
|
```
|
|
141
144
|
|
|
142
145
|
### 5. Update Controllers
|
|
@@ -243,7 +246,7 @@ end
|
|
|
243
246
|
1. **Phase 1: Side-by-side deployment**
|
|
244
247
|
|
|
245
248
|
- Keep existing OllamaService
|
|
246
|
-
- Add
|
|
249
|
+
- Add Prescient alongside
|
|
247
250
|
- Test thoroughly in development
|
|
248
251
|
|
|
249
252
|
2. **Phase 2: Gradual migration**
|
|
@@ -260,11 +263,11 @@ end
|
|
|
260
263
|
### 8. Testing Updates
|
|
261
264
|
|
|
262
265
|
```ruby
|
|
263
|
-
#
|
|
264
|
-
|
|
265
|
-
|
|
266
|
+
# test/services/ai_service_test.rb
|
|
267
|
+
class AIServiceTest < ActiveSupport::TestCase
|
|
268
|
+
setup do
|
|
266
269
|
Prescient.configure do |config|
|
|
267
|
-
config.add_provider(:test, Prescient::Ollama
|
|
270
|
+
config.add_provider(:test, Prescient::Provider::Ollama,
|
|
268
271
|
url: 'http://localhost:11434',
|
|
269
272
|
embedding_model: 'test-embed',
|
|
270
273
|
chat_model: 'test-chat'
|
|
@@ -273,15 +276,10 @@ RSpec.describe AIService do
|
|
|
273
276
|
end
|
|
274
277
|
end
|
|
275
278
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
.to receive(:generate_embedding)
|
|
281
|
-
.and_return([0.1, 0.2, 0.3])
|
|
282
|
-
|
|
283
|
-
result = described_class.generate_embedding('test text')
|
|
284
|
-
expect(result).to eq([0.1, 0.2, 0.3])
|
|
279
|
+
test 'generate_embedding returns an embedding vector' do
|
|
280
|
+
Prescient.stub(:generate_embedding, [0.1, 0.2, 0.3]) do
|
|
281
|
+
result = Prescient.generate_embedding('test text', provider: :test, enable_fallback: false)
|
|
282
|
+
assert_equal [0.1, 0.2, 0.3], result
|
|
285
283
|
end
|
|
286
284
|
end
|
|
287
285
|
end
|
data/LICENSE.txt
CHANGED