discourse-ai/lib/automation.rb
Sam 01893bb6ed
FEATURE: Add persona-based replies and whisper support to LLM triage (#1170)
This PR enhances the LLM triage automation with several important improvements:

- Add ability to use AI personas for automated replies instead of canned replies
- Add support for whisper responses
- Refactor LLM persona reply functionality into a reusable method
- Add new settings to configure response behavior in automations
- Improve error handling and logging
- Fix handling of personal messages in the triage flow
- Add comprehensive test coverage for new features
- Make personas configurable with more flexible requirements

This allows for more dynamic and context-aware responses in automated workflows, with better control over visibility and attribution.
2025-03-06 17:18:15 +11:00

55 lines
1.6 KiB
Ruby

# frozen_string_literal: true
module DiscourseAi
module Automation
def self.flag_types
[
{ id: "review", translated_name: I18n.t("discourse_automation.ai.flag_types.review") },
{ id: "spam", translated_name: I18n.t("discourse_automation.ai.flag_types.spam") },
{
id: "spam_silence",
translated_name: I18n.t("discourse_automation.ai.flag_types.spam_silence"),
},
]
end
def self.available_custom_tools
AiTool
.where(enabled: true)
.where("parameters = '[]'::jsonb")
.pluck(:id, :name, :description)
.map { |id, name, description| { id: id, translated_name: name, description: description } }
end
def self.available_models
values = DB.query_hash(<<~SQL)
SELECT display_name AS translated_name, id AS id
FROM llm_models
SQL
values =
values
.filter do |value_h|
value_h["id"] > 0 ||
SiteSetting.ai_automation_allowed_seeded_models_map.include?(value_h["id"].to_s)
end
.each { |value_h| value_h["id"] = "custom:#{value_h["id"]}" }
values
end
def self.available_persona_choices(require_user: true, require_default_llm: true)
relation = AiPersona.joins(:user)
relation = relation.where.not(user_id: nil) if require_user
relation = relation.where.not(default_llm: nil) if require_default_llm
relation.map do |persona|
{
id: persona.id,
translated_name: persona.name,
description: "#{persona.name} (#{persona.user.username})",
}
end
end
end
end