class OpenUI::Rails::PromptBuilder
Builds the explicit system instruction handed to a model and ties it to the exact component-library revision it was generated from.
The library prompt itself is produced by the pinned OpenUI CLI (‘openui generate <entry> –out <prompt file>`), which writes both the prompt and `<prompt file>.spec.json` from the same library revision. This class adds the Gem’s framing rules and computes a combined fingerprint so a response can be persisted with the prompt/library pair that produced it.
Constants
- DEFAULT_INSTRUCTIONS
- MAX_BYTES
Attributes
Public Class Methods
Build from the current (or given) configuration, reading the prompt and library manifest from disk.
@param configuration [Configuration] @return [PromptBuilder] @raise [ManifestError] when the manifest or prompt cannot be read
# File lib/openui/rails/prompt_builder.rb, line 38 def load(configuration = OpenUI::Rails.configuration) manifest = configuration.library_manifest raise ManifestError, "library_spec_path is not configured" if manifest.nil? new( manifest: manifest, library_prompt: read_prompt(configuration.prompt_path), instructions: DEFAULT_INSTRUCTIONS ) end
Create a builder from a manifest and optional generated prompt text.
@param manifest [LibraryManifest] @param library_prompt [String, nil] @param instructions [String] framing rules supplied to the model @return [PromptBuilder]
# File lib/openui/rails/prompt_builder.rb, line 71 def initialize(manifest:, library_prompt: nil, instructions: DEFAULT_INSTRUCTIONS) @manifest = manifest @library_prompt = library_prompt @instructions = instructions end
Public Instance Methods
Fingerprint of the prompt and the library revision it targets. This is what a response is persisted with, so a later render can detect drift.
@return [String] a scheme-tagged SHA-256 fingerprint
# File lib/openui/rails/prompt_builder.rb, line 88 def fingerprint @fingerprint ||= "sha256:#{Digest::SHA256.hexdigest("#{manifest.fingerprint}\n#{system_instruction}")}" end
True when a previously persisted fingerprint still matches this builder.
@param other_fingerprint [String, nil] @return [Boolean]
# File lib/openui/rails/prompt_builder.rb, line 96 def matches?(other_fingerprint) return false if other_fingerprint.nil? other_fingerprint.to_s == fingerprint end
The complete system instruction for the model.
@return [String]
# File lib/openui/rails/prompt_builder.rb, line 80 def system_instruction @system_instruction ||= [ instructions, library_prompt ].compact.join("\n\n").strip end
Return the library and prompt provenance values.
@return [Hash]
# File lib/openui/rails/prompt_builder.rb, line 105 def to_h { library: manifest.identifier, library_fingerprint: manifest.fingerprint, prompt_fingerprint: fingerprint, prompt_source: manifest.source } end