Keep only the last segment after bracketed metadata in LLM responses
The model dumps paraphrased context and style labels in [brackets] before its actual roast. Instead of just removing bracket lines (which leaves the preamble text), split on them and keep only the last non-empty segment — the real answer is always last. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+10
-8
@@ -205,12 +205,13 @@ class ChatCog(commands.Cog):
|
|||||||
await typing_ctx.__aexit__(None, None, None)
|
await typing_ctx.__aexit__(None, None, None)
|
||||||
|
|
||||||
# Strip leaked metadata the LLM may echo back.
|
# Strip leaked metadata the LLM may echo back.
|
||||||
# The LLM paraphrases/reformats injected context in unpredictable ways,
|
# The LLM often dumps paraphrased context and style labels in [brackets]
|
||||||
# so nuke any [bracketed block] that sits on its own line — real roasts
|
# before/between its actual answer. Split on those bracket lines and
|
||||||
# don't use standalone bracketed text.
|
# keep only the last non-empty segment — the real roast is always last.
|
||||||
if response:
|
if response:
|
||||||
response = re.sub(r"^\s*\[[^\]]*\]\s*$", "", response, flags=re.MULTILINE)
|
segments = re.split(r"^\s*\[[^\]]*\]\s*$", response, flags=re.MULTILINE)
|
||||||
response = re.sub(r"\n{2,}", "\n", response).strip()
|
segments = [s.strip() for s in segments if s.strip()]
|
||||||
|
response = segments[-1] if segments else ""
|
||||||
|
|
||||||
if not response:
|
if not response:
|
||||||
log_channel = discord.utils.get(message.guild.text_channels, name="bcs-log")
|
log_channel = discord.utils.get(message.guild.text_channels, name="bcs-log")
|
||||||
@@ -317,10 +318,11 @@ class ChatCog(commands.Cog):
|
|||||||
recent_bot_replies=recent_bot_replies,
|
recent_bot_replies=recent_bot_replies,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Strip leaked metadata (same catch-all as main chat path)
|
# Strip leaked metadata (same approach as main chat path)
|
||||||
if response:
|
if response:
|
||||||
response = re.sub(r"^\s*\[[^\]]*\]\s*$", "", response, flags=re.MULTILINE)
|
segments = re.split(r"^\s*\[[^\]]*\]\s*$", response, flags=re.MULTILINE)
|
||||||
response = re.sub(r"\n{2,}", "\n", response).strip()
|
segments = [s.strip() for s in segments if s.strip()]
|
||||||
|
response = segments[-1] if segments else ""
|
||||||
|
|
||||||
if not response:
|
if not response:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user