2023-12-18 20:04:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
if defined?(DiscourseAutomation)
|
|
|
|
module DiscourseAutomation::LlmReport
|
|
|
|
end
|
|
|
|
|
2024-03-05 10:48:28 -05:00
|
|
|
DiscourseAutomation::Scriptable.add("llm_report") do
|
2023-12-18 20:04:15 -05:00
|
|
|
version 1
|
|
|
|
triggerables %i[recurring]
|
|
|
|
|
|
|
|
field :sender, component: :user, required: true
|
2023-12-21 19:46:23 -05:00
|
|
|
field :receivers, component: :users
|
|
|
|
field :topic_id, component: :text
|
|
|
|
field :title, component: :text
|
2023-12-18 20:04:15 -05:00
|
|
|
field :days, component: :text, required: true, default_value: 7
|
|
|
|
field :offset, component: :text, required: true, default_value: 0
|
|
|
|
field :instructions,
|
|
|
|
component: :message,
|
|
|
|
required: true,
|
|
|
|
default_value: DiscourseAi::Automation::ReportRunner.default_instructions
|
|
|
|
field :sample_size, component: :text, required: true, default_value: 100
|
|
|
|
field :tokens_per_post, component: :text, required: true, default_value: 150
|
|
|
|
|
|
|
|
field :model,
|
|
|
|
component: :choices,
|
|
|
|
required: true,
|
|
|
|
extra: {
|
|
|
|
content: DiscourseAi::Automation::AVAILABLE_MODELS,
|
|
|
|
}
|
|
|
|
|
|
|
|
field :priority_group, component: :group
|
|
|
|
field :categories, component: :categories
|
|
|
|
field :tags, component: :tags
|
|
|
|
|
2024-01-29 23:55:05 -05:00
|
|
|
field :exclude_categories, component: :categories
|
|
|
|
field :exclude_tags, component: :tags
|
|
|
|
|
2023-12-18 20:04:15 -05:00
|
|
|
field :allow_secure_categories, component: :boolean
|
2024-01-30 17:58:25 -05:00
|
|
|
|
|
|
|
field :top_p, component: :text, required: true, default_value: 0.1
|
|
|
|
field :temperature, component: :text, required: true, default_value: 0.2
|
|
|
|
|
2024-03-15 17:05:03 -04:00
|
|
|
field :suppress_notifications, component: :boolean
|
2023-12-18 20:04:15 -05:00
|
|
|
field :debug_mode, component: :boolean
|
|
|
|
|
|
|
|
script do |context, fields, automation|
|
|
|
|
begin
|
|
|
|
sender = fields.dig("sender", "value")
|
|
|
|
receivers = fields.dig("receivers", "value")
|
2023-12-21 19:46:23 -05:00
|
|
|
topic_id = fields.dig("topic_id", "value")
|
2023-12-18 20:04:15 -05:00
|
|
|
title = fields.dig("title", "value")
|
|
|
|
model = fields.dig("model", "value")
|
|
|
|
category_ids = fields.dig("categories", "value")
|
|
|
|
tags = fields.dig("tags", "value")
|
|
|
|
allow_secure_categories = !!fields.dig("allow_secure_categories", "value")
|
|
|
|
debug_mode = !!fields.dig("debug_mode", "value")
|
|
|
|
sample_size = fields.dig("sample_size", "value")
|
|
|
|
instructions = fields.dig("instructions", "value")
|
|
|
|
days = fields.dig("days", "value")
|
|
|
|
offset = fields.dig("offset", "value").to_i
|
|
|
|
priority_group = fields.dig("priority_group", "value")
|
|
|
|
tokens_per_post = fields.dig("tokens_per_post", "value")
|
|
|
|
|
2024-01-29 23:55:05 -05:00
|
|
|
exclude_category_ids = fields.dig("exclude_categories", "value")
|
|
|
|
exclude_tags = fields.dig("exclude_tags", "value")
|
|
|
|
|
2024-01-30 17:58:25 -05:00
|
|
|
# set defaults in code to support easy migration for old rules
|
|
|
|
top_p = 0.1
|
|
|
|
top_p = fields.dig("top_p", "value").to_f if fields.dig("top_p", "value")
|
|
|
|
|
|
|
|
temperature = 0.2
|
|
|
|
temperature = fields.dig("temperature", "value").to_f if fields.dig("temperature", "value")
|
|
|
|
|
2024-03-15 17:05:03 -04:00
|
|
|
suppress_notifications = !!fields.dig("suppress_notifications", "value")
|
2023-12-18 20:04:15 -05:00
|
|
|
DiscourseAi::Automation::ReportRunner.run!(
|
|
|
|
sender_username: sender,
|
|
|
|
receivers: receivers,
|
2023-12-21 19:46:23 -05:00
|
|
|
topic_id: topic_id,
|
2023-12-18 20:04:15 -05:00
|
|
|
title: title,
|
|
|
|
model: model,
|
|
|
|
category_ids: category_ids,
|
|
|
|
tags: tags,
|
|
|
|
allow_secure_categories: allow_secure_categories,
|
|
|
|
debug_mode: debug_mode,
|
|
|
|
sample_size: sample_size,
|
|
|
|
instructions: instructions,
|
|
|
|
days: days,
|
|
|
|
offset: offset,
|
|
|
|
priority_group_id: priority_group,
|
|
|
|
tokens_per_post: tokens_per_post,
|
2024-01-29 23:55:05 -05:00
|
|
|
exclude_category_ids: exclude_category_ids,
|
|
|
|
exclude_tags: exclude_tags,
|
2024-01-30 17:58:25 -05:00
|
|
|
temperature: temperature,
|
|
|
|
top_p: top_p,
|
2024-03-15 17:05:03 -04:00
|
|
|
suppress_notifications: suppress_notifications,
|
2023-12-18 20:04:15 -05:00
|
|
|
)
|
|
|
|
rescue => e
|
|
|
|
Discourse.warn_exception e, message: "Error running LLM report!"
|
|
|
|
if Rails.env.development?
|
|
|
|
p e
|
|
|
|
puts e.backtrace
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|