4
4
import streamlit as st
5
5
from langchain .llms import OpenAI
6
6
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
8
9
9
10
os .environ ['OPENAI_API_KEY' ] = apikey
10
11
11
- st .title ('🦜🔗 LangChain 0.0.193 Tutorial - YouTube GPT Creator ' )
12
+ st .title ('🦜🔗 LangChain Tutorial - YouTube GPT Creator - by Raseel ' )
12
13
prompt = st .text_input ('Prompt: Write me a Youtube Video Script about' )
13
14
14
15
# Prompt Templates
22
23
template = 'Write me a Youtube Video script based on this title, TITLE {title}'
23
24
)
24
25
26
+ # Memory
27
+ memory = ConversationBufferMemory (input_key = 'topic' , memory_key = 'chat_history' )
28
+
25
29
# LLMs
26
30
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 )
29
33
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 )
31
38
32
39
if prompt :
33
40
#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