Improve JSON parsing.

This commit is contained in:
OK
2023-03-29 19:22:54 +02:00
parent 7f3cb66043
commit ddc44bb9da
3 changed files with 20 additions and 6 deletions
+3 -2
View File
@@ -5,6 +5,7 @@ import json
import toml
import openai
import logging
import pytest
from unittest.mock import Mock, PropertyMock, MagicMock, AsyncMock, patch, mock_open, ANY
from fjerkroa_bot import FjerkroaBot
from discord import User, Message, TextChannel
@@ -113,8 +114,8 @@ class TestFunctionality(TestBotBase):
return {'choices': [{'message': {'content': '{ "test": 3 ]'}}]}
message = self.create_message("Hello there! How are you?")
with patch.object(openai.ChatCompletion, 'acreate', new=acreate):
await self.bot.on_message(message)
self.bot.staff_channel.send.assert_called_once_with("ERROR: I could not parse this answer: '{ \"test\": 3 ]'", suppress_embeds=True)
with pytest.raises(RuntimeError, match="Failed to generate answer after multiple retries"):
await self.bot.on_message(message)
async def test_on_message_event4(self) -> None:
async def acreate(*a, **kw):