File size: 966 Bytes
e1999d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
const axios = require('axios')
api_base = process.env.OPENAI_API_BASE;
api_key = process.env.OPENAI_API_KEY;
api_version = '2023-06-01-preview'
url = api_base + "openai/images/generations:submit?api-version=" + api_version
headers = { "api-key": api_key, "Content-Type": "application/json" }
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function txt2images(prompt,size) {
body = {
"prompt": prompt,
"size": size,
"n": 1
}
submission = await axios.post(url, body, { headers });
operation_location = submission.headers['operation-location'];
status = "";
while (status != "succeeded") {
await sleep(1000);
res = await axios.get(operation_location, { headers });
status = res.data.status;
console.log(status)
if (status == "succeeded") {
return res.data.result.data[0].url;
}
}
}
exports.txt2img = txt2images;
|