diff --git a/fjerkroa_bot/ai_responder.py b/fjerkroa_bot/ai_responder.py index 4407e4a..7e46eeb 100644 --- a/fjerkroa_bot/ai_responder.py +++ b/fjerkroa_bot/ai_responder.py @@ -128,7 +128,7 @@ class AIResponder(object): result = await openai.ChatCompletion.acreate(model=self.config["fix-model"], messages=messages, temperature=0.2) - return result['chaices'][0]['message']['content'] + return result['choices'][0]['message']['content'] except Exception as err: logging.warning(f"failed to execute a fix for the answer: {repr(err)}") return answer @@ -143,12 +143,16 @@ class AIResponder(object): answer, limit = await self._acreate(messages, limit) if answer is None: continue - answer['content'] = await self.fix(answer['content']) try: response = json.loads(answer['content']) except Exception as err: - logging.error(f"failed to parse the answer: {pformat(err)}\n{repr(answer['content'])}") - return AIResponse(None, False, f"ERROR: I could not parse this answer: {repr(answer['content'])}", None, False) + logging.warning(f"failed to parse the answer: {pformat(err)}\n{repr(answer['content'])}") + answer['content'] = await self.fix(answer['content']) + try: + response = json.loads(answer['content']) + except Exception as err: + logging.error(f"failed to parse the answer: {pformat(err)}\n{repr(answer['content'])}") + return AIResponse(None, False, f"ERROR: I could not parse this answer: {repr(answer['content'])}", None, False) if 'hack' not in response or type(response.get('picture', None)) not in (type(None), str): continue logging.info(f"got this answer:\n{pformat(response)}")