FIX: avoid all bot feedback loops (#507)

We need to ensure that under no circumstances feedback loops between
bots will emerge cause this can eat up a lot of tokens
This commit is contained in:
Sam 2024-03-05 10:02:49 +11:00 committed by GitHub
parent 9485f3110a
commit b7a96e3bcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 6 deletions

View File

@ -12,12 +12,10 @@ module DiscourseAi
REQUIRE_TITLE_UPDATE = "discourse-ai-title-update" REQUIRE_TITLE_UPDATE = "discourse-ai-title-update"
def self.is_bot_user_id?(user_id) def self.is_bot_user_id?(user_id)
bot_ids = DiscourseAi::AiBot::EntryPoint::BOT_USER_IDS # this will catch everything and avoid any feedback loops
bot_ids.include?(user_id) || # we could get feedback loops between say discobot and ai-bot or third party plugins
begin # and bots
mentionable_ids = AiPersona.mentionables.map { |mentionable| mentionable[:user_id] } user_id.to_i <= 0
mentionable_ids.include?(user_id)
end
end end
def self.schedule_reply(post) def self.schedule_reply(post)

View File

@ -52,6 +52,15 @@ RSpec.describe DiscourseAi::AiBot::Playground do
) )
end end
describe "is_bot_user_id?" do
it "properly detects ALL bots as bot users" do
persona = Fabricate(:ai_persona, enabled: false)
persona.create_user!
expect(DiscourseAi::AiBot::Playground.is_bot_user_id?(persona.user_id)).to eq(true)
end
end
describe "persona with user support" do describe "persona with user support" do
before do before do
Jobs.run_immediately! Jobs.run_immediately!