using AIStudio.Chat;
using AIStudio.Provider;
namespace AIStudio.Assistants.BeyondFactsLab;
///
/// 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.
///
///
/// 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.
///
public static class BflHiddenRequest
{
///
/// Sends a request in the hidden copy of a conversation and waits for the whole answer.
///
/// The hidden copy of the conversation, which keeps the request and the answer.
/// The provider which answers.
/// The request.
/// The images of the material, which go along with the first message.
/// The cancellation token.
/// The answer, empty when the provider failed.
public static async Task AskAsync(ChatThread hidden, AIStudio.Settings.Provider provider, string text, IReadOnlyList 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;
}
}