mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-23 05:33:48 +00:00
Added context compression (#1198)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
28b88580a9
commit
8a4a26503b
54 files changed
+4582
-56
No files matched your search
@@ -0,0 +1,119 @@
|
||||
@using AIStudio.Chat.Compression
|
||||
@inherits MSGComponentBase
|
||||
|
||||
<MudDialog DefaultFocus="DefaultFocus.FirstChild">
|
||||
<DialogContent>
|
||||
<MudStack Spacing="3">
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@if (this.Target is ChatCompressionTarget.SAME_CHAT)
|
||||
{
|
||||
@TA("The AI summarizes this conversation, the content of its documents included. The summary then takes the place of the earlier messages, while your last message and the last answer of the AI stay as they are. AI Studio does not keep the earlier messages. Since the conversation is much shorter afterward, every further message costs fewer tokens.")
|
||||
}
|
||||
else
|
||||
{
|
||||
@TA("The AI summarizes this chat, the content of its documents included, and the conversation continues in a new chat. It holds the summary, your last message with its files, and the last answer of the AI. Since the new chat is much shorter, every further message costs fewer tokens. This chat stays as it is, so the whole conversation remains available.")
|
||||
}
|
||||
</MudJustifiedText>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@this.SummaryScope
|
||||
</MudJustifiedText>
|
||||
|
||||
@if (this.Plan.PendingQuestion is not null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Dense="true">
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@TA("Your last message has no answer yet. It goes into the input field of the new chat, so you can send it there.")
|
||||
</MudJustifiedText>
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
@if (this.StoresChatFirst)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Dense="true">
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@T("This chat has changes which are not saved yet. AI Studio saves it first, so that the whole conversation remains available.")
|
||||
</MudJustifiedText>
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
@if (this.HasDocumentsToSummarize)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Dense="true">
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@T("The summary takes in the content of the documents attached in this chat. This takes longer than summarizing the messages alone.")
|
||||
</MudJustifiedText>
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
@if (this.HasImagesToSummarize)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Dense="true">
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@T("The AI does not look at the images in this chat again. The summary keeps what the conversation said about them.")
|
||||
</MudJustifiedText>
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
<MudForm @ref="this.form">
|
||||
@if (this.Target is ChatCompressionTarget.NEW_CHAT)
|
||||
{
|
||||
<MudTextField T="string"
|
||||
@bind-Value="@this.chatName"
|
||||
Label="@T("Name of the new chat")"
|
||||
Variant="Variant.Outlined"
|
||||
Immediate="@true"
|
||||
Disabled="@this.isSummarizing"
|
||||
OnKeyDown="@this.HandleChatNameKeyDown"
|
||||
UserAttributes="@USER_INPUT_ATTRIBUTES"
|
||||
Validation="@this.ValidateChatName"/>
|
||||
}
|
||||
|
||||
<MudTextField T="string"
|
||||
@bind-Text="@this.focus"
|
||||
Label="@T("What should the summary pay particular attention to? (optional)")"
|
||||
Placeholder="@T("For example: the decisions about the budget, with all figures.")"
|
||||
Variant="Variant.Outlined"
|
||||
Lines="3"
|
||||
Sizing="InputSizing.Auto"
|
||||
MaxLines="8"
|
||||
Immediate="@true"
|
||||
Disabled="@this.isSummarizing"
|
||||
UserAttributes="@USER_INPUT_ATTRIBUTES"
|
||||
Class="mt-3"/>
|
||||
</MudForm>
|
||||
|
||||
@if (this.isSummarizing)
|
||||
{
|
||||
<MudProgressLinear Indeterminate="true" Color="Color.Primary"/>
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@this.ProgressMessage
|
||||
</MudJustifiedText>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(this.issue))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Dense="true">
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@this.issue
|
||||
</MudJustifiedText>
|
||||
</MudAlert>
|
||||
}
|
||||
</MudStack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">
|
||||
@T("Cancel")
|
||||
</MudButton>
|
||||
<MudButton OnClick="@this.CompressAsync" Variant="Variant.Filled" Color="Color.Primary" StartIcon="@AppIcons.COMPRESS_CHAT" Disabled="@this.isSummarizing">
|
||||
@if (this.Target is ChatCompressionTarget.SAME_CHAT)
|
||||
{
|
||||
@T("Compress")
|
||||
}
|
||||
else
|
||||
{
|
||||
@T("Compress & switch")
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
@@ -0,0 +1,160 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Chat.Compression;
|
||||
using AIStudio.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
/// <summary>
|
||||
/// Asks the AI for a summary of a chat, for continuing the conversation in a new chat.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The dialog only writes the summary. Creating the new chat and switching to it is left to the
|
||||
/// chat, which knows what is on the screen, see ChatComponent.CompressCurrentChat. Canceling while
|
||||
/// the AI writes stops the request, and nothing changes.
|
||||
/// </remarks>
|
||||
public partial class ChatCompressionDialog : MSGComponentBase
|
||||
{
|
||||
[CascadingParameter]
|
||||
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private ChatCompressionService ChatCompressionService { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The chat to compress.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public ChatThread SourceChat { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Which messages the summary replaces, see ChatCompressionPlan.Of.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public ChatCompressionPlan Plan { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The provider which writes the summary: the one the chat would send its next message to.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public AIStudio.Settings.Provider ProviderSettings { get; set; } = AIStudio.Settings.Provider.NONE;
|
||||
|
||||
/// <summary>
|
||||
/// Where the conversation goes on: in a new chat, which the user names here, or in the same chat.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public ChatCompressionTarget Target { get; set; } = ChatCompressionTarget.NEW_CHAT;
|
||||
|
||||
/// <summary>
|
||||
/// The name suggested for the new chat; not asked for when the conversation goes on in the same chat.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string SuggestedName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the chat has unsaved changes, which it stores before the new chat opens.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool StoresChatFirst { get; set; }
|
||||
|
||||
private static readonly Dictionary<string, object?> USER_INPUT_ATTRIBUTES = new();
|
||||
|
||||
private readonly CancellationTokenSource cancellationTokenSource = new();
|
||||
|
||||
private MudForm form = null!;
|
||||
private string chatName = string.Empty;
|
||||
private string focus = string.Empty;
|
||||
private string issue = string.Empty;
|
||||
private bool isSummarizing;
|
||||
private ChatCompressionProgress progress;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Configure the spellchecking for the user input:
|
||||
this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
|
||||
this.chatName = this.SuggestedName;
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private bool HasDocumentsToSummarize => this.Plan.ToSummarize.Any(block => block.Content?.FileAttachments.MayContainDocuments() is true);
|
||||
|
||||
private bool HasImagesToSummarize => this.Plan.ToSummarize.Any(block => block.Content?.FileAttachments.ContainsImages() is true);
|
||||
|
||||
private string SummaryScope => this.Plan.ToSummarize.Count is 1
|
||||
? string.Format(T("'{0}' summarizes 1 message."), this.ProviderSettings.InstanceName)
|
||||
: string.Format(T("'{0}' summarizes {1} messages."), this.ProviderSettings.InstanceName, this.Plan.ToSummarize.Count);
|
||||
|
||||
private string ProgressMessage => this.progress.Step switch
|
||||
{
|
||||
ChatCompressionStep.SUMMARIZING when this.progress.Total > 1 => string.Format(T("The AI is summarizing part {0} of {1}..."), this.progress.Current, this.progress.Total),
|
||||
ChatCompressionStep.SUMMARIZING => T("The AI is summarizing the chat..."),
|
||||
ChatCompressionStep.CONDENSING => T("The summary grew too long. The AI is shortening it..."),
|
||||
|
||||
_ => T("AI Studio is reading the messages and their files..."),
|
||||
};
|
||||
|
||||
private string? ValidateChatName(string? value) => string.IsNullOrWhiteSpace(value) ? TA("Please enter a chat name.") : null;
|
||||
|
||||
private async Task HandleChatNameKeyDown(KeyboardEventArgs keyEvent)
|
||||
{
|
||||
if (keyEvent.IsPlainEnter)
|
||||
await this.CompressAsync();
|
||||
}
|
||||
|
||||
private async Task CompressAsync()
|
||||
{
|
||||
await this.form.ValidateAsync();
|
||||
if (!this.form.IsValid || this.isSummarizing)
|
||||
return;
|
||||
|
||||
this.isSummarizing = true;
|
||||
this.issue = string.Empty;
|
||||
this.progress = default;
|
||||
await this.InvokeAsync(this.StateHasChanged);
|
||||
|
||||
var progressReporter = new Progress<ChatCompressionProgress>(reported =>
|
||||
{
|
||||
this.progress = reported;
|
||||
this.InvokeAsync(this.StateHasChanged).Observe($"{nameof(ChatCompressionDialog)}: showing the progress of the summary");
|
||||
});
|
||||
|
||||
var result = await this.ChatCompressionService.SummarizeAsync(this.SourceChat, this.Plan, this.ProviderSettings, this.focus, progressReporter, this.cancellationTokenSource.Token);
|
||||
|
||||
// The user canceled, and the dialog is gone already:
|
||||
if (this.cancellationTokenSource.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
this.issue = result.Issue;
|
||||
this.isSummarizing = false;
|
||||
await this.InvokeAsync(this.StateHasChanged);
|
||||
return;
|
||||
}
|
||||
|
||||
this.MudDialog.Close(DialogResult.Ok(new ChatCompressionDialogResult(this.chatName.Trim(), result.Summary)));
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
{
|
||||
this.cancellationTokenSource.Cancel();
|
||||
this.MudDialog.Cancel();
|
||||
}
|
||||
|
||||
#region Overrides of MSGComponentBase
|
||||
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
this.cancellationTokenSource.Cancel();
|
||||
this.cancellationTokenSource.Dispose();
|
||||
base.DisposeResources();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
/// <summary>
|
||||
/// What the dialog for compressing a chat hands back to the chat.
|
||||
/// </summary>
|
||||
/// <param name="Name">The name of the new chat.</param>
|
||||
/// <param name="Summary">The summary the AI wrote, not filtered for prompt injections yet.</param>
|
||||
public sealed record ChatCompressionDialogResult(string Name, string Summary);
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
/// <summary>
|
||||
/// What should happen with a message which does not fit into the context window of the model.
|
||||
/// </summary>
|
||||
public enum ContextWindowFullDecision
|
||||
{
|
||||
/// <summary>
|
||||
/// Send nothing. The message stays where it is, so the user can change it.
|
||||
/// </summary>
|
||||
CANCEL,
|
||||
|
||||
/// <summary>
|
||||
/// Compress the chat first. The message goes along, and the user sends it afterward.
|
||||
/// </summary>
|
||||
COMPRESS,
|
||||
|
||||
/// <summary>
|
||||
/// Send the message as it is and leave it to the provider what happens.
|
||||
/// </summary>
|
||||
SEND_ANYWAY,
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
@inherits MSGComponentBase
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudStack Spacing="3">
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@if (this.Subject is ContextWindowFullSubject.ASSISTANT_REQUEST)
|
||||
{
|
||||
@if (this.IsWindowExceeded)
|
||||
{
|
||||
@(string.Format(T("Together with its files, this request takes about {0} tokens, but the selected model reads at most {1} tokens. The provider will probably refuse the request or leave out a part of it."), this.Tokens, this.WindowTokens))
|
||||
}
|
||||
else
|
||||
{
|
||||
@(string.Format(T("Together with its files, this request takes about {0} of the {1} tokens which the selected model reads at most. Little room is left for the answer, which may break off."), this.Tokens, this.WindowTokens))
|
||||
}
|
||||
}
|
||||
else if (this.IsWindowExceeded)
|
||||
{
|
||||
@(string.Format(TA("Together with your message, this chat takes about {0} tokens, but the selected model reads at most {1} tokens. The provider will probably refuse your message or leave out a part of the conversation."), this.Tokens, this.WindowTokens))
|
||||
}
|
||||
else
|
||||
{
|
||||
@(string.Format(TA("Together with your message, this chat takes about {0} of the {1} tokens which the selected model reads at most. Little room is left for the answer, which may break off, and your next message will probably no longer fit."), this.Tokens, this.WindowTokens))
|
||||
}
|
||||
</MudJustifiedText>
|
||||
|
||||
@if (!this.CanSendAnyway)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@T("This chat sends no message which no longer fits, since the model would lose the beginning of the conversation and the instructions of the assistant first.")
|
||||
</MudJustifiedText>
|
||||
}
|
||||
|
||||
@if (this.CompressionIssue is { } compressionIssue)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@compressionIssue
|
||||
</MudJustifiedText>
|
||||
}
|
||||
|
||||
@if (this.CanCompress && this.Subject is ContextWindowFullSubject.EMBEDDED_CHAT)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@TA("When you compress the conversation, the AI summarizes it, and the summary takes the place of the earlier messages. Your message stays in the input field, so you can send it afterward.")
|
||||
</MudJustifiedText>
|
||||
}
|
||||
else if (this.CanCompress)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@TA("When you compress the chat, the AI summarizes it, and the conversation continues in a new chat. Your message goes along into the input field of the new chat, so you can send it there.")
|
||||
</MudJustifiedText>
|
||||
}
|
||||
else if (this.Subject is ContextWindowFullSubject.ASSISTANT_REQUEST)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@TA("You can attach fewer or smaller files, shorten your input, or select a model which takes longer texts.")
|
||||
</MudJustifiedText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@TA("You can shorten your message, remove some of its files, or select a model which takes longer texts.")
|
||||
</MudJustifiedText>
|
||||
}
|
||||
</MudStack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">
|
||||
@T("Cancel")
|
||||
</MudButton>
|
||||
@if (this.CanSendAnyway)
|
||||
{
|
||||
<MudButton OnClick="@this.SendAnyway" Variant="Variant.Filled" Color="Color.Error">
|
||||
@T("Send anyway")
|
||||
</MudButton>
|
||||
}
|
||||
@if (this.CanCompress)
|
||||
{
|
||||
<MudButton OnClick="@this.Compress" Variant="Variant.Filled" Color="Color.Primary">
|
||||
@T("Compress chat")
|
||||
</MudButton>
|
||||
}
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
@@ -0,0 +1,129 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Chat.Compression;
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
/// <summary>
|
||||
/// Tells the user before sending that the chat or the request of an assistant fills the context
|
||||
/// window of the model, or no longer fits into it, and offers to compress a chat.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only a notice: it compresses nothing by itself, and the user may send the message anyway. The
|
||||
/// numbers are those of the token count under the input field, so the dialog never disagrees with
|
||||
/// what the user sees there. Open it through ShowAsync, which every place that asks before sending
|
||||
/// shares.
|
||||
/// </remarks>
|
||||
public partial class ContextWindowFullDialog : MSGComponentBase
|
||||
{
|
||||
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ContextWindowFullDialog).Namespace, nameof(ContextWindowFullDialog));
|
||||
|
||||
[CascadingParameter]
|
||||
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// How many tokens the chat takes together with the message, formatted for the reader.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Tokens { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// How many tokens the model reads at most, formatted for the reader.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string WindowTokens { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the chat takes more than the window, rather than nearly all of it.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool IsWindowExceeded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// What is about to be sent, which decides the wording.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public ContextWindowFullSubject Subject { get; set; } = ContextWindowFullSubject.CHAT;
|
||||
|
||||
/// <summary>
|
||||
/// Whether compressing is offered, or why it would not help, see ChatCompressionService.OfferBeforeSendingAsync.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public ChatCompressionOffer Offer { get; set; } = ChatCompressionOffer.NONE;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the user may send the message anyway; not when the chat refuses a message which no longer fits.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool CanSendAnyway { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Asks the user what to do with a message which fills the context window of the model.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The caller decides when to ask, see ConversationTokens.AsksBeforeSending, and whether
|
||||
/// compressing would help, see ChatCompressionService.OfferBeforeSendingAsync. The numbers are
|
||||
/// formatted with the culture of the active language.
|
||||
/// </remarks>
|
||||
/// <param name="dialogService">The dialog service of the caller.</param>
|
||||
/// <param name="tokens">What the conversation costs together with the message, with the context window of the model.</param>
|
||||
/// <param name="subject">What is about to be sent.</param>
|
||||
/// <param name="offer">Whether compressing is offered, or why it would not help; NONE where nothing compresses.</param>
|
||||
/// <param name="canSendAnyway">Whether the user may send the message anyway, e.g., not where the chat refuses a message which no longer fits.</param>
|
||||
/// <returns>What the user decided; CANCEL when the dialog was closed.</returns>
|
||||
public static async Task<ContextWindowFullDecision> ShowAsync(IDialogService dialogService, ConversationTokens tokens, ContextWindowFullSubject subject, ChatCompressionOffer offer, bool canSendAnyway = true)
|
||||
{
|
||||
var isWindowExceeded = tokens.FillShare >= 1d;
|
||||
var culture = I18N.I.Culture;
|
||||
var dialogParameters = new DialogParameters<ContextWindowFullDialog>
|
||||
{
|
||||
{ x => x.Tokens, TokenAmount.Format(tokens.Tokens, culture) },
|
||||
{ x => x.WindowTokens, TokenAmount.Format(tokens.Window.DefaultTokens, culture) },
|
||||
{ x => x.IsWindowExceeded, isWindowExceeded },
|
||||
{ x => x.Subject, subject },
|
||||
{ x => x.Offer, offer },
|
||||
{ x => x.CanSendAnyway, canSendAnyway },
|
||||
};
|
||||
|
||||
var title = subject is ContextWindowFullSubject.ASSISTANT_REQUEST
|
||||
? isWindowExceeded ? TB("This request is too long for the model") : TB("This request nearly fills the context window of the model")
|
||||
: isWindowExceeded ? TB("This chat is too long for the model") : TB("This chat nearly fills the context window of the model");
|
||||
var dialogReference = await dialogService.ShowAsync<ContextWindowFullDialog>(title, dialogParameters, DialogOptions.FULLSCREEN);
|
||||
var dialogResult = await dialogReference.Result;
|
||||
if (dialogResult is null || dialogResult.Canceled || dialogResult.Data is not ContextWindowFullDecision decision)
|
||||
return ContextWindowFullDecision.CANCEL;
|
||||
|
||||
return decision;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the dialog offers to compress, see Offer.
|
||||
/// </summary>
|
||||
private bool CanCompress => this.Offer is ChatCompressionOffer.OFFERED;
|
||||
|
||||
/// <summary>
|
||||
/// Why the dialog does not offer to compress, where the place compresses but it would not help; null otherwise.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The user guide recommends compressing a long chat, so a notice which leaves it out says why. In the chat of an
|
||||
/// assistant, the instructions of the assistant stay as well, and they are often the larger part.
|
||||
/// </remarks>
|
||||
private string? CompressionIssue => this.Offer switch
|
||||
{
|
||||
ChatCompressionOffer.WINDOW_TOO_SMALL => string.Format(T("Compressing is not possible with the selected model, since it needs a context window of at least {0} tokens."), ChatCompressionService.MIN_CONTEXT_WINDOW.ToString("N0", I18N.I.Culture)),
|
||||
ChatCompressionOffer.MESSAGE_TOO_LONG => TA("Compressing would not help, since your message alone nearly fills the context window of the model."),
|
||||
ChatCompressionOffer.NOTHING_TO_SUMMARIZE => TA("Compressing would not help yet, since there is nothing to summarize before your last message and the last answer of the AI."),
|
||||
ChatCompressionOffer.KEEPS_TOO_MUCH when this.Subject is ContextWindowFullSubject.EMBEDDED_CHAT => TA("Compressing would not help, since the instructions of the assistant, your last message, and the last answer of the AI stay as they are, and together with your new message, they still nearly fill the context window of the model."),
|
||||
ChatCompressionOffer.KEEPS_TOO_MUCH => TA("Compressing would not help, since the new chat keeps the system prompt, your last message with its files, and the last answer of the AI word for word, and together with your new message, they still nearly fill the context window of the model."),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
private void Cancel() => this.MudDialog.Cancel();
|
||||
|
||||
private void SendAnyway() => this.MudDialog.Close(DialogResult.Ok(ContextWindowFullDecision.SEND_ANYWAY));
|
||||
|
||||
private void Compress() => this.MudDialog.Close(DialogResult.Ok(ContextWindowFullDecision.COMPRESS));
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
/// <summary>
|
||||
/// What is about to be sent when the context window of the model is nearly full, see ContextWindowFullDialog.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Decides how the notice words what fills the window and what compressing would do.
|
||||
/// </remarks>
|
||||
public enum ContextWindowFullSubject
|
||||
{
|
||||
/// <summary>
|
||||
/// A message of the chat page, which compressing continues in a new chat.
|
||||
/// </summary>
|
||||
CHAT,
|
||||
|
||||
/// <summary>
|
||||
/// A message of the embedded chat of an assistant, whose earlier messages compressing replaces with the summary.
|
||||
/// </summary>
|
||||
EMBEDDED_CHAT,
|
||||
|
||||
/// <summary>
|
||||
/// A request of an assistant, together with its files, which nothing compresses.
|
||||
/// </summary>
|
||||
ASSISTANT_REQUEST,
|
||||
}
|
||||
@@ -63,15 +63,8 @@ public partial class SingleInputDialog : MSGComponentBase
|
||||
|
||||
private async Task HandleUserInputKeyDown(KeyboardEventArgs keyEvent)
|
||||
{
|
||||
var key = keyEvent.Key.ToLowerInvariant();
|
||||
var code = keyEvent.Code.ToLowerInvariant();
|
||||
if (key is not "enter" && code is not "enter" and not "numpadenter")
|
||||
return;
|
||||
|
||||
if (keyEvent is { AltKey: true } or { CtrlKey: true } or { MetaKey: true })
|
||||
return;
|
||||
|
||||
await this.Confirm();
|
||||
if (keyEvent.IsPlainEnter)
|
||||
await this.Confirm();
|
||||
}
|
||||
|
||||
private async Task Confirm()
|
||||
|
||||
@@ -93,15 +93,8 @@ public partial class WorkspaceSelectionDialog : MSGComponentBase
|
||||
|
||||
private async Task HandleNewWorkspaceNameKeyDown(KeyboardEventArgs keyEvent)
|
||||
{
|
||||
var key = keyEvent.Key.ToLowerInvariant();
|
||||
var code = keyEvent.Code.ToLowerInvariant();
|
||||
if (key is not "enter" && code is not "enter" and not "numpadenter")
|
||||
return;
|
||||
|
||||
if (keyEvent is { AltKey: true } or { CtrlKey: true } or { MetaKey: true })
|
||||
return;
|
||||
|
||||
await this.CreateWorkspaceAsync();
|
||||
if (keyEvent.IsPlainEnter)
|
||||
await this.CreateWorkspaceAsync();
|
||||
}
|
||||
|
||||
private void ShowCreateWorkspaceForm()
|
||||
|
||||
Reference in new issue
Block a user