|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module DiscourseAi |
| 4 | + module Configuration |
| 5 | + class Feature |
| 6 | + class << self |
| 7 | + def feature_cache |
| 8 | + @feature_cache ||= ::DiscourseAi::MultisiteHash.new("feature_cache") |
| 9 | + end |
| 10 | + |
| 11 | + def summarization_features |
| 12 | + feature_cache[:summarization] ||= [ |
| 13 | + new( |
| 14 | + "topic_summaries", |
| 15 | + "ai_summarization_persona", |
| 16 | + DiscourseAi::Configuration::Module::SUMMARIZATION_ID, |
| 17 | + DiscourseAi::Configuration::Module::SUMMARIZATION, |
| 18 | + ), |
| 19 | + new( |
| 20 | + "gists", |
| 21 | + "ai_summary_gists_persona", |
| 22 | + DiscourseAi::Configuration::Module::SUMMARIZATION_ID, |
| 23 | + DiscourseAi::Configuration::Module::SUMMARIZATION, |
| 24 | + enabled_by_setting: "ai_summary_gists_enabled", |
| 25 | + ), |
| 26 | + ] |
| 27 | + end |
| 28 | + |
| 29 | + def search_features |
| 30 | + feature_cache[:search] ||= [ |
| 31 | + new( |
| 32 | + "discoveries", |
| 33 | + "ai_bot_discover_persona", |
| 34 | + DiscourseAi::Configuration::Module::SEARCH_ID, |
| 35 | + DiscourseAi::Configuration::Module::SEARCH, |
| 36 | + ), |
| 37 | + ] |
| 38 | + end |
| 39 | + |
| 40 | + def discord_features |
| 41 | + feature_cache[:discord] ||= [ |
| 42 | + new( |
| 43 | + "search", |
| 44 | + "ai_discord_search_persona", |
| 45 | + DiscourseAi::Configuration::Module::DISCORD_ID, |
| 46 | + DiscourseAi::Configuration::Module::DISCORD, |
| 47 | + ), |
| 48 | + ] |
| 49 | + end |
| 50 | + |
| 51 | + def inference_features |
| 52 | + feature_cache[:inference] ||= [ |
| 53 | + new( |
| 54 | + "generate_concepts", |
| 55 | + "inferred_concepts_generate_persona", |
| 56 | + DiscourseAi::Configuration::Module::INFERENCE_ID, |
| 57 | + DiscourseAi::Configuration::Module::INFERENCE, |
| 58 | + ), |
| 59 | + new( |
| 60 | + "match_concepts", |
| 61 | + "inferred_concepts_match_persona", |
| 62 | + DiscourseAi::Configuration::Module::INFERENCE_ID, |
| 63 | + DiscourseAi::Configuration::Module::INFERENCE, |
| 64 | + ), |
| 65 | + new( |
| 66 | + "deduplicate_concepts", |
| 67 | + "inferred_concepts_deduplicate_persona", |
| 68 | + DiscourseAi::Configuration::Module::INFERENCE_ID, |
| 69 | + DiscourseAi::Configuration::Module::INFERENCE, |
| 70 | + ), |
| 71 | + ] |
| 72 | + end |
| 73 | + |
| 74 | + def ai_helper_features |
| 75 | + feature_cache[:ai_helper] ||= [ |
| 76 | + new( |
| 77 | + "proofread", |
| 78 | + "ai_helper_proofreader_persona", |
| 79 | + DiscourseAi::Configuration::Module::AI_HELPER_ID, |
| 80 | + DiscourseAi::Configuration::Module::AI_HELPER, |
| 81 | + ), |
| 82 | + new( |
| 83 | + "title_suggestions", |
| 84 | + "ai_helper_title_suggestions_persona", |
| 85 | + DiscourseAi::Configuration::Module::AI_HELPER_ID, |
| 86 | + DiscourseAi::Configuration::Module::AI_HELPER, |
| 87 | + ), |
| 88 | + new( |
| 89 | + "explain", |
| 90 | + "ai_helper_explain_persona", |
| 91 | + DiscourseAi::Configuration::Module::AI_HELPER_ID, |
| 92 | + DiscourseAi::Configuration::Module::AI_HELPER, |
| 93 | + ), |
| 94 | + new( |
| 95 | + "smart_dates", |
| 96 | + "ai_helper_smart_dates_persona", |
| 97 | + DiscourseAi::Configuration::Module::AI_HELPER_ID, |
| 98 | + DiscourseAi::Configuration::Module::AI_HELPER, |
| 99 | + ), |
| 100 | + new( |
| 101 | + "markdown_tables", |
| 102 | + "ai_helper_markdown_tables_persona", |
| 103 | + DiscourseAi::Configuration::Module::AI_HELPER_ID, |
| 104 | + DiscourseAi::Configuration::Module::AI_HELPER, |
| 105 | + ), |
| 106 | + new( |
| 107 | + "custom_prompt", |
| 108 | + "ai_helper_custom_prompt_persona", |
| 109 | + DiscourseAi::Configuration::Module::AI_HELPER_ID, |
| 110 | + DiscourseAi::Configuration::Module::AI_HELPER, |
| 111 | + ), |
| 112 | + new( |
| 113 | + "image_caption", |
| 114 | + "ai_helper_image_caption_persona", |
| 115 | + DiscourseAi::Configuration::Module::AI_HELPER_ID, |
| 116 | + DiscourseAi::Configuration::Module::AI_HELPER, |
| 117 | + ), |
| 118 | + ] |
| 119 | + end |
| 120 | + |
| 121 | + def all |
| 122 | + [ |
| 123 | + summarization_features, |
| 124 | + search_features, |
| 125 | + discord_features, |
| 126 | + inference_features, |
| 127 | + ai_helper_features, |
| 128 | + ].flatten |
| 129 | + end |
| 130 | + |
| 131 | + def all_persona_setting_names |
| 132 | + all.map(&:persona_setting) |
| 133 | + end |
| 134 | + |
| 135 | + def find_features_using(persona_id:) |
| 136 | + all.select { |feature| feature.persona_id == persona_id } |
| 137 | + end |
| 138 | + end |
| 139 | + |
| 140 | + def initialize(name, persona_setting, module_id, module_name, enabled_by_setting: "") |
| 141 | + @name = name |
| 142 | + @persona_setting = persona_setting |
| 143 | + @module_id = module_id |
| 144 | + @module_name = module_name |
| 145 | + @enabled_by_setting = enabled_by_setting |
| 146 | + end |
| 147 | + |
| 148 | + attr_reader :name, :persona_setting, :module_id, :module_name |
| 149 | + |
| 150 | + def enabled? |
| 151 | + @enabled_by_setting.blank? || SiteSetting.get(@enabled_by_setting) |
| 152 | + end |
| 153 | + |
| 154 | + def persona_id |
| 155 | + SiteSetting.get(persona_setting).to_i |
| 156 | + end |
| 157 | + end |
| 158 | + end |
| 159 | +end |
0 commit comments