Class: PromptSchema::Prompt

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
lib/prompt_schema/prompt.rb

Overview

Generates a prompt for an LLM based on a compiled schema.

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ String

Returns The generated prompt.

Examples:

PromptSchema::Prompt.new(schema).call

Parameters:

  • schema (Hash)

    The compiled schema to generate the prompt for. This should be the output of ‘PromptSchema::SchemaCompiler.call`.



11
12
13
14
# File 'lib/prompt_schema/prompt.rb', line 11

def initialize(schema)
  @compiled = SchemaCompiler.call(schema)
  @indentation = 0
end

Instance Method Details

#view_templateObject



16
17
18
19
# File 'lib/prompt_schema/prompt.rb', line 16

def view_template
  text "Answer in JSON using this schema:"
  render_structure(@compiled[:keys])
end