Spaces:
Building
Building
Update flare-ui/src/app/components/environment/environment.component.ts
Browse files
flare-ui/src/app/components/environment/environment.component.ts
CHANGED
@@ -22,6 +22,7 @@ import { EnvironmentService } from '../../services/environment.service';
|
|
22 |
imports: [
|
23 |
CommonModule,
|
24 |
FormsModule,
|
|
|
25 |
MatCardModule,
|
26 |
MatFormFieldModule,
|
27 |
MatInputModule,
|
@@ -564,24 +565,16 @@ export class EnvironmentComponent implements OnInit {
|
|
564 |
private fb = inject(FormBuilder);
|
565 |
|
566 |
environmentForm!: FormGroup;
|
567 |
-
sttSettingsForm!: FormGroup;
|
568 |
-
|
569 |
-
sttSettingsExpanded = false;
|
570 |
loading = true;
|
571 |
saving = false;
|
|
|
572 |
|
573 |
ngOnInit() {
|
574 |
-
this.
|
575 |
this.loadEnvironment();
|
576 |
}
|
577 |
|
578 |
-
|
579 |
-
console.log('EnvironmentComponent ngAfterViewInit');
|
580 |
-
console.log('Current environment:', this.environment);
|
581 |
-
console.log('STT settings:', this.environment.stt_settings);
|
582 |
-
}
|
583 |
-
|
584 |
-
initializeForms() {
|
585 |
this.environmentForm = this.fb.group({
|
586 |
work_mode: ['hfcloud'],
|
587 |
cloud_token: [''],
|
@@ -590,44 +583,29 @@ export class EnvironmentComponent implements OnInit {
|
|
590 |
tts_engine: ['no_tts'],
|
591 |
tts_engine_api_key: [''],
|
592 |
stt_engine: ['no_stt'],
|
593 |
-
stt_engine_api_key: ['']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
});
|
595 |
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
vad_sensitivity: [0.5],
|
600 |
-
language: ['tr-TR'],
|
601 |
-
model: ['latest_long'],
|
602 |
-
use_enhanced: [true],
|
603 |
-
enable_punctuation: [true],
|
604 |
-
interim_results: [true]
|
605 |
});
|
606 |
}
|
607 |
-
|
608 |
-
get sttSettings(): STTSettings {
|
609 |
-
if (!this.environment.stt_settings) {
|
610 |
-
this.environment.stt_settings = {
|
611 |
-
speech_timeout_ms: 2000,
|
612 |
-
noise_reduction_level: 2,
|
613 |
-
vad_sensitivity: 0.5,
|
614 |
-
language: 'tr-TR',
|
615 |
-
model: 'latest_long',
|
616 |
-
use_enhanced: true,
|
617 |
-
enable_punctuation: true,
|
618 |
-
interim_results: true
|
619 |
-
};
|
620 |
-
}
|
621 |
-
return this.environment.stt_settings;
|
622 |
-
}
|
623 |
-
|
624 |
loadEnvironment() {
|
625 |
this.loading = true;
|
626 |
this.apiService.getEnvironment().subscribe({
|
627 |
next: (env) => {
|
628 |
-
this.environment = env;
|
629 |
-
|
630 |
-
// Form'ları güncelle
|
631 |
this.environmentForm.patchValue({
|
632 |
work_mode: env.work_mode,
|
633 |
cloud_token: env.cloud_token,
|
@@ -640,7 +618,7 @@ export class EnvironmentComponent implements OnInit {
|
|
640 |
});
|
641 |
|
642 |
if (env.stt_settings) {
|
643 |
-
this.
|
644 |
}
|
645 |
|
646 |
this.loading = false;
|
@@ -655,15 +633,66 @@ export class EnvironmentComponent implements OnInit {
|
|
655 |
});
|
656 |
}
|
657 |
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
}
|
|
|
|
|
663 |
}
|
664 |
|
665 |
-
|
666 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
}
|
668 |
|
669 |
onSTTCredentialsFileSelected(event: any) {
|
@@ -672,15 +701,12 @@ export class EnvironmentComponent implements OnInit {
|
|
672 |
const reader = new FileReader();
|
673 |
reader.onload = (e: any) => {
|
674 |
try {
|
675 |
-
// Validate
|
676 |
-
|
677 |
-
// Store the entire JSON content as the API key
|
678 |
-
this.environment.stt_engine_api_key = e.target.result;
|
679 |
this.snackBar.open('Google credentials loaded successfully', 'Close', {
|
680 |
duration: 3000
|
681 |
});
|
682 |
} catch (error) {
|
683 |
-
console.error('JSON parse error:', error);
|
684 |
this.snackBar.open('Invalid JSON file', 'Close', {
|
685 |
duration: 3000,
|
686 |
panelClass: 'error-snackbar'
|
@@ -690,6 +716,17 @@ export class EnvironmentComponent implements OnInit {
|
|
690 |
reader.readAsText(file);
|
691 |
}
|
692 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
693 |
|
694 |
updateSTTSetting(key: string, value: any) {
|
695 |
if (!this.environment.stt_settings) {
|
@@ -793,30 +830,6 @@ export class EnvironmentComponent implements OnInit {
|
|
793 |
}
|
794 |
}
|
795 |
|
796 |
-
save() {
|
797 |
-
this.saving = true;
|
798 |
-
|
799 |
-
this.apiService.updateEnvironment(this.environment).subscribe({
|
800 |
-
next: () => {
|
801 |
-
// Environment service'i güncelle
|
802 |
-
this.environmentService.updateEnvironment(this.environment);
|
803 |
-
|
804 |
-
this.snackBar.open('Environment configuration saved successfully', 'Close', {
|
805 |
-
duration: 3000
|
806 |
-
});
|
807 |
-
this.saving = false;
|
808 |
-
},
|
809 |
-
error: (err) => {
|
810 |
-
this.snackBar.open(
|
811 |
-
err.error?.detail || 'Failed to save configuration',
|
812 |
-
'Close',
|
813 |
-
{ duration: 5000, panelClass: 'error-snackbar' }
|
814 |
-
);
|
815 |
-
this.saving = false;
|
816 |
-
}
|
817 |
-
});
|
818 |
-
}
|
819 |
-
|
820 |
testConnection() {
|
821 |
this.snackBar.open('Testing connection to Spark endpoint...', undefined, {
|
822 |
duration: 2000
|
|
|
22 |
imports: [
|
23 |
CommonModule,
|
24 |
FormsModule,
|
25 |
+
ReactiveFormsModule, // Bunu ekle
|
26 |
MatCardModule,
|
27 |
MatFormFieldModule,
|
28 |
MatInputModule,
|
|
|
565 |
private fb = inject(FormBuilder);
|
566 |
|
567 |
environmentForm!: FormGroup;
|
|
|
|
|
|
|
568 |
loading = true;
|
569 |
saving = false;
|
570 |
+
sttSettingsExpanded = false;
|
571 |
|
572 |
ngOnInit() {
|
573 |
+
this.initializeForm();
|
574 |
this.loadEnvironment();
|
575 |
}
|
576 |
|
577 |
+
initializeForm() {
|
|
|
|
|
|
|
|
|
|
|
|
|
578 |
this.environmentForm = this.fb.group({
|
579 |
work_mode: ['hfcloud'],
|
580 |
cloud_token: [''],
|
|
|
583 |
tts_engine: ['no_tts'],
|
584 |
tts_engine_api_key: [''],
|
585 |
stt_engine: ['no_stt'],
|
586 |
+
stt_engine_api_key: [''],
|
587 |
+
stt_settings: this.fb.group({
|
588 |
+
speech_timeout_ms: [2000],
|
589 |
+
noise_reduction_level: [2],
|
590 |
+
vad_sensitivity: [0.5],
|
591 |
+
language: ['tr-TR'],
|
592 |
+
model: ['latest_long'],
|
593 |
+
use_enhanced: [true],
|
594 |
+
enable_punctuation: [true],
|
595 |
+
interim_results: [true]
|
596 |
+
})
|
597 |
});
|
598 |
|
599 |
+
// STT engine değişikliklerini dinle
|
600 |
+
this.environmentForm.get('stt_engine')?.valueChanges.subscribe(value => {
|
601 |
+
this.onSTTEngineChange(value);
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
});
|
603 |
}
|
604 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
605 |
loadEnvironment() {
|
606 |
this.loading = true;
|
607 |
this.apiService.getEnvironment().subscribe({
|
608 |
next: (env) => {
|
|
|
|
|
|
|
609 |
this.environmentForm.patchValue({
|
610 |
work_mode: env.work_mode,
|
611 |
cloud_token: env.cloud_token,
|
|
|
618 |
});
|
619 |
|
620 |
if (env.stt_settings) {
|
621 |
+
this.environmentForm.get('stt_settings')?.patchValue(env.stt_settings);
|
622 |
}
|
623 |
|
624 |
this.loading = false;
|
|
|
633 |
});
|
634 |
}
|
635 |
|
636 |
+
onSTTEngineChange(value: string) {
|
637 |
+
if (value === 'no_stt') {
|
638 |
+
this.environmentForm.patchValue({ stt_engine_api_key: '' });
|
639 |
+
this.sttSettingsExpanded = false;
|
640 |
+
} else {
|
641 |
+
this.sttSettingsExpanded = true;
|
642 |
+
}
|
643 |
}
|
644 |
|
645 |
+
save() {
|
646 |
+
if (this.environmentForm.invalid) {
|
647 |
+
return;
|
648 |
+
}
|
649 |
+
|
650 |
+
this.saving = true;
|
651 |
+
const formValue = this.environmentForm.value;
|
652 |
+
|
653 |
+
this.apiService.updateEnvironment(formValue).subscribe({
|
654 |
+
next: () => {
|
655 |
+
this.environmentService.updateEnvironment(formValue);
|
656 |
+
this.snackBar.open('Environment configuration saved successfully', 'Close', {
|
657 |
+
duration: 3000
|
658 |
+
});
|
659 |
+
this.saving = false;
|
660 |
+
},
|
661 |
+
error: (err) => {
|
662 |
+
this.snackBar.open(
|
663 |
+
err.error?.detail || 'Failed to save configuration',
|
664 |
+
'Close',
|
665 |
+
{ duration: 5000, panelClass: 'error-snackbar' }
|
666 |
+
);
|
667 |
+
this.saving = false;
|
668 |
+
}
|
669 |
+
});
|
670 |
+
}
|
671 |
+
|
672 |
+
// Diğer metodlar
|
673 |
+
isGPTMode(): boolean {
|
674 |
+
const workMode = this.environmentForm.get('work_mode')?.value;
|
675 |
+
return workMode === 'gpt4o' || workMode === 'gpt4o-mini';
|
676 |
+
}
|
677 |
+
|
678 |
+
formatVAD(value: number): string {
|
679 |
+
return value.toFixed(1);
|
680 |
+
}
|
681 |
+
|
682 |
+
getSTTKeyPlaceholder(): string {
|
683 |
+
const sttEngine = this.environmentForm.get('stt_engine')?.value;
|
684 |
+
switch(sttEngine) {
|
685 |
+
case 'google':
|
686 |
+
return 'Google service account JSON content';
|
687 |
+
case 'azure':
|
688 |
+
return 'Azure subscription key';
|
689 |
+
case 'amazon':
|
690 |
+
return 'AWS access key';
|
691 |
+
case 'gpt4o_realtime':
|
692 |
+
return 'OpenAI API key';
|
693 |
+
default:
|
694 |
+
return 'Enter API key';
|
695 |
+
}
|
696 |
}
|
697 |
|
698 |
onSTTCredentialsFileSelected(event: any) {
|
|
|
701 |
const reader = new FileReader();
|
702 |
reader.onload = (e: any) => {
|
703 |
try {
|
704 |
+
JSON.parse(e.target.result); // Validate JSON
|
705 |
+
this.environmentForm.patchValue({ stt_engine_api_key: e.target.result });
|
|
|
|
|
706 |
this.snackBar.open('Google credentials loaded successfully', 'Close', {
|
707 |
duration: 3000
|
708 |
});
|
709 |
} catch (error) {
|
|
|
710 |
this.snackBar.open('Invalid JSON file', 'Close', {
|
711 |
duration: 3000,
|
712 |
panelClass: 'error-snackbar'
|
|
|
716 |
reader.readAsText(file);
|
717 |
}
|
718 |
}
|
719 |
+
|
720 |
+
get environment(): Environment {
|
721 |
+
return {
|
722 |
+
...this.environmentForm.value,
|
723 |
+
stt_settings: this.sttSettingsForm.value
|
724 |
+
};
|
725 |
+
}
|
726 |
+
|
727 |
+
set environment(value: Environment) {
|
728 |
+
// Form update için kullanılmıyor, sadece compat için
|
729 |
+
}
|
730 |
|
731 |
updateSTTSetting(key: string, value: any) {
|
732 |
if (!this.environment.stt_settings) {
|
|
|
830 |
}
|
831 |
}
|
832 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
testConnection() {
|
834 |
this.snackBar.open('Testing connection to Spark endpoint...', undefined, {
|
835 |
duration: 2000
|