Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created January 3, 2023 11:34
Show Gist options
  • Save deleteman/7598de71767ec1c8317e66981fe35dc9 to your computer and use it in GitHub Desktop.
Save deleteman/7598de71767ec1c8317e66981fe35dc9 to your computer and use it in GitHub Desktop.
const { Configuration, OpenAIApi } = require("openai");
require('dotenv').config()
const readline = require('node:readline/promises').createInterface({
input: process.stdin,
output: process.stdout
});
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY
});
const openai = new OpenAIApi(configuration);
async function writeEmail(name, topic, destination) {
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: `Write an email for ${destination}, ${topic}, my name is ${name}`,
max_tokens: 200,
temperature: 0.7,
});
console.log(response.data.choices[0].text)
}
(async () => {
let destination = await readline.question('Who is the email for? (let us know if this person knows you) ')
let name = await readline.question("What's your name? ")
let topic = await readline.question('What is the email about? ')
await writeEmail(name, topic, destination)
readline.close();
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment