Last active
April 19, 2023 05:09
-
-
Save eniodev/5f806fd9b6f8a950e912a76757947afe to your computer and use it in GitHub Desktop.
This is a starter snippet for building applications powered by openAI models
This file contains hidden or 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
| // npm i openai dotenv | |
| import { config } from 'dotenv'; | |
| config(); | |
| // OpenAI API Configuration | |
| import { Configuration, OpenAIApi } from "openai"; | |
| const configuration = new Configuration({ | |
| apiKey: process.env.OPENAI_API_KEY, // Replace this with your key | |
| }); | |
| const openai = new OpenAIApi(configuration); | |
| // Fetch the data passing your prompt | |
| export const getGPTResponse = async (prompt) => { | |
| const response = await openai.createCompletion({ | |
| model: "text-davinci-003", // This is where you put your openAI model | |
| prompt: `${prompt}`, | |
| temperature: 0, | |
| max_tokens: 150, // This is the max tokens you want for your response | |
| top_p: 1, | |
| frequency_penalty: 0.0, | |
| presence_penalty: 0.6, | |
| stop: [" Human:", " AI:"], | |
| }) | |
| if(response) { | |
| return `${response.data.choices[0].text}`; // This is your final response | |
| } | |
| } | |
| //Ok, you are all set up! 😁 | |
| //For more information about each parameter and the variety of available models, please check: https://platform.openai.com/docs/models |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment