Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

313
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda