Bitzsoft.Integrations.AI.Abstractions 1.1.0

dotnet add package Bitzsoft.Integrations.AI.Abstractions --version 1.1.0
                    
NuGet\Install-Package Bitzsoft.Integrations.AI.Abstractions -Version 1.1.0
                    
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.Abstractions" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.AI.Abstractions" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.AI.Abstractions" />
                    
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 Bitzsoft.Integrations.AI.Abstractions --version 1.1.0
                    
#r "nuget: Bitzsoft.Integrations.AI.Abstractions, 1.1.0"
                    
#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.Abstractions@1.1.0
                    
#: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.Abstractions&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.AI.Abstractions&version=1.1.0
                    
Install as a Cake Tool

Bitzsoft.Integrations.AI.Abstractions

AI 集成的共享契约包。它定义 Provider Profile、模型能力、租户感知聊天与向量 Factory 以及 Provider Adapter Seam;不绑定具体厂商 SDK。

安装与兼容性

dotnet add package Bitzsoft.Integrations.AI.Abstractions
  • 目标框架:net8.0;net10.0;
  • 依赖 Microsoft.Extensions.AI.Abstractions 和 Bitzsoft.Integrations.Core;
  • 适合由宿主、基础设施 Adapter 和其他 AI 包共同引用;
  • .NET 5 系统应通过独立的 .NET 8/10 AI 服务调用。

主要契约

类型 职责
AiOptions 一个命名客户端的非敏感 Provider、Profile、Endpoint、Model 与管道开关
AIEmbeddingOptions 一个命名文本向量生成器的非敏感模型、维度与管道配置
AIProviderProfile 协议、默认端点、保守能力与限制的不可变描述
AIModelCapabilities Chat、Streaming、Tools、Structured Output、Vision、Reasoning 等能力标志
IAIProviderProfileCatalog 查询已注册 Profile
IAIChatClientFactory 按命名配置和当前租户上下文创建短生命周期 IChatClient
IAIChatClientProviderAdapter 把一种协议转换为 IChatClient 的扩展 Seam
IAIEmbeddingGeneratorFactory 按命名配置和当前租户上下文创建短生命周期文本向量生成器
IAIEmbeddingGeneratorProviderAdapter 把一种协议转换为 IEmbeddingGenerator 的扩展 Seam
IAIDynamicModelCatalogPort 按租户上下文从数据库或配置中心解析动态模型(AIDynamicModelConfig)与供应商(AIDynamicProviderConfig)的纯端口(含 ResolveThinkingPolicy 提供商/单模型三态思考开关与默认推理强度级联解析)
IAIDynamicChatClientComposer 将动态模型与供应商记录装配为带遥测、日志与请求审计管线的一次性 IChatClient
AIDynamicChatClientOptions 动态编目聊天客户端的总闸开关、禁用提示文案及三类管线开关
AIExecutionErrorCodes / AIDomainException 全套件稳定机器可读错误码与携带 HTTP 状态码映射的结构化 AI 领域异常基类
IAICacheEpochCoordinator / AICacheEpochKeys 零 Redis 客户端依赖的 L1/L2 多租户纪元缓存协调契约与 AOT 序列化信封
IAIProviderCatalogStore / IDynamicAIProviderResolver 运行期动态提供商/模型目录只读存储端口、多级缓存解析器及 [JsonIgnore] 密钥隔离快照(含提供商/单模型 EnableThinking 与 DefaultReasoningEffort AOT 序列化支持)
AIReasoningEffortNormalizer 跨厂商思考推理强度别名归一化、强校验(NormalizeOrThrow)与原生强制推理模型识别器
IAISpeechToTextProviderAdapter / IAIDynamicSpeechToTextComposer 等 面向 ISpeechToTextClient、ITextToSpeechClient、IRealtimeClient 与 IImageGenerator 的多模态扩展点
IAIBackgroundJobStore / IAIBackgroundJobQueue 支持续传令牌与乐观并发状态跃迁的异步后台长任务持久化与调度契约
IAIOutboundRedactor / AIDataResidencyPolicy 外发出站敏感词脱敏、分级路由(AIDataClassification)与 Fail-Closed 数据驻留边界
AIFinOpsCostCalculator / AIOpenTelemetryTagNames 高精度 decimal 百万令牌费用与缓存命中率核算器及 GenAI OTel 标准标签
AITenantSolutionManifest 面向企业级 FDE 快速交付的租户声明式模型槽位、技能包、白名单与试运行清单

