prescient 0.0.0 → 0.1.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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prescient
4
- VERSION = "0.0.0"
4
+ VERSION = '0.1.0'
5
5
  end
data/lib/prescient.rb CHANGED
@@ -1,8 +1,90 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "prescient/version"
3
+ require_relative 'prescient/version'
4
4
 
5
5
  module Prescient
6
6
  class Error < StandardError; end
7
- # Your code goes here...
7
+ class ConnectionError < Error; end
8
+ class AuthenticationError < Error; end
9
+ class RateLimitError < Error; end
10
+ class ModelNotAvailableError < Error; end
11
+ class InvalidResponseError < Error; end
12
+
13
+ module Provider
14
+ # Module for AI provider implementations
15
+ end
16
+ end
17
+
18
+ require_relative 'prescient/base'
19
+ require_relative 'prescient/provider/ollama'
20
+ require_relative 'prescient/provider/anthropic'
21
+ require_relative 'prescient/provider/openai'
22
+ require_relative 'prescient/provider/huggingface'
23
+ require_relative 'prescient/client'
24
+
25
+ module Prescient
26
+ # Configure the gem
27
+ def self.configure
28
+ yield(configuration)
29
+ end
30
+
31
+ def self.configuration
32
+ @_configuration ||= Configuration.new
33
+ end
34
+
35
+ def self.reset_configuration!
36
+ @_configuration = Configuration.new
37
+ end
38
+
39
+ class Configuration
40
+ attr_accessor :default_provider
41
+ attr_accessor :timeout
42
+ attr_accessor :retry_attempts
43
+ attr_accessor :retry_delay
44
+ attr_reader :providers
45
+
46
+ def initialize
47
+ @default_provider = :ollama
48
+ @timeout = 30
49
+ @retry_attempts = 3
50
+ @retry_delay = 1.0
51
+ @providers = {}
52
+ end
53
+
54
+ def add_provider(name, provider_class, **options)
55
+ @providers[name.to_sym] = {
56
+ class: provider_class,
57
+ options: options,
58
+ }
59
+ end
60
+
61
+ def provider(name)
62
+ provider_config = @providers[name.to_sym]
63
+ return nil unless provider_config
64
+
65
+ provider_config[:class].new(**provider_config[:options])
66
+ end
67
+ end
68
+
69
+ # Default configuration
70
+ configure do |config|
71
+ config.add_provider(:ollama, Prescient::Provider::Ollama,
72
+ url: ENV.fetch('OLLAMA_URL', 'http://localhost:11434'),
73
+ embedding_model: ENV.fetch('OLLAMA_EMBEDDING_MODEL', 'nomic-embed-text'),
74
+ chat_model: ENV.fetch('OLLAMA_CHAT_MODEL', 'llama3.1:8b'))
75
+
76
+ config.add_provider(:anthropic, Prescient::Provider::Anthropic,
77
+ api_key: ENV.fetch('ANTHROPIC_API_KEY', nil),
78
+ model: ENV.fetch('ANTHROPIC_MODEL', 'claude-3-haiku-20240307'))
79
+
80
+ config.add_provider(:openai, Prescient::Provider::OpenAI,
81
+ api_key: ENV.fetch('OPENAI_API_KEY', nil),
82
+ embedding_model: ENV.fetch('OPENAI_EMBEDDING_MODEL', 'text-embedding-3-small'),
83
+ chat_model: ENV.fetch('OPENAI_CHAT_MODEL', 'gpt-3.5-turbo'))
84
+
85
+ config.add_provider(:huggingface, Prescient::Provider::HuggingFace,
86
+ api_key: ENV.fetch('HUGGINGFACE_API_KEY', nil),
87
+ embedding_model: ENV.fetch('HUGGINGFACE_EMBEDDING_MODEL', 'sentence-transformers/all-MiniLM-L6-v2'),
88
+ chat_model: ENV.fetch('HUGGINGFACE_CHAT_MODEL', 'microsoft/DialoGPT-medium'))
89
+ end
8
90
  end
