diff --git a/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs b/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs index 87d451fb..b260b8ed 100644 --- a/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs +++ b/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs @@ -190,6 +190,7 @@ public abstract partial class AssistantBase : AssistantLowerBase wher { this.chatThread = new() { + IncludeDateTime = false, SelectedProvider = this.providerSettings.Id, SelectedProfile = this.AllowProfiles ? this.currentProfile.Id : Profile.NO_PROFILE.Id, SystemPrompt = this.SystemPrompt, @@ -205,6 +206,7 @@ public abstract partial class AssistantBase : AssistantLowerBase wher var chatId = Guid.NewGuid(); this.chatThread = new() { + IncludeDateTime = false, SelectedProvider = this.providerSettings.Id, SelectedProfile = this.AllowProfiles ? this.currentProfile.Id : Profile.NO_PROFILE.Id, SystemPrompt = this.SystemPrompt, diff --git a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs index 612e91eb..9ee972ba 100644 --- a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs +++ b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs @@ -457,6 +457,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore public string SelectedChatTemplate { get; set; } = string.Empty; + /// + /// Indicates whether to include the current date and time in the system prompt. + /// False by default for backward compatibility. + /// + public bool IncludeDateTime { get; set; } = false; + /// /// The data source options for this chat thread. /// @@ -65,7 +73,7 @@ public sealed record ChatThread /// /// The current system prompt for the chat thread. /// - public string SystemPrompt { get; init; } = string.Empty; + public string SystemPrompt { get; set; } = string.Empty; /// /// The content blocks of the chat thread. @@ -83,33 +91,32 @@ public sealed record ChatThread /// is extended with the profile chosen. /// /// The settings manager instance to use. - /// The chat thread to prepare the system prompt for. /// The prepared system prompt. - public string PrepareSystemPrompt(SettingsManager settingsManager, ChatThread chatThread) + public string PrepareSystemPrompt(SettingsManager settingsManager) { // // Use the information from the chat template, if provided. Otherwise, use the default system prompt // string systemPromptTextWithChatTemplate; - var logMessage = $"Using no chat template for chat thread '{chatThread.Name}'."; - if (string.IsNullOrWhiteSpace(chatThread.SelectedChatTemplate)) - systemPromptTextWithChatTemplate = chatThread.SystemPrompt; + var logMessage = $"Using no chat template for chat thread '{this.Name}'."; + if (string.IsNullOrWhiteSpace(this.SelectedChatTemplate)) + systemPromptTextWithChatTemplate = this.SystemPrompt; else { - if(!Guid.TryParse(chatThread.SelectedChatTemplate, out var chatTemplateId)) - systemPromptTextWithChatTemplate = chatThread.SystemPrompt; + if(!Guid.TryParse(this.SelectedChatTemplate, out var chatTemplateId)) + systemPromptTextWithChatTemplate = this.SystemPrompt; else { - if(chatThread.SelectedChatTemplate == ChatTemplate.NO_CHAT_TEMPLATE.Id || chatTemplateId == Guid.Empty) - systemPromptTextWithChatTemplate = chatThread.SystemPrompt; + if(this.SelectedChatTemplate == ChatTemplate.NO_CHAT_TEMPLATE.Id || chatTemplateId == Guid.Empty) + systemPromptTextWithChatTemplate = this.SystemPrompt; else { - var chatTemplate = settingsManager.ConfigurationData.ChatTemplates.FirstOrDefault(x => x.Id == chatThread.SelectedChatTemplate); + var chatTemplate = settingsManager.ConfigurationData.ChatTemplates.FirstOrDefault(x => x.Id == this.SelectedChatTemplate); if(chatTemplate == null) - systemPromptTextWithChatTemplate = chatThread.SystemPrompt; + systemPromptTextWithChatTemplate = this.SystemPrompt; else { - logMessage = $"Using chat template '{chatTemplate.Name}' for chat thread '{chatThread.Name}'."; + logMessage = $"Using chat template '{chatTemplate.Name}' for chat thread '{this.Name}'."; this.allowProfile = chatTemplate.AllowProfileUsage; systemPromptTextWithChatTemplate = chatTemplate.ToSystemPrompt(); } @@ -120,20 +127,19 @@ public sealed record ChatThread // We need a way to save the changed system prompt in our chat thread. // Otherwise, the chat thread will always tell us that it is using the // default system prompt: - chatThread = chatThread with { SystemPrompt = systemPromptTextWithChatTemplate }; - + this.SystemPrompt = systemPromptTextWithChatTemplate; LOGGER.LogInformation(logMessage); - + // // Add augmented data, if available: // - var isAugmentedDataAvailable = !string.IsNullOrWhiteSpace(chatThread.AugmentedData); + var isAugmentedDataAvailable = !string.IsNullOrWhiteSpace(this.AugmentedData); var systemPromptWithAugmentedData = isAugmentedDataAvailable switch { true => $""" {systemPromptTextWithChatTemplate} - {chatThread.AugmentedData} + {this.AugmentedData} """, false => systemPromptTextWithChatTemplate, @@ -149,25 +155,25 @@ public sealed record ChatThread // Add information from the profile if available and allowed: // string systemPromptText; - logMessage = $"Using no profile for chat thread '{chatThread.Name}'."; - if (string.IsNullOrWhiteSpace(chatThread.SelectedProfile) || this.allowProfile is false) + logMessage = $"Using no profile for chat thread '{this.Name}'."; + if (string.IsNullOrWhiteSpace(this.SelectedProfile) || !this.allowProfile) systemPromptText = systemPromptWithAugmentedData; else { - if(!Guid.TryParse(chatThread.SelectedProfile, out var profileId)) + if(!Guid.TryParse(this.SelectedProfile, out var profileId)) systemPromptText = systemPromptWithAugmentedData; else { - if(chatThread.SelectedProfile == Profile.NO_PROFILE.Id || profileId == Guid.Empty) + if(this.SelectedProfile == Profile.NO_PROFILE.Id || profileId == Guid.Empty) systemPromptText = systemPromptWithAugmentedData; else { - var profile = settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == chatThread.SelectedProfile); - if(profile == default) + var profile = settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == this.SelectedProfile); + if(profile is null) systemPromptText = systemPromptWithAugmentedData; else { - logMessage = $"Using profile '{profile.Name}' for chat thread '{chatThread.Name}'."; + logMessage = $"Using profile '{profile.Name}' for chat thread '{this.Name}'."; systemPromptText = $""" {systemPromptWithAugmentedData} @@ -179,7 +185,24 @@ public sealed record ChatThread } LOGGER.LogInformation(logMessage); - return systemPromptText; + if(!this.IncludeDateTime) + return systemPromptText; + + // + // Prepend the current date and time to the system prompt: + // + var nowUtc = DateTime.UtcNow; + var nowLocal = DateTime.Now; + var currentDateTime = string.Create( + new CultureInfo("en-US"), + $"Today is {nowUtc:dddd, MMMM d, yyyy h:mm tt} (UTC) and {nowLocal:dddd, MMMM d, yyyy h:mm tt} (local time)." + ); + + return $""" + {currentDateTime} + + {systemPromptText} + """; } /// diff --git a/app/MindWork AI Studio/Chat/SystemPrompts.cs b/app/MindWork AI Studio/Chat/SystemPrompts.cs index 0ed69b9f..6f60e603 100644 --- a/app/MindWork AI Studio/Chat/SystemPrompts.cs +++ b/app/MindWork AI Studio/Chat/SystemPrompts.cs @@ -2,5 +2,5 @@ namespace AIStudio.Chat; public static class SystemPrompts { - public const string DEFAULT = "You are a helpful assistant!"; + public const string DEFAULT = "You are a helpful assistant."; } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor.cs b/app/MindWork AI Studio/Components/ChatComponent.razor.cs index 5cf71ff1..ed37e54d 100644 --- a/app/MindWork AI Studio/Components/ChatComponent.razor.cs +++ b/app/MindWork AI Studio/Components/ChatComponent.razor.cs @@ -97,6 +97,8 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable // Use chat thread sent by the user: this.ChatThread = deferredContent; + this.ChatThread.IncludeDateTime = true; + this.Logger.LogInformation($"The chat '{this.ChatThread.ChatId}' with {this.ChatThread.Blocks.Count} messages was deferred and will be rendered now."); await this.ChatThreadChanged.InvokeAsync(this.ChatThread); @@ -435,6 +437,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable { this.ChatThread = new() { + IncludeDateTime = true, SelectedProvider = this.Provider.Id, SelectedProfile = this.currentProfile.Id, SelectedChatTemplate = this.currentChatTemplate.Id, @@ -675,6 +678,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable // this.ChatThread = new() { + IncludeDateTime = true, SelectedProvider = this.Provider.Id, SelectedProfile = this.currentProfile.Id, SelectedChatTemplate = this.currentChatTemplate.Id, diff --git a/app/MindWork AI Studio/Provider/AlibabaCloud/ProviderAlibabaCloud.cs b/app/MindWork AI Studio/Provider/AlibabaCloud/ProviderAlibabaCloud.cs index 2c763678..de46e95b 100644 --- a/app/MindWork AI Studio/Provider/AlibabaCloud/ProviderAlibabaCloud.cs +++ b/app/MindWork AI Studio/Provider/AlibabaCloud/ProviderAlibabaCloud.cs @@ -33,7 +33,7 @@ public sealed class ProviderAlibabaCloud() : BaseProvider(LLMProviders.ALIBABA_C var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs b/app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs index 539c4427..b536ee4d 100644 --- a/app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs +++ b/app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs @@ -72,7 +72,7 @@ public sealed class ProviderAnthropic() : BaseProvider(LLMProviders.ANTHROPIC, " // Build the messages: Messages = [..messages], - System = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + System = chatThread.PrepareSystemPrompt(settingsManager), MaxTokens = apiParameters.TryGetValue("max_tokens", out var value) && value is int intValue ? intValue : 4_096, // Right now, we only support streaming completions: diff --git a/app/MindWork AI Studio/Provider/DeepSeek/ProviderDeepSeek.cs b/app/MindWork AI Studio/Provider/DeepSeek/ProviderDeepSeek.cs index f5e1016d..ce33f288 100644 --- a/app/MindWork AI Studio/Provider/DeepSeek/ProviderDeepSeek.cs +++ b/app/MindWork AI Studio/Provider/DeepSeek/ProviderDeepSeek.cs @@ -33,7 +33,7 @@ public sealed class ProviderDeepSeek() : BaseProvider(LLMProviders.DEEP_SEEK, "h var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/Fireworks/ProviderFireworks.cs b/app/MindWork AI Studio/Provider/Fireworks/ProviderFireworks.cs index 25fc2611..1eb21894 100644 --- a/app/MindWork AI Studio/Provider/Fireworks/ProviderFireworks.cs +++ b/app/MindWork AI Studio/Provider/Fireworks/ProviderFireworks.cs @@ -33,7 +33,7 @@ public class ProviderFireworks() : BaseProvider(LLMProviders.FIREWORKS, "https:/ var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/GWDG/ProviderGWDG.cs b/app/MindWork AI Studio/Provider/GWDG/ProviderGWDG.cs index 28af268f..2b7e4dcb 100644 --- a/app/MindWork AI Studio/Provider/GWDG/ProviderGWDG.cs +++ b/app/MindWork AI Studio/Provider/GWDG/ProviderGWDG.cs @@ -33,7 +33,7 @@ public sealed class ProviderGWDG() : BaseProvider(LLMProviders.GWDG, "https://ch var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/Google/ProviderGoogle.cs b/app/MindWork AI Studio/Provider/Google/ProviderGoogle.cs index 55490992..48dea49e 100644 --- a/app/MindWork AI Studio/Provider/Google/ProviderGoogle.cs +++ b/app/MindWork AI Studio/Provider/Google/ProviderGoogle.cs @@ -33,7 +33,7 @@ public class ProviderGoogle() : BaseProvider(LLMProviders.GOOGLE, "https://gener var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/Groq/ProviderGroq.cs b/app/MindWork AI Studio/Provider/Groq/ProviderGroq.cs index e66cec3e..07cdb390 100644 --- a/app/MindWork AI Studio/Provider/Groq/ProviderGroq.cs +++ b/app/MindWork AI Studio/Provider/Groq/ProviderGroq.cs @@ -33,7 +33,7 @@ public class ProviderGroq() : BaseProvider(LLMProviders.GROQ, "https://api.groq. var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/Helmholtz/ProviderHelmholtz.cs b/app/MindWork AI Studio/Provider/Helmholtz/ProviderHelmholtz.cs index cf4359ea..ec5fca2c 100644 --- a/app/MindWork AI Studio/Provider/Helmholtz/ProviderHelmholtz.cs +++ b/app/MindWork AI Studio/Provider/Helmholtz/ProviderHelmholtz.cs @@ -33,7 +33,7 @@ public sealed class ProviderHelmholtz() : BaseProvider(LLMProviders.HELMHOLTZ, " var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/HuggingFace/ProviderHuggingFace.cs b/app/MindWork AI Studio/Provider/HuggingFace/ProviderHuggingFace.cs index 685dea10..a05ca11e 100644 --- a/app/MindWork AI Studio/Provider/HuggingFace/ProviderHuggingFace.cs +++ b/app/MindWork AI Studio/Provider/HuggingFace/ProviderHuggingFace.cs @@ -38,7 +38,7 @@ public sealed class ProviderHuggingFace : BaseProvider var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/Mistral/ProviderMistral.cs b/app/MindWork AI Studio/Provider/Mistral/ProviderMistral.cs index 0755f349..6685e6d6 100644 --- a/app/MindWork AI Studio/Provider/Mistral/ProviderMistral.cs +++ b/app/MindWork AI Studio/Provider/Mistral/ProviderMistral.cs @@ -31,7 +31,7 @@ public sealed class ProviderMistral() : BaseProvider(LLMProviders.MISTRAL, "http var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/OpenAI/ProviderOpenAI.cs b/app/MindWork AI Studio/Provider/OpenAI/ProviderOpenAI.cs index c4a213db..d2d0b32b 100644 --- a/app/MindWork AI Studio/Provider/OpenAI/ProviderOpenAI.cs +++ b/app/MindWork AI Studio/Provider/OpenAI/ProviderOpenAI.cs @@ -73,7 +73,7 @@ public sealed class ProviderOpenAI() : BaseProvider(LLMProviders.OPEN_AI, "https var systemPrompt = new TextMessage { Role = systemPromptRole, - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // diff --git a/app/MindWork AI Studio/Provider/OpenRouter/ProviderOpenRouter.cs b/app/MindWork AI Studio/Provider/OpenRouter/ProviderOpenRouter.cs index e627ee4c..ca8ef155 100644 --- a/app/MindWork AI Studio/Provider/OpenRouter/ProviderOpenRouter.cs +++ b/app/MindWork AI Studio/Provider/OpenRouter/ProviderOpenRouter.cs @@ -36,7 +36,7 @@ public sealed class ProviderOpenRouter() : BaseProvider(LLMProviders.OPEN_ROUTER var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/Perplexity/ProviderPerplexity.cs b/app/MindWork AI Studio/Provider/Perplexity/ProviderPerplexity.cs index 6ecfc69f..691dcdd5 100644 --- a/app/MindWork AI Studio/Provider/Perplexity/ProviderPerplexity.cs +++ b/app/MindWork AI Studio/Provider/Perplexity/ProviderPerplexity.cs @@ -42,7 +42,7 @@ public sealed class ProviderPerplexity() : BaseProvider(LLMProviders.PERPLEXITY, var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/SelfHosted/ProviderSelfHosted.cs b/app/MindWork AI Studio/Provider/SelfHosted/ProviderSelfHosted.cs index 7cfb236b..a1e411e1 100644 --- a/app/MindWork AI Studio/Provider/SelfHosted/ProviderSelfHosted.cs +++ b/app/MindWork AI Studio/Provider/SelfHosted/ProviderSelfHosted.cs @@ -32,7 +32,7 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/Provider/X/ProviderX.cs b/app/MindWork AI Studio/Provider/X/ProviderX.cs index 82d92c2a..a0510dd6 100644 --- a/app/MindWork AI Studio/Provider/X/ProviderX.cs +++ b/app/MindWork AI Studio/Provider/X/ProviderX.cs @@ -33,7 +33,7 @@ public sealed class ProviderX() : BaseProvider(LLMProviders.X, "https://api.x.ai var systemPrompt = new TextMessage { Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), + Content = chatThread.PrepareSystemPrompt(settingsManager), }; // Parse the API parameters: diff --git a/app/MindWork AI Studio/wwwroot/changelog/v26.1.2.md b/app/MindWork AI Studio/wwwroot/changelog/v26.1.2.md index 2e7c9b53..b3d253b6 100644 --- a/app/MindWork AI Studio/wwwroot/changelog/v26.1.2.md +++ b/app/MindWork AI Studio/wwwroot/changelog/v26.1.2.md @@ -1,5 +1,6 @@ # v26.1.2, build 232 (2026-01-xx xx:xx UTC) - Added the option to hide specific assistants by configuration plugins. This is useful for enterprise environments in organizations. +- Added the current date and time to the system prompt for better context in conversations. Thanks Peer `peerschuett` for the contribution. - Improved error handling for model loading in provider dialogs (LLMs, embeddings, transcriptions). - Improved the microphone handling (transcription preview) so that all sound effects and the voice recording are processed without interruption. - Improved the handling of self-hosted providers in the configuration dialogs (LLMs, embeddings, and transcriptions) when the host cannot provide a list of models.