Module: RubyLLM::Registry
- Defined in:
- lib/ruby_llm/registry.rb,
lib/ruby_llm/registry/errors.rb,
lib/ruby_llm/registry/prompt.rb,
lib/ruby_llm/registry/semver.rb,
lib/ruby_llm/registry/context.rb,
lib/ruby_llm/registry/version.rb,
lib/ruby_llm/registry/adapters.rb,
lib/ruby_llm/registry/exporter.rb,
lib/ruby_llm/registry/importer.rb,
lib/ruby_llm/registry/comparison.rb,
lib/ruby_llm/registry/adapters/s3.rb,
lib/ruby_llm/registry/front_matter.rb,
lib/ruby_llm/registry/adapters/base.rb,
lib/ruby_llm/registry/adapters/mongo.rb,
lib/ruby_llm/registry/adapters/sqlite.rb,
lib/ruby_llm/registry/filesystem_backend.rb,
lib/ruby_llm/registry/adapters/active_record.rb
Defined Under Namespace
Modules: Adapters, FrontMatter
Classes: Comparison, Configuration, DiffLines, Error, Exporter, FilesystemBackend, Importer, InvalidVersionError, MissingVariableError, Prompt, PromptNotFoundError, RenderContext, UnknownLabelError, Version
Constant Summary
collapse
- VERSION =
"0.1.2"
Class Method Summary
collapse
-
.backend(type = nil, **options) ⇒ Object
-
.configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
-
.database_backend(type = nil, **options) ⇒ Object
-
.default_root ⇒ Object
-
.diff(left, right) ⇒ Object
-
.export(prompt_or_path, format: :markdown, backend: nil, version: nil, label: nil, **options) ⇒ Object
-
.get(path, version: nil, label: nil, root: nil, manifest_path: nil) ⇒ Object
-
.import(payload, format: :auto, backend: nil, **options) ⇒ Object
-
.reset! ⇒ Object
Class Method Details
.backend(type = nil, **options) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/ruby_llm/registry.rb', line 45
def backend(type = nil, **options)
type = (type || configuration.default_adapter).to_sym
case type
when :filesystem
FilesystemBackend.new(
root: options[:root] || configuration.root || default_root,
manifest_path: options[:manifest_path] || configuration.manifest_path
)
when :sqlite, :active_record, :ar, :mongo, :mongodb, :s3
Adapters.build(type, **options)
else
raise ArgumentError, "Unknown backend type: #{type.inspect}"
end
end
|
.configuration ⇒ Object
29
30
31
|
# File 'lib/ruby_llm/registry.rb', line 29
def configuration
@configuration ||= Configuration.new
end
|
33
34
35
|
# File 'lib/ruby_llm/registry.rb', line 33
def configure
yield(configuration)
end
|
.database_backend(type = nil, **options) ⇒ Object
61
62
63
|
# File 'lib/ruby_llm/registry.rb', line 61
def database_backend(type = nil, **options)
backend(type || configuration.default_database_adapter, **options)
end
|
.default_root ⇒ Object
88
89
90
91
|
# File 'lib/ruby_llm/registry.rb', line 88
def default_root
local_candidates = %w[prompts app/prompts].map { |relative| File.join(Dir.pwd, relative) }
local_candidates.find { |candidate| Dir.exist?(candidate) } || File.join(Dir.pwd, "prompts")
end
|
.diff(left, right) ⇒ Object
82
83
84
85
86
|
# File 'lib/ruby_llm/registry.rb', line 82
def diff(left, right)
left_prompt = left.respond_to?(:body) ? left : Importer.new(left, format: :auto).to_prompt
right_prompt = right.respond_to?(:body) ? right : Importer.new(right, format: :auto).to_prompt
Comparison.new(left_prompt, right_prompt)
end
|
.export(prompt_or_path, format: :markdown, backend: nil, version: nil, label: nil, **options) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/ruby_llm/registry.rb', line 65
def export(prompt_or_path, format: :markdown, backend: nil, version: nil, label: nil, **options)
prompt = if prompt_or_path.is_a?(Prompt)
prompt_or_path
elsif backend
backend.get(prompt_or_path, version: version, label: label)
else
get(prompt_or_path, version: version, label: label, **options)
end
Exporter.new(prompt).public_send(exporter_method(format))
end
|
.get(path, version: nil, label: nil, root: nil, manifest_path: nil) ⇒ Object
41
42
43
|
# File 'lib/ruby_llm/registry.rb', line 41
def get(path, version: nil, label: nil, root: nil, manifest_path: nil)
backend(root: root, manifest_path: manifest_path).get(path, version: version, label: label)
end
|
.import(payload, format: :auto, backend: nil, **options) ⇒ Object
76
77
78
79
80
|
# File 'lib/ruby_llm/registry.rb', line 76
def import(payload, format: :auto, backend: nil, **options)
prompt = Importer.new(payload, format: format, **options).to_prompt
backend&.store(prompt)
prompt
end
|
.reset! ⇒ Object
37
38
39
|
# File 'lib/ruby_llm/registry.rb', line 37
def reset!
@configuration = nil
end
|