BaşlayınÜcretsiz Başlayın

Moderating the model response

Even though the chatbot has generated a tailored response, it's important to verify that the content is safe to send to the customer. In this step, you'll moderate the response to ensure all category scores fall below the customer safety threshold.

The model's reply from the previous exercise is available as chatbot_reply.

Bu egzersiz

Multi-Modal Systems with the OpenAI API

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Send a moderation request with chatbot_reply as input.
  • Extract the response's category scores, convert them to a dictionary using .model_dump(), and check if any score exceeds 0.7.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

client = OpenAI(api_key="")

# Send the moderation request
response = ____

# Extract scores and convert to dictionary
scores = ____

if any(____ for score in scores.values()):
    print("AI Response flagged for moderation!")
    chatbot_reply = """I'm sorry, but I can't provide a response to that request. Please contact [email protected] for further assistance."""
else:
    print("AI Response is safe.")
Kodu Düzenle ve Çalıştır