File size: 1,053 Bytes
bf06fa6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
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_gap_prompt():
    """Get the prompt template for research gap analysis"""
    return ChatPromptTemplate.from_template("""
Analyze the following summary and identify key research gaps, unanswered questions, or limitations:
{summary}
""")

def identify_research_gaps(llm, documents):
    """
    Identify research gaps in the document
    
    Args:
        llm: Language model instance
        documents: List of document chunks
        
    Returns:
        str: Research gaps analysis
    """
    # First get summary
    summary_prompt = get_summary_prompt()
    chain1 = create_stuff_documents_chain(llm, summary_prompt)
    summary = chain1.invoke({"context": documents})
    
    # Then analyze gaps
    gap_prompt = get_gap_prompt()
    chain2 = LLMChain(llm=llm, prompt=gap_prompt)
    return chain2.invoke({"summary": summary})