ciyidogan commited on
Commit
0c17bf3
·
verified ·
1 Parent(s): 7193183

Update flare-ui/src/app/dialogs/version-edit-dialog/version-edit-dialog.component.ts

Browse files
flare-ui/src/app/dialogs/version-edit-dialog/version-edit-dialog.component.ts CHANGED
@@ -391,32 +391,41 @@ export default class VersionEditDialogComponent implements OnInit {
391
  });
392
  }
393
 
394
- async loadVersions() {
395
- this.loading = true;
396
- try {
397
- const project = await this.apiService.getProject(this.project.id).toPromise();
398
- if (project) {
399
- this.project = project;
400
- this.versions = project.versions || [];
401
-
402
- // Re-select current version if it still exists
403
- if (this.selectedVersion) {
404
- const currentVersion = this.versions.find(v => v.id === this.selectedVersion!.id);
405
- if (currentVersion) {
406
- this.loadVersion(currentVersion);
407
- } else if (this.versions.length > 0) {
408
- this.loadVersion(this.versions[0]);
409
- }
410
- } else if (this.versions.length > 0) {
411
- this.loadVersion(this.versions[0]);
 
 
 
 
 
 
 
412
  }
413
- }
414
- } catch (error) {
415
- this.snackBar.open('Failed to reload versions', 'Close', { duration: 3000 });
416
- } finally {
417
- this.loading = false;
418
  }
419
- }
 
 
 
 
 
 
420
 
