MulaiMulai sekarang secara gratis

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

Latihan ini adalah bagian dari kursus

Developing LLM Applications with LangChain

Lihat Kursus

Petunjuk latihan

  • 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!

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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.____({"____": "____"}))
Edit dan Jalankan Kode