6
6
from langchain .prompts import PromptTemplate
7
7
from langchain .chains import LLMChain , SequentialChain
8
8
from langchain .memory import ConversationBufferMemory
9
+ from langchain .utilities import WikipediaAPIWrapper
9
10
10
11
os .environ ['OPENAI_API_KEY' ] = apikey
11
12
19
20
)
20
21
21
22
script_template = PromptTemplate (
22
- input_variables = ['title' ],
23
- template = 'Write me a Youtube Video script based on this title, TITLE {title}'
23
+ input_variables = ['title' , 'wikipedia_research' ],
24
+ template = 'Write me a Youtube Video script based on the title, TITLE {title} while leveraging its Wikipedia researc: {wikipedia_research }'
24
25
)
25
26
26
27
# Memory
27
- memory = ConversationBufferMemory (input_key = 'topic' , memory_key = 'chat_history' )
28
+ title_memory = ConversationBufferMemory (input_key = 'topic' , memory_key = 'chat_history' )
29
+ script_memory = ConversationBufferMemory (input_key = 'title' , memory_key = 'chat_history' )
28
30
29
31
# LLMs
30
32
llm = OpenAI (temperature = 0.9 )
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 )
33
+ title_chain = LLMChain (llm = llm , prompt = title_template , verbose = True , output_key = 'title' , memory = title_memory )
34
+ script_chain = LLMChain (llm = llm , prompt = script_template , verbose = True , output_key = 'script' , memory = script_memory )
33
35
34
- sequential_chain = SequentialChain (chains = [title_chain , script_chain ],
35
- input_variables = ['topic' ],
36
- output_variables = ['title' , 'script' ],
37
- verbose = True )
36
+ # Tools
37
+ wiki = WikipediaAPIWrapper ()
38
38
39
- if prompt :
40
- #response = title_chain.run(topic=prompt)
41
- response = sequential_chain ({'topic' :prompt })
42
- st .write (response ['title' ])
43
- st .write (response ['script' ])
39
+ # sequential_chain = SequentialChain(chains=[title_chain, script_chain],
40
+ # input_variables=['topic'],
41
+ # output_variables=['title', 'script'],
42
+ # verbose=True)
44
43
45
- with st .expander ('Message History:' ):
46
- st .info (memory .buffer )
44
+ if prompt :
45
+ title = title_chain .run (prompt )
46
+ wiki_research = wiki .run (prompt )
47
+ script = script_chain .run (title = title , wikipedia_research = wiki_research )
48
+
49
+ st .write (title )
50
+ st .write (script )
51
+
52
+ with st .expander ('Title History:' ):
53
+ st .info (title_memory .buffer )
54
+
55
+ with st .expander ('Script History:' ):
56
+ st .info (script_memory .buffer )
57
+
58
+ with st .expander ('Wikipedia Research:' ):
59
+ st .info (wiki_research )
0 commit comments