prescient 0.0.0 → 0.2.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/.env.example +37 -0
- data/.rubocop.yml +330 -0
- data/.yardopts +14 -0
- data/CHANGELOG.md +64 -0
- data/CHANGELOG.pdf +0 -0
- data/Dockerfile.example +41 -0
- data/INTEGRATION_GUIDE.md +363 -0
- data/README.md +917 -13
- data/Rakefile +26 -3
- data/VECTOR_SEARCH_GUIDE.md +453 -0
- data/db/init/01_enable_pgvector.sql +30 -0
- data/db/init/02_create_schema.sql +108 -0
- data/db/init/03_create_indexes.sql +96 -0
- data/db/init/04_insert_sample_data.sql +121 -0
- data/db/migrate/001_create_prescient_tables.rb +158 -0
- data/docker-compose.yml +153 -0
- data/examples/basic_usage.rb +123 -0
- data/examples/custom_contexts.rb +355 -0
- data/examples/custom_prompts.rb +212 -0
- data/examples/vector_search.rb +330 -0
- data/lib/prescient/base.rb +374 -0
- data/lib/prescient/client.rb +211 -0
- data/lib/prescient/provider/anthropic.rb +146 -0
- data/lib/prescient/provider/huggingface.rb +200 -0
- data/lib/prescient/provider/ollama.rb +172 -0
- data/lib/prescient/provider/openai.rb +181 -0
- data/lib/prescient/version.rb +1 -1
- data/lib/prescient.rb +186 -2
- data/prescient.gemspec +53 -0
- data/scripts/setup-ollama-models.sh +77 -0
- metadata +252 -14
- data/.vscode/settings.json +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2b41fc6acb2528a3d74e5bbc58f777a34ead604d3f7bc4e58cc1ff4f8709142
|
4
|
+
data.tar.gz: 665efb1e4b6cc1ed526e91470e7c06278461e98e9d81f0ace34b0872c456251f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23eeca8c5353bcb4219a634905a7f6dc565acbfde665e0e71a0682eb3277abb9384882f70afe168ee27c435f049048f0a715b92daac3fcdc8f34f4ff2b4f7de0
|
7
|
+
data.tar.gz: 77eccf05a9bedfad68de0a262b4ebf32d35b1c1a6d4c35f0327c1c6d16814841a6361b5123b27a8ba6f05e9d999256e2b330200d3e4c7eda0763010c98759c44
|
data/.env.example
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Example environment configuration for Prescient gem
|
2
|
+
# Copy this file to .env and configure your API keys
|
3
|
+
|
4
|
+
# Ollama Configuration (Local AI)
|
5
|
+
OLLAMA_URL=http://localhost:11434
|
6
|
+
OLLAMA_EMBEDDING_MODEL=nomic-embed-text
|
7
|
+
OLLAMA_CHAT_MODEL=llama3.1:8b
|
8
|
+
|
9
|
+
# OpenAI Configuration
|
10
|
+
OPENAI_API_KEY=your_openai_api_key_here
|
11
|
+
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
|
12
|
+
OPENAI_CHAT_MODEL=gpt-3.5-turbo
|
13
|
+
|
14
|
+
# Anthropic Configuration
|
15
|
+
ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
16
|
+
ANTHROPIC_MODEL=claude-3-haiku-20240307
|
17
|
+
|
18
|
+
# HuggingFace Configuration
|
19
|
+
HUGGINGFACE_API_KEY=your_huggingface_api_key_here
|
20
|
+
HUGGINGFACE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
|
21
|
+
HUGGINGFACE_CHAT_MODEL=microsoft/DialoGPT-medium
|
22
|
+
|
23
|
+
# PostgreSQL with pgvector Configuration
|
24
|
+
DB_HOST=localhost
|
25
|
+
DB_PORT=5432
|
26
|
+
DB_NAME=prescient_development
|
27
|
+
DB_USER=prescient
|
28
|
+
DB_PASSWORD=prescient_password
|
29
|
+
|
30
|
+
# Optional: Redis for caching (if using with Docker)
|
31
|
+
REDIS_URL=redis://localhost:6379/0
|
32
|
+
|
33
|
+
# Application Configuration
|
34
|
+
PRESCIENT_DEFAULT_PROVIDER=ollama
|
35
|
+
PRESCIENT_TIMEOUT=60
|
36
|
+
PRESCIENT_RETRY_ATTEMPTS=3
|
37
|
+
PRESCIENT_RETRY_DELAY=1.0
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,330 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# RuboCop configuration for Prescient gem
|
4
|
+
# Modern Ruby best practices with sensible defaults
|
5
|
+
|
6
|
+
plugins:
|
7
|
+
- rubocop-minitest
|
8
|
+
- rubocop-performance
|
9
|
+
- rubocop-rake
|
10
|
+
|
11
|
+
AllCops:
|
12
|
+
# Target Ruby 3.1+ (matches gemspec requirement)
|
13
|
+
TargetRubyVersion: 3.1
|
14
|
+
|
15
|
+
# Use new cops by default
|
16
|
+
NewCops: enable
|
17
|
+
|
18
|
+
# Exclude common directories
|
19
|
+
Exclude:
|
20
|
+
- 'vendor/**/*'
|
21
|
+
- 'bin/*'
|
22
|
+
- 'tmp/**/*'
|
23
|
+
- 'coverage/**/*'
|
24
|
+
- 'pkg/**/*'
|
25
|
+
- '*.gemspec'
|
26
|
+
- 'Gemfile'
|
27
|
+
- 'Rakefile'
|
28
|
+
- 'examples/**/*'
|
29
|
+
|
30
|
+
# === LAYOUT & FORMATTING ===
|
31
|
+
|
32
|
+
Layout/LineLength:
|
33
|
+
Max: 120
|
34
|
+
Exclude:
|
35
|
+
- 'test/**/*'
|
36
|
+
- 'lib/prescient.rb' # Configuration can have long lines
|
37
|
+
AllowedPatterns:
|
38
|
+
- '^\s*#' # Comments
|
39
|
+
- '^\s*it\s' # Test descriptions
|
40
|
+
- '^\s*context\s' # Test contexts
|
41
|
+
- '^\s*describe\s' # Test descriptions
|
42
|
+
|
43
|
+
Layout/MultilineMethodCallIndentation:
|
44
|
+
EnforcedStyle: indented
|
45
|
+
|
46
|
+
Layout/FirstHashElementIndentation:
|
47
|
+
EnforcedStyle: consistent
|
48
|
+
|
49
|
+
Layout/FirstArrayElementIndentation:
|
50
|
+
EnforcedStyle: consistent
|
51
|
+
|
52
|
+
Layout/HashAlignment:
|
53
|
+
EnforcedHashRocketStyle: table
|
54
|
+
EnforcedColonStyle: table
|
55
|
+
|
56
|
+
Layout/SpaceInsideHashLiteralBraces:
|
57
|
+
EnforcedStyle: space
|
58
|
+
|
59
|
+
Layout/EmptyLinesAroundModuleBody:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Layout/EmptyLinesAroundClassBody:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
# === STYLE ===
|
66
|
+
|
67
|
+
Style/StringLiterals:
|
68
|
+
EnforcedStyle: single_quotes
|
69
|
+
|
70
|
+
Style/StringLiteralsInInterpolation:
|
71
|
+
EnforcedStyle: single_quotes
|
72
|
+
|
73
|
+
Style/FrozenStringLiteralComment:
|
74
|
+
Enabled: true
|
75
|
+
EnforcedStyle: always
|
76
|
+
Exclude:
|
77
|
+
- 'examples/**/*'
|
78
|
+
|
79
|
+
Style/Documentation:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
Style/ClassAndModuleChildren:
|
83
|
+
EnforcedStyle: compact
|
84
|
+
|
85
|
+
Style/TrailingCommaInArguments:
|
86
|
+
EnforcedStyleForMultiline: comma
|
87
|
+
|
88
|
+
Style/TrailingCommaInArrayLiteral:
|
89
|
+
EnforcedStyleForMultiline: comma
|
90
|
+
|
91
|
+
Style/TrailingCommaInHashLiteral:
|
92
|
+
EnforcedStyleForMultiline: comma
|
93
|
+
|
94
|
+
Style/HashSyntax:
|
95
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
96
|
+
|
97
|
+
Style/Lambda:
|
98
|
+
EnforcedStyle: literal
|
99
|
+
|
100
|
+
Style/NumericLiterals:
|
101
|
+
MinDigits: 6
|
102
|
+
|
103
|
+
Style/BlockDelimiters:
|
104
|
+
EnforcedStyle: semantic
|
105
|
+
AllowedMethods:
|
106
|
+
- expect
|
107
|
+
- let
|
108
|
+
- subject
|
109
|
+
|
110
|
+
Style/WordArray:
|
111
|
+
EnforcedStyle: brackets
|
112
|
+
|
113
|
+
Style/SymbolArray:
|
114
|
+
EnforcedStyle: brackets
|
115
|
+
|
116
|
+
Style/FormatString:
|
117
|
+
EnforcedStyle: percent
|
118
|
+
|
119
|
+
Style/CollectionMethods:
|
120
|
+
PreferredMethods:
|
121
|
+
collect: map
|
122
|
+
collect!: map!
|
123
|
+
detect: find
|
124
|
+
find_all: select
|
125
|
+
reduce: inject
|
126
|
+
|
127
|
+
Style/Alias:
|
128
|
+
EnforcedStyle: prefer_alias_method
|
129
|
+
|
130
|
+
Style/AccessorGrouping:
|
131
|
+
EnforcedStyle: separated
|
132
|
+
|
133
|
+
Style/BisectedAttrAccessor:
|
134
|
+
Enabled: true
|
135
|
+
|
136
|
+
Style/RedundantAssignment:
|
137
|
+
Enabled: true
|
138
|
+
|
139
|
+
Style/RedundantFetchBlock:
|
140
|
+
Enabled: true
|
141
|
+
|
142
|
+
Style/RedundantFileExtensionInRequire:
|
143
|
+
Enabled: true
|
144
|
+
|
145
|
+
Style/RedundantRegexpCharacterClass:
|
146
|
+
Enabled: true
|
147
|
+
|
148
|
+
Style/RedundantRegexpEscape:
|
149
|
+
Enabled: true
|
150
|
+
|
151
|
+
Style/SlicingWithRange:
|
152
|
+
Enabled: true
|
153
|
+
|
154
|
+
Style/ExponentialNotation:
|
155
|
+
Enabled: true
|
156
|
+
|
157
|
+
Style/HashTransformKeys:
|
158
|
+
Enabled: true
|
159
|
+
|
160
|
+
Style/HashTransformValues:
|
161
|
+
Enabled: true
|
162
|
+
|
163
|
+
Style/RedundantReturn:
|
164
|
+
AllowMultipleReturnValues: true
|
165
|
+
|
166
|
+
# === METRICS ===
|
167
|
+
|
168
|
+
Metrics/ModuleLength:
|
169
|
+
Max: 150
|
170
|
+
|
171
|
+
Metrics/ClassLength:
|
172
|
+
Enabled: false
|
173
|
+
Max: 150
|
174
|
+
Exclude:
|
175
|
+
- 'test/**/*'
|
176
|
+
|
177
|
+
Metrics/MethodLength:
|
178
|
+
Enabled: false
|
179
|
+
Max: 25
|
180
|
+
Exclude:
|
181
|
+
- 'test/**/*'
|
182
|
+
- 'db/**/*'
|
183
|
+
- 'lib/prescient/provider/*.rb'
|
184
|
+
|
185
|
+
Metrics/BlockLength:
|
186
|
+
Enabled: false
|
187
|
+
Max: 25
|
188
|
+
Exclude:
|
189
|
+
- 'test/**/*'
|
190
|
+
- 'lib/prescient.rb' # Configuration block
|
191
|
+
|
192
|
+
Metrics/AbcSize:
|
193
|
+
Max: 20
|
194
|
+
Exclude:
|
195
|
+
- 'test/**/*'
|
196
|
+
- 'db/**/*'
|
197
|
+
- 'lib/prescient/provider/*.rb'
|
198
|
+
|
199
|
+
Metrics/CyclomaticComplexity:
|
200
|
+
Max: 8
|
201
|
+
Exclude:
|
202
|
+
- 'lib/prescient/provider/*.rb'
|
203
|
+
|
204
|
+
Metrics/PerceivedComplexity:
|
205
|
+
Enabled: false
|
206
|
+
Max: 8
|
207
|
+
Exclude:
|
208
|
+
- 'lib/prescient/provider/*.rb'
|
209
|
+
|
210
|
+
Metrics/ParameterLists:
|
211
|
+
Max: 5
|
212
|
+
CountKeywordArgs: false
|
213
|
+
|
214
|
+
# === LINT ===
|
215
|
+
|
216
|
+
Lint/RaiseException:
|
217
|
+
Enabled: true
|
218
|
+
|
219
|
+
Lint/StructNewOverride:
|
220
|
+
Enabled: true
|
221
|
+
|
222
|
+
Lint/DeprecatedOpenSSLConstant:
|
223
|
+
Enabled: true
|
224
|
+
|
225
|
+
Lint/MixedRegexpCaptureTypes:
|
226
|
+
Enabled: true
|
227
|
+
|
228
|
+
Lint/DuplicateElsifCondition:
|
229
|
+
Enabled: true
|
230
|
+
|
231
|
+
Lint/BinaryOperatorWithIdenticalOperands:
|
232
|
+
Enabled: true
|
233
|
+
|
234
|
+
Lint/DuplicateRescueException:
|
235
|
+
Enabled: true
|
236
|
+
|
237
|
+
Lint/EmptyConditionalBody:
|
238
|
+
Enabled: true
|
239
|
+
|
240
|
+
Lint/FloatComparison:
|
241
|
+
Enabled: true
|
242
|
+
|
243
|
+
Lint/MissingSuper:
|
244
|
+
Enabled: true
|
245
|
+
|
246
|
+
Lint/OutOfRangeRegexpRef:
|
247
|
+
Enabled: true
|
248
|
+
|
249
|
+
Lint/SelfAssignment:
|
250
|
+
Enabled: true
|
251
|
+
|
252
|
+
Lint/TopLevelReturnWithArgument:
|
253
|
+
Enabled: true
|
254
|
+
|
255
|
+
Lint/UnreachableLoop:
|
256
|
+
Enabled: true
|
257
|
+
|
258
|
+
# === NAMING ===
|
259
|
+
|
260
|
+
Naming/PredicatePrefix:
|
261
|
+
ForbiddenPrefixes:
|
262
|
+
- is_
|
263
|
+
AllowedMethods:
|
264
|
+
- is_a?
|
265
|
+
|
266
|
+
Naming/MemoizedInstanceVariableName:
|
267
|
+
EnforcedStyleForLeadingUnderscores: required
|
268
|
+
|
269
|
+
Naming/VariableNumber:
|
270
|
+
EnforcedStyle: snake_case
|
271
|
+
|
272
|
+
# === SECURITY ===
|
273
|
+
|
274
|
+
Security/Open:
|
275
|
+
Enabled: true
|
276
|
+
|
277
|
+
Security/YAMLLoad:
|
278
|
+
Enabled: true
|
279
|
+
|
280
|
+
Security/JSONLoad:
|
281
|
+
Enabled: true
|
282
|
+
|
283
|
+
# === PERFORMANCE ===
|
284
|
+
|
285
|
+
Performance/AncestorsInclude:
|
286
|
+
Enabled: true
|
287
|
+
|
288
|
+
Performance/BigDecimalWithNumericArgument:
|
289
|
+
Enabled: true
|
290
|
+
|
291
|
+
Performance/RedundantSortBlock:
|
292
|
+
Enabled: true
|
293
|
+
|
294
|
+
Performance/RedundantStringChars:
|
295
|
+
Enabled: true
|
296
|
+
|
297
|
+
Performance/ReverseFirst:
|
298
|
+
Enabled: true
|
299
|
+
|
300
|
+
Performance/SortReverse:
|
301
|
+
Enabled: true
|
302
|
+
|
303
|
+
Performance/Squeeze:
|
304
|
+
Enabled: true
|
305
|
+
|
306
|
+
Performance/StringInclude:
|
307
|
+
Enabled: true
|
308
|
+
|
309
|
+
Performance/Sum:
|
310
|
+
Enabled: true
|
311
|
+
|
312
|
+
# === MINITEST ===
|
313
|
+
|
314
|
+
Minitest/MultipleAssertions:
|
315
|
+
Max: 10
|
316
|
+
|
317
|
+
Minitest/AssertTruthy:
|
318
|
+
Enabled: true
|
319
|
+
|
320
|
+
Minitest/AssertWithExpectedArgument:
|
321
|
+
Enabled: true
|
322
|
+
|
323
|
+
Minitest/RefuteFalse:
|
324
|
+
Enabled: true
|
325
|
+
|
326
|
+
Minitest/RefuteNil:
|
327
|
+
Enabled: true
|
328
|
+
|
329
|
+
Minitest/TestMethodName:
|
330
|
+
Enabled: true
|
data/.yardopts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
--markup markdown
|
2
|
+
--markup-provider kramdown
|
3
|
+
--main README.md
|
4
|
+
--output-dir doc
|
5
|
+
--protected
|
6
|
+
--private
|
7
|
+
--title "Prescient Documentation"
|
8
|
+
lib/**/*.rb
|
9
|
+
-
|
10
|
+
README.md
|
11
|
+
CHANGELOG.md
|
12
|
+
LICENSE.txt
|
13
|
+
INTEGRATION_GUIDE.md
|
14
|
+
VECTOR_SEARCH_GUIDE.md
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
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).
|
7
|
+
|
8
|
+
## [0.1.0] - 2025-08-05
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Added new featire: Providers fallbacks mechanism
|
13
|
+
|
14
|
+
## [0.1.0] - 2025-08-05
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Initial release of Prescient gem
|
19
|
+
- Support for four AI providers:
|
20
|
+
- **Ollama**: Local AI provider with embedding and text generation
|
21
|
+
- **Anthropic**: Claude models for text generation
|
22
|
+
- **OpenAI**: GPT models and embeddings
|
23
|
+
- **HuggingFace**: Open-source models and embeddings
|
24
|
+
- Unified client interface for all providers
|
25
|
+
- Comprehensive error handling with provider-specific exceptions:
|
26
|
+
- `ConnectionError` for network issues
|
27
|
+
- `AuthenticationError` for API key problems
|
28
|
+
- `RateLimitError` for rate limiting
|
29
|
+
- `ModelNotAvailableError` for missing models
|
30
|
+
- `InvalidResponseError` for malformed responses
|
31
|
+
- Automatic retry logic with configurable attempts and delays
|
32
|
+
- Health monitoring capabilities for all providers
|
33
|
+
- Environment variable configuration support
|
34
|
+
- Programmatic configuration system
|
35
|
+
- Context-aware generation support with context items
|
36
|
+
- Text preprocessing and embedding normalization
|
37
|
+
- Provider availability checking
|
38
|
+
- Model listing capabilities (where supported)
|
39
|
+
- Comprehensive test suite with RSpec
|
40
|
+
- Documentation and usage examples
|
41
|
+
|
42
|
+
### Provider-Specific Features
|
43
|
+
|
44
|
+
- **Ollama**: Model management (pull, list), local deployment
|
45
|
+
- **Anthropic**: Latest Claude 3 models (Haiku, Sonnet, Opus)
|
46
|
+
- **OpenAI**: Multiple embedding dimensions, latest GPT models
|
47
|
+
- **HuggingFace**: Open-source model support, research-friendly API
|
48
|
+
|
49
|
+
### Development
|
50
|
+
|
51
|
+
- RSpec test suite with WebMock and VCR
|
52
|
+
- RuboCop code style enforcement
|
53
|
+
- SimpleCov test coverage reporting
|
54
|
+
- Comprehensive documentation
|
55
|
+
- Example usage scripts
|
56
|
+
- Rake tasks for testing and linting
|
57
|
+
|
58
|
+
## [0.0.0] - 2025-08-05
|
59
|
+
|
60
|
+
### Added
|
61
|
+
|
62
|
+
- Project initialization
|
63
|
+
- Basic gem structure
|
64
|
+
- Core interfaces defined
|
data/CHANGELOG.pdf
ADDED
Binary file
|
data/Dockerfile.example
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Example Dockerfile for running Prescient gem applications
|
2
|
+
FROM ruby:3.4-alpine
|
3
|
+
|
4
|
+
# Install system dependencies
|
5
|
+
RUN apk add --no-cache \
|
6
|
+
build-base \
|
7
|
+
curl \
|
8
|
+
git \
|
9
|
+
postgresql-dev \
|
10
|
+
tzdata
|
11
|
+
|
12
|
+
# Set working directory
|
13
|
+
WORKDIR /app
|
14
|
+
|
15
|
+
# Create non-root user
|
16
|
+
RUN addgroup -g 1000 -S appuser && \
|
17
|
+
adduser -u 1000 -S appuser -G appuser
|
18
|
+
|
19
|
+
# Copy Gemfile and Gemfile.lock
|
20
|
+
COPY Gemfile* ./
|
21
|
+
COPY prescient.gemspec ./
|
22
|
+
COPY lib/prescient/version.rb ./lib/prescient/
|
23
|
+
|
24
|
+
# Install gems
|
25
|
+
RUN bundle config --global frozen 1 && \
|
26
|
+
bundle install --jobs 4 --retry 3
|
27
|
+
|
28
|
+
# Copy application code
|
29
|
+
COPY . .
|
30
|
+
|
31
|
+
# Change ownership to appuser
|
32
|
+
RUN chown -R appuser:appuser /app
|
33
|
+
|
34
|
+
# Switch to non-root user
|
35
|
+
USER appuser
|
36
|
+
|
37
|
+
# Expose port (if running a web service)
|
38
|
+
EXPOSE 3000
|
39
|
+
|
40
|
+
# Default command
|
41
|
+
CMD ["bundle", "exec", "ruby", "examples/custom_contexts.rb"]
|