CommencerCommencez gratuitement

Adding assistant messages

Chat mode is great for creating conversational applications, and it 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.

Cet exercice fait partie du cours

<cours>Working with DeepSeek in Python</cours>
Voir le cours

Instructions de l’exercice

  • 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.

Exercice interactif pratique

Essayez cet exercice en complétant ce code d’exemple.

client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    # Add a user and assistant message for in-context learning
    messages=[
        {"role": "system", "content": "You are a helpful Geography tutor that generates concise, one-sentence summaries for different countries."},
        ____,
        ____,
        {"role": "user", "content": "Give me a quick summary of Greece."}
    ]
)

print(response.choices[0].message.content)
Modifier et exécuter le code