|
17 | 17 | WebsocketMessageType, |
18 | 18 | ) |
19 | 19 |
|
| 20 | + |
20 | 21 | def clean_citations(text: str) -> str: |
21 | 22 | """Remove citation markers from agent responses while preserving formatting.""" |
22 | 23 | if not text: |
23 | 24 | return text |
24 | | - |
| 25 | + |
25 | 26 | # Remove citation patterns like [9:0|source], [9:1|source], etc. |
26 | 27 | text = re.sub(r'\[\d+:\d+\|source\]', '', text) |
27 | | - |
28 | | - #Remove other common citation pattern |
| 28 | + |
| 29 | + # Remove other common citation pattern |
29 | 30 | text = re.sub(r'\[\s*source\s*\]', '', text, flags=re.IGNORECASE) |
30 | 31 | text = re.sub(r'\[\d+\]', '', text) |
31 | 32 | text = re.sub(r'【[^】]*】', '', text) # Unicode brackets |
32 | 33 | text = re.sub(r'\(source:[^)]*\)', '', text, flags=re.IGNORECASE) |
33 | 34 | text = re.sub(r'\[source:[^\]]*\]', '', text, flags=re.IGNORECASE) |
34 | | - |
| 35 | + |
| 36 | + |
35 | 37 | return text |
36 | 38 |
|
37 | 39 | def agent_response_callback(message: ChatMessageContent, user_id: str = None) -> None: |
@@ -96,7 +98,7 @@ async def streaming_agent_response_callback( |
96 | 98 | try: |
97 | 99 | message = AgentMessageStreaming( |
98 | 100 | agent_name=streaming_message.name or "Unknown Agent", |
99 | | - content=clean_citations(streaming_message.content), |
| 101 | + content=clean_citations(streaming_message.content) or "", |
100 | 102 | is_final=is_final, |
101 | 103 | ) |
102 | 104 | await connection_config.send_status_update_async( |
|
0 commit comments