Created
January 15, 2023 14:49
-
-
Save Andrej123456789/c197b7c87039edee40af7b9461f5a646 to your computer and use it in GitHub Desktop.
This file contains 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 { Configuration, OpenAIApi } from "openai"; | |
import { writeFileSync } from "fs"; | |
async function Generate(prompt) { | |
const configuration = new Configuration({ | |
apiKey: "your api key", | |
}); | |
const openai = new OpenAIApi(configuration); | |
const result = await openai.createImage({ | |
prompt, | |
n: 1, | |
size: "1024x1024", | |
user: "Andrej", | |
}); | |
const url = result.data.data[0].url; | |
console.log(url); | |
const imgResult = await fetch(url); | |
const blob = await imgResult.blob(); | |
const buffer = Buffer.from(await blob.arrayBuffer()); | |
writeFileSync(`./img/${Date.now()}.png`, buffer); | |
} | |
/* Main function */ | |
// Generate("monorail"); | |
Generate("your prompt goes here"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment