Module: Raif::ApplicationHelper
- Includes:
- Pagy::Frontend
- Defined in:
- app/helpers/raif/application_helper.rb
Instance Method Summary collapse
- #format_task_response(task) ⇒ Object
- #llm_model_options(selected: nil) ⇒ Object
- #llm_pricing_json ⇒ Object
Instance Method Details
#format_task_response(task) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'app/helpers/raif/application_helper.rb', line 7 def format_task_response(task) if task.response_format_json? && task.raw_response.present? JSON.pretty_generate(JSON.parse(task.raw_response)) else task.raw_response end rescue JSON::ParserError task.raw_response end |
#llm_model_options(selected: nil) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/helpers/raif/application_helper.rb', line 17 def (selected: nil) = Raif.available_llm_keys.map do |key| label = I18n.t("raif.model_names.#{key}", default: key.to_s) [label, key.to_s] end.sort_by(&:first) (, selected&.to_s) end |
#llm_pricing_json ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/raif/application_helper.rb', line 26 def llm_pricing_json pricing = {} Raif.available_llm_keys.each do |key| config = Raif.llm_config(key) next unless config pricing[key.to_s] = { input: config[:input_token_cost] || 0, output: config[:output_token_cost] || 0 } end pricing.to_json end |