From 3c4db5c511abbab9d444a98be777fcd4319e6465 Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 23 Apr 2026 21:51:55 +0200 Subject: fix: fallback to plaintext if no json is provided for assistant.py Signed-off-by: salmonik --- cogs/assistant.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'cogs/assistant.py') diff --git a/cogs/assistant.py b/cogs/assistant.py index 6cc1b03..a89c356 100644 --- a/cogs/assistant.py +++ b/cogs/assistant.py @@ -146,10 +146,13 @@ class Jarvis(commands.Cog): def _parse_response(response_data): content = response_data['choices'][0]['message']['content'] inner_json_str = content.strip('```json\n').strip('```').strip() - inner_data = json.loads(inner_json_str) - - response_message = inner_data['message'] - action = inner_data['action'] + try: + inner_data = json.loads(inner_json_str) + response_message = inner_data['message'] + action = inner_data['action'] + except (json.JSONDecodeError, KeyError): + response_message = content + action = "none" logger.info(response_message) logger.info(action) -- cgit v1.2.3