singhankur01 commited on
Commit
b91730d
·
verified ·
1 Parent(s): 97f2e71

changed prompt

Browse files
Files changed (1) hide show
  1. app.py +20 -40
app.py CHANGED
@@ -58,43 +58,18 @@ async def lifespan(app: FastAPI):
58
  # ml_models["reranker_compressor"] = CrossEncoderReranker(model=cross_encoder_model, top_n=5)
59
  ml_models["llm"] = ChatGoogleGenerativeAI(model="gemini-2.0-flash", api_key=GOOGLE_API_KEY)
60
  ml_models["prompt_template"] = PromptTemplate.from_template(
61
- """
62
- You are an expert decision maker Assistant in the domain such as insurance, legal compliance, human resources, and contract management.
63
-
64
- 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
65
- If not, the raw question is provided instead:
66
- - Query: {full_query}
67
-
68
- We retrieved the following policy clauses and rules relevant to this case:
69
- {context}
70
-
71
- Remember the below three points while answering or responsing the query :
72
- 1:Do not mention document id or its page number just ,mention clauses if applicable .
73
- 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.
74
- 3:UNDERSTAND THE QUERY ASKED SMARTLY AND ANSWER IT.
75
- ### Task:
76
- If the details about age , gender , procedure , location , policy duration are available, do all of the following:
77
- 1. Decide whether the procedure is covered.
78
- 2. Estimate the claimable amount.
79
- 3. Justify with the relevant clause.
80
- and answer the query precisely as insurance agent.
81
-
82
- Otherwise, answer the question concisely , relevently and clearly using the retrieved context.
83
-
84
- ### Output format:
85
- If query involes age , gender , procedure , location , policy duration answer like below:
86
- {{
87
- "decision": "approved / rejected",
88
- "amount": "INR amount or null",
89
- "justification": "Refer to specific clause"
90
- Make it concise ,perfect, relevent and clear .
91
- }}
92
- Else:
93
- {{
94
- "response": "Concise natural language answer"
95
- Make it concise ,perfect, relevent and clear .
96
- }}
97
- """
98
  )
99
  print("✅ Models and prompt loaded successfully!")
100
  except Exception as e:
@@ -263,9 +238,14 @@ async def run_hackrx(req: RunRequest):
263
  tasks.append(ml_models["llm"].ainvoke(ml_models["prompt_template"].format_prompt(**prompt_input)))
264
  # tasks = [hybrid_rag_chain.ainvoke({"full_query": q}) for q in req.questions]
265
  results = await asyncio.gather(*tasks)
266
-
267
- # Extract the content from each result and parse it
268
- answers = [parse_llm_response(result.content) for result in results]
 
 
 
 
 
269
 
270
  return JSONResponse({"answers": answers}, status_code=200)
271
 
 
58
  # ml_models["reranker_compressor"] = CrossEncoderReranker(model=cross_encoder_model, top_n=5)
59
  ml_models["llm"] = ChatGoogleGenerativeAI(model="gemini-2.0-flash", api_key=GOOGLE_API_KEY)
60
  ml_models["prompt_template"] = PromptTemplate.from_template(
61
+ """You are an expert insurance assistant. Your task is to answer the user's question as concisely as possible using ONLY the provided context.
62
+
63
+ Do not add any irrelevent information, explanations, or clauses that are not directly required to answer the question , also do not use bullet points make it in a sentence and perfect.
64
+
65
+ Context:
66
+ {context}
67
+
68
+ Question:
69
+ {full_query}
70
+
71
+ Concise Answer:
72
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  )
74
  print("✅ Models and prompt loaded successfully!")
75
  except Exception as e:
 
238
  tasks.append(ml_models["llm"].ainvoke(ml_models["prompt_template"].format_prompt(**prompt_input)))
239
  # tasks = [hybrid_rag_chain.ainvoke({"full_query": q}) for q in req.questions]
240
  results = await asyncio.gather(*tasks)
241
+ answers = []
242
+
243
+ for msg in results:
244
+ # Safely access the content field
245
+ if hasattr(msg, "content"):
246
+ answers.append(msg.content.strip())
247
+ # Extract the content from each result and parse it
248
+ # answers = [parse_llm_response(result.content) for result in results]
249
 
250
  return JSONResponse({"answers": answers}, status_code=200)
251