0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/plugins/discourse-ai/lib/personas/summarizer.rb
Roman Rizzi 5ccd7fa1e4
FIX: Default prompts have to be explicit about the expected format. (#34442)
Wrapping the expected response with `<output>` tags confuses models,
especially those from the Claude family, which don't have schema support
and rely on prefilling. Relying on prefilling means they only know the
response must start with `{`, and how the JSON looks is only hinted at
in the system prompt.
2025-08-20 13:56:21 -03:00

52 lines
2.1 KiB
Ruby
Vendored

# frozen_string_literal: true
module DiscourseAi
module Personas
class Summarizer < Persona
def self.default_enabled
false
end
def system_prompt
<<~PROMPT.strip
You are an advanced summarization bot that generates concise, coherent summaries of provided text.
You are also capable of enhancing an existing summaries by incorporating additional posts if asked to.
- Only include the summary, without any additional commentary.
- You understand and generate Discourse forum Markdown; including links, _italics_, **bold**.
- Maintain the original language of the text being summarized.
- Aim for summaries to be 400 words or less.
- Each post is formatted as "<POST_NUMBER>) <USERNAME> <MESSAGE>"
- Cite specific noteworthy posts using the format [DESCRIPTION]({resource_url}/POST_NUMBER)
- Example: link to the 6th post by jane: [agreed with]({resource_url}/6)
- Example: link to the 13th post by joe: [joe]({resource_url}/13)
- When formatting usernames use [USERNAME]({resource_url}/POST_NUMBER)
Format your response as a JSON object with a single key named "summary", which has the summary as the value.
Your output should be in the following format:
{"summary": "xx"}
Where "xx" is replaced by the summary.
reply with valid JSON only
PROMPT
end
def response_format
[{ "key" => "summary", "type" => "string" }]
end
def examples
[
[
"Here are the posts inside <input></input> XML tags:\n\n<input>1) user1 said: I love Mondays 2) user2 said: I hate Mondays</input>\n\nGenerate a concise, coherent summary of the text above maintaining the original language.",
{
summary:
"Two users are sharing their feelings toward Mondays. [user1]({resource_url}/1) hates them, while [user2]({resource_url}/2) loves them.",
}.to_json,
],
]
end
end
end
end