会话持久化使用 Bitzsoft.Integrations.AgentFramework 的专用 Store/租约契约,知识数据使用 Bitzsoft.Integrations.RAG.IKnowledgeStore,工具则通过 Agent 或 MCP 显式注册,契约测试基类与测试替身统一位于 Bitzsoft.Integrations.AI.Testing。 本包不提供可从数据库反射加载任意类型/方法的“技能注册表”,避免把配置数据变成代码执行入口。

配置模型

AiOptions 只允许非敏感数据:

var options = new AiOptions
{
    // ProviderId 参与凭据键,允许同一 Profile 配置多个账户或地域。
    ProviderId = "openai-prod",
    // ProfileId 只描述协议、默认端点和已确认能力。
    ProfileId = "openai-responses",
    ModelId = "approved-model",
    CredentialName = "default",
    // 三个管道开关不应承载敏感数据。
    EnableTelemetry = true,
    EnableLogging = true,
    EnableRequestAudit = true
};

Endpoint 为空时使用 Profile 默认值;覆盖值必须使用 HTTPS,只有 loopback 可以使用 HTTP;端点不能包含 userinfo、query 或 fragment。ApiKey 不存在于 Options,由 Core IIntegrationCredentialResolver 在调用时解析。

向量配置同样不保存凭据:

var embeddingOptions = new AIEmbeddingOptions
{
    // 聊天与向量可以使用不同 ProviderId 和独立凭据。
    ProviderId = "qwen-prod",
    ProfileId = "qwen",
    ModelId = "text-embedding-v4",
    // 固定维度必须与向量数据库 Schema 一致。
    Dimensions = 1024,
    CredentialName = "default"
};

固定 Dimensions 是索引 Schema 契约。模型或维度变化需要版本化 Collection 和重建索引,不能在旧 Collection 中混写不同维度。

自定义 Adapter

实现全新协议时,具体 Adapter 包应同时引用 Bitzsoft.Integrations.AI.Abstractions 与 Bitzsoft.Integrations.AI。前者提供 Factory/Adapter 契约,后者提供运行时注册、统一凭据字段和 Profile 目录。

下面是可直接放入具体厂商包的完整骨架。ICompanyAIClientFactory 由该厂商包使用官方 SDK 实现;注册方法接收工厂实例,因此示例没有隐藏的类型或全局变量:

using Bitzsoft.Integrations.AI;
using Bitzsoft.Integrations.AI.Abstractions;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;

public interface ICompanyAIClientFactory
{
    IChatClient CreateChatClient(
        Uri endpoint,
        string modelId,
        string apiKey);

    IEmbeddingGenerator<string, Embedding<float>> CreateEmbeddingGenerator(
        Uri endpoint,
        string modelId,
        int? dimensions,
        string apiKey);
}

public sealed class PrivateProviderAdapter :
    IAIChatClientProviderAdapter
{
    private readonly ICompanyAIClientFactory _factory;

    public PrivateProviderAdapter(ICompanyAIClientFactory factory)
        => _factory = factory;

    public bool Supports(AIProviderProtocol protocol)
        => protocol == AIProviderProtocol.Custom;

    public IChatClient CreateClient(
        AIChatClientCreationContext context)
    {
        // 凭据快照只在 CreateClient 返回前有效,不能被 Adapter 缓存。
        var apiKey = context.Credential.GetRequiredSecret(
            AICredentialFieldNames.ApiKey);
        return _factory.CreateChatClient(
            context.Endpoint,
            context.ModelId,
            apiKey);
    }
}

public sealed class PrivateEmbeddingAdapter :
    IAIEmbeddingGeneratorProviderAdapter
{
    private readonly ICompanyAIClientFactory _factory;

    public PrivateEmbeddingAdapter(ICompanyAIClientFactory factory)
        => _factory = factory;

    public bool Supports(AIProviderProtocol protocol)
        => protocol == AIProviderProtocol.Custom;

    public IEmbeddingGenerator<string, Embedding<float>> CreateGenerator(
        AIEmbeddingGeneratorCreationContext context)
        => _factory.CreateEmbeddingGenerator(
            context.Endpoint,
            context.ModelId,
            context.Dimensions,
            context.Credential.GetRequiredSecret(
                AICredentialFieldNames.ApiKey));
}

