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

Adding assistant messages

Chat models are great for creating conversational applications, but they can be further improved by providing part of a conversation for the model to build on.

Improve this geography tutor application by including this example student prompt and ideal model response in the messages:

  • Example Question: Give me a quick summary of Portugal.
  • Example Answer: Portugal is a country in Europe that borders Spain. The capital city is Lisboa.

Bu egzersiz

Working with the OpenAI API

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

Egzersiz talimatları

  • Add the example question and answer provided as a user-assistant pair in the messages sent to the model.
    • Example Question: Give me a quick summary of Portugal.
    • Example Answer: Portugal is a country in Europe that borders Spain. The capital city is Lisboa.

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)
Kodu Düzenle ve Çalıştır