@comate/zulu 0.7.4-beta.1 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44491,6 +44491,7 @@ const RESULT_TIMEOUT_TIMR = 5 * 60 * 1000;
44491
44491
  const REPAIR_STATUS_URL = 'https://uflow.baidu-int.com/workflow/api/flow/v1/trigger-webhook/985e90acabd0416392ddf8f3c69b0869';
44492
44492
  const REPAIR_PROMPT_URL = 'http://uflow.baidu-int.com/workflow/api/flow/v1/trigger-webhook/0b4aff3e4e614fec902f80f8c2414d5b';
44493
44493
  const GET_CODE_REQUIRE = 'https://uflow.baidu-int.com/workflow/api/flow/v1/trigger-webhook/de514c00d3ca438581940f0bb0bb1f3c';
44494
+ const REPAIR_LINE_URL = 'https://uflow.baidu-int.com/workflow/api/flow/v1/trigger-webhook/c8e8077c9fe340ea9240dff7b0976cbe';
44494
44495
 
44495
44496
  // @ts-expect-error ESM兼容
44496
44497
  class BosUtil {
@@ -51670,6 +51671,41 @@ async function getJobBuildId(realUserName, module, branch) {
51670
51671
  return result.data;
51671
51672
  }
51672
51673
 
51674
+ // 默认语言推荐文件修复长度映射
51675
+ const DEFAULT_LANGUAGE_RECOMMEND_LENGTH_MAP = {
51676
+ 'PYTHON': 200,
51677
+ 'JAVA': 500,
51678
+ 'GO': 300,
51679
+ 'JS': 300,
51680
+ 'OTHER': 300
51681
+ };
51682
+ // 获取语言推荐文件修复长度映射
51683
+ async function getLanguageRecommendedLengthMap() {
51684
+ try {
51685
+ const response = await fetch(REPAIR_LINE_URL, {
51686
+ method: 'POST',
51687
+ headers: {
51688
+ 'Content-Type': 'application/json'
51689
+ }
51690
+ });
51691
+ if (!response.ok) {
51692
+ throw new Error(`HTTP error! status: ${response.status}`);
51693
+ }
51694
+ const result = await response.json();
51695
+ // 假设接口返回的数据格式与 DEFAULT_LANGUAGE_RECOMMEND_LENGTH_MAP 相同
51696
+ // 如果接口返回格式不同,需要根据实际情况调整
51697
+ if (result.data && typeof result.data === 'object') {
51698
+ console.log('22222222222@@@@2222222222');
51699
+ console.log(JSON.stringify(result.data));
51700
+ return result.data;
51701
+ }
51702
+ // 如果接口返回格式不符合预期,使用默认值
51703
+ return DEFAULT_LANGUAGE_RECOMMEND_LENGTH_MAP;
51704
+ } catch (error) {
51705
+ console.log('获取语言推荐长度映射失败:', error);
51706
+ return DEFAULT_LANGUAGE_RECOMMEND_LENGTH_MAP;
51707
+ }
51708
+ }
51673
51709
  function removeFirstAndLastLines(content) {
51674
51710
  // 按行分割字符串
51675
51711
  const lines = content.split(/\r?\n/);
@@ -51682,10 +51718,51 @@ function removeFirstAndLastLines(content) {
51682
51718
  // 重新组合为字符串
51683
51719
  return remainingLines.join('\n');
51684
51720
  }
51685
- function processBugListAndFile(bugList, fileContent) {
51721
+ async function processBugListAndFile(bugList, fileContent) {
51686
51722
  // 将文件内容按行分割成数组
51687
51723
  const fileLines = fileContent.split('\n');
51688
51724
  const totalFileLines = fileLines.length;
51725
+ // 判断文件语言类型
51726
+ let languageType = 'OTHER';
51727
+ const filename = bugList[0]?.file_path || '';
51728
+ const extension = filename.split('.').pop()?.toLowerCase();
51729
+ if (extension === 'py') {
51730
+ languageType = 'PYTHON';
51731
+ } else if (extension === 'java') {
51732
+ languageType = 'JAVA';
51733
+ } else if (extension === 'go') {
51734
+ languageType = 'GO';
51735
+ } else if ([
51736
+ 'js',
51737
+ 'jsx',
51738
+ 'ts',
51739
+ 'tsx',
51740
+ 'vue'
51741
+ ].includes(extension || '')) {
51742
+ languageType = 'JS';
51743
+ }
51744
+ // 获取语言推荐长度映射
51745
+ const languageLengthMap = await getLanguageRecommendedLengthMap();
51746
+ const recommendLength = languageLengthMap[languageType] || 300;
51747
+ // 如果文件长度不超过推荐长度,直接返回原格式
51748
+ if (totalFileLines <= recommendLength) {
51749
+ const adjustedBugList = bugList.map((bug)=>({
51750
+ line_number: bug.line_number,
51751
+ description: bug.description
51752
+ }));
51753
+ return {
51754
+ fileline: fileContent,
51755
+ needRepairLine: fileContent,
51756
+ frontFile: '',
51757
+ backFile: '',
51758
+ minBugLine: bugList[0]?.line_number || 1,
51759
+ maxBugLine: bugList[bugList.length - 1]?.line_number || 1,
51760
+ startLine: 1,
51761
+ endLine: totalFileLines,
51762
+ bugList: adjustedBugList,
51763
+ totalFileLines
51764
+ };
51765
+ }
51689
51766
  // 1. 获取最小和最大行号
51690
51767
  let minBugLine = Infinity;
51691
51768
  let maxBugLine = -Infinity;
@@ -51706,7 +51783,6 @@ function processBugListAndFile(bugList, fileContent) {
51706
51783
  endLine = Math.min(totalFileLines, maxBugLine + 10);
51707
51784
  }
51708
51785
  // 3. 截取文件内容
51709
- // 4. 如果 startLine != 1,在开头添加提示行
51710
51786
  const extractedLines = fileLines.slice(startLine - 1, endLine);
51711
51787
  let fileline;
51712
51788
  let needRepairLine;
@@ -51726,9 +51802,8 @@ function processBugListAndFile(bugList, fileContent) {
51726
51802
  const adjustedBugList = bugList.map((bug)=>({
51727
51803
  ...bug,
51728
51804
  line_number: startLine === 1 ? bug.line_number - startLine + 1 // 无额外行,正常偏移
51729
- : bug.line_number - startLine + 2
51805
+ : bug.line_number - startLine + 2 // 有额外行,额外 +1
51730
51806
  }));
51731
- console.log(adjustedBugList);
51732
51807
  const simpleBugList = adjustedBugList.map((item)=>({
51733
51808
  line_number: item.line_number,
51734
51809
  description: item.description
@@ -51756,6 +51831,49 @@ function removeFirstLineIfMarker(fileline) {
51756
51831
  }
51757
51832
  return fileline; // 如果不是,原样返回
51758
51833
  }
51834
+ async function processBugListInBatches(fileContent, languageType, originalBugList) {
51835
+ // 获取语言推荐长度映射
51836
+ const languageLengthMap = await getLanguageRecommendedLengthMap();
51837
+ const recommendedLength = languageLengthMap[languageType] || 300;
51838
+ console.log(`Recommended length for ${languageType}: ${recommendedLength}`);
51839
+ // 将文件内容按行分割
51840
+ const fileLines = fileContent.split('\n');
51841
+ const totalLines = fileLines.length;
51842
+ // 如果总行数小于等于推荐长度,直接返回
51843
+ if (totalLines <= recommendedLength) {
51844
+ return [
51845
+ {
51846
+ bugList: originalBugList.map((bug)=>({
51847
+ ...bug,
51848
+ line_number: bug.line_number
51849
+ })),
51850
+ needRepairLine: fileContent
51851
+ }
51852
+ ];
51853
+ }
51854
+ // 按推荐长度分块
51855
+ const batches = [];
51856
+ let startIdx = 0;
51857
+ while(startIdx < totalLines){
51858
+ const endIdx = Math.min(startIdx + recommendedLength, totalLines);
51859
+ const batchContent = fileLines.slice(startIdx, endIdx).join('\n');
51860
+ // 计算当前批次中涉及的 bug
51861
+ const currentBatchBugs = originalBugList.filter((bug)=>{
51862
+ const bugLine = bug.line_number - 1; // 转换为0基准索引
51863
+ return bugLine >= startIdx && bugLine < endIdx;
51864
+ }).map((bug)=>({
51865
+ ...bug,
51866
+ line_number: bug.line_number - startIdx + 1
51867
+ }));
51868
+ batches.push({
51869
+ bugList: currentBatchBugs,
51870
+ needRepairLine: batchContent
51871
+ });
51872
+ startIdx = endIdx;
51873
+ }
51874
+ console.log(JSON.stringify(batches));
51875
+ return batches;
51876
+ }
51759
51877
  async function getPromptText(filename, runtype = 'aiscan') {
51760
51878
  try {
51761
51879
  const response = await fetch(REPAIR_PROMPT_URL, {
@@ -51768,6 +51886,8 @@ async function getPromptText(filename, runtype = 'aiscan') {
51768
51886
  throw new Error(`HTTP error! status: ${response.status}`);
51769
51887
  }
51770
51888
  const result = await response.json();
51889
+ let text = '';
51890
+ let languageType = 'Other';
51771
51891
  // 如果 runtype 为 'icode',增加其他语言支持
51772
51892
  if (runtype === 'icode') {
51773
51893
  const languageInfoMap = new Map([
@@ -51812,16 +51932,22 @@ async function getPromptText(filename, runtype = 'aiscan') {
51812
51932
  }
51813
51933
  ]
51814
51934
  ]);
51935
+ const suffixToLanguageType = new Map();
51815
51936
  const suffixToDisplayString = new Map();
51816
- for (const [_, languageInfo] of languageInfoMap){
51937
+ for (const [langType, languageInfo] of languageInfoMap){
51817
51938
  for (const suffix of languageInfo.suffixes){
51939
+ suffixToLanguageType.set(suffix, langType);
51818
51940
  suffixToDisplayString.set(suffix, languageInfo.displayString);
51819
51941
  }
51820
51942
  }
51821
51943
  const lastDotIndex = filename.lastIndexOf('.');
51822
- if (lastDotIndex === -1) return result.data.Other || '';
51823
- const suffix = filename.slice(lastDotIndex);
51824
- return suffixToDisplayString.get(suffix) || result.data.Other || '';
51944
+ if (lastDotIndex === -1) {
51945
+ text = result.data.Other || '';
51946
+ } else {
51947
+ const suffix = filename.slice(lastDotIndex);
51948
+ languageType = suffixToLanguageType.get(suffix) || 'Other';
51949
+ text = suffixToDisplayString.get(suffix) || result.data.Other || '';
51950
+ }
51825
51951
  } else {
51826
51952
  // 原逻辑:只支持 Java 和 Python
51827
51953
  const languageInfoMap = new Map([
@@ -51844,20 +51970,33 @@ async function getPromptText(filename, runtype = 'aiscan') {
51844
51970
  }
51845
51971
  ]
51846
51972
  ]);
51973
+ const suffixToLanguageType = new Map();
51847
51974
  const suffixToDisplayString = new Map();
51848
- for (const [_, languageInfo] of languageInfoMap){
51975
+ for (const [langType, languageInfo] of languageInfoMap){
51849
51976
  for (const suffix of languageInfo.suffixes){
51977
+ suffixToLanguageType.set(suffix, langType);
51850
51978
  suffixToDisplayString.set(suffix, languageInfo.displayString);
51851
51979
  }
51852
51980
  }
51853
51981
  const lastDotIndex = filename.lastIndexOf('.');
51854
- if (lastDotIndex === -1) return '';
51855
- const suffix = filename.slice(lastDotIndex);
51856
- return suffixToDisplayString.get(suffix) || '';
51982
+ if (lastDotIndex === -1) {
51983
+ text = '';
51984
+ } else {
51985
+ const suffix = filename.slice(lastDotIndex);
51986
+ languageType = suffixToLanguageType.get(suffix) || 'Other';
51987
+ text = suffixToDisplayString.get(suffix) || '';
51988
+ }
51857
51989
  }
51990
+ return {
51991
+ text,
51992
+ languageType
51993
+ };
51858
51994
  } catch (error) {
51859
51995
  console.error('请求失败:', error);
51860
- return '';
51996
+ return {
51997
+ text: '',
51998
+ languageType: 'Other'
51999
+ };
51861
52000
  }
51862
52001
  }
51863
52002
  async function getRepairStatus() {
@@ -52382,7 +52521,9 @@ class codeStyleCheckProvider extends SkillProvider {
52382
52521
  repaireResultStatus = 0;
52383
52522
  }
52384
52523
  try {
52385
- let promptText = await getPromptText(filePath, 'aiscan');
52524
+ let promptResult = await getPromptText(filePath, 'aiscan');
52525
+ let promptText = promptResult.text;
52526
+ let languageType = promptResult.languageType;
52386
52527
  if (promptText != '') {
52387
52528
  // 获取原文件内容
52388
52529
  const fileSystem = await this.requestWorkspaceFileSystem();
@@ -52391,21 +52532,41 @@ class codeStyleCheckProvider extends SkillProvider {
52391
52532
  oldFilecontent = await fileSystem.readFile(filePath, 'utf-8');
52392
52533
  }
52393
52534
  // 截取文件内容,只保留需修复的问题,第一行前10行至,最后一个问题的后10行,其他内容不处理
52394
- const fine_fileContent = processBugListAndFile(allBugs[filePath], oldFilecontent);
52535
+ const fine_fileContent = await processBugListAndFile(allBugs[filePath], oldFilecontent);
52395
52536
  // 调用大模型获取修复文件
52396
- const prompt = this.llm.createPrompt(promptText, {
52397
- 'CODE_ERROR_DETAIL': JSON.stringify(fine_fileContent.bugList, null, 2),
52398
- 'CODE_FILE_CONTENT': fine_fileContent.needRepairLine
52399
- });
52400
- console.info('开始修复时间:', new Date().toLocaleString());
52401
- console.info('prompt:', prompt);
52402
52537
  try {
52403
- const chunk = await this.llm.askForCode(prompt, {
52404
- model: TextModel.ErnieBot4Turbo128
52405
- });
52406
- // 按照格式渲染
52407
- const finalRepairContent = removeFirstAndLastLines(chunk);
52408
- console.info(`修复建议内容:${finalRepairContent}`);
52538
+ // 将第一次切片后的 fine_fileContent 进行重复切片
52539
+ const needrepairlist = await processBugListInBatches(fine_fileContent.needRepairLine, languageType, fine_fileContent.bugList);
52540
+ console.log("needrepairlist==================");
52541
+ console.log(JSON.stringify(needrepairlist));
52542
+ let resultRepairList = [];
52543
+ for (const data of needrepairlist){
52544
+ try {
52545
+ const prompt = this.llm.createPrompt(promptText, {
52546
+ 'CODE_ERROR_DETAIL': JSON.stringify(data.bugList, null, 2),
52547
+ 'CODE_FILE_CONTENT': data.needRepairLine
52548
+ });
52549
+ console.info('开始修复时间:', new Date().toLocaleString());
52550
+ console.info('prompt:', prompt);
52551
+ const chunk = await this.llm.askForCode(prompt, {
52552
+ model: TextModel.ErnieBot4Turbo128
52553
+ });
52554
+ // 按照格式渲染
52555
+ const finalRepairContent = removeFirstAndLastLines(chunk);
52556
+ console.info(`修复建议内容:${finalRepairContent}`);
52557
+ if (chunk != '') {
52558
+ // 循环调用模型,如果当前段失败,则取调用模型前的代码块进行拼接
52559
+ resultRepairList.push(finalRepairContent);
52560
+ } else {
52561
+ resultRepairList.push(data.needRepairLine);
52562
+ }
52563
+ } catch (error) {
52564
+ console.error(`修复失败:${error.message}`);
52565
+ resultRepairList.push(data.needRepairLine);
52566
+ }
52567
+ }
52568
+ // 合并所有修复结果的代码块
52569
+ const finalRepairContent = resultRepairList.join('\n');
52409
52570
  let nowOldFilecontent = '';
52410
52571
  if (fileSystem) {
52411
52572
  nowOldFilecontent = await fileSystem.readFile(filePath, 'utf-8');
@@ -53332,7 +53493,9 @@ class iscanResultProvider extends SkillProvider {
53332
53493
  repaireResultStatus = 0;
53333
53494
  }
53334
53495
  try {
53335
- let promptText = await getPromptText(filePath, 'aiscan');
53496
+ let promptResult = await getPromptText(filePath, 'aiscan');
53497
+ let promptText = promptResult.text;
53498
+ let languageType = promptResult.languageType;
53336
53499
  if (promptText != '') {
53337
53500
  // 获取原文件内容
53338
53501
  const fileSystem = await this.requestWorkspaceFileSystem();
@@ -53341,21 +53504,44 @@ class iscanResultProvider extends SkillProvider {
53341
53504
  oldFilecontent = await fileSystem.readFile(filePath, 'utf-8');
53342
53505
  }
53343
53506
  // 截取文件内容,只保留需修复的问题,第一行前10行至,最后一个问题的后10行,其他内容不处理
53344
- const fine_fileContent = processBugListAndFile(allBugs[filePath], oldFilecontent);
53507
+ const fine_fileContent = await processBugListAndFile(allBugs[filePath], oldFilecontent);
53345
53508
  // 调用大模型获取修复文件
53346
- const prompt = this.llm.createPrompt(promptText, {
53347
- 'CODE_ERROR_DETAIL': JSON.stringify(fine_fileContent.bugList, null, 2),
53348
- 'CODE_FILE_CONTENT': fine_fileContent.needRepairLine
53349
- });
53350
- console.info('开始修复时间:', new Date().toLocaleString());
53351
- console.info('prompt:', prompt);
53352
53509
  try {
53353
- const chunk = await this.llm.askForCode(prompt, {
53354
- model: TextModel.ErnieBot4Turbo128
53355
- });
53356
- // 按照格式渲染
53357
- const finalRepairContent = removeFirstAndLastLines(chunk);
53358
- console.info(`修复建议内容:${finalRepairContent}`);
53510
+ // 将第一次切片后的 fine_fileContent 进行重复切片
53511
+ const needrepairlist = await processBugListInBatches(fine_fileContent.needRepairLine, languageType, fine_fileContent.bugList);
53512
+ console.log("needrepairlist==================");
53513
+ console.log(JSON.stringify(needrepairlist));
53514
+ let resultRepairList = [];
53515
+ for (const data of needrepairlist){
53516
+ try {
53517
+ console.log('running--------------');
53518
+ console.log(JSON.stringify(data.bugList, null, 2));
53519
+ console.log(data.needRepairLine);
53520
+ const prompt = this.llm.createPrompt(promptText, {
53521
+ 'CODE_ERROR_DETAIL': JSON.stringify(data.bugList, null, 2),
53522
+ 'CODE_FILE_CONTENT': data.needRepairLine
53523
+ });
53524
+ console.info('开始修复时间:', new Date().toLocaleString());
53525
+ console.info('prompt:', prompt);
53526
+ const chunk = await this.llm.askForCode(prompt, {
53527
+ model: TextModel.ErnieBot4Turbo128
53528
+ });
53529
+ // 按照格式渲染
53530
+ const finalRepairContent = removeFirstAndLastLines(chunk);
53531
+ console.info(`修复建议内容:${finalRepairContent}`);
53532
+ if (chunk != '') {
53533
+ // 循环调用模型,如果当前段失败,则取调用模型前的代码块进行拼接
53534
+ resultRepairList.push(finalRepairContent);
53535
+ } else {
53536
+ resultRepairList.push(data.needRepairLine);
53537
+ }
53538
+ } catch (error) {
53539
+ console.info(`修复失败:${error.message}`);
53540
+ resultRepairList.push(data.needRepairLine);
53541
+ }
53542
+ }
53543
+ // 合并所有修复结果的代码块
53544
+ const finalRepairContent = resultRepairList.join('\n');
53359
53545
  let nowOldFilecontent = '';
53360
53546
  if (fileSystem) {
53361
53547
  nowOldFilecontent = await fileSystem.readFile(filePath, 'utf-8');
@@ -53832,29 +54018,52 @@ class checkResultByIdProvider extends SkillProvider {
53832
54018
  repaireResultStatus = 0;
53833
54019
  }
53834
54020
  try {
53835
- // 获取原文件内容
53836
- let promptText = await getPromptText(filePath, 'icode');
53837
- if (promptText !== '') {
53838
- // 展示修复loading
54021
+ let promptResult = await getPromptText(filePath, 'aiscan');
54022
+ let promptText = promptResult.text;
54023
+ let languageType = promptResult.languageType;
54024
+ if (promptText != '') {
54025
+ // 获取原文件内容
53839
54026
  const fileSystem = await this.requestWorkspaceFileSystem();
53840
54027
  let oldFilecontent = '';
53841
54028
  if (fileSystem) {
53842
54029
  oldFilecontent = await fileSystem.readFile(filePath, 'utf-8');
53843
54030
  }
53844
54031
  // 截取文件内容,只保留需修复的问题,第一行前10行至,最后一个问题的后10行,其他内容不处理
53845
- const fine_fileContent = processBugListAndFile(bugsDetail, oldFilecontent);
53846
- console.log('filePath:', filePath, 'bugsDetail:', fine_fileContent);
54032
+ const fine_fileContent = await processBugListAndFile(bugsDetail, oldFilecontent);
53847
54033
  // 调用大模型获取修复文件
53848
54034
  try {
53849
- const prompt = this.llm.createPrompt(promptText, {
53850
- 'CODE_ERROR_DETAIL': JSON.stringify(fine_fileContent.bugList, null, 2),
53851
- 'CODE_FILE_CONTENT': fine_fileContent.needRepairLine
53852
- });
53853
- const chunk = await this.llm.askForCode(prompt, {
53854
- model: TextModel.ErnieBot4Turbo128
53855
- });
53856
- // 按照格式渲染
53857
- const finalRepairContent = removeFirstAndLastLines(chunk);
54035
+ // 将第一次切片后的 fine_fileContent 进行重复切片
54036
+ const needrepairlist = await processBugListInBatches(fine_fileContent.needRepairLine, languageType, fine_fileContent.bugList);
54037
+ console.log("needrepairlist==================");
54038
+ console.log(JSON.stringify(needrepairlist));
54039
+ let resultRepairList = [];
54040
+ for (const data of needrepairlist){
54041
+ try {
54042
+ const prompt = this.llm.createPrompt(promptText, {
54043
+ 'CODE_ERROR_DETAIL': JSON.stringify(data.bugList, null, 2),
54044
+ 'CODE_FILE_CONTENT': data.needRepairLine
54045
+ });
54046
+ console.info('开始修复时间:', new Date().toLocaleString());
54047
+ console.info('prompt:', prompt);
54048
+ const chunk = await this.llm.askForCode(prompt, {
54049
+ model: TextModel.ErnieBot4Turbo128
54050
+ });
54051
+ // 按照格式渲染
54052
+ const finalRepairContent = removeFirstAndLastLines(chunk);
54053
+ console.info(`修复建议内容:${finalRepairContent}`);
54054
+ if (chunk != '') {
54055
+ // 循环调用模型,如果当前段失败,则取调用模型前的代码块进行拼接
54056
+ resultRepairList.push(finalRepairContent);
54057
+ } else {
54058
+ resultRepairList.push(data.needRepairLine);
54059
+ }
54060
+ } catch (error) {
54061
+ console.error(`修复失败:${error.message}`);
54062
+ resultRepairList.push(data.needRepairLine);
54063
+ }
54064
+ }
54065
+ // 合并所有修复结果的代码块
54066
+ const finalRepairContent = resultRepairList.join('\n');
53858
54067
  let nowOldFilecontent = '';
53859
54068
  if (fileSystem) {
53860
54069
  nowOldFilecontent = await fileSystem.readFile(filePath, 'utf-8');
@@ -54198,30 +54407,52 @@ class checkResultByIdProvider extends SkillProvider {
54198
54407
  repaireResultStatus = 0;
54199
54408
  }
54200
54409
  try {
54201
- // 获取原文件内容
54202
- let promptText = await getPromptText(filePath, 'icode');
54203
- if (promptText !== '') {
54204
- // 展示修复loading
54410
+ let promptResult = await getPromptText(filePath, 'aiscan');
54411
+ let promptText = promptResult.text;
54412
+ let languageType = promptResult.languageType;
54413
+ if (promptText != '') {
54414
+ // 获取原文件内容
54205
54415
  const fileSystem = await this.requestWorkspaceFileSystem();
54206
54416
  let oldFilecontent = '';
54207
54417
  if (fileSystem) {
54208
54418
  oldFilecontent = await fileSystem.readFile(filePath, 'utf-8');
54209
54419
  }
54210
54420
  // 截取文件内容,只保留需修复的问题,第一行前10行至,最后一个问题的后10行,其他内容不处理
54211
- const fine_fileContent = processBugListAndFile(bugsDetail, oldFilecontent);
54212
- console.log('filePath:', filePath, 'bugsDetail:', fine_fileContent);
54421
+ const fine_fileContent = await processBugListAndFile(bugsDetail, oldFilecontent);
54213
54422
  // 调用大模型获取修复文件
54214
- const prompt = this.llm.createPrompt(promptText, {
54215
- 'CODE_ERROR_DETAIL': JSON.stringify(fine_fileContent.bugList, null, 2),
54216
- 'CODE_FILE_CONTENT': fine_fileContent.needRepairLine
54217
- });
54218
- console.log('prompt:', prompt);
54219
54423
  try {
54220
- const chunk = await this.llm.askForCode(prompt, {
54221
- model: TextModel.ErnieBot4Turbo128
54222
- });
54223
- // 按照格式渲染
54224
- const finalRepairContent = removeFirstAndLastLines(chunk);
54424
+ // 将第一次切片后的 fine_fileContent 进行重复切片
54425
+ const needrepairlist = await processBugListInBatches(fine_fileContent.needRepairLine, languageType, fine_fileContent.bugList);
54426
+ console.log("needrepairlist==================");
54427
+ console.log(JSON.stringify(needrepairlist));
54428
+ let resultRepairList = [];
54429
+ for (const data of needrepairlist){
54430
+ try {
54431
+ const prompt = this.llm.createPrompt(promptText, {
54432
+ 'CODE_ERROR_DETAIL': JSON.stringify(data.bugList, null, 2),
54433
+ 'CODE_FILE_CONTENT': data.needRepairLine
54434
+ });
54435
+ console.info('开始修复时间:', new Date().toLocaleString());
54436
+ console.info('prompt:', prompt);
54437
+ const chunk = await this.llm.askForCode(prompt, {
54438
+ model: TextModel.ErnieBot4Turbo128
54439
+ });
54440
+ // 按照格式渲染
54441
+ const finalRepairContent = removeFirstAndLastLines(chunk);
54442
+ console.info(`修复建议内容:${finalRepairContent}`);
54443
+ if (chunk != '') {
54444
+ // 循环调用模型,如果当前段失败,则取调用模型前的代码块进行拼接
54445
+ resultRepairList.push(finalRepairContent);
54446
+ } else {
54447
+ resultRepairList.push(data.needRepairLine);
54448
+ }
54449
+ } catch (error) {
54450
+ console.error(`修复失败:${error.message}`);
54451
+ resultRepairList.push(data.needRepairLine);
54452
+ }
54453
+ }
54454
+ // 合并所有修复结果的代码块
54455
+ const finalRepairContent = resultRepairList.join('\n');
54225
54456
  let nowOldFilecontent = '';
54226
54457
  if (fileSystem) {
54227
54458
  nowOldFilecontent = await fileSystem.readFile(filePath, 'utf-8');