This commit is contained in:
di-sukharev
2023-05-20 15:43:45 +08:00
parent 8acaf4c860
commit 17e80e0b4f
2 changed files with 12 additions and 10 deletions

View File

@@ -27944,8 +27944,8 @@ async function improveCommitMessagesWithRebase(commits, diffs) {
);
let improvedMessagesBySha2 = {};
for (let i2 = 0; i2 < improvePromises.length; i2 += chunkSize) {
const promises = improvePromises.slice(i2, i2 + chunkSize);
await Promise.all(promises).then((results) => {
const chunkOfPromises = improvePromises.slice(i2, i2 + chunkSize);
await Promise.all(chunkOfPromises).then((results) => {
return results.reduce((acc, improvedMsg, i3) => {
const index = Object.keys(improvedMessagesBySha2).length;
acc[diffs[index + i3].sha] = improvedMsg;
@@ -27955,9 +27955,10 @@ async function improveCommitMessagesWithRebase(commits, diffs) {
ce(`error in Promise.all(getCommitDiffs(SHAs)): ${error}`);
throw error;
});
ce(`Improved ${improvedMessagesBySha2.length} commits.`);
const sleepFor = 1e3 + 100 * (i2 === 0 ? 0 : i2 - chunkSize);
ce(`Sleeping for ${sleepFor}`);
const sleepFor = 2e3 + 100 * (i2 / chunkSize);
ce(
`Improved ${chunkOfPromises.length} messages. Sleeping for ${sleepFor}`
);
await sleep(sleepFor);
}
return improvedMessagesBySha2;

View File

@@ -81,9 +81,9 @@ async function improveCommitMessagesWithRebase(
let improvedMessagesBySha: MessageBySha = {};
for (let i = 0; i < improvePromises.length; i += chunkSize) {
const promises = improvePromises.slice(i, i + chunkSize);
const chunkOfPromises = improvePromises.slice(i, i + chunkSize);
await Promise.all(promises)
await Promise.all(chunkOfPromises)
.then((results) => {
return results.reduce((acc, improvedMsg, i) => {
const index = Object.keys(improvedMessagesBySha).length;
@@ -97,11 +97,12 @@ async function improveCommitMessagesWithRebase(
throw error;
});
outro(`Improved ${improvedMessagesBySha.length} commits.`);
// openAI errors with 429 code (too many requests) so lets sleep a bit
const sleepFor = 1000 + 100 * (i === 0 ? 0 : i - chunkSize);
const sleepFor = 2000 + 100 * (i / chunkSize);
outro(`Sleeping for ${sleepFor}`);
outro(
`Improved ${chunkOfPromises.length} messages. Sleeping for ${sleepFor}`
);
await sleep(sleepFor);
}