fixbug: Message id, token counter

This commit is contained in:
莘权 马 2023-12-19 10:44:06 +08:00
parent 5593008110
commit e42b1969cc
4 changed files with 16 additions and 9 deletions

View file

@ -163,8 +163,14 @@ class Message(BaseModel):
def load(val):
"""Convert the json string to object."""
try:
d = json.loads(val)
return Message(**d)
m = json.loads(val)
id = m.get("id")
if "id" in m:
del m["id"]
msg = Message(**m)
if id:
msg.id = id
return msg
except JSONDecodeError as err:
logger.error(f"parse json failed: {val}, error:{err}")
return None