Collapse blockquote and strip <think> blocks from AI responses
- blockquote expandable: replies are collapsed by default in Telegram - strip <think>...</think> sections (chain-of-thought from reasoning models like DeepSeek R1 / QwQ) before sending the response Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -626,12 +626,17 @@ class AIService:
|
||||
return ""
|
||||
content = getattr(message, "content", None)
|
||||
if isinstance(content, str):
|
||||
return content.strip()
|
||||
return self._strip_think(content)
|
||||
if isinstance(content, list):
|
||||
parts = []
|
||||
for part in content:
|
||||
text = getattr(part, "text", None)
|
||||
if isinstance(text, str):
|
||||
parts.append(text)
|
||||
return "\n".join(parts).strip()
|
||||
return self._strip_think("\n".join(parts))
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def _strip_think(text: str) -> str:
|
||||
import re
|
||||
return re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL).strip()
|
||||
|
||||
Reference in New Issue
Block a user