Update services/chat_service.py
Browse files- services/chat_service.py +22 -20
services/chat_service.py
CHANGED
@@ -199,34 +199,36 @@ class ChatService:
|
|
199 |
try:
|
200 |
print("-----------------------------")
|
201 |
print("starting searches .... ")
|
202 |
-
# Run searches in parallel
|
203 |
-
product_task = asyncio.create_task(
|
204 |
-
self.data_service.search(query, top_k)
|
205 |
-
)
|
206 |
-
pdf_task = asyncio.create_task(
|
207 |
-
self.pdf_service.search(query, top_k)
|
208 |
-
)
|
209 |
-
faq_task = asyncio.create_task(
|
210 |
-
self.faq_service.search_faqs(query, top_k)
|
211 |
-
)
|
212 |
|
213 |
-
#
|
214 |
-
|
215 |
-
|
216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
-
|
219 |
-
|
220 |
-
'
|
221 |
-
'
|
222 |
-
'faqs': faqs
|
223 |
}
|
224 |
|
|
|
|
|
|
|
225 |
except Exception as e:
|
226 |
logger.error(f"Error searching sources: {e}")
|
227 |
return {'products': [], 'documents': [], 'faqs': []}
|
228 |
|
229 |
-
|
230 |
async def generate_response(
|
231 |
self,
|
232 |
prompt: str,
|
|
|
199 |
try:
|
200 |
print("-----------------------------")
|
201 |
print("starting searches .... ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
|
203 |
+
# Make sure the search methods are actually async
|
204 |
+
if not hasattr(self.data_service.search, '__await__'):
|
205 |
+
products = await asyncio.to_thread(self.data_service.search, query, top_k)
|
206 |
+
else:
|
207 |
+
products = await self.data_service.search(query, top_k)
|
208 |
+
|
209 |
+
if not hasattr(self.pdf_service.search, '__await__'):
|
210 |
+
pdfs = await asyncio.to_thread(self.pdf_service.search, query, top_k)
|
211 |
+
else:
|
212 |
+
pdfs = await self.pdf_service.search(query, top_k)
|
213 |
+
|
214 |
+
if not hasattr(self.faq_service.search_faqs, '__await__'):
|
215 |
+
faqs = await asyncio.to_thread(self.faq_service.search_faqs, query, top_k)
|
216 |
+
else:
|
217 |
+
faqs = await self.faq_service.search_faqs(query, top_k)
|
218 |
|
219 |
+
results = {
|
220 |
+
'products': products or [],
|
221 |
+
'documents': pdfs or [],
|
222 |
+
'faqs': faqs or []
|
|
|
223 |
}
|
224 |
|
225 |
+
print("Search results:", results)
|
226 |
+
return results
|
227 |
+
|
228 |
except Exception as e:
|
229 |
logger.error(f"Error searching sources: {e}")
|
230 |
return {'products': [], 'documents': [], 'faqs': []}
|
231 |
|
|
|
232 |
async def generate_response(
|
233 |
self,
|
234 |
prompt: str,
|