Bias of the day (#173)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2024-10-28 15:41:00 +01:00
1 parent e9c805f0df
commit 217b9c4db3
20 files changed
+491 -35

No files matched your search

+47 -10
View File
@@ -45,7 +45,11 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
private bool workspacesVisible;
private Workspaces? workspaces;
private bool mustScrollToBottomAfterRender;
private bool mustStoreChat;
private bool mustLoadChat;
private LoadChat loadChat;
private byte scrollRenderCountdown;
private bool autoSaveEnabled;
// Unfortunately, we need the input field reference to blur the focus away. Without
// this, we cannot clear the input field.
@@ -55,7 +59,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
protected override async Task OnInitializedAsync()
{
this.ApplyFilters([], [ Event.HAS_CHAT_UNSAVED_CHANGES, Event.RESET_CHAT_STATE ]);
this.ApplyFilters([], [ Event.HAS_CHAT_UNSAVED_CHANGES, Event.RESET_CHAT_STATE, Event.CHAT_STREAMING_DONE ]);
// Configure the spellchecking for the user input:
this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
@@ -68,14 +72,23 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.chatThread = deferredContent;
if (this.chatThread is not null)
{
var firstUserBlock = this.chatThread.Blocks.FirstOrDefault(x => x.Role == ChatRole.USER);
if (firstUserBlock is not null)
if (string.IsNullOrWhiteSpace(this.chatThread.Name))
{
this.chatThread.Name = firstUserBlock.Content switch
var firstUserBlock = this.chatThread.Blocks.FirstOrDefault(x => x.Role == ChatRole.USER);
if (firstUserBlock is not null)
{
ContentText textBlock => this.ExtractThreadName(textBlock.Text),
_ => "Thread"
};
this.chatThread.Name = firstUserBlock.Content switch
{
ContentText textBlock => this.ExtractThreadName(textBlock.Text),
_ => "Thread"
};
}
}
if(this.chatThread.WorkspaceId != Guid.Empty)
{
this.autoSaveEnabled = true;
this.mustStoreChat = true;
}
}
@@ -86,12 +99,33 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.StateHasChanged();
}
}
var deferredLoading = MessageBus.INSTANCE.CheckDeferredMessages<LoadChat>(Event.LOAD_CHAT).FirstOrDefault();
if (deferredLoading != default)
{
this.loadChat = deferredLoading;
this.mustLoadChat = true;
}
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && this.workspaces is not null && this.chatThread is not null && this.mustStoreChat)
{
this.mustStoreChat = false;
await this.workspaces.StoreChat(this.chatThread, false);
this.currentWorkspaceId = this.chatThread.WorkspaceId;
this.currentWorkspaceName = await this.workspaces.LoadWorkspaceName(this.chatThread.WorkspaceId);
}
if (firstRender && this.workspaces is not null && this.mustLoadChat)
{
this.mustLoadChat = false;
await this.workspaces.LoadChat(this.loadChat);
}
if(this.mustScrollToBottomAfterRender)
{
if (--this.scrollRenderCountdown == 0)
@@ -455,16 +489,19 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
#region Overrides of MSGComponentBase
public override Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
public override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
{
switch (triggeredEvent)
{
case Event.RESET_CHAT_STATE:
this.ResetState();
break;
case Event.CHAT_STREAMING_DONE:
if(this.autoSaveEnabled)
await this.SaveThread();
break;
}
return Task.CompletedTask;
}
public override Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) where TResult : default where TPayload : default