File size: 710 Bytes
23bf579
 
 
 
 
 
 
 
 
9653435
 
23bf579
 
9653435
78ea7c0
9653435
 
 
 
23bf579
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# backend_agent/live_api.py
from fastapi import FastAPI, Request
import uvicorn

app = FastAPI()
routes_registry = {}

def add_dynamic_route(task_name, code_str):
    """
    Dynamically adds a placeholder route for a backend task.
    Currently executes safe placeholder logic.
    """
    route_path = "/" + task_name.replace(" ", "_").lower()
    
    async def dynamic_func(request: Request):
        # Placeholder for actual LLM code execution
        return {"message": f"Task '{task_name}' executed (placeholder)"}
    
    app.add_api_route(route_path, dynamic_func, methods=["GET","POST"])
    routes_registry[task_name] = route_path

def run_server():
    uvicorn.run(app, host="0.0.0.0", port=8000)