Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/ai_bot/playground.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def self.schedule_reply(post)

if mentionables.present?
mentions = post.mentions.map(&:downcase)

# in case we are replying to a post by a bot
if post.reply_to_post_number && post.reply_to_post.user
mentions << post.reply_to_post.user.username_lower
end

mentioned = mentionables.find { |mentionable| mentions.include?(mentionable[:username]) }

# direct PM to mentionable
Expand All @@ -51,6 +57,11 @@ def self.schedule_reply(post)
bot_user ||= User.find_by(id: mentioned[:user_id]) if mentioned
end

if bot_user && post.reply_to_post_number && !post.reply_to_post.user&.bot?
# replying to a non-bot user
return
end

if bot_user
persona_id = mentioned&.dig(:id) || post.topic.custom_fields["ai_persona_id"]
persona = nil
Expand Down
5 changes: 2 additions & 3 deletions lib/automation/report_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ def suppress_notifications(raw)
parsed
.css("span.mention")
.each do |mention|
mention.replace(
"<a href='/u/#{mention.text.sub("@", "")}' class='mention'>#{mention.text}</a>",
)
no_at_username = mention.text.sub("@", "")
mention.replace("<a href='/u/#{no_at_username}' class='mention'>#{no_at_username}</a>")
end

parsed.to_html
Expand Down
11 changes: 11 additions & 0 deletions lib/summarization/entry_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ def inject_into(plugin)
"#{claude_prov}:claude-instant-1",
max_tokens: 100_000,
)
foldable_models << Models::Anthropic.new(
"#{claude_prov}:claude-3-haiku",
max_tokens: 200_000,
)
foldable_models << Models::Anthropic.new(
"#{claude_prov}:claude-3-sonnet",
max_tokens: 200_000,
)

# no opus yet for AWS bedrock
foldable_models << Models::Anthropic.new("anthropic:claude-3-opus", max_tokens: 200_000)

mixtral_prov = "hugging_face"
if DiscourseAi::Completions::Endpoints::Vllm.correctly_configured?(
Expand Down
27 changes: 27 additions & 0 deletions spec/lib/modules/ai_bot/playground_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,33 @@

last_post.topic.reload
expect(last_post.topic.allowed_users.pluck(:user_id)).to include(persona.user_id)

# does not reply if replying directly to a user
# nothing is mocked, so this would result in HTTP error
# if we were going to reply
create_post(
raw: "Please ignore this bot, I am replying to a user",
topic: post.topic,
user: admin,
reply_to_post_number: post.post_number,
)

# replies as correct persona if replying direct to persona
DiscourseAi::Completions::Llm.with_prepared_responses(
["Another reply"],
llm: "open_ai:gpt-3.5-turbo-16k",
) do
create_post(
raw: "Please ignore this bot, I am replying to a user",
topic: post.topic,
user: admin,
reply_to_post_number: last_post.post_number,
)
end

last_post = post.topic.posts.order(:post_number).last
expect(last_post.raw).to eq("Another reply")
expect(last_post.user_id).to eq(persona.user_id)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/modules/automation/report_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module Automation

# note, magic surprise &amp; is correct HTML 5 representation
expected = <<~HTML
<p><a href="/u/sam" class="mention">@sam</a> is a person<br>
<p><a href="/u/sam" class="mention">sam</a> is a person<br>
<a href="/test?silent=true">test1</a> is an internal link<br>
<a href="/test?1=2&amp;silent=true">test2</a> is an internal link<br>
<a href="https://example.com" rel="noopener nofollow ugc">test3</a> is an external link<br>
Expand Down