Spaces:
Runtime error
Runtime error
Aleksandr Maiorov
commited on
Commit
·
13d6e67
1
Parent(s):
484c62c
v 0.1
Browse files- правка формата ответа
app.py
CHANGED
@@ -54,22 +54,13 @@ llm = LlamaCPP(
|
|
54 |
verbose=True,
|
55 |
)
|
56 |
|
57 |
-
def generate_response(
|
58 |
try:
|
59 |
-
|
60 |
-
|
61 |
-
logger.info(prompt)
|
62 |
-
|
63 |
-
response = prompt['choices'][0]['text']
|
64 |
-
|
65 |
-
# Отправка ответа
|
66 |
-
if response:
|
67 |
-
return response
|
68 |
-
|
69 |
-
return 'Произошла ошибка при обработке запроса'
|
70 |
-
|
71 |
except Exception as e:
|
72 |
-
logger.error(f"Ошибка обработки
|
|
|
73 |
|
74 |
|
75 |
@app.get("/")
|
@@ -87,5 +78,5 @@ async def predict(text: str):
|
|
87 |
# Генерация ответа с помощью модели
|
88 |
logger.info('post/predict')
|
89 |
response = llm.complete(text)
|
90 |
-
|
91 |
-
return {"response":
|
|
|
54 |
verbose=True,
|
55 |
)
|
56 |
|
57 |
+
def generate_response(completion_response):
|
58 |
try:
|
59 |
+
response_text = completion_response.text
|
60 |
+
return response_text.strip() if response_text else "Пустой ответ"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
except Exception as e:
|
62 |
+
logger.error(f"Ошибка обработки ответа: {str(e)}")
|
63 |
+
return "Ошибка генерации"
|
64 |
|
65 |
|
66 |
@app.get("/")
|
|
|
78 |
# Генерация ответа с помощью модели
|
79 |
logger.info('post/predict')
|
80 |
response = llm.complete(text)
|
81 |
+
text_response = generate_response(response)
|
82 |
+
return {"response": text_response}
|