mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-14 20:48:27 +00:00
Added the Model Comparison assistant for blind comparisons of two models (#1009)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
12f26445ba
commit
b7255694cd
221 files changed
+19989
-90
No files matched your search
@@ -0,0 +1,46 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Chat.Embedded;
|
||||
|
||||
namespace AIStudio.Tests.Chat.Embedded;
|
||||
|
||||
/// <summary>
|
||||
/// Keeps embedded chats in memory, as they were when they were stored last.
|
||||
/// </summary>
|
||||
public sealed class InMemoryEmbeddedChatStore : IEmbeddedChatStore
|
||||
{
|
||||
private readonly Dictionary<Guid, ChatThread> threads = [];
|
||||
|
||||
/// <summary>
|
||||
/// Whether loading fails, as with a chat this version cannot open.
|
||||
/// </summary>
|
||||
public bool CannotOpen { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// How often a chat was stored.
|
||||
/// </summary>
|
||||
public int SaveCount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the blocks of a chat as they were stored last, or none.
|
||||
/// </summary>
|
||||
/// <param name="chatId">The ID of the chat.</param>
|
||||
public IReadOnlyList<ContentBlock> StoredBlocks(Guid chatId) => this.threads.TryGetValue(chatId, out var thread) ? thread.Blocks : [];
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ChatThread?> LoadThreadAsync(Guid chatId, CancellationToken token = default)
|
||||
{
|
||||
if (this.CannotOpen)
|
||||
throw new InvalidDataException("A newer version stored this chat.");
|
||||
|
||||
return Task.FromResult(this.threads.TryGetValue(chatId, out var thread) ? thread : null);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SaveThreadAsync(ChatThread thread, CancellationToken token = default)
|
||||
{
|
||||
// A copy of the list, so that what the chat adds later does not change what was stored:
|
||||
this.threads[thread.ChatId] = thread with { Blocks = [.. thread.Blocks] };
|
||||
this.SaveCount++;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user