Sohbet rolleri ve sistem iletileri

OpenAI API ile Çalışmak

James Chapman

Curriculum Manager, DataCamp

Sohbet Tamamlamaları

 

Tek adımlı görevler

  • Metin üretimi
  • Metin dönüştürme
  • Sınıflandırma

Bir istem ve bir yanıt içeren tek adımlı görev.

OpenAI API ile Çalışmak

Sohbet Tamamlamaları

 

Tek adımlı görevler

  • Metin üretimi
  • Metin dönüştürme
  • Sınıflandırma

 

Çok adımlı sohbetler

→ Önceki istem ve yanıtlara dayanır

Birden çok istem ve yanıt içeren çok adımlı görev.

OpenAI API ile Çalışmak

Roller

 

  • System: asistanın davranışını kontrol eder
  • User: asistana talimat verir
  • Assistant: kullanıcı talimatına yanıt verir
    • Geliştirici örnek sağlamak için de yazabilir

Bir sohbet etkileşimindeki üç rol: system, user ve assistant.

OpenAI API ile Çalışmak

İstek kurulumu

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": prompt}]
)
OpenAI API ile Çalışmak

İpucu (prompt) kurulumu

messages=[{"role": "system",
           "content": "You are a Python programming tutor who speaks concisely."},
          {"role": "user",
           "content": "What is the difference between mutable and immutable objects?"}]
OpenAI API ile Çalışmak

İstek oluşturma

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a Python programming tutor who speaks concisely."},
            {"role": "user",
             "content": "What is the difference between mutable and immutable objects?"}]
)

print(response.choices[0].message.content)
OpenAI API ile Çalışmak

Yanıt

Mutable objects can be changed after creation, while immutable objects cannot be
modified once they are created.
OpenAI API ile Çalışmak

Kötüye kullanımı azaltma

 

  • Sistem iletisi: korkuluklar içerebilir
    • Model çıktıları için kısıtlar

korkuluklar.jpg

Bir finans eğitmeni chatbotu ve bir finans danışmanı chatbotu.

OpenAI API ile Çalışmak

Sistem iletileriyle kötüye kullanımı azaltma

sys_msg = """
You are finance education assistant that helps students study for exams.

If you are asked for specific, real-world financial advice with risk to their
finances, respond with:

I'm sorry, I am not allowed to provide financial advice.
"""
OpenAI API ile Çalışmak

Sistem iletileriyle kötüye kullanımı azaltma

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": sys_msg},
            {"role": "user",
             "content": "Which stocks should I invest in?"}]
)

print(response.choices[0].message.content)
I'm sorry, I am not allowed to provide financial advice.
OpenAI API ile Çalışmak

Ayo berlatih!

OpenAI API ile Çalışmak

Preparing Video For Download...