Spaces:
Sleeping
Sleeping
Commit
·
4f41461
1
Parent(s):
eb321a3
added the logging about prompting to check
Browse files- chat_handler.py +1 -1
- index_retriever.py +56 -34
chat_handler.py
CHANGED
|
@@ -116,7 +116,7 @@ class ChatHandler:
|
|
| 116 |
<h3 style='color: #63b3ed; margin-top: 0;'>Ответ (Модель: {current_model}):</h3>
|
| 117 |
<div style='line-height: 1.6; font-size: 16px;'>{response.response}</div>
|
| 118 |
<div style='margin-top: 15px; padding-top: 10px; border-top: 1px solid #4a5568; font-size: 14px; color: #a0aec0;'>
|
| 119 |
-
Время обработки: {processing_time:.2f} секунд
|
| 120 |
</div>
|
| 121 |
</div>"""
|
| 122 |
|
|
|
|
| 116 |
<h3 style='color: #63b3ed; margin-top: 0;'>Ответ (Модель: {current_model}):</h3>
|
| 117 |
<div style='line-height: 1.6; font-size: 16px;'>{response.response}</div>
|
| 118 |
<div style='margin-top: 15px; padding-top: 10px; border-top: 1px solid #4a5568; font-size: 14px; color: #a0aec0;'>
|
| 119 |
+
Время обработки: {processing_time:.2f} секунд
|
| 120 |
</div>
|
| 121 |
</div>"""
|
| 122 |
|
index_retriever.py
CHANGED
|
@@ -79,40 +79,62 @@ class IndexRetriever:
|
|
| 79 |
return False
|
| 80 |
|
| 81 |
def create_query_engine(self):
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
def switch_model(self, model_name):
|
| 118 |
try:
|
|
|
|
| 79 |
return False
|
| 80 |
|
| 81 |
def create_query_engine(self):
|
| 82 |
+
try:
|
| 83 |
+
log_message(f"Применяется промпт: {self.config.PROMPT_SIMPLE_POISK[:100]}...")
|
| 84 |
+
|
| 85 |
+
bm25_retriever = BM25Retriever.from_defaults(
|
| 86 |
+
docstore=self.vector_index.docstore,
|
| 87 |
+
similarity_top_k=15
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
vector_retriever = VectorIndexRetriever(
|
| 91 |
+
index=self.vector_index,
|
| 92 |
+
similarity_top_k=20,
|
| 93 |
+
similarity_cutoff=0.5
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
hybrid_retriever = QueryFusionRetriever(
|
| 97 |
+
[vector_retriever, bm25_retriever],
|
| 98 |
+
similarity_top_k=30,
|
| 99 |
+
num_queries=1
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
custom_prompt_template = PromptTemplate(self.config.PROMPT_SIMPLE_POISK)
|
| 103 |
+
response_synthesizer = get_response_synthesizer(
|
| 104 |
+
response_mode=ResponseMode.TREE_SUMMARIZE,
|
| 105 |
+
text_qa_template=custom_prompt_template
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
self.query_engine = RetrieverQueryEngine(
|
| 109 |
+
retriever=hybrid_retriever,
|
| 110 |
+
response_synthesizer=response_synthesizer
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
log_message("Query engine успешно создан с кастомным промптом")
|
| 114 |
+
|
| 115 |
+
except Exception as e:
|
| 116 |
+
log_message(f"Ошибка создания query engine: {str(e)}")
|
| 117 |
+
raise
|
| 118 |
+
|
| 119 |
+
def query(self, question):
|
| 120 |
+
"""Метод для выполнения запроса с применением промпта"""
|
| 121 |
+
if self.query_engine is None:
|
| 122 |
+
log_message("❌ Query engine не инициализирован")
|
| 123 |
+
return "❌ Система не инициализирована"
|
| 124 |
+
|
| 125 |
+
try:
|
| 126 |
+
log_message(f"Обрабатываю запрос: {question}")
|
| 127 |
+
log_message(f"Используется промпт: {self.config.PROMPT_SIMPLE_POISK[:100]}...")
|
| 128 |
+
|
| 129 |
+
response = self.query_engine.query(question)
|
| 130 |
+
log_message(f"Ответ получен, длина: {len(str(response))}")
|
| 131 |
+
|
| 132 |
+
return str(response)
|
| 133 |
+
|
| 134 |
+
except Exception as e:
|
| 135 |
+
error_msg = f"Ошибка обработки запроса: {str(e)}"
|
| 136 |
+
log_message(error_msg)
|
| 137 |
+
return f"❌ {error_msg}"
|
| 138 |
|
| 139 |
def switch_model(self, model_name):
|
| 140 |
try:
|