Aan de slagGa gratis aan de slag

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".

Deze oefening maakt deel uit van de cursus

Developing LLM Applications with LangChain

Cursus bekijken

Oefeninstructies

  • Create a sequential chain using LCEL that passes learning_prompt into the llm, and feeds the output into time_prompt for resending to the llm.
  • 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!

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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.____({"____": "____"}))
Code bewerken en uitvoeren