421
  async saveVersion() {
422
  if (!this.selectedVersion) {
@@ -445,55 +454,40 @@ export default class VersionEditDialogComponent implements OnInit {
445
  return;
446
  }
447
 
448
- // selectedVersion null check'i yukarıda yapıldı, artık güvenle kullanabiliriz
449
- const currentVersion = this.selectedVersion!; // Non-null assertion
450
 
451
  this.saving = true;
452
 
453
  try {
454
  const formValue = this.versionForm.getRawValue();
455
 
456
- // LLM config'i düzgün formatta hazırla
457
- const llmConfig = {
458
- repo_id: formValue.llm.repo_id,
459
- generation_config: formValue.llm.generation_config,
460
- use_fine_tune: formValue.llm.use_fine_tune,
461
- fine_tune_zip: formValue.llm.fine_tune_zip
462
- };
463
-
464
- // Intent verilerini düzgün formatta hazırla
465
- const intents = formValue.intents.map((intent: any) => ({
466
- name: intent.name,
467
- caption: intent.caption,
468
- locale: intent.locale,
469
- detection_prompt: intent.detection_prompt,
470
- examples: Array.isArray(intent.examples) ? intent.examples.filter((ex: any) => ex) : [],
471
- parameters: Array.isArray(intent.parameters) ? intent.parameters.map((param: any) => ({
472
- name: param.name,
473
- caption: param.caption,
474
- type: param.type,
475
- required: param.required,
476
- variable_name: param.variable_name,
477
- extraction_prompt: param.extraction_prompt,
478
- validation_regex: param.validation_regex,
479
- invalid_prompt: param.invalid_prompt,
480
- type_error_prompt: param.type_error_prompt
481
- })) : [],
482
- action: intent.action,
483
- fallback_timeout_prompt: intent.fallback_timeout_prompt,
484
- fallback_error_prompt: intent.fallback_error_prompt
485
- }));
486
-
487
- // updateData'yı burada tanımla - currentVersion kullan
488
  const updateData = {
489
  caption: formValue.caption,
490
- description: formValue.caption,
491
- default_api: currentVersion.default_api || '',
492
- published: currentVersion.published,
493
- llm: llmConfig,
494
- intents: intents,
495
- parameters: [],
496
- last_update_date: currentVersion.last_update_date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
  };
498
 
499
  console.log('Saving version data:', JSON.stringify(updateData, null, 2));
@@ -506,7 +500,6 @@ export default class VersionEditDialogComponent implements OnInit {
506
 
507
  this.snackBar.open('Version saved successfully', 'Close', { duration: 3000 });
508
 
509
- // Update version data locally
510
  if (result) {
511
  this.selectedVersion = result;
512
  this.versionForm.patchValue({
@@ -514,47 +507,33 @@ export default class VersionEditDialogComponent implements OnInit {
514
  });
515
  }
516
 
517
- // Reload versions
518
  await this.loadVersions();
519
 
520
  } catch (error: any) {
521
  console.error('Save error:', error);
522
 
523
  if (error.status === 409) {
524
- // updateData'ya burada da ihtiyacımız var
525
  const formValue = this.versionForm.getRawValue();
526
- const llmConfig = {
527
- repo_id: formValue.llm.repo_id,
528
- generation_config: formValue.llm.generation_config,
529
- use_fine_tune: formValue.llm.use_fine_tune,
530
- fine_tune_zip: formValue.llm.fine_tune_zip
531
- };
532
 
533
- const intents = formValue.intents.map((intent: any) => ({
534
- name: intent.name,
535
- caption: intent.caption,
536
- locale: intent.locale,
537
- detection_prompt: intent.detection_prompt,
538
- examples: Array.isArray(intent.examples) ? intent.examples.filter((ex: any) => ex) : [],
539
- parameters: Array.isArray(intent.parameters) ? intent.parameters : [],
540
- action: intent.action,
541
- fallback_timeout_prompt: intent.fallback_timeout_prompt,
542
- fallback_error_prompt: intent.fallback_error_prompt
543
- }));
544
-
545
  const retryUpdateData = {
546
  caption: formValue.caption,
547
- description: formValue.caption,
548
- default_api: currentVersion.default_api || '',
549
- published: currentVersion.published,
550
- llm: llmConfig,
551
- intents: intents,
552
- parameters: [],
553
- last_update_date: currentVersion.last_update_date
 
 
 
 
 
 
 
554
  };
555
 
556
- const { default: ConfirmDialogComponent } = await import('../confirm-dialog/confirm-dialog.component');
557
-
558
  const dialogRef = this.dialog.open(ConfirmDialogComponent, {
559
  width: '500px',
560
  data: {
@@ -568,13 +547,12 @@ export default class VersionEditDialogComponent implements OnInit {
568
 
569
  dialogRef.afterClosed().subscribe(async (forceSave) => {
570
  if (forceSave) {
571
- // Force save
572
  try {
573
  await this.apiService.updateVersion(
574
  this.project.id,
575
  currentVersion.id,
576
  retryUpdateData,
577
- true // force flag
578
  ).toPromise();
579
  this.snackBar.open('Version force saved', 'Close', { duration: 3000 });
580
  await this.loadVersions();
@@ -585,7 +563,6 @@ export default class VersionEditDialogComponent implements OnInit {
585
  });
586
  }
587
  } else {
588
- // Reload
589
  await this.loadVersions();
590
  }
591
  });
@@ -600,7 +577,7 @@ export default class VersionEditDialogComponent implements OnInit {
600
  this.saving = false;
601
  }
602
  }
603
-
604
  async publishVersion() {
605
  if (!this.selectedVersion) return;
606
 
 
391
  });
392
  }
393
 
394
+ loadVersion(version: Version) {
395
+ this.selectedVersion = version;
396
+
397
+ // Form değerlerini set et
398
+ this.versionForm.patchValue({
399
+ id: version.id,
400
+ caption: version.caption || '',
401
+ published: version.published || false,
402
+ general_prompt: (version as any).general_prompt || '', // Backend'den gelen general_prompt
403
+ last_update_date: version.last_update_date || ''
404
+ });
405
+
406
+ // LLM config'i ayrı set et
407
+ if (version.llm) {
408
+ this.versionForm.patchValue({
409
+ llm: {
410
+ repo_id: version.llm.repo_id || '',
411
+ generation_config: version.llm.generation_config || {
412
+ max_new_tokens: 512,
413
+ temperature: 0.7,
414
+ top_p: 0.95,
415
+ repetition_penalty: 1.1
416
+ },
417
+ use_fine_tune: version.llm.use_fine_tune || false,
418
+ fine_tune_zip: version.llm.fine_tune_zip || ''
419
  }
420
+ });
 
 
 
 
421
  }
422
+
423
+ // Clear and rebuild intents
424
+ this.intents.clear();
425
+ (version.intents || []).forEach(intent => {
426
+ this.intents.push(this.createIntentFormGroup(intent));
427
+ });
428
+ }
429
 
430
  async saveVersion() {
431
  if (!this.selectedVersion) {
 
454
  return;
455
  }
456
 
457
+ const currentVersion = this.selectedVersion!;
 
458
 
459
  this.saving = true;
460
 
461
  try {
462
  const formValue = this.versionForm.getRawValue();
463
 
464
+ // updateData'yı backend'in beklediği formatta hazırla
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
  const updateData = {
466
  caption: formValue.caption,
467
+ general_prompt: formValue.general_prompt, // Bu alan eksikti
468
+ llm: formValue.llm,
469
+ intents: formValue.intents.map((intent: any) => ({
470
+ name: intent.name,
471
+ caption: intent.caption,
472
+ locale: intent.locale,
473
+ detection_prompt: intent.detection_prompt,
474
+ examples: Array.isArray(intent.examples) ? intent.examples.filter((ex: any) => ex) : [],
475
+ parameters: Array.isArray(intent.parameters) ? intent.parameters.map((param: any) => ({
476
+ name: param.name,
477
+ caption: param.caption,
478
+ type: param.type,
479
+ required: param.required,
480
+ variable_name: param.variable_name,
481
+ extraction_prompt: param.extraction_prompt,
482
+ validation_regex: param.validation_regex,
483
+ invalid_prompt: param.invalid_prompt,
484
+ type_error_prompt: param.type_error_prompt
485
+ })) : [],
486
+ action: intent.action,
487
+ fallback_timeout_prompt: intent.fallback_timeout_prompt,
488
+ fallback_error_prompt: intent.fallback_error_prompt
489
+ })),
490
+ last_update_date: currentVersion.last_update_date || ''
491
  };
492
 
493
  console.log('Saving version data:', JSON.stringify(updateData, null, 2));
 
500
 
501
  this.snackBar.open('Version saved successfully', 'Close', { duration: 3000 });
502
 
 
503
  if (result) {
504
  this.selectedVersion = result;
505
  this.versionForm.patchValue({
 
507
  });
508
  }
509
 
 
510
  await this.loadVersions();
511
 
512
  } catch (error: any) {
513
  console.error('Save error:', error);
514
 
515
  if (error.status === 409) {
516
+ // Race condition handling
517
  const formValue = this.versionForm.getRawValue();
 
 
 
 
 
 
518
 
 
 
 
 
 
 
 
 
 
 
 
 
519
  const retryUpdateData = {
520
  caption: formValue.caption,
521
+ general_prompt: formValue.general_prompt,
522
+ llm: formValue.llm,
523
+ intents: formValue.intents.map((intent: any) => ({
524
+ name: intent.name,
525
+ caption: intent.caption,
526
+ locale: intent.locale,
527
+ detection_prompt: intent.detection_prompt,
528
+ examples: Array.isArray(intent.examples) ? intent.examples.filter((ex: any) => ex) : [],
529
+ parameters: Array.isArray(intent.parameters) ? intent.parameters : [],
530
+ action: intent.action,
531
+ fallback_timeout_prompt: intent.fallback_timeout_prompt,
532
+ fallback_error_prompt: intent.fallback_error_prompt
533
+ })),
534
+ last_update_date: currentVersion.last_update_date || ''
535
  };
536
 
 
 
537
  const dialogRef = this.dialog.open(ConfirmDialogComponent, {
538
  width: '500px',
539
  data: {
 
547
 
548
  dialogRef.afterClosed().subscribe(async (forceSave) => {
549
  if (forceSave) {
 
550
  try {
551
  await this.apiService.updateVersion(
552
  this.project.id,
553
  currentVersion.id,
554
  retryUpdateData,
555
+ true
556
  ).toPromise();
557
  this.snackBar.open('Version force saved', 'Close', { duration: 3000 });
558
  await this.loadVersions();
 
563
  });
564
  }
565
  } else {
 
566
  await this.loadVersions();
567
  }
568
  });
 
577
  this.saving = false;
578
  }
579
  }
580
+
581
  async publishVersion() {
582
  if (!this.selectedVersion) return;
583