mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-21 07:55:18 +08:00
fix(dingtalk): normalize spacing around visible think markers
This commit is contained in:
@@ -7,10 +7,12 @@ _MARKER = re.compile(r"</?think>", re.IGNORECASE)
|
||||
|
||||
def visible_think_markers(content: str, markdown: bool = True) -> str:
|
||||
def replace(match):
|
||||
tag = match.group(0).lower()
|
||||
return "\n\n" + (f"`{tag}`" if markdown else tag) + "\n\n"
|
||||
tag = match.group(1).lower()
|
||||
separator = "\n\n" if markdown else "\n"
|
||||
return separator + (f"`{tag}`" if markdown else tag) + separator
|
||||
|
||||
return _MARKER.sub(replace, content).strip()
|
||||
# Normalize only marker boundaries; preserve paragraph spacing in the body.
|
||||
return re.sub(r"[ \t\r\n]*(</?think>)[ \t\r\n]*", replace, content, flags=re.IGNORECASE).strip()
|
||||
|
||||
|
||||
def card_text_fields(content: str) -> dict[str, str]:
|
||||
|
||||
Reference in New Issue
Block a user