Class: RubyLLM::Evals::Prompt

Inherits:
ApplicationRecord show all
Defined in:
app/models/ruby_llm/evals/prompt.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.execute(slug, variables: {}, files: []) ⇒ Object



21
22
23
24
# File 'app/models/ruby_llm/evals/prompt.rb', line 21

def self.execute(slug, variables: {}, files: [])
  prompt = find_by!(slug: slug)
  prompt.execute(variables: variables, files: files)
end

Instance Method Details

#execute(variables: {}, files: []) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/ruby_llm/evals/prompt.rb', line 26

def execute(variables: {}, files: [])
  chat = RubyLLM.chat(model: model, provider: provider)

  chat.with_instructions Liquid::Template.parse(instructions).render(variables) if instructions.present?

  chat.with_temperature(temperature) if temperature.present?
  chat.with_params(**params) if params.present?

  if tools.present?
    tool_classes = tools.map { _1.constantize rescue nil }.compact
    chat.with_tools(*tool_classes)
  end

  if schema_other.present?
    chat.with_schema(**schema_other)
  elsif schema.present?
    chat.with_schema schema.constantize
  end

  chat.ask Liquid::Template.parse(message).render(variables), with: files
end