Error using await inside code loop block

I have a loop block using the 'Code' mode to define the loop. inside this I await the call to .trigger(). the loop lambda just calls an openAI API endpoint (uses the REST API resource, not the built-in openAI one).

await (pollOpenAIRun_lambda.trigger()) this is what caused me problems because

await pollOpenAIRun_lambda.trigger() causes a run-time error :frowning_face: .

image
image

but if I just add the parentheses everything runs just fine
image

I don't have a clue what's going on, but the linter doesn't catch this and for some reason await is no longer blue

Hey @bobthebear!

Interesting find, I am also confused as to why the linter is no longer properly coloring await.

It is good to know that adding parentheses allows the code to run, but I will look into why triggering a REST API resource with .trigger() returns the ... is not a function error message. Is this only happening with an OpenAI REST Resource or has the error message occurred with other APIs?

My hunch is that the polling of the LLM might be a tricky response connection for Retool to handle outside of our built-in OpenAI Resource. But since you got it to work and fully await the query response with await () I could be wrong :sweat_smile:

I'll do some testing for ya when I get home

1 Like

How are you getting the query into the workflow? Is pollOpenAIRun_lambda in your query library or did you create the query in an a separate app?

neither, the GUI defined it(?)

other than renaming the block I just changed 'Run JS Code' to different resource
image

edit: forgot to include the settings
image

Ah ok, yes it looks like you are using the GUI correctly for the lambda function to run on each iteration of the loop block.

That is very interesting that changing the resource from JS code eliminated the "not a function" error.

I can report the parser needing parentheses to our eng team but I can't guarantee they will be able to fix it soon :sweat_smile: very glad you were able to get it working!

1 Like

lol no rush at all, await <promise> and await (<promise>) should resolve the same no matter what so if someone uses this syntax or splits it into different lines it'll always resolve the same with or without a fix