Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
BeepBeepBopBop committed Jan 23, 2025
1 parent 9d3c2c3 commit 8e713e5
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 148 deletions.
2 changes: 1 addition & 1 deletion LM-Kit-Maestro/UI/Razor/Components/ChatSettings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<MudStack Spacing="6">

<Setting Value="ViewModel.RequestTimeout"/>

Check failure on line 7 in LM-Kit-Maestro/UI/Razor/Components/ChatSettings.razor

View workflow job for this annotation

GitHub Actions / build

The type of component 'Setting' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'T'.

Check failure on line 7 in LM-Kit-Maestro/UI/Razor/Components/ChatSettings.razor

View workflow job for this annotation

GitHub Actions / build

The type of component 'Setting' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'T'.

Check failure on line 7 in LM-Kit-Maestro/UI/Razor/Components/ChatSettings.razor

View workflow job for this annotation

GitHub Actions / build

The type of component 'Setting' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'T'.

Check failure on line 7 in LM-Kit-Maestro/UI/Razor/Components/ChatSettings.razor

View workflow job for this annotation

GitHub Actions / build

The type of component 'Setting' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'T'.

Check failure on line 7 in LM-Kit-Maestro/UI/Razor/Components/ChatSettings.razor

View workflow job for this annotation

GitHub Actions / build

The type of component 'Setting' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'T'.

<div class="setting-container">
<MudText>
Chatbot purpose
Expand Down
48 changes: 19 additions & 29 deletions LM-Kit-Maestro/UI/Razor/Components/Setting.razor
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> *@
39 changes: 39 additions & 0 deletions LM-Kit-Maestro/UI/Razor/Components/Setting.razor.cs
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()!;
}
}
}
25 changes: 25 additions & 0 deletions LM-Kit-Maestro/UI/Razor/Components/Setting.razor.css
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;*/
}
236 changes: 118 additions & 118 deletions LM-Kit-Maestro/ViewModels/SettingsViewModel.cs
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;
}
}
}

0 comments on commit 8e713e5

Please sign in to comment.