From c63638283bdf29ee9429f8286c83ec58b310aa3d Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 8 Mar 2025 13:52:04 +0100 Subject: [PATCH] Refactored chat thread block checks --- .../RAG/RAGProcesses/AISrcSelWithRetCtxVal.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/app/MindWork AI Studio/Tools/RAG/RAGProcesses/AISrcSelWithRetCtxVal.cs b/app/MindWork AI Studio/Tools/RAG/RAGProcesses/AISrcSelWithRetCtxVal.cs index fe9cc694..ae7c078b 100644 --- a/app/MindWork AI Studio/Tools/RAG/RAGProcesses/AISrcSelWithRetCtxVal.cs +++ b/app/MindWork AI Studio/Tools/RAG/RAGProcesses/AISrcSelWithRetCtxVal.cs @@ -38,6 +38,30 @@ public sealed class AISrcSelWithRetCtxVal : IRagProcess // makes sense to proceed with the RAG process: var proceedWithRAG = true; + // + // We read the last block in the chat thread. We need to re-arrange + // the order of blocks later, after the augmentation process takes + // place: + // + if(chatThread.Blocks.Count == 0) + { + logger.LogError("The chat thread is empty. Skipping the RAG process."); + return chatThread; + } + + if (chatThread.Blocks.Last().Role != ChatRole.AI) + { + logger.LogError("The last block in the chat thread is not the AI block. There is something wrong with the chat thread. Skipping the RAG process."); + return chatThread; + } + + // + // At this point in time, the chat thread contains already the + // last block, which is the waiting AI block. We need to remove + // this block before we call some parts of the RAG process: + // + var chatThreadWithoutWaitingAIBlock = chatThread with { Blocks = chatThread.Blocks[..^1] }; + // // When the user wants to bind data sources to the chat, we // have to check if the data sources are available for the @@ -79,13 +103,6 @@ public sealed class AISrcSelWithRetCtxVal : IRagProcess var dataContexts = new List(); if (proceedWithRAG) { - // - // At this point in time, the chat thread contains already the - // last block, which is the waiting AI block. We need to remove - // this block before we call the RAG process: - // - var chatThreadWithoutWaitingAIBlock = chatThread with { Blocks = chatThread.Blocks[..^1] }; - // // We kick off the retrieval process for each data source in parallel: //