開始使用免費開始

與監控分享模型參數

你想在企鵝分類 API 中加入一個健康檢查端點,用來提供模型的參數。

所需的套件(FastAPIjoblib)已經匯入。

本練習屬於課程

使用 FastAPI 將 AI 佈署到生產環境

檢視課程

練習說明

  • 在健康檢查的常見位置新增一個 GET 端點。
  • 使用 sklearn 模型的 get_params 方法取得模型參數。
  • 在回應中加入模型參數,作為鍵 params 的值。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

model = joblib.load(
    'penguin_classifier.pkl'
)
app = FastAPI()

# Create health check endpoint
@app.get("____")
async def get_health():
    # Capture the model params
    params = ____.get_params()
    return {"status": "OK",
            # Include model params in response
            "params": ____}
編輯並執行程式碼