开始使用免费开始使用

为 Llama 设计提示语的格式

当提示语很长且缺乏结构时,模型有时难以区分任务、期望的输出以及额外上下文。要解决这个问题,您可以加入清晰的标签,将这些信息分段并加以区分。

Llama 模型以 llm 提供,并将在本课程后续内容中持续可用。

本练习是课程的一部分

使用 Llama 3

查看课程

练习说明

  • 在提示语中添加 InstructionQuestionAnswer 这三个标签,使其结构更清晰。
  • 将该提示语传递给模型。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Add formatting to the prompt
prompt="""
____: Explain the concept of gravity in simple terms.
____: What is gravity?
____:
"""

# Send the prompt to the model
output = llm(____, max_tokens=15, stop=["Question:"]) 
print(output['choices'][0]['text'])
编辑并运行代码