Refactored chat thread block checks

This commit is contained in:
Thorsten Sommer 2025-03-08 13:52:04 +01:00
parent 888330c616
commit c63638283b
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -38,6 +38,30 @@ public sealed class AISrcSelWithRetCtxVal : IRagProcess
// makes sense to proceed with the RAG process: // makes sense to proceed with the RAG process:
var proceedWithRAG = true; 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 // When the user wants to bind data sources to the chat, we
// have to check if the data sources are available for the // have to check if the data sources are available for the
@ -79,13 +103,6 @@ public sealed class AISrcSelWithRetCtxVal : IRagProcess
var dataContexts = new List<IRetrievalContext>(); var dataContexts = new List<IRetrievalContext>();
if (proceedWithRAG) 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: // We kick off the retrieval process for each data source in parallel:
// //