1 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 import { IntentManagementService } from '../../../../core/services/intentManagement.service';
3 import { Util } from '../../../../shared/utils/utils';
4 import { NzMessageService, UploadFile } from 'ng-zorro-antd';
5 import { HttpClient, HttpHeaders } from '@angular/common/http';
6 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
9 selector: 'app-input-knowledge-base',
10 templateUrl: './input-knowledge-base.component.html',
11 styleUrls: ['./input-knowledge-base.component.less']
13 export class InputKnowledgeBaseComponent implements OnInit {
14 title = 'Add Knowledge Base';
16 private myhttp: IntentManagementService,
18 private message: NzMessageService,
19 private http: HttpClient,
20 private fb: FormBuilder
23 @Input() showModel: boolean;
24 @Output() modalOpreation = new EventEmitter();
26 apiUrl = '/api/usecaseui-llm-adaptation/v1/knowledgeBase/create';
27 apiUrl1 = '/api/usecaseui-intent-analysis/v1/intents/upload';
28 maasUrl = '/api/usecaseui-llm-adaptation/v1/operator/maas/getAll'
29 url = "http://172.22.16.126:3000/api/core/dataset/create";
34 fileList: UploadFile[] = [];
35 operators: any[] = [];
36 selectedOperator: any = null;
37 filteredPlatforms: any[] = [];
38 allPlatforms: any[] = [];
39 selectedPlatform: any = null;
40 validateForm: FormGroup;
43 this.fetchOperators();
44 this.validateForm = this.fb.group({
47 selectedOperator: [null],
48 selectedPlatform: [null],
52 fetchOperators(): void {
53 this.http.get<any>(this.maasUrl).subscribe(
55 console.log(response);
56 this.operators = response.result_body;
59 this.message.error('Failed to fetch operators');
65 for (const i in this.validateForm.controls) {
66 this.validateForm.controls[i].markAsDirty();
67 this.validateForm.controls[i].updateValueAndValidity();
71 handleOperatorChange(value: any): void {
73 this.filteredPlatforms = value.maaSPlatformList;
75 this.filteredPlatforms = [];
77 this.validateForm.get('selectedPlatform').setValue(null);
81 beforeUpload = (file: UploadFile): boolean => {
82 this.fileList.push(file);
86 handleCancel(): void {
87 this.showModel = false;
88 this.modalOpreation.emit({ "cancel": true });
91 const formData = new FormData();
93 knowledgeBaseName: this.validateForm.controls.name.value,
94 knowledgeBaseDescription: this.validateForm.controls.description.value,
95 operatorId: this.validateForm.controls.selectedOperator.value.operatorId,
96 operatorName: this.validateForm.controls.selectedOperator.value.operatorName,
97 maaSPlatformId: this.validateForm.controls.selectedPlatform.value.maaSPlatformId,
98 maaSPlatformName: this.validateForm.controls.selectedPlatform.value.maaSPlatformName
100 const metaDataJson = JSON.stringify(metaData);
101 formData.append('metaData', metaDataJson);
102 this.fileList.forEach((file: any) => {
103 formData.append('files', file);
105 this.http.post<any>(this.apiUrl, formData).subscribe(
107 if (response.result_header.result_code === 200) {
108 this.message.success('Created successfully');
110 this.message.error(response.result_header.result_message);
112 this.knowledgeBase = {
117 this.modalOpreation.emit({ "cancel": false });
120 this.knowledgeBase = {
125 console.log('Upload failed', error);