Daniel Marques commited on
Commit
7b6b04f
1 Parent(s): 0fa1208

fix: memory error

Browse files
Files changed (1) hide show
  1. main.py +43 -43
main.py CHANGED
@@ -78,7 +78,7 @@ def sendPromptChain(QA, user_prompt):
78
 
79
  return prompt_response_dict;
80
 
81
- socket_manager = WebSocketManager()
82
 
83
  app = FastAPI(title="homepage-app")
84
  api_app = FastAPI(title="api app")
@@ -213,63 +213,63 @@ async def create_upload_file(file: UploadFile):
213
 
214
  return {"filename": file.filename}
215
 
216
- @api_app.websocket("/ws/{user_id}")
217
- async def websocket_endpoint_student(websocket: WebSocket, user_id: str):
218
- global QA
219
 
220
- message = {
221
- "message": f"Student {user_id} connected"
222
- }
223
 
224
- await socket_manager.add_user_to_room(user_id, websocket)
225
- await socket_manager.broadcast_to_room(user_id, json.dumps(message))
226
 
227
- try:
228
- while True:
229
- data = await websocket.receive_text()
230
 
231
- prompt_response_dict = sendPromptChain(QA, data)
232
 
233
- await socket_manager.broadcast_to_room(user_id, json.dumps(prompt_response_dict))
234
 
235
- except WebSocketDisconnect:
236
- await socket_manager.remove_user_from_room(user_id, websocket)
237
 
238
- message = {
239
- "message": f"Student {user_id} disconnected"
240
- }
241
 
242
- await socket_manager.broadcast_to_room(user_id, json.dumps(message))
243
- except RuntimeError as error:
244
- print(error)
245
 
246
- @api_app.websocket("/ws/{room_id}/{user_id}")
247
- async def websocket_endpoint_room(websocket: WebSocket, room_id: str, user_id: str):
248
- global QA
249
 
250
- message = {
251
- "message": f"Student {user_id} connected to the classroom"
252
- }
253
 
254
- await socket_manager.add_user_to_room(room_id, websocket)
255
- await socket_manager.broadcast_to_room(room_id, json.dumps(message))
256
 
257
- try:
258
- while True:
259
- data = await websocket.receive_text()
260
 
261
- prompt_response_dict = sendPromptChain(QA, data)
262
 
263
- await socket_manager.broadcast_to_room(room_id, json.dumps(prompt_response_dict))
264
 
265
- except WebSocketDisconnect:
266
- await socket_manager.remove_user_from_room(room_id, websocket)
267
 
268
- message = {
269
- "message": f"Student {user_id} disconnected from room - {room_id}"
270
- }
271
 
272
- await socket_manager.broadcast_to_room(room_id, json.dumps(message))
273
- except RuntimeError as error:
274
- print(error)
275
 
 
78
 
79
  return prompt_response_dict;
80
 
81
+ # socket_manager = WebSocketManager()
82
 
83
  app = FastAPI(title="homepage-app")
84
  api_app = FastAPI(title="api app")
 
213
 
214
  return {"filename": file.filename}
215
 
216
+ # @api_app.websocket("/ws/{user_id}")
217
+ # async def websocket_endpoint_student(websocket: WebSocket, user_id: str):
218
+ # global QA
219
 
220
+ # message = {
221
+ # "message": f"Student {user_id} connected"
222
+ # }
223
 
224
+ # await socket_manager.add_user_to_room(user_id, websocket)
225
+ # await socket_manager.broadcast_to_room(user_id, json.dumps(message))
226
 
227
+ # try:
228
+ # while True:
229
+ # data = await websocket.receive_text()
230
 
231
+ # prompt_response_dict = sendPromptChain(QA, data)
232
 
233
+ # await socket_manager.broadcast_to_room(user_id, json.dumps(prompt_response_dict))
234
 
235
+ # except WebSocketDisconnect:
236
+ # await socket_manager.remove_user_from_room(user_id, websocket)
237
 
238
+ # message = {
239
+ # "message": f"Student {user_id} disconnected"
240
+ # }
241
 
242
+ # await socket_manager.broadcast_to_room(user_id, json.dumps(message))
243
+ # except RuntimeError as error:
244
+ # print(error)
245
 
246
+ # @api_app.websocket("/ws/{room_id}/{user_id}")
247
+ # async def websocket_endpoint_room(websocket: WebSocket, room_id: str, user_id: str):
248
+ # global QA
249
 
250
+ # message = {
251
+ # "message": f"Student {user_id} connected to the classroom"
252
+ # }
253
 
254
+ # await socket_manager.add_user_to_room(room_id, websocket)
255
+ # await socket_manager.broadcast_to_room(room_id, json.dumps(message))
256
 
257
+ # try:
258
+ # while True:
259
+ # data = await websocket.receive_text()
260
 
261
+ # prompt_response_dict = sendPromptChain(QA, data)
262
 
263
+ # await socket_manager.broadcast_to_room(room_id, json.dumps(prompt_response_dict))
264
 
265
+ # except WebSocketDisconnect:
266
+ # await socket_manager.remove_user_from_room(room_id, websocket)
267
 
268
+ # message = {
269
+ # "message": f"Student {user_id} disconnected from room - {room_id}"
270
+ # }
271
 
272
+ # await socket_manager.broadcast_to_room(room_id, json.dumps(message))
273
+ # except RuntimeError as error:
274
+ # print(error)
275