ruby_llm-sequel 0.1.0 → 0.1.1
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/README.md +7 -1
- data/lib/ruby_llm/sequel/version.rb +1 -1
- data/lib/ruby_llm/sequel.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca798a25ce99f4041c275112f8b98547d41081c8aa3f6ba471a206ee9a3a5b95
|
|
4
|
+
data.tar.gz: 9527f83e686789683dfc650c9e5893983f76d636e06565065450d6c0879be556
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1fe594e587d11a662a64eef422eea7f7d636d478908dcbb74fc4e44c7d9b2c2467c851d9f0c7480621b67499a071abae6e4328d343fe4ac24ca1187af2109766
|
|
7
|
+
data.tar.gz: f442118b9e1e524fbdc646b3deb6af963aaa8f687a7eae4a03a5d48c07992c0ce902c646e6c9cbe92fa5a58ab20e034f14297b16e7b1515b8aaf5490050bd759
|
data/README.md
CHANGED
|
@@ -137,8 +137,14 @@ end
|
|
|
137
137
|
# Configure RubyLLM
|
|
138
138
|
RubyLLM.configure do |config|
|
|
139
139
|
config.openai_api_key = ENV['OPENAI_API_KEY']
|
|
140
|
+
|
|
141
|
+
# For custom Model class names (defaults to 'Model')
|
|
142
|
+
# config.model_registry_class = 'AIModel'
|
|
140
143
|
end
|
|
141
144
|
|
|
145
|
+
# Opt-in behaviour to use models registry from database
|
|
146
|
+
RubyLLM.Sequel.use_model_registry!
|
|
147
|
+
|
|
142
148
|
# Create a chat
|
|
143
149
|
chat = Chat.create
|
|
144
150
|
|
|
@@ -246,7 +252,7 @@ ruby -Ilib:spec spec/ruby_llm/sequel/chat_methods_spec.rb
|
|
|
246
252
|
The tests use:
|
|
247
253
|
- **Minitest** for the test framework
|
|
248
254
|
- **SQLite** in-memory database for fast test execution
|
|
249
|
-
- **
|
|
255
|
+
- **SimpleCov** for code coverage reporting
|
|
250
256
|
- **Transaction rollback** to isolate tests and maintain a clean database state
|
|
251
257
|
|
|
252
258
|
All test configuration is in `spec/spec_helper.rb`.
|
data/lib/ruby_llm/sequel.rb
CHANGED
|
@@ -15,5 +15,29 @@ require_relative '../sequel/plugins/ruby_llm'
|
|
|
15
15
|
module RubyLLM
|
|
16
16
|
module Sequel
|
|
17
17
|
class UnsupportedFeatureError < StandardError; end
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
def use_model_registry!
|
|
21
|
+
# Monkey-patch Models to use database
|
|
22
|
+
RubyLLM::Models.class_eval do
|
|
23
|
+
def self.load_models
|
|
24
|
+
read_from_database
|
|
25
|
+
rescue StandardError => e
|
|
26
|
+
RubyLLM.logger.debug "Failed to load models from database: #{e.message}, falling back to JSON"
|
|
27
|
+
read_from_json
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.read_from_database
|
|
31
|
+
model_class = RubyLLM.config.model_registry_class
|
|
32
|
+
model_class = model_class.constantize if model_class.is_a?(String)
|
|
33
|
+
model_class.all.map(&:to_llm)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def load_from_database!
|
|
37
|
+
@models = self.class.read_from_database
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
18
42
|
end
|
|
19
43
|
end
|