taaha3244 commited on
Commit
dd9d8a6
1 Parent(s): dddfd41

Create summarize.py

Browse files
Files changed (1) hide show
  1. summarize.py +14 -0
summarize.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms import OpenAI
2
+ from langchain.chains.summarize import load_summarize_chain
3
+ from utils import openai_llm
4
+
5
+
6
+ def setup_summary_chain(api_key):
7
+ """Set up a summary chain with a specified LLM."""
8
+ llm = openai_llm(api_key=api_key)
9
+ return load_summarize_chain(llm=llm, chain_type='map_reduce')
10
+
11
+ def summarize_documents(documents, api_key):
12
+ """Generate summaries for provided documents."""
13
+ summary_chain = setup_summary_chain(api_key)
14
+ return summary_chain.run(documents)