mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-08 15:18:58 +08:00
Rebased version of [discouse/discourse-ai#1496](https://github.com/discourse/discourse-ai/pull/1496)
26 lines
837 B
Ruby
26 lines
837 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi::ChatBotHelper
|
|
def toggle_enabled_bots(bots: [])
|
|
models = LlmModel.all
|
|
models = models.where("id not in (?)", bots.map(&:id)) if bots.present?
|
|
models.update_all(enabled_chat_bot: false)
|
|
|
|
bots.each { |b| b.update!(enabled_chat_bot: true) }
|
|
DiscourseAi::AiBot::SiteSettingsExtension.enable_or_disable_ai_bots
|
|
end
|
|
|
|
def assign_fake_provider_to(setting_name)
|
|
Fabricate(:fake_model).tap do |fake_llm|
|
|
SiteSetting.public_send("#{setting_name}=", "#{fake_llm.id}")
|
|
end
|
|
end
|
|
|
|
def assign_persona_to(setting_name, allowed_group_ids)
|
|
Fabricate(:ai_persona, allowed_group_ids: allowed_group_ids).tap do |p|
|
|
SiteSetting.public_send("#{setting_name}=", p.id)
|
|
end
|
|
end
|
|
end
|
|
|
|
RSpec.configure { |config| config.include DiscourseAi::ChatBotHelper }
|