Skip to content

View12138/Community.Extensions.AI.CompatibleAI

Repository files navigation

Community.Extensions.AI.CompatibleAI

NuGet stable version

Provides an implementation of IChatClient and IEmbeddingGenerator for Kimi/DeepSeek API and OpenAI-compatible endpoints, based on Microsoft.Extensions.AI.

Install the package

From the command-line:

dotnet add package Community.Extensions.AI.CompatibleAI

Usage Examples

Chat

using OpenAI;
using Microsoft.Extensions.AI;

IChatClient client = new OpenAIClient("kimi-k2.5", Environment.GetEnvironmentVariable("API_KEY"))
    .AsIChatClient();

Console.WriteLine(await client.GetResponseAsync("What is AI?"));

Chat + Conversation History

using OpenAI;
using Microsoft.Extensions.AI;

IChatClient client = new OpenAIClient("kimi-k2.5", Environment.GetEnvironmentVariable("API_KEY"))
    .AsIChatClient();

Console.WriteLine(await client.GetResponseAsync(
[
    new ChatMessage(ChatRole.System, "You are a helpful AI assistant"),
    new ChatMessage(ChatRole.User, "What is AI?")
]));

Chat Streaming

using OpenAI;
using Microsoft.Extensions.AI;

IChatClient client = new OpenAIClient("kimi-k2.5", Environment.GetEnvironmentVariable("API_KEY"))
    .AsIChatClient();

await foreach (var update in client.GetStreamingResponseAsync("What is AI?"))
{
    Console.Write(update);
}

Tool Calling

using OpenAI;
using System.ComponentModel;
using Microsoft.Extensions.AI;

IChatClient client = new OpenAIClient("deepseek-v4-flash", Environment.GetEnvironmentVariable("API_KEY"))
    .AsIChatClient();

ChatOptions chatOptions = new()
{
    Tools = [AIFunctionFactory.Create(GetWeather)]
};

await foreach (var message in client.GetStreamingResponseAsync("Do I need an umbrella?", chatOptions))
{
    Console.Write(message);
}

[Description("Gets the weather")]
static string GetWeather() =>
    Random.Shared.NextDouble() > 0.5 ? "It's sunny" : "It's raining";

Notes

  • Compatible with Kimi/DeepSeek API
  • Supports OpenAI-compatible endpoints
  • Fully integrates with Microsoft.Extensions.AI
  • Supports streaming, tool-calling, caching, telemetry, and DI

Environment Variables

API_KEY=your_api_key

Optional custom endpoint:

BASE_URL=https://api.moonshot.cn/v1
# BASE_URL=https://api.deepseek.com

Relationship to Microsoft.Extensions.AI.OpenAI

This package is adapted from Microsoft.Extensions.AI.OpenAI and modified to support Kimi/DeepSeek API while preserving the same programming model.


License

Same as upstream project.

About

Implementation of generative AI abstractions for Moonshot/DeepSeek and OpenAI-compatible endpoints.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages