singhankur01 commited on
Commit
c91485b
·
verified ·
1 Parent(s): 3ded8a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -18
app.py CHANGED
@@ -69,21 +69,41 @@ async def lifespan(app: FastAPI):
69
  max_output_tokens=300
70
  )
71
  ml_models["prompt_template"] = PromptTemplate.from_template("""
72
- **Role**: You are an expert decision maker Assistant in the domain such as insurance, legal compliance, human resources, and contract management.
 
 
 
 
73
 
74
- **Context**:
75
  {context}
76
 
77
- **Query**: {full_query}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- **Instructions**:
80
- 1. If query contains age ,gender,procedure,duration , location ,and query like can i get a knee surgery ,if i am male and duration is 3months or any query is similar to the previus example :
81
- - Output ONLY JSON: {{"decision":"approved/rejected","amount":"₹X","justification":"Clause reference"}}
82
- 2. Else: Provide concise answer
83
- 3. NEVER mention document sources
84
- 4. If unsure, respond: "Insufficient information"
85
-
86
- **Response**:
87
  """
88
  )
89
  print("✅ Models and prompt loaded successfully!")
@@ -153,7 +173,7 @@ async def run_hackrx(req: RunRequest):
153
  )
154
 
155
  # dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8})
156
- dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8 ,"lambda_mult": 0.6})
157
 
158
 
159
  # Create retrievers using the pre-loaded models from our ml_models dictionary
@@ -263,13 +283,13 @@ async def run_hackrx(req: RunRequest):
263
  # # Extract the content from each result and parse it
264
  tasks = [hybrid_rag_chain.ainvoke({"full_query": q}) for q in req.questions]
265
  results = await asyncio.gather(*tasks)
266
- # answers = [parse_llm_response(result.content) for result in results]
267
- answers = []
268
 
269
- for msg in results:
270
- # Safely access the content field
271
- if hasattr(msg, "content"):
272
- answers.append(msg.content.strip())
273
 
274
  return JSONResponse({"answers": answers}, status_code=200)
275
 
 
69
  max_output_tokens=300
70
  )
71
  ml_models["prompt_template"] = PromptTemplate.from_template("""
72
+ You are an expert decision maker Assistant in the domain such as insurance, legal compliance, human resources, and contract management.
73
+ Do not add any irrelevent information, also do not use bullet points, make it in a perfect sentence answer.
74
+ The customer has submitted a query. If the query has details about age , gender ,procedure ,location , policy duration, then parse it and understand the query properly
75
+ If not, the raw question is provided instead:
76
+ - Query: {full_query}
77
 
78
+ We retrieved the following policy clauses and rules relevant to this case:
79
  {context}
80
 
81
+ Remember the below three points while answering or responsing the query :
82
+ 1:Do not mention document id or its page number just ,mention clauses if applicable .
83
+ 2:Do not make such statement in the response that you need more document or information to answer the query, just answer from retrieved data.
84
+ ### Task:
85
+ If the details about age , gender , procedure , location , policy duration are available, do all of the following:
86
+ 1. Decide whether the procedure is covered.
87
+ 2. Estimate the claimable amount.
88
+ 3. Justify with the relevant clause.
89
+ and answer the query precisely as insurance agent.
90
+
91
+ Otherwise, answer the question concisely , relevently and clearly using the retrieved context.
92
+
93
+ ### Output format:
94
+ If query involes age , gender , procedure , location , policy duration answer like below:
95
+ {{
96
+ "decision": "approved / rejected",
97
+ "amount": "INR amount or null",
98
+ "justification": "Refer to specific clause"
99
+ Make it concise ,perfect, relevent and clear .
100
+ }}
101
+ Else:
102
+ {{
103
+ "response": "Concise natural language answer"
104
+ Make it concise ,perfect, relevent and clear .
105
+ }}
106
 
 
 
 
 
 
 
 
 
107
  """
108
  )
109
  print("✅ Models and prompt loaded successfully!")
 
173
  )
174
 
175
  # dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8})
176
+ dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8 ,"lambda_mult": 0.5})
177
 
178
 
179
  # Create retrievers using the pre-loaded models from our ml_models dictionary
 
283
  # # Extract the content from each result and parse it
284
  tasks = [hybrid_rag_chain.ainvoke({"full_query": q}) for q in req.questions]
285
  results = await asyncio.gather(*tasks)
286
+ answers = [parse_llm_response(result.content) for result in results]
287
+ # answers = []
288
 
289
+ # for msg in results:
290
+ # # Safely access the content field
291
+ # if hasattr(msg, "content"):
292
+ # answers.append(msg.content.strip())
293
 
294
  return JSONResponse({"answers": answers}, status_code=200)
295