Skip to content

Commit

Permalink
Merge pull request #33 from lowcoding/feat/v1.8.8
Browse files Browse the repository at this point in the history
🐞 fix: openai log
  • Loading branch information
wjkang authored Aug 20, 2024
2 parents 8e961f4 + fd4770c commit d2abc1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "lowcode",
"description": "lowcode tool, support ChatGPT and other LLM",
"author": "wjkang <ruoxieme@gmail.com>",
"version": "1.8.7",
"version": "1.8.8",
"icon": "asset/icon.png",
"publisher": "wjkang",
"repository": "https://github.com/lowcoding/lowcode-vscode",
Expand Down
12 changes: 9 additions & 3 deletions src/utils/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const createChatCompletion = (options: {
}) =>
new Promise<string>((resolve) => {
let combinedResult = '';
const error = '发生错误:';
let error = '发生错误:';
const config = getChatGPTConfig();
const request = https.request(
{
Expand All @@ -27,6 +27,7 @@ export const createChatCompletion = (options: {
res.on('data', async (chunk) => {
const text = new TextDecoder('utf-8').decode(chunk);
const data = text.split('\n\n').filter((s) => s);
console.log(data);
for (let i = 0; i < data.length; i++) {
try {
let element = data[i];
Expand All @@ -43,7 +44,7 @@ export const createChatCompletion = (options: {
// 处理没有 data 开头
element = preDataLast + element;
}
if (element.includes('data: ')) {
if (element.startsWith('data: ')) {
if (element.includes('[DONE]')) {
if (options.handleChunk) {
options.handleChunk({ text: '' });
Expand All @@ -69,13 +70,18 @@ export const createChatCompletion = (options: {
}
} else {
console.log('no includes data: ', element);
if (options.handleChunk) {
options.handleChunk({
text: element,
});
}
}
} catch (e) {
console.error({
e: (e as Error).toString(),
element: data[i],
});
// error = (e as Error).toString();
error = (e as Error).toString();
}
}
});
Expand Down

0 comments on commit d2abc1b

Please sign in to comment.