Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,7 @@ def get_apartment_data(query):
|
|
| 34 |
|
| 35 |
# Функция для обработки запросов и ответов
|
| 36 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 37 |
-
print("Получен запрос:", message)
|
| 38 |
print("История общения:", history)
|
| 39 |
|
| 40 |
try:
|
|
@@ -47,20 +47,18 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 47 |
f"Класс: {row['project_class']}, Площадь: {row['apt_area']}"
|
| 48 |
for row in response
|
| 49 |
])
|
| 50 |
-
history.append(
|
| 51 |
-
|
|
|
|
| 52 |
else:
|
| 53 |
-
history.append(
|
| 54 |
-
|
|
|
|
| 55 |
else:
|
| 56 |
# Генерация ответа от модели
|
| 57 |
messages = [{"role": "system", "content": system_message}]
|
| 58 |
-
for
|
| 59 |
-
|
| 60 |
-
messages.append({"role": "user", "content": user_message})
|
| 61 |
-
if bot_response:
|
| 62 |
-
messages.append({"role": "assistant", "content": bot_response})
|
| 63 |
-
|
| 64 |
messages.append({"role": "user", "content": message})
|
| 65 |
|
| 66 |
response = ""
|
|
@@ -73,11 +71,12 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 73 |
):
|
| 74 |
token = message.choices[0].delta.content
|
| 75 |
response += token
|
| 76 |
-
yield response
|
| 77 |
except Exception as e:
|
| 78 |
print(f"Ошибка обработки запроса: {e}")
|
| 79 |
-
history.append(
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
# Интерфейс Gradio
|
| 83 |
demo = gr.ChatInterface(
|
|
|
|
| 34 |
|
| 35 |
# Функция для обработки запросов и ответов
|
| 36 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 37 |
+
print("Получен запрос:", message)
|
| 38 |
print("История общения:", history)
|
| 39 |
|
| 40 |
try:
|
|
|
|
| 47 |
f"Класс: {row['project_class']}, Площадь: {row['apt_area']}"
|
| 48 |
for row in response
|
| 49 |
])
|
| 50 |
+
history.append({"role": "user", "content": message})
|
| 51 |
+
history.append({"role": "assistant", "content": result})
|
| 52 |
+
yield result, history
|
| 53 |
else:
|
| 54 |
+
history.append({"role": "user", "content": message})
|
| 55 |
+
history.append({"role": "assistant", "content": "Извините, подходящих вариантов не найдено."})
|
| 56 |
+
yield "Извините, подходящих вариантов не найдено.", history
|
| 57 |
else:
|
| 58 |
# Генерация ответа от модели
|
| 59 |
messages = [{"role": "system", "content": system_message}]
|
| 60 |
+
for item in history:
|
| 61 |
+
messages.append(item)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
messages.append({"role": "user", "content": message})
|
| 63 |
|
| 64 |
response = ""
|
|
|
|
| 71 |
):
|
| 72 |
token = message.choices[0].delta.content
|
| 73 |
response += token
|
| 74 |
+
yield response, history
|
| 75 |
except Exception as e:
|
| 76 |
print(f"Ошибка обработки запроса: {e}")
|
| 77 |
+
history.append({"role": "user", "content": message})
|
| 78 |
+
history.append({"role": "assistant", "content": "Произошла ошибка при обработке вашего запроса."})
|
| 79 |
+
yield "Произошла ошибка при обработке вашего запроса.", history
|
| 80 |
|
| 81 |
# Интерфейс Gradio
|
| 82 |
demo = gr.ChatInterface(
|