Module: RubyLLM::Evals::PromptsHelper

Defined in:
app/helpers/ruby_llm/evals/prompts_helper.rb

Instance Method Summary collapse

Instance Method Details

#available_schemas ⇒ Object



13
14
15
16
# File 'app/helpers/ruby_llm/evals/prompts_helper.rb', line 13

def available_schemas
  Rails.application.eager_load! unless Rails.application.config.eager_load
  RubyLLM::Schema.descendants.map(&:name).reject { |name| name.start_with? "RubyLLM::Evals::" }.uniq.sort
end

#available_tools ⇒ Object



8
9
10
11
# File 'app/helpers/ruby_llm/evals/prompts_helper.rb', line 8

def available_tools
  Rails.application.eager_load! unless Rails.application.config.eager_load
  RubyLLM::Tool.descendants.map(&:name).uniq.sort
end

#models_by_provider_data ⇒ Object



4
5
6
# File 'app/helpers/ruby_llm/evals/prompts_helper.rb', line 4

def models_by_provider_data
  @models_by_provider_data ||= RubyLLM.models.group_by(&:provider).transform_values { |models| models.map { |m| { id: m.id, name: m.name } } }.to_json
end

#schema_options_for_select(prompt) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/ruby_llm/evals/prompts_helper.rb', line 18

def schema_options_for_select(prompt)
  options = available_schemas.map { |s| [ s, s ] } + [ [ "Other", "" ] ]

  # Determine what should be selected:
  # * If schema is present and in available schemas, select it
  # * If schema is blank but schema_other is present, select "Other" (empty string)
  # * Otherwise, select nothing (nil)
  selected = if prompt.schema.present? && available_schemas.include?(prompt.schema)
    prompt.schema
  elsif prompt.schema.blank? && prompt.schema_other.present?
    ""
  else
    nil
  end

  options_for_select(options, selected)
end