Deepseek.ASPClient is a lightweight ASP.NET wrapper for the Deepseek AI API, designed to simplify AI-driven text processing in .NET applications.
- ✅ Simple and fluent API
- ✅ Supports Dependency Injection
- ✅ Built-in error handling
- ✅ Uses HttpClient best practices
- ✅ Asynchronous and thread-safe
You can install the package via NuGet:
dotnet add package Deepseek.ASPClient
using Deepseek.ASPClient;
var client = new DeepseekClient("your-api-key");
var response = await client.GenerateResponseAsync("Hello Deepseek!");
Console.WriteLine(response.Choices[0].Message.Content);
// In Program.cs or Startup.cs
services.AddSingleton<IDeepseekClient>(provider =>
new DeepseekClient(Configuration["Deepseek:ApiKey"]));
// In a Controller
public class AiController : Controller
{
private readonly IDeepseekClient _client;
public AiController(IDeepseekClient client)
{
_client = client;
}
public async Task<IActionResult> Generate(string prompt)
{
try
{
var response = await _client.GenerateResponseAsync(prompt);
return Ok(response.Choices.First().Message.Content);
}
catch (DeepseekException ex)
{
return StatusCode((int)ex.StatusCode, ex.Message);
}
}
}
Method | Description |
---|---|
Task<DeepseekResponse> GenerateResponseAsync(DeepseekRequest request) |
Generates a response based on a structured request. |
Task<DeepseekResponse> GenerateResponseAsync(string prompt) |
Generates a response from a simple text prompt. |
All API errors are wrapped inside DeepseekException
. Handle exceptions as follows:
try
{
var response = await client.GenerateResponseAsync("Hello Deepseek!");
Console.WriteLine(response.Choices[0].Message.Content);
}
catch (DeepseekException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
We welcome contributions! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature-name
). - Commit your changes (
git commit -m "Added new feature"
). - Push to the branch (
git push origin feature-name
). - Open a Pull Request.
If you encounter any issues, please create an issue on GitHub: Report an Issue
This project is licensed under the MIT License. See LICENSE for details.
Created by Anwar Al-Hitar.