Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,15 @@ client = Client()
|
|
| 6 |
# --- Обработчик диалога ---
|
| 7 |
import re
|
| 8 |
from typing import List, Tuple, Any
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def strip_citations(text: str) -> str:
|
| 11 |
"""
|
|
@@ -170,7 +179,7 @@ def respond(message, history):
|
|
| 170 |
|
| 171 |
|
| 172 |
)
|
| 173 |
-
bot_message = strip_citations(f"{responsed.choices[0].message.content}")
|
| 174 |
|
| 175 |
except Exception as e:
|
| 176 |
bot_message = f"Ошибка: {str(e)}"
|
|
|
|
| 6 |
# --- Обработчик диалога ---
|
| 7 |
import re
|
| 8 |
from typing import List, Tuple, Any
|
| 9 |
+
def strip_md_refs(text: str) -> str:
|
| 10 |
+
"""
|
| 11 |
+
Удаляет из строки все конструкции вида [[N]](URL),
|
| 12 |
+
где N – произвольное число (может быть и несколько цифр).
|
| 13 |
+
Возвращает «чистый» текст без ссылок.
|
| 14 |
+
"""
|
| 15 |
+
# Шаблон: [[ любые цифры ]]( любой URL )
|
| 16 |
+
pattern = r'\[\[\d+\]\]\([^\)]*\)'
|
| 17 |
+
return re.sub(pattern, '', text)
|
| 18 |
|
| 19 |
def strip_citations(text: str) -> str:
|
| 20 |
"""
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
)
|
| 182 |
+
bot_message = strip_citations(f"{strip_md_refs(responsed.choices[0].message.content)}")
|
| 183 |
|
| 184 |
except Exception as e:
|
| 185 |
bot_message = f"Ошибка: {str(e)}"
|