开始使用免费开始使用

为顺序链构建提示

在接下来的几个练习中,您将构建一个帮助人们学习新技能的系统。该系统需要按顺序构建,便于学习者根据自身偏好和限制来调整计划。您将运用 LangChain LCEL 技能来搭建一个顺序链来实现该系统,第一步是设计系统将要使用的提示模板(prompt templates)

本练习是课程的一部分

使用 LangChain 开发 LLM 应用

查看课程

练习说明

  • 创建名为 learning_prompt 的提示模板,接收输入 "activity" 并生成一个学习计划。
  • 创建名为 time_prompt 的提示模板,接收输入 "learning_plan" 并将其调整为在「一周」内完成。
  • 以您选择的活动来调用 learning_prompt(如果一时没有想法,可以尝试 "play golf")。

交互式实操练习

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

# Create a prompt template that takes an input activity
learning_prompt = PromptTemplate(
    input_variables=["____"],
    template="I want to learn how to {activity}. Can you suggest how I can learn this step-by-step?"
)

# Create a prompt template that places a time constraint on the output
time_prompt = PromptTemplate(
    ____,
    template="I only have one week. Can you create a plan to help me hit this goal: {learning_plan}."
)

# Invoke the learning_prompt with an activity
print(learning_prompt.____({"activity": "____"}))
编辑并运行代码