Implemented feature to start new chats from a workspace

This commit is contained in:
tsommer committed 2024-07-12 19:30:06 +02:00
1 parent ce8f50ee66
commit 733b2b1ac9
4 files changed
+80 -13

No files matched your search

@@ -3,7 +3,14 @@
@using AIStudio.Settings
<MudText Typo="Typo.h3" Class="mb-2 mr-3">
Chats
@if (this.chatThread is not null && this.chatThread.WorkspaceId != Guid.Empty)
{
@($"Chat in Workspace \"{this.currentWorkspaceName}\"")
}
else
{
@("Temporary Chat")
}
</MudText>
<MudSelect T="Provider" @bind-Value="@this.selectedProvider" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Apps" Margin="Margin.Dense" Label="Provider" Class="mb-2 rounded-lg" Variant="Variant.Outlined">
@@ -67,7 +74,7 @@
</MudStack>
</MudDrawerHeader>
<MudDrawerContainer Class="ml-6">
<Workspaces @ref="this.workspaces" @bind-CurrentChatThread="@this.chatThread"/>
<Workspaces @ref="this.workspaces" @bind-CurrentChatThread="@this.chatThread" LoadedChatWasChanged="this.LoadedChatChanged"/>
</MudDrawerContainer>
</MudDrawer>
}
@@ -36,6 +36,7 @@ public partial class Chat : ComponentBase, IAsyncDisposable
private bool hasUnsavedChanges;
private bool isStreaming;
private string userInput = string.Empty;
private string currentWorkspaceName = string.Empty;
private bool workspacesVisible;
private Workspaces? workspaces;
@@ -71,15 +72,25 @@ public partial class Chat : ComponentBase, IAsyncDisposable
// Create a new chat thread if necessary:
var threadName = this.ExtractThreadName(this.userInput);
this.chatThread ??= new()
if (this.chatThread is null)
{
WorkspaceId = Guid.Empty,
ChatId = Guid.NewGuid(),
Name = threadName,
Seed = this.RNG.Next(),
SystemPrompt = "You are a helpful assistant!",
Blocks = [],
};
this.chatThread = new()
{
WorkspaceId = Guid.Empty,
ChatId = Guid.NewGuid(),
Name = threadName,
Seed = this.RNG.Next(),
SystemPrompt = "You are a helpful assistant!",
Blocks = [],
};
}
else
{
// Set the thread name if it is empty:
if (string.IsNullOrWhiteSpace(this.chatThread.Name))
this.chatThread.Name = threadName;
}
//
// Add the user message to the thread:
@@ -226,6 +237,7 @@ public partial class Chat : ComponentBase, IAsyncDisposable
this.isStreaming = false;
this.hasUnsavedChanges = false;
this.userInput = string.Empty;
this.currentWorkspaceName = string.Empty;
await this.inputField.Clear();
}
@@ -267,6 +279,21 @@ public partial class Chat : ComponentBase, IAsyncDisposable
this.chatThread!.WorkspaceId = workspaceId;
await this.SaveThread();
this.currentWorkspaceName = await this.workspaces.LoadWorkspaceName(this.chatThread.WorkspaceId);
}
private async Task LoadedChatChanged()
{
if(this.workspaces is null)
return;
this.isStreaming = false;
this.hasUnsavedChanges = false;
this.userInput = string.Empty;
this.currentWorkspaceName = this.chatThread is null ? string.Empty : await this.workspaces.LoadWorkspaceName(this.chatThread.WorkspaceId);
await this.inputField.Clear();
}
#region Implementation of IAsyncDisposable