Aeex.LLMService.Shared
0.0.3-preview
See the version list below for details.
dotnet add package Aeex.LLMService.Shared --version 0.0.3-preview
NuGet\Install-Package Aeex.LLMService.Shared -Version 0.0.3-preview
<PackageReference Include="Aeex.LLMService.Shared" Version="0.0.3-preview" />
paket add Aeex.LLMService.Shared --version 0.0.3-preview
#r "nuget: Aeex.LLMService.Shared, 0.0.3-preview"
// Install Aeex.LLMService.Shared as a Cake Addin #addin nuget:?package=Aeex.LLMService.Shared&version=0.0.3-preview&prerelease // Install Aeex.LLMService.Shared as a Cake Tool #tool nuget:?package=Aeex.LLMService.Shared&version=0.0.3-preview&prerelease
ChatGPT、文心一言、百度智能作画 SDK (.net6.0+)
Aeex.LLMService
是一个非官方的开源项目.提供了在.NET6.0
.NET8.0
项目中使用接口调用OpenAI ChatGPT、百度文心大模型和百度智能绘图高级版功能.
已知问题
安装
通过Nuget
安装.
OpenAI ChatGPT
Package Manager
Install-Package Aeex.LLMService.OpenAI.ChatGPT
Cli
dotnet add package Aeex.LLMService.OpenAI.ChatGPT
文心大模型
Package Manager
Install-Package Aeex.LLMService.Baidu.Wenxin
Cli
dotnet add package Aeex.LLMService.Baidu.Wenxin
智能绘图V2
Package Manager
Install-Package Aeex.LLMService.Baidu.ErnieVilg
Cli
dotnet add package Aeex.LLMService.Baidu.ErnieVilg
使用
- 在
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);
//...
}
- 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 | Versions 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. |
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Aeex.LLMService.Shared:
Package | Downloads |
---|---|
Aeex.LLMService.Baidu.Wenxin
A dotnet Library for ChatGPT, Baidu ernie-bot and ErnievilgV2 |
|
Aeex.LLMService.Baidu.ErnieVilg
A dotnet Library for ChatGPT, Baidu ernie-bot and ErnievilgV2 |
|
Aeex.LLMService.OpenAI.ChatGPT
A dotnet Library for ChatGPT, Baidu ernie-bot and ErnievilgV2 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.5.1-preview | 64 | 8/6/2024 |
0.0.3.1-preview | 63 | 6/11/2024 |
0.0.3-preview | 72 | 6/7/2024 |
0.0.2.4-preview | 63 | 6/5/2024 |
0.0.2.3-preview | 84 | 3/21/2024 |
0.0.2.2-preview | 77 | 2/19/2024 |
0.0.2.1-preview | 171 | 12/25/2023 |
0.0.3.0-preview Rewrite data provider.Breaking changes: IDataProvider interfaces and DI methods.
0.0.2.4-preview Refactor IChatDataProvider.Add overload Save method.
0.0.2.0-preview Init publish.