forked from opea-project/GenAIExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (41 loc) · 1.47 KB
/
Copy pathmain.py
File metadata and controls
58 lines (41 loc) · 1.47 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
49
50
51
52
53
54
55
56
57
58
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import logging
from fastapi import APIRouter, FastAPI
from workflow import run_workflow
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
app = FastAPI()
router = APIRouter(prefix="/serving", tags=["Workflow Serving"])
app.results = {}
@router.post("/servable_workflows/{wf_id}/start", summary="Start Workflow")
async def start_workflow(wf_id: int, params: dict):
try:
app.results = run_workflow(params["params"])
wf_key = "example_key"
return {"msg": "ok", "wf_key": wf_key}
except Exception as e:
logging.error(e, exc_info=True)
return {"msg": "error occurred"}
@router.get("/serving_workflows/{wf_key}/status", summary="Get Workflow Status")
async def get_status(wf_key: str):
try:
if app.results:
status = "finished"
else:
status = "failed"
return {"workflow_status": status}
except Exception as e:
logging.error(e)
return {"msg": "error occurred"}
@router.get("/serving_workflows/{wf_key}/results", summary="Get Workflow Results")
async def get_results(wf_key: str):
try:
if app.results:
return app.results
else:
return {"msg": "There is an issue while getting results !!"}
except Exception as e:
logging.error(e)
return {"msg": "There is an issue while getting results !!"}
app.include_router(router)