Spaces:
Running
Running
fix
Browse files- app/main.py +11 -3
- app/rag.py +3 -4
app/main.py
CHANGED
@@ -53,11 +53,19 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int):
|
|
53 |
data = await websocket.receive_text()
|
54 |
data = data.strip()
|
55 |
if len(data) > 0:
|
56 |
-
|
57 |
-
|
58 |
-
message = {"time":current_time,"clientId":client_id,"message":text}
|
59 |
# await manager.broadcast(json.dumps(message))
|
60 |
await manager.send_personal_message(json.dumps(message), websocket)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
except WebSocketDisconnect:
|
62 |
manager.disconnect(websocket)
|
63 |
message = {"time":current_time,"clientId":client_id,"message":"Offline"}
|
|
|
53 |
data = await websocket.receive_text()
|
54 |
data = data.strip()
|
55 |
if len(data) > 0:
|
56 |
+
if not session_assistant.pdf_count > 0:
|
57 |
+
message = {"time":current_time,"clientId":client_id,"message":"Please, add a PDF document first."}
|
|
|
58 |
# await manager.broadcast(json.dumps(message))
|
59 |
await manager.send_personal_message(json.dumps(message), websocket)
|
60 |
+
else
|
61 |
+
print("FETCHING STREAM")
|
62 |
+
streaming_response = session_assistant.ask(data)
|
63 |
+
print("STARTING STREAM")
|
64 |
+
for text in streaming_response.response_gen:
|
65 |
+
message = {"time":current_time,"clientId":client_id,"message":text}
|
66 |
+
# await manager.broadcast(json.dumps(message))
|
67 |
+
await manager.send_personal_message(json.dumps(message), websocket)
|
68 |
+
print("ENDING STREAM")
|
69 |
except WebSocketDisconnect:
|
70 |
manager.disconnect(websocket)
|
71 |
message = {"time":current_time,"clientId":client_id,"message":"Offline"}
|
app/rag.py
CHANGED
@@ -107,11 +107,10 @@ class ChatPDF:
|
|
107 |
|
108 |
def ask(self, query: str):
|
109 |
logger.info("retrieving the response to the query")
|
110 |
-
|
111 |
-
return "Please, add a PDF document first."
|
112 |
-
|
113 |
streaming_response = self.query_engine.query(query)
|
114 |
-
|
|
|
115 |
|
116 |
def clear(self):
|
117 |
self.pdf_count = 0
|
|
|
107 |
|
108 |
def ask(self, query: str):
|
109 |
logger.info("retrieving the response to the query")
|
110 |
+
print("GENERATING STREAM")
|
|
|
|
|
111 |
streaming_response = self.query_engine.query(query)
|
112 |
+
print("PASSING STREAM")
|
113 |
+
return streaming_response
|
114 |
|
115 |
def clear(self):
|
116 |
self.pdf_count = 0
|