Improve handling of wrong keys in response
This commit is contained in:
parent
77fe7a69d6
commit
defe598651
@ -117,12 +117,12 @@ class AIResponder(object):
|
|||||||
raise RuntimeError(f"Failed to generate image {repr(description)} after multiple retries")
|
raise RuntimeError(f"Failed to generate image {repr(description)} after multiple retries")
|
||||||
|
|
||||||
async def post_process(self, message: AIMessage, response: Dict[str, Any]) -> AIResponse:
|
async def post_process(self, message: AIMessage, response: Dict[str, Any]) -> AIResponse:
|
||||||
for fld in ('answer', 'staff', 'picture'):
|
for fld in ('answer', 'staff', 'picture', 'hack'):
|
||||||
if str(response[fld]).strip().lower() in \
|
if str(response.get(fld)).strip().lower() in \
|
||||||
('none', '', 'null', '"none"', '"null"', "'none'", "'null'"):
|
('none', '', 'null', '"none"', '"null"', "'none'", "'null'"):
|
||||||
response[fld] = None
|
response[fld] = None
|
||||||
for fld in ('answer_needed', 'hack'):
|
for fld in ('answer_needed', 'hack'):
|
||||||
if str(response[fld]).strip().lower() == 'true':
|
if str(response.get(fld)).strip().lower() == 'true':
|
||||||
response[fld] = True
|
response[fld] = True
|
||||||
else:
|
else:
|
||||||
response[fld] = False
|
response[fld] = False
|
||||||
@ -243,7 +243,8 @@ class AIResponder(object):
|
|||||||
logging.error(f"failed to parse the fixed answer: {pp(err)}\n{repr(answer['content'])}")
|
logging.error(f"failed to parse the fixed answer: {pp(err)}\n{repr(answer['content'])}")
|
||||||
retries -= 1
|
retries -= 1
|
||||||
continue
|
continue
|
||||||
if 'hack' not in response or type(response.get('picture', None)) not in (type(None), str):
|
if type(response.get('picture')) not in (type(None), str):
|
||||||
|
logging.warning(f"picture key is wrong in response: {pp(response)}")
|
||||||
retries -= 1
|
retries -= 1
|
||||||
continue
|
continue
|
||||||
answer_message = await self.post_process(message, response)
|
answer_message = await self.post_process(message, response)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user