Skip to content

Instantly share code, notes, and snippets.

@kidGodzilla
Last active April 5, 2024 21:15
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidGodzilla/d581a4ca9f9faea9de5d89f44dcf99bd to your computer and use it in GitHub Desktop.
Save kidGodzilla/d581a4ca9f9faea9de5d89f44dcf99bd to your computer and use it in GitHub Desktop.
OpenAI Chat Completion Example
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