Ybd.AbpLite.AI 1.2.1

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

Ybd.AbpLite.AI

ABP Framework 的 AI 模块。引入模块并写好 Ai 配置后,业务代码用 IAbpLiteAiAgentFactory 创建 Agent。一次 RunAsync 里,模型自己决定是否调用工具和内存技能。连接的是 OpenAI 兼容 HTTP,官方接口和第三方代理都只改 Endpoint。图像用 IAbpLiteImageGeneratorAccessor,不进 Agent 循环。

包内引用 Volo.Abp.AI 10.7.0 和 Microsoft.Agents.AI。Microsoft.Agents.AI 不在 Volo.Abp.AI 里面。不含聊天接口,也不带供应商密钥。

维护者用的完整说明在源码仓库 docs/ai.md,不随这个包发布。

非 ABP 官方包。适用于 ABP 10.7(net10.0)。

安装

dotnet add package Ybd.AbpLite.AI

在 Host 模块里依赖它:

[DependsOn(typeof(AbpLiteAiModule))]
public class MyHttpApiHostModule : AbpModule
{
}

配置

配置节名为 Ai。平铺的三项表示名为 default 的 OpenAICompatible 聊天。缺任意一项时应用仍能启动,创建 Agent 会得到错误码 AbpLiteAI:NotConfigured。Profiles 里可以再加连接;Provider 目前有 OpenAICompatible 和 DashScopeImage。

{
  "Ai": {
    "Endpoint": "https://api.openai.com/v1",
    "ApiKey": "",
    "Model": "gpt-4o-mini",
    "Profiles": {
      "qwen-image": {
        "Provider": "DashScopeImage",
        "Capability": "Image",
        "Endpoint": "https://dashscope.aliyuncs.com/compatible-mode/v1",
        "ApiKey": "",
        "Model": "qwen-image-3.0",
        "Parameters": { "prompt_extend": "true" }
      }
    }
  }
}

生产环境用环境变量 Ai__ApiKey 注入密钥。代理只要提供相同的 /chat/completions,把 Endpoint 换成代理的 /v1 地址即可。协议不同的 HTTP 不在这个供应商里。

创建 Agent

public class SummaryAppService : ApplicationService
{
    private readonly IAbpLiteAiAgentFactory _agents;

    public SummaryAppService(IAbpLiteAiAgentFactory agents) => _agents = agents;

    public async Task<string> SummarizeAsync(string text)
    {
        var agent = _agents.Create("用一句话概括用户给出的内容。");
        var response = await agent.RunAsync(text);
        return response.Text;
    }
}

需要模型自己决定何时调用业务代码时,把方法封成工具再交给 Agent:

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

[Description("查询指定城市的天气。")]
static string GetWeather([Description("城市名")] string city)
    => $"{city}:多云,15°C";

var agent = _agents.Create(
    "你是助手。需要天气信息时调用工具,不要编造。",
    [AIFunctionFactory.Create(GetWeather)]);

var response = await agent.RunAsync("阿姆斯特丹天气怎么样?");

Create 不调用模型。RunAsync 才会访问对应 profile 的地址。有工具时框架会在这一次运行里自动执行工具并把结果回传给模型。内存技能传 AgentInlineSkill,模型按需加载说明和资源。不扫描磁盘,也不执行技能脚本。

指定其它聊天 profile 时传入 profile 名。图像不走 Agent:

var images = serviceProvider.GetRequiredService<IAbpLiteImageGeneratorAccessor>();
var response = await images.Get("qwen-image").GenerateAsync(new ImageGenerationRequest("一只猫"));
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
2.0.0-preview.2 45 11/3/2026
1.2.1 104 10/31/2026
1.2.0 101 10/31/2026
1.0.0 112 10/29/2026