Skip to content

Commit b1820af

Browse files
committed
Wikipedia Tool. Final README updates
1 parent 02a3525 commit b1820af

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

first/README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
# First LangChain tutorial
22
This is the first LangChain tutorial hands-on.
33
It's a Youtube script generator using OpenAI LLM.
4+
It covers the following topics:
5+
* Streamlist for Web App development
6+
* LLMChain
7+
* PromptTemplate
8+
* SimpleSequentialChain
9+
* SequentialChain
10+
* ConversationalMemoryBuffer
11+
* WikipediaAPIWrapper
12+
413

514
### Pre-requisites
15+
616
$ pip install openai langchain streamlit wikipedia chromadb tiktoken
717

18+
* Install the above Python packages
19+
* Replace the API key in the file `apikey.py` with your own OpenAI API
820
### Running
921
$ streamlit run app.py
1022

11-
Reference : https://www.youtube.com/watch?v=MlK6SIjcjE8
23+
## Reference
24+
* Video tutorial: https://www.youtube.com/watch?v=MlK6SIjcjE8
25+
* Langchain Docs: https://python.langchain.com/en/latest/index.html
26+
* Streamlist: https://streamlit.io/

first/app.py

+29-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from langchain.prompts import PromptTemplate
77
from langchain.chains import LLMChain, SequentialChain
88
from langchain.memory import ConversationBufferMemory
9+
from langchain.utilities import WikipediaAPIWrapper
910

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

@@ -19,28 +20,40 @@
1920
)
2021

2122
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}'
2425
)
2526

2627
# 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')
2830

2931
# LLMs
3032
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)
3335

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()
3838

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)
4443

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

Comments
 (0)