LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Working with DeepSeek in Python

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

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

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3",
    # 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)
Code bearbeiten und ausführen