ciyidogan commited on
Commit
1e38a52
·
verified ·
1 Parent(s): 7623189

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
@@ -459,15 +459,31 @@ export default class VersionEditDialogComponent implements OnInit {
459
 
460
  try {
461
  const formValue = this.versionForm.getRawValue();
 
 
 
 
 
 
 
462
 
463
- // Intent verilerini düzgün formatta hazırla
464
  const intents = formValue.intents.map((intent: any) => ({
465
  name: intent.name,
466
  caption: intent.caption,
467
  locale: intent.locale,
468
  detection_prompt: intent.detection_prompt,
469
- examples: Array.isArray(intent.examples) ? intent.examples : [],
470
- parameters: Array.isArray(intent.parameters) ? intent.parameters : [],
 
 
 
 
 
 
 
 
 
 
471
  action: intent.action,
472
  fallback_timeout_prompt: intent.fallback_timeout_prompt,
473
  fallback_error_prompt: intent.fallback_error_prompt
@@ -475,17 +491,18 @@ export default class VersionEditDialogComponent implements OnInit {
475
 
476
  const updateData = {
477
  caption: formValue.caption,
478
- description: formValue.caption,
479
  default_api: this.selectedVersion.default_api || '',
480
- llm: formValue.llm,
 
481
  intents: intents,
482
- parameters: formValue.parameters || [],
483
- last_update_date: formValue.last_update_date
484
  };
485
 
486
- console.log('Saving version data:', updateData);
487
-
488
- await this.apiService.updateVersion(
489
  this.project.id,
490
  this.selectedVersion.id,
491
  updateData
@@ -493,30 +510,59 @@ export default class VersionEditDialogComponent implements OnInit {
493
 
494
  this.snackBar.open('Version saved successfully', 'Close', { duration: 3000 });
495
 
496
- // Update last_update_date for next save
497
- this.versionForm.patchValue({
498
- last_update_date: new Date().toISOString()
499
- });
 
 
 
500
 
501
- // Reload versions to get fresh data
502
  await this.loadVersions();
503
 
504
  } catch (error: any) {
505
  console.error('Save error:', error);
506
 
507
- if (error.status === 409 || error.requiresReload) {
508
- // Race condition handling kodunuz...
509
- } else {
510
- const errorMessage = error.error?.detail || error.message || 'Failed to save version';
511
- this.snackBar.open(errorMessage, 'Close', {
512
- duration: 5000,
513
- panelClass: 'error-snackbar'
514
- });
515
- }
516
- } finally {
517
- this.saving = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
518
  }
 
 
519
  }
 
520
 
521
  async publishVersion() {
522
  if (!this.selectedVersion) return;
 
459
 
460
  try {
461
  const formValue = this.versionForm.getRawValue();
462
+
463
+ const llmConfig = {
464
+ repo_id: formValue.llm.repo_id,
465
+ generation_config: formValue.llm.generation_config,
466
+ use_fine_tune: formValue.llm.use_fine_tune,
467
+ fine_tune_zip: formValue.llm.fine_tune_zip
468
+ };
469
 
 
470
  const intents = formValue.intents.map((intent: any) => ({
471
  name: intent.name,
472
  caption: intent.caption,
473
  locale: intent.locale,
474
  detection_prompt: intent.detection_prompt,
475
+ examples: Array.isArray(intent.examples) ? intent.examples.filter((ex: any) => ex) : [],
476
+ parameters: Array.isArray(intent.parameters) ? intent.parameters.map((param: any) => ({
477
+ name: param.name,
478
+ caption: param.caption,
479
+ type: param.type,
480
+ required: param.required,
481
+ variable_name: param.variable_name,
482
+ extraction_prompt: param.extraction_prompt,
483
+ validation_regex: param.validation_regex,
484
+ invalid_prompt: param.invalid_prompt,
485
+ type_error_prompt: param.type_error_prompt
486
+ })) : [],
487
  action: intent.action,
488
  fallback_timeout_prompt: intent.fallback_timeout_prompt,
489
  fallback_error_prompt: intent.fallback_error_prompt
 
491
 
492
  const updateData = {
493
  caption: formValue.caption,
494
+ description: formValue.caption, // description eksikti
495
  default_api: this.selectedVersion.default_api || '',
496
+ published: this.selectedVersion.published,
497
+ llm: llmConfig,
498
  intents: intents,
499
+ parameters: [], // Global parameters, genelde boş
500
+ last_update_date: this.selectedVersion.last_update_date
501
  };
502
 
503
+ console.log('Saving version data:', JSON.stringify(updateData, null, 2));
504
+
505
+ const result = await this.apiService.updateVersion(
506
  this.project.id,
507
  this.selectedVersion.id,
508
  updateData
 
510
 
511
  this.snackBar.open('Version saved successfully', 'Close', { duration: 3000 });
512
 
513
+ // Update version data locally
514
+ if (result) {
515
+ this.selectedVersion = result;
516
+ this.versionForm.patchValue({
517
+ last_update_date: result.last_update_date
518
+ });
519
+ }
520
 
521
+ // Reload versions
522
  await this.loadVersions();
523
 
524
  } catch (error: any) {
525
  console.error('Save error:', error);
526
 
527
+ if (error.status === 409) {
528
+ const dialogRef = this.dialog.open(ConfirmDialogComponent, {
529
+ width: '500px',
530
+ data: {
531
+ title: 'Version Modified',
532
+ message: 'This version was modified by another user. Do you want to reload and lose your changes, or force save?',
533
+ confirmText: 'Force Save',
534
+ cancelText: 'Reload',
535
+ confirmColor: 'warn'
536
+ }
537
+ });
538
+
539
+ dialogRef.afterClosed().subscribe(async (forceSave) => {
540
+ if (forceSave) {
541
+ // Force save
542
+ await this.apiService.updateVersion(
543
+ this.project.id,
544
+ this.selectedVersion!.id,
545
+ updateData,
546
+ true // force flag
547
+ ).toPromise();
548
+ this.snackBar.open('Version force saved', 'Close', { duration: 3000 });
549
+ await this.loadVersions();
550
+ } else {
551
+ // Reload
552
+ await this.loadVersions();
553
+ }
554
+ });
555
+ } else {
556
+ const errorMessage = error.error?.detail || error.message || 'Failed to save version';
557
+ this.snackBar.open(errorMessage, 'Close', {
558
+ duration: 5000,
559
+ panelClass: 'error-snackbar'
560
+ });
561
  }
562
+ } finally {
563
+ this.saving = false;
564
  }
565
+ }
566
 
567
  async publishVersion() {
568
  if (!this.selectedVersion) return;