Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -352,34 +352,33 @@ class VectorRAGSystem:
|
|
352 |
# JSON Schema для принуждения к структуре
|
353 |
schema = FinancialAnswer.model_json_schema()
|
354 |
|
355 |
-
prompt = f"""Ты
|
356 |
|
357 |
ВОПРОС: {query}
|
358 |
|
359 |
КОНТЕКСТ ИЗ ОТЧЕТА:
|
360 |
{context}
|
361 |
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
Отвечай ТОЛЬКО в формате JSON согласно схеме. Все тексты на русском языке."""
|
383 |
|
384 |
response = self.client.chat.completions.create(
|
385 |
model=self.generation_model,
|
@@ -393,16 +392,11 @@ class VectorRAGSystem:
|
|
393 |
print("Raw JSON response:", json_response)
|
394 |
|
395 |
# Парсим и валидируем JSON
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
return self._format_structured_response(validated_response)
|
400 |
-
except Exception as parse_error:
|
401 |
-
print(f"⚠️ Ошибка парсинга JSON: {parse_error}")
|
402 |
-
return self._generate_simple_answer(query, context)
|
403 |
-
|
404 |
except Exception as e:
|
405 |
-
print(f"⚠️ Ошибка
|
406 |
return self._generate_simple_answer(query, context)
|
407 |
|
408 |
def _generate_simple_answer(self, query: str, context: str) -> str:
|
|
|
352 |
# JSON Schema для принуждения к структуре
|
353 |
schema = FinancialAnswer.model_json_schema()
|
354 |
|
355 |
+
prompt = f"""Ты — эксперт по анализу финансовых отчетов ПАО Сбербанк. Проанализируй вопрос пользователя, используя Chain-of-Thought.
|
356 |
|
357 |
ВОПРОС: {query}
|
358 |
|
359 |
КОНТЕКСТ ИЗ ОТЧЕТА:
|
360 |
{context}
|
361 |
|
362 |
+
Отвечай строго JSON со следующими полями:
|
363 |
+
|
364 |
+
{{
|
365 |
+
"thinking": {{
|
366 |
+
"question_analysis": "<анализ вопроса>",
|
367 |
+
"information_found": "<что найдено в источниках>",
|
368 |
+
"reasoning_steps": ["<шаг 1>", "<шаг 2>", "..."],
|
369 |
+
"conclusion": "<краткий вывод>"
|
370 |
+
}},
|
371 |
+
"answer": "<основной ответ на русском языке>",
|
372 |
+
"confidence": <число от 0 до 1>,
|
373 |
+
"sources": [
|
374 |
+
{{
|
375 |
+
"page": <номер страницы>,
|
376 |
+
"relevance_score": <0–1>,
|
377 |
+
"content_preview": "<превью текста>"
|
378 |
+
}},
|
379 |
+
…
|
380 |
+
]
|
381 |
+
}}"""
|
|
|
382 |
|
383 |
response = self.client.chat.completions.create(
|
384 |
model=self.generation_model,
|
|
|
392 |
print("Raw JSON response:", json_response)
|
393 |
|
394 |
# Парсим и валидируем JSON
|
395 |
+
parsed = json.loads(json_response)
|
396 |
+
validated = FinancialAnswer(**parsed)
|
397 |
+
return self._format_structured_response(validated)
|
|
|
|
|
|
|
|
|
|
|
398 |
except Exception as e:
|
399 |
+
print(f"⚠️ Ошибка в _generate_structured_answer: {e}")
|
400 |
return self._generate_simple_answer(query, context)
|
401 |
|
402 |
def _generate_simple_answer(self, query: str, context: str) -> str:
|