Spaces:
Running
Running
Update app/graph/nodes/synthesizer.py
Browse files
app/graph/nodes/synthesizer.py
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# app/graph/nodes/synthesizer.py
|
| 2 |
|
| 3 |
from app.core.llm_engine import llm
|
| 4 |
from app.core.prompts.rag_prompt import rag_prompt
|
|
|
|
| 5 |
from langchain_core.output_parsers import StrOutputParser
|
| 6 |
|
| 7 |
|
|
@@ -9,18 +13,25 @@ def synthesizer_node(state):
|
|
| 9 |
route = state.get("route")
|
| 10 |
general_answer = state.get("general_answer")
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
return {
|
| 14 |
**state,
|
| 15 |
-
"final_answer": general_answer or "I couldn't find
|
| 16 |
}
|
| 17 |
-
|
|
|
|
| 18 |
query = state["query"]
|
| 19 |
context = state.get("context", "")
|
| 20 |
history = state.get("history", "")
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
answer = chain.invoke({
|
| 26 |
"context": context,
|
|
@@ -32,5 +43,4 @@ def synthesizer_node(state):
|
|
| 32 |
**state,
|
| 33 |
"final_answer": answer.strip()
|
| 34 |
}
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
|
| 4 |
# app/graph/nodes/synthesizer.py
|
| 5 |
|
| 6 |
from app.core.llm_engine import llm
|
| 7 |
from app.core.prompts.rag_prompt import rag_prompt
|
| 8 |
+
from app.core.prompts.hybrid_prompt import hybrid_prompt
|
| 9 |
from langchain_core.output_parsers import StrOutputParser
|
| 10 |
|
| 11 |
|
|
|
|
| 13 |
route = state.get("route")
|
| 14 |
general_answer = state.get("general_answer")
|
| 15 |
|
| 16 |
+
# ✅ FIX: Use 'in' operator
|
| 17 |
+
if route == "general":
|
| 18 |
return {
|
| 19 |
**state,
|
| 20 |
+
"final_answer": general_answer or "I couldn't find relevant information."
|
| 21 |
}
|
| 22 |
+
|
| 23 |
+
# Prepare common inputs
|
| 24 |
query = state["query"]
|
| 25 |
context = state.get("context", "")
|
| 26 |
history = state.get("history", "")
|
| 27 |
+
|
| 28 |
+
# ✅ Route-specific prompt selection
|
| 29 |
+
if route == "hybrid":
|
| 30 |
+
chain = hybrid_prompt | llm | StrOutputParser()
|
| 31 |
+
print("🔀 Using HYBRID prompt (doc snippet + general knowledge)")
|
| 32 |
+
else: # route == "rag"
|
| 33 |
+
chain = rag_prompt | llm | StrOutputParser()
|
| 34 |
+
print("📚 Using RAG prompt (document-only)")
|
| 35 |
|
| 36 |
answer = chain.invoke({
|
| 37 |
"context": context,
|
|
|
|
| 43 |
**state,
|
| 44 |
"final_answer": answer.strip()
|
| 45 |
}
|
| 46 |
+
|
|
|