-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLangchain_SimpleSequentialChain.py
More file actions
36 lines (26 loc) · 1.14 KB
/
Langchain_SimpleSequentialChain.py
File metadata and controls
36 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import streamlit as st
import os
from langchain.llms import OpenAI
from langchain import PromptTemplate
from langchain.chains import LLMChain
from langchain.chains import SimpleSequentialChain
openai_key = "********************************************"
os.environ["OPENAI_API_KEY"] = openai_key
st.title('Langchain Demo with OpenAI')
input_text = st.text_input("Search about any Car")
first_input_prompt = PromptTemplate (
input_variables =['car_name'],
template="Give me the mileage, company and on road price in India about {car_name}"
)
llm = OpenAI(temperature=0.8)
chain = LLMChain(llm = llm, prompt = first_input_prompt, verbose = True, output_key ='answer1')
second_input_prompt = PromptTemplate (
input_variables =['answer1'],
template="Give me the mileage, company details of {answer1} of similar type"
)
chain2 = LLMChain(llm = llm, prompt = second_input_prompt, verbose=True)
# parent_chain = SimpleSequentialChain(chains=[chain,chain2],verbose=True)
parent_chain = SimpleSequentialChain(
chains=[chain,chain2],verbose=True)
if input_text:
st.write(parent_chain.run(input_text))