ciyidogan commited on
Commit
2269987
·
verified ·
1 Parent(s): 0078bab

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
@@ -127,7 +127,7 @@ export default class VersionEditDialogComponent implements OnInit {
127
  id: version.id,
128
  caption: version.caption || '',
129
  published: version.published || false,
130
- general_prompt: '', // Bu alan version'da yok, backend'de kontrol edilmeli
131
  last_update_date: version.last_update_date || ''
132
  });
133
 
@@ -154,6 +154,33 @@ export default class VersionEditDialogComponent implements OnInit {
154
  this.intents.push(this.createIntentFormGroup(intent));
155
  });
156
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  createIntentFormGroup(intent: any = {}): FormGroup {
159
  const group = this.fb.group({
@@ -391,42 +418,6 @@ export default class VersionEditDialogComponent implements OnInit {
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) {
432
  this.snackBar.open('No version selected', 'Close', { duration: 3000 });
@@ -464,7 +455,7 @@ export default class VersionEditDialogComponent implements OnInit {
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,
@@ -513,59 +504,8 @@ export default class VersionEditDialogComponent implements OnInit {
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: {
540
- title: 'Version Modified',
541
- message: 'This version was modified by another user. Do you want to reload and lose your changes, or force save?',
542
- confirmText: 'Force Save',
543
- cancelText: 'Reload',
544
- confirmColor: 'warn'
545
- }
546
- });
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();
559
- } catch (err: any) {
560
- this.snackBar.open(err.error?.detail || 'Force save failed', 'Close', {
561
- duration: 5000,
562
- panelClass: 'error-snackbar'
563
- });
564
- }
565
- } else {
566
- await this.loadVersions();
567
- }
568
- });
569
  } else {
570
  const errorMessage = error.error?.detail || error.message || 'Failed to save version';
571
  this.snackBar.open(errorMessage, 'Close', {
@@ -578,6 +518,62 @@ export default class VersionEditDialogComponent implements OnInit {
578
  }
579
  }
580
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
  async publishVersion() {
582
  if (!this.selectedVersion) return;
583
 
 
127
  id: version.id,
128
  caption: version.caption || '',
129
  published: version.published || false,
130
+ general_prompt: (version as any).general_prompt || '', // Backend'den gelen general_prompt
131
  last_update_date: version.last_update_date || ''
132
  });
133
 
 
154
  this.intents.push(this.createIntentFormGroup(intent));
155
  });
156
  }
157
+
158
+ async loadVersions() {
159
+ this.loading = true;
160
+ try {
161
+ const project = await this.apiService.getProject(this.project.id).toPromise();
162
+ if (project) {
163
+ this.project = project;
164
+ this.versions = [...project.versions].sort((a, b) => b.id - a.id);
165
+
166
+ // Re-select current version if it still exists
167
+ if (this.selectedVersion) {
168
+ const currentVersion = this.versions.find(v => v.id === this.selectedVersion!.id);
169
+ if (currentVersion) {
170
+ this.loadVersion(currentVersion);
171
+ } else if (this.versions.length > 0) {
172
+ this.loadVersion(this.versions[0]);
173
+ }
174
+ } else if (this.versions.length > 0) {
175
+ this.loadVersion(this.versions[0]);
176
+ }
177
+ }
178
+ } catch (error) {
179
+ this.snackBar.open('Failed to reload versions', 'Close', { duration: 3000 });
180
+ } finally {
181
+ this.loading = false;
182
+ }
183
+ }
184
 
185
  createIntentFormGroup(intent: any = {}): FormGroup {
186
  const group = this.fb.group({
 
418
  });
419
  }
420
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  async saveVersion() {
422
  if (!this.selectedVersion) {
423
  this.snackBar.open('No version selected', 'Close', { duration: 3000 });
 
455
  // updateData'yı backend'in beklediği formatta hazırla
456
  const updateData = {
457
  caption: formValue.caption,
458
+ general_prompt: formValue.general_prompt || '', // Bu alan eksikti
459
  llm: formValue.llm,
460
  intents: formValue.intents.map((intent: any) => ({
461
  name: intent.name,
 
504
  console.error('Save error:', error);
505
 
506
  if (error.status === 409) {
507
+ // Race condition handling için ayrı metod çağır
508
+ await this.handleRaceCondition(currentVersion);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
  } else {
510
  const errorMessage = error.error?.detail || error.message || 'Failed to save version';
511
  this.snackBar.open(errorMessage, 'Close', {
 
518
  }
519
  }
520
 
521
+ // Race condition handling için ayrı metod
522
+ private async handleRaceCondition(currentVersion: Version) {
523
+ const formValue = this.versionForm.getRawValue();
524
+
525
+ const retryUpdateData = {
526
+ caption: formValue.caption,
527
+ general_prompt: formValue.general_prompt || '',
528
+ llm: formValue.llm,
529
+ intents: formValue.intents.map((intent: any) => ({
530
+ name: intent.name,
531
+ caption: intent.caption,
532
+ locale: intent.locale,
533
+ detection_prompt: intent.detection_prompt,
534
+ examples: Array.isArray(intent.examples) ? intent.examples.filter((ex: any) => ex) : [],
535
+ parameters: Array.isArray(intent.parameters) ? intent.parameters : [],
536
+ action: intent.action,
537
+ fallback_timeout_prompt: intent.fallback_timeout_prompt,
538
+ fallback_error_prompt: intent.fallback_error_prompt
539
+ })),
540
+ last_update_date: currentVersion.last_update_date || ''
541
+ };
542
+
543
+ const dialogRef = this.dialog.open(ConfirmDialogComponent, {
544
+ width: '500px',
545
+ data: {
546
+ title: 'Version Modified',
547
+ message: 'This version was modified by another user. Do you want to reload and lose your changes, or force save?',
548
+ confirmText: 'Force Save',
549
+ cancelText: 'Reload',
550
+ confirmColor: 'warn'
551
+ }
552
+ });
553
+
554
+ dialogRef.afterClosed().subscribe(async (forceSave) => {
555
+ if (forceSave) {
556
+ try {
557
+ await this.apiService.updateVersion(
558
+ this.project.id,
559
+ currentVersion.id,
560
+ retryUpdateData,
561
+ true
562
+ ).toPromise();
563
+ this.snackBar.open('Version force saved', 'Close', { duration: 3000 });
564
+ await this.loadVersions();
565
+ } catch (err: any) {
566
+ this.snackBar.open(err.error?.detail || 'Force save failed', 'Close', {
567
+ duration: 5000,
568
+ panelClass: 'error-snackbar'
569
+ });
570
+ }
571
+ } else {
572
+ await this.loadVersions();
573
+ }
574
+ });
575
+ }
576
+
577
  async publishVersion() {
578
  if (!this.selectedVersion) return;
579