From 2c4499ec45be8f5ab057d93a2da14aa4af2f476d Mon Sep 17 00:00:00 2001 From: Magicbook1108 Date: Wed, 28 Jan 2026 14:39:34 +0800 Subject: [PATCH] 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 --- pyproject.toml | 2 +- sdk/python/ragflow_sdk/modules/session.py | 8 ++++++-- uv.lock | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0ec19e2bb..117a7408b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,7 @@ dependencies = [ "pyobvector==0.2.22", "pyodbc>=5.2.0,<6.0.0", "pypandoc>=1.16", - "pypdf==6.4.0", + "pypdf>=6.6.2", "pypdf2>=3.0.1,<4.0.0", "python-calamine>=0.4.0", "python-docx>=1.1.2,<2.0.0", diff --git a/sdk/python/ragflow_sdk/modules/session.py b/sdk/python/ragflow_sdk/modules/session.py index d2bbc76e8..2ea65d17a 100644 --- a/sdk/python/ragflow_sdk/modules/session.py +++ b/sdk/python/ragflow_sdk/modules/session.py @@ -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", {}) diff --git a/uv.lock b/uv.lock index 79e199324..109a4b1db 100644 --- a/uv.lock +++ b/uv.lock @@ -5675,11 +5675,11 @@ wheels = [ [[package]] name = "pypdf" -version = "6.4.0" +version = "6.6.2" source = { registry = "https://pypi.tuna.tsinghua.edu.cn/simple" } -sdist = { url = "https://pypi.tuna.tsinghua.edu.cn/packages/f3/01/f7510cc6124f494cfbec2e8d3c2e1a20d4f6c18622b0c03a3a70e968bacb/pypdf-6.4.0.tar.gz", hash = "sha256:4769d471f8ddc3341193ecc5d6560fa44cf8cd0abfabf21af4e195cc0c224072", size = 5276661, upload-time = "2025-11-23T14:04:43.185Z" } +sdist = { url = "https://pypi.tuna.tsinghua.edu.cn/packages/b8/bb/a44bab1ac3c54dbcf653d7b8bcdee93dddb2d3bf025a3912cacb8149a2f2/pypdf-6.6.2.tar.gz", hash = "sha256:0a3ea3b3303982333404e22d8f75d7b3144f9cf4b2970b96856391a516f9f016", size = 5281850, upload-time = "2026-01-26T11:57:55.964Z" } wheels = [ - { url = "https://pypi.tuna.tsinghua.edu.cn/packages/cd/f2/9c9429411c91ac1dd5cd66780f22b6df20c64c3646cdd1e6d67cf38579c4/pypdf-6.4.0-py3-none-any.whl", hash = "sha256:55ab9837ed97fd7fcc5c131d52fcc2223bc5c6b8a1488bbf7c0e27f1f0023a79", size = 329497, upload-time = "2025-11-23T14:04:41.448Z" }, + { url = "https://pypi.tuna.tsinghua.edu.cn/packages/7d/be/549aaf1dfa4ab4aed29b09703d2fb02c4366fc1f05e880948c296c5764b9/pypdf-6.6.2-py3-none-any.whl", hash = "sha256:44c0c9811cfb3b83b28f1c3d054531d5b8b81abaedee0d8cb403650d023832ba", size = 329132, upload-time = "2026-01-26T11:57:54.099Z" }, ] [[package]] @@ -6328,7 +6328,7 @@ requires-dist = [ { name = "pyobvector", specifier = "==0.2.22" }, { name = "pyodbc", specifier = ">=5.2.0,<6.0.0" }, { name = "pypandoc", specifier = ">=1.16" }, - { name = "pypdf", specifier = "==6.4.0" }, + { name = "pypdf", specifier = ">=6.6.2" }, { name = "pypdf2", specifier = ">=3.0.1,<4.0.0" }, { name = "python-calamine", specifier = ">=0.4.0" }, { name = "python-docx", specifier = ">=1.1.2,<2.0.0" },