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}`);
});
})();
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",