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

266
Vistas
How to pass a variable from a post request to a function that takes params as string or array of string in Node.js?

I would like to pass the variable below called query into the end of the prompt , I tried template literals but it doesn't work

(async () => {
  const gbtResponse = await openai.createCompletion({
    model: "text-davinci-002",
    prompt:
      "Generate a product description explanation for the following product:  \n\n",
    temperature: 0.8,
    max_tokens: 256,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
  });
  console.log(`${gbtResponse.data.choices[0].text}`);
  // console.log(`${gbtResponse}.choices[0].text`);
  app.get("/api", (req, res) => {
    res.send(`${gbtResponse.data.choices[0].text}`);
  });
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));

  app.post("/api", (req, res) => {
    res.send(
      `I received your POST request. This is what you sent me: ${req.body.productName}`
    );
    const query = req.body.productName;
    console.log(`${query}`);
  });
})();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think what you will need to do is this:

  const gbtResponse = async (param) => {
    return await openai.createCompletion({
    model: "text-davinci-002",
    prompt:
      `Generate a product description explanation for the 
      following product: ${param} \n\n`,
    temperature: 0.8,
    max_tokens: 256,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
  });
}

and then rather than referring it you need to call it.

Since you specified you don't want to use template literals you could use this approach.

    prompt:
      "Generate a product description explanation for the 
      following product: " +  param + "\n\n",
about 4 years ago · Juan Pablo Isaza Denunciar
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