Skip to content

Instantly share code, notes, and snippets.

@tanner-west
Created June 30, 2023 02:02
Show Gist options
  • Save tanner-west/c7a07090a3e2301c093b9c9fbcb95c41 to your computer and use it in GitHub Desktop.
Save tanner-west/c7a07090a3e2301c093b9c9fbcb95c41 to your computer and use it in GitHub Desktop.
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: "xxx",
});
const openai = new OpenAIApi(configuration);
async function callCompletionAPI() {
try {
const response = await openai.createChatCompletion({
messages: [
{
role: "user",
content:
"Generate 25 tweets based on historically accurate information that various founding fathers might have tweeted if they had Twitter accounts in 1776.",
},
],
model: "gpt-3.5-turbo-0613",
functions: [
{
name: "create_tweets",
description: "Creates tweets",
parameters: {
type: "object",
properties: {
tweets: {
type: "array",
items: {
type: "object",
properties: {
dateTimeISO: {
type: "string",
},
content: {
type: "string",
},
sender: {
type: "string",
}
},
},
},
},
required: ["tweets"],
},
},
],
});
console.log(response.data.choices[0].message);
} catch (error) {
console.error("Error:", error);
}
}
callCompletionAPI();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment