add: configure open ai and get api key

This commit is contained in:
sushant dhimal 2023-01-02 23:41:33 +05:45
parent 85ab638bec
commit 8d6b427efd
4 changed files with 1322 additions and 2 deletions

24
.gitignore vendored
View File

@ -1 +1,23 @@
node_modules
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

18
index.js Normal file
View File

@ -0,0 +1,18 @@
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.REACT_APP_OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function CallAPI() {
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Say this is a test",
max_tokens: 7,
temperature: 0,
});
console.log(response.data.choices[0].text);
}
CallAPI();

1273
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,5 +7,12 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Sushant Dhimal",
"license": "ISC"
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.1",
"cors": "^2.8.5",
"express": "^4.18.2",
"morgan": "^1.10.0",
"openai": "^3.1.0"
}
}