Skip to content

Commit ab1b4e1

Browse files
authored
fix: shape of chatbot completion app data (#191)
fix: await for chatbot completion before creating responses sets
1 parent 1a18cc7 commit ab1b4e1

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/hooks/useAssistants.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ const useAssistants = (): UseAssistantsValues => {
7979
]).then((ans) => {
8080
const a = postAppDataAsync({
8181
...DEFAULT_CHATBOT_RESPONSE_APP_DATA,
82-
data: ans,
82+
data: {
83+
...ans,
84+
},
8385
}) as Promise<ChatbotResponseAppData>;
8486
return a;
8587
});
@@ -124,7 +126,7 @@ const useAssistants = (): UseAssistantsValues => {
124126
const a = postAppDataAsync({
125127
...DEFAULT_CHATBOT_RESPONSE_APP_DATA,
126128
data: {
127-
ans,
129+
...ans, // Be careful. Destructure.
128130
assistantId: assistant.id,
129131
},
130132
}) as Promise<ChatbotResponseAppData>;
@@ -164,7 +166,7 @@ const useAssistants = (): UseAssistantsValues => {
164166
);
165167
})
166168
.map((promise) =>
167-
promise.then((assistantResponseAppData) => {
169+
promise.then(async (assistantResponseAppData) => {
168170
if (assistantResponseAppData) {
169171
const { completion: response, assistantId } =
170172
assistantResponseAppData.data;

src/hooks/useSteps.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ const useSteps = (): UseStepsValues => {
7979

8080
if ((nextStep?.round || 0) > round) {
8181
// TODO: Insane amount of work here. REFACTOR!
82-
await generateResponsesWithEachAssistant().then(() =>
83-
createAllResponsesSet().then(() => {
84-
changeStep(nextStep, nextStepIndex);
85-
}),
86-
);
82+
await generateResponsesWithEachAssistant()
83+
.then((p) => Promise.all(p))
84+
.then(() =>
85+
createAllResponsesSet().then(() => {
86+
changeStep(nextStep, nextStepIndex);
87+
}),
88+
);
8789
} else {
8890
changeStep(nextStep, nextStepIndex);
8991
}

0 commit comments

Comments
 (0)