File size: 1,307 Bytes
d0f2866
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
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
from gap_analyzer import get_gap_prompt

def get_idea_prompt():
    """Get the prompt template for research idea generation"""
    return ChatPromptTemplate.from_template("""
Given the research gaps:
{gaps}
Suggest 2-3 original research project ideas or questions that address these gaps. Explain why they are valuable.
""")

def suggest_research_ideas(llm, documents):
    """
    Suggest research ideas based on identified gaps
    
    Args:
        llm: Language model instance
        documents: List of document chunks
        
    Returns:
        str: Research ideas suggestions
    """
    # First get summary
    summary_prompt = get_summary_prompt()
    chain1 = create_stuff_documents_chain(llm, summary_prompt)
    summary = chain1.invoke({"context": documents})
    
    # Then identify gaps
    gap_prompt = get_gap_prompt()
    chain2 = LLMChain(llm=llm, prompt=gap_prompt)
    gaps = chain2.invoke({"summary": summary})
    
    # Finally suggest ideas
    idea_prompt = get_idea_prompt()
    chain3 = LLMChain(llm=llm, prompt=idea_prompt)
    return chain3.invoke({"gaps": gaps})