Created
June 30, 2023 02:02
-
-
Save tanner-west/c7a07090a3e2301c093b9c9fbcb95c41 to your computer and use it in GitHub Desktop.
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"); | |
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