運用 system 訊息
Chat 模式支援 3 種不同的訊息角色:
- System:控制助理的「行為」
- User:用來「指示」助理
- Assistant:對使用者指示做出「回應」
在這個練習中,你將開始設計一個用來幫助人們學習新技能的 AI 系統,並使用 system 訊息來設定合適的模型行為。
本練習屬於課程
使用 Python 操作 DeepSeek
練習說明
- 建立一個同時包含 system 與 user 訊息的請求,產生一份學習荷蘭語口說的讀書計畫。
- 擷取並列印助理的文字回應。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
# Create a request to the chat model
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4.1-Flash",
max_tokens=500,
messages=[
{"role": ____,
"content": "You are a study planning assistant that creates plans for learning new skills. Only return the structured plan."},
{"____": "____",
"____": "I want to learn to speak Dutch."}
]
)
# Extract the assistant's text response
print(response.choices[0].____.____)