Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
BeepBeepBopBop committed Jan 24, 2025
1 parent d9cef49 commit 78ea484
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
4 changes: 3 additions & 1 deletion LM-Kit-Maestro/UI/Razor/Components/ChatSettings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<MudExpansionPanel Text="General settings">
<MudStack Spacing="6">

<NumericSetting Value="ViewModel.MaximumCompletionTokens" />
<NumericSetting @bind-Value="ViewModel.RequestTimeout"
Title="Request timeout (sec)" MinValue="10" MaxValue="120" />

<div class="setting-container">
<MudText>
Expand Down Expand Up @@ -71,4 +72,5 @@
@code
{
[Parameter] public SettingsViewModel ViewModel { get; set; }

}
48 changes: 38 additions & 10 deletions LM-Kit-Maestro/UI/Razor/Components/NumericSetting.razor.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components;
using System.Numerics;
using System.Globalization;

namespace LMKit.Maestro.UI.Razor.Components;

public partial class NumericSetting<T> : ComponentBase where T : struct, INumber<T>
{
private string _inputText = "";

[Parameter] public required string Title { get; set; }
[Parameter] public required T Value { get; set; }
[Parameter] public EventCallback<T> ValueChanged { get; set; }

[Parameter] public required T MinValue { get; set; }
[Parameter] public required T MaxValue { get; set; }


private T _value;

[Parameter]
public T Value
{
get => _value;
set
{
if (!EqualityComparer<T>.Default.Equals(_value, value))
{
_value = value;
ValueChanged.InvokeAsync(value);
_inputText = value.ToString()!;
}
}
}

private void OnInputFocusOut()
{
ValidateSettingValue();
}

protected override void OnParametersSet()
{
base.OnParametersSet();

_inputText = Value.ToString()!;
InvokeAsync(() => StateHasChanged());
}

private void OnKeyDown(KeyboardEventArgs keyboardEventArgs)
{
if (keyboardEventArgs.Key == "Enter")
Expand All @@ -28,13 +55,14 @@ private void OnKeyDown(KeyboardEventArgs keyboardEventArgs)

private void ValidateSettingValue()
{
//if (int.TryParse(_inputText, out int parsedValue))
//{
// Value = parsedValue;
//}
//else
//{
// _inputText = Value.ToString()!;
//}
if (T.TryParse(_inputText, new CultureInfo("en-US"), out T parsedValue))
{
Value = parsedValue;
}
else
{
_inputText = Value.ToString()!;
InvokeAsync(() => StateHasChanged());
}
}
}

0 comments on commit 78ea484

Please sign in to comment.