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

310
Views
No se puede obtener el valor de retorno de la función de espera. Entonces ()

Tengo una función que realiza una solicitud a una 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); }

y otra función que lo llama, y debería devolver su respuesta.

 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; }

La return response de línea final genera el error Type 'Promise<any>' is not assignable to type 'string'. ts(2322)

Entiendo que el retorno de una función asíncrona es una promesa, pero estoy llamando a .then() en ella, ¿no debería eso resolver la promesa en un valor real? Cuando paso el cursor sobre promse.then() , mi IDE me dice que su tipo de devolución también es una promesa. ¿Ambos await y .then() devuelven promesas? ¿Cuál es el punto de .then() ?

¿Cómo puedo obtener el retorno de una función asíncrona aquí y almacenarla en una 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!