diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/OpenAi/ThorChatCompletionsRequest.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/OpenAi/ThorChatCompletionsRequest.cs index fe84a991..0c83885b 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/OpenAi/ThorChatCompletionsRequest.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/OpenAi/ThorChatCompletionsRequest.cs @@ -9,11 +9,6 @@ namespace Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAi; /// public class ThorChatCompletionsRequest { - // public ThorChatCompletionsRequest() - // { - // Messages = new List(); - // } - [JsonPropertyName("store")] public bool? Store { get; set; } /// @@ -34,6 +29,50 @@ public class ThorChatCompletionsRequest [JsonPropertyName("messages")] public List? Messages { get; set; } + /// + /// 兼容-代码补全 + /// + [JsonPropertyName("suffix")] + public string? Suffix { get; set; } + + /// + /// 兼容-代码补全 + /// + [JsonPropertyName("prompt")] + public string? Prompt { get; set; } + + private const string CodeCompletionPrompt = """ + Provide the provided content, predict and complete the code: + Requirement: + 1:Only need to output completion content, do not add additional content + 2:The last part of the code that needs to be completed is :{0} + 3:The following is the provided context and the preceding section :{1} + 4:Do not include ``` markdown format in the output, display it directly in plain text + 5:The returned content should not be duplicated with the given part. Remove the duplicated parts and complete them backwards + 6: The returned comments need to be in Chinese + """; + + /// + /// 兼容代码补全 + /// + public void CompatibleCodeCompletion() + { + if (Messages is null || !Messages.Any()) + { + Messages = new List() + { + new ThorChatMessage + { + Role = "user", + Content = string.Format(CodeCompletionPrompt, Prompt, Suffix) + } + }; + } + + Suffix = null; + Prompt = null; + } + /// /// 模型唯一编码值,如 gpt-4,gpt-3.5-turbo,moonshot-v1-8k,看底层具体平台定义 /// diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/YiFrameworkAiHubDomainModule.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/YiFrameworkAiHubDomainModule.cs index bd70b201..3e76b59e 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/YiFrameworkAiHubDomainModule.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/YiFrameworkAiHubDomainModule.cs @@ -1,3 +1,4 @@ +using Dm.util; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Domain; using Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAi; @@ -33,6 +34,11 @@ namespace Yi.Framework.AiHub.Domain //ai模型特殊性兼容处理 Configure(options => { + options.Handles.add(request => + { + request.CompatibleCodeCompletion(); + }); + options.Handles.Add(request => { if (request.Model == "o1")