#Function async issue

19 messages · Page 1 of 1 (latest)

scarlet spear
#

What's the code?

#

And the runtime you're using?

#

Do you get some error/s in the console?

merry solar
# scarlet spear What's the code?
export const generateNotes = async (userId, uid, topic, context, error) => {
  try {
    const study = await notesModel.generateContent(JSON.stringify({ uid, topic_name: topic, topic_context: context }))
    const data = study.response.text
    if (isResponseValid(data)) await saveInDatabase(userId, data)
    else await saveInDatabase(userId, "Error occured! Please try again!")
  } catch (err) {
    error(`Error generating notes: ${err}`)
  }
}
merry solar
merry solar
merry solar
#

is this expected??

scarlet spear
#

You're not using appwrite SDK?

#

Do you have initialized the SDK?

merry solar
#

i am but i didnt add that

#

i just sent u the code which has the main functioning

scarlet spear
#

What's the code for that?

merry solar
#

@scarlet spear it simply saves the response in separate collection for retrieval (polling)

export const saveInDatabase = async (documentId, data) => {
  await databases.createDocument(
    process.env.DATABASE_ID,
    process.env.GEN_COLLECTION_ID,
    documentId,
    { data }
  )
}
merry solar
#

@scarlet spear also in my main.js i return a json object. is that making it run in sync?

merry solar