FastAPI में अलग-अलग इनपुट टाइप्स को संभालना

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

Matt Eckerle

Software and Data Engineering Leader

Restaurant बनाम API

एक रेस्टोरेंट की तुलना API के इनपुट से

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

Validation फ्लो

 

 

  • रिक्वेस्ट से आने वाला डेटा
  • Pydantic से इनपुट वैलिडेशन होता है
  • मॉडल की ज़रूरत के अनुसार अलग-अलग डेटा टाइप प्रोसेस करें
  • प्रोसेस किया इनपुट मॉडल को भेजें

रिक्वेस्ट वैलिडेशन का फ्लोचार्ट

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

Comment मॉडरेशन सिस्टम

 

class CommentMetrics(BaseModel):
    length: int           
    user_karma: int     
    report_count: int

class CommentText(BaseModel): content: str

कमेंट बॉक्स आइकॉन की इमेज

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

Floating point नंबरों के लिए endpoint

app = FastAPI()

@app.post("/predict")
def predict_score(data: CommentMetrics):
features = np.array([ data.length, data.user_karma, data.report_count ])
model = CommentScorer() prediction = model.predict(features)
return {"prediction": round(prediction, 2), "input": data.dict()}
FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

टेक्स्टुअल इनपुट के लिए endpoint

@app.post("/analyze_text")

def analyze(comment: CommentText):
forbidden = ["spam", "hate", "free" "fake", "sign up"]
text_lower = comment.lower()
issues = [word for word in forbidden if word in text_lower]
return { "issues": issues, "needs_moderation": len(issues) }

कमेंट के लिए आउटपुट: Sign up for free

{
    "issues": ["free", "sign up"],
    "needs_moderation": 2
}
FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

अभ्यास करते हैं!

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

Preparing Video For Download...