From 5ce906a9b321a3652e109746ec912e8e53dea6b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20Lesn=C3=A9?= Date: Mon, 15 Jan 2024 23:35:13 +0100 Subject: [PATCH] fix: Not crash if LLM fails to return "customer_response" var GPT-3.5 Turbo often forget to include it. --- main.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index ce63a604..85946284 100644 --- a/main.py +++ b/main.py @@ -680,14 +680,28 @@ async def gpt_chat(call: CallModel) -> ActionModel: elif name == IndentAction.UPDATED_CLAIM: intent = IndentAction.UPDATED_CLAIM parameters = json.loads(arguments) - content += parameters[customer_response_prop] + " " + + if not customer_response_prop in parameters: + _logger.warn( + f"Missing {customer_response_prop} prop in {arguments}, please fix this!" + ) + else: + content += parameters[customer_response_prop] + " " + setattr(call.claim, parameters["field"], parameters["value"]) model.content = f"Updated claim field \"{parameters['field']}\" with value \"{parameters['value']}\"." elif name == IndentAction.NEW_CLAIM: intent = IndentAction.NEW_CLAIM parameters = json.loads(arguments) - content += parameters[customer_response_prop] + " " + + if not customer_response_prop in parameters: + _logger.warn( + f"Missing {customer_response_prop} prop in {arguments}, please fix this!" + ) + else: + content += parameters[customer_response_prop] + " " + call.claim = ClaimModel() call.reminders = [] model.content = "Claim and reminders created reset." @@ -695,7 +709,13 @@ async def gpt_chat(call: CallModel) -> ActionModel: elif name == IndentAction.NEW_OR_UPDATED_REMINDER: intent = IndentAction.NEW_OR_UPDATED_REMINDER parameters = json.loads(arguments) - content += parameters[customer_response_prop] + " " + + if not customer_response_prop in parameters: + _logger.warn( + f"Missing {customer_response_prop} prop in {arguments}, please fix this!" + ) + else: + content += parameters[customer_response_prop] + " " updated = False for reminder in call.reminders: