misc.generate: add time/retries
This commit is contained in:
parent
4df473339d
commit
8ccd08d56c
1 changed files with 13 additions and 1 deletions
|
@ -2,7 +2,12 @@ const Command = require("../lib/command.js");
|
|||
const CATEGORY = "misc";
|
||||
|
||||
const fetch = require("node-fetch");
|
||||
const {hastebin, safeString, parseHtmlEntities} = require("../lib/utils.js");
|
||||
const {
|
||||
hastebin,
|
||||
safeString,
|
||||
parseHtmlEntities,
|
||||
formatTime,
|
||||
} = require("../lib/utils.js");
|
||||
const GoogleImages = require("google-images");
|
||||
|
||||
const imagesClient = new GoogleImages(hf.apikeys.gimg, hf.apikeys.google);
|
||||
|
@ -405,6 +410,9 @@ generate.helpText = "Generate images from prompt via craiyon";
|
|||
generate.callback = async function (msg, line) {
|
||||
if (!line || line.length === 0) return "Arguments required.";
|
||||
|
||||
const start = Date.now();
|
||||
let retries = 0;
|
||||
|
||||
let request = await fetch("https://backend.craiyon.com/generate", {
|
||||
method: "POST",
|
||||
headers: GENERATE_HEADERS,
|
||||
|
@ -416,6 +424,7 @@ generate.callback = async function (msg, line) {
|
|||
headers: GENERATE_HEADERS,
|
||||
body: JSON.stringify({prompt: line}),
|
||||
});
|
||||
retries++;
|
||||
}
|
||||
|
||||
const data = await request.json();
|
||||
|
@ -426,6 +435,9 @@ generate.callback = async function (msg, line) {
|
|||
const title = `Responses for "${safeString(line)}"`;
|
||||
|
||||
const out = {
|
||||
content: `Generated in ${formatTime(Date.now() - start)}${
|
||||
retries > 0 ? " with " + retries + " retries" : ""
|
||||
}`,
|
||||
embeds: [],
|
||||
file: images,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue