Skip to content

Commit 7af91d3

Browse files
committed
feat:上下文超过一定长度就自动启动预处理压缩
1 parent 49b8823 commit 7af91d3

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/cvbManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,19 +961,19 @@ function func2() {
961961

962962
const systemContent = "你是一个代码分析助手。给定一个文件的内容和用户的请求,识别并提取出对理解代码在请求上下文中的有价值的代码片段。注意输出的时候不要有 \`\`\`";
963963

964-
outputChannel.appendLine(`compress processing .. ${filePath}`);
964+
outputChannel.appendLine(`compress processing .. ${filePath} [🚀start]`);
965965
try {
966966
const response = await callDeepSeekApi(requestContent, systemContent, undefined, true, undefined, signal, true);
967967
if (response) {
968968
const segments = response.split("===SEGMENT===").map(segment => segment.trim());
969969
const compressedContent = segments.join("\n//...CCVB\n");
970970
compressedFiles[filePath] = compressedContent;
971-
outputChannel.appendLine(`compress processing .. ${filePath} [success]`);
971+
outputChannel.appendLine(`compress processing .. ${filePath} [success]`);
972972
} else {
973-
outputChannel.appendLine(`compress processing .. ${filePath} [failed]`);
973+
outputChannel.appendLine(`compress processing .. ${filePath} [failed]`);
974974
}
975975
} catch (error) {
976-
outputChannel.appendLine(`compress processing .. ${filePath} [failed: ${error}]`);
976+
outputChannel.appendLine(`compress processing .. ${filePath} [⚠️error: ${error}]`);
977977
}
978978
};
979979

src/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import * as path from 'path';
33
import * as fs from 'fs';
44
import { selectFiles } from './fileSelector';
5-
import { generateCvb, applyCvbToWorkspace, generateTimestamp, Cvb, TCVB, mergeCvb} from './cvbManager';
5+
import { generateCvb, applyCvbToWorkspace, generateTimestamp, Cvb, TCVB, mergeCvb, compressCvb} from './cvbManager';
66
import { queryCodeReDesign, generateFilenameFromRequest, analyzeCode, callDeepSeekFixApi, GetLastMessageBody } from './deepseekApi';
77
import { setupCvbAsMarkdown } from './cvbMarkdownHandler';
88
import { registerCvbContextMenu } from './siderBar';
@@ -66,7 +66,16 @@ export async function doUploadCommand(cvbFilePath: string, userPrompt: string, o
6666
i++;
6767
}
6868

69-
const cvbContent = fs.readFileSync(cvbFilePath, 'utf-8');
69+
let cvbContent = fs.readFileSync(cvbFilePath, 'utf-8');
70+
const CVB_QUERY_LENGTH_LIMIT = 1024 * 2;
71+
if(cvbContent.length > CVB_QUERY_LENGTH_LIMIT) {
72+
const inputCvb = new Cvb(cvbContent);
73+
if (!inputCvb.getMetaData("compressFrom")) {
74+
currentOutputChannel?.appendLine("输入数据过于巨大,先进行压缩预处理...");
75+
const compressedCvb = await compressCvb(inputCvb, userPrompt);
76+
cvbContent = compressedCvb.toString();
77+
}
78+
}
7079

7180
let apiResponse = await queryCodeReDesign(cvbContent, userPrompt, outputChannel, CurrentOperationController.signal);
7281
let processSuccess = true;

0 commit comments

Comments
 (0)