Improve JSON parsing.
This commit is contained in:
+3
-2
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user