AnatoliiG commited on
Commit ·
929276c
1
Parent(s): f9aca5d
Update callbacks.py
Browse files- src/ui/callbacks.py +26 -0
src/ui/callbacks.py
CHANGED
|
@@ -4,6 +4,32 @@ from src.core.engine import engine
|
|
| 4 |
from src.utils.helpers import get_clean_text
|
| 5 |
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def bot_response(history, system_prompt, temperature, max_tokens):
|
| 8 |
messages = [{"role": "system", "content": system_prompt}]
|
| 9 |
for msg in history[-7:]:
|
|
|
|
| 4 |
from src.utils.helpers import get_clean_text
|
| 5 |
|
| 6 |
|
| 7 |
+
def user_input(user_message, history):
|
| 8 |
+
"""
|
| 9 |
+
Добавляет сообщение пользователя в историю и очищает поле ввода.
|
| 10 |
+
"""
|
| 11 |
+
if not user_message:
|
| 12 |
+
return None, history
|
| 13 |
+
history = history or []
|
| 14 |
+
history.append({"role": "user", "content": str(user_message)})
|
| 15 |
+
return "", history
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def set_interactive(is_interactive):
|
| 19 |
+
"""
|
| 20 |
+
Блокирует/разблокирует интерфейс во время генерации.
|
| 21 |
+
"""
|
| 22 |
+
return (
|
| 23 |
+
gr.update(
|
| 24 |
+
interactive=is_interactive,
|
| 25 |
+
placeholder="Wait..."
|
| 26 |
+
if not is_interactive
|
| 27 |
+
else "Type your message here...",
|
| 28 |
+
),
|
| 29 |
+
gr.update(interactive=is_interactive),
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
def bot_response(history, system_prompt, temperature, max_tokens):
|
| 34 |
messages = [{"role": "system", "content": system_prompt}]
|
| 35 |
for msg in history[-7:]:
|