Open HuangKaibo2017 opened 4 weeks ago
Might be caused by the double-awaiting -- automaFetch
returns a promise, and you already await the result with const result = await automaFetch(...)
, so const res = await result;
is incorrect because result
is not a promise anymore -- it's the resolved value.
Just remove const res = await result;
and replace the references to res
with result
directly.
@jingbof how to reuse the promise in my js code created by automaFetch or other system function?
Is your feature request related to a problem? Please describe. I am composing a feature calling cloudflase model rest api by automaFetch as below. The rest api returns like 20 sec but automaFetch returns much earlier even with .then or await. so variable llm_response cannot be set in "automaSetVariable('llm_response', res.response);".
async function fetchAndProcess() { try { const result = await automaFetch('json', { url: url, method: 'POST', headers: { 'Authorization':
Bearer ${apiKey}
, 'Content-Type': 'application/json', }, body: JSON.stringify({ prompt: 'tell me a story', }), });} catch (error) { console.error('Fetch Error:', error); // Handle any fetch or processing errors } }
// Call the async function fetchAndProcess();
Describe the solution you'd like It would be good that adding an timeout parameter to automaFetch and make sure the function would return with data or return after timeout.
Describe alternatives you've considered Pls give a proper sample before timeout parameter added.
Additional context Add any other context or screenshots about the feature request here.