Spaces:
Sleeping
Sleeping
DevelopedBy-Siva commited on
Commit ·
12b9f26
1
Parent(s): 83fe4f9
fix routes
Browse files
backend/api/__pycache__/routes.cpython-311.pyc
CHANGED
|
Binary files a/backend/api/__pycache__/routes.cpython-311.pyc and b/backend/api/__pycache__/routes.cpython-311.pyc differ
|
|
|
backend/api/__pycache__/routes.cpython-312.pyc
CHANGED
|
Binary files a/backend/api/__pycache__/routes.cpython-312.pyc and b/backend/api/__pycache__/routes.cpython-312.pyc differ
|
|
|
backend/api/routes.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter, HTTPException
|
| 2 |
|
| 3 |
from backend.ai.analyzer import analyze_business_description, analyze_custom_task
|
|
@@ -24,11 +26,16 @@ from backend.storage.database import db
|
|
| 24 |
|
| 25 |
router = APIRouter()
|
| 26 |
executor = WorkflowExecutor()
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
@router.post("/analyze")
|
| 30 |
def analyze(request: AnalyzeRequest) -> dict:
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
owner = db.ensure_owner(request.owner_id, request.owner_email)
|
| 33 |
owner["business_description"] = request.description
|
| 34 |
owner["business_analysis"] = analysis
|
|
@@ -39,30 +46,42 @@ def analyze(request: AnalyzeRequest) -> dict:
|
|
| 39 |
@router.post("/custom-task")
|
| 40 |
def custom_task(request: CustomTaskRequest) -> dict:
|
| 41 |
owner = db.get_owner(request.owner_id)
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
@router.post("/suggest-workflows")
|
| 50 |
def suggest_workflows(request: WorkflowSuggestionRequest) -> dict:
|
| 51 |
owner = db.get_owner(request.owner_id)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
@router.post("/build-workflow", response_model=BuildWorkflowResponse)
|
| 62 |
def build_workflow(request: BuildWorkflowRequest) -> BuildWorkflowResponse:
|
| 63 |
owner = db.get_owner(request.owner_id)
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
return BuildWorkflowResponse(workflow=compiled)
|
| 67 |
|
| 68 |
|
|
@@ -119,3 +138,15 @@ def simulate_run(owner_id: str, workflow_id: str, trigger: dict) -> dict:
|
|
| 119 |
result = executor.execute(workflow, trigger, db=db, owner_id=owner_id)
|
| 120 |
db.save_execution_log(owner_id, workflow_id, trigger, result["steps"], result["outcome"], result.get("error"))
|
| 121 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
|
| 3 |
from fastapi import APIRouter, HTTPException
|
| 4 |
|
| 5 |
from backend.ai.analyzer import analyze_business_description, analyze_custom_task
|
|
|
|
| 26 |
|
| 27 |
router = APIRouter()
|
| 28 |
executor = WorkflowExecutor()
|
| 29 |
+
logger = logging.getLogger(__name__)
|
| 30 |
|
| 31 |
|
| 32 |
@router.post("/analyze")
|
| 33 |
def analyze(request: AnalyzeRequest) -> dict:
|
| 34 |
+
try:
|
| 35 |
+
analysis = analyze_business_description(request.description)
|
| 36 |
+
except Exception as exc:
|
| 37 |
+
logger.exception("Analyze request failed")
|
| 38 |
+
raise HTTPException(status_code=500, detail=f"Analyze failed: {exc}") from exc
|
| 39 |
owner = db.ensure_owner(request.owner_id, request.owner_email)
|
| 40 |
owner["business_description"] = request.description
|
| 41 |
owner["business_analysis"] = analysis
|
|
|
|
| 46 |
@router.post("/custom-task")
|
| 47 |
def custom_task(request: CustomTaskRequest) -> dict:
|
| 48 |
owner = db.get_owner(request.owner_id)
|
| 49 |
+
try:
|
| 50 |
+
return analyze_custom_task(
|
| 51 |
+
business_description=owner.get("business_description", ""),
|
| 52 |
+
existing_workflows=db.list_workflows(request.owner_id),
|
| 53 |
+
custom_task=request.custom_task,
|
| 54 |
+
)
|
| 55 |
+
except Exception as exc:
|
| 56 |
+
logger.exception("Custom task analysis failed")
|
| 57 |
+
raise HTTPException(status_code=500, detail=f"Custom task analysis failed: {exc}") from exc
|
| 58 |
|
| 59 |
|
| 60 |
@router.post("/suggest-workflows")
|
| 61 |
def suggest_workflows(request: WorkflowSuggestionRequest) -> dict:
|
| 62 |
owner = db.get_owner(request.owner_id)
|
| 63 |
+
try:
|
| 64 |
+
return suggest_workflow_options(
|
| 65 |
+
task_name=request.task_name,
|
| 66 |
+
task_description=request.task_description,
|
| 67 |
+
category=request.category,
|
| 68 |
+
spreadsheet_info=owner.get("spreadsheet_config", {"connected": False}),
|
| 69 |
+
uploaded_files=db.list_data_files(request.owner_id),
|
| 70 |
+
)
|
| 71 |
+
except Exception as exc:
|
| 72 |
+
logger.exception("Workflow suggestion failed")
|
| 73 |
+
raise HTTPException(status_code=500, detail=f"Workflow suggestion failed: {exc}") from exc
|
| 74 |
|
| 75 |
|
| 76 |
@router.post("/build-workflow", response_model=BuildWorkflowResponse)
|
| 77 |
def build_workflow(request: BuildWorkflowRequest) -> BuildWorkflowResponse:
|
| 78 |
owner = db.get_owner(request.owner_id)
|
| 79 |
+
try:
|
| 80 |
+
workflow_json = build_workflow_definition(request=request, owner=owner)
|
| 81 |
+
compiled = compile_workflow(workflow_json)
|
| 82 |
+
except Exception as exc:
|
| 83 |
+
logger.exception("Workflow build failed")
|
| 84 |
+
raise HTTPException(status_code=500, detail=f"Workflow build failed: {exc}") from exc
|
| 85 |
return BuildWorkflowResponse(workflow=compiled)
|
| 86 |
|
| 87 |
|
|
|
|
| 138 |
result = executor.execute(workflow, trigger, db=db, owner_id=owner_id)
|
| 139 |
db.save_execution_log(owner_id, workflow_id, trigger, result["steps"], result["outcome"], result.get("error"))
|
| 140 |
return result
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
@router.get("/debug/vertex")
|
| 144 |
+
def debug_vertex() -> dict:
|
| 145 |
+
from backend.ai.client import vertex_client
|
| 146 |
+
|
| 147 |
+
try:
|
| 148 |
+
text = vertex_client.generate_text("Reply with exactly: Vertex debug ok")
|
| 149 |
+
return {"status": "ok", "response": text}
|
| 150 |
+
except Exception as exc:
|
| 151 |
+
logger.exception("Vertex debug call failed")
|
| 152 |
+
raise HTTPException(status_code=500, detail=f"Vertex debug failed: {exc}") from exc
|