Sequential chains with LCEL
With your prompt templates created, it's time to tie everything together, including the LLM, using chains and LCEL. An llm
has already been defined for you that uses OpenAI's gpt-4o-mini
model
For the final step of calling the chain, feel free to insert any activity you wish! If you're struggling for ideas, try inputting "play the harmonica"
.
This exercise is part of the course
Developing LLM Applications with LangChain
Exercise instructions
- Create a sequential chain using LCEL that passes
learning_prompt
into thellm
, and feeds the output intotime_prompt
for resending to thellm
. - Call the chain with the activity of your choice!
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
learning_prompt = PromptTemplate(
input_variables=["activity"],
template="I want to learn how to {activity}. Can you suggest how I can learn this step-by-step?"
)
time_prompt = PromptTemplate(
input_variables=["learning_plan"],
template="I only have one week. Can you create a concise plan to help me hit this goal: {learning_plan}."
)
# Complete the sequential chain with LCEL
seq_chain = ({"____": ____ | ____ | StrOutputParser()}
| ____
| ____
| StrOutputParser())
# Call the chain
print(seq_chain.____({"____": "____"}))