mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 15:19:46 +00:00
Refactored provider dialog
This commit is contained in:
parent
4f5815272a
commit
e68bd4f574
@ -13,7 +13,7 @@
|
|||||||
<MudSelectItem Value="@provider">@provider</MudSelectItem>
|
<MudSelectItem Value="@provider">@provider</MudSelectItem>
|
||||||
}
|
}
|
||||||
</MudSelect>
|
</MudSelect>
|
||||||
<MudButton Disabled="@this.IsSelfHostedOrNone" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.GetProviderCreationURL()" Target="_blank">Create account</MudButton>
|
<MudButton Disabled="@(!this.ShowRegisterButton)" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.GetProviderCreationURL()" Target="_blank">Create account</MudButton>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
|
|
||||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||||
@ -21,7 +21,7 @@
|
|||||||
T="string"
|
T="string"
|
||||||
@bind-Text="@this.dataAPIKey"
|
@bind-Text="@this.dataAPIKey"
|
||||||
Label="API Key"
|
Label="API Key"
|
||||||
Disabled="@this.IsSelfHostedOrNone"
|
Disabled="@(!this.NeedAPIKey)"
|
||||||
Class="mb-3"
|
Class="mb-3"
|
||||||
Adornment="Adornment.Start"
|
Adornment="Adornment.Start"
|
||||||
AdornmentIcon="@Icons.Material.Filled.VpnKey"
|
AdornmentIcon="@Icons.Material.Filled.VpnKey"
|
||||||
@ -34,7 +34,7 @@
|
|||||||
T="string"
|
T="string"
|
||||||
@bind-Text="@this.DataHostname"
|
@bind-Text="@this.DataHostname"
|
||||||
Label="Hostname"
|
Label="Hostname"
|
||||||
Disabled="@this.IsCloudProvider"
|
Disabled="@(!this.NeedHostname)"
|
||||||
Class="mb-3"
|
Class="mb-3"
|
||||||
Adornment="Adornment.Start"
|
Adornment="Adornment.Start"
|
||||||
AdornmentIcon="@Icons.Material.Filled.Dns"
|
AdornmentIcon="@Icons.Material.Filled.Dns"
|
||||||
@ -43,7 +43,7 @@
|
|||||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<MudSelect Disabled="@this.IsCloudProvider" @bind-Value="@this.DataHost" Label="Host" Class="mb-3" OpenIcon="@Icons.Material.Filled.ExpandMore" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.ValidatingHost">
|
<MudSelect Disabled="@(!this.NeedHost)" @bind-Value="@this.DataHost" Label="Host" Class="mb-3" OpenIcon="@Icons.Material.Filled.ExpandMore" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.ValidatingHost">
|
||||||
@foreach (Host host in Enum.GetValues(typeof(Host)))
|
@foreach (Host host in Enum.GetValues(typeof(Host)))
|
||||||
{
|
{
|
||||||
<MudSelectItem Value="@host">@host.Name()</MudSelectItem>
|
<MudSelectItem Value="@host">@host.Name()</MudSelectItem>
|
||||||
@ -51,13 +51,31 @@
|
|||||||
</MudSelect>
|
</MudSelect>
|
||||||
|
|
||||||
<MudStack Row="@true" AlignItems="AlignItems.Center">
|
<MudStack Row="@true" AlignItems="AlignItems.Center">
|
||||||
<MudButton Disabled="@(!this.CanLoadModels())" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Refresh" OnClick="this.ReloadModels">Load</MudButton>
|
@if (this.ProvideModelManually)
|
||||||
<MudSelect Disabled="@this.IsNoneProvider" @bind-Value="@this.DataModel" Label="Model" Class="mb-3" OpenIcon="@Icons.Material.Filled.FaceRetouchingNatural" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.ValidatingModel">
|
{
|
||||||
@foreach (var model in this.availableModels)
|
<MudButton Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.GetModelOverviewURL()" Target="_blank">Show available models</MudButton>
|
||||||
{
|
<MudTextField
|
||||||
<MudSelectItem Value="@model">@model</MudSelectItem>
|
T="string"
|
||||||
}
|
@bind-Text="@this.dataManuallyModel"
|
||||||
</MudSelect>
|
Label="Model"
|
||||||
|
Class="mb-3"
|
||||||
|
Adornment="Adornment.Start"
|
||||||
|
AdornmentIcon="@Icons.Material.Filled.Dns"
|
||||||
|
AdornmentColor="Color.Info"
|
||||||
|
Validation="@this.ValidateManuallyModel"
|
||||||
|
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudButton Disabled="@(!this.CanLoadModels())" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Refresh" OnClick="this.ReloadModels">Load</MudButton>
|
||||||
|
<MudSelect Disabled="@this.IsNoneProvider" @bind-Value="@this.DataModel" Label="Model" Class="mb-3" OpenIcon="@Icons.Material.Filled.FaceRetouchingNatural" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.ValidatingModel">
|
||||||
|
@foreach (var model in this.availableModels)
|
||||||
|
{
|
||||||
|
<MudSelectItem Value="@model">@model</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
}
|
||||||
</MudStack>
|
</MudStack>
|
||||||
|
|
||||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||||
|
@ -86,6 +86,7 @@ public partial class ProviderDialog : ComponentBase
|
|||||||
private bool dataIsValid;
|
private bool dataIsValid;
|
||||||
private string[] dataIssues = [];
|
private string[] dataIssues = [];
|
||||||
private string dataAPIKey = string.Empty;
|
private string dataAPIKey = string.Empty;
|
||||||
|
private string dataManuallyModel = string.Empty;
|
||||||
private string dataAPIKeyStorageIssue = string.Empty;
|
private string dataAPIKeyStorageIssue = string.Empty;
|
||||||
private string dataEditingPreviousInstanceName = string.Empty;
|
private string dataEditingPreviousInstanceName = string.Empty;
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ public partial class ProviderDialog : ComponentBase
|
|||||||
Id = this.DataId,
|
Id = this.DataId,
|
||||||
InstanceName = this.DataInstanceName,
|
InstanceName = this.DataInstanceName,
|
||||||
UsedProvider = this.DataProvider,
|
UsedProvider = this.DataProvider,
|
||||||
Model = this.DataModel,
|
Model = this.DataProvider is Providers.FIREWORKS ? new Model(this.dataManuallyModel) : this.DataModel,
|
||||||
IsSelfHosted = this.DataProvider is Providers.SELF_HOSTED,
|
IsSelfHosted = this.DataProvider is Providers.SELF_HOSTED,
|
||||||
Hostname = this.DataHostname.EndsWith('/') ? this.DataHostname[..^1] : this.DataHostname,
|
Hostname = this.DataHostname.EndsWith('/') ? this.DataHostname[..^1] : this.DataHostname,
|
||||||
Host = this.DataHost,
|
Host = this.DataHost,
|
||||||
@ -220,6 +221,14 @@ public partial class ProviderDialog : ComponentBase
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string? ValidateManuallyModel(string manuallyModel)
|
||||||
|
{
|
||||||
|
if (this.DataProvider is Providers.FIREWORKS && string.IsNullOrWhiteSpace(manuallyModel))
|
||||||
|
return "Please enter a model name.";
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private string? ValidatingModel(Model model)
|
private string? ValidatingModel(Model model)
|
||||||
{
|
{
|
||||||
if(this.DataProvider is Providers.SELF_HOSTED && this.DataHost == Host.LLAMACPP)
|
if(this.DataProvider is Providers.SELF_HOSTED && this.DataHost == Host.LLAMACPP)
|
||||||
@ -354,11 +363,52 @@ public partial class ProviderDialog : ComponentBase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsCloudProvider => this.DataProvider is not Providers.SELF_HOSTED;
|
private bool ShowRegisterButton => this.DataProvider switch
|
||||||
|
{
|
||||||
|
Providers.OPEN_AI => true,
|
||||||
|
Providers.MISTRAL => true,
|
||||||
|
Providers.ANTHROPIC => true,
|
||||||
|
|
||||||
|
Providers.FIREWORKS => true,
|
||||||
|
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
private bool NeedAPIKey => this.DataProvider switch
|
||||||
|
{
|
||||||
|
Providers.OPEN_AI => true,
|
||||||
|
Providers.MISTRAL => true,
|
||||||
|
Providers.ANTHROPIC => true,
|
||||||
|
|
||||||
|
Providers.FIREWORKS => true,
|
||||||
|
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
private bool NeedHostname => this.DataProvider switch
|
||||||
|
{
|
||||||
|
Providers.SELF_HOSTED => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
private bool IsSelfHostedOrNone => this.DataProvider is Providers.SELF_HOSTED or Providers.NONE;
|
private bool NeedHost => this.DataProvider switch
|
||||||
|
{
|
||||||
|
Providers.SELF_HOSTED => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
private bool IsNoneProvider => this.DataProvider is Providers.NONE;
|
private bool ProvideModelManually => this.DataProvider switch
|
||||||
|
{
|
||||||
|
Providers.FIREWORKS => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
private string GetModelOverviewURL() => this.DataProvider switch
|
||||||
|
{
|
||||||
|
Providers.FIREWORKS => "https://fireworks.ai/models?show=Serverless",
|
||||||
|
|
||||||
|
_ => string.Empty,
|
||||||
|
};
|
||||||
|
|
||||||
private string GetProviderCreationURL() => this.DataProvider switch
|
private string GetProviderCreationURL() => this.DataProvider switch
|
||||||
{
|
{
|
||||||
@ -366,6 +416,10 @@ public partial class ProviderDialog : ComponentBase
|
|||||||
Providers.MISTRAL => "https://console.mistral.ai/",
|
Providers.MISTRAL => "https://console.mistral.ai/",
|
||||||
Providers.ANTHROPIC => "https://console.anthropic.com/dashboard",
|
Providers.ANTHROPIC => "https://console.anthropic.com/dashboard",
|
||||||
|
|
||||||
|
Providers.FIREWORKS => "https://fireworks.ai/login",
|
||||||
|
|
||||||
_ => string.Empty,
|
_ => string.Empty,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private bool IsNoneProvider => this.DataProvider is Providers.NONE;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user