|
|
|
@ -74,6 +74,9 @@ export class AIModelDialogComponent extends DialogComponent<AIModelDialogCompone |
|
|
|
|
|
|
|
authenticationHint: string; |
|
|
|
|
|
|
|
apiKeyRequired = true; |
|
|
|
private readonly openAiDefaultBaseUrl = 'https://api.openai.com/v1'; |
|
|
|
|
|
|
|
constructor(protected store: Store<AppState>, |
|
|
|
protected router: Router, |
|
|
|
protected dialogRef: MatDialogRef<AIModelDialogComponent, AiModel>, |
|
|
|
@ -107,7 +110,7 @@ export class AIModelDialogComponent extends DialogComponent<AIModelDialogCompone |
|
|
|
region: [this.data.AIModel ? this.data.AIModel.configuration.providerConfig?.region : '', [Validators.required, Validators.pattern(/.*\S.*/)]], |
|
|
|
accessKeyId: [this.data.AIModel ? this.data.AIModel.configuration.providerConfig?.accessKeyId : '', [Validators.required, Validators.pattern(/.*\S.*/)]], |
|
|
|
secretAccessKey: [this.data.AIModel ? this.data.AIModel.configuration.providerConfig?.secretAccessKey : '', [Validators.required, Validators.pattern(/.*\S.*/)]], |
|
|
|
baseUrl: [this.data.AIModel ? this.data.AIModel.configuration.providerConfig?.baseUrl : '', [Validators.required, Validators.pattern(/.*\S.*/)]], |
|
|
|
baseUrl: [this.data.AIModel ? this.data.AIModel.configuration.providerConfig?.baseUrl : this.openAiDefaultBaseUrl, [Validators.required, Validators.pattern(/.*\S.*/)]], |
|
|
|
auth: this.fb.group({ |
|
|
|
type: [this.data.AIModel?.configuration?.providerConfig?.auth?.type ?? AuthenticationType.NONE], |
|
|
|
username: [this.data.AIModel?.configuration?.providerConfig?.auth?.username ?? '', [Validators.required, Validators.pattern(/.*\S.*/)]], |
|
|
|
@ -133,6 +136,18 @@ export class AIModelDialogComponent extends DialogComponent<AIModelDialogCompone |
|
|
|
this.aiModelForms.get('configuration.modelId').reset(''); |
|
|
|
this.aiModelForms.get('configuration.providerConfig').reset({}); |
|
|
|
this.updateValidation(provider); |
|
|
|
if (provider === AiProvider.OPENAI) { |
|
|
|
this.aiModelForms.get('configuration.providerConfig.baseUrl').patchValue(this.openAiDefaultBaseUrl, {emitEvent: false}); |
|
|
|
this.updateApiKeyValidatorForOpenAIProvider(this.openAiDefaultBaseUrl); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.aiModelForms.get('configuration.providerConfig.baseUrl').valueChanges.pipe( |
|
|
|
takeUntilDestroyed() |
|
|
|
).subscribe((url: string) => { |
|
|
|
if (this.provider === AiProvider.OPENAI) { |
|
|
|
this.updateApiKeyValidatorForOpenAIProvider(url); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.aiModelForms.get('configuration.providerConfig.auth.type').valueChanges.pipe( |
|
|
|
@ -161,6 +176,17 @@ 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}); |
|
|
|
} |
|
|
|
|
|
|
|
private getAuthenticationHint(type: AuthenticationType) { |
|
|
|
if (type === AuthenticationType.BASIC) { |
|
|
|
this.authenticationHint = this.translate.instant('ai-models.authentication-basic-hint'); |
|
|
|
|