-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d3c2c3
commit 8e713e5
Showing
5 changed files
with
202 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,20 @@ | ||
@inherits ComponentBase | ||
@typeparam T | ||
@inherits Setting<T> | ||
|
||
<div class="setting-container"> | ||
<div class="flex-row"> | ||
<MudText> | ||
Request timeout | ||
</MudText> | ||
|
||
<MudTextField Class="setting-field" | ||
Margin="Margin.Dense" | ||
@onfocusout="OnInputFocusOut" | ||
Variant="Variant.Outlined" | ||
Value="@Value"/> | ||
</div> | ||
|
||
@* <MudSlider Min="10" Max="120" Value="Value" Color="Color.Primary" *@ | ||
@* Variant="Variant.Filled"/> *@ | ||
</div> | ||
|
||
@code { | ||
|
||
[Parameter] public required object Value { get; set; } | ||
[Parameter] public object? MinValue { get; set; } | ||
[Parameter] public object? MaxValue { get; set; } | ||
|
||
private void OnInputFocusOut() | ||
{ | ||
|
||
} | ||
} | ||
@* <div class="setting-container"> *@ | ||
@* <div class="flex-row"> *@ | ||
@* <MudText> *@ | ||
@* Request timeout *@ | ||
@* </MudText> *@ | ||
@* *@ | ||
@* <MudTextField Class="setting-field" *@ | ||
@* Margin="Margin.Dense" *@ | ||
@* @onfocusout="OnInputFocusOut" *@ | ||
@* @onkeydown="OnKeyDown" *@ | ||
@* Variant="Variant.Outlined" *@ | ||
@* Value="@Value"/> *@ | ||
@* </div> *@ | ||
@* *@ | ||
@* <MudSlider Min="10" Max="120" Value="Value" Color="Color.Primary" *@ | ||
@* Variant="Variant.Filled"/> *@ | ||
@* </div> *@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Components; | ||
using System.Numerics; | ||
|
||
namespace LMKit.Maestro.UI.Razor; | ||
|
||
public partial class Setting<T> : ComponentBase where T : struct, INumber<T> | ||
{ | ||
private string _inputText = ""; | ||
|
||
[Parameter] public required object Value { get; set; } | ||
[Parameter] public object? MinValue { get; set; } | ||
[Parameter] public object? MaxValue { get; set; } | ||
|
||
private void OnInputFocusOut() | ||
{ | ||
ValidateSettingValue(); | ||
} | ||
|
||
private void OnKeyDown(KeyboardEventArgs keyboardEventArgs) | ||
{ | ||
if (keyboardEventArgs.Key == "Enter") | ||
{ | ||
ValidateSettingValue(); | ||
} | ||
} | ||
|
||
private void ValidateSettingValue() | ||
{ | ||
if (int.TryParse(_inputText, out int parsedValue)) | ||
{ | ||
Value = parsedValue; | ||
} | ||
else | ||
{ | ||
_inputText = Value.ToString()!; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.setting-container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
} | ||
|
||
.flex-row { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
|
||
::deep .setting-field { | ||
max-width: 64px !important; | ||
min-width: 64px !important; | ||
} | ||
|
||
::deep .setting-field .mud-input-root { | ||
text-align: right !important; | ||
padding-inline: 8px !important; | ||
padding-block: 8px !important; | ||
/*padding-block-start: 0 !important;*/ | ||
/*padding-block-end: 0 !important;*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,140 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using LMKit.Maestro.Services; | ||
|
||
namespace LMKit.Maestro.ViewModels | ||
{ | ||
public partial class SettingsViewModel : ViewModelBase | ||
{ | ||
private readonly IAppSettingsService _appSettingsService; | ||
private readonly LMKitConfig _config; | ||
|
||
public string SystemPrompt | ||
{ | ||
get => _config.SystemPrompt; | ||
set | ||
{ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using LMKit.Maestro.Services; | ||
|
||
namespace LMKit.Maestro.ViewModels | ||
{ | ||
public partial class SettingsViewModel : ViewModelBase | ||
{ | ||
private readonly IAppSettingsService _appSettingsService; | ||
private readonly LMKitConfig _config; | ||
|
||
public string SystemPrompt | ||
{ | ||
get => _config.SystemPrompt; | ||
set | ||
{ | ||
if (_config.SystemPrompt != value) | ||
{ | ||
_config.SystemPrompt = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
public int MaximumCompletionTokens | ||
{ | ||
get => _config.MaximumCompletionTokens; | ||
set | ||
{ | ||
} | ||
} | ||
} | ||
|
||
public int MaximumCompletionTokens | ||
{ | ||
get => _config.MaximumCompletionTokens; | ||
set | ||
{ | ||
if (_config.MaximumCompletionTokens != value) | ||
{ | ||
_config.MaximumCompletionTokens = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
public int RequestTimeout | ||
{ | ||
get => _config.RequestTimeout; | ||
set | ||
{ | ||
} | ||
} | ||
} | ||
|
||
public int RequestTimeout | ||
{ | ||
get => _config.RequestTimeout; | ||
set | ||
{ | ||
if (_config.RequestTimeout != value) | ||
{ | ||
_config.RequestTimeout = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
public int ContextSize | ||
{ | ||
get => _config.ContextSize; | ||
set | ||
{ | ||
} | ||
} | ||
} | ||
|
||
public int ContextSize | ||
{ | ||
get => _config.ContextSize; | ||
set | ||
{ | ||
int newValue = (int)Math.Round(value / 128.0) * 128; | ||
|
||
if (_config.ContextSize != newValue) | ||
{ | ||
_config.ContextSize = newValue; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
public SamplingMode SamplingMode | ||
{ | ||
get => _config.SamplingMode; | ||
set | ||
{ | ||
} | ||
} | ||
} | ||
|
||
public SamplingMode SamplingMode | ||
{ | ||
get => _config.SamplingMode; | ||
set | ||
{ | ||
if (_config.SamplingMode != value) | ||
{ | ||
_config.SamplingMode = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
[ObservableProperty] | ||
RandomSamplingSettingsViewModel _randomSamplingSettings; | ||
|
||
[ObservableProperty] | ||
Mirostat2SamplingSettingsViewModel _Mirostat2SamplingSettings; | ||
|
||
public SettingsViewModel(IAppSettingsService appSettingsService, LMKitService lmkitService) | ||
{ | ||
_appSettingsService = appSettingsService; | ||
_config = lmkitService.LMKitConfig; | ||
RandomSamplingSettings = new RandomSamplingSettingsViewModel(_config.RandomSamplingConfig); | ||
Mirostat2SamplingSettings = new Mirostat2SamplingSettingsViewModel(_config.Mirostat2SamplingConfig); | ||
} | ||
|
||
[RelayCommand] | ||
public void ResetDefaultValues() | ||
{ | ||
SystemPrompt = LMKitDefaultSettings.DefaultSystemPrompt; | ||
SamplingMode = LMKitDefaultSettings.DefaultSamplingMode; | ||
MaximumCompletionTokens = LMKitDefaultSettings.DefaultMaximumCompletionTokens; | ||
RequestTimeout = LMKitDefaultSettings.DefaultRequestTimeout; | ||
ContextSize = LMKitDefaultSettings.DefaultContextSize; | ||
RandomSamplingSettings.Reset(); | ||
Mirostat2SamplingSettings.Reset(); | ||
} | ||
|
||
public void Init() | ||
{ | ||
SystemPrompt = _appSettingsService.SystemPrompt; | ||
SamplingMode = _appSettingsService.SamplingMode; | ||
MaximumCompletionTokens = _appSettingsService.MaximumCompletionTokens; | ||
RequestTimeout = _appSettingsService.RequestTimeout; | ||
SamplingMode = _appSettingsService.SamplingMode; | ||
ContextSize = _appSettingsService.ContextSize; | ||
|
||
var randomSamplingConfig = _appSettingsService.RandomSamplingConfig; | ||
RandomSamplingSettings.Temperature = randomSamplingConfig.Temperature; | ||
RandomSamplingSettings.DynamicTemperatureRange = randomSamplingConfig.DynamicTemperatureRange; | ||
RandomSamplingSettings.TopP = randomSamplingConfig.TopP; | ||
RandomSamplingSettings.MinP = randomSamplingConfig.MinP; | ||
RandomSamplingSettings.TopK = randomSamplingConfig.TopK; | ||
RandomSamplingSettings.LocallyTypical = randomSamplingConfig.LocallyTypical; | ||
|
||
var Mirostat2SamplingConfig = _appSettingsService.Mirostat2SamplingConfig; | ||
Mirostat2SamplingSettings.Temperature = Mirostat2SamplingConfig.Temperature; | ||
Mirostat2SamplingSettings.TargetEntropy = Mirostat2SamplingConfig.TargetEntropy; | ||
Mirostat2SamplingSettings.LearningRate = Mirostat2SamplingConfig.LearningRate; | ||
} | ||
|
||
public void Save() | ||
{ | ||
_appSettingsService.LastLoadedModelUri = _config.LoadedModelUri; | ||
_appSettingsService.SystemPrompt = _config.SystemPrompt; | ||
_appSettingsService.MaximumCompletionTokens = _config.MaximumCompletionTokens; | ||
_appSettingsService.RequestTimeout = _config.RequestTimeout; | ||
_appSettingsService.ContextSize = _config.ContextSize; | ||
_appSettingsService.SamplingMode = _config.SamplingMode; | ||
_appSettingsService.RandomSamplingConfig = _config.RandomSamplingConfig; | ||
_appSettingsService.Mirostat2SamplingConfig = _config.Mirostat2SamplingConfig; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
[ObservableProperty] | ||
RandomSamplingSettingsViewModel _randomSamplingSettings; | ||
|
||
[ObservableProperty] | ||
Mirostat2SamplingSettingsViewModel _Mirostat2SamplingSettings; | ||
|
||
public SettingsViewModel(IAppSettingsService appSettingsService, LMKitService lmkitService) | ||
{ | ||
_appSettingsService = appSettingsService; | ||
_config = lmkitService.LMKitConfig; | ||
RandomSamplingSettings = new RandomSamplingSettingsViewModel(_config.RandomSamplingConfig); | ||
Mirostat2SamplingSettings = new Mirostat2SamplingSettingsViewModel(_config.Mirostat2SamplingConfig); | ||
} | ||
|
||
[RelayCommand] | ||
public void ResetDefaultValues() | ||
{ | ||
SystemPrompt = LMKitDefaultSettings.DefaultSystemPrompt; | ||
SamplingMode = LMKitDefaultSettings.DefaultSamplingMode; | ||
MaximumCompletionTokens = LMKitDefaultSettings.DefaultMaximumCompletionTokens; | ||
RequestTimeout = LMKitDefaultSettings.DefaultRequestTimeout; | ||
ContextSize = LMKitDefaultSettings.DefaultContextSize; | ||
RandomSamplingSettings.Reset(); | ||
Mirostat2SamplingSettings.Reset(); | ||
} | ||
|
||
public void Init() | ||
{ | ||
SystemPrompt = _appSettingsService.SystemPrompt; | ||
SamplingMode = _appSettingsService.SamplingMode; | ||
MaximumCompletionTokens = _appSettingsService.MaximumCompletionTokens; | ||
RequestTimeout = _appSettingsService.RequestTimeout; | ||
SamplingMode = _appSettingsService.SamplingMode; | ||
ContextSize = _appSettingsService.ContextSize; | ||
|
||
var randomSamplingConfig = _appSettingsService.RandomSamplingConfig; | ||
RandomSamplingSettings.Temperature = randomSamplingConfig.Temperature; | ||
RandomSamplingSettings.DynamicTemperatureRange = randomSamplingConfig.DynamicTemperatureRange; | ||
RandomSamplingSettings.TopP = randomSamplingConfig.TopP; | ||
RandomSamplingSettings.MinP = randomSamplingConfig.MinP; | ||
RandomSamplingSettings.TopK = randomSamplingConfig.TopK; | ||
RandomSamplingSettings.LocallyTypical = randomSamplingConfig.LocallyTypical; | ||
|
||
var Mirostat2SamplingConfig = _appSettingsService.Mirostat2SamplingConfig; | ||
Mirostat2SamplingSettings.Temperature = Mirostat2SamplingConfig.Temperature; | ||
Mirostat2SamplingSettings.TargetEntropy = Mirostat2SamplingConfig.TargetEntropy; | ||
Mirostat2SamplingSettings.LearningRate = Mirostat2SamplingConfig.LearningRate; | ||
} | ||
|
||
public void Save() | ||
{ | ||
_appSettingsService.LastLoadedModelUri = _config.LoadedModelUri; | ||
_appSettingsService.SystemPrompt = _config.SystemPrompt; | ||
_appSettingsService.MaximumCompletionTokens = _config.MaximumCompletionTokens; | ||
_appSettingsService.RequestTimeout = _config.RequestTimeout; | ||
_appSettingsService.ContextSize = _config.ContextSize; | ||
_appSettingsService.SamplingMode = _config.SamplingMode; | ||
_appSettingsService.RandomSamplingConfig = _config.RandomSamplingConfig; | ||
_appSettingsService.Mirostat2SamplingConfig = _config.Mirostat2SamplingConfig; | ||
} | ||
} | ||
} |