开始使用免费开始使用

创建 few-shot 示例集

PromptTemplateChatPromptTemplate 非常适合集成变量,但在集成包含大量示例的数据集时会比较吃力。这时就需要 FewShotPromptTemplate!在本练习中,您将创建一个由字典组成的列表,用来存放以下问答对。

  • Question: How many DataCamp courses has Jack completed?
  • Answer: 36
  • Question: How much XP does Jack have on DataCamp?
  • Answer: 284,320XP
  • Question: What technology does Jack learn about most on DataCamp?
  • Answer: Python

在下一个练习中,您将把这些信息转换为一个 few-shot 提示模板。

本练习是课程的一部分

使用 LangChain 开发 LLM 应用

查看课程

练习说明

  • 使用 "question""answer" 作为键,为提供的问答创建一个字典列表。

交互式实操练习

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

# Create the examples list of dicts
examples = [
  {
    "question": "____",
    "answer": "____"
  },
  {
    "question": "____",
    "answer": "____"
  },
  {
    "question": "____",
    "answer": "____"
  }
]
编辑并运行代码