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_promptinto thellm, and feeds the output intotime_promptfor resending to thellm. - The first part should create a dictionary with
"learning_plan"as the key and the first chain as the value. - Call the chain using the
.invoke()method 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 = ({"learning_plan": ____ | ____ | ____}
| ____
| ____
| StrOutputParser())
# Call the chain
print(seq_chain.____({"____": "____"}))