मॉडरेशन

OpenAI API के साथ AI सिस्टम बनाना

Francesca Donadoni

Curriculum Manager, DataCamp

OpenAI API में मॉडरेशन समझना

  • मॉडरेशन: इनपुट का विश्लेषण करना ताकि पता चले कि उसमें किसी पूर्वनिर्धारित पॉलिसी या गाइडलाइन का उल्लंघन तो नहीं है OpenAI मॉडरेशन API द्वारा यूज़र संदेश पढ़ने और जवाब में उस संदेश के किसी भी हानिकारक कंटेंट श्रेणी से संबंधित होने की संभावनाएँ दिखाने वाला डायग्राम
OpenAI API के साथ AI सिस्टम बनाना

OpenAI API में मॉडरेशन समझना

OpenAI मॉडरेशन API द्वारा यूज़र संदेश पढ़ने और जवाब में मानी जाने वाली हानिकारक कंटेंट श्रेणियों की सूची दिखाने वाला डायग्राम

OpenAI API के साथ AI सिस्टम बनाना

कंटेंट मॉडरेट करना

moderation_response = client.moderations.create(input="""
...until someone draws an Exploding Kitten.
When that happens, that person explodes. They are now dead.
This process continues until...
""") 

print(moderation_response.results[0].categories.violence)
True
1 https://ek.explodingkittens.com/how-to-play/exploding-kittens
OpenAI API के साथ AI सिस्टम बनाना

संदर्भ में मॉडरेशन

moderation_response = client.moderations.create(input="""
In the deck of cards are some Exploding Kittens. You play the game by putting the deck face down and taking turns drawing cards until someone draws an Exploding Kitten.
When that happens, that person explodes. They are now dead.
This process continues until there's only 1 player left, who wins the game.
The more cards you draw, the greater your chances of drawing an Exploding Kitten.
""") 

moderation_response.results[0].categories.violence
False
OpenAI API के साथ AI सिस्टम बनाना

प्रॉम्प्ट इंजेक्शन

एक महिला चैटबॉट इस्तेमाल कर रही है और उस पर एक दुर्भावनापूर्ण प्रॉम्प्ट इंजेक्ट किया जा रहा है

OpenAI API के साथ AI सिस्टम बनाना

प्रॉम्प्ट इंजेक्शन

 

  • प्रॉम्प्ट में टेक्स्ट की मात्रा सीमित करें
  • जनरेट होने वाले आउटपुट टोकन की संख्या सीमित करें
  • वैलिडेटेड इनपुट और आउटपुट के लिए पूर्व-चयनित कंटेंट का उपयोग करें
OpenAI API के साथ AI सिस्टम बनाना

गार्डरेल जोड़ना

user_request = """
In the deck of cards are some Exploding Kittens. You play the game by putting the 
deck face down and taking turns drawing cards until  someone draws an Exploding 
Kitten. When that happens, that person explodes. They are now dead.
This process continues until there's only 1 player left, who wins the game.
The more cards you draw, the greater your chances of drawing an Exploding Kitten.
"""

messages = [{"role": "system", "content": "Your role is to assess whether the user question is allowed or not. The allowed topics are games of chess only. If the topic is allowed, reply with an answer as normal, otherwise say 'Apologies, but the topic is not_allowed.'",}, {"role": "user", "content": user_request},]
OpenAI API के साथ AI सिस्टम बनाना

गार्डरेल जोड़ना

response = client.chat.completions.create(
    model="gpt-4o-mini", 
    messages=messages
)

print(response.choices[0].message.content)
Apologies, but the topic is not allowed.
OpenAI API के साथ AI सिस्टम बनाना

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

OpenAI API के साथ AI सिस्टम बनाना

Preparing Video For Download...