開始使用免費開始

為序列式鏈建立提示

在接下來的幾個練習中,你將建立一個幫助人們學習新技能的系統。這個系統需要以序列方式建構,讓學習者能依照自己的偏好與限制來調整計畫。你會運用 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": "____"}))
編輯並執行程式碼