feat: 兼容代码补全功能
This commit is contained in:
@@ -9,11 +9,6 @@ namespace Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAi;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ThorChatCompletionsRequest
|
public class ThorChatCompletionsRequest
|
||||||
{
|
{
|
||||||
// public ThorChatCompletionsRequest()
|
|
||||||
// {
|
|
||||||
// Messages = new List<ThorChatMessage>();
|
|
||||||
// }
|
|
||||||
|
|
||||||
[JsonPropertyName("store")] public bool? Store { get; set; }
|
[JsonPropertyName("store")] public bool? Store { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -34,6 +29,50 @@ public class ThorChatCompletionsRequest
|
|||||||
[JsonPropertyName("messages")]
|
[JsonPropertyName("messages")]
|
||||||
public List<ThorChatMessage>? Messages { get; set; }
|
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}
|
||||||
|
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
|
||||||
|
""";
|
||||||
|
|
||||||
|
/// <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>
|
/// <summary>
|
||||||
/// 模型唯一编码值,如 gpt-4,gpt-3.5-turbo,moonshot-v1-8k,看底层具体平台定义
|
/// 模型唯一编码值,如 gpt-4,gpt-3.5-turbo,moonshot-v1-8k,看底层具体平台定义
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Dm.util;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Volo.Abp.Domain;
|
using Volo.Abp.Domain;
|
||||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAi;
|
using Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAi;
|
||||||
@@ -33,6 +34,11 @@ namespace Yi.Framework.AiHub.Domain
|
|||||||
//ai模型特殊性兼容处理
|
//ai模型特殊性兼容处理
|
||||||
Configure<SpecialCompatibleOptions>(options =>
|
Configure<SpecialCompatibleOptions>(options =>
|
||||||
{
|
{
|
||||||
|
options.Handles.add(request =>
|
||||||
|
{
|
||||||
|
request.CompatibleCodeCompletion();
|
||||||
|
});
|
||||||
|
|
||||||
options.Handles.Add(request =>
|
options.Handles.Add(request =>
|
||||||
{
|
{
|
||||||
if (request.Model == "o1")
|
if (request.Model == "o1")
|
||||||
|
|||||||
Reference in New Issue
Block a user