zhaoyingbo b530229e90
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 59s
feat: 修改打印逻辑 & 请求等待结果
2024-08-13 01:30:15 +00:00

57 lines
1.6 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.

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.info(`summarize for Mr: ${summarize}`)
return summarize as string
} catch {
// 记录错误日志
logger.error(`Failed to summarize for Mr`)
return ""
}
}
export default summaryMr