Last active
March 14, 2023 14:28
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