Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,30 +28,34 @@ class AgentMessage(BaseModel):
|
|
| 28 |
# This would ideally call an LLM (OpenAI/Mistral) to 'think' like a Payer
|
| 29 |
@app.post("/agent-chat")
|
| 30 |
async def agent_chat(payload: AgentMessage):
|
| 31 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
prompt = [
|
| 33 |
-
{"role": "system", "content":
|
| 34 |
-
"Policy MED-772: Requires Weight Loss OR Dysphagia OR 8-week PPI failure. "
|
| 35 |
-
"If evidence is found, reply 'APPROVED: [Reason]'. If not, ask for it."},
|
| 36 |
{"role": "user", "content": payload.message}
|
| 37 |
]
|
| 38 |
|
| 39 |
response = client.chat.completions.create(
|
| 40 |
-
model="gpt-
|
| 41 |
-
messages=prompt
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
-
return {"agent_response": response.choices[0].message.content}
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
#@app.post("/evaluate")
|
| 48 |
-
#async def evaluate(request: PARequest):
|
| 49 |
-
# # Payer Logic
|
| 50 |
-
# approved = request.dysphagia or request.weight_loss or request.ppi_weeks >= 8
|
| 51 |
-
|
| 52 |
-
# return {
|
| 53 |
-
# "status": "APPROVED" if approved else "DENIED",
|
| 54 |
-
# "auth_id": str(uuid.uuid4()) if approved else None,
|
| 55 |
-
# "reason": "Criteria met via alarm symptoms or PPI trial" if approved else "Insufficient clinical evidence",
|
| 56 |
-
# "payer_system": "Vim-Internal-Payer-Alpha"
|
| 57 |
-
# }
|
|
|
|
| 28 |
# This would ideally call an LLM (OpenAI/Mistral) to 'think' like a Payer
|
| 29 |
@app.post("/agent-chat")
|
| 30 |
async def agent_chat(payload: AgentMessage):
|
| 31 |
+
# DYNAMIC POLICY DATABASE (Mirroring your Provider side)
|
| 32 |
+
POLICIES = {
|
| 33 |
+
"22558": "Policy LCD-L341 (Spinal Fusion): Requires Physical Therapy (6+ weeks), Instability, or Spondylolisthesis.",
|
| 34 |
+
"43239": "Policy MED-772 (EGD): Requires Weight Loss, Dysphagia, or 8-week PPI failure."
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
# Step 1: Tell the Payer to identify the code first
|
| 38 |
+
system_instruction = (
|
| 39 |
+
"You are an Oracle Health Payer Adjudication Agent. "
|
| 40 |
+
"Your goal is to verify medical necessity based on the following policies: \n"
|
| 41 |
+
f"1. {POLICIES['22558']}\n"
|
| 42 |
+
f"2. {POLICIES['43239']}\n\n"
|
| 43 |
+
"INSTRUCTIONS:\n"
|
| 44 |
+
"- Identify which CPT code the Provider is requesting.\n"
|
| 45 |
+
"- ONLY apply the criteria for THAT specific code.\n"
|
| 46 |
+
"- If evidence for THAT code is found, reply 'APPROVED'.\n"
|
| 47 |
+
"- If evidence is missing, ask for the specific missing documentation for THAT policy."
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
prompt = [
|
| 51 |
+
{"role": "system", "content": system_instruction},
|
|
|
|
|
|
|
| 52 |
{"role": "user", "content": payload.message}
|
| 53 |
]
|
| 54 |
|
| 55 |
response = client.chat.completions.create(
|
| 56 |
+
model="gpt-4o", # Recommended for better logic than 3.5
|
| 57 |
+
messages=prompt,
|
| 58 |
+
temperature=0
|
| 59 |
)
|
| 60 |
|
| 61 |
+
return {"agent_response": response.choices[0].message.content}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|