Last active
March 14, 2023 14:28
-
-
Save mustafabutt-dev/772dc075f44561ff923e9b0fb761ed38 to your computer and use it in GitHub Desktop.
Integrate ChatGPT in JavaScript app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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