|
4 | 4 | from fastapi import APIRouter, Query, HTTPException |
5 | 5 | from fastapi.responses import JSONResponse |
6 | 6 |
|
7 | | -from consts.exceptions import TimeoutException, NotFoundException, MEConnectionException |
8 | | -from services.me_model_management_service import get_me_models_impl, check_me_variable_set |
9 | | -from services.model_health_service import check_me_connectivity_impl |
| 7 | +from consts.exceptions import MEConnectionException, TimeoutException |
| 8 | +from services.me_model_management_service import check_me_variable_set, check_me_connectivity |
10 | 9 |
|
11 | 10 | router = APIRouter(prefix="/me") |
12 | 11 |
|
13 | 12 |
|
14 | | -@router.get("/model/list") |
15 | | -async def get_me_models( |
16 | | - type: str = Query( |
17 | | - default="", description="Model type: embed/chat/rerank"), |
18 | | - timeout: int = Query( |
19 | | - default=2, description="Request timeout in seconds") |
20 | | -): |
21 | | - """ |
22 | | - Get list of models from model engine API |
23 | | - """ |
24 | | - try: |
25 | | - # Pre-check ME environment variables; return empty list if not configured |
26 | | - if not await check_me_variable_set(): |
27 | | - return JSONResponse( |
28 | | - status_code=HTTPStatus.OK, |
29 | | - content={ |
30 | | - "message": "Retrieve skipped", |
31 | | - "data": [] |
32 | | - } |
33 | | - ) |
34 | | - filtered_result = await get_me_models_impl(timeout=timeout, type=type) |
35 | | - return JSONResponse( |
36 | | - status_code=HTTPStatus.OK, |
37 | | - content={ |
38 | | - "message": "Successfully retrieved", |
39 | | - "data": filtered_result |
40 | | - } |
41 | | - ) |
42 | | - except TimeoutException as e: |
43 | | - logging.error(f"Request me model timeout: {str(e)}") |
44 | | - raise HTTPException(status_code=HTTPStatus.REQUEST_TIMEOUT, detail="Failed to get ModelEngine model list: timeout") |
45 | | - except NotFoundException as e: |
46 | | - logging.error(f"Request me model not found: {str(e)}") |
47 | | - raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="ModelEngine model not found") |
48 | | - except Exception as e: |
49 | | - logging.error(f"Failed to get me model list: {str(e)}") |
50 | | - raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Failed to get ModelEngine model list") |
51 | | - |
52 | | - |
53 | 13 | @router.get("/healthcheck") |
54 | | -async def check_me_connectivity(timeout: int = Query(default=2, description="Timeout in seconds")): |
| 14 | +async def check_me_health(timeout: int = Query(default=30, description="Timeout in seconds")): |
55 | 15 | """ |
56 | | - Health check from model engine API |
| 16 | + Health check for ModelEngine platform by actually calling the API. |
| 17 | + Returns connectivity status based on actual API response. |
57 | 18 | """ |
58 | 19 | try: |
59 | | - # Pre-check ME environment variables; return not connected if not configured |
| 20 | + # First check if environment variables are configured |
60 | 21 | if not await check_me_variable_set(): |
61 | 22 | return JSONResponse( |
62 | 23 | status_code=HTTPStatus.OK, |
63 | 24 | content={ |
64 | 25 | "connectivity": False, |
65 | | - "message": "ModelEngine platform necessary environment variables not configured. Healthcheck skipped.", |
| 26 | + "message": "ModelEngine platform environment variables not configured. Healthcheck skipped.", |
66 | 27 | } |
67 | 28 | ) |
68 | | - await check_me_connectivity_impl(timeout) |
| 29 | + |
| 30 | + # Then check actual connectivity |
| 31 | + await check_me_connectivity(timeout) |
69 | 32 | return JSONResponse( |
70 | 33 | status_code=HTTPStatus.OK, |
71 | 34 | content={ |
72 | 35 | "connectivity": True, |
73 | | - "message": "ModelEngine platform connect successfully.", |
| 36 | + "message": "ModelEngine platform connected successfully.", |
74 | 37 | } |
75 | 38 | ) |
76 | 39 | except MEConnectionException as e: |
77 | | - logging.error(f"ModelEngine model healthcheck failed: {str(e)}") |
78 | | - raise HTTPException(status_code=HTTPStatus.SERVICE_UNAVAILABLE, detail="ModelEngine model connect failed.") |
| 40 | + logging.error(f"ModelEngine healthcheck failed: {str(e)}") |
| 41 | + raise HTTPException(status_code=HTTPStatus.SERVICE_UNAVAILABLE, detail=f"ModelEngine connection failed: {str(e)}") |
79 | 42 | except TimeoutException as e: |
80 | | - logging.error(f"ModelEngine model healthcheck timeout: {str(e)}") |
81 | | - raise HTTPException(status_code=HTTPStatus.REQUEST_TIMEOUT, detail="ModelEngine model connect timeout.") |
| 43 | + logging.error(f"ModelEngine healthcheck timeout: {str(e)}") |
| 44 | + raise HTTPException(status_code=HTTPStatus.REQUEST_TIMEOUT, detail="ModelEngine connection timeout.") |
82 | 45 | except Exception as e: |
83 | | - logging.error(f"ModelEngine model healthcheck failed with unknown error: {str(e)}.") |
84 | | - raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="ModelEngine model connect failed.") |
| 46 | + logging.error(f"ModelEngine healthcheck failed with unknown error: {str(e)}") |
| 47 | + raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=f"ModelEngine healthcheck failed: {str(e)}") |
0 commit comments