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:
@@ -258,8 +258,8 @@ const tableActionsConfigs: Record<string, TableActionsConfig> = {
|
||||
variant: 'primary',
|
||||
},
|
||||
{
|
||||
key: 'generate_images',
|
||||
label: 'Generate Images',
|
||||
key: 'generate_image_prompts',
|
||||
label: 'Generate Image Prompts',
|
||||
icon: <BoltIcon className="w-5 h-5 text-purple-500" />,
|
||||
variant: 'primary',
|
||||
},
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -952,6 +952,13 @@ export async function autoGenerateImages(taskIds: number[]): Promise<{ success:
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateImagePrompts(contentIds: number[]): Promise<any> {
|
||||
return fetchAPI('/v1/writer/content/generate_image_prompts/', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ ids: contentIds }),
|
||||
});
|
||||
}
|
||||
|
||||
// TaskImages API functions
|
||||
export interface TaskImage {
|
||||
id: number;
|
||||
|
||||
Reference in New Issue
Block a user