I’ve been going through the quick tutorial and I have followed all of the steps. But when actually generating the pet names , I’m met with an error. See below:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Any suggestions?
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
apiKey: process.env.OPEN_API_KEY,
});
const openai = new OpenAIApi(configuration);
// eslint-disable-next-line import/no-anonymous-default-export
export default async function (res) {
const completion = await openai.createCompletion({
model: "text-davinci-002",
prompt: generatePrompt(req.body.idea),
temperature: 0.6,
});
res.status(200).json({ result: completion.data.choices[0].text });
}
console.log(completion);
function generatePrompt(idea) {
const capitalizedIdea = idea[0].toUpperCase() + idea.slice(1).toLowerCase();
return `Suggest three names for a buisness.
Idea: VR
Names: Hyper, Vyper, Seeing is believing
Idea: Finance
Names: Money Matters, Money Time, Money Mine
Animal: ${capitalizedIdea}
Names:`;
}
Hi - brand new to this and have been following the tutorial
I am getting this error as well. i have tried running under XAMP in case I needed a server but that made no difference. I am running the example code out the box:
import { Configuration, OpenAIApi } from “openai”;
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
function generatePrompt(animal) {
const capitalizedAnimal =
animal[0].toUpperCase() + animal.slice(1).toLowerCase();
return `Suggest three names for an animal that is a superhero.
Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: ${capitalizedAnimal}
Names:`;
}
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data