Spaces:
Sleeping
Sleeping
Jakaria commited on
Commit ·
cc2eb6d
1
Parent(s): 02e3818
Add Bangla model API
Browse files
rag.py
CHANGED
|
@@ -36,50 +36,34 @@ def build_chain():
|
|
| 36 |
llm = ChatGroq(model=GROQ_MODEL, api_key=GROQ_API_KEY, temperature=0.1)
|
| 37 |
|
| 38 |
# ---- System + Human Prompt with diverse few-shot examples ----
|
|
|
|
|
|
|
| 39 |
chat_prompt = ChatPromptTemplate.from_messages([
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
{context}
|
| 48 |
|
| 49 |
-
Question:
|
| 50 |
{question}
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
Reference: page:5
|
| 58 |
-
|
| 59 |
-
Question: Who is responsible for preparing the annual budget?
|
| 60 |
-
Answer: The Ministry of Finance is responsible for preparing the annual budget, ensuring alignment with government policies.
|
| 61 |
-
Reference: page:12
|
| 62 |
-
|
| 63 |
-
Question: When is the fiscal report published each year?
|
| 64 |
-
Answer: The fiscal report is published annually in September to provide transparency on government revenues and expenditures.
|
| 65 |
-
Reference: page:20
|
| 66 |
-
|
| 67 |
-
Question: Where can one find the details of government subsidies in the document?
|
| 68 |
-
Answer: Details of government subsidies are provided in the fiscal policy section under the heading 'Subsidies and Support Programs'.
|
| 69 |
-
Reference: page:15
|
| 70 |
|
| 71 |
-
|
| 72 |
-
Answer: The financial risk management framework is important to identify, assess, and mitigate potential risks in government financial operations.
|
| 73 |
-
Reference: page:18
|
| 74 |
-
|
| 75 |
-
Question: How does the government evaluate financial policy effectiveness?
|
| 76 |
-
Answer: The government evaluates financial policy effectiveness using key performance indicators and benchmarking against fiscal objectives.
|
| 77 |
-
Reference: page:22
|
| 78 |
-
|
| 79 |
-
Now answer the user's question in the same format:
|
| 80 |
"""
|
| 81 |
-
|
| 82 |
-
|
|
|
|
| 83 |
|
| 84 |
chain = ConversationalRetrievalChain.from_llm(
|
| 85 |
llm=llm,
|
|
|
|
| 36 |
llm = ChatGroq(model=GROQ_MODEL, api_key=GROQ_API_KEY, temperature=0.1)
|
| 37 |
|
| 38 |
# ---- System + Human Prompt with diverse few-shot examples ----
|
| 39 |
+
from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
|
| 40 |
+
|
| 41 |
chat_prompt = ChatPromptTemplate.from_messages([
|
| 42 |
+
SystemMessagePromptTemplate.from_template(
|
| 43 |
+
"You are a highly knowledgeable financial expert assistant. "
|
| 44 |
+
"Use the context provided to answer the user question accurately. "
|
| 45 |
+
"Always provide the answer in clear, concise sentences. "
|
| 46 |
+
"Cite the reference (page number or section title) from the PDF where the information was found. "
|
| 47 |
+
"If the answer is not present in the context, say 'The information is not available in the provided document.'"
|
| 48 |
+
),
|
| 49 |
+
HumanMessagePromptTemplate.from_template(
|
| 50 |
+
"""Context:
|
| 51 |
{context}
|
| 52 |
|
| 53 |
+
User Question:
|
| 54 |
{question}
|
| 55 |
|
| 56 |
+
Instructions:
|
| 57 |
+
- Answer the question clearly and concisely.
|
| 58 |
+
- Always start the answer naturally (What, Who, When, Where, Why, How) depending on the question.
|
| 59 |
+
- Include the reference where the information is found in the format: Reference: page:X or section name.
|
| 60 |
+
- If the information is not in the context, state clearly that it is not available.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
Answer:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
"""
|
| 64 |
+
)
|
| 65 |
+
])
|
| 66 |
+
|
| 67 |
|
| 68 |
chain = ConversationalRetrievalChain.from_llm(
|
| 69 |
llm=llm,
|