Created
January 3, 2023 11:34
-
-
Save deleteman/7598de71767ec1c8317e66981fe35dc9 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"); | |
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