|
|
|
@ -1,12 +1,21 @@
|
|
|
|
|
using System.Diagnostics; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Collections.Immutable; |
|
|
|
|
using System.Diagnostics; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Text; |
|
|
|
|
using System.Text.Json.Nodes; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using AvaloniaEdit.Document; |
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel; |
|
|
|
|
using CommunityToolkit.Mvvm.Input; |
|
|
|
|
using StabilityMatrix.Avalonia.Controls; |
|
|
|
|
using StabilityMatrix.Avalonia.Models; |
|
|
|
|
using StabilityMatrix.Avalonia.Models.Inference; |
|
|
|
|
using StabilityMatrix.Avalonia.Models.TagCompletion; |
|
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Base; |
|
|
|
|
using StabilityMatrix.Core.Attributes; |
|
|
|
|
using StabilityMatrix.Core.Extensions; |
|
|
|
|
using StabilityMatrix.Core.Services; |
|
|
|
|
|
|
|
|
|
namespace StabilityMatrix.Avalonia.ViewModels.Inference; |
|
|
|
@ -16,6 +25,7 @@ public partial class PromptCardViewModel : LoadableViewModelBase
|
|
|
|
|
{ |
|
|
|
|
public ICompletionProvider CompletionProvider { get; } |
|
|
|
|
public ITokenizerProvider TokenizerProvider { get; } |
|
|
|
|
public SharedState SharedState { get; } |
|
|
|
|
|
|
|
|
|
public TextDocument PromptDocument { get; } = new(); |
|
|
|
|
public TextDocument NegativePromptDocument { get; } = new(); |
|
|
|
@ -27,22 +37,55 @@ public partial class PromptCardViewModel : LoadableViewModelBase
|
|
|
|
|
public PromptCardViewModel( |
|
|
|
|
ICompletionProvider completionProvider, |
|
|
|
|
ITokenizerProvider tokenizerProvider, |
|
|
|
|
ISettingsManager settingsManager) |
|
|
|
|
ISettingsManager settingsManager, |
|
|
|
|
SharedState sharedState) |
|
|
|
|
{ |
|
|
|
|
CompletionProvider = completionProvider; |
|
|
|
|
TokenizerProvider = tokenizerProvider; |
|
|
|
|
SharedState = sharedState; |
|
|
|
|
|
|
|
|
|
settingsManager.RelayPropertyFor(this, |
|
|
|
|
vm => vm.IsAutoCompletionEnabled, |
|
|
|
|
settings => settings.IsPromptCompletionEnabled, |
|
|
|
|
true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Processes current positive prompt text into a Prompt object |
|
|
|
|
/// </summary> |
|
|
|
|
public Prompt GetPrompt() |
|
|
|
|
{ |
|
|
|
|
return Prompt.FromRawText(PromptDocument.Text, TokenizerProvider); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
partial void OnIsAutoCompletionEnabledChanged(bool value) |
|
|
|
|
/// <summary> |
|
|
|
|
/// Processes current negative prompt text into a Prompt object |
|
|
|
|
/// </summary> |
|
|
|
|
public Prompt GetNegativePrompt() |
|
|
|
|
{ |
|
|
|
|
Debug.WriteLine("OnIsAutoCompletionEnabledChanged: " + value); |
|
|
|
|
return Prompt.FromRawText(NegativePromptDocument.Text, TokenizerProvider); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[RelayCommand] |
|
|
|
|
private async Task DebugShowTokens() |
|
|
|
|
{ |
|
|
|
|
var prompt = GetPrompt(); |
|
|
|
|
var tokens = prompt.TokenizeResult.Tokens; |
|
|
|
|
|
|
|
|
|
var builder = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
builder.AppendLine($"Tokens ({tokens.Length}):"); |
|
|
|
|
builder.AppendLine("```csharp"); |
|
|
|
|
builder.AppendLine(prompt.GetDebugText()); |
|
|
|
|
builder.AppendLine("```"); |
|
|
|
|
|
|
|
|
|
var dialog = DialogHelper.CreateMarkdownDialog(builder.ToString(), "Prompt Tokens"); |
|
|
|
|
dialog.MinDialogWidth = 800; |
|
|
|
|
dialog.MaxDialogHeight = 1000; |
|
|
|
|
dialog.MaxDialogWidth = 1000; |
|
|
|
|
await dialog.ShowAsync(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <inheritdoc /> |
|
|
|
|
public override JsonObject SaveStateToJsonObject() |
|
|
|
|
{ |
|
|
|
|