mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-15 19:41:36 +00:00
Refactored the system prompt to use a dynamic date and time processing
This commit is contained in:
parent
0b006cd330
commit
a72ec276b8
@ -99,7 +99,7 @@ public partial class AssistantAgenda : AssistantBaseCore<SettingsDialogAgenda>
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -120,7 +120,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public partial class AssistantEMail : AssistantBaseCore<SettingsDialogWritingEMa
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public partial class AssistantGrammarSpelling : AssistantBaseCore<SettingsDialog
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public partial class AssistantJobPostings : AssistantBaseCore<SettingsDialogJobP
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -30,7 +30,7 @@ public partial class AssistantLegalCheck : AssistantBaseCore<SettingsDialogLegal
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public partial class AssistantMyTasks : AssistantBaseCore<SettingsDialogMyTasks>
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -44,7 +44,7 @@ public partial class AssistantRewriteImprove : AssistantBaseCore<SettingsDialogR
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -55,7 +55,7 @@ public partial class AssistantSynonyms : AssistantBaseCore<SettingsDialogSynonym
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public partial class AssistantTextSummarizer : AssistantBaseCore<SettingsDialogT
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public partial class AssistantTranslation : AssistantBaseCore<SettingsDialogTran
|
|||||||
|
|
||||||
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
{
|
{
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
using AIStudio.Components;
|
using AIStudio.Components;
|
||||||
using AIStudio.Settings;
|
using AIStudio.Settings;
|
||||||
using AIStudio.Settings.DataModel;
|
using AIStudio.Settings.DataModel;
|
||||||
@ -91,7 +93,7 @@ public sealed record ChatThread
|
|||||||
// Use the information from the chat template, if provided. Otherwise, use the default system prompt
|
// Use the information from the chat template, if provided. Otherwise, use the default system prompt
|
||||||
//
|
//
|
||||||
string systemPromptTextWithChatTemplate;
|
string systemPromptTextWithChatTemplate;
|
||||||
var logMessage = $"Using no chat template for chat thread '{chatThread.Name}'.";
|
var firstLogMessage = $"Using no chat template for chat thread '{chatThread.Name}'.";
|
||||||
if (string.IsNullOrWhiteSpace(chatThread.SelectedChatTemplate))
|
if (string.IsNullOrWhiteSpace(chatThread.SelectedChatTemplate))
|
||||||
systemPromptTextWithChatTemplate = chatThread.SystemPrompt;
|
systemPromptTextWithChatTemplate = chatThread.SystemPrompt;
|
||||||
else
|
else
|
||||||
@ -109,7 +111,7 @@ public sealed record ChatThread
|
|||||||
systemPromptTextWithChatTemplate = chatThread.SystemPrompt;
|
systemPromptTextWithChatTemplate = chatThread.SystemPrompt;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logMessage = $"Using chat template '{chatTemplate.Name}' for chat thread '{chatThread.Name}'.";
|
firstLogMessage = $"Using chat template '{chatTemplate.Name}' for chat thread '{chatThread.Name}'.";
|
||||||
this.allowProfile = chatTemplate.AllowProfileUsage;
|
this.allowProfile = chatTemplate.AllowProfileUsage;
|
||||||
systemPromptTextWithChatTemplate = chatTemplate.ToSystemPrompt();
|
systemPromptTextWithChatTemplate = chatTemplate.ToSystemPrompt();
|
||||||
}
|
}
|
||||||
@ -122,7 +124,7 @@ public sealed record ChatThread
|
|||||||
// default system prompt:
|
// default system prompt:
|
||||||
chatThread = chatThread with { SystemPrompt = systemPromptTextWithChatTemplate };
|
chatThread = chatThread with { SystemPrompt = systemPromptTextWithChatTemplate };
|
||||||
|
|
||||||
LOGGER.LogInformation(logMessage);
|
LOGGER.LogInformation(firstLogMessage);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Add augmented data, if available:
|
// Add augmented data, if available:
|
||||||
@ -149,7 +151,7 @@ public sealed record ChatThread
|
|||||||
// Add information from the profile if available and allowed:
|
// Add information from the profile if available and allowed:
|
||||||
//
|
//
|
||||||
string systemPromptText;
|
string systemPromptText;
|
||||||
logMessage = $"Using no profile for chat thread '{chatThread.Name}'.";
|
var secondLogMessage = $"Using no profile for chat thread '{chatThread.Name}'.";
|
||||||
if (string.IsNullOrWhiteSpace(chatThread.SelectedProfile) || this.allowProfile is false)
|
if (string.IsNullOrWhiteSpace(chatThread.SelectedProfile) || this.allowProfile is false)
|
||||||
systemPromptText = systemPromptWithAugmentedData;
|
systemPromptText = systemPromptWithAugmentedData;
|
||||||
else
|
else
|
||||||
@ -163,11 +165,11 @@ public sealed record ChatThread
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var profile = settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == chatThread.SelectedProfile);
|
var profile = settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == chatThread.SelectedProfile);
|
||||||
if(profile == default)
|
if(profile is null)
|
||||||
systemPromptText = systemPromptWithAugmentedData;
|
systemPromptText = systemPromptWithAugmentedData;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logMessage = $"Using profile '{profile.Name}' for chat thread '{chatThread.Name}'.";
|
secondLogMessage = $"Using profile '{profile.Name}' for chat thread '{chatThread.Name}'.";
|
||||||
systemPromptText = $"""
|
systemPromptText = $"""
|
||||||
{systemPromptWithAugmentedData}
|
{systemPromptWithAugmentedData}
|
||||||
|
|
||||||
@ -178,8 +180,23 @@ public sealed record ChatThread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.LogInformation(logMessage);
|
LOGGER.LogInformation(secondLogMessage);
|
||||||
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:MMMM d, yyyy h:mm tt} (UTC) and {nowLocal:MMMM d, yyyy h:mm tt} (local time)."
|
||||||
|
);
|
||||||
|
|
||||||
|
return $"""
|
||||||
|
{currentDateTime}
|
||||||
|
|
||||||
|
{systemPromptText}
|
||||||
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,20 +1,6 @@
|
|||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace AIStudio.Chat;
|
namespace AIStudio.Chat;
|
||||||
|
|
||||||
public static class SystemPrompts
|
public static class SystemPrompts
|
||||||
{
|
{
|
||||||
public static string Default
|
public const string DEFAULT = "You are a helpful assistant.";
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var nowUtc = DateTime.UtcNow;
|
|
||||||
var nowLocal = DateTime.Now;
|
|
||||||
|
|
||||||
return string.Create(
|
|
||||||
new CultureInfo("en-US"),
|
|
||||||
$"Today is {nowUtc:MMMM d, yyyy h:mm tt} (UTC) and {nowLocal:MMMM d, yyyy h:mm tt} (local time)."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
SelectedProvider = this.Provider.Id,
|
SelectedProvider = this.Provider.Id,
|
||||||
SelectedProfile = this.currentProfile.Id,
|
SelectedProfile = this.currentProfile.Id,
|
||||||
SelectedChatTemplate = this.currentChatTemplate.Id,
|
SelectedChatTemplate = this.currentChatTemplate.Id,
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
WorkspaceId = this.currentWorkspaceId,
|
WorkspaceId = this.currentWorkspaceId,
|
||||||
ChatId = Guid.NewGuid(),
|
ChatId = Guid.NewGuid(),
|
||||||
DataSourceOptions = this.earlyDataSourceOptions,
|
DataSourceOptions = this.earlyDataSourceOptions,
|
||||||
@ -679,7 +679,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
SelectedProvider = this.Provider.Id,
|
SelectedProvider = this.Provider.Id,
|
||||||
SelectedProfile = this.currentProfile.Id,
|
SelectedProfile = this.currentProfile.Id,
|
||||||
SelectedChatTemplate = this.currentChatTemplate.Id,
|
SelectedChatTemplate = this.currentChatTemplate.Id,
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
WorkspaceId = this.currentWorkspaceId,
|
WorkspaceId = this.currentWorkspaceId,
|
||||||
ChatId = Guid.NewGuid(),
|
ChatId = Guid.NewGuid(),
|
||||||
Name = string.Empty,
|
Name = string.Empty,
|
||||||
|
|||||||
@ -573,7 +573,7 @@ public partial class Workspaces : MSGComponentBase
|
|||||||
WorkspaceId = workspaceId,
|
WorkspaceId = workspaceId,
|
||||||
ChatId = Guid.NewGuid(),
|
ChatId = Guid.NewGuid(),
|
||||||
Name = string.Empty,
|
Name = string.Empty,
|
||||||
SystemPrompt = SystemPrompts.Default,
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
Blocks = [],
|
Blocks = [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -263,7 +263,7 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
|||||||
|
|
||||||
private void UseDefaultSystemPrompt()
|
private void UseDefaultSystemPrompt()
|
||||||
{
|
{
|
||||||
this.DataSystemPrompt = SystemPrompts.Default;
|
this.DataSystemPrompt = SystemPrompts.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Cancel() => this.MudDialog.Cancel();
|
private void Cancel() => this.MudDialog.Cancel();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user