feat: 兼容代码补全功能

This commit is contained in:
chenchun
2025-07-28 14:39:02 +08:00
parent 1986901031
commit bda4fdf69d
2 changed files with 50 additions and 5 deletions

View File

@@ -9,11 +9,6 @@ namespace Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAi;
/// </summary>
public class ThorChatCompletionsRequest
{
// public ThorChatCompletionsRequest()
// {
// Messages = new List<ThorChatMessage>();
// }
[JsonPropertyName("store")] public bool? Store { get; set; }
/// <summary>
@@ -34,6 +29,50 @@ public class ThorChatCompletionsRequest
[JsonPropertyName("messages")]
public List<ThorChatMessage>? Messages { get; set; }
/// <summary>
/// 兼容-代码补全
/// </summary>
[JsonPropertyName("suffix")]
public string? Suffix { get; set; }
/// <summary>
/// 兼容-代码补全
/// </summary>
[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}
4Do not include ``` markdown format in the output, display it directly in plain text
5The 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
""";
/// <summary>
/// 兼容代码补全
/// </summary>
public void CompatibleCodeCompletion()
{
if (Messages is null || !Messages.Any())
{
Messages = new List<ThorChatMessage>()
{
new ThorChatMessage
{
Role = "user",
Content = string.Format(CodeCompletionPrompt, Prompt, Suffix)
}
};
}
Suffix = null;
Prompt = null;
}
/// <summary>
/// 模型唯一编码值,如 gpt-4gpt-3.5-turbo,moonshot-v1-8k看底层具体平台定义
/// </summary>

View File

@@ -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<SpecialCompatibleOptions>(options =>
{
options.Handles.add(request =>
{
request.CompatibleCodeCompletion();
});
options.Handles.Add(request =>
{
if (request.Model == "o1")