Skip to content

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

fix Conversation roles must alternate user/assistant/user/assistant/... bug (#6880)

dylan9d9f2dacd27d
diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py
index 16b1c8a141..1498a1c561 100644
--- a/api/apps/sdk/session.py
+++ b/api/apps/sdk/session.py
@@ -240,8 +240,13 @@ def chat_completion_openai_like(tenant_id, chat_id):
dia = dia[0]
# Filter system and non-sense assistant messages
- msg = None
- msg = [m for m in messages if m["role"] != "system" and (m["role"] != "assistant" or msg)]
+ msg = []
+ for m in messages:
+ if m["role"] == "system":
+ continue
+ if m["role"] == "assistant" and not msg:
+ continue
+ msg.append(m)
# tools = get_tools()
# toolcall_session = SimpleFunctionCallServer()