mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 21:39:46 +00:00
Refactored LLM provider related actions
This commit is contained in:
parent
a0c7875cf7
commit
4e7d19d8db
@ -12,7 +12,7 @@
|
|||||||
<MudSelectItem Value="@provider">@provider</MudSelectItem>
|
<MudSelectItem Value="@provider">@provider</MudSelectItem>
|
||||||
}
|
}
|
||||||
</MudSelect>
|
</MudSelect>
|
||||||
<MudButton Disabled="@(!this.ShowRegisterButton)" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.GetProviderCreationURL()" Target="_blank">Create account</MudButton>
|
<MudButton Disabled="@(!this.DataLLMProvider.ShowRegisterButton())" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.DataLLMProvider.GetCreationURL()" Target="_blank">Create account</MudButton>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
|
|
||||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||||
@ -20,7 +20,7 @@
|
|||||||
T="string"
|
T="string"
|
||||||
@bind-Text="@this.dataAPIKey"
|
@bind-Text="@this.dataAPIKey"
|
||||||
Label="@this.APIKeyText"
|
Label="@this.APIKeyText"
|
||||||
Disabled="@(!this.NeedAPIKey)"
|
Disabled="@(!this.DataLLMProvider.IsAPIKeyNeeded(this.DataHost))"
|
||||||
Class="mb-3"
|
Class="mb-3"
|
||||||
Adornment="Adornment.Start"
|
Adornment="Adornment.Start"
|
||||||
AdornmentIcon="@Icons.Material.Filled.VpnKey"
|
AdornmentIcon="@Icons.Material.Filled.VpnKey"
|
||||||
@ -33,7 +33,7 @@
|
|||||||
T="string"
|
T="string"
|
||||||
@bind-Text="@this.DataHostname"
|
@bind-Text="@this.DataHostname"
|
||||||
Label="Hostname"
|
Label="Hostname"
|
||||||
Disabled="@(!this.NeedHostname)"
|
Disabled="@(!this.DataLLMProvider.IsHostnameNeeded())"
|
||||||
Class="mb-3"
|
Class="mb-3"
|
||||||
Adornment="Adornment.Start"
|
Adornment="Adornment.Start"
|
||||||
AdornmentIcon="@Icons.Material.Filled.Dns"
|
AdornmentIcon="@Icons.Material.Filled.Dns"
|
||||||
@ -42,7 +42,7 @@
|
|||||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<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">
|
<MudSelect Disabled="@(!this.DataLLMProvider.IsHostNeeded())" @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>
|
||||||
@ -50,9 +50,9 @@
|
|||||||
</MudSelect>
|
</MudSelect>
|
||||||
|
|
||||||
<MudStack Row="@true" AlignItems="AlignItems.Center">
|
<MudStack Row="@true" AlignItems="AlignItems.Center">
|
||||||
@if (this.ProvideModelManually)
|
@if (this.DataLLMProvider.IsLLMModelProvidedManually())
|
||||||
{
|
{
|
||||||
<MudButton Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.GetModelOverviewURL()" Target="_blank">Show available models</MudButton>
|
<MudButton Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.DataLLMProvider.GetModelsOverviewURL()" Target="_blank">Show available models</MudButton>
|
||||||
<MudTextField
|
<MudTextField
|
||||||
T="string"
|
T="string"
|
||||||
@bind-Text="@this.dataManuallyModel"
|
@bind-Text="@this.dataManuallyModel"
|
||||||
@ -67,7 +67,7 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<MudButton Disabled="@(!this.CanLoadModels())" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Refresh" OnClick="this.ReloadModels">Load</MudButton>
|
<MudButton Disabled="@(!this.DataLLMProvider.CanLoadModels(this.DataHost, this.dataAPIKey))" 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">
|
<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)
|
@foreach (var model in this.availableModels)
|
||||||
{
|
{
|
||||||
|
@ -324,109 +324,11 @@ public partial class ProviderDialog : ComponentBase
|
|||||||
this.availableModels.AddRange(orderedModels);
|
this.availableModels.AddRange(orderedModels);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanLoadModels()
|
|
||||||
{
|
|
||||||
if (this.DataLLMProvider is LLMProviders.SELF_HOSTED)
|
|
||||||
{
|
|
||||||
switch (this.DataHost)
|
|
||||||
{
|
|
||||||
case Host.NONE:
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case Host.LLAMACPP:
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case Host.LM_STUDIO:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case Host.OLLAMA:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.DataLLMProvider is LLMProviders.NONE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(this.dataAPIKey))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ShowRegisterButton => this.DataLLMProvider switch
|
|
||||||
{
|
|
||||||
LLMProviders.OPEN_AI => true,
|
|
||||||
LLMProviders.MISTRAL => true,
|
|
||||||
LLMProviders.ANTHROPIC => true,
|
|
||||||
LLMProviders.GOOGLE => true,
|
|
||||||
|
|
||||||
LLMProviders.GROQ => true,
|
|
||||||
LLMProviders.FIREWORKS => true,
|
|
||||||
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
private bool NeedAPIKey => this.DataLLMProvider switch
|
|
||||||
{
|
|
||||||
LLMProviders.OPEN_AI => true,
|
|
||||||
LLMProviders.MISTRAL => true,
|
|
||||||
LLMProviders.ANTHROPIC => true,
|
|
||||||
LLMProviders.GOOGLE => true,
|
|
||||||
|
|
||||||
LLMProviders.GROQ => true,
|
|
||||||
LLMProviders.FIREWORKS => true,
|
|
||||||
|
|
||||||
LLMProviders.SELF_HOSTED => this.DataHost is Host.OLLAMA,
|
|
||||||
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
private string APIKeyText => this.DataLLMProvider switch
|
private string APIKeyText => this.DataLLMProvider switch
|
||||||
{
|
{
|
||||||
LLMProviders.SELF_HOSTED => "(Optional) API Key",
|
LLMProviders.SELF_HOSTED => "(Optional) API Key",
|
||||||
_ => "API Key",
|
_ => "API Key",
|
||||||
};
|
};
|
||||||
|
|
||||||
private bool NeedHostname => this.DataLLMProvider switch
|
|
||||||
{
|
|
||||||
LLMProviders.SELF_HOSTED => true,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
private bool NeedHost => this.DataLLMProvider switch
|
|
||||||
{
|
|
||||||
LLMProviders.SELF_HOSTED => true,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
private bool ProvideModelManually => this.DataLLMProvider switch
|
|
||||||
{
|
|
||||||
LLMProviders.FIREWORKS => true,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
private string GetModelOverviewURL() => this.DataLLMProvider switch
|
|
||||||
{
|
|
||||||
LLMProviders.FIREWORKS => "https://fireworks.ai/models?show=Serverless",
|
|
||||||
|
|
||||||
_ => string.Empty,
|
|
||||||
};
|
|
||||||
|
|
||||||
private string GetProviderCreationURL() => this.DataLLMProvider switch
|
|
||||||
{
|
|
||||||
LLMProviders.OPEN_AI => "https://platform.openai.com/signup",
|
|
||||||
LLMProviders.MISTRAL => "https://console.mistral.ai/",
|
|
||||||
LLMProviders.ANTHROPIC => "https://console.anthropic.com/dashboard",
|
|
||||||
LLMProviders.GOOGLE => "https://console.cloud.google.com/",
|
|
||||||
|
|
||||||
LLMProviders.GROQ => "https://console.groq.com/",
|
|
||||||
LLMProviders.FIREWORKS => "https://fireworks.ai/login",
|
|
||||||
|
|
||||||
_ => string.Empty,
|
|
||||||
};
|
|
||||||
|
|
||||||
private bool IsNoneProvider => this.DataLLMProvider is LLMProviders.NONE;
|
private bool IsNoneProvider => this.DataLLMProvider is LLMProviders.NONE;
|
||||||
}
|
}
|
@ -7,6 +7,8 @@ using AIStudio.Provider.OpenAI;
|
|||||||
using AIStudio.Provider.SelfHosted;
|
using AIStudio.Provider.SelfHosted;
|
||||||
using AIStudio.Settings;
|
using AIStudio.Settings;
|
||||||
|
|
||||||
|
using Host = AIStudio.Provider.SelfHosted.Host;
|
||||||
|
|
||||||
namespace AIStudio.Provider;
|
namespace AIStudio.Provider;
|
||||||
|
|
||||||
public static class LLMProvidersExtensions
|
public static class LLMProvidersExtensions
|
||||||
@ -125,4 +127,101 @@ public static class LLMProvidersExtensions
|
|||||||
return new NoProvider();
|
return new NoProvider();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetCreationURL(this LLMProviders provider) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.OPEN_AI => "https://platform.openai.com/signup",
|
||||||
|
LLMProviders.MISTRAL => "https://console.mistral.ai/",
|
||||||
|
LLMProviders.ANTHROPIC => "https://console.anthropic.com/dashboard",
|
||||||
|
LLMProviders.GOOGLE => "https://console.cloud.google.com/",
|
||||||
|
|
||||||
|
LLMProviders.GROQ => "https://console.groq.com/",
|
||||||
|
LLMProviders.FIREWORKS => "https://fireworks.ai/login",
|
||||||
|
|
||||||
|
_ => string.Empty,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static string GetModelsOverviewURL(this LLMProviders provider) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.FIREWORKS => "https://fireworks.ai/models?show=Serverless",
|
||||||
|
_ => string.Empty,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool IsLLMModelProvidedManually(this LLMProviders provider) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.FIREWORKS => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool IsEmbeddingModelProvidedManually(this LLMProviders provider) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.SELF_HOSTED => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool IsHostNeeded(this LLMProviders provider) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.SELF_HOSTED => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool IsHostnameNeeded(this LLMProviders provider) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.SELF_HOSTED => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool IsAPIKeyNeeded(this LLMProviders provider, Host host) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.OPEN_AI => true,
|
||||||
|
LLMProviders.MISTRAL => true,
|
||||||
|
LLMProviders.ANTHROPIC => true,
|
||||||
|
LLMProviders.GOOGLE => true,
|
||||||
|
|
||||||
|
LLMProviders.GROQ => true,
|
||||||
|
LLMProviders.FIREWORKS => true,
|
||||||
|
|
||||||
|
LLMProviders.SELF_HOSTED => host is Host.OLLAMA,
|
||||||
|
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool ShowRegisterButton(this LLMProviders provider) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.OPEN_AI => true,
|
||||||
|
LLMProviders.MISTRAL => true,
|
||||||
|
LLMProviders.ANTHROPIC => true,
|
||||||
|
LLMProviders.GOOGLE => true,
|
||||||
|
|
||||||
|
LLMProviders.GROQ => true,
|
||||||
|
LLMProviders.FIREWORKS => true,
|
||||||
|
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool CanLoadModels(this LLMProviders provider, Host host, string? apiKey)
|
||||||
|
{
|
||||||
|
if (provider is LLMProviders.SELF_HOSTED)
|
||||||
|
{
|
||||||
|
switch (host)
|
||||||
|
{
|
||||||
|
case Host.NONE:
|
||||||
|
case Host.LLAMACPP:
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case Host.OLLAMA:
|
||||||
|
case Host.LM_STUDIO:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(provider is LLMProviders.NONE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(string.IsNullOrWhiteSpace(apiKey))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user