Lab7 LLM Chains
Lab7 LLM Chains
Lab7 LLM Chains
: Creating applications using different types of LangChains – Simple Sequential, Sequential and map reduce
Ex1 : Simple Sequential LLM CHains - Chains with single input and single output
#Using LLM Chains Suggest a good name for a company that makes a particular product
###############################################################################
prompt1 = PromptTemplate.from_template(template)
prompt2 = PromptTemplate.from_template(template)
final_chain = SimpleSequentialChain(
chains = [chain1,chain2],
verbose = True)
response = final_chain.run("Noodles")
print(response)
SEQUENTIAL CHAIN
EX2 : USING A SEQUENTIAL LANGCHAIN, FIND THE YEAR WHEN “FORD” WAS LAUNCHED AND LIST
THE TOP 5 CAR MODELS OF THAT YEAR
prompt1 = PromptTemplate(
input_variables = ['name'],
prompt2 = PromptTemplate(
input_variables = ["year"],
chain2 = LLMChain(llm = llm, prompt = prompt2, verbose = True, output_key = 'top 5')
final_chain = SequentialChain(
chains = [chain1,chain2],
input_variables = ['name'],
print(response)
****************************************************************************
Ex3 FIND THE YEAR WHEN “FORD” LAUNCHED “ECO-SPORT”. FIND SIMILAR PRODUCTS LAUNCHED
IN THAT YEAR
prompt1 = PromptTemplate(
prompt2 = PromptTemplate(
input_variables = ["year"],
chain2 = LLMChain(llm = llm, prompt = prompt2, verbose = True, output_key = 'four similar')
final_chain = SequentialChain(
chains = [chain1,chain2],
print(response)
PROBLEM: TRANSLATE THE GIVEN REVIEW To ENGLISH. SUMMARIZE IT. FIND THE LANGUAGE IN
WHICH THE REVIEW IS WRITTEN. WRITE A FOLLOW UP RESPONSE TO THE SUMARY IN A GIVEN
LANGUAGE.
de jeu et portabilité."""
"\n\n{Review}"
prompt2 = ChatPromptTemplate.from_template(
"\n\n{Eng_review}"
prompt3 = ChatPromptTemplate.from_template(
"\n\n{Review}"
)
#Chain 3 : Input : Review Output : language
#Promp Template 4 : Write a follow up response to the summary in the language given
prompt4 = ChatPromptTemplate.from_template(
final_chain = SequentialChain(
chains = [chain1,chain2,chain3,chain4],
input_variables = ["Review"],
verbose = True)
response = final_chain(Review)