mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-02-08 12:34:43 +00:00
FIX: mention suppression was not working right (#538)
We were only suppressing non mentions, ones that become spans. @sam in the test was not resolving to a mention cause the user did not exist. depends on: https://github.com/discourse/discourse/pull/26253 for tests to pass.
This commit is contained in:
parent
1a55d7f6e7
commit
41f1530078
@ -237,6 +237,10 @@ Follow the provided writing composition instructions carefully and precisely ste
|
|||||||
parsed
|
parsed
|
||||||
.css("a")
|
.css("a")
|
||||||
.each do |a|
|
.each do |a|
|
||||||
|
if a["class"] == "mention"
|
||||||
|
a.inner_html = a.inner_html.sub("@", "")
|
||||||
|
next
|
||||||
|
end
|
||||||
href = a["href"]
|
href = a["href"]
|
||||||
if href.present? && (href.start_with?("#{Discourse.base_url}") || href.start_with?("/"))
|
if href.present? && (href.start_with?("#{Discourse.base_url}") || href.start_with?("/"))
|
||||||
begin
|
begin
|
||||||
@ -255,13 +259,6 @@ Follow the provided writing composition instructions carefully and precisely ste
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parsed
|
|
||||||
.css("span.mention")
|
|
||||||
.each do |mention|
|
|
||||||
no_at_username = mention.text.sub("@", "")
|
|
||||||
mention.replace("<a href='/u/#{no_at_username}' class='mention'>#{no_at_username}</a>")
|
|
||||||
end
|
|
||||||
|
|
||||||
parsed.to_html
|
parsed.to_html
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,8 @@ module DiscourseAi
|
|||||||
end
|
end
|
||||||
|
|
||||||
def correctly_configured?
|
def correctly_configured?
|
||||||
SiteSetting.ai_anthropic_api_key.present?
|
SiteSetting.ai_anthropic_api_key.present? ||
|
||||||
|
DiscourseAi::Completions::Endpoints::AwsBedrock.correctly_configured?("claude-2")
|
||||||
end
|
end
|
||||||
|
|
||||||
def configuration_hint
|
def configuration_hint
|
||||||
|
@ -82,8 +82,10 @@ module DiscourseAi
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "can suppress notifications by remapping content" do
|
it "can suppress notifications by remapping content" do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
|
||||||
markdown = <<~MD
|
markdown = <<~MD
|
||||||
@sam is a person
|
@#{user.username} is a person
|
||||||
[test1](/test) is an internal link
|
[test1](/test) is an internal link
|
||||||
[test2](/test?1=2) is an internal link
|
[test2](/test?1=2) is an internal link
|
||||||
[test3](https://example.com) is an external link
|
[test3](https://example.com) is an external link
|
||||||
@ -117,7 +119,7 @@ module DiscourseAi
|
|||||||
|
|
||||||
# note, magic surprise & is correct HTML 5 representation
|
# note, magic surprise & is correct HTML 5 representation
|
||||||
expected = <<~HTML
|
expected = <<~HTML
|
||||||
<p><a href="/u/sam" class="mention">sam</a> is a person<br>
|
<p><a class="mention" href="/u/#{user.username}">#{user.username}</a> is a person<br>
|
||||||
<a href="/test?silent=true">test1</a> is an internal link<br>
|
<a href="/test?silent=true">test1</a> is an internal link<br>
|
||||||
<a href="/test?1=2&silent=true">test2</a> is an internal link<br>
|
<a href="/test?1=2&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>
|
<a href="https://example.com" rel="noopener nofollow ugc">test3</a> is an external link<br>
|
||||||
@ -127,7 +129,10 @@ module DiscourseAi
|
|||||||
<a href="//%5B%5Btest?silent=true" rel="noopener nofollow ugc">test7</a> is a link with an invalid URL</p>
|
<a href="//%5B%5Btest?silent=true" rel="noopener nofollow ugc">test7</a> is a link with an invalid URL</p>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
expect(report.ordered_posts.first.raw.strip).to eq(expected.strip)
|
post = report.ordered_posts.first
|
||||||
|
|
||||||
|
expect(post.mentions.to_a).to eq([])
|
||||||
|
expect(post.raw.strip).to eq(expected.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can exclude tags" do
|
it "can exclude tags" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user