Skip to content

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

Fix: "AttributeError(\"'list' object has no attribute 'get'\")" (#12518)

Stephen Huf522391d1ea5
diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py
index ceba4b40e2..03140b60b7 100644
--- a/api/apps/sdk/session.py
+++ b/api/apps/sdk/session.py
@@ -425,7 +425,7 @@ async def chat_completion_openai_like(tenant_id, chat_id):
],
}
if need_reference:
- response["choices"][0]["message"]["reference"] = chunks_format(answer.get("reference", []))
+ response["choices"][0]["message"]["reference"] = chunks_format(answer.get("reference", {}))
return jsonify(response)
diff --git a/rag/prompts/generator.py b/rag/prompts/generator.py
index 7c07146631..25fd4702e6 100644
--- a/rag/prompts/generator.py
+++ b/rag/prompts/generator.py
@@ -38,6 +38,8 @@ def get_value(d, k1, k2):
def chunks_format(reference):
+ if not reference or (reference is not dict):
+ return []
return [
{
"id": get_value(chunk, "chunk_id", "id"),