mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-25 01:21:00 +08:00
We can't enable `Rails/WhereNot` lint/autofix, because it would break code that uses mini_sql instead of AR (which rubocop, and tbh also we, can't easily differentiate) Those are safe because they either: * are executed in AR model scope definitions * are clearly chained starting from a AR model * are less-clearly chained, but still can be traced to a AR model/scope --------- Co-authored-by: Loïc Guitaut <loic@discourse.org>
26 lines
828 B
Ruby
Vendored
26 lines
828 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseAi::ChatBotHelper
|
|
def toggle_enabled_bots(bots: [])
|
|
models = LlmModel.all
|
|
models = models.where.not(id: 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 }
|