Spaces:
Paused
Paused
Daniel Marques
commited on
Commit
·
f1368ae
1
Parent(s):
9117ff3
feat: add v1
Browse files
main.py
CHANGED
@@ -55,7 +55,7 @@ QA = RetrievalQA.from_chain_type(
|
|
55 |
},
|
56 |
)
|
57 |
|
58 |
-
def sendPromptChain(QA, user_prompt):
|
59 |
|
60 |
res = QA(user_prompt)
|
61 |
|
@@ -64,6 +64,7 @@ def sendPromptChain(QA, user_prompt):
|
|
64 |
prompt_response_dict = {
|
65 |
"Prompt": user_prompt,
|
66 |
"Answer": answer,
|
|
|
67 |
}
|
68 |
|
69 |
prompt_response_dict["Sources"] = []
|
@@ -74,11 +75,8 @@ def sendPromptChain(QA, user_prompt):
|
|
74 |
|
75 |
return prompt_response_dict;
|
76 |
|
77 |
-
|
78 |
socket_manager = WebSocketManager()
|
79 |
|
80 |
-
|
81 |
-
|
82 |
app = FastAPI(title="homepage-app")
|
83 |
api_app = FastAPI(title="api app")
|
84 |
|
@@ -247,19 +245,18 @@ async def websocket_endpoint_student(websocket: WebSocket, user_id: str):
|
|
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:
|
260 |
data = await websocket.receive_text()
|
261 |
|
262 |
-
prompt_response_dict = sendPromptChain(QA, data)
|
263 |
|
264 |
await socket_manager.broadcast_to_room(room_id, json.dumps(prompt_response_dict))
|
265 |
|
|
|
55 |
},
|
56 |
)
|
57 |
|
58 |
+
def sendPromptChain(QA, user_prompt, isRoom=False):
|
59 |
|
60 |
res = QA(user_prompt)
|
61 |
|
|
|
64 |
prompt_response_dict = {
|
65 |
"Prompt": user_prompt,
|
66 |
"Answer": answer,
|
67 |
+
"Room": isRoom
|
68 |
}
|
69 |
|
70 |
prompt_response_dict["Sources"] = []
|
|
|
75 |
|
76 |
return prompt_response_dict;
|
77 |
|
|
|
78 |
socket_manager = WebSocketManager()
|
79 |
|
|
|
|
|
80 |
app = FastAPI(title="homepage-app")
|
81 |
api_app = FastAPI(title="api app")
|
82 |
|
|
|
245 |
async def websocket_endpoint_room(websocket: WebSocket, room_id: str, user_id: str):
|
246 |
global QA
|
247 |
|
|
|
|
|
248 |
message = {
|
249 |
"message": f"Student {user_id} connected to the classroom"
|
250 |
}
|
251 |
|
252 |
+
await socket_manager.add_user_to_room(room_id, websocket)
|
253 |
await socket_manager.broadcast_to_room(room_id, json.dumps(message))
|
254 |
|
255 |
try:
|
256 |
while True:
|
257 |
data = await websocket.receive_text()
|
258 |
|
259 |
+
prompt_response_dict = sendPromptChain(QA, data, True)
|
260 |
|
261 |
await socket_manager.broadcast_to_room(room_id, json.dumps(prompt_response_dict))
|
262 |
|