System 消息
您之前的消息可以得到有效回复,但也允许用户提出任何他们想问的问题,即使与网络服务支持无关。本练习中,您将使用一条 system 消息,让模型仅回答与用户网络服务相关的客户问题。
Llama 模型仍以 llm 提供。
本练习是课程的一部分
使用 Llama 3
练习说明
- 将提供的消息字典添加到
conv列表中,并将其"role"设为"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)