-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmartList.js
More file actions
31 lines (30 loc) · 1.24 KB
/
smartList.js
File metadata and controls
31 lines (30 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import ai from './ai.js'
import { generateMeal, generateSmartMeal } from './recommendation.js'
export const generateSmartList = async(filters, numberOfMeals) => {
try{
let currentMealList = []
while(currentMealList.length !== numberOfMeals){
if(currentMealList.length < 1){
let newMeal = await generateMeal(filters)
// continue to request for a recommendation if there's some issues
while(newMeal === null){
newMeal = await generateMeal(filters)
}
currentMealList.push(JSON.parse(newMeal))
}
else{
let newMeal = await generateSmartMeal(currentMealList)
// continue to request for a recommendation if there's some issues
while(newMeal === null || newMeal === undefined){
newMeal = await generateSmartMeal(currentMealList)
}
currentMealList.push(JSON.parse(newMeal))
}
}
console.log("/smart list generated --- successful response chatGPT")
return currentMealList
}catch(err){
console.log(`error: \n${err}`)
return generateSmartList(filters, numberOfMeals)
}
}