Created
January 14, 2023 15:56
-
-
Save bedwards/642f1364e31b627cd443b5191c78c39d 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
import dotenv from "dotenv"; | |
import {Configuration, OpenAIApi} from "openai"; | |
dotenv.config(); | |
const prompt = process.argv.slice(2).join(" "); | |
const configuration = new Configuration({ | |
organization: process.env.OPENAI_ORG_ID, | |
apiKey: process.env.OPENAI_API_KEY, | |
}); | |
const openai = new OpenAIApi(configuration); | |
try { | |
const completion = await openai.createCompletion({ | |
model: "text-davinci-003", | |
prompt: prompt, | |
temperature: 0.6, | |
max_tokens: 2048, | |
}); | |
completion.data.choices.forEach(x => { | |
console.log(x.text); | |
}); | |
} catch (error) { | |
if (error.response) { | |
console.log(JSON.stringify(error.response.data)); | |
console.log(JSON.stringify(completionerror.response.status)); | |
console.log(JSON.stringify(error.response.headers)); | |
} else if (error.request) { | |
console.log(JSON.stringify(error.request)); | |
} else { | |
console.log('Error ' + JSON.stringify(error.message)); | |
} | |
console.log(JSON.stringify(error.config)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment