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

267
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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