From 74fa1d14a6334eef436cfe1310fe400968389d70 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peer=20Sch=C3=BCtt?=
<20603780+peerschuett@users.noreply.github.com>
Date: Fri, 11 Apr 2025 10:43:13 +0200
Subject: [PATCH] Hugging Face works now
---
app/MindWork AI Studio.sln.DotSettings | 3 ++
.../Settings/SettingsPanelProviders.razor.cs | 1 +
.../Dialogs/ProviderDialog.razor | 12 +++++-
.../Dialogs/ProviderDialog.razor.cs | 14 ++++--
app/MindWork AI Studio/Provider/Confidence.cs | 6 +--
.../HuggingFace/HFInstanceProvider.cs | 18 ++++++++
.../HFInstanceProviderExtensions.cs | 43 +++++++++++++++++++
.../HuggingFace/ProviderHuggingFace.cs | 7 ++-
.../Provider/LLMProvidersExtensions.cs | 24 +++++++----
app/MindWork AI Studio/Settings/Provider.cs | 5 ++-
.../Tools/Validation/ProviderValidation.cs | 13 +++++-
11 files changed, 125 insertions(+), 21 deletions(-)
create mode 100644 app/MindWork AI Studio/Provider/HuggingFace/HFInstanceProvider.cs
create mode 100644 app/MindWork AI Studio/Provider/HuggingFace/HFInstanceProviderExtensions.cs
diff --git a/app/MindWork AI Studio.sln.DotSettings b/app/MindWork AI Studio.sln.DotSettings
index 44079898..6cbaf40c 100644
--- a/app/MindWork AI Studio.sln.DotSettings
+++ b/app/MindWork AI Studio.sln.DotSettings
@@ -3,14 +3,17 @@
EDI
ERI
GWDG
+ HF
LLM
LM
MSG
RAG
UI
+ URL
True
True
True
+ True
True
True
True
\ No newline at end of file
diff --git a/app/MindWork AI Studio/Components/Settings/SettingsPanelProviders.razor.cs b/app/MindWork AI Studio/Components/Settings/SettingsPanelProviders.razor.cs
index 6ca2f6ca..5a71925b 100644
--- a/app/MindWork AI Studio/Components/Settings/SettingsPanelProviders.razor.cs
+++ b/app/MindWork AI Studio/Components/Settings/SettingsPanelProviders.razor.cs
@@ -65,6 +65,7 @@ public partial class SettingsPanelProviders : SettingsPanelBase
{ x => x.IsSelfHosted, provider.IsSelfHosted },
{ x => x.IsEditing, true },
{ x => x.DataHost, provider.Host },
+ { x => x.HfInstanceProviderId, provider.HFInstanceProvider },
};
var dialogReference = await this.DialogService.ShowAsync("Edit LLM Provider", dialogParameters, DialogOptions.FULLSCREEN);
diff --git a/app/MindWork AI Studio/Dialogs/ProviderDialog.razor b/app/MindWork AI Studio/Dialogs/ProviderDialog.razor
index 108f7375..240bfff4 100644
--- a/app/MindWork AI Studio/Dialogs/ProviderDialog.razor
+++ b/app/MindWork AI Studio/Dialogs/ProviderDialog.razor
@@ -1,4 +1,5 @@
@using AIStudio.Provider
+@using AIStudio.Provider.HuggingFace
@using AIStudio.Provider.SelfHosted
@@ -48,11 +49,18 @@
@host.Name()
}
-
+
+
+ @foreach (HFInstanceProvider instanceProvider in Enum.GetValues(typeof(HFInstanceProvider)))
+ {
+ @instanceProvider.ToName()
+ }
+
+
@if (this.DataLLMProvider.IsLLMModelProvidedManually())
{
- Show available models
+ Show available models
+ /// The HFInstanceProvider to use, e.g., CEREBRAS.
+ ///
+ [Parameter]
+ public HFInstanceProvider HfInstanceProviderId { get; set; } = HFInstanceProvider.NONE;
+
///
/// Is this provider self-hosted?
///
@@ -131,6 +138,7 @@ public partial class ProviderDialog : ComponentBase, ISecretId
IsSelfHosted = this.DataLLMProvider is LLMProviders.SELF_HOSTED,
Hostname = cleanedHostname.EndsWith('/') ? cleanedHostname[..^1] : cleanedHostname,
Host = this.DataHost,
+ HFInstanceProvider = this.HfInstanceProviderId,
};
}
@@ -151,8 +159,8 @@ public partial class ProviderDialog : ComponentBase, ISecretId
{
this.dataEditingPreviousInstanceName = this.DataInstanceName.ToLowerInvariant();
- // When using Fireworks, we must copy the model name:
- if (this.DataLLMProvider is LLMProviders.FIREWORKS)
+ // When using Fireworks or Hugging Face, we must copy the model name:
+ if (this.DataLLMProvider is LLMProviders.FIREWORKS or LLMProviders.HUGGINGFACE)
this.dataManuallyModel = this.DataModel.Id;
//
@@ -235,7 +243,7 @@ public partial class ProviderDialog : ComponentBase, ISecretId
private string? ValidateManuallyModel(string manuallyModel)
{
- if (this.DataLLMProvider is LLMProviders.FIREWORKS && string.IsNullOrWhiteSpace(manuallyModel))
+ if ((this.DataLLMProvider is LLMProviders.FIREWORKS or LLMProviders.HUGGINGFACE) && string.IsNullOrWhiteSpace(manuallyModel))
return "Please enter a model name.";
return null;
diff --git a/app/MindWork AI Studio/Provider/Confidence.cs b/app/MindWork AI Studio/Provider/Confidence.cs
index 087ac4e0..a49c2781 100644
--- a/app/MindWork AI Studio/Provider/Confidence.cs
+++ b/app/MindWork AI Studio/Provider/Confidence.cs
@@ -35,10 +35,10 @@ public sealed record Confidence
""",
};
- public static readonly Confidence USA_NOT_TRUSTED = new()
+ public static readonly Confidence USA_HUB = new()
{
- Level = ConfidenceLevel.UNTRUSTED,
- Description = "The provider operates its service from the USA and is subject to **U.S. jurisdiction**. In case of suspicion, authorities in the USA can access your data. The provider's terms of service state that **all your data can be used by the provider at will.**",
+ Level = ConfidenceLevel.UNKNOWN,
+ Description = "The provider operates its service from the USA and is subject to **U.S. jurisdiction**. In case of suspicion, authorities in the USA can access your data. Please inform yourself about the use of your data. We do not know if your data is safe.",
};
public static readonly Confidence UNKNOWN = new()
diff --git a/app/MindWork AI Studio/Provider/HuggingFace/HFInstanceProvider.cs b/app/MindWork AI Studio/Provider/HuggingFace/HFInstanceProvider.cs
new file mode 100644
index 00000000..63221290
--- /dev/null
+++ b/app/MindWork AI Studio/Provider/HuggingFace/HFInstanceProvider.cs
@@ -0,0 +1,18 @@
+namespace AIStudio.Provider.HuggingFace;
+
+///
+/// Enum for instance providers that Hugging Face supports.
+///
+public enum HFInstanceProvider
+{
+ NONE,
+
+ CEREBRAS,
+ NEBIUS_AI_STUDIO,
+ SAMBANOVA,
+ NOVITA,
+ HYPERBOLIC,
+ TOGETHER_AI,
+ FIREWORKS,
+ HF_INFERENCE_API,
+}
\ No newline at end of file
diff --git a/app/MindWork AI Studio/Provider/HuggingFace/HFInstanceProviderExtensions.cs b/app/MindWork AI Studio/Provider/HuggingFace/HFInstanceProviderExtensions.cs
new file mode 100644
index 00000000..b0d81fba
--- /dev/null
+++ b/app/MindWork AI Studio/Provider/HuggingFace/HFInstanceProviderExtensions.cs
@@ -0,0 +1,43 @@
+namespace AIStudio.Provider.HuggingFace;
+
+public static class HFInstanceProviderExtensions
+{
+ public static string Endpoints(this HFInstanceProvider provider, Model model) => provider switch
+ {
+ HFInstanceProvider.CEREBRAS => "cerebras/v1/",
+ HFInstanceProvider.NEBIUS_AI_STUDIO => "nebius/v1/",
+ HFInstanceProvider.SAMBANOVA => "sambanova/v1/",
+ HFInstanceProvider.NOVITA => "novita/v3/openai/",
+ HFInstanceProvider.HYPERBOLIC => "hyperbolic/v1/",
+ HFInstanceProvider.TOGETHER_AI => "together/v1/",
+ HFInstanceProvider.FIREWORKS => "fireworks-ai/inference/v1/",
+ HFInstanceProvider.HF_INFERENCE_API => $"hf-inference/models/{model.ToString()}/v1/",
+ _ => string.Empty,
+ };
+
+ public static string EndpointsId(this HFInstanceProvider provider) => provider switch
+ {
+ HFInstanceProvider.CEREBRAS => "cerebras",
+ HFInstanceProvider.NEBIUS_AI_STUDIO => "nebius",
+ HFInstanceProvider.SAMBANOVA => "sambanova",
+ HFInstanceProvider.NOVITA => "novita",
+ HFInstanceProvider.HYPERBOLIC => "hyperbolic",
+ HFInstanceProvider.TOGETHER_AI => "together",
+ HFInstanceProvider.FIREWORKS => "fireworks",
+ HFInstanceProvider.HF_INFERENCE_API => "hf-inference",
+ _ => string.Empty,
+ };
+
+ public static string ToName(this HFInstanceProvider provider) => provider switch
+ {
+ HFInstanceProvider.CEREBRAS => "Cerebras",
+ HFInstanceProvider.NEBIUS_AI_STUDIO => "Nebius AI Studio",
+ HFInstanceProvider.SAMBANOVA => "Sambanova",
+ HFInstanceProvider.NOVITA => "Novita",
+ HFInstanceProvider.HYPERBOLIC => "Hyperbolic",
+ HFInstanceProvider.TOGETHER_AI => "Together AI",
+ HFInstanceProvider.FIREWORKS => "Fireworks AI",
+ HFInstanceProvider.HF_INFERENCE_API => "Hugging Face Inference API",
+ _ => string.Empty,
+ };
+}
\ No newline at end of file
diff --git a/app/MindWork AI Studio/Provider/HuggingFace/ProviderHuggingFace.cs b/app/MindWork AI Studio/Provider/HuggingFace/ProviderHuggingFace.cs
index 298754fc..25f2baae 100644
--- a/app/MindWork AI Studio/Provider/HuggingFace/ProviderHuggingFace.cs
+++ b/app/MindWork AI Studio/Provider/HuggingFace/ProviderHuggingFace.cs
@@ -9,8 +9,13 @@ using AIStudio.Settings;
namespace AIStudio.Provider.HuggingFace;
-public sealed class ProviderHuggingFace(ILogger logger) : BaseProvider($"https://router.huggingface.co/nebius/v1/", logger)
+public sealed class ProviderHuggingFace : BaseProvider
{
+ public ProviderHuggingFace(ILogger logger, HFInstanceProvider hfProvider, Model model) : base($"https://router.huggingface.co/{hfProvider.Endpoints(model)}", logger)
+ {
+ logger.LogInformation($"We use the instance provider '{hfProvider}'. Thus we use the base URL 'https://router.huggingface.co/{hfProvider.Endpoints(model)}'.");
+ }
+
#region Implementation of IProvider
///
diff --git a/app/MindWork AI Studio/Provider/LLMProvidersExtensions.cs b/app/MindWork AI Studio/Provider/LLMProvidersExtensions.cs
index 3a2a69d8..8abb0bd4 100644
--- a/app/MindWork AI Studio/Provider/LLMProvidersExtensions.cs
+++ b/app/MindWork AI Studio/Provider/LLMProvidersExtensions.cs
@@ -34,7 +34,7 @@ public static class LLMProvidersExtensions
LLMProviders.GOOGLE => "Google",
LLMProviders.X => "xAI",
LLMProviders.DEEP_SEEK => "DeepSeek",
- LLMProviders.ALIBABA_CLOUD => "ALIBABA_CLOUD",
+ LLMProviders.ALIBABA_CLOUD => "Alibaba Cloud",
LLMProviders.GROQ => "Groq",
LLMProviders.FIREWORKS => "Fireworks.ai",
@@ -58,10 +58,10 @@ public static class LLMProvidersExtensions
{
LLMProviders.NONE => Confidence.NONE,
- LLMProviders.FIREWORKS => Confidence.USA_NOT_TRUSTED.WithRegion("America, U.S.").WithSources("https://fireworks.ai/terms-of-service").WithLevel(settingsManager.GetConfiguredConfidenceLevel(llmProvider)),
+ LLMProviders.FIREWORKS => Confidence.USA_HUB.WithRegion("America, U.S.").WithSources("https://fireworks.ai/terms-of-service").WithLevel(settingsManager.GetConfiguredConfidenceLevel(llmProvider)),
// Not trusted, because huggingface only routes you to a third-party-provider and we can't make sure they do not use your data
- LLMProviders.HUGGINGFACE => Confidence.USA_NOT_TRUSTED.WithRegion("America, U.S.").WithSources("https://huggingface.co/terms-of-service").WithLevel(settingsManager.GetConfiguredConfidenceLevel(llmProvider)),
+ LLMProviders.HUGGINGFACE => Confidence.USA_HUB.WithRegion("America, U.S.").WithSources("https://huggingface.co/terms-of-service").WithLevel(settingsManager.GetConfiguredConfidenceLevel(llmProvider)),
LLMProviders.OPEN_AI => Confidence.USA_NO_TRAINING.WithRegion("America, U.S.").WithSources(
"https://platform.openai.com/docs/models/default-usage-policies-by-endpoint",
@@ -135,7 +135,7 @@ public static class LLMProvidersExtensions
/// The provider instance.
public static IProvider CreateProvider(this AIStudio.Settings.Provider providerSettings, ILogger logger)
{
- return providerSettings.UsedLLMProvider.CreateProvider(providerSettings.InstanceName, providerSettings.Host, providerSettings.Hostname, logger);
+ return providerSettings.UsedLLMProvider.CreateProvider(providerSettings.InstanceName, providerSettings.Host, providerSettings.Hostname, providerSettings.Model, providerSettings.HFInstanceProvider ,logger);
}
///
@@ -146,10 +146,10 @@ public static class LLMProvidersExtensions
/// The provider instance.
public static IProvider CreateProvider(this EmbeddingProvider embeddingProviderSettings, ILogger logger)
{
- return embeddingProviderSettings.UsedLLMProvider.CreateProvider(embeddingProviderSettings.Name, embeddingProviderSettings.Host, embeddingProviderSettings.Hostname, logger);
+ return embeddingProviderSettings.UsedLLMProvider.CreateProvider(embeddingProviderSettings.Name, embeddingProviderSettings.Host, embeddingProviderSettings.Hostname, embeddingProviderSettings.Model, HFInstanceProvider.NONE,logger);
}
- private static IProvider CreateProvider(this LLMProviders provider, string instanceName, Host host, string hostname, ILogger logger)
+ private static IProvider CreateProvider(this LLMProviders provider, string instanceName, Host host, string hostname, Model model, HFInstanceProvider instanceProvider , ILogger logger)
{
try
{
@@ -165,7 +165,7 @@ public static class LLMProvidersExtensions
LLMProviders.GROQ => new ProviderGroq(logger) { InstanceName = instanceName },
LLMProviders.FIREWORKS => new ProviderFireworks(logger) { InstanceName = instanceName },
- LLMProviders.HUGGINGFACE => new ProviderHuggingFace(logger) { InstanceName = instanceName },
+ LLMProviders.HUGGINGFACE => new ProviderHuggingFace(logger, instanceProvider, model) { InstanceName = instanceName },
LLMProviders.SELF_HOSTED => new ProviderSelfHosted(logger, host, hostname) { InstanceName = instanceName },
@@ -234,10 +234,10 @@ public static class LLMProvidersExtensions
_ => false,
};
- public static string GetModelsOverviewURL(this LLMProviders provider) => provider switch
+ public static string GetModelsOverviewURL(this LLMProviders provider, HFInstanceProvider instanceProvider) => provider switch
{
LLMProviders.FIREWORKS => "https://fireworks.ai/models?show=Serverless",
- LLMProviders.HUGGINGFACE => "https://huggingface.co/models?inference_provider=all",
+ LLMProviders.HUGGINGFACE => $"https://huggingface.co/models?inference_provider={instanceProvider.EndpointsId()}",
_ => string.Empty,
};
@@ -331,4 +331,10 @@ public static class LLMProvidersExtensions
return true;
}
+
+ public static bool IsHFInstanceProviderNeeded(this LLMProviders provider) => provider switch
+ {
+ LLMProviders.HUGGINGFACE => true,
+ _ => false,
+ };
}
\ No newline at end of file
diff --git a/app/MindWork AI Studio/Settings/Provider.cs b/app/MindWork AI Studio/Settings/Provider.cs
index b349016d..6aefc5b5 100644
--- a/app/MindWork AI Studio/Settings/Provider.cs
+++ b/app/MindWork AI Studio/Settings/Provider.cs
@@ -1,7 +1,7 @@
using System.Text.Json.Serialization;
using AIStudio.Provider;
-
+using AIStudio.Provider.HuggingFace;
using Host = AIStudio.Provider.SelfHosted.Host;
namespace AIStudio.Settings;
@@ -24,7 +24,8 @@ public readonly record struct Provider(
Model Model,
bool IsSelfHosted = false,
string Hostname = "http://localhost:1234",
- Host Host = Host.NONE) : ISecretId
+ Host Host = Host.NONE,
+ HFInstanceProvider HFInstanceProvider = HFInstanceProvider.NONE) : ISecretId
{
#region Overrides of ValueType
diff --git a/app/MindWork AI Studio/Tools/Validation/ProviderValidation.cs b/app/MindWork AI Studio/Tools/Validation/ProviderValidation.cs
index be7b16be..12d27b43 100644
--- a/app/MindWork AI Studio/Tools/Validation/ProviderValidation.cs
+++ b/app/MindWork AI Studio/Tools/Validation/ProviderValidation.cs
@@ -1,5 +1,5 @@
using AIStudio.Provider;
-
+using AIStudio.Provider.HuggingFace;
using Host = AIStudio.Provider.SelfHosted.Host;
namespace AIStudio.Tools.Validation;
@@ -93,4 +93,15 @@ public sealed class ProviderValidation
return null;
}
+
+ public string? ValidatingHFInstanceProvider(HFInstanceProvider instanceProvider)
+ {
+ if(this.GetProvider() is not LLMProviders.HUGGINGFACE)
+ return null;
+
+ if (instanceProvider is HFInstanceProvider.NONE)
+ return "Please select an Hugging Face instance provider.";
+
+ return null;
+ }
}
\ No newline at end of file