Reworked the Hugging Face provider (#944)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-08-30 16:45:14 +02:00
1 parent a7228c7782
commit f14c69b938
28 files changed
+1039 -93

No files matched your search

@@ -1,4 +1,5 @@
@using AIStudio.Provider
@using AIStudio.Provider.HuggingFace
@using AIStudio.Provider.SelfHosted
@inherits MSGComponentBase
@@ -64,6 +65,24 @@
</MudSelect>
}
@if (this.DataLLMProvider.IsHFInstanceProviderNeeded())
{
<MudSelect T="HFInferenceProvider" Value="@this.HFInferenceProviderId" ValueChanged="@this.OnHFInferenceProviderChanged" Label="@T("Hugging Face Inference Provider")" Class="mb-3" OpenIcon="@Icons.Material.Filled.Dns" AdornmentColor="Color.Info" Adornment="Adornment.Start" Disabled="@this.IsEnterpriseConfiguration" Validation="@this.providerValidation.ValidatingHFInstanceProviderForEmbeddings">
@foreach (HFInferenceProvider inferenceProvider in Enum.GetValues(typeof(HFInferenceProvider)))
{
@if (inferenceProvider.SupportsEmbeddings())
{
<MudSelectItem Value="@inferenceProvider">
@inferenceProvider.ToName()
</MudSelectItem>
}
}
</MudSelect>
<MudJustifiedText Class="mb-3">
@T("Hugging Face offers embeddings through a few of its inference providers only, which is why this list is shorter than the one for chatting.")
</MudJustifiedText>
}
<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))
@@ -1,5 +1,6 @@
using AIStudio.Components;
using AIStudio.Provider;
using AIStudio.Provider.HuggingFace;
using AIStudio.Settings;
using AIStudio.Tools.Services;
using AIStudio.Tools.Validation;
@@ -68,6 +69,12 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
/// </summary>
[Parameter]
public Model DataModel { get; set; }
/// <summary>
/// The Hugging Face inference provider to use.
/// </summary>
[Parameter]
public HFInferenceProvider HFInferenceProviderId { get; set; } = HFInferenceProvider.NONE;
/// <summary>
/// Should the dialog be in editing mode?
@@ -151,6 +158,7 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
IsEnterpriseConfiguration = this.IsEnterpriseConfiguration,
EnterpriseConfigurationPluginId = Guid.Empty,
CustomIconDataUrl = this.DataCustomIconDataUrl,
HFInferenceProvider = this.HFInferenceProviderId,
};
}
@@ -316,6 +324,22 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
this.dataLoadingModelsIssue = string.Empty;
}
/// <summary>
/// Resets the model selection when the user picks another Hugging Face inference provider.
/// </summary>
/// <remarks>
/// Each inference provider offers embedding models of its own, so the models loaded for the
/// previous one say nothing about the new one.
/// </remarks>
/// <param name="selectedInferenceProvider">The inference provider the user chose.</param>
private void OnHFInferenceProviderChanged(HFInferenceProvider selectedInferenceProvider)
{
this.HFInferenceProviderId = selectedInferenceProvider;
this.DataModel = default;
this.availableModels.Clear();
this.dataLoadingModelsIssue = string.Empty;
}
private async Task ReloadModels()
{
this.dataLoadingModelsIssue = string.Empty;
@@ -69,19 +69,20 @@
@if (this.DataLLMProvider.IsHFInstanceProviderNeeded())
{
<MudSelect @bind-Value="@this.HFInferenceProviderId" Label="@T("Hugging Face Inference Provider")" Class="mb-3" OpenIcon="@Icons.Material.Filled.Dns" AdornmentColor="Color.Info" Adornment="Adornment.Start" Disabled="@this.IsEnterpriseConfiguration" Validation="@this.providerValidation.ValidatingHFInstanceProvider">
<MudSelect T="HFInferenceProvider" Value="@this.HFInferenceProviderId" ValueChanged="@this.OnHFInferenceProviderChanged" Label="@T("Hugging Face Inference Provider")" Class="mb-3" OpenIcon="@Icons.Material.Filled.Dns" AdornmentColor="Color.Info" Adornment="Adornment.Start" Disabled="@this.IsEnterpriseConfiguration" Validation="@this.providerValidation.ValidatingHFInstanceProvider">
@foreach (HFInferenceProvider inferenceProvider in Enum.GetValues(typeof(HFInferenceProvider)))
{
<MudSelectItem Value="@inferenceProvider">
@inferenceProvider.ToName()
</MudSelectItem>
}
@if (inferenceProvider.SupportsChat())
{
<MudSelectItem Value="@inferenceProvider">
@inferenceProvider.ToName()
</MudSelectItem>
}
}
</MudSelect>
@* ReSharper disable Asp.Entity *@
<MudJustifiedText Class="mb-3">
Please double-check if your model name matches the curl specifications provided by the inference provider. If it doesn't, you might get a <b>Not Found</b> error when trying to use the model. Here's a <MudLink Href="https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct?inference_api=true&inference_provider=novita&language=sh" Target="_blank">curl example</MudLink>.
@T("Choose which inference provider should answer your requests. When you pick one of the automatic options instead, Hugging Face selects a provider for you and switches to another one when your choice is unavailable.")
</MudJustifiedText>
@* ReSharper restore Asp.Entity *@
}
@if (!this.IsLLMModelSelectionHidden)
@@ -90,7 +91,7 @@
<MudStack Row="@true" AlignItems="AlignItems.Center" StretchItems="StretchItems.End">
@if (this.DataLLMProvider.IsLLMModelProvidedManually())
{
<MudButton Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.DataLLMProvider.GetModelsOverviewURL(this.HFInferenceProviderId)" Target="_blank">
<MudButton Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.ModelsOverviewURL" Target="_blank">
@T("Show available models")
</MudButton>
<MudTextField
@@ -108,6 +109,12 @@
}
else
{
@if (!string.IsNullOrWhiteSpace(this.ModelsOverviewURL))
{
<MudButton Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.ModelsOverviewURL" Target="_blank">
@T("Show available models")
</MudButton>
}
<MudButton Disabled="@(this.IsEnterpriseConfiguration || !this.DataLLMProvider.CanLoadModels(this.DataHost, this.dataAPIKey))" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Refresh" OnClick="@this.ReloadModels">
@T("Load models")
</MudButton>
@@ -226,7 +226,7 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
{
this.dataEditingPreviousInstanceName = this.DataInstanceName.ToLowerInvariant();
// When using Fireworks or Hugging Face, we must copy the model name:
// When using Fireworks, we must copy the model name:
if (this.DataLLMProvider.IsLLMModelProvidedManually())
this.dataManuallyModel = this.DataModel.Id;
@@ -372,6 +372,24 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
this.usesLegacySystemModelFallback = false;
}
/// <summary>
/// Resets the model selection when the user picks another Hugging Face inference provider.
/// </summary>
/// <remarks>
/// Which models are on offer depends on the inference provider, so the models loaded for the
/// previous one say nothing about the new one. Keeping them would let the user pick a model
/// their provider does not serve, which the router answers with an error.
/// </remarks>
/// <param name="selectedInferenceProvider">The inference provider the user chose.</param>
private void OnHFInferenceProviderChanged(HFInferenceProvider selectedInferenceProvider)
{
this.HFInferenceProviderId = selectedInferenceProvider;
this.DataModel = default;
this.capabilityOverrides = new();
this.availableModels.Clear();
this.dataLoadingModelsIssue = string.Empty;
}
private void OnHostChanged(Host selectedHost)
{
// When the host changes, reset the model selection state:
@@ -430,6 +448,11 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
this.DataHost is Host.LLAMA_CPP &&
this.usesLegacySystemModelFallback;
/// <summary>
/// The catalog of the provider, where the user can read up on the models before choosing one.
/// </summary>
private string ModelsOverviewURL => this.DataLLMProvider.GetModelsOverviewURL(this.HFInferenceProviderId);
private void UpdateModelSelectionAfterLoading()
{
if (this.DataLLMProvider is not LLMProviders.SELF_HOSTED || this.DataHost is not Host.LLAMA_CPP)
@@ -1,4 +1,5 @@
@using AIStudio.Provider
@using AIStudio.Provider.HuggingFace
@using AIStudio.Provider.SelfHosted
@inherits MSGComponentBase
@@ -64,6 +65,24 @@
</MudSelect>
}
@if (this.DataLLMProvider.IsHFInstanceProviderNeeded())
{
<MudSelect T="HFInferenceProvider" Value="@this.HFInferenceProviderId" ValueChanged="@this.OnHFInferenceProviderChanged" Label="@T("Hugging Face Inference Provider")" Class="mb-3" OpenIcon="@Icons.Material.Filled.Dns" AdornmentColor="Color.Info" Adornment="Adornment.Start" Disabled="@this.IsEnterpriseConfiguration" Validation="@this.providerValidation.ValidatingHFInstanceProviderForTranscription">
@foreach (HFInferenceProvider inferenceProvider in Enum.GetValues(typeof(HFInferenceProvider)))
{
@if (inferenceProvider.SupportsTranscription())
{
<MudSelectItem Value="@inferenceProvider">
@inferenceProvider.ToName()
</MudSelectItem>
}
}
</MudSelect>
<MudJustifiedText Class="mb-3">
@T("Hugging Face transcribes audio through a few of its inference providers only, which is why this list is shorter than the one for chatting.")
</MudJustifiedText>
}
@if (!this.DataLLMProvider.IsTranscriptionModelSelectionHidden(this.DataHost))
{
<MudField FullWidth="true" Label="@T("Model selection")" Variant="Variant.Outlined" Class="mb-3">
@@ -1,5 +1,6 @@
using AIStudio.Components;
using AIStudio.Provider;
using AIStudio.Provider.HuggingFace;
using AIStudio.Settings;
using AIStudio.Tools.Services;
using AIStudio.Tools.Validation;
@@ -68,6 +69,12 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
/// </summary>
[Parameter]
public Model DataModel { get; set; }
/// <summary>
/// The Hugging Face inference provider to use.
/// </summary>
[Parameter]
public HFInferenceProvider HFInferenceProviderId { get; set; } = HFInferenceProvider.NONE;
/// <summary>
/// Should the dialog be in editing mode?
@@ -166,6 +173,7 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
IsEnterpriseConfiguration = this.IsEnterpriseConfiguration,
EnterpriseConfigurationPluginId = Guid.Empty,
CustomIconDataUrl = this.DataCustomIconDataUrl,
HFInferenceProvider = this.HFInferenceProviderId,
};
}
@@ -331,6 +339,22 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
this.dataLoadingModelsIssue = string.Empty;
}
/// <summary>
/// Resets the model selection when the user picks another Hugging Face inference provider.
/// </summary>
/// <remarks>
/// Each inference provider offers transcription models of its own, so the models loaded for the
/// previous one say nothing about the new one.
/// </remarks>
/// <param name="selectedInferenceProvider">The inference provider the user chose.</param>
private void OnHFInferenceProviderChanged(HFInferenceProvider selectedInferenceProvider)
{
this.HFInferenceProviderId = selectedInferenceProvider;
this.DataModel = default;
this.availableModels.Clear();
this.dataLoadingModelsIssue = string.Empty;
}
private async Task ReloadModels()
{
this.dataLoadingModelsIssue = string.Empty;