Spaces:
Runtime error
Runtime error
File size: 844 Bytes
bbe5b39 dd9d8a6 bbe5b39 dd9d8a6 bbe5b39 dd9d8a6 bbe5b39 |
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 |
import os
from langchain.chains.summarize import load_summarize_chain
from utils import openai_llm
from dotenv import load_dotenv
from langfuse.callback import CallbackHandler
load_dotenv()
os.environ["LANGFUSE_PUBLIC_KEY"] = os.getenv("LANGFUSE_PUBLIC_KEY")
os.environ["LANGFUSE_SECRET_KEY"] = os.getenv("LANGFUSE_SECRET_KEY")
os.environ["LANGFUSE_HOST"] = os.getenv("LANGFUSE_HOST")
langfuse_handler = CallbackHandler()
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, callbacks=[langfuse_handler]) |