From cc3da1ec3f5da98f04204813c5b698ed8576dcb0 Mon Sep 17 00:00:00 2001 From: xbotter Date: Mon, 19 Feb 2024 13:27:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A7=20Update=20ERNIE=20Bot=20SDK?= =?UTF-8?q?=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove unused package references - Add new ERNIE Bot 3.5 models - Add new properties to ChatRequest model --- Directory.Packages.props | 2 -- .../ERNIE-Bot-Semantic-Kernel.Sample.csproj | 1 - src/ERNIE-Bot.SDK/ModelEndpoints.cs | 12 +++++++- src/ERNIE-Bot.SDK/Models/ChatRequest.cs | 30 ++++++++++++++++++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 17b53ce..c22d7f5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,7 +7,6 @@ - @@ -15,7 +14,6 @@ - diff --git a/samples/SK-ERNIE-Bot.Sample/ERNIE-Bot-Semantic-Kernel.Sample.csproj b/samples/SK-ERNIE-Bot.Sample/ERNIE-Bot-Semantic-Kernel.Sample.csproj index e64c335..7f05f82 100644 --- a/samples/SK-ERNIE-Bot.Sample/ERNIE-Bot-Semantic-Kernel.Sample.csproj +++ b/samples/SK-ERNIE-Bot.Sample/ERNIE-Bot-Semantic-Kernel.Sample.csproj @@ -14,7 +14,6 @@ - diff --git a/src/ERNIE-Bot.SDK/ModelEndpoints.cs b/src/ERNIE-Bot.SDK/ModelEndpoints.cs index db1b294..5f73ac0 100644 --- a/src/ERNIE-Bot.SDK/ModelEndpoints.cs +++ b/src/ERNIE-Bot.SDK/ModelEndpoints.cs @@ -10,13 +10,23 @@ public static class ModelEndpoints /// /// ERNIE Bot 4 Chat Model /// - public static readonly ModelEndpoint ERNIE_Bot_4 = new("completions_pro"); + public static readonly ModelEndpoint ERNIE_Bot_4 = new("completions_pro", 5000); /// /// ERNIE Bot Chat Model /// public static readonly ModelEndpoint ERNIE_Bot = new("completions"); + /// + /// + /// + public static readonly ModelEndpoint ERNIE_Bot_35_4K_0205 = new("ernie-3.5-4k-0205"); + + /// + /// + /// + public static readonly ModelEndpoint ERNIE_Bot_35_8K_0205 = new("ernie-3.5-8k-0205"); + /// /// ERNIE Bot Turbo Chat Model /// diff --git a/src/ERNIE-Bot.SDK/Models/ChatRequest.cs b/src/ERNIE-Bot.SDK/Models/ChatRequest.cs index c13ac95..e320132 100644 --- a/src/ERNIE-Bot.SDK/Models/ChatRequest.cs +++ b/src/ERNIE-Bot.SDK/Models/ChatRequest.cs @@ -43,6 +43,32 @@ public class ChatCompletionsRequest : ChatRequest [JsonPropertyName("max_output_tokens")] public int? MaxTokens { get; set; } + /// + /// 生成停止标识,当模型生成结果以stop中某个元素结尾时,停止文本生成。 + ///
说明: + ///
(1)每个元素长度不超过20字符 + ///
(2)最多4个元素 + ///
+ [JsonPropertyName("stop")] + public string[]? Stops { get; set; } + + /// + /// 是否强制关闭实时搜索功能,默认false,表示不关闭 + /// + [JsonPropertyName("disable_search")] + public bool? DisableSearch { get; set; } + + /// + /// 是否开启引用返回,说明: + ///(1)开启后,有概率触发搜索溯源信息search_info,search_info内容见响应参数介绍 + ///(2)默认false,不开启 + [JsonPropertyName("enable_citation")] + public bool? EnableCitation { get; set; } + } + + public class FunctionInfo + { + } public class Message @@ -52,8 +78,10 @@ public class Message [JsonPropertyName("content")] public string Content { get; set; } = string.Empty; - } + [JsonPropertyName("name")] + public string? Name { get; set; } + } public static class MessageRole { public const string User = "user"; From b6811dd69c4aabc1dd3b2cd3ec569ff94296cf6d Mon Sep 17 00:00:00 2001 From: xbotter Date: Mon, 19 Feb 2024 13:39:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=84=20Rename=20TokenResponse=20to?= =?UTF-8?q?=20AccessTokenResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Renamed TokenResponse to AccessTokenResponse in ERNIE-Bot.SDK.Models namespace. - Updated references to the renamed class in ERNIEBotClient.cs. - Improved clarity and accuracy of the code. --- src/ERNIE-Bot.SDK/ERNIEBotClient.cs | 2 +- .../Models/{TokenResponse.cs => AccessTokenResponse.cs} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/ERNIE-Bot.SDK/Models/{TokenResponse.cs => AccessTokenResponse.cs} (95%) diff --git a/src/ERNIE-Bot.SDK/ERNIEBotClient.cs b/src/ERNIE-Bot.SDK/ERNIEBotClient.cs index 2e75896..6afa49d 100644 --- a/src/ERNIE-Bot.SDK/ERNIEBotClient.cs +++ b/src/ERNIE-Bot.SDK/ERNIEBotClient.cs @@ -154,7 +154,7 @@ public async Task GetAccessTokenAsync(CancellationToken cancellationToke var webRequest = new HttpRequestMessage(HttpMethod.Post, url); var response = await _client.SendAsync(webRequest, cancellationToken); - var accessToken = await ParseResponseAsync(response); + var accessToken = await ParseResponseAsync(response); if (string.IsNullOrWhiteSpace(accessToken.AccessToken)) { diff --git a/src/ERNIE-Bot.SDK/Models/TokenResponse.cs b/src/ERNIE-Bot.SDK/Models/AccessTokenResponse.cs similarity index 95% rename from src/ERNIE-Bot.SDK/Models/TokenResponse.cs rename to src/ERNIE-Bot.SDK/Models/AccessTokenResponse.cs index 9b4cae2..1030bb8 100644 --- a/src/ERNIE-Bot.SDK/Models/TokenResponse.cs +++ b/src/ERNIE-Bot.SDK/Models/AccessTokenResponse.cs @@ -5,7 +5,7 @@ namespace ERNIE_Bot.SDK.Models /// /// Access Token Response /// - public class TokenResponse + public class AccessTokenResponse { [JsonPropertyName("access_token")] public string AccessToken { get; set; } = string.Empty;