AI 领域拥有一套自有的抽象栈,独立于其他功能域的三层包模式。它建立在 Microsoft.Extensions.AI 之上,为多租户 AI 调用、嵌入生成、检索增强和智能体编排提供统一入口。
AI.Abstractions
包:Bitzsoft.Integrations.AI.Abstractions(仅 net8/net10)
共享契约层,定义 Provider Profile、聊天/嵌入 Factory 和 Adapter 接口。
核心类型:
// Provider 能力描述public sealed class AIProviderProfile{ public string ProfileId { get; } public string DisplayName { get; } public string Protocol { get; } // "openai" / "anthropic" public Uri DefaultEndpoint { get; } // 必须是 HTTPS 或 loopback public AIModelCapabilities Capabilities { get; } // 标志枚举 public IReadOnlyCollection<string> Limitations { get; }}
// 工厂接口public interface IAIChatClientFactory{ IChatClient CreateClient(AIChatClientCreationContext context);}
public interface IAIEmbeddingGeneratorFactory{ IEmbeddingGenerator<string, Embedding<float>> CreateGenerator(...);}AIModelCapabilities 是标志枚举,标注 Provider 支持的能力(ChatCompletion / Streaming / ToolUse / StructuredOutput / Embedding)。
AI
包:Bitzsoft.Integrations.AI(仅 net8/net10)
通用接口封装。内置 OpenAI 协议适配器(兼容 OpenAI / 智谱 / Kimi / 通义 / DeepSeek),提供租户感知的聊天与嵌入工厂。
注册入口:
// ① 注册聊天客户端builder.Services.AddBitzChatClient(configure);// 或命名注册builder.Services.AddBitzChatClient("primary", configure);
// ② 注册嵌入生成器builder.Services.AddBitzEmbeddingGenerator(configure);
// ③ 注册内置 Provider Profile(OpenAI/智谱/Kimi/通义/DeepSeek)builder.Services.AddBitzAIProviderProfile(profile);RequestLoggingChatClient 和 RequestLoggingEmbeddingGenerator 包装 M.E.AI 客户端,自动接入审计日志。
AI.Anthropic
包:Bitzsoft.Integrations.AI.Anthropic(仅 net8/net10)
Claude 原生 Messages API Adapter。不走 OpenAI 兼容层,直接调用 Anthropic Messages 端点,保留完整的 thinking、tool_use、stop_reason 语义。
SemanticKernel
包:Bitzsoft.Integrations.SemanticKernel(仅 net8/net10)
复用安全 IChatClient 的 Scoped Semantic Kernel 插件兼容层。让基于 Semantic Kernel 编写的插件无需改造即可使用库的租户感知聊天客户端。
RAG
包:Bitzsoft.Integrations.RAG(仅 net8/net10)
检索增强生成。集成 Qdrant 向量数据库,提供:
- 访问控制(租户/角色过滤)
- 混合检索(向量 + 关键词)
- 引用追踪(标注来源文档)
- Prompt Injection 边界防护
AgentFramework
包:Bitzsoft.Integrations.AgentFramework(仅 net8/net10)
Microsoft Agent Framework 封装。提供:
- 工具审批(敏感操作需人工确认)
- 租户会话持久化
- 并发协调(同一会话的消息串行化)
McpServer
包:Bitzsoft.Integrations.McpServer(仅 net8/net10)
安全的 MCP(Model Context Protocol)HTTP/stdio Client 与 Server。让连接器库自身可以作为 MCP Server 暴露工具,也可以作为 Client 消费外部 MCP Server。
net8+ 限制
所有 AI 包仅目标 net8.0;net10.0,因为 Microsoft.Extensions.AI.Abstractions、Qdrant 客户端、Microsoft Agent Framework 和 MCP 协议 SDK 均要求 net8+。这是全库唯一被文档化的 TFM 例外。