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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2b41fc6acb2528a3d74e5bbc58f777a34ead604d3f7bc4e58cc1ff4f8709142
4
- data.tar.gz: 665efb1e4b6cc1ed526e91470e7c06278461e98e9d81f0ace34b0872c456251f
3
+ metadata.gz: a54256e23ba55fc2492fae38d687b275dcb2362df73449d3212bd03659150717
4
+ data.tar.gz: 73ab805b7a5781a1d03488605ae8d7890feda7344b41b1ac550343484b3b597a
5
5
  SHA512:
6
- metadata.gz: 23eeca8c5353bcb4219a634905a7f6dc565acbfde665e0e71a0682eb3277abb9384882f70afe168ee27c435f049048f0a715b92daac3fcdc8f34f4ff2b4f7de0
7
- data.tar.gz: 77eccf05a9bedfad68de0a262b4ebf32d35b1c1a6d4c35f0327c1c6d16814841a6361b5123b27a8ba6f05e9d999256e2b330200d3e4c7eda0763010c98759c44
6
+ metadata.gz: e918a87b3e09affe9d5a002a3955051e7729ee565f84c42c534c99dc3fc70371fda930e63cc90801da07b4c4f5e48031c41e952088dfc3de24f0f38b579e9567
7
+ data.tar.gz: feb707947b7cc0b67d8bff933b4c584a69595b9b5e1dd3f214b4c4aa2d48c0577c996b542c238fbcef337f0f276a1bb995acc9653e8fad32262a6f6fa17caaf4
data/.rubocop.yml CHANGED
@@ -11,10 +11,8 @@ plugins:
11
11
  AllCops:
12
12
  # Target Ruby 3.1+ (matches gemspec requirement)
13
13
  TargetRubyVersion: 3.1
14
-
15
14
  # Use new cops by default
16
15
  NewCops: enable
17
-
18
16
  # Exclude common directories
19
17
  Exclude:
20
18
  - 'vendor/**/*'
data/.yardopts CHANGED
@@ -1,10 +1,7 @@
1
- --markup markdown
2
- --markup-provider kramdown
3
- --main README.md
4
- --output-dir doc
1
+ --title "Prescient API Documentation"
5
2
  --protected
6
- --private
7
- --title "Prescient Documentation"
3
+ --markup markdown
4
+
8
5
  lib/**/*.rb
9
6
  -
10
7
  README.md
data/CHANGELOG.md CHANGED
@@ -1,11 +1,48 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to this project will be documented in this file.
3
+ ## Unreleased
4
4
 
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
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
- ## [0.1.0] - 2025-08-05
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 AI Providers gem into your existing Rails AI application.
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.1.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 AI Providers Gem):**
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::Provider,
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.1:8b'),
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::Provider,
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-3.5-turbo')
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::Provider,
100
+ config.add_provider(:anthropic, Prescient::Provider::Anthropic,
98
101
  api_key: ENV['ANTHROPIC_API_KEY'],
99
- model: ENV.fetch('ANTHROPIC_MODEL', 'claude-3-haiku-20240307')
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::Provider,
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', 'microsoft/DialoGPT-medium')
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.1:8b
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-3.5-turbo
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-3-haiku-20240307
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=microsoft/DialoGPT-medium
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 AI Providers gem alongside
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
- # spec/services/ai_service_spec.rb
264
- RSpec.describe AIService do
265
- before do
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::Provider,
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
- describe '.generate_embedding' do
277
- it 'returns embedding vector' do
278
- # Mock the provider response
279
- allow_any_instance_of(Prescient::Ollama::Provider)
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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2025 Ken C. Demanawa
3
+ Copyright (c) 2025 Kenneth C. Demanawa
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal