Skip to content

Commit 02a3525

Browse files
committed
SequentialChain and ConversationalBufferMemory
1 parent b119c24 commit 02a3525

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

first/app.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import streamlit as st
55
from langchain.llms import OpenAI
66
from langchain.prompts import PromptTemplate
7-
from langchain.chains import LLMChain, SimpleSequentialChain
7+
from langchain.chains import LLMChain, SequentialChain
8+
from langchain.memory import ConversationBufferMemory
89

910
os.environ['OPENAI_API_KEY'] = apikey
1011

11-
st.title('🦜🔗 LangChain 0.0.193 Tutorial - YouTube GPT Creator ')
12+
st.title('🦜🔗 LangChain Tutorial - YouTube GPT Creator - by Raseel ')
1213
prompt = st.text_input('Prompt: Write me a Youtube Video Script about')
1314

1415
# Prompt Templates
@@ -22,14 +23,24 @@
2223
template='Write me a Youtube Video script based on this title, TITLE {title}'
2324
)
2425

26+
# Memory
27+
memory = ConversationBufferMemory(input_key='topic', memory_key='chat_history')
28+
2529
# LLMs
2630
llm = OpenAI(temperature=0.9)
27-
title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True)
28-
script_chain = LLMChain(llm=llm, prompt=script_template, verbose=True)
31+
title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True, output_key='title', memory=memory)
32+
script_chain = LLMChain(llm=llm, prompt=script_template, verbose=True, output_key='script', memory=memory)
2933

30-
sequential_chain = SimpleSequentialChain(chains=[title_chain, script_chain], verbose=True)
34+
sequential_chain = SequentialChain(chains=[title_chain, script_chain],
35+
input_variables=['topic'],
36+
output_variables=['title', 'script'],
37+
verbose=True)
3138

3239
if prompt:
3340
#response = title_chain.run(topic=prompt)
34-
response = sequential_chain.run(prompt)
35-
st.write(response)
41+
response = sequential_chain({'topic':prompt})
42+
st.write(response['title'])
43+
st.write(response['script'])
44+
45+
with st.expander('Message History:'):
46+
st.info(memory.buffer)

0 commit comments

Comments
 (0)