Aeex.LLMService.Baidu.Wenxin 0.0.5.1-preview

This is a prerelease version of Aeex.LLMService.Baidu.Wenxin.
dotnet add package Aeex.LLMService.Baidu.Wenxin --version 0.0.5.1-preview                
NuGet\Install-Package Aeex.LLMService.Baidu.Wenxin -Version 0.0.5.1-preview                
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="Aeex.LLMService.Baidu.Wenxin" Version="0.0.5.1-preview" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aeex.LLMService.Baidu.Wenxin --version 0.0.5.1-preview                
#r "nuget: Aeex.LLMService.Baidu.Wenxin, 0.0.5.1-preview"                
#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.
// Install Aeex.LLMService.Baidu.Wenxin as a Cake Addin
#addin nuget:?package=Aeex.LLMService.Baidu.Wenxin&version=0.0.5.1-preview&prerelease

// Install Aeex.LLMService.Baidu.Wenxin as a Cake Tool
#tool nuget:?package=Aeex.LLMService.Baidu.Wenxin&version=0.0.5.1-preview&prerelease                

ChatGPT、文心一言、百度智能作画 SDK (.net6.0+)

.NET6.0 .NET8.0 license

Aeex.LLMService 是一个非官方的开源项目.提供了在.NET6.0 .NET8.0项目中使用接口调用OpenAI ChatGPT、百度文心大模型和百度智能绘图高级版功能.

已知问题

安装

通过Nuget安装.

OpenAI ChatGPT

Nuget地址

Package Manager
Install-Package Aeex.LLMService.OpenAI.ChatGPT
Cli
dotnet add package Aeex.LLMService.OpenAI.ChatGPT

文心大模型

Nuget地址

Package Manager
Install-Package Aeex.LLMService.Baidu.Wenxin
Cli
dotnet add package Aeex.LLMService.Baidu.Wenxin

智能绘图V2

Nuget地址

Package Manager
Install-Package Aeex.LLMService.Baidu.ErnieVilg
Cli
dotnet add package Aeex.LLMService.Baidu.ErnieVilg

使用

  1. ConfigureService方法中添加依赖注入
public void ConfigureServices(IServiceCollection services, IConfiguration config){
    //....
    
    // Ensure HttpContext injected. It will be accessed in Chat service.
    services.AddHttpContextAccessor();

    // inject image storage provider
    services.AddTransient<IImageStorageProvider, LocalImageStorageProvider>();
    // inject chat data provider
    // for baidu chat caching
    services.AddTransient<IChatDataProvider<ChatMessageBase, string>, ChatDataProvider<ChatMessageBase, string>>();
    // for chatgpt
    services.AddTransient<IChatDataProvider<OpenAIChatMessage, List<OpenAIMessageContent>>, ChatDataProvider<OpenAIChatMessage, List<OpenAIMessageContent>>>();
    
    // inject service
    services.AddChatGPT(config);
    services.AddWenxinworkshop(config);
    services.AddErnieVilg(config);

    //...
}
  1. Have fun!

    /// <summary>
    /// 集成百度AI类api
    /// </summary>
    [ApiVersion("1.0")]
    [ApiController]
    [Route("api/v{version:apiVersion}/baidu")]
    public class BaiduApiController(
        IBaiduErniebotLLMService baiduApiService,
        IAIPaintApiService<PaintApplyRequest, PaintResultResponse> ernieVilgApiService) : ControllerBase
    {
        /// <summary>
        /// The API service
        /// </summary>
        private readonly IBaiduErniebotLLMService _apiService = baiduApiService;
        /// <summary>
        /// The ernie vilg API service
        /// </summary>
        private readonly IAIPaintApiService<PaintApplyRequest, PaintResultResponse> _ernieVilgApiService = ernieVilgApiService;

        /// <summary>
        /// 发起文心一言大模型对话
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        [HttpPost("chat")]
        [ProducesResponseType(typeof(string), 200)]
        [ProducesResponseType(typeof(ChatApiResponse), 200)]
        public async Task Chat(ChatRequest request)
        {
            await _apiService.Chat(request);
        }

        /// <summary>
        /// 文生图
        /// <para>封装文生图api以及回调获取生成图片api</para>
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        [HttpPost("text2img")]
        [ProducesResponseType(typeof(PaintResultResponse), 200)]
        public async Task<IActionResult> ApplyText2Img(PaintApplyRequest request)
        {
            var result = await _ernieVilgApiService.Text2Image(request);
            Response.BuildAIGeneratedResponseFeature();
            return Ok(result);
        }
    }


    [ApiVersion("1.0")]
    [ApiController]
    [Route("api/v{version:apiVersion}/chatgpt")]
    [ApiExplorerSettings(GroupName = "ChatGPT")]
    public class ChatGPTApiController(
        IChatGPTLLMService gptService): ControllerBase
    {

        /// <summary>
        /// The API service
        /// </summary>
        private readonly IChatGPTLLMService _apiService = gptService;

        /// <summary>
        /// 发起ChatGPT对话
        /// eg.
        /// what is the difference between star and planet?
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        [HttpPost("chat")]
        [ProducesResponseType(typeof(string), 200)]
        [ProducesResponseType(typeof(OpenAIChatResponse), 200)]
        [AppExceptionInterceptor(ReturnCode = -100001, ApiVersion = "1.0")]
        public async Task Chat(ChatRequest request)
        {
            await _apiService.Chat(request);
        }

    }

支持的模型

Aeex.LLMService 支持的语言模型列表如下:

模型 描述
ERNIEBot 百度自行研发的大语言模型,覆盖海量中文数据,具有更强的对话问答、内容创作生成等能力。
ERNIEBotTurbo 百度自行研发的大语言模型,覆盖海量中文数据,具有更强的对话问答、内容创作生成等能力,响应速度更快。
ERNIE-Bot-4 ERNIE-Bot-4是百度自行研发的大语言模型,覆盖海量中文数据,具有更强的对话问答、内容创作生成等能力。
GPT_3_5_TURBO
GPT_3_5_TURBO_1106
GPT_4
GPT_4_32K

项目说明

项目 说明
LLMService.Shared 公共模型和接口及扩展方法
LLMService.OpenAI.ChatGPT ChatGPT大模型项目,目前支持文字对话
LLMService.Baidu.WenxinWorkshop 百度千帆大模型项目,目前提供ErnieBot系列API调用支持
LLMService.Baidu.ErnieVilg 百度智能创作模块,目前支持AI作画高级版2
LLMServiceHub .NET8 MVC WebApi 项目示例,填入自己的 application id可以完美调用,实现了基本的接口
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
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
0.0.5.1-preview 51 8/6/2024
0.0.3.3-preview 65 6/21/2024
0.0.3.2-preview 56 6/21/2024
0.0.3.1-preview 57 6/11/2024
0.0.3-preview 58 6/7/2024
0.0.2.3-preview 74 3/21/2024
0.0.2.1-preview 165 12/25/2023

0.0.5.1-preview [breaking changes] IAsyncEnumerable method.refactor code.
0.0.3.4-preview Add interface.
0.0.3.3-preview Add parameter max output token.
0.0.3.1-preview Add whether generate httpresponse option for Chat method.
0.0.3.0-preview Rewrite interfaces.Breaking changes: IChatDataProvider
0.0.2.2-preview Bug fix.
0.0.1.4-preview Update documents.
0.0.1.3-preview Init publish.