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

262
Views
El código de ejemplo de AI abierto no funciona "Esperar solo es válido en funciones asíncronas y los cuerpos de módulos de nivel superior"

Disculpas si esto parece simple, soy relativamente nuevo en esto.

Como se dice en el título, aparece el error "La espera solo es válida en funciones asíncronas y los cuerpos de los módulos de nivel superior". Aunque estoy confundido porque la espera está en la parte superior del cuerpo.

 const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: 'Api Key Go Brrrrrr', }); const openai = new OpenAIApi(configuration); const response = await openai.createCompletion("text-davinci-002", { prompt: "You: What have you been up to?\nFriend: Watching old movies.\nYou: Did you watch anything interesting?\nFriend:", temperature: 0.5, max_tokens: 60, top_p: 1.0, frequency_penalty: 0.5, presence_penalty: 0.0, stop: ["You:"], });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede envolver el código en un IIFE asíncrono:

 // add ; at the start to be safe, this is one of the very few cases where semicolons matter in JS ;(async ()=>{ const response = await openai.createCompletion("text-davinci-002", { prompt: "You: What have you been up to?\nFriend: Watching old movies.\nYou: Did you watch anything interesting?\nFriend:", temperature: 0.5, max_tokens: 60, top_p: 1.0, frequency_penalty: 0.5, presence_penalty: 0.0, stop: ["You:"], }); })();
about 4 years ago · Juan Pablo Isaza Report
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!