data/prescient.gemspec ADDED
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/prescient/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "prescient"
7
+ spec.version = Prescient::VERSION
8
+ spec.authors = ["Ken C. Demanawa"]
9
+ spec.email = ["kenneth.c.demanawa@gmail.com"]
10
+
11
+ spec.summary = "Prescient AI provider abstraction for Ruby applications"
12
+ spec.description = "Prescient provides a unified interface for AI providers including local Ollama, Anthropic Claude, OpenAI GPT, and HuggingFace models. Built for AI applications with error handling, health monitoring, and provider switching."
13
+ spec.homepage = "https://github.com/yourcompany/prescient"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/yourcompany/prescient"
20
+ spec.metadata["changelog_uri"] = "https://github.com/yourcompany/prescient/blob/main/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) ||
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Runtime dependencies
34
+ spec.add_dependency "httparty", "~> 0.22.0"
35
+
36
+ # Optional dependencies for vector database integration
37
+ spec.add_development_dependency "pg", "~> 1.5" # PostgreSQL adapter for pgvector integration
38
+
39
+ # Development dependencies
40
+ spec.add_development_dependency "minitest", "~> 5.20"
41
+ spec.add_development_dependency "mocha", "~> 2.1"
42
+ spec.add_development_dependency "webmock", "~> 3.18"
43
+ spec.add_development_dependency "vcr", "~> 6.1"
44
+ spec.add_development_dependency "rubocop", "~> 1.50"
45
+ spec.add_development_dependency "rubocop-minitest", "~> 0.35"
46
+ spec.add_development_dependency "rubocop-performance", "~> 1.19"
47
+ spec.add_development_dependency "rubocop-rake", "~> 0.6"
48
+ spec.add_development_dependency "simplecov", "~> 0.22"
49
+ spec.add_development_dependency "rake", "~> 13.0"
50
+ spec.add_development_dependency "irb"
51
+ end
@@ -0,0 +1,77 @@
1
+ #!/bin/bash
2
+ # Setup script for pulling required Ollama models for Prescient gem
3
+
4
+ set -e
5
+
6
+ OLLAMA_URL=${OLLAMA_URL:-"http://localhost:11434"}
7
+ EMBEDDING_MODEL=${OLLAMA_EMBEDDING_MODEL:-"nomic-embed-text"}
8
+ CHAT_MODEL=${OLLAMA_CHAT_MODEL:-"llama3.1:8b"}
9
+
10
+ echo "🚀 Setting up Ollama models for Prescient gem..."
11
+ echo "Ollama URL: $OLLAMA_URL"
12
+
13
+ # Function to check if Ollama is ready
14
+ wait_for_ollama() {
15
+ echo "⏳ Waiting for Ollama to be ready..."
16
+ local max_attempts=30
17
+ local attempt=1
18
+
19
+ while [ $attempt -le $max_attempts ]; do
20
+ if curl -s "$OLLAMA_URL/api/tags" > /dev/null 2>&1; then
21
+ echo "✅ Ollama is ready!"
22
+ return 0
23
+ fi
24
+
25
+ echo "Attempt $attempt/$max_attempts - Ollama not ready yet..."
26
+ sleep 2
27
+ ((attempt++))
28
+ done
29
+
30
+ echo "❌ Ollama failed to start within expected time"
31
+ exit 1
32
+ }
33
+
34
+ # Function to pull a model
35
+ pull_model() {
36
+ local model_name=$1
37
+ echo "📦 Pulling model: $model_name"
38
+
39
+ if curl -s -X POST "$OLLAMA_URL/api/pull" \
40
+ -H "Content-Type: application/json" \
41
+ -d "{\"name\": \"$model_name\"}" | grep -q "success"; then
42
+ echo "✅ Successfully pulled $model_name"
43
+ else
44
+ echo "⚠️ Model pull initiated for $model_name (this may take a while)"
45
+ # Wait a bit and check if model appears in list
46
+ sleep 5
47
+ fi
48
+ }
49
+
50
+ # Function to list available models
51
+ list_models() {
52
+ echo "📋 Available models:"
53
+ curl -s "$OLLAMA_URL/api/tags" | jq -r '.models[]?.name // empty' 2>/dev/null || echo "Unable to list models"
54
+ }
55
+
56
+ # Main execution
57
+ main() {
58
+ wait_for_ollama
59
+
60
+ echo "🔧 Current models:"
61
+ list_models
62
+
63
+ echo "📥 Pulling required models..."
64
+ pull_model "$EMBEDDING_MODEL"
65
+ pull_model "$CHAT_MODEL"
66
+
67
+ echo "✨ Model setup complete!"
68
+ echo "📋 Final model list:"
69
+ list_models
70
+
71
+ echo ""
72
+ echo "🎉 Ollama is ready for use with Prescient gem!"
73
+ echo "💡 You can now run the examples with:"
74
+ echo " OLLAMA_URL=$OLLAMA_URL ruby examples/custom_contexts.rb"
75
+ }
76
+
77
+ main "$@"
metadata CHANGED
@@ -1,38 +1,242 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prescient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken C. Demanawa
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
12
- description: Unified interface for AI providers including Ollama (local), Anthropic
13
- Claude, OpenAI GPT, and HuggingFace models. Built for prescient applications that
14
- need AI predictions with provider switching, error handling, and fallback mechanisms.
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: httparty
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.22.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.22.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: pg
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.5'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.5'
40
+ - !ruby/object:Gem::Dependency
41
+ name: minitest
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.20'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.20'
54
+ - !ruby/object:Gem::Dependency
55
+ name: mocha
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.1'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.1'
68
+ - !ruby/object:Gem::Dependency
69
+ name: webmock
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.18'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.18'
82
+ - !ruby/object:Gem::Dependency
83
+ name: vcr
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '6.1'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '6.1'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rubocop
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.50'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.50'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rubocop-minitest
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.35'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.35'
124
+ - !ruby/object:Gem::Dependency
125
+ name: rubocop-performance
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.19'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '1.19'
138
+ - !ruby/object:Gem::Dependency
139
+ name: rubocop-rake
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '0.6'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '0.6'
152
+ - !ruby/object:Gem::Dependency
153
+ name: simplecov
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '0.22'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '0.22'
166
+ - !ruby/object:Gem::Dependency
167
+ name: rake
168
+ requirement: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '13.0'
173
+ type: :development
174
+ prerelease: false
175
+ version_requirements: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '13.0'
180
+ - !ruby/object:Gem::Dependency
181
+ name: irb
182
+ requirement: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ type: :development
188
+ prerelease: false
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ description: Prescient provides a unified interface for AI providers including local
195
+ Ollama, Anthropic Claude, OpenAI GPT, and HuggingFace models. Built for AI applications
196
+ with error handling, health monitoring, and provider switching.
15
197
  email:
