Skip to main content
Part 2: Production Features - Provider wrappers, policy enforcement, sessions, और observability।

Setup

हम “CloudDash” नाम के एक fictional SaaS product के लिए customer support chatbot बना रहे हैं — यह एक cloud monitoring dashboard है। यह chatbot pricing, features, और troubleshooting के बारे में सवालों के जवाब देता है। साथ ही, हम हर layer पर RAIL Score evaluation add करेंगे ताकि chatbot के responses safe, accurate, fair, और helpful हों।

Dependencies install करें

Environment variables

एक .env file बनाएँ:
अपनी RAIL API key लें: responsibleailabs.ai/dashboard पर sign up करें। Free tier में 100 credits मिलते हैं — इस पूरे tutorial को follow करने के लिए काफ़ी हैं।

Basic chatbot बनाएँ

पहले OpenAI से directly एक basic chatbot बनाएँ, बिना किसी RAIL integration के। यही वो foundation है जिस पर हम scoring layer करेंगे।
chatbot.py
यह काम तो करता है, लेकिन response quality की कोई visibility नहीं है। क्या यह response safe है? क्या factually accurate है? कोई bias तो नहीं है? जब तक RAIL Score add नहीं करते, जानने का कोई तरीका नहीं।

RAIL Score evaluation add करें

RAIL evaluation add करने का सबसे simple तरीका RailScoreClient use करना है। एक ही call से सभी 8 RAIL dimensions के scores मिल जाते हैं।
chatbot_with_eval.py

Results को समझें

Privacy = 5.0 का मतलब है “applicable नहीं।” जब privacy evaluate किए जा रहे content के लिए relevant नहीं होती, तो RAIL 5.0 (neutral) return करता है।

Deep evaluation

Basic mode आपको scores देता है। Deep mode आपको why बताता है: हर dimension की explanations, detected issues, और improvement suggestions।
deep_eval.py

Basic vs Deep

Cost-saving tip: Production में हर response के लिए basic mode use करें, और deep mode selectively use करें। जैसे, जब basic score आपके threshold से नीचे गिरे तो deep mode trigger करें, या responses के sample पर periodic audit के लिए।

आगे क्या है

Part 2: Production Features

Provider wrappers, policy enforcement (block/regenerate), multi-turn session tracking, और Langfuse observability।