Spaces:
Sleeping
Sleeping
Download debate_simulator.py from chburhan64/PDF_Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/chburhan64/PDF_Agent/resolve/main/debate_simulator.py
- Command line
-
hf download hf://spaces/chburhan64/PDF_Agent/debate_simulator.py
-
curl -L -o debate_simulator.py https://huggingface.co/spaces/chburhan64/PDF_Agent/resolve/main/debate_simulator.py
1.2 kB
| from langchain.chains.combine_documents import create_stuff_documents_chain | |
| from langchain.chains import LLMChain | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from summarizer import get_summary_prompt | |
| def get_debate_prompt(): | |
| """Get the prompt template for debate simulation""" | |
| return ChatPromptTemplate.from_template(""" | |
| Act as two researchers discussing a paper. | |
| Supporter: Defends the core idea of the document. | |
| Critic: Challenges its assumptions, methods, or impact. | |
| Use the following summary as reference: | |
| {summary} | |
| Generate a short conversation between them. | |
| """) | |
| def simulate_debate(llm, documents): | |
| """ | |
| Simulate a debate about the document | |
| Args: | |
| llm: Language model instance | |
| documents: List of document chunks | |
| Returns: | |
| str: Debate conversation | |
| """ | |
| # First get summary | |
| summary_prompt = get_summary_prompt() | |
| chain = create_stuff_documents_chain(llm, summary_prompt) | |
| summary = chain.invoke({"context": documents}) | |
| # Then simulate debate | |
| debate_prompt = get_debate_prompt() | |
| debate_chain = LLMChain(llm=llm, prompt=debate_prompt) | |
| return debate_chain.invoke({"summary": summary}) |