I've been struggling with a coding dilemma for quite some time now and I'm in need of assistance. The issue at hand is related to a method that's returning ZoneAwarePromise
instead of the desired string output. Let's take a look at the code snippet below.
retriveRes() {
/*
Within the subscription callback, an asynchronous method (httpTranslateToAr) is being invoked.
However, it's returning a ZoneAwarePromise when we actually require the translated string as the output.
Despite my efforts with async and await functionalities, I haven't been successful in removing the ZoneAwarePromise from the equation.
*/
this.userSubjectOutput.subscribe((res) => {
let manipulatedJSArr = res.map((step: any) => {
return {
step: step.step,
content: this.httpTranslateToAr(step.content), // The problem lies here, where the content value ends up as a ZoneAwarePromise
exercises: step.exercises
}
})
})
}
/*
I've been tinkering around with this method but I can't seem to figure out how to fetch the API response
and provide a specific value for use within the retriveRes method.
*/
async httpTranslateToAr(str: string) {
this.openAIparams = {
messages: messages,
model: "gpt-4",
max_tokens: 700,
temperature: 0.3
}
await this.client.post('https://api.openai.com/v1/chat/completions', this.openAIparams).then(
client=> {
console.log(client)
clientValue = client;
}).catch(err => {
console.log(err)
})
console.log("lol")
console.log(clientValue.data.choices[0].message.content)
return clientValue.data.choices[0].message.content // My aim is to have this value returned without it being a ZoneAwarePromise
}
Can someone guide me on how to modify the content
in the map
function so that it only provides a translated Arabic string rather than a ZoneAwarePromise? Any insights or explanations are greatly appreciated! :)