-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
48 lines (42 loc) · 1.1 KB
/
Copy pathapi.py
File metadata and controls
48 lines (42 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import StreamingResponse
from pydantic import BaseModel
from agents import agent
from database import get_db, Tasks
import time
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"]
)
class RunRequest(BaseModel):
task: str
folder_path: str
def stream_agent(request):
db = next(get_db())
task = Tasks(task=request.task, status="running")
db.add(task)
db.commit()
for chunk in agent.stream({
"task": request.task,
"plan": "",
"architecture": "",
"folder_path": request.folder_path,
"file_name": "",
"code": "",
"tests": "",
"test_results": "",
"status": "",
"retry_count": 0
}):
node_name = list(chunk.keys())[0]
yield f"{node_name} done\n"
task.status = "done"
db.commit()
db.close()
@app.post("/run")
def run(request: RunRequest):
return StreamingResponse(stream_agent(request), media_type="text/plain")