DEV: Clearly separate post/composer helper settings (#747)
This commit is contained in:
parent
a1eb1ba180
commit
f72ab12761
|
@ -165,9 +165,13 @@ module DiscourseAi
|
|||
end
|
||||
|
||||
def ensure_can_request_suggestions
|
||||
if !current_user.in_any_groups?(SiteSetting.ai_helper_allowed_groups_map)
|
||||
raise Discourse::InvalidAccess
|
||||
end
|
||||
allowed_groups =
|
||||
(
|
||||
SiteSetting.composer_ai_helper_allowed_groups_map |
|
||||
SiteSetting.post_ai_helper_allowed_groups_map
|
||||
)
|
||||
|
||||
raise Discourse::InvalidAccess if !current_user.in_any_groups?(allowed_groups)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,5 @@ export function showPostAIHelper(outletArgs, helper) {
|
|||
}
|
||||
|
||||
function _helperEnabled(siteSettings) {
|
||||
return (
|
||||
siteSettings.discourse_ai_enabled && siteSettings.composer_ai_helper_enabled
|
||||
);
|
||||
return siteSettings.discourse_ai_enabled && siteSettings.ai_helper_enabled;
|
||||
}
|
||||
|
|
|
@ -46,8 +46,8 @@ en:
|
|||
ai_hugging_face_tei_endpoint: URL where the API is running for the Hugging Face text embeddings inference
|
||||
ai_hugging_face_tei_api_key: API key for Hugging Face text embeddings inference
|
||||
|
||||
composer_ai_helper_enabled: "Enable the Composer's AI helper."
|
||||
ai_helper_allowed_groups: "Users on these groups will see the AI helper button in the composer."
|
||||
ai_helper_enabled: "Enable the AI helper."
|
||||
composer_ai_helper_allowed_groups: "Users on these groups will see the AI helper button in the composer."
|
||||
ai_helper_allowed_in_pm: "Enable the composer's AI helper in PMs."
|
||||
ai_helper_model: "Model to use for the AI helper."
|
||||
ai_helper_custom_prompts_allowed_groups: "Users on these groups will see the custom prompt option in the AI helper."
|
||||
|
|
|
@ -225,11 +225,11 @@ discourse_ai:
|
|||
hidden: true
|
||||
default: ""
|
||||
|
||||
composer_ai_helper_enabled:
|
||||
ai_helper_enabled:
|
||||
default: false
|
||||
client: true
|
||||
validator: "DiscourseAi::Configuration::LlmDependencyValidator"
|
||||
ai_helper_allowed_groups:
|
||||
composer_ai_helper_allowed_groups:
|
||||
type: group_list
|
||||
list_type: compact
|
||||
default: "3|14" # 3: @staff, 14: @trust_level_4
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RenameAiHelperEnabledSetting < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
execute "UPDATE site_settings SET name = 'ai_helper_enabled' WHERE name = 'composer_ai_helper_enabled'"
|
||||
end
|
||||
|
||||
def down
|
||||
execute "UPDATE site_settings SET name = 'composer_ai_helper_enabled' WHERE name = 'ai_helper_enabled'"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RenameAiHelperAllowedGroupsSetting < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
execute "UPDATE site_settings SET name = 'composer_ai_helper_allowed_groups' WHERE name = 'ai_helper_allowed_groups'"
|
||||
end
|
||||
|
||||
def down
|
||||
execute "UPDATE site_settings SET name = 'ai_helper_allowed_groups' WHERE name = 'composer_ai_helper_allowed_groups'"
|
||||
end
|
||||
end
|
|
@ -151,18 +151,6 @@ module DiscourseAi
|
|||
bots_map
|
||||
end
|
||||
|
||||
plugin.add_to_serializer(:current_user, :can_use_assistant) do
|
||||
scope.user.in_any_groups?(SiteSetting.ai_helper_allowed_groups_map)
|
||||
end
|
||||
|
||||
plugin.add_to_serializer(:current_user, :can_use_assistant_in_post) do
|
||||
scope.user.in_any_groups?(SiteSetting.post_ai_helper_allowed_groups_map)
|
||||
end
|
||||
|
||||
plugin.add_to_serializer(:current_user, :can_use_custom_prompts) do
|
||||
scope.user.in_any_groups?(SiteSetting.ai_helper_custom_prompts_allowed_groups_map)
|
||||
end
|
||||
|
||||
plugin.add_to_serializer(:current_user, :can_share_ai_bot_conversations) do
|
||||
scope.user.in_any_groups?(SiteSetting.ai_bot_public_sharing_allowed_groups_map)
|
||||
end
|
||||
|
|
|
@ -10,8 +10,20 @@ module DiscourseAi
|
|||
additional_icons = %w[spell-check language images]
|
||||
additional_icons.each { |icon| plugin.register_svg_icon(icon) }
|
||||
|
||||
plugin.add_to_serializer(:current_user, :can_use_assistant) do
|
||||
scope.user.in_any_groups?(SiteSetting.composer_ai_helper_allowed_groups_map)
|
||||
end
|
||||
|
||||
plugin.add_to_serializer(:current_user, :can_use_assistant_in_post) do
|
||||
scope.user.in_any_groups?(SiteSetting.post_ai_helper_allowed_groups_map)
|
||||
end
|
||||
|
||||
plugin.add_to_serializer(:current_user, :can_use_custom_prompts) do
|
||||
scope.user.in_any_groups?(SiteSetting.ai_helper_custom_prompts_allowed_groups_map)
|
||||
end
|
||||
|
||||
plugin.on(:chat_message_created) do |message, channel, user, extra|
|
||||
next unless SiteSetting.composer_ai_helper_enabled
|
||||
next unless SiteSetting.ai_helper_enabled
|
||||
next unless SiteSetting.ai_helper_automatic_chat_thread_title
|
||||
next if extra[:thread].blank?
|
||||
next if extra[:thread].title.present?
|
||||
|
@ -32,10 +44,7 @@ module DiscourseAi
|
|||
plugin.add_to_serializer(
|
||||
:current_user,
|
||||
:ai_helper_prompts,
|
||||
include_condition: -> do
|
||||
SiteSetting.composer_ai_helper_enabled && scope.authenticated? &&
|
||||
scope.user.in_any_groups?(SiteSetting.ai_helper_allowed_groups_map)
|
||||
end,
|
||||
include_condition: -> { SiteSetting.ai_helper_enabled && scope.authenticated? },
|
||||
) do
|
||||
ActiveModel::ArraySerializer.new(
|
||||
DiscourseAi::AiHelper::Assistant.new.available_prompts(scope.user),
|
||||
|
@ -52,7 +61,7 @@ module DiscourseAi
|
|||
:user_option,
|
||||
:auto_image_caption,
|
||||
include_condition: -> do
|
||||
SiteSetting.composer_ai_helper_enabled &&
|
||||
SiteSetting.ai_helper_enabled &&
|
||||
SiteSetting.ai_helper_enabled_features.include?("image_caption") &&
|
||||
scope.user.in_any_groups?(SiteSetting.ai_auto_image_caption_allowed_groups_map)
|
||||
end,
|
||||
|
@ -62,7 +71,7 @@ module DiscourseAi
|
|||
:current_user_option,
|
||||
:auto_image_caption,
|
||||
include_condition: -> do
|
||||
SiteSetting.composer_ai_helper_enabled &&
|
||||
SiteSetting.ai_helper_enabled &&
|
||||
SiteSetting.ai_helper_enabled_features.include?("image_caption") &&
|
||||
scope.user.in_any_groups?(SiteSetting.ai_auto_image_caption_allowed_groups_map)
|
||||
end,
|
||||
|
|
|
@ -57,7 +57,7 @@ module DiscourseAi
|
|||
def modules_and_choose_llm_settings
|
||||
{
|
||||
ai_embeddings_semantic_search_enabled: :ai_embeddings_semantic_search_hyde_model,
|
||||
composer_ai_helper_enabled: :ai_helper_model,
|
||||
ai_helper_enabled: :ai_helper_model,
|
||||
ai_summarization_enabled: :ai_summarization_model,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ RSpec.describe Jobs::StreamPostHelper do
|
|||
|
||||
before do
|
||||
Group.find(Group::AUTO_GROUPS[:trust_level_3]).add(user)
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
end
|
||||
|
||||
describe "validates params" do
|
||||
|
|
|
@ -8,8 +8,8 @@ describe DiscourseAi::AiHelper::EntryPoint do
|
|||
assign_fake_provider_to(:ai_helper_model)
|
||||
SiteSetting.default_locale = "en"
|
||||
SiteSetting.allow_user_locale = true
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_allowed_groups = "10" # tl0
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
SiteSetting.composer_ai_helper_allowed_groups = "10" # tl0
|
||||
DiscourseAi::AiHelper::Assistant.clear_prompt_cache!
|
||||
|
||||
Group.refresh_automatic_groups!
|
||||
|
@ -40,7 +40,7 @@ describe DiscourseAi::AiHelper::EntryPoint do
|
|||
it "will include auto_image_caption field in the user_option if image caption is enabled" do
|
||||
assign_fake_provider_to(:ai_helper_model)
|
||||
assign_fake_provider_to(:ai_helper_image_caption_model)
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled_features = "image_caption"
|
||||
SiteSetting.ai_auto_image_caption_allowed_groups = "10" # tl0
|
||||
serializer = CurrentUserSerializer.new(english_user, scope: Guardian.new(english_user))
|
||||
|
|
|
@ -4,7 +4,7 @@ RSpec.describe UserOption do
|
|||
before do
|
||||
assign_fake_provider_to(:ai_helper_model)
|
||||
assign_fake_provider_to(:ai_helper_image_caption_model)
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled_features = "image_caption"
|
||||
SiteSetting.ai_auto_image_caption_allowed_groups = "10" # tl0
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ describe Plugin::Instance do
|
|||
|
||||
before do
|
||||
assign_fake_provider_to(:ai_helper_model)
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_illustrate_post_model = "disabled"
|
||||
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
|
|||
|
||||
before do
|
||||
sign_in(user)
|
||||
SiteSetting.ai_helper_allowed_groups = Group::AUTO_GROUPS[:staff]
|
||||
SiteSetting.composer_ai_helper_allowed_groups = Group::AUTO_GROUPS[:staff]
|
||||
end
|
||||
|
||||
it "returns a 403 response" do
|
||||
|
@ -37,7 +37,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
|
|||
before do
|
||||
sign_in(user)
|
||||
user.group_ids = [Group::AUTO_GROUPS[:trust_level_1]]
|
||||
SiteSetting.ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]
|
||||
SiteSetting.composer_ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]
|
||||
end
|
||||
|
||||
it "returns a 400 if the helper mode is invalid" do
|
||||
|
@ -128,7 +128,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
|
|||
before do
|
||||
sign_in(user)
|
||||
|
||||
SiteSetting.ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]
|
||||
SiteSetting.composer_ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]
|
||||
end
|
||||
|
||||
it "returns the suggested caption for the image" do
|
||||
|
@ -208,9 +208,9 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
|
|||
stub_s3_store
|
||||
assign_fake_provider_to(:ai_helper_image_caption_model)
|
||||
SiteSetting.secure_uploads = true
|
||||
SiteSetting.ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]
|
||||
SiteSetting.composer_ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]
|
||||
|
||||
Group.find(SiteSetting.ai_helper_allowed_groups_map.first).add(user)
|
||||
Group.find(SiteSetting.composer_ai_helper_allowed_groups_map.first).add(user)
|
||||
user.reload
|
||||
|
||||
stub_request(
|
||||
|
|
|
@ -7,7 +7,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
|
|||
before do
|
||||
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
||||
assign_fake_provider_to(:ai_helper_model)
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
|
@ -383,7 +383,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
|
|||
|
||||
context "when AI helper is disabled" do
|
||||
let(:mode) { CompletionPrompt::GENERATE_TITLES }
|
||||
before { SiteSetting.composer_ai_helper_enabled = false }
|
||||
before { SiteSetting.ai_helper_enabled = false }
|
||||
|
||||
it "does not trigger AI context menu" do
|
||||
trigger_context_menu(input)
|
||||
|
@ -400,7 +400,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
|
|||
|
||||
context "when user is not a member of AI helper allowed group" do
|
||||
let(:mode) { CompletionPrompt::GENERATE_TITLES }
|
||||
before { SiteSetting.ai_helper_allowed_groups = non_member_group.id.to_s }
|
||||
before { SiteSetting.composer_ai_helper_allowed_groups = non_member_group.id.to_s }
|
||||
|
||||
it "does not trigger AI context menu" do
|
||||
trigger_context_menu(input)
|
||||
|
|
|
@ -37,7 +37,7 @@ RSpec.describe "AI image caption", type: :system, js: true do
|
|||
end
|
||||
|
||||
context "when not a member of ai helper group" do
|
||||
before { SiteSetting.ai_helper_allowed_groups = non_member_group.id.to_s }
|
||||
before { SiteSetting.composer_ai_helper_allowed_groups = non_member_group.id.to_s }
|
||||
include_examples "shows no image caption button"
|
||||
end
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ RSpec.describe "AI Post helper", type: :system, js: true do
|
|||
before do
|
||||
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
||||
assign_fake_provider_to(:ai_helper_model)
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
|
@ -170,7 +170,7 @@ RSpec.describe "AI Post helper", type: :system, js: true do
|
|||
end
|
||||
|
||||
context "when AI helper is disabled" do
|
||||
before { SiteSetting.composer_ai_helper_enabled = false }
|
||||
before { SiteSetting.ai_helper_enabled = false }
|
||||
|
||||
it "does not show the Ask AI button in the post selection toolbar" do
|
||||
select_post_text(post)
|
||||
|
@ -181,7 +181,7 @@ RSpec.describe "AI Post helper", type: :system, js: true do
|
|||
|
||||
context "when user is not a member of the post AI helper allowed group" do
|
||||
before do
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
SiteSetting.post_ai_helper_allowed_groups = non_member_group.id.to_s
|
||||
end
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ RSpec.describe "AI Post helper", type: :system, js: true do
|
|||
before do
|
||||
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
||||
assign_fake_provider_to(:ai_helper_model)
|
||||
SiteSetting.composer_ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue