zyratlo commented on code in PR #7601:
URL: https://github.com/apache/texera/pull/7601#discussion_r3778775072
##########
frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.ts:
##########
@@ -312,6 +322,107 @@ export class UserWorkflowComponent implements
AfterViewInit {
});
}
+ public get pythonNotebookMigrationEnabled(): boolean {
+ return this.config.env.pythonNotebookMigrationEnabled;
+ }
+
+ /** Open the AI-generate import modal, wiring its submit to
generateWorkflowFromNotebook. */
+ public openAiGenerateModal(): void {
+ this.modalService.create<NotebookImportModalComponent,
NotebookImportModalData>({
+ nzTitle: "AI Generate Workflow from Python Notebook",
+ nzContent: NotebookImportModalComponent,
+ nzWidth: 700,
+ nzFooter: null,
+ nzCentered: true,
+ nzData: {
+ requestImport: (file, model) =>
this.generateWorkflowFromNotebook(file, model),
+ },
+ });
+ }
+
+ /**
+ * Parse the notebook, generate a workflow via the LLM, save it, store the
cell mapping, and open it.
+ * Resolves true on success (modal closes), false to keep the modal open on
a bad file or a failure.
+ */
+ private async generateWorkflowFromNotebook(file: NzUploadFile, model:
string): Promise<boolean> {
+ const fileExtension = file.name.split(".").pop()?.toLowerCase();
+ if (fileExtension !== "ipynb") {
+ this.notificationService.error("Please upload a valid Jupyter Notebook
(.ipynb) file.");
+ return false;
+ }
+ let notebook: Notebook;
+ try {
+ notebook = await this.notebookMigrationService.parseAndTagNotebook(file
as unknown as File);
+ } catch (error) {
+ this.notificationService.error("Failed to read the notebook file. Please
upload a valid .ipynb file.");
+ console.error("Notebook parse failed:", error);
+ return false;
+ }
+
+ let generated: { workflowContent: WorkflowContent; mappingContent:
MappingContent };
+ try {
+ generated = await
this.notebookMigrationService.sendToAIGenerateWorkflow(notebook, model);
+ } catch (error) {
+ this.notificationService.error("Error while communicating with the LLM,
check console for details.");
+ console.error("LLM generation failed:", error);
+ return false;
+ }
+
+ // Commit point: persisting captures the expensive LLM result. On failure
nothing was created,
+ // so returning false to let the user retry is safe.
+ let wid: number;
+ try {
+ // workflow.name is VARCHAR(128); cap the base so base + suffix fits the
column.
+ const generatedSuffix = "_GENERATED_BY_LLM";
+ const generatedName = this.deriveWorkflowName(file.name).slice(0, 128 -
generatedSuffix.length);
+ const createdWorkflow = await firstValueFrom(
Review Comment:
Fixed in
[3698d6f](https://github.com/apache/texera/pull/7601/commits/3698d6f30b04ec374c7f120d1b2d517846a5bcd7).
The component now sets a destroyed flag in ngOnDestroy and gates the final
router.navigate on it. If the user leaves mid-generation the workflow is still
created and saved to the dashboard, but we no longer navigate them into the
workspace after the fact. An info toast tells them it was saved. Added a spec
covering the destroyed path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]