Skip to content

Commit fd4770c

Browse files
committed
🐞 fix: openai log
1 parent 8e961f4 commit fd4770c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "lowcode",
44
"description": "lowcode tool, support ChatGPT and other LLM",
55
"author": "wjkang <ruoxieme@gmail.com>",
6-
"version": "1.8.7",
6+
"version": "1.8.8",
77
"icon": "asset/icon.png",
88
"publisher": "wjkang",
99
"repository": "https://github.com/lowcoding/lowcode-vscode",

src/utils/openai.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const createChatCompletion = (options: {
99
}) =>
1010
new Promise<string>((resolve) => {
1111
let combinedResult = '';
12-
const error = '发生错误:';
12+
let error = '发生错误:';
1313
const config = getChatGPTConfig();
1414
const request = https.request(
1515
{
@@ -27,6 +27,7 @@ export const createChatCompletion = (options: {
2727
res.on('data', async (chunk) => {
2828
const text = new TextDecoder('utf-8').decode(chunk);
2929
const data = text.split('\n\n').filter((s) => s);
30+
console.log(data);
3031
for (let i = 0; i < data.length; i++) {
3132
try {
3233
let element = data[i];
@@ -43,7 +44,7 @@ export const createChatCompletion = (options: {
4344
// 处理没有 data 开头
4445
element = preDataLast + element;
4546
}
46-
if (element.includes('data: ')) {
47+
if (element.startsWith('data: ')) {
4748
if (element.includes('[DONE]')) {
4849
if (options.handleChunk) {
4950
options.handleChunk({ text: '' });
@@ -69,13 +70,18 @@ export const createChatCompletion = (options: {
6970
}
7071
} else {
7172
console.log('no includes data: ', element);
73+
if (options.handleChunk) {
74+
options.handleChunk({
75+
text: element,
76+
});
77+
}
7278
}
7379
} catch (e) {
7480
console.error({
7581
e: (e as Error).toString(),
7682
element: data[i],
7783
});
78-
// error = (e as Error).toString();
84+
error = (e as Error).toString();
7985
}
8086
}
8187
});

0 commit comments

Comments
 (0)