zhaoyingbo 92fa30ef3d
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 2m42s
feat: 支持初步的CR
2024-08-12 12:24:45 +00:00

129 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 生成系统消息,包含知识截止日期和当前日期。
* @returns {string} 返回包含系统消息的字符串。
*/
const genSystemMessage = () => {
return `
知识截止日期: 2023-12-01
当前日期: ${new Date().toISOString().split("T")[0]}
重要提示: 整个回复必须使用ISO代码为zh的语言
`
}
/**
* Inputs类用于存储和处理各种输入数据。
*/
export class Inputs {
systemMessage: string
title: string
description: string
rawSummary: string
shortSummary: string
filename: string
fileContent: string
fileDiff: string
patches: string
diff: string
commentChain: string
comment: string
/**
* 构造函数初始化Inputs类的实例。
* @param {string} [systemMessage=""] - 系统消息。
* @param {string} [title="no title provided"] - 标题。
* @param {string} [description="no description provided"] - 描述。
* @param {string} [rawSummary=""] - 原始摘要。
* @param {string} [shortSummary=""] - 简短摘要。
* @param {string} [filename=""] - 文件名。
* @param {string} [fileContent="file contents cannot be provided"] - 文件内容。
* @param {string} [fileDiff="file diff cannot be provided"] - 文件差异。
* @param {string} [patches=""] - 补丁。
* @param {string} [diff="no diff"] - 差异。
* @param {string} [commentChain="no other comments on this patch"] - 评论链。
* @param {string} [comment="no comment provided"] - 评论。
*/
constructor(
systemMessage = "",
title = "no title provided",
description = "no description provided",
rawSummary = "",
shortSummary = "",
filename = "",
fileContent = "file contents cannot be provided",
fileDiff = "file diff cannot be provided",
patches = "",
diff = "no diff",
commentChain = "no other comments on this patch",
comment = "no comment provided"
) {
this.systemMessage = systemMessage || genSystemMessage()
this.title = title
this.description = description
this.rawSummary = rawSummary
this.shortSummary = shortSummary
this.filename = filename
this.fileContent = fileContent
this.fileDiff = fileDiff
this.patches = patches
this.diff = diff
this.commentChain = commentChain
this.comment = comment
}
/**
* 克隆当前Inputs实例。
* @returns {Inputs} 返回当前对象的副本。
*/
clone(): Inputs {
return new Inputs(
this.systemMessage,
this.title,
this.description,
this.rawSummary,
this.shortSummary,
this.filename,
this.fileContent,
this.fileDiff,
this.patches,
this.diff,
this.commentChain,
this.comment
)
}
/**
* 渲染内容,将占位符替换为实际值。
* @param {string} content - 包含占位符的内容。
* @returns {string} 返回替换后的内容。
*/
render(content: string): string {
if (!content) {
return ""
}
const replacements = {
$system_message: this.systemMessage,
$title: this.title,
$description: this.description,
$raw_summary: this.rawSummary,
$short_summary: this.shortSummary,
$filename: this.filename,
$file_content: this.fileContent,
$file_diff: this.fileDiff,
$patches: this.patches,
$diff: this.diff,
$comment_chain: this.commentChain,
$comment: this.comment,
}
for (const [key, value] of Object.entries(replacements)) {
if (value) {
content = content.replace(key, value)
}
}
return content
}
}