Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
Can't get return value from await function.then()

I have a function that makes a request to an API.

    async sendPrompt(prompt: string, engine: string, maxTokens: number): Promise<string> {
        const gptResponse = await this.openai.complete({
            // ...
            // API call details
            // ...
        });
        return gptResponse.data.choices[0].text.substring(1);
    }

and another function that calls it, and should return it's response.

    queryGPT3(message: string): string {
        const prompt = this.preparePrompt('classifyPrompt', message);
        const promise = this.sendPrompt(prompt, 'gpt3', 100);
        const response = promise.then((res) => {
            return res;
        }
        return response;
    }

The final line return response is raising the error Type 'Promise<any>' is not assignable to type 'string'. ts(2322)

I get that the return of an async function is a promise, but I'm calling .then() on it - shouldn't that resolve the promise to an actual value? When I hover over promse.then(), my IDE tells me it's return type is also a promise. Both await and .then() return promises? What's the point of .then()?

How can I get the return of an async function here and store it in a variable?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!