Smart-Notes-backend / app /graph /nodes /synthesizer.py
pluto90's picture
Update app/graph/nodes/synthesizer.py
81f75a5 verified
# app/graph/nodes/synthesizer.py
from app.core.llm_engine import llm
from app.core.prompts.rag_prompt import rag_prompt
from app.core.prompts.hybrid_prompt import hybrid_prompt
from langchain_core.output_parsers import StrOutputParser
def synthesizer_node(state):
route = state.get("route")
general_answer = state.get("general_answer")
# βœ… FIX: Use 'in' operator
if route == "general":
return {
**state,
"final_answer": general_answer or "I couldn't find relevant information."
}
# Prepare common inputs
query = state["query"]
context = state.get("context", "")
history = state.get("history", "")
# βœ… Route-specific prompt selection
if route == "hybrid":
chain = hybrid_prompt | llm | StrOutputParser()
print("πŸ”€ Using HYBRID prompt (doc snippet + general knowledge)")
else: # route == "rag"
chain = rag_prompt | llm | StrOutputParser()
print("πŸ“š Using RAG prompt (document-only)")
answer = chain.invoke({
"context": context,
"query": query,
"history": history
})
return {
**state,
"final_answer": answer.strip()
}