Reputation: 61
Sorry if this is a simple problem but I'm new to this stuff.
İ have my code below, but the API returns saying İ don't have the right API key put it.
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function test() {
const response = await openai.createCompletion("text-davinci-002", {
prompt: "Summarize this for a college student:\n\nJupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.",
temperature: 0.7,
max_tokens: 64,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});
console.log(response)
}
test()
the API key seems to be found in a process.env file that İ don't have, and when İ made a file named process.env and made a variable called OPENAI_API_KEY, but it didn't seem to work. It returns something when İ set apiKey equal to the actual key, but that seems like a roundabout solution. Thanks
Upvotes: 4
Views: 2768
Reputation: 313
process.env is not a folder, it is used to get an environment variable from the host OS. You can simply replace process.env.OPENAI_API_KEY
with "your-api-key-here"
process.env is most commonly used when publishing to something like github where you need to keep your api keys secret so that nobody else can use them but so that you can still use them when deploying
Upvotes: 3