Fix: python api streaming structure (#11105)

### What problem does this PR solve?

Fix: python api streaming structure

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Billy Bao
2025-11-07 16:50:58 +08:00
committed by GitHub
parent dd1c8c5779
commit c7bd0a755c

View File

@ -74,15 +74,15 @@ class Session(Base):
json_data = res.json() json_data = res.json()
except ValueError: except ValueError:
raise Exception(f"Invalid response {res}") raise Exception(f"Invalid response {res}")
yield self._structure_answer(json_data) yield self._structure_answer(json_data["data"])
def _structure_answer(self, json_data): def _structure_answer(self, json_data):
if self.__session_type == "agent": if self.__session_type == "agent":
answer = json_data["data"]["data"]["content"] answer = json_data["data"]["content"]
elif self.__session_type == "chat": elif self.__session_type == "chat":
answer =json_data["data"]["answer"] answer = json_data["answer"]
reference = json_data["data"].get("reference", {}) reference = json_data.get("reference", {})
temp_dict = { temp_dict = {
"content": answer, "content": answer,
"role": "assistant" "role": "assistant"