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:
Desktop
2025-11-10 22:16:02 +05:00
parent 46f5bb4d62
commit e2f2d79d4c
12 changed files with 920 additions and 58 deletions

View File

@@ -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`);
}