Skip to content

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

Fix: chats_openai in none stream condition (#13495)

Magicbook11087143954b48bb
diff --git a/rag/prompts/generator.py b/rag/prompts/generator.py
index b9c2113d8f..3037e0c4a3 100644
--- a/rag/prompts/generator.py
+++ b/rag/prompts/generator.py
@@ -40,6 +40,9 @@ def get_value(d, k1, k2):
def chunks_format(reference):
if not reference or not isinstance(reference, dict):
return []
+ raw_chunks = reference.get("chunks", [])
+ if not isinstance(raw_chunks, list):
+ return []
return [
{
"id": get_value(chunk, "chunk_id", "id"),
@@ -55,7 +58,8 @@ def chunks_format(reference):
"term_similarity": chunk.get("term_similarity"),
"doc_type": get_value(chunk, "doc_type_kwd", "doc_type"),
}
- for chunk in reference.get("chunks", [])
+ for chunk in raw_chunks
+ if isinstance(chunk, dict)
]
diff --git a/test/testcases/test_http_api/test_session_management/test_session_sdk_routes_unit.py b/test/testcases/test_http_api/test_session_management/test_session_sdk_routes_unit.py
index 6852024db3..a83a3564d4 100644
--- a/test/testcases/test_http_api/test_session_management/test_session_sdk_routes_unit.py
+++ b/test/testcases/test_http_api/test_session_management/test_session_sdk_routes_unit.py
@@ -762,7 +762,7 @@ def test_openai_nonstream_branch_unit(monkeypatch):
res = _run(inspect.unwrap(module.chat_completion_openai_like)("tenant-1", "chat-1"))
assert res["choices"][0]["message"]["content"] == "world"
-
+
@pytest.mark.p2
def test_agents_openai_compatibility_unit(monkeypatch):