Browse Source

UI: Add for apiKey required value

pull/14076/head^2
ArtemDzhereleiko 1 year ago
parent
commit
90d9b75790
  1. 2
      ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.html
  2. 3
      ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.ts

2
ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.html

@ -129,7 +129,7 @@
@if (providerFieldsList.includes('apiKey')) {
<mat-form-field class="mat-block flex-1" appearance="outline">
<mat-label translate>ai-models.api-key</mat-label>
<input type="password" matInput formControlName="apiKey" autocomplete="new-password">
<input type="password" matInput formControlName="apiKey" [required]="apiKeyRequired" autocomplete="new-password">
<tb-toggle-password matSuffix></tb-toggle-password>
<mat-error *ngIf="aiModelForms.get('configuration.providerConfig.apiKey').hasError('required') ||
aiModelForms.get('configuration.providerConfig.apiKey').hasError('pattern')">

3
ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.ts

@ -74,6 +74,7 @@ export class AIModelDialogComponent extends DialogComponent<AIModelDialogCompone
authenticationHint: string;
apiKeyRequired = true;
private readonly openAiDefaultBaseUrl = 'https://api.openai.com/v1';
constructor(protected store: Store<AppState>,
@ -178,8 +179,10 @@ export class AIModelDialogComponent extends DialogComponent<AIModelDialogCompone
private updateApiKeyValidatorForOpenAIProvider(url: string) {
if (url !== this.openAiDefaultBaseUrl) {
this.aiModelForms.get('configuration.providerConfig.apiKey').removeValidators(Validators.required);
this.apiKeyRequired = false;
} else {
this.aiModelForms.get('configuration.providerConfig.apiKey').addValidators(Validators.required);
this.apiKeyRequired = true;
}
this.aiModelForms.get('configuration.providerConfig.apiKey').updateValueAndValidity({emitEvent: false});
}

Loading…
Cancel
Save