-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummarizer.py
More file actions
30 lines (22 loc) · 953 Bytes
/
Copy pathsummarizer.py
File metadata and controls
30 lines (22 loc) · 953 Bytes
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
# LangChain Text Summarizer
# Based on https://python.langchain.com/docs/use_cases/summarization
# Example usage:
# python3 summarizer.py "https://www.forbes.com/sites/bryanrobinson/2020/09/02/why-neuroscientists-say-boredom-is-good-for-your-brains-health/"
import argparse
import dotenv
dotenv.load_dotenv()
from langchain.chat_models import ChatOpenAI
from langchain.document_loaders import WebBaseLoader
from langchain.chains.summarize import load_summarize_chain
# Parse command line arguments
parser = argparse.ArgumentParser(description='Process some URLs.')
parser.add_argument('url', type=str, help='The URL to process')
args = parser.parse_args()
loader = WebBaseLoader(args.url)
docs = loader.load()
llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")
chain = load_summarize_chain(llm, chain_type="stuff")
# Run the summarization and store the result in a variable
result = chain.run(docs)
# Print the result
print(result)