mgbam commited on
Commit
26b566a
·
verified ·
1 Parent(s): 65bc4b3

Create pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +47 -0
pipeline.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app/routes/pipeline.py
2
+
3
+ import os
4
+ import requests
5
+ from fastapi import APIRouter, Depends, Query
6
+ from datetime import datetime
7
+ from agent_manager import AgentManager
8
+ from memory.database import init_db, log_action
9
+ from app.dependencies import require_api_key
10
+
11
+ router = APIRouter(
12
+ prefix="/pipeline",
13
+ tags=["Pipeline"],
14
+ dependencies=[Depends(require_api_key)]
15
+ )
16
+
17
+ WEBHOOK_URL = os.getenv("ZAPIER_WEBHOOK") # Set this in HF Secrets
18
+
19
+ @router.on_event("startup")
20
+ def startup_db():
21
+ init_db()
22
+
23
+ @router.get("/run", summary="Run full multi‑agent pipeline")
24
+ def run_pipeline(
25
+ niche: str = Query("fitness"),
26
+ business_type: str = Query("dropshipping")
27
+ ):
28
+ manager = AgentManager(niche, business_type)
29
+ summary = manager.run_all()
30
+ # Log each step
31
+ for agent_name, result in summary.items():
32
+ log_action(agent_name, "pipeline_run", result)
33
+ payload = {
34
+ "niche": niche,
35
+ "business_type": business_type,
36
+ "results": summary,
37
+ "timestamp": datetime.utcnow().isoformat()
38
+ }
39
+ # Fire the Zapier webhook (non‑blocking)
40
+ try:
41
+ requests.post(WEBHOOK_URL, json=payload, timeout=2)
42
+ except Exception:
43
+ pass
44
+ return {
45
+ "status": "pipeline_executed",
46
+ **payload
47
+ }