Asistan mesajları ekleme
Sohbet modelleri, konuşmaya dayalı uygulamalar oluşturmak için harikadır; ancak modele üzerine inşa edebileceği bir konuşma parçası vererek daha da iyileştirilebilir.
Bu coğrafya eğitmeni uygulamasını, iletilere örnek bir öğrenci istemi ve ideal model yanıtı ekleyerek geliştir:
- Örnek Soru:
Give me a quick summary of Portugal. - Örnek Yanıt:
Portugal is a country in Europe that borders Spain. The capital city is Lisboa.
Bu egzersiz
OpenAI API ile Çalışmak
kursunun bir parçasıdırEgzersiz talimatları
- Sağlanan örnek soru ve yanıtı, modele gönderilen iletilerde bir kullanıcı-asistan çifti olarak ekle.
- Örnek Soru:
Give me a quick summary of Portugal. - Örnek Yanıt:
Portugal is a country in Europe that borders Spain. The capital city is Lisboa.
- Örnek Soru:
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
client = OpenAI(api_key="")
response = client.chat.completions.create(
model="gpt-4o-mini",
# Add a user and assistant message for in-context learning
messages=[
{"role": "system", "content": "You are a helpful Geography tutor that generates concise summaries for different countries."},
____,
____,
{"role": "user", "content": "Give me a quick summary of Greece."}
]
)
print(response.choices[0].message.content)