All checks were successful
CI Monitor MIflow / build-image (push) Successful in 2m42s
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { Logger } from "winston"
|
||
|
||
import chatTools from "../../utils/chatTools"
|
||
import { Inputs } from "./utils/inputs"
|
||
import { Prompts } from "./utils/prompts"
|
||
|
||
/**
|
||
* 总结合并请求的变更。
|
||
* @param {Map<string, string>} summarizedFileMap - 一个包含文件路径和对应摘要的Map。
|
||
* @param {Inputs} rawInputs - 输入数据的实例。
|
||
* @param {Logger} logger - 用于记录日志的Logger实例。
|
||
* @returns {Promise<string>} 返回包含总结的Promise字符串。
|
||
*/
|
||
const summaryMr = async (
|
||
summarizedFileMap: Map<string, string>,
|
||
rawInputs: Inputs,
|
||
logger: Logger
|
||
) => {
|
||
// 创建Prompts实例
|
||
const prompts = new Prompts()
|
||
// 克隆输入数据
|
||
const inputs = rawInputs.clone()
|
||
|
||
// 遍历summarizedFileMap,将每个文件的摘要添加到rawSummary中
|
||
summarizedFileMap.forEach((summarize, path) => {
|
||
inputs.rawSummary += `---
|
||
${path}: ${summarize}
|
||
`
|
||
})
|
||
// 记录完整的变更日志
|
||
logger.debug(`full changes: ${inputs.rawSummary}`)
|
||
|
||
// 渲染总结提示
|
||
const summarizePrompt = prompts.renderSummarize(inputs)
|
||
|
||
// 记录总结提示日志
|
||
logger.debug(`summarizePrompt for Mr: ${summarizePrompt}`)
|
||
|
||
// 获取GPT-4o模型实例
|
||
const codeChatBot = await chatTools.getGpt4oModel(0)
|
||
|
||
try {
|
||
// 调用模型生成总结
|
||
const { content: summarize } = await codeChatBot.invoke(summarizePrompt)
|
||
if (!summarize) throw new Error("Empty summarize")
|
||
// 记录总结日志
|
||
logger.debug(`summarize for Mr: ${summarize}`)
|
||
return summarize as string
|
||
} catch {
|
||
// 记录错误日志
|
||
logger.error(`Failed to summarize for Mr`)
|
||
return ""
|
||
}
|
||
}
|
||
|
||
export default summaryMr
|