2024-12-03 14:24:40 +00:00
@using AIStudio.Provider
@using AIStudio.Provider.SelfHosted
2026-04-10 16:31:20 +00:00
@using AIStudio.Tools.Rust
2025-05-11 14:57:52 +00:00
@inherits MSGComponentBase
2024-12-03 14:24:40 +00:00
<MudDialog>
<DialogContent>
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues">
<MudStack Row="@true" AlignItems="AlignItems.Center">
@* ReSharper disable once CSharpWarnings::CS8974 *@
2026-04-10 16:31:20 +00:00
<MudSelect @bind-Value="@this.DataLLMProvider" Label="@T("Provider")" Class="mb-3" OpenIcon="@Icons.Material.Filled.AccountBalance" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.providerValidation.ValidatingProvider">
2024-12-03 14:24:40 +00:00
@foreach (LLMProviders provider in Enum.GetValues(typeof(LLMProviders)))
{
2026-01-09 11:45:21 +00:00
if (provider.ProvideEmbeddingAPI() || provider is LLMProviders.NONE)
2024-12-03 14:24:40 +00:00
{
2025-04-20 10:42:42 +00:00
<MudSelectItem Value="@provider">
@provider.ToName()
</MudSelectItem>
2024-12-03 14:24:40 +00:00
}
}
</MudSelect>
2025-05-11 14:57:52 +00:00
<MudButton Disabled="@(!this.DataLLMProvider.ShowRegisterButton())" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.DataLLMProvider.GetCreationURL()" Target="_blank">
@T("Create account")
</MudButton>
2024-12-03 14:24:40 +00:00
</MudStack>
2026-04-10 16:31:20 +00:00
2025-04-20 10:42:42 +00:00
@if (this.DataLLMProvider.IsAPIKeyNeeded(this.DataHost))
{
2026-01-11 15:02:28 +00:00
<SecretInputField Secret="@this.dataAPIKey" SecretChanged="@this.OnAPIKeyChanged" Label="@this.APIKeyText" Validation="@this.providerValidation.ValidatingAPIKey"/>
2025-04-20 10:42:42 +00:00
}
2024-12-03 14:24:40 +00:00
2025-04-20 10:42:42 +00:00
@if (this.DataLLMProvider.IsHostnameNeeded())
{
<MudTextField
T="string"
@bind-Text="@this.DataHostname"
2025-05-11 14:57:52 +00:00
Label="@T("Hostname")"
2025-04-20 10:42:42 +00:00
Class="mb-3"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Dns"
AdornmentColor="Color.Info"
Validation="@this.providerValidation.ValidatingHostname"
UserAttributes="@SPELLCHECK_ATTRIBUTES"/>
}
@if (this.DataLLMProvider.IsHostNeeded())
{
2026-01-18 16:15:18 +00:00
<MudSelect T="Host" Value="@this.DataHost" ValueChanged="@this.OnHostChanged" Label="@T("Host")" Class="mb-3" OpenIcon="@Icons.Material.Filled.ExpandMore" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.providerValidation.ValidatingHost">
2025-04-20 10:42:42 +00:00
@foreach (Host host in Enum.GetValues(typeof(Host)))
2024-12-03 14:24:40 +00:00
{
2026-01-09 11:45:21 +00:00
if (host.IsEmbeddingSupported())
2025-04-20 10:42:42 +00:00
{
<MudSelectItem Value="@host">
@host.Name()
</MudSelectItem>
}
2024-12-03 14:24:40 +00:00
}
2025-04-20 10:42:42 +00:00
</MudSelect>
}
2024-12-03 14:24:40 +00:00
2025-05-11 14:57:52 +00:00
<MudField FullWidth="true" Label="@T("Model selection")" Variant="Variant.Outlined" Class="mb-3">
<MudStack Row="@true" AlignItems="AlignItems.Center" StretchItems="StretchItems.End">
@if (this.DataLLMProvider.IsEmbeddingModelProvidedManually(this.DataHost))
{
<MudTextField
T="string"
@bind-Text="@this.dataManuallyModel"
Label="@T("Model")"
Class="mb-3"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Dns"
AdornmentColor="Color.Info"
Validation="@this.ValidateManuallyModel"
UserAttributes="@SPELLCHECK_ATTRIBUTES"
2026-04-10 16:31:20 +00:00
HelperText="@T("Currently, we cannot query the embedding models for the selected provider and/or host. Therefore, please enter the model name manually.")"/>
2025-05-11 14:57:52 +00:00
}
else
{
2026-01-09 11:45:21 +00:00
<MudButton Disabled="@(!this.DataLLMProvider.CanLoadModels(this.DataHost, this.dataAPIKey))" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Refresh" OnClick="@this.ReloadModels">
2025-05-11 14:57:52 +00:00
@T("Load")
</MudButton>
2026-04-10 16:31:20 +00:00
@if (this.availableModels.Count is 0)
2024-12-03 14:24:40 +00:00
{
2025-05-11 14:57:52 +00:00
<MudText Typo="Typo.body1">
@T("No models loaded or available.")
</MudText>
2024-12-03 14:24:40 +00:00
}
2025-05-11 14:57:52 +00:00
else
{
<MudSelect Disabled="@this.IsNoneProvider" @bind-Value="@this.DataModel" Label="@T("Model")"
OpenIcon="@Icons.Material.Filled.FaceRetouchingNatural"
AdornmentColor="Color.Info" Adornment="Adornment.Start"
Validation="@this.providerValidation.ValidatingModel">
@foreach (var model in this.availableModels)
{
<MudSelectItem Value="@model">
@model
</MudSelectItem>
}
</MudSelect>
}
}
</MudStack>
2026-01-18 16:15:18 +00:00
@if (!string.IsNullOrWhiteSpace(this.dataLoadingModelsIssue))
{
<MudAlert Severity="Severity.Error" Class="mt-3">
@this.dataLoadingModelsIssue
</MudAlert>
}
2025-05-11 14:57:52 +00:00
</MudField>
2024-12-03 14:24:40 +00:00
@* ReSharper disable once CSharpWarnings::CS8974 *@
<MudTextField
T="string"
@bind-Text="@this.DataName"
2025-05-11 14:57:52 +00:00
Label="@T("Instance Name")"
2024-12-03 14:24:40 +00:00
Class="mb-3"
MaxLength="40"
Counter="40"
Immediate="@true"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Lightbulb"
AdornmentColor="Color.Info"
Validation="@this.providerValidation.ValidatingInstanceName"
2026-04-10 16:31:20 +00:00
UserAttributes="@SPELLCHECK_ATTRIBUTES"/>
@if (this.DataModel != default){
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
@T("For better embeddings and less storage usage, it's recommended to use a custom tokenizer to enable a more accurate token count.")
</MudJustifiedText>
<SelectFile
File="@this.dataFilePath"
FileChanged="@this.OnDataFilePathChanged"
Label="@T("Selected file path for the custom tokenizer")"
FileDialogTitle="@T("Choose a custom tokenizer here")"
Filter="[FileTypes.JSON]"
IsClearable="@true"
Error="@(!string.IsNullOrWhiteSpace(this.dataCustomTokenizerValidationIssue))"
ErrorText="@(this.dataCustomTokenizerValidationIssue)"
Validation="@this.providerValidation.ValidatingCustomTokenizer"
OnClear = "@this.ClearPathTokenizer"
/>
}
2024-12-03 14:24:40 +00:00
</MudForm>
2026-04-10 16:31:20 +00:00
@if (this.dataStoreWasAttempted)
{
<Issues IssuesData="@this.dataIssues"/>
}
2024-12-03 14:24:40 +00:00
</DialogContent>
<DialogActions>
2025-05-11 14:57:52 +00:00
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">
@T("Cancel")
</MudButton>
2024-12-03 14:24:40 +00:00
<MudButton OnClick="@this.Store" Variant="Variant.Filled" Color="Color.Primary">
2026-04-10 16:31:20 +00:00
@if (this.IsEditing)
2024-12-03 14:24:40 +00:00
{
2025-05-11 14:57:52 +00:00
@T("Update")
2024-12-03 14:24:40 +00:00
}
else
{
2025-05-11 14:57:52 +00:00
@T("Add")
2024-12-03 14:24:40 +00:00
}
</MudButton>
</DialogActions>
2026-04-10 16:31:20 +00:00
</MudDialog>