16
198
  - kenneth.c.demanawa@gmail.com
17
199
  executables: []
18
200
  extensions: []
19
201
  extra_rdoc_files: []
20
202
  files:
21
- - ".vscode/settings.json"
203
+ - ".env.example"
204
+ - ".rubocop.yml"
22
205
  - CODE_OF_CONDUCT.md
206
+ - Dockerfile.example
23
207
  - LICENSE.txt
24
208
  - README.md
25
209
  - Rakefile
210
+ - VECTOR_SEARCH_GUIDE.md
211
+ - db/init/01_enable_pgvector.sql
212
+ - db/init/02_create_schema.sql
213
+ - db/init/03_create_indexes.sql
214
+ - db/init/04_insert_sample_data.sql
215
+ - db/migrate/001_create_prescient_tables.rb
216
+ - docker-compose.yml
217
+ - examples/basic_usage.rb
218
+ - examples/custom_contexts.rb
219
+ - examples/custom_prompts.rb
220
+ - examples/vector_search.rb
26
221
  - lib/prescient.rb
222
+ - lib/prescient/base.rb
223
+ - lib/prescient/client.rb
224
+ - lib/prescient/provider/anthropic.rb
225
+ - lib/prescient/provider/huggingface.rb
226
+ - lib/prescient/provider/ollama.rb
227
+ - lib/prescient/provider/openai.rb
27
228
  - lib/prescient/version.rb
229
+ - prescient.gemspec
230
+ - scripts/setup-ollama-models.sh
28
231
  - sig/prescient.rbs
29
- homepage: https://github.com/kanutocd/prescient
232
+ homepage: https://github.com/yourcompany/prescient
30
233
  licenses:
31
234
  - MIT
32
235
  metadata:
33
236
  allowed_push_host: https://rubygems.org
34
- homepage_uri: https://github.com/kanutocd/prescient
35
- source_code_uri: https://github.com/kanutocd/prescient
237
+ homepage_uri: https://github.com/yourcompany/prescient
238
+ source_code_uri: https://github.com/yourcompany/prescient
239
+ changelog_uri: https://github.com/yourcompany/prescient/blob/main/CHANGELOG.md
36
240
  rdoc_options: []
37
241
  require_paths:
38
242
  - lib
@@ -40,7 +244,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
244
  requirements:
41
245
  - - ">="
42
246
  - !ruby/object:Gem::Version
43
- version: 3.2.0
247
+ version: 3.0.0
44
248
  required_rubygems_version: !ruby/object:Gem::Requirement
45
249
  requirements:
46
250
  - - ">="
@@ -49,6 +253,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
253
  requirements: []
50
254
  rubygems_version: 3.6.9
51
255
  specification_version: 4
52
- summary: Unified interface for AI providers including Ollama (local), Anthropic Claude,
53
- OpenAI GPT, and HuggingFace models
256
+ summary: Prescient AI provider abstraction for Ruby applications
54
257
  test_files: []
@@ -1 +0,0 @@
1
- {}