Implement V2 AI functions and enhance progress handling
- Added support for new V2 functions: `auto_cluster_v2` and `generate_ideas_v2`, including backend logic and API endpoints. - Updated model configuration to ensure V2 functions validate the presence of models before execution. - Enhanced progress modal to provide better feedback during asynchronous tasks, including task IDs for debugging. - Updated frontend components to integrate new V2 functionalities and improve user experience with clustering and idea generation.
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
bulkDeleteClusters,
|
||||
bulkUpdateClustersStatus,
|
||||
autoGenerateIdeas,
|
||||
generateIdeasV2,
|
||||
Cluster,
|
||||
ClusterFilters,
|
||||
ClusterCreateData,
|
||||
@@ -218,6 +219,22 @@ export default function Clusters() {
|
||||
} catch (error: any) {
|
||||
toast.error(`Failed to generate ideas: ${error.message}`);
|
||||
}
|
||||
} else if (action === 'generate_ideas_v2') {
|
||||
try {
|
||||
const result = await generateIdeasV2([row.id]);
|
||||
|
||||
if (result.success && result.task_id) {
|
||||
// Async task - show progress modal
|
||||
progressModal.openModal(result.task_id, 'Generate Ideas', 'ai_generate_ideas_v2');
|
||||
} else if (result.success) {
|
||||
toast.success(result.message || 'Ideas generated successfully');
|
||||
await loadClusters();
|
||||
} else {
|
||||
toast.error(result.error || 'Failed to generate ideas');
|
||||
}
|
||||
} catch (error: any) {
|
||||
toast.error(`Failed to generate ideas: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}, [toast, progressModal, loadClusters]);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
Cluster,
|
||||
API_BASE_URL,
|
||||
autoClusterKeywords,
|
||||
autoClusterKeywordsV2,
|
||||
fetchSeedKeywords,
|
||||
SeedKeyword,
|
||||
} from '../../services/api';
|
||||
@@ -448,6 +449,35 @@ export default function Keywords() {
|
||||
}]);
|
||||
toast.error(errorMsg);
|
||||
}
|
||||
} else if (action === 'keywords_clustering') {
|
||||
if (ids.length === 0) {
|
||||
toast.error('Please select at least one keyword');
|
||||
return;
|
||||
}
|
||||
if (ids.length > 50) {
|
||||
toast.error('Maximum 50 keywords allowed for clustering');
|
||||
return;
|
||||
}
|
||||
|
||||
const numIds = ids.map(id => parseInt(id));
|
||||
const sectorId = activeSector?.id;
|
||||
|
||||
try {
|
||||
const result = await autoClusterKeywordsV2(numIds, sectorId);
|
||||
|
||||
if (result.success && result.task_id) {
|
||||
// Async task - open progress modal
|
||||
hasReloadedRef.current = false;
|
||||
progressModal.openModal(result.task_id, 'Keywords Clustering', 'ai_auto_cluster_v2');
|
||||
} else if (result.success) {
|
||||
toast.success(result.message || 'Clustering completed');
|
||||
await loadKeywords();
|
||||
} else {
|
||||
toast.error(result.error || 'Clustering failed');
|
||||
}
|
||||
} catch (error: any) {
|
||||
toast.error(`Clustering failed: ${error.message}`);
|
||||
}
|
||||
} else {
|
||||
toast.info(`Bulk action "${action}" for ${ids.length} items`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user