HuggingFaceClient 1.0.3

dotnet add package HuggingFaceClient --version 1.0.3
                    
NuGet\Install-Package HuggingFaceClient -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HuggingFaceClient" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HuggingFaceClient" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="HuggingFaceClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HuggingFaceClient --version 1.0.3
                    
#r "nuget: HuggingFaceClient, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=HuggingFaceClient&version=1.0.3
                    
Install HuggingFaceClient as a Cake Addin
#tool nuget:?package=HuggingFaceClient&version=1.0.3
                    
Install HuggingFaceClient as a Cake Tool

HuggingFace .NET Client

A powerful and developer-friendly .NET client for accessing Hugging Face models with ease. This NuGet package supports four core tasks:

  • Chat Completions (sync and streaming)
  • Feature Extraction
  • Text-to-Image Generation

📦 Installation

Install via NuGet:

dotnet add package HuggingFaceClient --version 1.0.x

🚀 Getting Started

Initialize the Hugging Face client by providing your API token and the endpoint URL:

var hfClient = new HfClient("hf_your_token_here", "https://your-endpoint-url");

💬 Chat Completions

Synchronous Response

var hfClient = new HfClient("hf_xxxxxxxxxxxxxx",
    "https://router.huggingface.co/together/v1/chat/completions");

var message = hfClient.Chat
    .WithModel("Qwen/Qwen2.5-Coder-32B-Instruct")
    .AddUserMessage("Hello, how is your day?")
    .SendAsync();

Console.WriteLine(message.Result?.Choices[0].Message);

Streaming Response

var hfClient = new HfClient("hf_xxxxxx",
    "https://router.huggingface.co/together/v1/chat/completions");

var messages = hfClient.Chat
    .WithModel("Qwen/Qwen2.5-Coder-32B-Instruct")
    .AddUserMessage("Hello, how is your day?")
    .SendStreamAsync();

foreach (var message in messages.Result) {
    Console.WriteLine(message.Choices[0].Delta.Content);
}

🧠 Feature Extraction

var hfClient = new HfClient("hf_xxxxxx",
    "https://router.huggingface.co/hf-inference/pipeline/feature-extraction/intfloat/multilingual-e5-large-instruct");

var features = hfClient.ExtractFeatures
    .WithInputs("Hello, World.")
    .SendAsync();

foreach (var feature in features.Result?.Features)
{
    Console.WriteLine(feature);
}

🎨 Text-to-Image Generation

var hfClient = new HfClient("hf_xxxxxxxxxxxxxxxxxxxx",
    "https://router.huggingface.co/replicate/v1/models/black-forest-labs/flux-dev/predictions");

var message = hfClient.TextToImage
    .WithPrompt("Generate an image of a cat riding a bike.")
    .SendAsync();

Console.WriteLine(message.Result?.Data[0].Url);

✨ Connect to your Hf Space

var hfSpace = new HfSpaceClient("x.y.z/predict");

var inputDto = new InputDto();

var result = hf.GetRequestAsync<InputDto, OutputDto>(inputDto);
Console.WriteLine(result.Result);

📄 License

This project is licensed under the MIT License.


🤝 Contributing

Contributions, suggestions, and feature requests are welcome! Feel free to open an issue or submit a pull request.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 233 4/14/2025
1.0.2 184 4/14/2025