Last active
May 27, 2025 11:39
-
-
Save mrityunjay-genai/a3ed64fc37c3104904794bbc34837e45 to your computer and use it in GitHub Desktop.
Types of Chain - Langchain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from langchain_openai import ChatOpenAI | |
from dotenv import load_dotenv | |
from langchain_core.prompts import PromptTemplate | |
from langchain_core.output_parsers import StrOutputParser | |
load_dotenv() | |
prompt = PromptTemplate( | |
template='Generate 5 interesting facts about {topic}', | |
input_variables=['topic'] | |
) | |
model = ChatOpenAI() | |
parser = StrOutputParser() | |
chain = prompt | model | parser | |
result = chain.invoke({'topic':'cricket'}) | |
print(result) | |
# To Visualize the chain Process | |
chain.get_graph().print_ascii() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from langchain_openai import ChatOpenAI | |
from dotenv import load_dotenv | |
from langchain_core.prompts import PromptTemplate | |
from langchain_core.output_parsers import StrOutputParser | |
load_dotenv() | |
prompt1 = PromptTemplate( | |
template='Generate a detailed report on {topic}', | |
input_variables=['topic'] | |
) | |
prompt2 = PromptTemplate( | |
template='Generate a 5 pointer summary from the following text \n {text}', | |
input_variables=['text'] | |
) | |
model = ChatOpenAI() | |
parser = StrOutputParser() | |
chain = prompt1 | model | parser | prompt2 | model | parser | |
result = chain.invoke({'topic': 'Unemployment in India'}) | |
print(result) | |
chain.get_graph().print_ascii() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment