LCEL로 만드는 순차 체인
프롬프트 템플릿을 만들었으니, 이제 LLM을 포함해 모든 요소를 체인과 LCEL로 연결해 볼 차례예요. OpenAI의 gpt-4o-mini 모델을 사용하는 llm은 이미 정의되어 있어요.
마지막으로 체인을 호출할 때는 원하는 어떤 활동이든 넣어 보세요! 아이디어가 떠오르지 않으면 "play the harmonica"를 입력해 보셔도 좋아요.
이 연습은 강의의 일부입니다
LangChain으로 LLM 애플리케이션 개발하기
연습 안내
- LCEL을 사용해
learning_prompt를llm에 전달하고, 해당 출력을time_prompt에 넣어 다시llm으로 보내는 순차 체인을 만드세요. - 첫 단계에서는
"learning_plan"을 키로, 첫 번째 체인을 값으로 하는 딕셔너리를 만들어야 해요. .invoke()메서드로, 원하는 활동을 넣어 체인을 호출하세요!
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
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.____({"____": "____"}))