mirror of https://github.com/garrytan/gstack.git
Merge PR #1273: remove ~/.gstack/openai.json fallback in design/prototype.ts
This commit is contained in:
commit
e36bf7e5f2
|
|
@ -9,8 +9,7 @@
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const API_KEY = process.env.OPENAI_API_KEY
|
const API_KEY = process.env.OPENAI_API_KEY;
|
||||||
|| JSON.parse(fs.readFileSync(path.join(process.env.HOME!, ".gstack/openai.json"), "utf-8")).api_key;
|
|
||||||
|
|
||||||
if (!API_KEY) {
|
if (!API_KEY) {
|
||||||
console.error("No API key found. Set OPENAI_API_KEY or save to ~/.gstack/openai.json");
|
console.error("No API key found. Set OPENAI_API_KEY or save to ~/.gstack/openai.json");
|
||||||
|
|
@ -85,7 +84,8 @@ async function generateMockup(brief: { name: string; prompt: string }) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputPath = path.join(OUTPUT_DIR, `${brief.name}.png`);
|
const safeName = brief.name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
||||||
|
const outputPath = OUTPUT_DIR + "/" + safeName + ".png";
|
||||||
const imageBuffer = Buffer.from(imageItem.result, "base64");
|
const imageBuffer = Buffer.from(imageItem.result, "base64");
|
||||||
fs.writeFileSync(outputPath, imageBuffer);
|
fs.writeFileSync(outputPath, imageBuffer);
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ async function main() {
|
||||||
const resultPath = await generateMockup(brief);
|
const resultPath = await generateMockup(brief);
|
||||||
results.push({ name: brief.name, path: resultPath });
|
results.push({ name: brief.name, path: resultPath });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`ERROR generating ${brief.name}:`, err);
|
console.error("ERROR generating:", brief.name, err);
|
||||||
results.push({ name: brief.name, path: null });
|
results.push({ name: brief.name, path: null });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +124,7 @@ async function main() {
|
||||||
console.log(`${succeeded.length}/${results.length} generated successfully`);
|
console.log(`${succeeded.length}/${results.length} generated successfully`);
|
||||||
|
|
||||||
if (failed.length > 0) {
|
if (failed.length > 0) {
|
||||||
console.log(`Failed: ${failed.map(f => f.name).join(", ")}`);
|
console.log("Failed:", failed.map(f => f.name).join(", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (succeeded.length > 0) {
|
if (succeeded.length > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue