Lex / summarize.py
taaha3244's picture
Create summarize.py
dd9d8a6 verified
raw
history blame
515 Bytes
from langchain_community.llms import OpenAI
from langchain.chains.summarize import load_summarize_chain
from utils import openai_llm
def setup_summary_chain(api_key):
"""Set up a summary chain with a specified LLM."""
llm = openai_llm(api_key=api_key)
return load_summarize_chain(llm=llm, chain_type='map_reduce')
def summarize_documents(documents, api_key):
"""Generate summaries for provided documents."""
summary_chain = setup_summary_chain(api_key)
return summary_chain.run(documents)