File size: 1,500 Bytes
195e631
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# # app/graph/rag_answer_node.py

# from langchain_core.prompts import PromptTemplate
# from app.core.llm_engine import run_llm
# from app.core.prompts.rag_prompt import rag_prompt
# # rag_prompt = PromptTemplate(
# #     input_variables=["context", "query"],
# #     template=(
# #         "You are a document intelligence system.\n"
# #         "Answer ONLY using the provided context.\n"
# #         "If answer is not present, say: 'Not in document'.\n\n"

# #         "Keep response concise:\n"
# #         "- Short explanation\n"
# #         "- Bullet points if useful\n"
# #         "- Max 120 words\n\n"

# #         "Avoid repeating the question.\n\n"

# #         "Context:\n{context}\n\n"
# #         "Question:\n{query}\n\n"
# #         "Answer:"
# #     )
# # )
 
# def rag_answer_node(state):
#     response = run_llm(rag_prompt, {
#         "context": state.get("context", ""),
#         "query": state.get("query")
#     })

#     return {
#         **state,
#         "final_answer": response
#     }












from app.core.llm_engine import llm
from app.core.prompts.rag_prompt import rag_prompt
from langchain_core.output_parsers import StrOutputParser

chain = rag_prompt | llm | StrOutputParser()


def rag_answer_node(state):
    response = chain.invoke({
        "context": state.get("context", ""),
        "query": state.get("query")
    })

    return {
        **state,
        "final_answer": response
    }