Bitzsoft.Integrations.AI
1.0.0-alpha.5
This is a prerelease version of Bitzsoft.Integrations.AI.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Bitzsoft.Integrations.AI --version 1.0.0-alpha.5
NuGet\Install-Package Bitzsoft.Integrations.AI -Version 1.0.0-alpha.5
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="Bitzsoft.Integrations.AI" Version="1.0.0-alpha.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.AI" Version="1.0.0-alpha.5" />
<PackageReference Include="Bitzsoft.Integrations.AI" />
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 Bitzsoft.Integrations.AI --version 1.0.0-alpha.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.AI, 1.0.0-alpha.5"
#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.
#:package Bitzsoft.Integrations.AI@1.0.0-alpha.5
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.AI&version=1.0.0-alpha.5&prerelease
#tool nuget:?package=Bitzsoft.Integrations.AI&version=1.0.0-alpha.5&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.AI
AI 服务集成 — 基于 Microsoft.Extensions.AI 的 IChatClient 抽象,提供轻量 OpenAI 兼容客户端。
功能特性
- 基于
Microsoft.Extensions.AI.IChatClient标准抽象,Provider 无关 - 兼容所有 OpenAI Chat Completions API 协议的服务商(OpenAI、DeepSeek、通义千问等)
- 支持命名客户端(Keyed DI),满足多租户或多模型场景
- 支持结构化输出(
GetObjectAsync<T>),直接获取强类型对象 - 内置 MEAI 中间件管道:OpenTelemetry 遥测、分布式缓存、日志记录
安装
dotnet add package Bitzsoft.Integrations.AI
配置
在 appsettings.json 中添加以下配置节:
{
"AI": {
"Endpoint": "https://api.openai.com/v1",
"ApiKey": "sk-your-api-key",
"ModelId": "gpt-4o",
"SystemPrompt": "你是一个有帮助的 AI 助手。"
}
}
| 配置项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Endpoint |
string |
https://api.openai.com/v1 |
OpenAI 兼容端点地址 |
ApiKey |
string |
- | API 密钥 |
ModelId |
string |
gpt-4o |
默认模型名称 |
SystemPrompt |
string |
你是一个有帮助的 AI 助手。 |
默认系统提示词 |
EnableTelemetry |
bool |
false |
是否启用 OpenTelemetry 遥测中间件 |
EnableCaching |
bool |
false |
是否启用分布式缓存中间件(需注册 IDistributedCache) |
兼容历史配置:
ApiUrl映射到Endpoint,DefaultModel映射到ModelId。
注册服务
基础注册
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.AI;
// Program.cs
services.AddBitzChatClient(options =>
{
options.Endpoint = "https://api.openai.com/v1";
options.ApiKey = "sk-your-api-key";
options.ModelId = "gpt-4o";
});
多租户 / 多模型注册
// 注册 GPT-4o 客户端
services.AddBitzChatClient("GPT4", options =>
{
options.Endpoint = "https://api.openai.com/v1";
options.ApiKey = "sk-openai-key";
options.ModelId = "gpt-4o";
});
// 注册 DeepSeek 客户端
services.AddBitzChatClient("DeepSeek", options =>
{
options.Endpoint = "https://api.deepseek.com/v1";
options.ApiKey = "sk-deepseek-key";
options.ModelId = "deepseek-chat";
});
使用示例
注入并使用 IChatClient
using Microsoft.Extensions.AI;
public class DocumentService(IChatClient chatClient)
{
/// <summary>
/// 对文档内容进行摘要提取
/// </summary>
public async Task<string> SummarizeAsync(string documentContent, CancellationToken ct = default)
{
var messages = new List<ChatMessage>
{
new(ChatRole.System, "你是一个专业的文档摘要助手。"),
new(ChatRole.User, $"请对以下文档内容进行摘要:\n\n{documentContent}")
};
var response = await chatClient.GetResponseAsync(messages, cancellationToken: ct);
return response.Text;
}
/// <summary>
/// 流式输出
/// </summary>
public async IAsyncEnumerable<string> SummarizeStreamAsync(
string documentContent,
[EnumeratorCancellation] CancellationToken ct = default)
{
var messages = new List<ChatMessage>
{
new(ChatRole.System, "你是一个专业的文档摘要助手。"),
new(ChatRole.User, documentContent)
};
await foreach (var update in chatClient.GetStreamingResponseAsync(messages, cancellationToken: ct))
{
if (update.Text is not null)
{
yield return update.Text;
}
}
}
}
结构化输出(Structured Output)
通过 GetObjectAsync<T> 直接获取强类型对象,无需手动 JSON 反序列化:
using Bitzsoft.Integrations.AI;
// 定义返回类型
public record SentimentResult(string Sentiment, double Confidence, string Summary);
public class AnalysisService(IChatClient chatClient)
{
public async Task<SentimentResult?> AnalyzeAsync(string text, CancellationToken ct = default)
{
return await chatClient.GetObjectAsync<SentimentResult>(
message: $"请分析以下文本的情感倾向:\n{text}",
systemPrompt: "你是情感分析助手,返回 JSON 格式:sentiment(正面/负面/中性)、confidence(0-1)、summary");
}
}
使用命名客户端(多模型场景)
public class MultiModelService(
[FromKeyedServices("BitzChatClient_GPT4")] IChatClient gpt4Client,
[FromKeyedServices("BitzChatClient_DeepSeek")] IChatClient deepseekClient)
{
public Task<string> AskGptAsync(string question) =>
gpt4Client.GetResponseAsync(question);
public Task<string> AskDeepSeekAsync(string question) =>
deepseekClient.GetResponseAsync(question);
}
相关包
| 包名 | 说明 |
|---|---|
| Bitzsoft.Integrations.AI.Abstractions | AI 共享抽象层(AiOptions、DI 扩展) |
| Bitzsoft.Integrations.SemanticKernel | Semantic Kernel 编排层(插件、函数调用) |
| Bitzsoft.Integrations.RAG | 检索增强生成(Qdrant + IEmbeddingGenerator) |
| Bitzsoft.Integrations.AgentFramework | AI Agent 框架 |
| Bitzsoft.Integrations.McpServer | MCP Server 集成 |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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 is compatible. 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.
-
net10.0
- Bitzsoft.Integrations.AI.Abstractions (>= 1.0.0-alpha.5)
- Microsoft.Extensions.AI (>= 10.7.0)
- Microsoft.Extensions.AI.OpenAI (>= 10.7.0)
- Microsoft.Extensions.Options (>= 10.0.9)
- OpenAI (>= 2.11.0)
-
net8.0
- Bitzsoft.Integrations.AI.Abstractions (>= 1.0.0-alpha.5)
- Microsoft.Extensions.AI (>= 10.7.0)
- Microsoft.Extensions.AI.OpenAI (>= 10.7.0)
- Microsoft.Extensions.Options (>= 10.0.9)
- OpenAI (>= 2.11.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.AI:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.All
Bitzsoft 第三方集成聚合包 — 包含全部 Integration 模块 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.7 | 56 | 6/16/2026 |
| 1.0.0-alpha.6 | 60 | 6/16/2026 |
| 1.0.0-alpha.5 | 55 | 6/14/2026 |
| 1.0.0-alpha.4 | 62 | 6/14/2026 |
| 1.0.0-alpha.3 | 60 | 6/7/2026 |
| 1.0.0-alpha.2 | 61 | 5/29/2026 |
| 1.0.0-alpha.1 | 55 | 5/28/2026 |