Building a DeepSeek request
Throughout the course, you'll write Python code to prompt DeepSeek models via the openai library. Entering your own API key is not necessary to create requests and complete the exercises in this course.
The OpenAI class has already been imported for you from the openai library.
Please note that although base_url is set to "https://api.together.xyz/v1" , the official DeepSeek API, the requests in these exercises are actually being rerouted to together.ai's API.
Deze oefening maakt deel uit van de cursus
Working with DeepSeek in Python
Oefeninstructies
- Create an
OpenAIAPI client (keep<TogetherAI API Key>unchanged). createa request for the"deepseek-ai/DeepSeek-V3"model to the Chat Completions endpoint.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Create the OpenAI client
client = ____(api_key="", base_url="https://api.together.xyz/v1")
# Create a request to the chat model
response = client.chat.completions.____(
model="deepseek-ai/DeepSeek-V3",
max_tokens=200,
messages=[
{"role": "user",
"content": "Write a polite reply accepting an AI Engineer job offer. Only output the reply."}]
)
print(response.choices[0].message.content)