Chris4K commited on
Commit
4fdfa4c
·
verified ·
1 Parent(s): 0ad8cb9

Update services/chat_service.py

Browse files
Files changed (1) hide show
  1. 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
- # Gather results
214
- products, pdfs, faqs = await asyncio.gather(
215
- product_task, pdf_task, faq_task
216
- )
 
 
 
 
 
 
 
 
 
 
 
217
 
218
- print(products)
219
- return {
220
- 'products': products,
221
- 'documents': pdfs,
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,