YashashMathur commited on
Commit
7bffd13
·
verified ·
1 Parent(s): edc3562

Add mock worker for demo

Browse files
Files changed (1) hide show
  1. mock_worker.py +58 -0
mock_worker.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Mock Worker for Demo - No GPU needed
3
+ Use this to test the multi-agent architecture without heavy compute.
4
+ """
5
+
6
+ from fastapi import FastAPI, Request
7
+ from fastapi.responses import JSONResponse
8
+ import random
9
+ import json
10
+
11
+ app = FastAPI()
12
+
13
+ RESPONSES = [
14
+ {
15
+ "output": "I have analyzed the request and determined it is safe to proceed.",
16
+ "status": "success",
17
+ "reasoning": "No policy violations detected in the worker output.",
18
+ },
19
+ {
20
+ "output": "Blocked: Detected potential security concern in the request.",
21
+ "status": "success",
22
+ "reasoning": "PII or sensitive data access pattern detected.",
23
+ },
24
+ {
25
+ "output": "Escalating to supervisor for further review.",
26
+ "status": "success",
27
+ "reasoning": "Ambiguous request requires human oversight.",
28
+ },
29
+ ]
30
+
31
+
32
+ @app.post("/execute")
33
+ async def execute_task(request: Request):
34
+ task = await request.json()
35
+ print(f"Mock worker received: {task.get('task_id', 'unknown')}")
36
+
37
+ # Return random response
38
+ response = random.choice(RESPONSES)
39
+
40
+ return JSONResponse(
41
+ content={"status": "success", "worker_id": "mock-local", "result": response}
42
+ )
43
+
44
+
45
+ @app.get("/health")
46
+ def health():
47
+ return {"status": "healthy", "worker_id": "mock-local"}
48
+
49
+
50
+ @app.get("/")
51
+ def root():
52
+ return {"message": "Mock Worker Running", "worker_id": "mock-local"}
53
+
54
+
55
+ if __name__ == "__main__":
56
+ import uvicorn
57
+
58
+ uvicorn.run(app, host="0.0.0.0", port=7861)