Module: LLM::Sequel::Plugin
- Defined in:
- lib/llm/sequel/plugin.rb
Overview
Sequel plugin for persisting LLM::Context state.
This plugin maps model columns onto provider selection, model selection, usage accounting, and serialized context data while leaving application-specific concerns such as credentials, associations, and UI shaping to the host app.
Context state can be stored as a JSON string (format:
:string, the default) or as a structured object (format:
:json / :jsonb) for databases such as PostgreSQL
that can persist JSON natively. :json and
:jsonb expect a real JSON column type with Sequel
handling JSON typecasting for the model. provider:,
context:, and tracer: can also be
configured as symbols that are called on the model.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, Utils
Constant Summary collapse
- EMPTY_HASH =
-
{}.freeze
- DEFAULTS =
-
{ data_column: :data, format: :string, tracer: nil, provider: nil, context: EMPTY_HASH }.freeze
Class Method Summary collapse
-
.apply(model) ⇒
void
Called by Sequel when the plugin is first applied to a model class.
-
.configure(model,
options = EMPTY_HASH) ⇒ void
Called by Sequel after Plugin.apply with the options passed to
plugin :llm, ....
Class Method Details
.apply(model) ⇒ void
This method returns an undefined value.
Called by Sequel when the plugin is first applied to a model class.
This hook installs the plugin's class- and instance-level behavior on the target model. It runs before configure, so it should only attach methods and not depend on per-model plugin options.
118 119 120 121 |
# File 'lib/llm/sequel/plugin.rb', line 118 def self.apply(model, **) model.extend ClassMethods model.include InstanceMethods end |
.configure(model, options = EMPTY_HASH) ⇒ void
This method returns an undefined value.
Called by Sequel after apply with the
options passed to plugin :llm, ....
This hook merges plugin defaults with the model's explicit settings and stores the resolved configuration on the model class for later use by instance methods such as LLM::Sequel::Plugin::InstanceMethods#llm and LLM::Sequel::Plugin::InstanceMethods#ctx.
143 144 145 146 147 |
# File 'lib/llm/sequel/plugin.rb', line 143 def self.configure(model, = EMPTY_HASH) = DEFAULTS.merge() model.db.extension :pg_json if %i[json jsonb].include?([:format]) model.instance_variable_set(:@llm_plugin_options, .freeze) end |