diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-23 21:51:55 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-23 21:51:55 +0200 |
| commit | 3c4db5c511abbab9d444a98be777fcd4319e6465 (patch) | |
| tree | 63c7e3d19294a047d74819cee6399e433af2448e /cogs | |
| parent | chore: update the ai model for assistant.py (diff) | |
| download | senator-sperma-3c4db5c511abbab9d444a98be777fcd4319e6465.tar.gz senator-sperma-3c4db5c511abbab9d444a98be777fcd4319e6465.zip | |
fix: fallback to plaintext if no json is provided for assistant.py
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to '')
| -rw-r--r-- | cogs/assistant.py | 11 |
1 files changed, 7 insertions, 4 deletions
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): | |||
| 146 | def _parse_response(response_data): | 146 | def _parse_response(response_data): |
| 147 | content = response_data['choices'][0]['message']['content'] | 147 | content = response_data['choices'][0]['message']['content'] |
| 148 | inner_json_str = content.strip('```json\n').strip('```').strip() | 148 | inner_json_str = content.strip('```json\n').strip('```').strip() |
| 149 | inner_data = json.loads(inner_json_str) | 149 | try: |
| 150 | 150 | inner_data = json.loads(inner_json_str) | |
| 151 | response_message = inner_data['message'] | 151 | response_message = inner_data['message'] |
| 152 | action = inner_data['action'] | 152 | action = inner_data['action'] |
| 153 | except (json.JSONDecodeError, KeyError): | ||
| 154 | response_message = content | ||
| 155 | action = "none" | ||
| 153 | 156 | ||
| 154 | logger.info(response_message) | 157 | logger.info(response_message) |
| 155 | logger.info(action) | 158 | logger.info(action) |
