System 訊息
你先前的訊息雖然得到有效回應,但也讓使用者能問任何問題,即使與網際網路客服無關。這一題要你使用 system 訊息,引導模型只回答與使用者的網際網路服務有關的客服問題。
Llama 模型仍以 llm 提供。
本練習屬於課程
使用 Llama 3
練習說明
- 在提供給
conv串列的訊息字典中,加入"system"角色。 - 從
result物件中擷取模型回應的"message"。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Add a system message to the conversation list
conv = [
{
"role": "____",
"content": "You are a helpful and professional customer support assistant for an internet service provider. If the question or instruction doesn't relate to internet service, quote the response: 'Sorry, I can't answer that.'"},
{
"role": "user",
"content": "Help me decide which stocks to invest in."
}
]
result = llm.create_chat_completion(messages=conv, max_tokens=15)
# Extract the model response from the result object
assistant_content = result["choices"][0]["____"]["content"]
print(assistant_content)