GET endpoint for model information
You're part of a machine learning team that has developed several machine learning models, each designed for different tasks such as sentiment analysis, product categorization, and customer churn prediction. You're working on deploying these models, and you need to create an endpoint that provides basic information about each model.
Your task is to implement a GET endpoint at route /model-info/{model_id} that retrieves and returns this essential model information.
Bu egzersiz, kursun bir parçasıdır
Deploying AI into Production with FastAPI
Egzersiz talimatları
- Create a
GETendpoint at"/model-info/{model_id}"that returns information about a specific model. - The endpoint should accept a
model_idas a path parameter. - Raise an
HTTPExceptionwith a404status code indicating that the model was not found if themodel_idis0.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
from fastapi import FastAPI, HTTPException
app = FastAPI()
# Add model_id as a path parameter in the route
@app.get("/model-info/{____}")
# Pass on the model id as an argument
async def get_model_info(____: int):
if model_id == 0:
# Raise the right status code for not found
raise HTTPException(status_code=____, detail="Model not found")
model_info = get_model_details(id)
return {"model_id": model_id, "model_name": model_info}