Spaces:
Paused
Paused
Daniel Marques
commited on
Commit
·
9117ff3
1
Parent(s):
48c871b
feat: add v1
Browse files
main.py
CHANGED
@@ -213,17 +213,16 @@ async def create_upload_file(file: UploadFile):
|
|
213 |
|
214 |
return {"filename": file.filename}
|
215 |
|
216 |
-
@api_app.websocket("/ws/{
|
217 |
-
async def
|
218 |
global QA
|
219 |
|
220 |
-
await socket_manager.add_user_to_room(room_id, websocket)
|
221 |
-
|
222 |
message = {
|
223 |
-
"message": f"Student {user_id} connected
|
224 |
}
|
225 |
|
226 |
-
await socket_manager.
|
|
|
227 |
|
228 |
try:
|
229 |
while True:
|
@@ -231,29 +230,30 @@ async def websocket_endpoint_room(websocket: WebSocket, room_id: str, user_id: s
|
|
231 |
|
232 |
prompt_response_dict = sendPromptChain(QA, data)
|
233 |
|
234 |
-
await socket_manager.broadcast_to_room(
|
235 |
|
236 |
except WebSocketDisconnect:
|
237 |
-
await socket_manager.remove_user_from_room(
|
238 |
|
239 |
message = {
|
240 |
-
"message": f"Student {user_id} disconnected
|
241 |
}
|
242 |
|
243 |
-
await socket_manager.broadcast_to_room(
|
244 |
except RuntimeError as error:
|
245 |
print(error)
|
246 |
|
247 |
-
@api_app.websocket("/ws/{user_id}")
|
248 |
-
async def
|
249 |
global QA
|
250 |
|
|
|
|
|
251 |
message = {
|
252 |
-
"message": f"Student {user_id} connected"
|
253 |
}
|
254 |
|
255 |
-
await socket_manager.
|
256 |
-
await socket_manager.broadcast_to_room(user_id, json.dumps(message))
|
257 |
|
258 |
try:
|
259 |
while True:
|
@@ -261,15 +261,16 @@ async def websocket_endpoint_student(websocket: WebSocket, user_id: str):
|
|
261 |
|
262 |
prompt_response_dict = sendPromptChain(QA, data)
|
263 |
|
264 |
-
await socket_manager.broadcast_to_room(
|
265 |
|
266 |
except WebSocketDisconnect:
|
267 |
-
await socket_manager.remove_user_from_room(
|
268 |
|
269 |
message = {
|
270 |
-
"message": f"Student {user_id} disconnected"
|
271 |
}
|
272 |
|
273 |
-
await socket_manager.broadcast_to_room(
|
274 |
except RuntimeError as error:
|
275 |
print(error)
|
|
|
|
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:
|
|
|
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 |
+
await socket_manager.add_user_to_room(room_id, websocket)
|
251 |
+
|
252 |
message = {
|
253 |
+
"message": f"Student {user_id} connected to the classroom"
|
254 |
}
|
255 |
|
256 |
+
await socket_manager.broadcast_to_room(room_id, json.dumps(message))
|
|
|
257 |
|
258 |
try:
|
259 |
while True:
|
|
|
261 |
|
262 |
prompt_response_dict = sendPromptChain(QA, data)
|
263 |
|
264 |
+
await socket_manager.broadcast_to_room(room_id, json.dumps(prompt_response_dict))
|
265 |
|
266 |
except WebSocketDisconnect:
|
267 |
+
await socket_manager.remove_user_from_room(room_id, websocket)
|
268 |
|
269 |
message = {
|
270 |
+
"message": f"Student {user_id} disconnected from room - {room_id}"
|
271 |
}
|
272 |
|
273 |
+
await socket_manager.broadcast_to_room(room_id, json.dumps(message))
|
274 |
except RuntimeError as error:
|
275 |
print(error)
|
276 |
+
|