mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 22:07:10 +00:00
测试一下
This commit is contained in:
parent
c6812abc64
commit
d1ca268f36
1 changed files with 19 additions and 10 deletions
|
|
@ -54,20 +54,29 @@ export class CodeExecutionTool extends AbstractTool {
|
||||||
const result = await this.executeCode(code, language, description);
|
const result = await this.executeCode(code, language, description);
|
||||||
console.debug(`[CodeExecutionTool] 执行结果:`, result);
|
console.debug(`[CodeExecutionTool] 执行结果:`, result);
|
||||||
|
|
||||||
// 构建转发消息
|
// 优化消息构建逻辑
|
||||||
const { output, explanation, error } = result;
|
const messages = [];
|
||||||
const forwardMsg = [];
|
|
||||||
|
|
||||||
if (error) {
|
// 添加代码信息
|
||||||
forwardMsg.push(`执行出错:\n${error}`);
|
messages.push(`执行代码:\n\`\`\`${language}\n${code}\n\`\`\``);
|
||||||
|
|
||||||
|
// 添加执行结果
|
||||||
|
if (result.error) {
|
||||||
|
messages.push(`执行错误:\n\`\`\`\n${result.error}\n\`\`\``);
|
||||||
} else {
|
} else {
|
||||||
forwardMsg.push(`执行结果:\n${output}`);
|
messages.push(`执行结果:\n\`\`\`\n${result.output}\n\`\`\``);
|
||||||
if (explanation) {
|
|
||||||
forwardMsg.push(`\n代码分析:\n${explanation}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e.reply(await common.makeForwardMsg(e, forwardMsg, `${e.sender.card || e.sender.nickname || e.user_id}的代码执行结果`));
|
// 添加代码分析
|
||||||
|
if (result.explanation) {
|
||||||
|
messages.push(`代码分析:\n${result.explanation}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加执行时间
|
||||||
|
messages.push(`执行时间:${new Date(result.executionTime).toLocaleString()}`);
|
||||||
|
|
||||||
|
// 发送转发消息
|
||||||
|
e.reply(await common.makeForwardMsg(e, messages, `${e.sender.card || e.sender.nickname || e.user_id}的代码执行结果`));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue