Axios.post problem.
# 🤝help
b
Hello I have this code: const OPENAI_API_KEY = 'xxxxxxx'; async function fetchCarBrandModel() { try { const response = await axios.post('https://api.openai.com/v1/chat/completions', { model: 'gpt-3.5-turbo-0613', messages: [ ........ // Select the content of the assistant's reply const assistantMessage = response.data.choices[0].message.content; let gptFound = false; let carbrand = ""; // If assistantMessage is not 'undefined', set it to workflow.GPTAnswer if (assistantMessage !== 'undefined') { carbrand = assistantMessage; console.log(carbrand) gptFound = true; console.log(gptFound) } // Return the result return { carbrand, gptFound }; } catch (error) { console.error(error.response.data); } } // Use the function (async () => { const result = await fetchCarBrandModel(); // Now you can update
workflow
here, where it is in scope if (result) { workflow.carBrandModel = result.carbrand; workflow.GPTfoundAnswer = result.gptFound; } console.log(result.carbrand + " " + result.gptFound) console.log(workflow.carBrandModel) })(); What happends is that i cannot update my actual workflow variables. It somehow creates new variables and does not update the actual values. Can somebode help me please?
a
hi @bitter-advantage-11751 , 1) are carBrandModel and GPTfoundAnswer your workflow variables? 2) what do you mean by creates new variables?
b
Hello, many thanks for your answer! carBrandModel and GPTfoundAnswer are indeed my workflow variables. When i log them aoutside my axios call function, they are not the right values. So the workflow variables are not reachable from within the function.
2 Views