feat: support local storage

This commit is contained in:
Hk-Gosuto
2024-01-05 18:41:16 +08:00
parent 8e10354109
commit 296df592e0
18 changed files with 181 additions and 56 deletions

View File

@@ -8,6 +8,13 @@ export class StableDiffusionWrapper extends Tool {
super();
}
async saveImage(imageBase64: string) {
const buffer = Buffer.from(imageBase64, "base64");
var fileName = `${Date.now()}.png`;
const filePath = await S3FileStorage.put(fileName, buffer);
return filePath;
}
/** @ignore */
async _call(prompt: string) {
let url = process.env.STABLE_DIFFUSION_API_URL;
@@ -40,8 +47,7 @@ export class StableDiffusionWrapper extends Tool {
const json = await response.json();
let imageBase64 = json.images[0];
if (!imageBase64) return "No image was generated";
const buffer = Buffer.from(imageBase64, "base64");
const filePath = await S3FileStorage.put(`${Date.now()}.png`, buffer);
const filePath = await this.saveImage(imageBase64);
console.log(`[${this.name}]`, filePath);
return filePath;
}