mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-27 22:59:47 +00:00
Added Hugging Face inference provider (#397)
Some checks are pending
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, deb) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Some checks are pending
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, deb) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
This commit is contained in:
parent
712ed2938f
commit
1ff27fe21f
@ -3,14 +3,17 @@
|
|||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EDI/@EntryIndexedValue">EDI</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EDI/@EntryIndexedValue">EDI</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ERI/@EntryIndexedValue">ERI</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ERI/@EntryIndexedValue">ERI</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GWDG/@EntryIndexedValue">GWDG</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GWDG/@EntryIndexedValue">GWDG</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HF/@EntryIndexedValue">HF</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LLM/@EntryIndexedValue">LLM</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LLM/@EntryIndexedValue">LLM</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LM/@EntryIndexedValue">LM</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LM/@EntryIndexedValue">LM</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSG/@EntryIndexedValue">MSG</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSG/@EntryIndexedValue">MSG</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RAG/@EntryIndexedValue">RAG</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RAG/@EntryIndexedValue">RAG</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=URL/@EntryIndexedValue">URL</s:String>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=agentic/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=agentic/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=groq/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=groq/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=gwdg/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=gwdg/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=huggingface/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=mwais/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=mwais/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ollama/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=ollama/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=tauri_0027s/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=tauri_0027s/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -29,7 +29,7 @@
|
|||||||
<RowTemplate>
|
<RowTemplate>
|
||||||
<MudTd>@context.Num</MudTd>
|
<MudTd>@context.Num</MudTd>
|
||||||
<MudTd>@context.InstanceName</MudTd>
|
<MudTd>@context.InstanceName</MudTd>
|
||||||
<MudTd>@context.UsedLLMProvider</MudTd>
|
<MudTd>@context.UsedLLMProvider.ToName()</MudTd>
|
||||||
<MudTd>
|
<MudTd>
|
||||||
@if (context.UsedLLMProvider is not LLMProviders.SELF_HOSTED)
|
@if (context.UsedLLMProvider is not LLMProviders.SELF_HOSTED)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,7 @@ public partial class SettingsPanelProviders : SettingsPanelBase
|
|||||||
{ x => x.IsSelfHosted, provider.IsSelfHosted },
|
{ x => x.IsSelfHosted, provider.IsSelfHosted },
|
||||||
{ x => x.IsEditing, true },
|
{ x => x.IsEditing, true },
|
||||||
{ x => x.DataHost, provider.Host },
|
{ x => x.DataHost, provider.Host },
|
||||||
|
{ x => x.HfInstanceProviderId, provider.HFInstanceProvider },
|
||||||
};
|
};
|
||||||
|
|
||||||
var dialogReference = await this.DialogService.ShowAsync<ProviderDialog>("Edit LLM Provider", dialogParameters, DialogOptions.FULLSCREEN);
|
var dialogReference = await this.DialogService.ShowAsync<ProviderDialog>("Edit LLM Provider", dialogParameters, DialogOptions.FULLSCREEN);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
@using AIStudio.Provider
|
@using AIStudio.Provider
|
||||||
|
@using AIStudio.Provider.HuggingFace
|
||||||
@using AIStudio.Provider.SelfHosted
|
@using AIStudio.Provider.SelfHosted
|
||||||
|
|
||||||
<MudDialog>
|
<MudDialog>
|
||||||
@ -29,6 +30,8 @@
|
|||||||
Validation="@this.providerValidation.ValidatingAPIKey"
|
Validation="@this.providerValidation.ValidatingAPIKey"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@if (this.DataLLMProvider.IsHostnameNeeded())
|
||||||
|
{
|
||||||
<MudTextField
|
<MudTextField
|
||||||
T="string"
|
T="string"
|
||||||
@bind-Text="@this.DataHostname"
|
@bind-Text="@this.DataHostname"
|
||||||
@ -39,27 +42,42 @@
|
|||||||
AdornmentIcon="@Icons.Material.Filled.Dns"
|
AdornmentIcon="@Icons.Material.Filled.Dns"
|
||||||
AdornmentColor="Color.Info"
|
AdornmentColor="Color.Info"
|
||||||
Validation="@this.providerValidation.ValidatingHostname"
|
Validation="@this.providerValidation.ValidatingHostname"
|
||||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
UserAttributes="@SPELLCHECK_ATTRIBUTES"/>
|
||||||
/>
|
}
|
||||||
|
|
||||||
|
@if (this.DataLLMProvider.IsHostNeeded())
|
||||||
|
{
|
||||||
<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.providerValidation.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.providerValidation.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>
|
||||||
}
|
}
|
||||||
</MudSelect>
|
</MudSelect>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (this.DataLLMProvider.IsHFInstanceProviderNeeded())
|
||||||
|
{
|
||||||
|
<MudSelect Disabled="@(!this.DataLLMProvider.IsHFInstanceProviderNeeded())" @bind-Value="@this.HfInstanceProviderId" Label="HF Instance Provider" Class="mb-3" OpenIcon="@Icons.Material.Filled.Dns" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.providerValidation.ValidatingHFInstanceProvider">
|
||||||
|
@foreach (HFInstanceProvider instanceProvider in Enum.GetValues(typeof(HFInstanceProvider)))
|
||||||
|
{
|
||||||
|
<MudSelectItem Value="@instanceProvider">@instanceProvider.ToName()</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
|
||||||
|
<MudJustifiedText Class="mb-3"> Please double-check if your model name matches the curl specifications provided by the instance 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>.</MudJustifiedText>
|
||||||
|
}
|
||||||
|
|
||||||
<MudStack Row="@true" AlignItems="AlignItems.Center">
|
<MudStack Row="@true" AlignItems="AlignItems.Center">
|
||||||
@if (this.DataLLMProvider.IsLLMModelProvidedManually())
|
@if (this.DataLLMProvider.IsLLMModelProvidedManually())
|
||||||
{
|
{
|
||||||
<MudButton Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.DataLLMProvider.GetModelsOverviewURL()" Target="_blank">Show available models</MudButton>
|
<MudButton Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@this.DataLLMProvider.GetModelsOverviewURL(this.HfInstanceProviderId)" Target="_blank">Show available models</MudButton>
|
||||||
<MudTextField
|
<MudTextField
|
||||||
T="string"
|
T="string"
|
||||||
@bind-Text="@this.dataManuallyModel"
|
@bind-Text="@this.dataManuallyModel"
|
||||||
Label="Model"
|
Label="Model"
|
||||||
Class="mb-3"
|
Class="mb-3"
|
||||||
Adornment="Adornment.Start"
|
Adornment="Adornment.Start"
|
||||||
AdornmentIcon="@Icons.Material.Filled.Dns"
|
AdornmentIcon="@Icons.Material.Filled.FaceRetouchingNatural"
|
||||||
AdornmentColor="Color.Info"
|
AdornmentColor="Color.Info"
|
||||||
Validation="@this.ValidateManuallyModel"
|
Validation="@this.ValidateManuallyModel"
|
||||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using AIStudio.Provider;
|
using AIStudio.Provider;
|
||||||
|
using AIStudio.Provider.HuggingFace;
|
||||||
using AIStudio.Settings;
|
using AIStudio.Settings;
|
||||||
using AIStudio.Tools.Services;
|
using AIStudio.Tools.Services;
|
||||||
using AIStudio.Tools.Validation;
|
using AIStudio.Tools.Validation;
|
||||||
@ -47,6 +48,12 @@ public partial class ProviderDialog : ComponentBase, ISecretId
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public Host DataHost { get; set; } = Host.NONE;
|
public Host DataHost { get; set; } = Host.NONE;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The HFInstanceProvider to use, e.g., CEREBRAS.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public HFInstanceProvider HfInstanceProviderId { get; set; } = HFInstanceProvider.NONE;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this provider self-hosted?
|
/// Is this provider self-hosted?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -122,10 +129,16 @@ public partial class ProviderDialog : ComponentBase, ISecretId
|
|||||||
Id = this.DataId,
|
Id = this.DataId,
|
||||||
InstanceName = this.DataInstanceName,
|
InstanceName = this.DataInstanceName,
|
||||||
UsedLLMProvider = this.DataLLMProvider,
|
UsedLLMProvider = this.DataLLMProvider,
|
||||||
Model = this.DataLLMProvider is LLMProviders.FIREWORKS ? new Model(this.dataManuallyModel, null) : this.DataModel,
|
Model = this.DataLLMProvider switch
|
||||||
|
{
|
||||||
|
LLMProviders.FIREWORKS => new Model(this.dataManuallyModel, null),
|
||||||
|
LLMProviders.HUGGINGFACE => new Model(this.dataManuallyModel, null),
|
||||||
|
_ => this.DataModel
|
||||||
|
},
|
||||||
IsSelfHosted = this.DataLLMProvider is LLMProviders.SELF_HOSTED,
|
IsSelfHosted = this.DataLLMProvider is LLMProviders.SELF_HOSTED,
|
||||||
Hostname = cleanedHostname.EndsWith('/') ? cleanedHostname[..^1] : cleanedHostname,
|
Hostname = cleanedHostname.EndsWith('/') ? cleanedHostname[..^1] : cleanedHostname,
|
||||||
Host = this.DataHost,
|
Host = this.DataHost,
|
||||||
|
HFInstanceProvider = this.HfInstanceProviderId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,8 +159,8 @@ public partial class ProviderDialog : ComponentBase, ISecretId
|
|||||||
{
|
{
|
||||||
this.dataEditingPreviousInstanceName = this.DataInstanceName.ToLowerInvariant();
|
this.dataEditingPreviousInstanceName = this.DataInstanceName.ToLowerInvariant();
|
||||||
|
|
||||||
// When using Fireworks, we must copy the model name:
|
// When using Fireworks or Hugging Face, we must copy the model name:
|
||||||
if (this.DataLLMProvider is LLMProviders.FIREWORKS)
|
if (this.DataLLMProvider is LLMProviders.FIREWORKS or LLMProviders.HUGGINGFACE)
|
||||||
this.dataManuallyModel = this.DataModel.Id;
|
this.dataManuallyModel = this.DataModel.Id;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -230,7 +243,7 @@ public partial class ProviderDialog : ComponentBase, ISecretId
|
|||||||
|
|
||||||
private string? ValidateManuallyModel(string manuallyModel)
|
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 "Please enter a model name.";
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -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,
|
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. The provider's terms of service state that **all your data can be used by the provider at will.**",
|
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()
|
public static readonly Confidence UNKNOWN = new()
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
namespace AIStudio.Provider.HuggingFace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enum for instance providers that Hugging Face supports.
|
||||||
|
/// </summary>
|
||||||
|
public enum HFInstanceProvider
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
|
||||||
|
CEREBRAS,
|
||||||
|
NEBIUS_AI_STUDIO,
|
||||||
|
SAMBANOVA,
|
||||||
|
NOVITA,
|
||||||
|
HYPERBOLIC,
|
||||||
|
TOGETHER_AI,
|
||||||
|
FIREWORKS,
|
||||||
|
HF_INFERENCE_API,
|
||||||
|
}
|
@ -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,
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
using AIStudio.Chat;
|
||||||
|
using AIStudio.Provider.OpenAI;
|
||||||
|
using AIStudio.Settings;
|
||||||
|
|
||||||
|
namespace AIStudio.Provider.HuggingFace;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string Id => LLMProviders.HUGGINGFACE.ToName();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string InstanceName { get; set; } = "HuggingFace";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override async IAsyncEnumerable<string> StreamChatCompletion(Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
|
||||||
|
{
|
||||||
|
// Get the API key:
|
||||||
|
var requestedSecret = await RUST_SERVICE.GetAPIKey(this);
|
||||||
|
if(!requestedSecret.Success)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
// Prepare the system prompt:
|
||||||
|
var systemPrompt = new Message
|
||||||
|
{
|
||||||
|
Role = "system",
|
||||||
|
Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread, this.logger),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Prepare the HuggingFace HTTP chat request:
|
||||||
|
var huggingfaceChatRequest = JsonSerializer.Serialize(new ChatRequest
|
||||||
|
{
|
||||||
|
Model = chatModel.Id,
|
||||||
|
|
||||||
|
// Build the messages:
|
||||||
|
// - First of all the system prompt
|
||||||
|
// - Then none-empty user and AI messages
|
||||||
|
Messages = [systemPrompt, ..chatThread.Blocks.Where(n => n.ContentType is ContentType.TEXT && !string.IsNullOrWhiteSpace((n.Content as ContentText)?.Text)).Select(n => new Message
|
||||||
|
{
|
||||||
|
Role = n.Role switch
|
||||||
|
{
|
||||||
|
ChatRole.USER => "user",
|
||||||
|
ChatRole.AI => "assistant",
|
||||||
|
ChatRole.AGENT => "assistant",
|
||||||
|
ChatRole.SYSTEM => "system",
|
||||||
|
|
||||||
|
_ => "user",
|
||||||
|
},
|
||||||
|
|
||||||
|
Content = n.Content switch
|
||||||
|
{
|
||||||
|
ContentText text => text.Text,
|
||||||
|
_ => string.Empty,
|
||||||
|
}
|
||||||
|
}).ToList()],
|
||||||
|
Stream = true,
|
||||||
|
}, JSON_SERIALIZER_OPTIONS);
|
||||||
|
|
||||||
|
async Task<HttpRequestMessage> RequestBuilder()
|
||||||
|
{
|
||||||
|
// Build the HTTP post request:
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Post, "chat/completions");
|
||||||
|
|
||||||
|
// Set the authorization header:
|
||||||
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await requestedSecret.Secret.Decrypt(ENCRYPTION));
|
||||||
|
|
||||||
|
// Set the content:
|
||||||
|
request.Content = new StringContent(huggingfaceChatRequest, Encoding.UTF8, "application/json");
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
await foreach (var content in this.StreamChatCompletionInternal<ResponseStreamLine>("HuggingFace", RequestBuilder, token))
|
||||||
|
yield return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override async IAsyncEnumerable<ImageURL> StreamImageCompletion(Model imageModel, string promptPositive, string promptNegative = FilterOperator.String.Empty, ImageURL referenceImageURL = default, [EnumeratorCancellation] CancellationToken token = default)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<IEnumerable<Model>> GetTextModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(Enumerable.Empty<Model>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<IEnumerable<Model>> GetImageModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(Enumerable.Empty<Model>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<IEnumerable<Model>> GetEmbeddingModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(Enumerable.Empty<Model>());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
@ -17,6 +17,7 @@ public enum LLMProviders
|
|||||||
|
|
||||||
FIREWORKS = 5,
|
FIREWORKS = 5,
|
||||||
GROQ = 6,
|
GROQ = 6,
|
||||||
|
HUGGINGFACE = 13,
|
||||||
|
|
||||||
SELF_HOSTED = 4,
|
SELF_HOSTED = 4,
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ using AIStudio.Provider.Google;
|
|||||||
using AIStudio.Provider.Groq;
|
using AIStudio.Provider.Groq;
|
||||||
using AIStudio.Provider.GWDG;
|
using AIStudio.Provider.GWDG;
|
||||||
using AIStudio.Provider.Helmholtz;
|
using AIStudio.Provider.Helmholtz;
|
||||||
|
using AIStudio.Provider.HuggingFace;
|
||||||
using AIStudio.Provider.Mistral;
|
using AIStudio.Provider.Mistral;
|
||||||
using AIStudio.Provider.OpenAI;
|
using AIStudio.Provider.OpenAI;
|
||||||
using AIStudio.Provider.SelfHosted;
|
using AIStudio.Provider.SelfHosted;
|
||||||
@ -37,6 +38,7 @@ public static class LLMProvidersExtensions
|
|||||||
|
|
||||||
LLMProviders.GROQ => "Groq",
|
LLMProviders.GROQ => "Groq",
|
||||||
LLMProviders.FIREWORKS => "Fireworks.ai",
|
LLMProviders.FIREWORKS => "Fireworks.ai",
|
||||||
|
LLMProviders.HUGGINGFACE => "Hugging Face",
|
||||||
|
|
||||||
LLMProviders.SELF_HOSTED => "Self-hosted",
|
LLMProviders.SELF_HOSTED => "Self-hosted",
|
||||||
|
|
||||||
@ -56,7 +58,10 @@ public static class LLMProvidersExtensions
|
|||||||
{
|
{
|
||||||
LLMProviders.NONE => Confidence.NONE,
|
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_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(
|
LLMProviders.OPEN_AI => Confidence.USA_NO_TRAINING.WithRegion("America, U.S.").WithSources(
|
||||||
"https://platform.openai.com/docs/models/default-usage-policies-by-endpoint",
|
"https://platform.openai.com/docs/models/default-usage-policies-by-endpoint",
|
||||||
@ -112,6 +117,7 @@ public static class LLMProvidersExtensions
|
|||||||
LLMProviders.X => false,
|
LLMProviders.X => false,
|
||||||
LLMProviders.GWDG => false,
|
LLMProviders.GWDG => false,
|
||||||
LLMProviders.DEEP_SEEK => false,
|
LLMProviders.DEEP_SEEK => false,
|
||||||
|
LLMProviders.HUGGINGFACE => false,
|
||||||
|
|
||||||
//
|
//
|
||||||
// Self-hosted providers are treated as a special case anyway.
|
// Self-hosted providers are treated as a special case anyway.
|
||||||
@ -129,7 +135,7 @@ public static class LLMProvidersExtensions
|
|||||||
/// <returns>The provider instance.</returns>
|
/// <returns>The provider instance.</returns>
|
||||||
public static IProvider CreateProvider(this AIStudio.Settings.Provider providerSettings, ILogger logger)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -140,10 +146,10 @@ public static class LLMProvidersExtensions
|
|||||||
/// <returns>The provider instance.</returns>
|
/// <returns>The provider instance.</returns>
|
||||||
public static IProvider CreateProvider(this EmbeddingProvider embeddingProviderSettings, ILogger logger)
|
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
|
try
|
||||||
{
|
{
|
||||||
@ -159,6 +165,7 @@ public static class LLMProvidersExtensions
|
|||||||
|
|
||||||
LLMProviders.GROQ => new ProviderGroq(logger) { InstanceName = instanceName },
|
LLMProviders.GROQ => new ProviderGroq(logger) { InstanceName = instanceName },
|
||||||
LLMProviders.FIREWORKS => new ProviderFireworks(logger) { InstanceName = instanceName },
|
LLMProviders.FIREWORKS => new ProviderFireworks(logger) { InstanceName = instanceName },
|
||||||
|
LLMProviders.HUGGINGFACE => new ProviderHuggingFace(logger, instanceProvider, model) { InstanceName = instanceName },
|
||||||
|
|
||||||
LLMProviders.SELF_HOSTED => new ProviderSelfHosted(logger, host, hostname) { InstanceName = instanceName },
|
LLMProviders.SELF_HOSTED => new ProviderSelfHosted(logger, host, hostname) { InstanceName = instanceName },
|
||||||
|
|
||||||
@ -187,6 +194,7 @@ public static class LLMProvidersExtensions
|
|||||||
|
|
||||||
LLMProviders.GROQ => "https://console.groq.com/",
|
LLMProviders.GROQ => "https://console.groq.com/",
|
||||||
LLMProviders.FIREWORKS => "https://fireworks.ai/login",
|
LLMProviders.FIREWORKS => "https://fireworks.ai/login",
|
||||||
|
LLMProviders.HUGGINGFACE => "https://huggingface.co/login",
|
||||||
|
|
||||||
LLMProviders.HELMHOLTZ => "https://sdlaml.pages.jsc.fz-juelich.de/ai/guides/blablador_api_access/#step-1-register-on-gitlab",
|
LLMProviders.HELMHOLTZ => "https://sdlaml.pages.jsc.fz-juelich.de/ai/guides/blablador_api_access/#step-1-register-on-gitlab",
|
||||||
LLMProviders.GWDG => "https://docs.hpc.gwdg.de/services/saia/index.html#api-request",
|
LLMProviders.GWDG => "https://docs.hpc.gwdg.de/services/saia/index.html#api-request",
|
||||||
@ -205,6 +213,7 @@ public static class LLMProvidersExtensions
|
|||||||
LLMProviders.FIREWORKS => "https://fireworks.ai/account/billing",
|
LLMProviders.FIREWORKS => "https://fireworks.ai/account/billing",
|
||||||
LLMProviders.DEEP_SEEK => "https://platform.deepseek.com/usage",
|
LLMProviders.DEEP_SEEK => "https://platform.deepseek.com/usage",
|
||||||
LLMProviders.ALIBABA_CLOUD => "https://usercenter2-intl.aliyun.com/billing",
|
LLMProviders.ALIBABA_CLOUD => "https://usercenter2-intl.aliyun.com/billing",
|
||||||
|
LLMProviders.HUGGINGFACE => "https://huggingface.co/settings/billing",
|
||||||
|
|
||||||
_ => string.Empty,
|
_ => string.Empty,
|
||||||
};
|
};
|
||||||
@ -220,19 +229,22 @@ public static class LLMProvidersExtensions
|
|||||||
LLMProviders.GOOGLE => true,
|
LLMProviders.GOOGLE => true,
|
||||||
LLMProviders.DEEP_SEEK => true,
|
LLMProviders.DEEP_SEEK => true,
|
||||||
LLMProviders.ALIBABA_CLOUD => true,
|
LLMProviders.ALIBABA_CLOUD => true,
|
||||||
|
LLMProviders.HUGGINGFACE => true,
|
||||||
|
|
||||||
_ => false,
|
_ => 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.FIREWORKS => "https://fireworks.ai/models?show=Serverless",
|
||||||
|
LLMProviders.HUGGINGFACE => $"https://huggingface.co/models?inference_provider={instanceProvider.EndpointsId()}",
|
||||||
_ => string.Empty,
|
_ => string.Empty,
|
||||||
};
|
};
|
||||||
|
|
||||||
public static bool IsLLMModelProvidedManually(this LLMProviders provider) => provider switch
|
public static bool IsLLMModelProvidedManually(this LLMProviders provider) => provider switch
|
||||||
{
|
{
|
||||||
LLMProviders.FIREWORKS => true,
|
LLMProviders.FIREWORKS => true,
|
||||||
|
LLMProviders.HUGGINGFACE => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -268,6 +280,7 @@ public static class LLMProvidersExtensions
|
|||||||
LLMProviders.FIREWORKS => true,
|
LLMProviders.FIREWORKS => true,
|
||||||
LLMProviders.HELMHOLTZ => true,
|
LLMProviders.HELMHOLTZ => true,
|
||||||
LLMProviders.GWDG => true,
|
LLMProviders.GWDG => true,
|
||||||
|
LLMProviders.HUGGINGFACE => true,
|
||||||
|
|
||||||
LLMProviders.SELF_HOSTED => host is Host.OLLAMA,
|
LLMProviders.SELF_HOSTED => host is Host.OLLAMA,
|
||||||
|
|
||||||
@ -288,6 +301,7 @@ public static class LLMProvidersExtensions
|
|||||||
LLMProviders.FIREWORKS => true,
|
LLMProviders.FIREWORKS => true,
|
||||||
LLMProviders.HELMHOLTZ => true,
|
LLMProviders.HELMHOLTZ => true,
|
||||||
LLMProviders.GWDG => true,
|
LLMProviders.GWDG => true,
|
||||||
|
LLMProviders.HUGGINGFACE => true,
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
@ -317,4 +331,10 @@ public static class LLMProvidersExtensions
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsHFInstanceProviderNeeded(this LLMProviders provider) => provider switch
|
||||||
|
{
|
||||||
|
LLMProviders.HUGGINGFACE => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
using AIStudio.Provider;
|
using AIStudio.Provider;
|
||||||
|
using AIStudio.Provider.HuggingFace;
|
||||||
using Host = AIStudio.Provider.SelfHosted.Host;
|
using Host = AIStudio.Provider.SelfHosted.Host;
|
||||||
|
|
||||||
namespace AIStudio.Settings;
|
namespace AIStudio.Settings;
|
||||||
@ -24,7 +24,8 @@ public readonly record struct Provider(
|
|||||||
Model Model,
|
Model Model,
|
||||||
bool IsSelfHosted = false,
|
bool IsSelfHosted = false,
|
||||||
string Hostname = "http://localhost:1234",
|
string Hostname = "http://localhost:1234",
|
||||||
Host Host = Host.NONE) : ISecretId
|
Host Host = Host.NONE,
|
||||||
|
HFInstanceProvider HFInstanceProvider = HFInstanceProvider.NONE) : ISecretId
|
||||||
{
|
{
|
||||||
#region Overrides of ValueType
|
#region Overrides of ValueType
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using AIStudio.Provider;
|
using AIStudio.Provider;
|
||||||
|
using AIStudio.Provider.HuggingFace;
|
||||||
using Host = AIStudio.Provider.SelfHosted.Host;
|
using Host = AIStudio.Provider.SelfHosted.Host;
|
||||||
|
|
||||||
namespace AIStudio.Tools.Validation;
|
namespace AIStudio.Tools.Validation;
|
||||||
@ -93,4 +93,15 @@ public sealed class ProviderValidation
|
|||||||
|
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user