첫번째 chain
특정 요리에 대한 recipe 를 제공해주는 chef chain
두번째 chain
요리의 recipe를 받아서 채식주의자용 recipe 로 변환해주는 veg_chef chain
최종 chain
위 두개의 chain 을 연결한 chain
하나의 chain의 출력값이 다른 chain의 입력값으로 사용될 수 있다.
# 첫번쨰 chain
chef_prompt = ChatPromptTemplate.from_messages([
('system',"""
You are a world-class international chef.
You create easy to follow recipes for any type of cuisines
with easy to find ingredients.
"""),
('human',"""
l want to cook {cuisine} food.
"""),
])
chef_chain = chef_prompt | chat
# 두번쩨 chain
# : 첫번째 chain 의 결과를 입력으로 받아서 '채식재료'만 사용하도록 레시피 변형.
veg_chef_prompt = ChatPromptTemplate.from_messages([
('system',"""
You are a vegetarian chef specialized on
making traditional recipies vegetarian.
You find alternative ingredients and explain their preparation.
You don't radically modify the recipe.
If there is no alternative for a food just say
you don't know how to replace it.
"""),
('human',"{recipe}"),
])
# you don't know how to replace it. 할루시네이션 방지
veg_chain = veg_chef_prompt | chat
# 최종 chain
# final_chain = chef_chain | veg_chain < - 이번 예제에선 동작하긴 하나...
#chef_chain 의 output 이 veg_chain {recipe} 입력값으로 전달 되게 하려면!
final_chain = {"recipe":chef_chain }| veg_chain
result = final_chain.invoke({
'cuisine':'indian', # 첫번쨰 chain 인 chef_chain의 {cuisine}에 전달
})
result
print(result.content)
"""
For a vegetarian version of Chicken Tikka Masala, you can replace the chicken with a plant-based alternative such as tofu or paneer. Here's how you can adapt the recipe:
Ingredients:
- 1 lb firm tofu or paneer, cut into bite-sized pieces
- 1 cup plain yogurt (you can use dairy-free yogurt for a vegan option)
- 2 tablespoons lemon juice
- 2 teaspoons ground cumin
- 2 teaspoons paprika
- 1 teaspoon ground cinnamon
- 1 teaspoon cayenne pepper (adjust to taste)
- 1 teaspoon ground black pepper
- 1 teaspoon salt
- 1 tablespoon grated fresh ginger
- 3 cloves garlic, minced
- 1 tablespoon vegetable oil
- 1 small onion, finely chopped
- 1 can (14 oz) tomato sauce
- 1 cup coconut cream (or dairy-free heavy cream alternative)
- Fresh cilantro, chopped (for garnish)
- Cooked rice or naan bread (to serve)
Instructions:
1. Follow the same marinating process as the original recipe, but use tofu or paneer instead of chicken. Coat the tofu or paneer well with the marinade and refrigerate as directed.
2. In the cooking process, you can treat tofu similarly to chicken. Pan-fry the marinated tofu until browned on all sides. For paneer, you can skip this step as it's usually added directly to the sauce.
3. Continue with the recipe by adding the onion, tomato sauce, and simmering until the sauce thickens.
4. Instead of heavy cream, use coconut cream or any dairy-free heavy cream alternative to achieve a creamy texture.
5. Adjust the seasoning as needed and serve the vegetarian Tikka Masala over rice or with naan bread, garnished with cilantro.
By making these simple swaps, you can enjoy a flavorful and satisfying vegetarian version of Chicken Tikka Masala. Enjoy your meal!
"""'AI > LLM' 카테고리의 다른 글
| LangChain - streaming = 과 callbacks (0) | 2026.05.25 |
|---|---|
| LangChain - LCEL (0) | 2026.05.23 |
| LangChain OutputParser (0) | 2026.05.19 |
| LangChain 시작 (0) | 2026.05.15 |