Can someone explain the difference to me?

Why this does not work:

const openai = new OpenAIApi(configuration);

const [prompt, setPrompt] = useState(“”);
const [result, setResult] = useState(“”);
const [loading, setLoading] = useState(false);

const handleClick = async () => {
setLoading(true);
try {
const response = await openai.createCompletion({
model: “text-davinci-003”,
messages:[
{
“role”: “system”,“content”:You are very cool person
},
{“role”: “user”, “content”: ${prompt}}
],

  });
  setResult(response.data.choices[0].text);
} catch (error) {
  console.error(error);
  console.log(prompt)
}
setLoading(false);

};

And this does:

const openai = new OpenAIApi(configuration);

const [prompt, setPrompt] = useState(“”);
const [result, setResult] = useState(“”);
const [loading, setLoading] = useState(false);

const handleClick = async () => {
setLoading(true);
try {
const response = await openai.createCompletion({
model: “text-davinci-003”,
prompt: prompt,

  });
  setResult(response.data.choices[0].text);
} catch (error) {
  console.error(error);
  console.log(prompt)
}
setLoading(false);

};

Wrong end point.

1 Like