To get around the POST request timeout errors, I’ve implemented a websocket variant of my code (below) that would send a task client side and awaits a response from my server side (whether the task has been completed successfully or unsuccessfully)
However, I can’t figure out why the Websocket would disconnect upon completing the “run_interaction” method. Note: run_interaction is not breaking as I put a debug statement and got (below) this on the console.
Completed result: {'text_output': 'The payment has been successfully processed, and the goods will be shipped soon.', 'session_id': '1519915-f3e6dc73-73ea-42b5-93a7-d3b395c728e6'}
Current specs:
Client is using Quart
Server is using FastAPI
Server side:
@app.websocket("/new_task")
async def websocket_new_task(websocket: WebSocket):
await websocket.accept()
try:
data = await websocket.receive_json()
print("Incoming Data", data)
context = data.get('context', '')
org_id = data.get('org_id', '')
url = data.get('url', '')
task = data.get("task", '')
token = data.get('token', '')
input = InteractionInput(
url=url,
user_input=task,
token=token,
base_prompt=""
)
result = await run_interaction(input, "generalist_endpoint", context=context, task_description=task)
print(f"Completed result: {result}")
task_summary = f"Task created for org {org_id} with context: {context}. Result: {result.get('text_output', 'No output')}"
await websocket.send_json({"response": 200, "task_summary": task_summary})
except WebSocketDisconnect:
print("WebSocket connection closed unexpectedly.")
except Exception as e:
print(f"An error occurred: {str(e)}")
await websocket.send_json({"response": 500, "error": "Internal server error"})
Client side:
async def perform_action(self, call_sid, context):
uri = "wss://localhost:5515/new_task"
task = """request
"""
async with websockets.connect(uri) as websocket:
task_details = {
"task": task,
"context": context,
"org_id": "orgid-placeholder",
"url": "url-placeholder",
"token": "t-placeholder",
}
await websocket.send(json.dumps(task_details))
print("Task details sent, waiting for response...")
response = await websocket.recv()
print("Response received from the server:")
print(response)
if (call_sid):
self.track.create_or_update_track(call_sid, on_hold=False)
return response
Thanks for your responses and help in advance.