Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -112,7 +112,7 @@ history_aware_retriever = create_history_aware_retriever(llm, compression_retrie
|
|
112 |
|
113 |
# QA system prompt and chain
|
114 |
qa_system_prompt = """ You are a highly skilled information retrieval assistant. Use the following context to answer questions effectively.
|
115 |
-
If you don't know the answer,
|
116 |
Your answer should be in {language} language.
|
117 |
|
118 |
When responding to queries, follow these guidelines:
|
@@ -132,7 +132,7 @@ When responding to queries, follow these guidelines:
|
|
132 |
- The inline citations should be in the format [[1]], [[2]], etc., in the response with links to reference sources.
|
133 |
- AT THE END OF THE RESPONSE, LIST OUT THE CITATIONS WITH THEIR SOURCES. If there are multiple citations with same source url then only mention that single source url for all of those.
|
134 |
|
135 |
-
FOLLOW ALL THE GIVEN INSTRUCTIONS, FAILURE TO DO SO WILL RESULT IN TERMINATION OF THE CHAT.
|
136 |
{context}
|
137 |
"""
|
138 |
qa_prompt = ChatPromptTemplate.from_messages(
|
@@ -200,17 +200,9 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
200 |
complete_response += chunk['answer']
|
201 |
await websocket.send_json({'response': chunk['answer']})
|
202 |
|
203 |
-
if context:
|
204 |
-
citations = re.findall(r'\[(\d+)\]', complete_response)
|
205 |
-
citation_numbers = list(map(int, citations))
|
206 |
-
sources = dict()
|
207 |
-
for index, doc in enumerate(context):
|
208 |
-
if (index+1) in citation_numbers:
|
209 |
-
sources[f"[{index+1}]"] = doc.metadata["source"]
|
210 |
-
await websocket.send_json({'sources': sources})
|
211 |
-
|
212 |
await stream_response()
|
213 |
except Exception as e:
|
|
|
214 |
print(f"Error during message handling: {e}")
|
215 |
await websocket.send_json({'response': "Something went wrong, Please try again." + str(e)})
|
216 |
except WebSocketDisconnect:
|
|
|
112 |
|
113 |
# QA system prompt and chain
|
114 |
qa_system_prompt = """ You are a highly skilled information retrieval assistant. Use the following context to answer questions effectively.
|
115 |
+
If you don't know the answer, state that you don't know.
|
116 |
Your answer should be in {language} language.
|
117 |
|
118 |
When responding to queries, follow these guidelines:
|
|
|
132 |
- The inline citations should be in the format [[1]], [[2]], etc., in the response with links to reference sources.
|
133 |
- AT THE END OF THE RESPONSE, LIST OUT THE CITATIONS WITH THEIR SOURCES. If there are multiple citations with same source url then only mention that single source url for all of those.
|
134 |
|
135 |
+
FOLLOW ALL THE GIVEN INSTRUCTIONS, FAILURE TO DO SO WILL RESULT IN THE TERMINATION OF THE CHAT.
|
136 |
{context}
|
137 |
"""
|
138 |
qa_prompt = ChatPromptTemplate.from_messages(
|
|
|
200 |
complete_response += chunk['answer']
|
201 |
await websocket.send_json({'response': chunk['answer']})
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
await stream_response()
|
204 |
except Exception as e:
|
205 |
+
print(traceback.format_exc())
|
206 |
print(f"Error during message handling: {e}")
|
207 |
await websocket.send_json({'response': "Something went wrong, Please try again." + str(e)})
|
208 |
except WebSocketDisconnect:
|