(request: Request, username: str)
| 60 | |
| 61 | @app.post('/run/{username}') |
| 62 | async def run_script(request: Request, username: str): |
| 63 | user_workspace = os.path.join("workspace", username) |
| 64 | |
| 65 | data = await request.json() |
| 66 | llm_model = data.get('llm_model', '') |
| 67 | api_key = data.get('api_key', '') |
| 68 | |
| 69 | command = [ |
| 70 | "python", "../../run_graph.py", |
| 71 | "--llm", llm_model, |
| 72 | "--key", api_key |
| 73 | ] |
| 74 | |
| 75 | # Get or create a handler for the user |
| 76 | if username not in handlers: |
| 77 | handlers[username] = ProcessHandler() |
| 78 | |
| 79 | handler = handlers[username] |
| 80 | # start process in background |
| 81 | async def stream_response(): |
| 82 | asyncio.create_task(handler.run(command, user_workspace)) # start the process as a task |
| 83 | async for output in handler.get_stream(): |
| 84 | if isinstance(output, dict): |
| 85 | yield f"data: {output}\n\n" # Send final status |
| 86 | break |
| 87 | yield f"data: {output}\n\n" |
| 88 | |
| 89 | return StreamingResponse(stream_response(), media_type="text/event-stream") |
| 90 | |
| 91 | @app.get('/status/{username}') |
| 92 | async def check_status(username: str): |
nothing calls this directly
no test coverage detected