मॉडल जानकारी के लिए GET endpoint
आप एक मशीन लर्निंग टीम का हिस्सा हैं जिसने कई मशीन लर्निंग मॉडल बनाए हैं. हर मॉडल अलग-अलग कार्यों के लिए बना है, जैसे sentiment analysis, product categorization, और customer churn prediction. आप इन मॉडलों को डिप्लॉय करने पर काम कर रहे हैं, और आपको ऐसा endpoint बनाना है जो हर मॉडल की बुनियादी जानकारी दे.
आपका कार्य है रूट /model-info/{model_id} पर एक GET endpoint इम्प्लीमेंट करना, जो यह आवश्यक मॉडल जानकारी प्राप्त करे और लौटाए.
यह अभ्यास पाठ्यक्रम का हिस्सा है
FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना
अभ्यास निर्देश
"/model-info/{model_id}"पर एकGETendpoint बनाएँ जो किसी विशिष्ट मॉडल की जानकारी लौटाए.- यह endpoint पाथ पैरामीटर के रूप में
model_idस्वीकार करे. - अगर
model_id0हो, तो404स्टेटस कोड के साथHTTPExceptionउठाएँ, यह दर्शाते हुए कि मॉडल नहीं मिला.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
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}