Skip to content

Commit 91796d8

Browse files
committed
updated the for loops to use promises because of the awaits
1 parent fdf500d commit 91796d8

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/gpt-controller.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export class GPTController {
4444
};
4545
//console.log(`Thread Message: ${threadMessage}`)
4646
// Create the three threads for each paper
47-
let threadResults: GPTData[] = []
48-
for (let i = 0; i < 3; i++) {
47+
let threadResults: GPTData[] = [];
48+
const loopPromises = Array.from({ length: 3 }, async (_) => {
4949
const assistant = await this.createAssistant(assistantParams);
5050
const thread = await this.createThread(threadMessage);
5151
// Run the assistant on the thread and get the prompt results. Think non-stream results are better?
@@ -68,21 +68,26 @@ export class GPTController {
6868
console.log(`${message.role} > ${result}`);
6969
//console.log();
7070
// TODO: push the parsed results to the threadResults as a GPTData object
71-
threadResults.push()
71+
threadResults.push();
7272
}
7373
}
7474
} else {
7575
console.log(run.status);
7676
}
77-
}
78-
/*
77+
});
78+
79+
// Wait for all loop iterations to finish
80+
await Promise.all(loopPromises);
81+
7982
const threadFinal: GPTResponse = {
8083
pass_1: threadResults[0],
8184
pass_2: threadResults[1],
82-
pass_3: threadResults[2]
83-
}
85+
pass_3: threadResults[2],
86+
};
87+
88+
//console.log(threadFinal)
8489
results.push(threadFinal);
85-
90+
8691
// TODO: Need to add the stream and and return it, not working yet.
8792
// Will be uncommented to implement
8893

0 commit comments

Comments
 (0)