Add Generate Image Prompts Functionality: Implement new AI function for generating image prompts, update API endpoints, and integrate with frontend actions for content management.

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-11 17:40:08 +00:00
parent f4d62448cf
commit fa696064e2
9 changed files with 333 additions and 16 deletions

View File

@@ -9,7 +9,7 @@ import {
fetchContent,
Content as ContentType,
ContentFilters,
autoGenerateImages,
generateImagePrompts,
} from '../../services/api';
import { useToast } from '../../components/ui/toast/ToastContainer';
import { FileIcon } from '../../icons';
@@ -147,27 +147,20 @@ export default function Content() {
}, [pageConfig?.headerMetrics, content, totalCount]);
const handleRowAction = useCallback(async (action: string, row: ContentType) => {
if (action === 'generate_images') {
const taskId = row.task_id;
if (!taskId) {
toast.error('No task linked to this content for image generation');
return;
}
if (action === 'generate_image_prompts') {
try {
const result = await autoGenerateImages([taskId]);
const result = await generateImagePrompts([row.id]);
if (result.success) {
if (result.task_id) {
toast.success('Image generation started');
toast.success('Image prompts generation started');
} else {
toast.success(`Image generation complete: ${result.images_created || 0} image${(result.images_created || 0) === 1 ? '' : 's'} generated`);
toast.success(`Image prompts generated: ${result.prompts_created || 0} prompt${(result.prompts_created || 0) === 1 ? '' : 's'} created`);
}
} else {
toast.error(result.error || 'Failed to generate images');
toast.error(result.error || 'Failed to generate image prompts');
}
} catch (error: any) {
toast.error(`Failed to generate images: ${error.message}`);
toast.error(`Failed to generate prompts: ${error.message}`);
}
}
}, [toast]);