Moderasyon

OpenAI API ile AI Sistemleri Geliştirme

Francesca Donadoni

Curriculum Manager, DataCamp

OpenAI API’de moderasyonu anlama

  • Moderasyon: girdinin, önceden tanımlı politika veya yönergeleri ihlal eden içerik içerip içermediğini analiz etme süreci Bir kullanıcı mesajını OpenAI moderasyon API’sinin okuduğu ve yanıt olarak mesajın kötü amaçlı içerik kategorilerine ait olma olasılıklarını ürettiği bir diyagram
OpenAI API ile AI Sistemleri Geliştirme

OpenAI API’de moderasyonu anlama

Bir kullanıcı mesajını OpenAI moderasyon API’sinin okuduğu ve yanıt olarak dikkate alınan kötü amaçlı içerik kategorilerinin listelendiği bir diyagram

OpenAI API ile AI Sistemleri Geliştirme

İçeriği denetleme

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 ile AI Sistemleri Geliştirme

Bağlamda moderasyon

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 ile AI Sistemleri Geliştirme

İstem enjeksiyonu

Kötü niyetli bir istem enjekte edilen bir sohbet botunu kullanan bir kadın

OpenAI API ile AI Sistemleri Geliştirme

İstem enjeksiyonu

 

  • İstemlerdeki metin miktarını sınırlama
  • Üretilen çıktı belirteçlerini sınırlama
  • Doğrulanmış girdi ve çıktı olarak ön seçili içerik kullanma
OpenAI API ile AI Sistemleri Geliştirme

Korumalar ekleme

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 ile AI Sistemleri Geliştirme

Korumalar ekleme

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

print(response.choices[0].message.content)
Üzgünüz, ancak konuya izin verilmiyor.
OpenAI API ile AI Sistemleri Geliştirme

Hadi pratik yapalım!

OpenAI API ile AI Sistemleri Geliştirme

Preparing Video For Download...