Class: RagRuby::PromptTemplate
- Inherits:
-
Object
- Object
- RagRuby::PromptTemplate
- Defined in:
- lib/rag_ruby/prompt_template.rb
Constant Summary collapse
- DEFAULT_SYSTEM =
"You are a helpful assistant that answers questions based on the provided context."- DEFAULT_USER =
<<~PROMPT Answer the question based on the following context. If the context doesn't contain enough information to answer, say so. Context: {{context}} Question: {{question}} Answer: PROMPT
Instance Attribute Summary collapse
-
#system_prompt ⇒ Object
readonly
Returns the value of attribute system_prompt.
-
#user_template ⇒ Object
readonly
Returns the value of attribute user_template.
Instance Method Summary collapse
-
#initialize(system_prompt: DEFAULT_SYSTEM, user_template: DEFAULT_USER) ⇒ PromptTemplate
constructor
A new instance of PromptTemplate.
- #render(context:, question:) ⇒ Object
Constructor Details
#initialize(system_prompt: DEFAULT_SYSTEM, user_template: DEFAULT_USER) ⇒ PromptTemplate
Returns a new instance of PromptTemplate.
21 22 23 24 |
# File 'lib/rag_ruby/prompt_template.rb', line 21 def initialize(system_prompt: DEFAULT_SYSTEM, user_template: DEFAULT_USER) @system_prompt = system_prompt @user_template = user_template end |
Instance Attribute Details
#system_prompt ⇒ Object (readonly)
Returns the value of attribute system_prompt.
19 20 21 |
# File 'lib/rag_ruby/prompt_template.rb', line 19 def system_prompt @system_prompt end |
#user_template ⇒ Object (readonly)
Returns the value of attribute user_template.
19 20 21 |
# File 'lib/rag_ruby/prompt_template.rb', line 19 def user_template @user_template end |
Instance Method Details
#render(context:, question:) ⇒ Object
26 27 28 29 30 |
# File 'lib/rag_ruby/prompt_template.rb', line 26 def render(context:, question:) user_template .gsub("{{context}}", context) .gsub("{{question}}", question) end |