Skip to content

Commit 76d279e

Browse files
authored
Merge pull request #38 from Pythagora-io/brija
Save the final test on end
2 parents b156b24 + bfdad67 commit 76d279e

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pythagora",
3-
"version": "0.0.60",
3+
"version": "0.0.63",
44
"author": {
55
"name": "Zvonimir Sabljic",
66
"email": "[email protected]"

src/helpers/api.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,34 @@ async function makeRequest(data, options, customLogFunction) {
4949
res.on('data', (chunk) => {
5050
try {
5151
let stringified = chunk.toString();
52-
if (stringified === 'pythagora_end') {
53-
gptResponse = '';
54-
end = true;
55-
return;
56-
}
57-
if (end) return gptResponse = stringified;
5852
try {
5953
let json = JSON.parse(stringified);
60-
if (json.error) gptResponse = json.error;
54+
if (json.error || json.message) gptResponse = json;
6155
return;
6256
} catch (e) {}
63-
let receivedMessages = extractGPTMessageFromStreamData(stringified);
64-
receivedMessages.forEach(rm => {
65-
let content = _.get(rm, 'choices.0.delta.content');
66-
if (content) {
67-
gptResponse += content;
68-
if (customLogFunction) customLogFunction(gptResponse);
69-
else process.stdout.write(content);
70-
}
71-
});
7257

58+
if (!stringified.includes('pythagora_end:')) {
59+
let receivedMessages = extractGPTMessageFromStreamData(stringified);
60+
receivedMessages.forEach(rm => {
61+
let content = _.get(rm, 'choices.0.delta.content');
62+
if (content) {
63+
gptResponse += content;
64+
if (customLogFunction) customLogFunction(gptResponse);
65+
else process.stdout.write(content);
66+
}
67+
});
68+
} else {
69+
gptResponse += stringified;
70+
if (customLogFunction) customLogFunction(gptResponse);
71+
else process.stdout.write(stringified);
72+
}
7373
} catch (e) {}
7474
});
75-
res.on('end', async (a,b,c) => {
75+
res.on('end', async function () {
7676
process.stdout.write('\n');
7777
if (res.statusCode >= 400) throw new Error(`Response status code: ${res.statusCode}. Error message: ${gptResponse}`);
7878
if (gptResponse.message) throw new Error(`Error: ${gptResponse.message}. Code: ${gptResponse.code}`);
79-
gptResponse = cleanupGPTResponse(gptResponse);
79+
gptResponse = cleanupGPTResponse(gptResponse.split('pythagora_end:').pop());
8080
resolve(gptResponse);
8181
});
8282
});

0 commit comments

Comments
 (0)