khalednabawi11 commited on
Commit
99639ba
·
verified ·
1 Parent(s): 3d6970c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -64,6 +64,7 @@ llm_pipeline = pipeline(
64
  generation_config=generation_config,
65
  device=model.device.index if model.device.type == "cuda" else -1
66
  )
 
67
  llm = HuggingFacePipeline(pipeline=llm_pipeline)
68
 
69
  retriever = vector_store.as_retriever(search_kwargs={"k": 3})
@@ -78,7 +79,6 @@ qa_chain = RetrievalQA.from_chain_type(
78
  # FastAPI setup
79
  app = FastAPI(title="Apollo RAG Medical Chatbot")
80
 
81
-
82
  class Query(BaseModel):
83
  question: str = Field(..., example="ما هي اسباب تساقط الشعر ؟", min_length=3)
84
 
@@ -155,18 +155,17 @@ async def ask(query: Query):
155
  timeout_callback = TimeoutCallback(timeout_seconds=60)
156
 
157
 
158
- docs = retriever.get_relevant_documents(query.question)
159
- if not docs:
160
- logger.warning("No documents retrieved from Qdrant for the question.")
161
- else:
162
- logger.debug(f"Retrieved documents: {[doc.page_content for doc in docs[:1]]}")
163
-
164
 
165
  loop = asyncio.get_event_loop()
166
 
167
  answer = await asyncio.wait_for(
168
  # qa_chain.run(prompt, callbacks=[timeout_callback]),
169
- loop.run_in_executor(None, qa_chain.run, prompt),
170
  timeout=360
171
  )
172
 
 
64
  generation_config=generation_config,
65
  device=model.device.index if model.device.type == "cuda" else -1
66
  )
67
+
68
  llm = HuggingFacePipeline(pipeline=llm_pipeline)
69
 
70
  retriever = vector_store.as_retriever(search_kwargs={"k": 3})
 
79
  # FastAPI setup
80
  app = FastAPI(title="Apollo RAG Medical Chatbot")
81
 
 
82
  class Query(BaseModel):
83
  question: str = Field(..., example="ما هي اسباب تساقط الشعر ؟", min_length=3)
84
 
 
155
  timeout_callback = TimeoutCallback(timeout_seconds=60)
156
 
157
 
158
+ # docs = retriever.get_relevant_documents(query.question)
159
+ # if not docs:
160
+ # logger.warning("No documents retrieved from Qdrant for the question.")
161
+ # else:
162
+ # logger.debug(f"Retrieved documents: {[doc.page_content for doc in docs[:1]]}")
 
163
 
164
  loop = asyncio.get_event_loop()
165
 
166
  answer = await asyncio.wait_for(
167
  # qa_chain.run(prompt, callbacks=[timeout_callback]),
168
+ loop.run_in_executor(None, qa_chain.run, query.question),
169
  timeout=360
170
  )
171