Spaces:
Paused
Paused
Daniel Marques
commited on
Commit
·
9b024c3
1
Parent(s):
42b3dea
feat: add backend
Browse files
main.py
CHANGED
@@ -212,9 +212,21 @@ async def websocket_endpoint(websocket: WebSocket, client_id: str):
|
|
212 |
|
213 |
try:
|
214 |
while True:
|
215 |
-
|
216 |
-
response = QA(inputs=
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
except WebSocketDisconnect:
|
220 |
print('disconnect')
|
|
|
212 |
|
213 |
try:
|
214 |
while True:
|
215 |
+
user_prompt = await websocket.receive_text()
|
216 |
+
response = QA(inputs=user_prompt, return_only_outputs=True, tags=f'{client_id}', include_run_info=True)
|
217 |
+
answer, docs = response["result"], response["source_documents"]
|
218 |
+
|
219 |
+
prompt_response_dict = {
|
220 |
+
"Prompt": user_prompt,
|
221 |
+
"Answer": answer,
|
222 |
+
}
|
223 |
+
|
224 |
+
prompt_response_dict["Sources"] = []
|
225 |
+
for document in docs:
|
226 |
+
prompt_response_dict["Sources"].append(
|
227 |
+
(os.path.basename(str(document.metadata["source"])), str(document.page_content))
|
228 |
+
)
|
229 |
+
await websocket.send_json(prompt_response_dict)
|
230 |
|
231 |
except WebSocketDisconnect:
|
232 |
print('disconnect')
|