1.0.4 • Published 3 years ago
chatgpt-api-free v1.0.4
Getting an API key
- Join the Discord server.
- Get your API key from the
#Botchannel by using the/keycommand. - Copy the API key that the bot gives you
Note: This is not an OpenAI API key.
Installation
- Run
npm init -y - Go to your package.json file and add
"type": "module"at the end (before the}) - Run
npm i gpt-proxy - Add
import { gpt } from 'chatgpt-api-free'to your index.js file
Note: Step 2 will make you not able to use require() instead you will have to switch to import/export so try to start new projects with this library instead of adding it to big projects
Creating gpt instance
const model = new gpt({
'api_key': 'your API key',
'temperature': 0.7,
'max_tokens': 256 // max: 4090
})
// new gpt(<config: <api_key: string> <temperature: number> <max_tokens: number> >)Text Completion
const completion = await model.text_completion('Human: Hello!\nAI:', [
'Human:',
'AI:'
])
console.log(completion.choices[0].text)
// text_completion(<prompt: string>, <stop: array>)Chat Completion
const completion = await model.chat_completion([
{
'role': 'system',
'content': `You are a helpful assistant, your name is Joe`
},
{
'role': 'user',
'content': 'What\'s your name?'
}
])
console.log(completion.choices[0].message.content)
// text_completion(<prompt: string>, <stop: array>)