我刚开始部署ML模型,我想部署一个包含几个模块的模型,每个模块都由包含一些数据文件、.py脚本和一个Python记事本的“文件夹”组成。
我在GitLab中创建了一个项目,并且我试图遵循关于FastAPI的教程,因为这是我将要使用的。但是有人告诉我,在我开始集成代码之前,我需要设置一个健康端点。
我知道请求curl "https://gitlab.example.com/-/health",但是我需要设置什么吗?在执行requirements.txt、构建应用程序的框架等之前,我还需要为项目设置做些什么吗?
发布于 2021-12-13 10:52:24
它完全取决于您的需要,没有在fastapi中本地实现的健康端点。
但是有人告诉我,在我开始集成代码之前,我需要设置一个健康端点。
不一定是一个坏的做法,你可以从列出所有的未来健康检查,并从那里建立你的路线。
评论中的最新情况:
但我不知道该怎么实现。我需要配置文件吗?我对这件事很陌生。
据我所知,您对python非常陌生,因此您应该从遵循官方快速表用户指南开始。您还可以从第一步跟踪这。
运行如下的一个非常基本的文件项目:
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/health")
async def root():
return {"message": "Alive!"}请记住,上面的内容不适合于生产,只适用于测试/学习目的,要制作一个生产api,您应该遵循官方的高级用户指南并实现如下内容。
更高级的路由器:
你有this health lib的fastapi,这太好了。
您可以这样进行基本检查:
# app.routers.health.py
from fastapi import APIRouter, status, Depends
from fastapi_health import health
from app.internal.health import healthy_condition, sick_condition
router = APIRouter(
tags=["healthcheck"],
responses={404: {"description": "not found"}},
)
@router.get('/health', status_code=status.HTTP_200_OK)
def perform_api_healthcheck(health_endpoint=Depends(health([healthy_condition, sick_condition]))):
return health_endpoint# app.internal.health.py
def healthy_condition(): # just for testing puposes
return {"database": "online"}
def sick_condition(): # just for testing puposes
return Truehttps://stackoverflow.com/questions/70333286
复制相似问题