mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 14:13:48 +00:00
Execute retrieval processes (#286)
This commit is contained in:
1 parent
7c59aa11fe
commit
77d427610b
9 files changed
+198
-3
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.ERIClient.DataModel;
|
||||
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
@@ -150,4 +151,46 @@ public sealed record ChatThread
|
||||
// Remove the block from the chat thread:
|
||||
this.Blocks.Remove(block);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms this chat thread to an ERI chat thread.
|
||||
/// </summary>
|
||||
/// <param name="token">The cancellation token.</param>
|
||||
/// <returns>The ERI chat thread.</returns>
|
||||
public async Task<Tools.ERIClient.DataModel.ChatThread> ToERIChatThread(CancellationToken token = default)
|
||||
{
|
||||
//
|
||||
// Transform the content blocks:
|
||||
//
|
||||
var contentBlocks = new List<Tools.ERIClient.DataModel.ContentBlock>(this.Blocks.Count);
|
||||
foreach (var block in this.Blocks)
|
||||
{
|
||||
var (contentData, contentType) = block.Content switch
|
||||
{
|
||||
ContentImage image => (await image.AsBase64(token), Tools.ERIClient.DataModel.ContentType.IMAGE),
|
||||
ContentText text => (text.Text, Tools.ERIClient.DataModel.ContentType.TEXT),
|
||||
|
||||
_ => (string.Empty, Tools.ERIClient.DataModel.ContentType.UNKNOWN),
|
||||
};
|
||||
|
||||
contentBlocks.Add(new Tools.ERIClient.DataModel.ContentBlock
|
||||
{
|
||||
Role = block.Role switch
|
||||
{
|
||||
ChatRole.AI => Role.AI,
|
||||
ChatRole.USER => Role.USER,
|
||||
ChatRole.AGENT => Role.AGENT,
|
||||
ChatRole.SYSTEM => Role.SYSTEM,
|
||||
ChatRole.NONE => Role.NONE,
|
||||
|
||||
_ => Role.UNKNOW,
|
||||
},
|
||||
|
||||
Content = contentData,
|
||||
Type = contentType,
|
||||
});
|
||||
}
|
||||
|
||||
return new Tools.ERIClient.DataModel.ChatThread { ContentBlocks = contentBlocks };
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using AIStudio.Agents;
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.RAG;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
namespace AIStudio.Chat;
|
||||
@@ -199,9 +200,30 @@ public sealed class ContentText : IContent
|
||||
//
|
||||
// Trigger the retrieval part of the (R)AG process:
|
||||
//
|
||||
var dataContexts = new List<IRetrievalContext>();
|
||||
if (proceedWithRAG)
|
||||
{
|
||||
|
||||
//
|
||||
// We kick off the retrieval process for each data source in parallel:
|
||||
//
|
||||
var retrievalTasks = new List<Task<IReadOnlyList<IRetrievalContext>>>(selectedDataSources.Count);
|
||||
foreach (var dataSource in selectedDataSources)
|
||||
retrievalTasks.Add(dataSource.RetrieveDataAsync(lastPrompt, chatThread, token));
|
||||
|
||||
//
|
||||
// Wait for all retrieval tasks to finish:
|
||||
//
|
||||
foreach (var retrievalTask in retrievalTasks)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataContexts.AddRange(await retrievalTask);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "An error occurred during the retrieval process.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -42,4 +42,15 @@ public interface IContent
|
||||
/// Uses the provider to create the content.
|
||||
/// </summary>
|
||||
public Task CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatChatThread, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the corresponding ERI content type.
|
||||
/// </summary>
|
||||
public Tools.ERIClient.DataModel.ContentType ToERIContentType => this switch
|
||||
{
|
||||
ContentText => Tools.ERIClient.DataModel.ContentType.TEXT,
|
||||
ContentImage => Tools.ERIClient.DataModel.ContentType.IMAGE,
|
||||
|
||||
_ => Tools.ERIClient.DataModel.ContentType.UNKNOWN,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user