Small fixes.

This commit is contained in:
Fjerkroa Auto 2023-03-24 18:01:57 +01:00
parent b3edc621f6
commit 8aab8e2ec8

View File

@ -128,7 +128,7 @@ class AIResponder(object):
result = await openai.ChatCompletion.acreate(model=self.config["fix-model"], result = await openai.ChatCompletion.acreate(model=self.config["fix-model"],
messages=messages, messages=messages,
temperature=0.2) temperature=0.2)
return result['chaices'][0]['message']['content'] return result['choices'][0]['message']['content']
except Exception as err: except Exception as err:
logging.warning(f"failed to execute a fix for the answer: {repr(err)}") logging.warning(f"failed to execute a fix for the answer: {repr(err)}")
return answer return answer
@ -143,12 +143,16 @@ class AIResponder(object):
answer, limit = await self._acreate(messages, limit) answer, limit = await self._acreate(messages, limit)
if answer is None: if answer is None:
continue continue
answer['content'] = await self.fix(answer['content'])
try: try:
response = json.loads(answer['content']) response = json.loads(answer['content'])
except Exception as err: except Exception as err:
logging.error(f"failed to parse the answer: {pformat(err)}\n{repr(answer['content'])}") logging.warning(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) 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): if 'hack' not in response or type(response.get('picture', None)) not in (type(None), str):
continue continue
logging.info(f"got this answer:\n{pformat(response)}") logging.info(f"got this answer:\n{pformat(response)}")