@bramato/openrouter-mock-generator
Version:
AI-powered mock data generator using OpenRouter API with JSON mode support
176 lines (168 loc) ⢠6.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv/config");
const fs_1 = require("fs");
const path_1 = require("path");
const image_mock_generator_1 = require("../services/image-mock-generator");
class ImageGeneratorCLI {
async run() {
try {
const options = this.parseArguments();
if (options.prompts.length === 0) {
this.showHelp();
return;
}
const hfApiKey = this.getHuggingFaceApiKey();
// Note: Hugging Face API key is optional for some models
this.generator = new image_mock_generator_1.ImageMockGenerator(hfApiKey || undefined);
console.log('š¤ AI Image Generator');
console.log(`š Generating ${options.prompts.length} image(s)...`);
const results = await this.generator.generateMultipleImageMocks(options.prompts, {
model: options.model,
size: options.size,
quality: options.quality,
style: options.style,
uploadToCloud: options.uploadToCloud,
});
// Output results
if (options.output) {
this.saveResults(results, options);
console.log(`š Results saved to: ${options.output}`);
}
else {
this.displayResults(results, options.format);
}
}
catch (error) {
console.error('ā Image generation failed:', error instanceof Error ? error.message : 'Unknown error');
process.exit(1);
}
}
parseArguments() {
const args = process.argv.slice(2);
const options = {
prompts: [],
uploadToCloud: false,
format: 'json',
};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
switch (arg) {
case '--model':
case '-m':
options.model = args[++i];
break;
case '--size':
case '-s':
options.size = args[++i];
break;
case '--quality':
case '-q':
options.quality = args[++i];
break;
case '--style':
options.style = args[++i];
break;
case '--count':
case '-c':
options.count = parseInt(args[++i]);
break;
case '--upload-cloud':
case '--cloud':
case '--upload-s3':
case '--s3':
options.uploadToCloud = true;
break;
case '--output':
case '-o':
options.output = args[++i];
break;
case '--format':
case '-f':
options.format = args[++i];
break;
case '--help':
case '-h':
this.showHelp();
process.exit(0);
break;
default:
if (!arg.startsWith('-')) {
options.prompts.push(arg);
}
break;
}
}
return options;
}
getHuggingFaceApiKey() {
try {
const envPath = (0, path_1.join)(process.cwd(), '.env');
const envContent = (0, fs_1.readFileSync)(envPath, 'utf8');
const match = envContent.match(/HUGGINGFACE_API_KEY=(.+)/);
return match ? match[1].trim() : null;
}
catch {
return null;
}
}
saveResults(results, options) {
if (!options.output || !this.generator)
return;
let content;
if (options.format === 'markdown') {
content = this.generator.formatResultsAsMarkdown(results);
}
else {
content = this.generator.formatResultsAsJSON(results);
}
(0, fs_1.writeFileSync)(options.output, content, 'utf8');
}
displayResults(results, format) {
if (!this.generator)
return;
if (format === 'markdown') {
console.log('\n' + this.generator.formatResultsAsMarkdown(results));
}
else {
console.log('\n' + this.generator.formatResultsAsJSON(results));
}
}
showHelp() {
console.log(`
šØ AI Image Generator
USAGE:
ai-generate-images [OPTIONS] <prompt1> [prompt2] [prompt3]...
OPTIONS:
-m, --model <model> OpenRouter model to use
-s, --size <size> Image size (256x256, 512x512, 1024x1024, 1024x1792, 1792x1024)
-q, --quality <quality> Image quality (standard, hd)
--style <style> Image style (vivid, natural)
-c, --count <number> Number of images per prompt (default: 1)
--cloud, --upload-cloud Upload images to configured cloud storage (AWS S3 or DigitalOcean Spaces)
-o, --output <file> Save results to file
-f, --format <format> Output format (json, markdown)
-h, --help Show this help
EXAMPLES:
# Generate single image
ai-generate-images "A sunset over mountains"
# Generate multiple images
ai-generate-images "Cat playing piano" "Dog reading book" "Robot cooking"
# Upload to cloud storage and save as markdown
ai-generate-images --cloud --format markdown --output results.md "AI generated art"
# Specify model and size
ai-generate-images --model "openrouter/horizon-beta" --size "1024x1024" "Abstract art"
SETUP:
1. Run 'ai-init' to configure cloud storage (AWS S3 or DigitalOcean Spaces)
2. (Optional) Set HUGGINGFACE_API_KEY in .env for better rate limits
NOTE:
This tool uses Hugging Face Inference API for image generation.
Some models work without API key but with rate limits.
`);
}
}
// Run CLI
const cli = new ImageGeneratorCLI();
cli.run();
//# sourceMappingURL=generate-images.js.map