Spaces:
Running
Running
File size: 1,220 Bytes
51fa3c2 1fa7f25 51fa3c2 1fa7f25 51fa3c2 1fa7f25 51fa3c2 1fa7f25 51fa3c2 1fa7f25 51fa3c2 1fa7f25 | 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 40 41 42 43 | # 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()
}
|