Spaces:
Sleeping
Sleeping
Update app.py
Browse files68 unmodified lines69707172737475767778798081828384858687888963 unmodified lines153154155156157158159103 unmodified lines26326426526626726826927027127227327427568 unmodified linesmax_output_tokens=300)ml_models["prompt_template"] = PromptTemplate.from_template("""**Role**: You are an expert decision maker Assistant in the domain such as insurance, legal compliance, human resources, and contract management.**Context**:{context}**Query**: {full_query}**Instructions**: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 :- Output ONLY JSON: {{"decision":"approved/rejected","amount":"₹X","justification":"Clause reference"}}2. Else: Provide concise answer3. NEVER mention document sources4. If unsure, respond: "Insufficient information"**Response**:""")print("✅ Models and prompt loaded successfully!")63 unmodified lines)# dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8})dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8 ,"lambda_mult": 0.6})# Create retrievers using the pre-loaded models from our ml_models dictionary103 unmodified lines# # Extract the content from each result and parse ittasks = [hybrid_rag_chain.ainvoke({"full_query": q}) for q in req.questions]results = await asyncio.gather(*tasks)# answers = [parse_llm_response(result.content) for result in results]answers = []for msg in results:# Safely access the content fieldif hasattr(msg, "content"):answers.append(msg.content.strip())return JSONResponse({"answers": answers}, status_code=200)68 unmodified lines6970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810963 unmodified lines173174175176177178179103 unmodified lines28328428528628728828929029129229329429568 unmodified linesmax_output_tokens=300)ml_models["prompt_template"] = PromptTemplate.from_template("""You are an expert decision maker Assistant in the domain such as insurance, legal compliance, human resources, and contract management.Do not add any irrelevent information, also do not use bullet points, make it in a perfect sentence answer.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 properlyIf not, the raw question is provided instead:- Query: {full_query}We retrieved the following policy clauses and rules relevant to this case:{context}Remember the below three points while answering or responsing the query :1:Do not mention document id or its page number just ,mention clauses if applicable .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.### Task:If the details about age , gender , procedure , location , policy duration are available, do all of the following:1. Decide whether the procedure is covered.2. Estimate the claimable amount.3. Justify with the relevant clause.and answer the query precisely as insurance agent.Otherwise, answer the question concisely , relevently and clearly using the retrieved context.### Output format:If query involes age , gender , procedure , location , policy duration answer like below:{{"decision": "approved / rejected","amount": "INR amount or null","justification": "Refer to specific clause"Make it concise ,perfect, relevent and clear .}}Else:{{"response": "Concise natural language answer"Make it concise ,perfect, relevent and clear .}}""")print("✅ Models and prompt loaded successfully!")63 unmodified lines)# dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8})dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8 ,"lambda_mult": 0.5})# Create retrievers using the pre-loaded models from our ml_models dictionary103 unmodified lines# # Extract the content from each result and parse ittasks = [hybrid_rag_chain.ainvoke({"full_query": q}) for q in req.questions]results = await asyncio.gather(*tasks)answers = [parse_llm_response(result.content) for result in results]# answers = []# for msg in results:# # Safely access the content field# if hasattr(msg, "content"):# answers.append(msg.content.strip())return JSONResponse({"answers": answers}, status_code=200)
app.py+38-18