mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-02-07 12:08:13 +00:00
This PR introduces 3 things: 1. Fake bot that can be used on local so you can test LLMs, to enable on dev use: SiteSetting.ai_bot_enabled_chat_bots = "fake" 2. More elegant smooth streaming of progress on LLM completion This leans on JavaScript to buffer and trickle llm results through. It also amends it so the progress dot is much more consistently rendered 3. It fixes the Claude dialect Claude needs newlines **exactly** at the right spot, amended so it is happy --------- Co-authored-by: Martin Brennan <martin@discourse.org>
46 lines
1.3 KiB
Ruby
46 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi::AiBot::SiteSettingsExtension
|
|
def self.enable_or_disable_ai_bots
|
|
enabled_bots = SiteSetting.ai_bot_enabled_chat_bots_map
|
|
enabled_bots = [] if !SiteSetting.ai_bot_enabled
|
|
DiscourseAi::AiBot::EntryPoint::BOTS.each do |id, bot_name, name|
|
|
if id == DiscourseAi::AiBot::EntryPoint::FAKE_ID
|
|
next if Rails.env.production?
|
|
end
|
|
|
|
active = enabled_bots.include?(name)
|
|
user = User.find_by(id: id)
|
|
|
|
if active
|
|
if !user
|
|
user =
|
|
User.new(
|
|
id: id,
|
|
email: "no_email_#{name}",
|
|
name: bot_name.titleize,
|
|
username: UserNameSuggester.suggest(bot_name),
|
|
active: true,
|
|
approved: true,
|
|
admin: true,
|
|
moderator: true,
|
|
trust_level: TrustLevel[4],
|
|
)
|
|
user.save!(validate: false)
|
|
else
|
|
user.update_columns(active: true)
|
|
end
|
|
elsif !active && user
|
|
# will include deleted
|
|
has_posts = DB.query_single("SELECT 1 FROM posts WHERE user_id = #{id} LIMIT 1").present?
|
|
|
|
if has_posts
|
|
user.update_columns(active: false) if user.active
|
|
else
|
|
user.destroy
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|