deepThink.ts
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
export function createDeepThink(content: string) {
const lines = content.split("\n");
let deepThink: string[] = [];
let j = 0;
let isBreak = false;
for (let i = 0; i < lines.length; i++) {
if (lines[i] === "") {
lines.splice(i, 1); // 删除空行
i--;
continue;
}
if (
lines[i].startsWith(">") ||
lines[i].startsWith("2") ||
lines[i].startsWith("3") ||
lines[i].startsWith("4")
) {
if (j !== 0 && lines[i].startsWith(">")) {
lines[i] = lines[i].substring(1);
}
deepThink.push(lines[i]);
lines.splice(i, 1);
j++;
i--;
} else {
break;
}
}
const deepThinkStr = deepThink.join("");
const linesStr = lines.join("\n");
const result = [deepThinkStr, "", linesStr].join("\n");
return result;
}
export function removeDeepThink(content: string) {
const lines = content.split("\n");
let deepThink: string[] = [];
let j = 0;
let isBreak = false;
for (let i = 0; i < lines.length; i++) {
if (lines[i] === "") {
lines.splice(i, 1); // 删除空行
i--;
continue;
}
if (
lines[i].startsWith(">") ||
lines[i].startsWith("2") ||
lines[i].startsWith("3") ||
lines[i].startsWith("4")
) {
if (j !== 0 && lines[i].startsWith(">")) {
lines[i] = lines[i].substring(1);
}
deepThink.push(lines[i]);
lines.splice(i, 1);
j++;
i--;
} else {
break;
}
}
return lines.join("\n");
}