diff --git a/AIDevGallery/Samples/Open Source Models/Language Models/CustomSystemPrompt.xaml b/AIDevGallery/Samples/Open Source Models/Language Models/CustomSystemPrompt.xaml index 8715503..e1dd91d 100644 --- a/AIDevGallery/Samples/Open Source Models/Language Models/CustomSystemPrompt.xaml +++ b/AIDevGallery/Samples/Open Source Models/Language Models/CustomSystemPrompt.xaml @@ -1,167 +1,158 @@ - + - - - - - - - - - - - - - + + + + + + - - - - - - - - + HorizontalAlignment="Right" + Orientation="Horizontal" + Spacing="8"> + + + + + + + + + + + + CleanUp(); + Unloaded += (s, e) => Page_Unloaded(); // Loaded += (s, e) => Page_Loaded(); // InitializeComponent(); DoSampleToggle.Toggled += DoSampleToggle_Toggled; @@ -56,6 +59,36 @@ protected override async Task LoadModelAsync(SampleNavigationParameters samplePa private void Page_Loaded() { InputTextBox.Focus(FocusState.Programmatic); + CustomParametersState? lastState = App.AppData.LastCustomParamtersState; + if (lastState != null) + { + DoSampleToggle.IsOn = lastState.DoSample ?? defaultDoSample; + MinLengthSlider.Value = lastState.MinLength ?? 0; + MaxLengthSlider.Value = lastState.MaxLength ?? defaultMaxLength; + TopKSlider.Value = lastState.TopK ?? defaultTopK; + TemperatureSlider.Value = lastState.Temperature ?? defaultTemperature; + TopPSlider.Value = lastState.TopP ?? defaultTopP; + SystemPromptInputTextBox.Text = lastState.SystemPrompt ?? defaultSystemPrompt; + InputTextBox.Text = lastState.UserPrompt ?? string.Empty; + } + } + + private async void Page_Unloaded() + { + CustomParametersState lastState = new() + { + DoSample = DoSampleToggle.IsOn, + MinLength = (int)MinLengthSlider.Value, + MaxLength = (int)MaxLengthSlider.Value, + TopK = (int)TopKSlider.Value, + TopP = (float)TopPSlider.Value, + Temperature = (float)TemperatureSlider.Value, + SystemPrompt = SystemPromptInputTextBox.Text, + UserPrompt = InputTextBox.Text + }; + + App.AppData.LastCustomParamtersState = lastState; + await App.AppData.SaveAsync(); } // diff --git a/AIDevGallery/Utils/AppData.cs b/AIDevGallery/Utils/AppData.cs index e636359..0cf38ad 100644 --- a/AIDevGallery/Utils/AppData.cs +++ b/AIDevGallery/Utils/AppData.cs @@ -16,6 +16,7 @@ internal class AppData { public required string ModelCachePath { get; set; } public required LinkedList MostRecentlyUsedItems { get; set; } + public CustomParametersState? LastCustomParamtersState { get; set; } // model or api ids public required LinkedList UsageHistory { get; set; } @@ -101,4 +102,16 @@ private static AppData GetDefault() UsageHistory = new() }; } +} + +internal class CustomParametersState +{ + public bool? DoSample { get; set; } + public int? MaxLength { get; set; } + public int? MinLength { get; set; } + public int? TopK { get; set; } + public float? TopP { get; set; } + public float? Temperature { get; set; } + public string? UserPrompt { get; set; } + public string? SystemPrompt { get; set; } } \ No newline at end of file