Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

309
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda