始める無料で始める

Creating a conversation history

An online math learning platform called Easy as Pi has contracted you to help them develop an AI tutor. You immediately see that you can build this application using DeepSeek in chat mode, and start to design a simple proof-of-concept (POC) for the major stakeholders at the company to review.

To start, you'll demonstrate how responses to student messages can be stored in a message history, which will enable full conversations.

この演習はコースの一部です

Working with DeepSeek in Python

コースを見る

演習の手順

  • Send messages to the model in a chat request.
  • Extract the assistant message from response, convert it to a message dictionary, and append it to messages.

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

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

messages = [
    {"role": "system", "content": "You are a helpful math tutor that generates concise, one-sentence responses."},
    {"role": "user", "content": "Explain what pi is."}
]

# Send the chat messages to the model
response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    messages=____,
    max_tokens=500
)

# Extract the assistant message from the response
assistant_dict = {"role": "____", "content": ____}

# Add assistant_dict to the messages dictionary
messages.____(assistant_dict)
print(messages)
コードを編集して実行