Update agents/future_works_agent.py
Browse files- agents/future_works_agent.py +88 -92
agents/future_works_agent.py
CHANGED
|
@@ -1,93 +1,89 @@
|
|
| 1 |
-
from langchain.vectorstores import FAISS
|
| 2 |
-
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 3 |
-
import os
|
| 4 |
-
from agents import SearchAgent
|
| 5 |
-
import streamlit as st
|
| 6 |
-
from config.config import model
|
| 7 |
-
|
| 8 |
-
embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
|
| 9 |
-
|
| 10 |
-
class FutureWorksAgent:
|
| 11 |
-
def __init__(self):
|
| 12 |
-
self.model = model
|
| 13 |
-
self.prompt = """Analyze the research context and provide targeted insights based on the specific task type.
|
| 14 |
-
|
| 15 |
-
Previous conversation:
|
| 16 |
-
{chat_history}
|
| 17 |
-
|
| 18 |
-
Current research context:
|
| 19 |
-
{context}
|
| 20 |
-
|
| 21 |
-
Task Type Detection:
|
| 22 |
-
1. Review Paper Future Work:
|
| 23 |
-
If the query involves generating future work for a review paper:
|
| 24 |
-
- Identify emerging trends and unexplored areas
|
| 25 |
-
- Suggest potential research questions
|
| 26 |
-
- Outline methodology gaps
|
| 27 |
-
- Propose innovative approaches
|
| 28 |
-
|
| 29 |
-
2. Structured Review Summary:
|
| 30 |
-
If the query involves creating a review paper summary:
|
| 31 |
-
- Synthesize key findings across papers
|
| 32 |
-
- Identify major research themes
|
| 33 |
-
- Highlight methodological approaches
|
| 34 |
-
- Present conflicting results or debates
|
| 35 |
-
- Suggest future research opportunities
|
| 36 |
-
|
| 37 |
-
3. Improvement Plan:
|
| 38 |
-
If the query involves generating an improvement plan:
|
| 39 |
-
- Analyze existing solutions and their limitations
|
| 40 |
-
- Identify potential enhancements
|
| 41 |
-
- Suggest novel technical contributions
|
| 42 |
-
- Propose validation approaches
|
| 43 |
-
- Outline implementation steps
|
| 44 |
-
|
| 45 |
-
4. Research Direction Synthesis:
|
| 46 |
-
If the query involves combining multiple papers:
|
| 47 |
-
- Identify common themes and patterns
|
| 48 |
-
- Highlight complementary approaches
|
| 49 |
-
- Suggest novel combinations of methods
|
| 50 |
-
- Propose new research directions
|
| 51 |
-
- Outline potential experimental designs
|
| 52 |
-
|
| 53 |
-
Format Guidelines:
|
| 54 |
-
- Begin with identifying the specific task type
|
| 55 |
-
- Provide structured, section-wise response
|
| 56 |
-
- Include specific examples from papers
|
| 57 |
-
- List concrete action items or suggestions
|
| 58 |
-
- Acknowledge limitations and assumptions
|
| 59 |
-
- Suggest validation approaches
|
| 60 |
-
|
| 61 |
-
Note: Focus on providing actionable, specific suggestions rather than general statements.
|
| 62 |
-
Consider both theoretical advances and practical implementations.
|
| 63 |
-
"""
|
| 64 |
-
|
| 65 |
-
self.papers = None
|
| 66 |
-
self.search_agent_response = ""
|
| 67 |
-
|
| 68 |
-
def solve(self, query):
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
# Get
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
#
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
chat_history=chat_history_text,
|
| 90 |
-
context=context
|
| 91 |
-
)
|
| 92 |
-
response = self.model.generate_content(str(self.search_agent_response) + full_prompt)
|
| 93 |
return response.text , self.papers
|
|
|
|
| 1 |
+
from langchain.vectorstores import FAISS
|
| 2 |
+
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 3 |
+
import os
|
| 4 |
+
from agents import SearchAgent
|
| 5 |
+
import streamlit as st
|
| 6 |
+
from config.config import model
|
| 7 |
+
|
| 8 |
+
embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
|
| 9 |
+
|
| 10 |
+
class FutureWorksAgent:
|
| 11 |
+
def __init__(self):
|
| 12 |
+
self.model = model
|
| 13 |
+
self.prompt = """Analyze the research context and provide targeted insights based on the specific task type.
|
| 14 |
+
|
| 15 |
+
Previous conversation:
|
| 16 |
+
{chat_history}
|
| 17 |
+
|
| 18 |
+
Current research context:
|
| 19 |
+
{context}
|
| 20 |
+
|
| 21 |
+
Task Type Detection:
|
| 22 |
+
1. Review Paper Future Work:
|
| 23 |
+
If the query involves generating future work for a review paper:
|
| 24 |
+
- Identify emerging trends and unexplored areas
|
| 25 |
+
- Suggest potential research questions
|
| 26 |
+
- Outline methodology gaps
|
| 27 |
+
- Propose innovative approaches
|
| 28 |
+
|
| 29 |
+
2. Structured Review Summary:
|
| 30 |
+
If the query involves creating a review paper summary:
|
| 31 |
+
- Synthesize key findings across papers
|
| 32 |
+
- Identify major research themes
|
| 33 |
+
- Highlight methodological approaches
|
| 34 |
+
- Present conflicting results or debates
|
| 35 |
+
- Suggest future research opportunities
|
| 36 |
+
|
| 37 |
+
3. Improvement Plan:
|
| 38 |
+
If the query involves generating an improvement plan:
|
| 39 |
+
- Analyze existing solutions and their limitations
|
| 40 |
+
- Identify potential enhancements
|
| 41 |
+
- Suggest novel technical contributions
|
| 42 |
+
- Propose validation approaches
|
| 43 |
+
- Outline implementation steps
|
| 44 |
+
|
| 45 |
+
4. Research Direction Synthesis:
|
| 46 |
+
If the query involves combining multiple papers:
|
| 47 |
+
- Identify common themes and patterns
|
| 48 |
+
- Highlight complementary approaches
|
| 49 |
+
- Suggest novel combinations of methods
|
| 50 |
+
- Propose new research directions
|
| 51 |
+
- Outline potential experimental designs
|
| 52 |
+
|
| 53 |
+
Format Guidelines:
|
| 54 |
+
- Begin with identifying the specific task type
|
| 55 |
+
- Provide structured, section-wise response
|
| 56 |
+
- Include specific examples from papers
|
| 57 |
+
- List concrete action items or suggestions
|
| 58 |
+
- Acknowledge limitations and assumptions
|
| 59 |
+
- Suggest validation approaches
|
| 60 |
+
|
| 61 |
+
Note: Focus on providing actionable, specific suggestions rather than general statements.
|
| 62 |
+
Consider both theoretical advances and practical implementations.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
self.papers = None
|
| 66 |
+
self.search_agent_response = ""
|
| 67 |
+
|
| 68 |
+
def solve(self, query):
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# Load vector store
|
| 73 |
+
vector_db = FAISS.load_local("vector_db", embeddings, index_name="base_and_adjacent", allow_dangerous_deserialization=True)
|
| 74 |
+
|
| 75 |
+
# Get chat history
|
| 76 |
+
chat_history = st.session_state.get("chat_history", [])
|
| 77 |
+
chat_history_text = "".join([f"{sender}: {msg}" for sender, msg in chat_history[-5:]])
|
| 78 |
+
|
| 79 |
+
# Get relevant chunks
|
| 80 |
+
retrieved = vector_db.as_retriever().get_relevant_documents(query)
|
| 81 |
+
context = "".join([f"{doc.page_content}\n Source: {doc.metadata['source']}" for doc in retrieved])
|
| 82 |
+
|
| 83 |
+
# Generate response
|
| 84 |
+
full_prompt = self.prompt.format(
|
| 85 |
+
chat_history=chat_history_text,
|
| 86 |
+
context=context
|
| 87 |
+
)
|
| 88 |
+
response = self.model.generate_content(str(self.search_agent_response) + full_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return response.text , self.papers
|