XiHan.Framework.AI.OpenAI 5.0.0-preview.1

Prefix Reserved
This is a prerelease version of XiHan.Framework.AI.OpenAI.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package XiHan.Framework.AI.OpenAI --version 5.0.0-preview.1
                    
NuGet\Install-Package XiHan.Framework.AI.OpenAI -Version 5.0.0-preview.1
                    
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="XiHan.Framework.AI.OpenAI" Version="5.0.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XiHan.Framework.AI.OpenAI" Version="5.0.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="XiHan.Framework.AI.OpenAI" />
                    
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 XiHan.Framework.AI.OpenAI --version 5.0.0-preview.1
                    
#r "nuget: XiHan.Framework.AI.OpenAI, 5.0.0-preview.1"
                    
#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 XiHan.Framework.AI.OpenAI@5.0.0-preview.1
                    
#: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=XiHan.Framework.AI.OpenAI&version=5.0.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=XiHan.Framework.AI.OpenAI&version=5.0.0-preview.1&prerelease
                    
Install as a Cake Tool

XiHan.Framework.AI.OpenAI

AI 的 OpenAI 兼容 Provider(Ring 3,RFC-0022):提供 ai.chat@1 与 ai.embedding@1,Kind = openai 的 Provider 都由本包创建——OpenAI 官方、Azure OpenAI 兼容网关、Ollama / vLLM / LM Studio 等本地兼容端点。

类型 用途
OpenAIFeature 登记两个工厂并装配 AI 核心服务;装配与启动不触网;启动时构建工具目录并解析提示增强器:工具名不合法或重名(AI_VALIDATION_001)、知识库配置引用的提示词找不到或渲染不了即启动失败(只装本特性时也一样)
OpenAIChatClientFactory GetChatClient(ChatModel).AsIChatClient() + 函数调用循环(UseFunctionInvocation),工具调用自动执行
OpenAIEmbeddingGeneratorFactory GetEmbeddingClient(EmbeddingModel).AsIEmbeddingGenerator(EmbeddingDimensions)
{
  "XiHan": { "AI": {
    "DefaultProvider": "openai",
    "Providers": {
      "openai": { "Kind": "openai", "ApiKey": "sk-…", "ChatModel": "gpt-4o-mini", "EmbeddingModel": "text-embedding-3-small", "EmbeddingDimensions": 1536 },
      "local": { "Kind": "openai", "Endpoint": "http://localhost:11434/v1", "ChatModel": "qwen2.5", "TimeoutSeconds": 300 }
    }
  } }
}

Endpoint 为空用官方端点;ApiKey 为空用占位凭据(本地端点不校验)。网络超时只以 TimeoutSeconds 为准(缺省 100 秒,示例里的 300 秒照样生效)。容器里有 IHttpClientFactory 时(应用在任何地方调用过 AddHttpClient)经名为 xihan.ai.openai 的客户端发请求,没有专门配置这个名字时是工厂的缺省客户端;可以用 services.AddHttpClient("xihan.ai.openai") 给它配置代理与处理器,但它的 Timeout 由本包置为不限,限时请改 TimeoutSeconds。经 IAIChat 与知识库流水线的调用另由框架按同一个 TimeoutSeconds 落成超时令牌(覆盖整次调用,含函数调用循环),超时与调用方取消同时发生时报 AI_TIMEOUT_001(RFC-0022「超时与取消」)。缺 ChatModel / EmbeddingModel → AI_VALIDATION_001。Provider 配置在装配时读一次、不热更新,改了要重启应用(ADR-0074)。

框架的端点来自配置,不过出站地址策略(RFC-0008、ADR-0117)。应用的提供商目录让用户填端点时,给命名客户端 OpenAIFeature.HttpClientName 接上:services.AddHttpClient(OpenAIFeature.HttpClientName).UseSocketsHttpHandler(static (handler, sp) => sp.GetRequiredService<OutboundAddressPolicy>().Apply(handler))。

依赖方向

依赖 XiHan.Framework.AI.Abstractions、Microsoft.Extensions.AI、Microsoft.Extensions.AI.OpenAI、Microsoft.Extensions.Http。不进 Profiles.Full(需要外部端点)。

状态

P0:可用(Preview)。

Product Compatible and additional computed target framework versions.
.NET 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0-preview.2 42 11/6/2026
5.0.0-preview.1 48 11/4/2026