Class: RubyLLM::Prompt
- Inherits:
-
Object
- Object
- RubyLLM::Prompt
- Defined in:
- lib/ruby_llm/prompt.rb
Overview
Resolves prompt templates from the application and registered engine directories.
Defined Under Namespace
Classes: Roots
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.render(name, **locals) ⇒ Object
:nodoc:.
-
.root ⇒ Object
:nodoc:.
-
.roots ⇒ Object
Returns the ordered prompt directories.
Instance Method Summary collapse
-
#initialize(name) ⇒ Prompt
constructor
:nodoc:.
-
#path ⇒ Object
:nodoc:.
-
#render(**locals) ⇒ Object
:nodoc:.
Constructor Details
#initialize(name) ⇒ Prompt
:nodoc:
41 42 43 44 |
# File 'lib/ruby_llm/prompt.rb', line 41 def initialize(name) # :nodoc: @name = name.to_s @filename = @name.end_with?('.txt.erb') ? @name : "#{@name}.txt.erb" end |
Instance Attribute Details
#name ⇒ Object (readonly)
:nodoc:
39 40 41 |
# File 'lib/ruby_llm/prompt.rb', line 39 def name @name end |
Class Method Details
.render(name, **locals) ⇒ Object
:nodoc:
56 57 58 |
# File 'lib/ruby_llm/prompt.rb', line 56 def self.render(name, **locals) # :nodoc: new(name).render(**locals) end |
.root ⇒ Object
:nodoc:
65 66 67 68 69 70 71 |
# File 'lib/ruby_llm/prompt.rb', line 65 def self.root # :nodoc: if defined?(Rails) && Rails.respond_to?(:root) && Rails.root Rails.root.join('app/prompts') else Pathname.new(Dir.pwd).join('app/prompts') end end |
Instance Method Details
#path ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/ruby_llm/prompt.rb', line 46 def path # :nodoc: @path ||= candidates.find { |candidate| File.exist?(candidate) } || candidates.first end |
#render(**locals) ⇒ Object
:nodoc:
50 51 52 53 54 |
# File 'lib/ruby_llm/prompt.rb', line 50 def render(**locals) # :nodoc: raise PromptNotFoundError, "Prompt file not found: #{path}" unless File.exist?(path) ERB.new(File.read(path)).result_with_hash(locals) end |