refactor: 移除代码补全兼容逻辑并优化 DTO 可空类型处理
This commit is contained in:
@@ -28,64 +28,7 @@ public class ThorChatCompletionsRequest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[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 = """
|
|
||||||
You are a code modification assistant. Your task is to modify the provided code based on the user's instructions.
|
|
||||||
|
|
||||||
Rules:
|
|
||||||
1. Return only the modified code, with no additional text or explanations.
|
|
||||||
2. The first character of your response must be the first character of the code.
|
|
||||||
3. The last character of your response must be the last character of the code.
|
|
||||||
4. NEVER use triple backticks (```) or any other markdown formatting in your response.
|
|
||||||
5. Do not use any code block indicators, syntax highlighting markers, or any other formatting characters.
|
|
||||||
6. Present the code exactly as it would appear in a plain text editor, preserving all whitespace, indentation, and line breaks.
|
|
||||||
7. Maintain the original code structure and only make changes as specified by the user's instructions.
|
|
||||||
8. Ensure that the modified code is syntactically and semantically correct for the given programming language.
|
|
||||||
9. Use consistent indentation and follow language-specific style guidelines.
|
|
||||||
10. If the user's request cannot be translated into code changes, respond only with the word NULL (without quotes or any formatting).
|
|
||||||
11. Do not include any comments or explanations within the code unless specifically requested.
|
|
||||||
12. Assume that any necessary dependencies or libraries are already imported or available.
|
|
||||||
|
|
||||||
IMPORTANT: Your response must NEVER begin or end with triple backticks, single backticks, or any other formatting characters.
|
|
||||||
|
|
||||||
The relevant context before the current editing content is: {0}.
|
|
||||||
After the current editing content is: {1}.
|
|
||||||
""";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 兼容代码补全
|
|
||||||
/// </summary>
|
|
||||||
public void CompatibleCodeCompletion()
|
|
||||||
{
|
|
||||||
if (Messages is null || !Messages.Any())
|
|
||||||
{
|
|
||||||
//兼容代码补全模式,Prompt为当前代码前内容,Suffix为当前代码后内容
|
|
||||||
Messages = new List<ThorChatMessage>()
|
|
||||||
{
|
|
||||||
new ThorChatMessage
|
|
||||||
{
|
|
||||||
Role = "system",
|
|
||||||
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>
|
||||||
|
|||||||
@@ -51,16 +51,17 @@ public class ThorChatMessage
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发出的消息内容计算,用于json序列号和反序列化,Content 和 Contents 不能同时赋值,只能二选一
|
/// 发出的消息内容计算,用于json序列号和反序列化,Content 和 Contents 不能同时赋值,只能二选一
|
||||||
|
/// 如果是工具调用,还真可能为空
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("content")]
|
[JsonPropertyName("content")]
|
||||||
public object ContentCalculated
|
public object? ContentCalculated
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Content is not null && Contents is not null)
|
// if (Content is not null && Contents is not null)
|
||||||
{
|
// {
|
||||||
throw new ValidationException("Messages 中 Content 和 Contents 字段不能同时有值");
|
// throw new ValidationException("Messages 中 Content 和 Contents 字段不能同时有值");
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (Content is not null)
|
if (Content is not null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ public class ThorToolFunctionDefinition
|
|||||||
/// documentation about the format.
|
/// documentation about the format.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("parameters")]
|
[JsonPropertyName("parameters")]
|
||||||
public ThorToolFunctionPropertyDefinition Parameters { get; set; }
|
public ThorToolFunctionPropertyDefinition? Parameters { get; set; }
|
||||||
}
|
}
|
||||||
@@ -55,14 +55,14 @@ public class ThorToolFunctionPropertyDefinition
|
|||||||
/// 必填的。函数参数对象类型。默认值为“object”。
|
/// 必填的。函数参数对象类型。默认值为“object”。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("type")]
|
[JsonPropertyName("type")]
|
||||||
public string Type { get; set; } = "object";
|
public object Type { get; set; } = "object";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 可选。“函数参数”列表,作为从参数名称映射的字典
|
/// 可选。“函数参数”列表,作为从参数名称映射的字典
|
||||||
/// 对于描述类型的对象,可能还有可能的枚举值等等。
|
/// 对于描述类型的对象,可能还有可能的枚举值等等。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("properties")]
|
[JsonPropertyName("properties")]
|
||||||
public IDictionary<string, ThorToolFunctionPropertyDefinition>? Properties { get; set; }
|
public IDictionary<string, ThorToolFunctionPropertyDefinition?>? Properties { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 可选。列出必需的“function arguments”列表。
|
/// 可选。列出必需的“function arguments”列表。
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ 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