Creating a reasoning chatbot for coding
Let's put everything together to build a reasoning chatbot for coding assistance!
You've been provided with two user messages: one to request Python code for a particular task, and a follow-up message requesting that it be written with a particular library.
V4-Pro reasons by default, so all you need to do is loop the conversation and append the right field to the history.
Este exercicio faz parte do curso
Working with DeepSeek in Python
Instruções do exercicio
- Loop over the user questions.
- Send each user question,
q, to thedeepseek-ai/DeepSeek-V4-Promodel. - Append the assistant's final answer (the
.content, not the reasoning) tomessagesso the conversation history stays lean.
exercicio interativo prático
Tente este exercicio completando este código de exemplo.
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
messages = []
user_msgs = ["Write some Python code to generate a list of numbers from 1-10.", "Update the code to use the NumPy library."]
# Loop over the user questions
for q in ____:
print("User: ", q)
user_dict = {"role": "user", "content": q}
messages.append(user_dict)
# Create the API request — V4-Pro reasons by default
response = client.chat.completions.create(
model="deepseek-ai/____",
messages=____,
max_tokens=500
)
# Append only the final answer to the conversation history
assistant_dict = {"role": "assistant", "content": response.choices[0].message.____}
messages.append(assistant_dict)
print("Assistant: ", response.choices[0].message.content, "\n")