指定 DeepSeek 模型
OpenAI 提供多種模型以因應不同情境。在這個練習中,你將指定要使用的模型,並定義角色來組織你的 API 請求。
OpenAI 類別已替你從 openai 函式庫匯入。
本練習屬於課程
使用 Python 操作 DeepSeek
練習說明
- 指定
deepseek-ai/DeepSeek-V4.1-Flash模型。 - 在
messages清單中指派正確的角色。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
response = client.chat.completions.create(
# Specify the model
model="____",
max_tokens=400,
messages=[
# Assign the correct role
{"role": "____",
"content": "Write a post to announce my new AI Engineer role on LinkedIn. Only output the post."}]
)
print(response.choices[0].message.content)