Class: Langfuse::ChatPromptTemplate
- Inherits:
-
Object
- Object
- Langfuse::ChatPromptTemplate
- Defined in:
- lib/langfuse/prompt.rb
Instance Attribute Summary collapse
-
#input_variables ⇒ Object
readonly
Returns the value of attribute input_variables.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Class Method Summary collapse
Instance Method Summary collapse
- #format(variables = {}) ⇒ Object
-
#initialize(messages:, input_variables: []) ⇒ ChatPromptTemplate
constructor
A new instance of ChatPromptTemplate.
Constructor Details
#initialize(messages:, input_variables: []) ⇒ ChatPromptTemplate
Returns a new instance of ChatPromptTemplate.
173 174 175 176 |
# File 'lib/langfuse/prompt.rb', line 173 def initialize(messages:, input_variables: []) @messages = @input_variables = input_variables end |
Instance Attribute Details
#input_variables ⇒ Object (readonly)
Returns the value of attribute input_variables.
171 172 173 |
# File 'lib/langfuse/prompt.rb', line 171 def input_variables @input_variables end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
171 172 173 |
# File 'lib/langfuse/prompt.rb', line 171 def @messages end |
Class Method Details
.from_messages(messages) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/langfuse/prompt.rb', line 193 def self.() input_variables = [] .each do || [:content].scan(/\{\{(\w+)\}\}/) do |match| input_variables << match[0] unless input_variables.include?(match[0]) end [:content].scan(/\{(\w+)\}/) do |match| input_variables << match[0] unless input_variables.include?(match[0]) end end new(messages: , input_variables: input_variables) end |
Instance Method Details
#format(variables = {}) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/langfuse/prompt.rb', line 178 def format(variables = {}) @messages.map do || compiled_content = [:content].dup variables.each do |key, value| compiled_content.gsub!("{{#{key}}}", value.to_s) compiled_content.gsub!("{#{key}}", value.to_s) end { role: [:role], content: compiled_content } end end |