From 29697f6274343861382ebb2334f3f9c156fe8255 Mon Sep 17 00:00:00 2001 From: ipu Date: Fri, 8 Aug 2025 18:16:43 +0300 Subject: [PATCH] fix ai estimation --- src/services/estimation_service_v2.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/services/estimation_service_v2.py b/src/services/estimation_service_v2.py index c51eaa9..622999d 100644 --- a/src/services/estimation_service_v2.py +++ b/src/services/estimation_service_v2.py @@ -1,5 +1,6 @@ from datetime import date from enum import Enum +import json from typing import Optional from src.cache.drug_cache import fetch_drug_with_dosage from src.models import PHQ, Applicant, Plan, EstimationResponse, EstimationDetails, EstimationResult @@ -121,11 +122,11 @@ class EstimationService: "/chat/", json={"chat_session_id": session_id, "user_message": f"Check if this applicant eligible for insurance:\n {phq.model_dump_json()}"}, ) - response_json = response.json() + response_json = response.json()['message'] print(f"AI DTQ Response: {response_json}") - - dtq = not response_json["message"]["insurable"] - reason = response_json["message"]["reason"] + ai_response = json.loads(response_json) + dtq = not ai_response["insurable"] + reason = ai_response["reason"] return dtq, reason except Exception as e: print(f"Error in AI DTQ check: {e}")