शुरू करेंमुफ़्त में शुरू करें

मॉडल जानकारी के लिए GET endpoint

आप एक मशीन लर्निंग टीम का हिस्सा हैं जिसने कई मशीन लर्निंग मॉडल बनाए हैं. हर मॉडल अलग-अलग कार्यों के लिए बना है, जैसे sentiment analysis, product categorization, और customer churn prediction. आप इन मॉडलों को डिप्लॉय करने पर काम कर रहे हैं, और आपको ऐसा endpoint बनाना है जो हर मॉडल की बुनियादी जानकारी दे.

आपका कार्य है रूट /model-info/{model_id} पर एक GET endpoint इम्प्लीमेंट करना, जो यह आवश्यक मॉडल जानकारी प्राप्त करे और लौटाए.

यह अभ्यास पाठ्यक्रम का हिस्सा है

FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

पाठ्यक्रम देखें

अभ्यास निर्देश

  • "/model-info/{model_id}" पर एक GET endpoint बनाएँ जो किसी विशिष्ट मॉडल की जानकारी लौटाए.
  • यह endpoint पाथ पैरामीटर के रूप में model_id स्वीकार करे.
  • अगर model_id 0 हो, तो 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}
कोड संपादित करें और चलाएँ