Last active
April 5, 2024 21:15
-
-
Save kidGodzilla/d581a4ca9f9faea9de5d89f44dcf99bd to your computer and use it in GitHub Desktop.
OpenAI Chat Completion Example
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
const { Configuration, OpenAIApi } = require('openai'); | |
let openai; | |
const instructions = ``; | |
if (process.env.OPEN_AI_API_KEY) { | |
const configuration = new Configuration({ apiKey: process.env.OPEN_AI_API_KEY }); | |
openai = new OpenAIApi(configuration); | |
} | |
const response = await openai.createChatCompletion({ | |
model: "gpt-3.5-turbo", | |
temperature: 0.888, | |
max_tokens: 2048, | |
frequency_penalty: 0, | |
presence_penalty: 0, | |
top_p: 1, | |
messages: [{role: "system", content: instructions}, {role: "user", content: ''}], // {role: "assistant", content: ''} | |
}, { timeout: 60000 }); | |
const response_text = response.data.choices[0].message.content.trim(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment