ERNIE-Bot.SDK
0.14.4
dotnet add package ERNIE-Bot.SDK --version 0.14.4
NuGet\Install-Package ERNIE-Bot.SDK -Version 0.14.4
<PackageReference Include="ERNIE-Bot.SDK" Version="0.14.4" />
<PackageVersion Include="ERNIE-Bot.SDK" Version="0.14.4" />
<PackageReference Include="ERNIE-Bot.SDK" />
paket add ERNIE-Bot.SDK --version 0.14.4
#r "nuget: ERNIE-Bot.SDK, 0.14.4"
#:package ERNIE-Bot.SDK@0.14.4
#addin nuget:?package=ERNIE-Bot.SDK&version=0.14.4
#tool nuget:?package=ERNIE-Bot.SDK&version=0.14.4
ERNIE-Bot SDK
ERNIE-Bot(文心千帆) .NET SDK
安装
dotnet add package ERNIE-Bot.SDK --prerelease
使用
引入该 Package 之后,实例化ERNIEBotClient 即可使用。
var clientId = builder.Configuration["ClientId"];
var secret = builder.Configuration["ClientSecret"];
var client = new ERNIEBotClient(clientId, secret);
ChatCompletion
直接使用ChatAsync方法可以完成对话。
其中 ModelEndpoint 是预置的模型地址,可以使用 ModelEndpoints 类来获取所有支持的模型地址。
await client.ChatAsync(new ChatCompletionsRequest()
{
Messages = new List<Message>
{
new Message()
{
Content = input.Text,
Role = MessageRole.User
}
}
}, ModelEndpoints.ERNIE_Bot);
ChatCompletionStream
使用 ChatStreamAsync 方法可以获取一个流,该流会不断的返回对话结果。
var results = client.ChatStreamAsync(new ChatCompletionsRequest()
{
Messages = new List<Message>
{
new Message()
{
Content = input.Text,
Role = MessageRole.User
}
}
}, ModelEndpoints.ERNIE_Bot);
可以使用一下方法获取流中的数据。
await foreach (var result in results)
{
// do something with result
}
Embedding
使用 EmbeddingAsync 方法可以获取文本的 Embedding。 同样可以使用 ModelEndpoints 类来获取所支持的Embedding模型的地址。
var result = await _client.EmbeddingsAsync(new EmbeddingsRequest()
{
Input = new List<string>()
{
input.Text
}
},ModelEndpoints.Embedding_v1);
自定义模型
如果您使用了自定义的模型服务,可以通过以下方法声明自定义模型的地址。
var endpoint = new ModelEndpoint("{申请发布时填写的API地址}");
API 鉴权令牌的存储和管理
由于百度的接口采用了AccessToken的鉴权方式,所以需要在使用之前先获取AccessToken,然后在请求的时候带上AccessToken。为了方便管理,SDK提供了ITokenStore接口,用于存储和管理AccessToken。
用户可自行实现该接口,自行管理AccessToken的存储和更新。SDK提供了MemoryTokenStore,在内存中存储AccessToken,该实现依赖于MemoryCache。
接口支持
- API 鉴权
- ERNIE-Bot
- ERNIE-Bot-turbo
- Embedding-V1
- BLOOMZ-7B
- Llama_2_7b_chat
- Llama_2_13b_chat
- Llama_2_70b_chat
- Qianfan_BLOOMZ_7B_compressed
- Qianfan_Chinese_Llama_2_7b
- ChatGLM2_6b_32k
- AquilaChat_7b
- bge_large_zh
- bge_large_en
- 自定义chat模型
- Prompt模版
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.VisualStudio.Validation (>= 17.8.8)
- System.Text.Json (>= 8.0.2)
- System.Threading.RateLimiting (>= 8.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ERNIE-Bot.SDK:
| Package | Downloads |
|---|---|
|
ERNIE-Bot.SemanticKernel
ERNIE-Bot(文心千帆) 集成 Semantic Kernel |
|
|
ERNIE-Bot.KernelMemory
Package Description |
|
|
Thor.ErnieBot
Thor(雷神托尔)AI网关,用于管理AI大模型服务。 |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on ERNIE-Bot.SDK:
| Repository | Stars |
|---|---|
|
AIDotNet/Thor
Thor is a powerful artificial intelligence model management tool, whose main purpose is to achieve unified management and use of multiple AI models. Through Thor, users can easily manage and utilize numerous AI models
|
| Version | Downloads | Last Updated |
|---|---|---|
| 0.14.4 | 5,342 | 3/19/2024 |
| 0.14.3 | 332 | 3/19/2024 |
| 0.14.2 | 294 | 3/18/2024 |
| 0.14.1 | 411 | 2/18/2024 |
| 0.14.0 | 304 | 2/6/2024 |
| 0.13.1 | 349 | 1/16/2024 |
| 0.13.0 | 2,311 | 12/21/2023 |
| 0.12.0-preview | 323 | 12/11/2023 |
| 0.11.0-preview | 316 | 12/5/2023 |
| 0.10.0-preview | 336 | 11/28/2023 |
| 0.9.0-preview | 319 | 11/23/2023 |
| 0.8.0-preview | 271 | 11/14/2023 |
| 0.7.0-preview | 747 | 10/16/2023 |
| 0.6.1-preview | 335 | 9/6/2023 |
| 0.6.0-preview | 272 | 9/5/2023 |
| 0.5.1-preview | 1,220 | 8/31/2023 |
| 0.5.0-preview | 350 | 8/29/2023 |
| 0.4.0-preview | 269 | 8/29/2023 |
| 0.3.2-preview | 661 | 7/11/2023 |
| 0.3.1-preview | 359 | 7/6/2023 |