public static class CompanyAIServiceCollectionExtensions
{
    public static IServiceCollection AddCompanyAI(
        this IServiceCollection services,
        ICompanyAIClientFactory sdkFactory)
    {
        ArgumentNullException.ThrowIfNull(services);
        ArgumentNullException.ThrowIfNull(sdkFactory);

        // SDK 工厂拥有 SDK 初始化细节,但不能缓存租户凭据。
        services.AddSingleton(sdkFactory);
        services.AddSingleton<
            IAIChatClientProviderAdapter,
            PrivateProviderAdapter>();
        services.AddSingleton<
            IAIEmbeddingGeneratorProviderAdapter,
            PrivateEmbeddingAdapter>();

        // Custom Profile 只声明已经通过真实账户契约测试的能力。
        services.AddBitzAIProviderProfile(new AIProviderProfile(
            profileId: "company-ai",
            displayName: "Company AI",
            protocol: AIProviderProtocol.Custom,
            defaultEndpoint: new Uri("https://ai.company.example/"),
            capabilities:
                AIModelCapabilities.Chat |
                AIModelCapabilities.Streaming |
                AIModelCapabilities.Embeddings));
        return services;
    }
}

Adapter 不拥有创建上下文中的 Credential,必须在创建方法返回前复制 SDK 所需的密钥值。返回客户端/生成器的所有权归 Factory 调用方。不要捕获凭据对象,也不要把密钥写入异常、日志、遥测标签或 GetService 元数据。生产实现还要为 SDK 客户端补齐取消、超时、流式释放和真实账户契约测试。

若供应商本身兼容 OpenAI 协议,不需要自建 Adapter;注册 AIProviderProtocol.OpenAIChatCompletions 的自定义 Profile 即可复用内置实现。

数据与安全边界

  • Provider 配置只保存 CredentialName,不能保存 API Key、Token 或私钥;
  • Agent/RAG 的 Store 查询必须把 tenant 作为强制条件,不能依赖事后过滤;
  • System Prompt、对话、工具参数和模型响应可能包含商业秘密或个人信息;
  • 模型和技能配置应版本化,历史会话应能追溯对应版本;
  • 技能元数据不是执行授权,工具执行边界必须重新做身份、租户、资源和参数校验;
  • 模型输出不能未经验证进入 SQL、Shell、HTML、模板、文件路径或有副作用操作。

具体模型注册与内置 Profile 请参阅 Bitzsoft.Integrations.AI。

Product 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.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Bitzsoft.Integrations.AI.Abstractions:

Package Downloads
Bitzsoft.Integrations.All

Bitzsoft 第三方集成聚合包 — net5.0 包含传统连接器,net8.0+ 额外包含受上游 TFM 限制的 AI 模块

Bitzsoft.Integrations.AI

多租户 AI 集成 — 基于 Microsoft.Extensions.AI 的聊天、向量生成、遥测与请求审计

Bitzsoft.Integrations.SemanticKernel

安全的 Semantic Kernel 兼容编排层 — 复用租户感知 IChatClient,提供 Scope 隔离插件与受限函数调用

Bitzsoft.Integrations.AI.Anthropic

Anthropic Claude 原生 Messages 协议与 Microsoft.Extensions.AI 集成

Bitzsoft.Integrations.Translation.AI.OpenAI

OpenAI 兼容网关大模型翻译实现 — 通吃 OpenAI / 智谱 GLM / DeepSeek / Kimi / 通义千问 compatible 端点,复用 AI.Abstractions 的 IChatClient 体系,法律术语约束提示词 + 分段回拼 + JSON 输出回退

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 0 11/14/2026
1.0.5 108 11/10/2026
1.0.4 290 9/23/2026
1.0.3 132 9/22/2026
1.0.2 197 8/29/2026
1.0.1 219 8/3/2026
1.0.0 230 8/2/2026
1.0.0-alpha.10 286 7/26/2026
1.0.0-alpha.9 1,659 7/12/2026
1.0.0-alpha.8 117 7/1/2026
1.0.0-alpha.7 122 6/16/2026
1.0.0-alpha.6 111 6/16/2026
1.0.0-alpha.5 114 6/14/2026