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"
def self.is_bot_user_id?(user_id)
bot_ids = DiscourseAi::AiBot::EntryPoint::BOT_USER_IDS
bot_ids.include?(user_id) ||
begin
mentionable_ids = AiPersona.mentionables.map { |mentionable| mentionable[:user_id] }
mentionable_ids.include?(user_id)
end
# this will catch everything and avoid any feedback loops
# we could get feedback loops between say discobot and ai-bot or third party plugins
# and bots
user_id.to_i <= 0
end
def self.schedule_reply(post)

View File

@ -52,6 +52,15 @@ RSpec.describe DiscourseAi::AiBot::Playground do
)
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
before do
Jobs.run_immediately!