2023-03-15 16:02:20 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
|
|
module AiHelper
|
|
|
|
class EntryPoint
|
|
|
|
def inject_into(plugin)
|
2023-03-17 14:14:19 -04:00
|
|
|
plugin.register_seedfu_fixtures(
|
2023-05-05 14:28:31 -04:00
|
|
|
Rails.root.join("plugins", "discourse-ai", "db", "fixtures", "ai_helper"),
|
2023-03-17 14:14:19 -04:00
|
|
|
)
|
2023-09-25 14:12:54 -04:00
|
|
|
|
2024-10-16 12:32:13 -04:00
|
|
|
additional_icons = %w[spell-check language images far-copy]
|
2023-09-25 14:12:54 -04:00
|
|
|
additional_icons.each { |icon| plugin.register_svg_icon(icon) }
|
2023-10-30 10:56:33 -04:00
|
|
|
|
2024-08-12 18:40:23 -04:00
|
|
|
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
|
|
|
|
|
2024-03-07 14:14:17 -05:00
|
|
|
plugin.on(:chat_message_created) do |message, channel, user, extra|
|
2024-08-12 18:40:23 -04:00
|
|
|
next unless SiteSetting.ai_helper_enabled
|
2023-10-30 12:32:56 -04:00
|
|
|
next unless SiteSetting.ai_helper_automatic_chat_thread_title
|
2024-05-28 05:15:42 -04:00
|
|
|
next if extra[:thread].blank?
|
|
|
|
next if extra[:thread].title.present?
|
2024-03-07 14:14:17 -05:00
|
|
|
|
|
|
|
reply_count = extra[:thread].replies.count
|
|
|
|
|
|
|
|
if reply_count.between?(1, 4)
|
|
|
|
::Jobs.enqueue_in(
|
|
|
|
SiteSetting.ai_helper_automatic_chat_thread_title_delay.minutes,
|
|
|
|
:generate_chat_thread_title,
|
|
|
|
thread_id: extra[:thread].id,
|
|
|
|
)
|
|
|
|
elsif reply_count >= 5
|
|
|
|
::Jobs.enqueue(:generate_chat_thread_title, thread_id: extra[:thread].id)
|
|
|
|
end
|
2023-10-30 10:56:33 -04:00
|
|
|
end
|
2024-02-16 13:57:14 -05:00
|
|
|
|
|
|
|
plugin.add_to_serializer(
|
|
|
|
:current_user,
|
|
|
|
:ai_helper_prompts,
|
2024-08-12 18:40:23 -04:00
|
|
|
include_condition: -> { SiteSetting.ai_helper_enabled && scope.authenticated? },
|
2024-02-16 13:57:14 -05:00
|
|
|
) do
|
|
|
|
ActiveModel::ArraySerializer.new(
|
2024-07-04 11:23:37 -04:00
|
|
|
DiscourseAi::AiHelper::Assistant.new.available_prompts(scope.user),
|
2024-02-16 13:57:14 -05:00
|
|
|
root: false,
|
|
|
|
)
|
|
|
|
end
|
2024-05-27 13:49:24 -04:00
|
|
|
|
2024-05-27 20:29:11 -04:00
|
|
|
plugin.add_to_serializer(:current_user, :user_allowed_ai_auto_image_captions) do
|
|
|
|
scope.user.in_any_groups?(SiteSetting.ai_auto_image_caption_allowed_groups_map)
|
|
|
|
end
|
|
|
|
|
2024-05-27 13:49:24 -04:00
|
|
|
UserUpdater::OPTION_ATTR.push(:auto_image_caption)
|
|
|
|
plugin.add_to_serializer(
|
|
|
|
:user_option,
|
|
|
|
:auto_image_caption,
|
|
|
|
include_condition: -> do
|
2024-08-12 18:40:23 -04:00
|
|
|
SiteSetting.ai_helper_enabled &&
|
2024-05-27 13:49:24 -04:00
|
|
|
SiteSetting.ai_helper_enabled_features.include?("image_caption") &&
|
|
|
|
scope.user.in_any_groups?(SiteSetting.ai_auto_image_caption_allowed_groups_map)
|
|
|
|
end,
|
|
|
|
) { object.auto_image_caption }
|
2024-08-08 16:37:26 -04:00
|
|
|
|
|
|
|
plugin.add_to_serializer(
|
|
|
|
:current_user_option,
|
|
|
|
:auto_image_caption,
|
|
|
|
include_condition: -> do
|
2024-08-12 18:40:23 -04:00
|
|
|
SiteSetting.ai_helper_enabled &&
|
2024-08-08 16:37:26 -04:00
|
|
|
SiteSetting.ai_helper_enabled_features.include?("image_caption") &&
|
|
|
|
scope.user.in_any_groups?(SiteSetting.ai_auto_image_caption_allowed_groups_map)
|
|
|
|
end,
|
|
|
|
) { object.auto_image_caption }
|
2023-03-15 16:02:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|