Skip to content

Commit

Permalink
Merge pull request #17 from cboard-org/serializeImageGeneration
Browse files Browse the repository at this point in the history
Refactor processPictograms function to wait the pictonizaer response before send new request
  • Loading branch information
RodriSanchez1 authored Mar 7, 2024
2 parents 6918fa6 + d2dfbcf commit eec71cc
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,19 @@ async function pictonizer(imagePrompt: string): Promise<AIImage> {
async function processPictograms(
suggestions: Suggestion[]
): Promise<Suggestion[]> {
const suggestionsWithAIImage = await Promise.all(
suggestions.map(async (suggestion) => {
if (suggestion.pictogram.isAIGenerated) {
const suggestionWithAIImage = { ...suggestion };
suggestionWithAIImage.pictogram.images = [
await pictonizer(suggestion.label),
];
return suggestionWithAIImage;
}
return suggestion;
})
);
const suggestionsWithAIImage: Suggestion[] = [];

for (const suggestion of suggestions) {
if (suggestion.pictogram.isAIGenerated) {
const suggestionWithAIImage = { ...suggestion };
suggestionWithAIImage.pictogram.images = [
await pictonizer(suggestion.label),
];
suggestionsWithAIImage.push(suggestionWithAIImage);
} else {
suggestionsWithAIImage.push(suggestion);
}
}
return suggestionsWithAIImage;
}

Expand Down

0 comments on commit eec71cc

Please sign in to comment.