Fix: key error "content" #12844 (#12847)

### What problem does this PR solve?

Fix: key error "content" #12844

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
Magicbook1108
2026-01-28 14:39:34 +08:00
committed by GitHub
parent 15a534909f
commit 2c4499ec45
3 changed files with 11 additions and 7 deletions

View File

@ -62,8 +62,12 @@ class Session(Base):
except json.JSONDecodeError:
continue # Skip lines that are not valid JSON
event = json_data.get("event",None)
if event and event != "message":
continue
if (
(self.__session_type == "agent" and json_data.get("event") == "message_end")
(self.__session_type == "agent" and event == "message_end")
or (self.__session_type == "chat" and json_data.get("data") is True)
):
return
@ -82,7 +86,7 @@ class Session(Base):
def _structure_answer(self, json_data):
answer = ""
if self.__session_type == "agent":
answer = json_data["data"]["content"]
answer = json_data["data"]["content"]
elif self.__session_type == "chat":
answer = json_data["answer"]
reference = json_data.get("reference", {})