Compare commits

...
8 Commits
23 changed files with 268 additions and 114 deletions

No files matched your search

@@ -166,6 +166,7 @@ public abstract partial class AssistantBase : ComponentBase, IMessageBusReceiver
{
this.chatThread = new()
{
SelectedProvider = this.providerSettings.Id,
WorkspaceId = Guid.Empty,
ChatId = Guid.NewGuid(),
Name = string.Empty,
@@ -185,6 +186,7 @@ public abstract partial class AssistantBase : ComponentBase, IMessageBusReceiver
var chatId = Guid.NewGuid();
this.chatThread = new()
{
SelectedProvider = this.providerSettings.Id,
WorkspaceId = workspaceId,
ChatId = chatId,
Name = name,
@@ -235,8 +237,13 @@ public abstract partial class AssistantBase : ComponentBase, IMessageBusReceiver
Role = ChatRole.AI,
Content = aiText,
};
this.chatThread?.Blocks.Add(this.resultingContentBlock);
if (this.chatThread is not null)
{
this.chatThread.Blocks.Add(this.resultingContentBlock);
this.chatThread.SelectedProvider = this.providerSettings.Id;
}
this.isProcessing = true;
this.StateHasChanged();
@@ -284,7 +291,9 @@ public abstract partial class AssistantBase : ComponentBase, IMessageBusReceiver
switch (destination)
{
case Tools.Components.CHAT:
MessageBus.INSTANCE.DeferMessage(this, sendToData.Event, this.ConvertToChatThread);
var convertedChatThread = this.ConvertToChatThread;
convertedChatThread = convertedChatThread with { SelectedProvider = this.providerSettings.Id };
MessageBus.INSTANCE.DeferMessage(this, sendToData.Event, convertedChatThread);
break;
default:
@@ -128,7 +128,7 @@ public partial class BiasOfTheDayAssistant : AssistantBaseCore
ChatId = this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayChatId,
};
if (Workspaces.IsChatExisting(biasChat))
if (WorkspaceBehaviour.IsChatExisting(biasChat))
{
MessageBus.INSTANCE.DeferMessage(this, Event.LOAD_CHAT, biasChat);
this.NavigationManager.NavigateTo(Routes.CHAT);
@@ -15,6 +15,11 @@ public sealed record ChatThread
/// </summary>
public Guid WorkspaceId { get; set; }
/// <summary>
/// Specifies the provider selected for the chat thread.
/// </summary>
public string SelectedProvider { get; set; } = string.Empty;
/// <summary>
/// The name of the chat thread. Usually generated by an AI model or manually edited by the user.
/// </summary>
@@ -13,6 +13,8 @@ public partial class Changelog
public static readonly Log[] LOGS =
[
new (196, "v0.9.21, build 196 (2024-11-23 12:22 UTC)", "v0.9.21.md"),
new (195, "v0.9.20, build 195 (2024-11-16 20:44 UTC)", "v0.9.20.md"),
new (194, "v0.9.19, build 194 (2024-11-14 05:58 UTC)", "v0.9.19.md"),
new (193, "v0.9.18, build 193 (2024-11-09 21:10 UTC)", "v0.9.18.md"),
new (192, "v0.9.17, build 192 (2024-11-03 11:11 UTC)", "v0.9.17.md"),
@@ -1,6 +1,5 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using AIStudio.Chat;
using AIStudio.Dialogs;
@@ -41,18 +40,6 @@ public partial class Workspaces : ComponentBase
private const Placement WORKSPACE_ITEM_TOOLTIP_PLACEMENT = Placement.Bottom;
public static readonly Guid WORKSPACE_ID_BIAS = Guid.Parse("82050a4e-ee92-43d7-8ee5-ab512f847e02");
private static readonly JsonSerializerOptions JSON_OPTIONS = new()
{
WriteIndented = true,
AllowTrailingCommas = true,
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
Converters =
{
new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseUpper),
}
};
private readonly List<TreeItemData<ITreeItem>> treeItems = new();
@@ -160,16 +147,6 @@ public partial class Workspaces : ComponentBase
return result;
}
public async Task<string> LoadWorkspaceName(Guid workspaceId)
{
if(workspaceId == Guid.Empty)
return string.Empty;
var workspacePath = Path.Join(SettingsManager.DataDirectory, "workspaces", workspaceId.ToString());
var workspaceNamePath = Path.Join(workspacePath, "name");
return await File.ReadAllTextAsync(workspaceNamePath, Encoding.UTF8);
}
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadWorkspaces()
{
var workspaces = new List<TreeItemData<ITreeItem>>();
@@ -261,22 +238,7 @@ public partial class Workspaces : ComponentBase
public async Task StoreChat(ChatThread chat, bool reloadTreeItems = true)
{
string chatDirectory;
if (chat.WorkspaceId == Guid.Empty)
chatDirectory = Path.Join(SettingsManager.DataDirectory, "tempChats", chat.ChatId.ToString());
else
chatDirectory = Path.Join(SettingsManager.DataDirectory, "workspaces", chat.WorkspaceId.ToString(), chat.ChatId.ToString());
// Ensure the directory exists:
Directory.CreateDirectory(chatDirectory);
// Save the chat name:
var chatNamePath = Path.Join(chatDirectory, "name");
await File.WriteAllTextAsync(chatNamePath, chat.Name);
// Save the thread as thread.json:
var chatPath = Path.Join(chatDirectory, "thread.json");
await File.WriteAllTextAsync(chatPath, JsonSerializer.Serialize(chat, JSON_OPTIONS), Encoding.UTF8);
await WorkspaceBehaviour.StoreChat(chat);
// Reload the tree items:
if(reloadTreeItems)
@@ -284,24 +246,6 @@ public partial class Workspaces : ComponentBase
this.StateHasChanged();
}
public async Task LoadChat(LoadChat loadChat)
{
var chatPath = loadChat.WorkspaceId == Guid.Empty
? Path.Join(SettingsManager.DataDirectory, "tempChats", loadChat.ChatId.ToString())
: Path.Join(SettingsManager.DataDirectory, "workspaces", loadChat.WorkspaceId.ToString(), loadChat.ChatId.ToString());
await this.LoadChat(chatPath, switchToChat: true);
}
public static bool IsChatExisting(LoadChat loadChat)
{
var chatPath = loadChat.WorkspaceId == Guid.Empty
? Path.Join(SettingsManager.DataDirectory, "tempChats", loadChat.ChatId.ToString())
: Path.Join(SettingsManager.DataDirectory, "workspaces", loadChat.WorkspaceId.ToString(), loadChat.ChatId.ToString());
return Directory.Exists(chatPath);
}
private async Task<ChatThread?> LoadChat(string? chatPath, bool switchToChat)
{
@@ -328,7 +272,7 @@ public partial class Workspaces : ComponentBase
try
{
var chatData = await File.ReadAllTextAsync(Path.Join(chatPath, "thread.json"), Encoding.UTF8);
var chat = JsonSerializer.Deserialize<ChatThread>(chatData, JSON_OPTIONS);
var chat = JsonSerializer.Deserialize<ChatThread>(chatData, WorkspaceBehaviour.JSON_OPTIONS);
if (switchToChat)
{
this.CurrentChatThread = chat;
@@ -354,7 +298,7 @@ public partial class Workspaces : ComponentBase
if (askForConfirmation)
{
var workspaceName = await this.LoadWorkspaceName(chat.WorkspaceId);
var workspaceName = await WorkspaceBehaviour.LoadWorkspaceName(chat.WorkspaceId);
var dialogParameters = new DialogParameters
{
{
@@ -419,7 +363,7 @@ public partial class Workspaces : ComponentBase
return;
var workspaceId = Guid.Parse(Path.GetFileName(workspacePath));
var workspaceName = await this.LoadWorkspaceName(workspaceId);
var workspaceName = await WorkspaceBehaviour.LoadWorkspaceName(workspaceId);
var dialogParameters = new DialogParameters
{
{ "Message", $"Please enter a new or edit the name for your workspace '{workspaceName}':" },
@@ -482,7 +426,7 @@ public partial class Workspaces : ComponentBase
return;
var workspaceId = Guid.Parse(Path.GetFileName(workspacePath));
var workspaceName = await this.LoadWorkspaceName(workspaceId);
var workspaceName = await WorkspaceBehaviour.LoadWorkspaceName(workspaceId);
// Determine how many chats are in the workspace:
var chatCount = Directory.EnumerateDirectories(workspacePath).Count();
@@ -572,7 +516,7 @@ public partial class Workspaces : ComponentBase
ChatId = Guid.NewGuid(),
Name = string.Empty,
Seed = this.RNG.Next(),
SystemPrompt = "You are a helpful assistant!",
SystemPrompt = SystemPrompts.DEFAULT,
Blocks = [],
};
@@ -46,7 +46,7 @@
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.11" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="9.0.0" />
<PackageReference Include="MudBlazor" Version="7.15.0" />
<PackageReference Include="MudBlazor.Markdown" Version="7.14.0" />
<PackageReference Include="ReverseMarkdown" Version="4.6.0" />
+73 -16
View File
@@ -64,7 +64,6 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
// Configure the spellchecking for the user input:
this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
this.currentProfile = this.SettingsManager.GetPreselectedProfile(Tools.Components.CHAT);
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<ChatThread>(Event.SEND_TO_CHAT).FirstOrDefault();
if (deferredContent is not null)
@@ -84,8 +83,8 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
};
}
}
if(this.chatThread.WorkspaceId != Guid.Empty)
if (this.SettingsManager.ConfigurationData.Workspace.StorageBehavior is WorkspaceStorageBehavior.STORE_CHATS_AUTOMATICALLY)
{
this.autoSaveEnabled = true;
this.mustStoreChat = true;
@@ -106,24 +105,38 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.loadChat = deferredLoading;
this.mustLoadChat = true;
}
this.SelectProviderWhenLoadingChat();
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && this.workspaces is not null && this.chatThread is not null && this.mustStoreChat)
if (firstRender && this.chatThread is not null && this.mustStoreChat)
{
this.mustStoreChat = false;
await this.workspaces.StoreChat(this.chatThread, false);
if(this.workspaces is not null)
await this.workspaces.StoreChat(this.chatThread);
else
await WorkspaceBehaviour.StoreChat(this.chatThread);
this.currentWorkspaceId = this.chatThread.WorkspaceId;
this.currentWorkspaceName = await this.workspaces.LoadWorkspaceName(this.chatThread.WorkspaceId);
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
}
if (firstRender && this.workspaces is not null && this.mustLoadChat)
if (firstRender && this.mustLoadChat)
{
this.mustLoadChat = false;
await this.workspaces.LoadChat(this.loadChat);
this.chatThread = await WorkspaceBehaviour.LoadChat(this.loadChat);
if(this.chatThread is not null)
{
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
this.SelectProviderWhenLoadingChat();
}
this.StateHasChanged();
}
if(this.mustScrollToBottomAfterRender)
@@ -192,6 +205,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
{
this.chatThread = new()
{
SelectedProvider = this.providerSettings.Id,
WorkspaceId = this.currentWorkspaceId,
ChatId = Guid.NewGuid(),
Name = threadName,
@@ -323,16 +337,22 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
private async Task SaveThread()
{
if(this.workspaces is null)
return;
if(this.chatThread is null)
return;
if (!this.CanThreadBeSaved)
return;
//
// When the workspace component is visible, we store the chat
// through the workspace component. The advantage of this is that
// the workspace gets updated automatically when the chat is saved.
//
if (this.workspaces is not null)
await this.workspaces.StoreChat(this.chatThread);
else
await WorkspaceBehaviour.StoreChat(this.chatThread);
await this.workspaces.StoreChat(this.chatThread);
this.hasUnsavedChanges = false;
}
@@ -382,6 +402,19 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.isStreaming = false;
this.hasUnsavedChanges = false;
this.userInput = string.Empty;
switch (this.SettingsManager.ConfigurationData.Chat.AddChatProviderBehavior)
{
case AddChatProviderBehavior.ADDED_CHATS_USE_DEFAULT_PROVIDER:
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
break;
default:
case AddChatProviderBehavior.ADDED_CHATS_USE_LATEST_PROVIDER:
if(this.providerSettings == default)
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
break;
}
if (!useSameWorkspace)
{
@@ -393,6 +426,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
{
this.chatThread = new()
{
SelectedProvider = this.providerSettings.Id,
WorkspaceId = this.currentWorkspaceId,
ChatId = Guid.NewGuid(),
Name = string.Empty,
@@ -462,7 +496,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
await this.SaveThread();
this.currentWorkspaceId = this.chatThread.WorkspaceId;
this.currentWorkspaceName = await this.workspaces.LoadWorkspaceName(this.chatThread.WorkspaceId);
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
}
private async Task LoadedChatChanged()
@@ -474,8 +508,10 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.hasUnsavedChanges = false;
this.userInput = string.Empty;
this.currentWorkspaceId = this.chatThread?.WorkspaceId ?? Guid.Empty;
this.currentWorkspaceName = this.chatThread is null ? string.Empty : await this.workspaces.LoadWorkspaceName(this.chatThread.WorkspaceId);
this.currentWorkspaceName = this.chatThread is null ? string.Empty : await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
this.SelectProviderWhenLoadingChat();
this.userInput = string.Empty;
if (this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading)
{
@@ -495,6 +531,27 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.chatThread = null;
}
private void SelectProviderWhenLoadingChat()
{
var chatProvider = this.chatThread?.SelectedProvider;
switch (this.SettingsManager.ConfigurationData.Chat.LoadingProviderBehavior)
{
default:
case LoadingChatProviderBehavior.USE_CHAT_PROVIDER_IF_AVAILABLE:
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT, chatProvider);
break;
case LoadingChatProviderBehavior.ALWAYS_USE_DEFAULT_CHAT_PROVIDER:
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
break;
case LoadingChatProviderBehavior.ALWAYS_USE_LATEST_CHAT_PROVIDER:
if(this.providerSettings == default)
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
break;
}
}
#region Overrides of MSGComponentBase
public override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
@@ -193,6 +193,9 @@
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Chat" HeaderText="Chat Options">
<ConfigurationSelect OptionDescription="Shortcut to send input" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Chat.ShortcutSendBehavior)" Data="@ConfigurationSelectDataFactory.GetSendBehaviorData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Chat.ShortcutSendBehavior = selectedValue)" OptionHelp="Do you want to use any shortcut to send your input?"/>
<ConfigurationOption OptionDescription="Show the latest message after loading?" LabelOn="Latest message is shown, after loading a chat" LabelOff="First (oldest) message is shown, after loading a chat" State="@(() => this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading = updatedState)" OptionHelp="When enabled, the latest message is shown after loading a chat. When disabled, the first (oldest) message is shown."/>
<ConfigurationSelect OptionDescription="Provider selection when creating new chats" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Chat.AddChatProviderBehavior)" Data="@ConfigurationSelectDataFactory.GetAddChatProviderBehavior()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Chat.AddChatProviderBehavior = selectedValue)" OptionHelp="Control how the LLM provider for added chats is selected."/>
<ConfigurationSelect OptionDescription="Provider selection when loading a chat and sending assistant results to chat" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Chat.LoadingProviderBehavior)" Data="@ConfigurationSelectDataFactory.GetLoadingChatProviderBehavior()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Chat.LoadingProviderBehavior = selectedValue)" OptionHelp="Control how the LLM provider for loaded chats is selected and when assistant results are sent to chat."/>
<MudPaper Class="pa-3 mb-8 border-dashed border rounded-lg">
<ConfigurationOption OptionDescription="Preselect chat options?" LabelOn="Chat options are preselected" LabelOff="No chat options are preselected" State="@(() => this.SettingsManager.ConfigurationData.Chat.PreselectOptions)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.Chat.PreselectOptions = updatedState)" OptionHelp="When enabled, you can preselect chat options. This is might be useful when you prefer a specific provider."/>
<ConfigurationProviderSelection Data="@this.availableProviders" Disabled="@(() => !this.SettingsManager.ConfigurationData.Chat.PreselectOptions)" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Chat.PreselectedProvider)" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Chat.PreselectedProvider = selectedValue)"/>
@@ -25,6 +25,19 @@ public readonly record struct ConfigurationSelectData<T>(string Name, T Value);
/// </summary>
public static class ConfigurationSelectDataFactory
{
public static IEnumerable<ConfigurationSelectData<LoadingChatProviderBehavior>> GetLoadingChatProviderBehavior()
{
yield return new("When possible, use the LLM provider which was used for each chat in the first place", LoadingChatProviderBehavior.USE_CHAT_PROVIDER_IF_AVAILABLE);
yield return new("Use the latest LLM provider, which was used before; use the default chat provider initially", LoadingChatProviderBehavior.ALWAYS_USE_LATEST_CHAT_PROVIDER);
yield return new("Always use the default chat provider when loading chats", LoadingChatProviderBehavior.ALWAYS_USE_DEFAULT_CHAT_PROVIDER);
}
public static IEnumerable<ConfigurationSelectData<AddChatProviderBehavior>> GetAddChatProviderBehavior()
{
yield return new("Use the latest LLM provider, which was used before; use the default chat provider initially", AddChatProviderBehavior.ADDED_CHATS_USE_LATEST_PROVIDER);
yield return new("Always use the default chat provider for new chats", AddChatProviderBehavior.ADDED_CHATS_USE_DEFAULT_PROVIDER);
}
public static IEnumerable<ConfigurationSelectData<SendBehavior>> GetSendBehaviorData()
{
yield return new("No key is sending the input", SendBehavior.NO_KEY_IS_SENDING);
@@ -0,0 +1,7 @@
namespace AIStudio.Settings.DataModel;
public enum AddChatProviderBehavior
{
ADDED_CHATS_USE_DEFAULT_PROVIDER = 0,
ADDED_CHATS_USE_LATEST_PROVIDER,
}
@@ -5924,18 +5924,12 @@ public static class BiasCatalog
{
if(usedBias.Count >= ALL_BIAS.Count)
usedBias.Clear();
int randomBiasIndex;
lock (RANDOM)
{
randomBiasIndex = RANDOM.Next(0, ALL_BIAS.Count);
while(usedBias.Contains(randomBiasIndex))
randomBiasIndex = RANDOM.Next(0, ALL_BIAS.Count);
}
var randomBiasIndex = Random.Shared.Next(0, ALL_BIAS.Count);
while(usedBias.Contains(randomBiasIndex))
randomBiasIndex = Random.Shared.Next(0, ALL_BIAS.Count);
usedBias.Add(randomBiasIndex);
return ALL_BIAS.Values.ElementAt(randomBiasIndex);
}
private static readonly Random RANDOM = new();
}
@@ -7,6 +7,16 @@ public sealed class DataChat
/// </summary>
public SendBehavior ShortcutSendBehavior { get; set; } = SendBehavior.ENTER_IS_SENDING;
/// <summary>
/// Defines the provider behavior for loading a chat.
/// </summary>
public LoadingChatProviderBehavior LoadingProviderBehavior { get; set; } = LoadingChatProviderBehavior.USE_CHAT_PROVIDER_IF_AVAILABLE;
/// <summary>
/// Defines the provider behavior when adding a chat.
/// </summary>
public AddChatProviderBehavior AddChatProviderBehavior { get; set; } = AddChatProviderBehavior.ADDED_CHATS_USE_LATEST_PROVIDER;
/// <summary>
/// Preselect any chat options?
/// </summary>
@@ -0,0 +1,8 @@
namespace AIStudio.Settings.DataModel;
public enum LoadingChatProviderBehavior
{
USE_CHAT_PROVIDER_IF_AVAILABLE = 0,
ALWAYS_USE_DEFAULT_CHAT_PROVIDER,
ALWAYS_USE_LATEST_CHAT_PROVIDER,
}
@@ -131,7 +131,7 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
return minimumLevel;
}
public Provider GetPreselectedProvider(Tools.Components component)
public Provider GetPreselectedProvider(Tools.Components component, string? chatProviderId = null)
{
var minimumLevel = this.GetMinimumConfidenceLevel(component);
@@ -139,6 +139,14 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
if (this.ConfigurationData.Providers.Count == 1 && this.ConfigurationData.Providers[0].UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
return this.ConfigurationData.Providers[0];
// When there is a chat provider, and it has a confidence level that is high enough, we return it:
if (chatProviderId is not null && !string.IsNullOrWhiteSpace(chatProviderId))
{
var chatProvider = this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == chatProviderId);
if (chatProvider.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
return chatProvider;
}
// When there is a component-preselected provider, and it has a confidence level that is high enough, we return it:
var preselectedProvider = component.PreselectedProvider(this);
if(preselectedProvider != default && preselectedProvider.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
@@ -0,0 +1,84 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using AIStudio.Chat;
using AIStudio.Settings;
namespace AIStudio.Tools;
public static class WorkspaceBehaviour
{
public static readonly JsonSerializerOptions JSON_OPTIONS = new()
{
WriteIndented = true,
AllowTrailingCommas = true,
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
Converters =
{
new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseUpper),
}
};
public static bool IsChatExisting(LoadChat loadChat)
{
var chatPath = loadChat.WorkspaceId == Guid.Empty
? Path.Join(SettingsManager.DataDirectory, "tempChats", loadChat.ChatId.ToString())
: Path.Join(SettingsManager.DataDirectory, "workspaces", loadChat.WorkspaceId.ToString(), loadChat.ChatId.ToString());
return Directory.Exists(chatPath);
}
public static async Task StoreChat(ChatThread chat)
{
string chatDirectory;
if (chat.WorkspaceId == Guid.Empty)
chatDirectory = Path.Join(SettingsManager.DataDirectory, "tempChats", chat.ChatId.ToString());
else
chatDirectory = Path.Join(SettingsManager.DataDirectory, "workspaces", chat.WorkspaceId.ToString(), chat.ChatId.ToString());
// Ensure the directory exists:
Directory.CreateDirectory(chatDirectory);
// Save the chat name:
var chatNamePath = Path.Join(chatDirectory, "name");
await File.WriteAllTextAsync(chatNamePath, chat.Name);
// Save the thread as thread.json:
var chatPath = Path.Join(chatDirectory, "thread.json");
await File.WriteAllTextAsync(chatPath, JsonSerializer.Serialize(chat, JSON_OPTIONS), Encoding.UTF8);
}
public static async Task<ChatThread?> LoadChat(LoadChat loadChat)
{
var chatPath = loadChat.WorkspaceId == Guid.Empty
? Path.Join(SettingsManager.DataDirectory, "tempChats", loadChat.ChatId.ToString())
: Path.Join(SettingsManager.DataDirectory, "workspaces", loadChat.WorkspaceId.ToString(), loadChat.ChatId.ToString());
if(!Directory.Exists(chatPath))
return null;
try
{
var chatData = await File.ReadAllTextAsync(Path.Join(chatPath, "thread.json"), Encoding.UTF8);
var chat = JsonSerializer.Deserialize<ChatThread>(chatData, JSON_OPTIONS);
return chat;
}
catch (Exception)
{
return null;
}
}
public static async Task<string> LoadWorkspaceName(Guid workspaceId)
{
if(workspaceId == Guid.Empty)
return string.Empty;
var workspacePath = Path.Join(SettingsManager.DataDirectory, "workspaces", workspaceId.ToString());
var workspaceNamePath = Path.Join(workspacePath, "name");
return await File.ReadAllTextAsync(workspaceNamePath, Encoding.UTF8);
}
}
+5 -2
View File
@@ -63,8 +63,11 @@ def "main fix_web_assets" []: nothing -> nothing {
mkdir wwwroot/system
# Copy the web assets from the first RID to the source project:
let source_path: glob = $"bin/release/net8.0/($rid)/publish/wwwroot/_content/*"
cp --recursive --force --update $source_path wwwroot/system/
let source_paths = glob --depth 99 bin/release/net8.0/($rid)/publish/wwwroot/_content/*
for source_path in $source_paths {
cp --recursive --force --update $source_path wwwroot/system/
}
}
def "main publish" []: nothing -> nothing {
+9 -9
View File
@@ -10,11 +10,11 @@
},
"Microsoft.Extensions.FileProviders.Embedded": {
"type": "Direct",
"requested": "[8.0.11, )",
"resolved": "8.0.11",
"contentHash": "1tn+c7d628+dASqo0UezdeWdKrEpp2XA376MUkr4nFYDj295iPWeWOV8rOvgR0Gma1xfOEjNJur1QvS6AVnjng==",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "6Ev1goLIvggLF6uCs6oZvdr9JM+2b1Zj+4FLdBWNW5iw3tm2BymVIb0yMsjnQTBWL7YUmqVWH3u45hSqOfvuqg==",
"dependencies": {
"Microsoft.Extensions.FileProviders.Abstractions": "8.0.0"
"Microsoft.Extensions.FileProviders.Abstractions": "9.0.0"
}
},
"Microsoft.NET.ILLink.Tasks": {
@@ -123,10 +123,10 @@
},
"Microsoft.Extensions.FileProviders.Abstractions": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "ZbaMlhJlpisjuWbvXr4LdAst/1XxH3vZ6A0BsgTphZ2L4PGuxRLz7Jr/S7mkAAnOn78Vu0fKhEgNF5JO3zfjqQ==",
"resolved": "9.0.0",
"contentHash": "uK439QzYR0q2emLVtYzwyK3x+T5bTY4yWsd/k/ZUS9LR6Sflp8MIdhGXW8kQCd86dQD4tLqvcbLkku8qHY263Q==",
"dependencies": {
"Microsoft.Extensions.Primitives": "8.0.0"
"Microsoft.Extensions.Primitives": "9.0.0"
}
},
"Microsoft.Extensions.Localization": {
@@ -164,8 +164,8 @@
},
"Microsoft.Extensions.Primitives": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g=="
"resolved": "9.0.0",
"contentHash": "N3qEBzmLMYiASUlKxxFIISP4AiwuPTHF5uCh+2CWSwwzAJiIYx0kBJsS30cp1nvhSySFAVi30jecD307jV+8Kg=="
},
"Microsoft.JSInterop": {
"type": "Transitive",
@@ -0,0 +1,2 @@
# v0.9.20, build 195 (2024-11-16 20:44 UTC)
- Fixed bugs related to storing and loading chats when the workspaces were docked to the left and were collapsed.
@@ -0,0 +1,5 @@
# v0.9.21, build 196 (2024-11-23 12:22 UTC)
- Added: Chats remember which LLM provider was used. This is useful to continue exactly where you left off.
- Added options for how to decide which LLM provider should be chosen when creating new chats and when loading chats. When you want the previous behavior restored (always use the default chat provider), you can configure this behavior as well.
- Fixed the missed workspace title when loading the today's bias.
- Fixed auto-save when sending assistant results to a new chat.
+4 -4
View File
@@ -1,9 +1,9 @@
0.9.19
2024-11-14 05:58:02 UTC
194
0.9.21
2024-11-23 12:22:00 UTC
196
8.0.111 (commit f3835a7fb4)
8.0.11 (commit 9cb3b725e3)
1.82.0 (commit f6e511eec)
7.15.0
1.8.1
9c0dea99271, release
f57e971f80b, release
+1 -1
View File
@@ -2174,7 +2174,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mindwork-ai-studio"
version = "0.9.19"
version = "0.9.21"
dependencies = [
"aes",
"arboard",
+3 -3
View File
@@ -1,6 +1,6 @@
[package]
name = "mindwork-ai-studio"
version = "0.9.19"
version = "0.9.21"
edition = "2021"
description = "MindWork AI Studio"
authors = ["Thorsten Sommer"]
@@ -9,7 +9,7 @@ authors = ["Thorsten Sommer"]
tauri-build = { version = "1.5", features = [] }
[dependencies]
tauri = { version = "1.8.1", features = [ "http-all", "updater", "shell-sidecar", "shell-open"] }
tauri = { version = "1.8", features = [ "http-all", "updater", "shell-sidecar", "shell-open"] }
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
@@ -29,7 +29,7 @@ cbc = "0.1.2"
pbkdf2 = "0.12.2"
hmac = "0.12.1"
sha2 = "0.10.8"
rcgen = { version = "0.13.1", features = ["pem"] }
rcgen = { version = "0.13", features = ["pem"] }
[target.'cfg(target_os = "linux")'.dependencies]
# See issue https://github.com/tauri-apps/tauri/issues/4470
+1 -1
View File
@@ -6,7 +6,7 @@
},
"package": {
"productName": "MindWork AI Studio",
"version": "0.9.19"
"version": "0.9.21"
},
"tauri": {
"allowlist": {