From a283e2b3d2528272f905bff0ba13487286057d5b Mon Sep 17 00:00:00 2001 From: Ayyub I Date: Tue, 14 Nov 2023 20:23:08 -0600 Subject: [PATCH] converted answer to json object before extracting responses and citations from cloud func --- packages/googlecloud/functions/getanswer/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/googlecloud/functions/getanswer/main.py b/packages/googlecloud/functions/getanswer/main.py index 5c8773fe..4cf7041a 100644 --- a/packages/googlecloud/functions/getanswer/main.py +++ b/packages/googlecloud/functions/getanswer/main.py @@ -80,6 +80,12 @@ def getanswer(request): answer = answer_query(query, response_type, voting_roll_df, db_general, db_in_depth) + try: + answer = json.loads(answer) + except json.JSONDecodeError as e: + logging.error(f"Failed to parse answer string to JSON: {e}") + return ("Failed to process answer", 500, headers) + responses_data = answer.get("responses") citations_data = answer.get("citations")