Skip to content

Instantly share code, notes, and snippets.

@mustafabutt-dev
Last active March 14, 2023 14:28
Show Gist options
  • Save mustafabutt-dev/772dc075f44561ff923e9b0fb761ed38 to your computer and use it in GitHub Desktop.
Save mustafabutt-dev/772dc075f44561ff923e9b0fb761ed38 to your computer and use it in GitHub Desktop.
Integrate ChatGPT in JavaScript app
// import the ChatGPTAPI
import { ChatGPTAPI } from 'chatgpt'
async function myFunction() {
// Initialize the constructor with your OpenAI API key
const api = new ChatGPTAPI({
apiKey: YOUR_OPENAI_API_KEY
})
// Invoke the sendMessage method to send a message to the GPT-3 model
const res = await api.sendMessage('Hello World!');
// display the response
console.log(res.text);
}
// Make the function call to execute the functionality
myFunction().then((data)=>{
// do something
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment