mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-10 16:47:22 +00:00
50 lines
2.1 KiB
C#
50 lines
2.1 KiB
C#
using AIStudio.Chat;
|
|
using AIStudio.Provider;
|
|
|
|
namespace AIStudio.Assistants.BeyondFactsLab;
|
|
|
|
/// <summary>
|
|
/// Sends a request which the person never sees, in a hidden copy of a conversation of the lab, e.g., for a work state
|
|
/// or a result.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The copy carries the system prompt and the messages of the conversation, so the model knows all the step knows.
|
|
/// The lab never stores it, and the conversation itself stays as it is.
|
|
/// </remarks>
|
|
public static class BflHiddenRequest
|
|
{
|
|
/// <summary>
|
|
/// Sends a request in the hidden copy of a conversation and waits for the whole answer.
|
|
/// </summary>
|
|
/// <param name="hidden">The hidden copy of the conversation, which keeps the request and the answer.</param>
|
|
/// <param name="provider">The provider which answers.</param>
|
|
/// <param name="text">The request.</param>
|
|
/// <param name="images">The images of the material, which go along with the first message.</param>
|
|
/// <param name="token">The cancellation token.</param>
|
|
/// <returns>The answer, empty when the provider failed.</returns>
|
|
public static async Task<string> AskAsync(ChatThread hidden, AIStudio.Settings.Provider provider, string text, IReadOnlyList<FileAttachmentImage> images, CancellationToken token)
|
|
{
|
|
var request = new ContentText { Text = text };
|
|
hidden.Blocks.Add(new ContentBlock
|
|
{
|
|
Time = DateTimeOffset.Now,
|
|
ContentType = ContentType.TEXT,
|
|
Role = ChatRole.USER,
|
|
Content = request,
|
|
HideFromUser = true
|
|
});
|
|
|
|
var answer = new ContentText { InitialRemoteWait = true };
|
|
hidden.Blocks.Add(new ContentBlock
|
|
{
|
|
Time = DateTimeOffset.Now,
|
|
ContentType = ContentType.TEXT,
|
|
Role = ChatRole.AI,
|
|
Content = answer,
|
|
HideFromUser = true
|
|
});
|
|
|
|
await answer.CreateFromProviderAsync(provider.CreateProvider(), provider.Model, request, BflConversationService.WithImages(hidden, images), token);
|
|
return answer.Text;
|
|
}
|
|
} |