Message variable does not seem to pass to CHATGPT

The MESSAGE variable does not seem to pass to CHATGPT and the answer that is received is:
${signature} ${footer} `; module.exports = { emailTemplate };
my code :
index.js

const OpenAI = require('openai');
const { Configuration, OpenAIApi } = OpenAI;

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = 3001; 

const configuration = new Configuration({
    organization: "org-DbrAtZeqhWwUsFhyqZ1DL0jh",
    apiKey: "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■sqErB5YJ",
});
const openai = new OpenAIApi(configuration);

app.use(bodyParser.json());
app.use(cors());

app.post('/', async (req,res) => {
    const {message} = req.body;
    console.log(message)
    const response = await openai.createCompletion({
        model: "text-davinci-003",
        //prompt: "tell me about steve jobs",
        prompt: "${message}",
        max_tokens: 10,
        temperature: 0,
        
      });
      console.log(response.data)
      if(response.data.choices[0].text){
            res.json({message: response.data.choices[0].text}) 
      }
});

app.listen(port, () => {
    console.log('Example app listening at http://localhost:'+ port);
});

app.js:

import React, {useState} from 'react';
import './App.css';

function App() {
  const [message, setMessage] = useState('');
  const [response, setResponse] = useState('');

  const handleSubmit = (e) => {
    e.preventDefault();
    fetch('http://localhost:3001/', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({message}),
    })
    .then((res) => res.json())
    .then((data) => setResponse(data.message));
  };
  return (
    <div className="App">
      <form onSubmit = {handleSubmit}>
        <textarea
          value = {message}
          onChange = {(e)=>setMessage(e.target.value)}
        ></textarea>
        <button type = "submit">Submit</button>
      </form>
      <div>{response}</div>  
    </div>
  );
}

export default App

but when i chage :
prompt: “${message}”,
to for example:
prompt: “tell me about steve jobs”,
I get a correct answer from CHATGPT
Would appreciate help

Welcome to the OpenAI community @yanivgot

The error lies in the following line in your code:

In JS/TS, template string is created using ``.

Here’s how this line should be:

prompt:`${message}`,

PS: You should consider using chat completions endpoint with gpt-3.5-turbo model for economic chat completions.

2 Likes