Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: Chat session completion (#10851)

Billy Bao95fad5d5234f
diff --git a/sdk/python/ragflow_sdk/modules/session.py b/sdk/python/ragflow_sdk/modules/session.py
index 30d7aeea33..9a54eb5e46 100644
--- a/sdk/python/ragflow_sdk/modules/session.py
+++ b/sdk/python/ragflow_sdk/modules/session.py
@@ -15,7 +15,6 @@
#
import json
-
from .base import Base
@@ -51,7 +50,6 @@ class Session(Base):
if not line:
continue # Skip empty lines
line = line.strip()
-
if line.startswith("data:"):
content = line[len("data:"):].strip()
if content == "[DONE]":
@@ -64,21 +62,26 @@ class Session(Base):
except json.JSONDecodeError:
continue # Skip lines that are not valid JSON
- event = json_data.get("event")
- if event == "message":
- yield self._structure_answer(json_data)
- elif event == "message_end":
- return # End of message stream
+ if (
+ (self.__session_type == "agent" and json_data.get("event") == "message_end")
+ or (self.__session_type == "chat" and json_data.get("data") is True)
+ ):
+ return
+
+ yield self._structure_answer(json_data)
else:
try:
json_data = res.json()
except ValueError:
raise Exception(f"Invalid response {res}")
- yield self._structure_answer(json_data["data"])
+ yield self._structure_answer(json_data)
def _structure_answer(self, json_data):
- answer = json_data["data"]["content"]
+ if self.__session_type == "agent":
+ answer = json_data["data"]["data"]["content"]
+ elif self.__session_type == "chat":
+ answer =json_data["data"]["answer"]
reference = json_data["data"].get("reference", {})
temp_dict = {
"content": answer,