71688d4ea1f91710d64e7d38860a680bd06198c8
[usecase-ui.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 import { Util } from '../../../../shared/utils/utils';
3 import {NzMessageService} from "ng-zorro-antd";
4 import { HttpClient,HttpHeaders } from '@angular/common/http';
5
6 @Component({
7   selector: 'app-input-application-management',
8   templateUrl: './input-application-management.component.html',
9   styleUrls: ['./input-application-management.component.less']
10 })
11 export class InputApplicationManagementComponent implements OnInit {
12   title = 'Add Application';
13   constructor(
14     private Util: Util,
15     private message: NzMessageService,
16     private http: HttpClient
17   ) { }
18
19   @Input() showModel: boolean;
20   @Output() modalOpreation = new EventEmitter();
21
22   maasUrl = '/api/usecaseui-llm-adaptation/v1/operator/maas/getAll';
23   knowBaseUrl = "/api/usecaseui-llm-adaptation/v1/knowledgeBase/queryByMaaSId/";
24   createApplicationUrl = "/api/usecaseui-llm-adaptation/v1/application/create";
25
26   applicationName = "";
27   applicationDescription = "";
28   applicationType = "Knowledge Assistant";
29     operators: any[] = [];
30     selectedOperator: any = null;
31     filteredPlatforms: any[] = [];
32     selectedPlatform: any = null;
33     filteredModels: any[] = [];
34     selectedModel: any = null;
35     knowledgeBases: any[] =[];
36     selectKnowledgeBase: any = null;
37   modelDefaultValue = "";
38   temperature = 3;
39   top_p = 3;
40   prompt ="";
41   openingRemarks = "";
42   ngOnInit() {
43      this.fetchOperators();
44   }
45
46   fetchOperators(): void {
47      this.http.get<any>(this.maasUrl).subscribe(
48       (response) => {
49         this.operators = response.result_body;
50       },
51       () => {
52         this.message.error('Failed to fetch operators');
53       }
54     );
55   }
56
57    handleOperatorChange(value: any): void {
58     if (value) {
59       this.filteredPlatforms = value.maaSPlatformList;
60     } else {
61       this.filteredPlatforms = [];
62     }
63     this.selectedPlatform = null;
64     this.selectedModel = null;
65     this.selectKnowledgeBase = null;
66   }
67
68    handleMaasChange(value: any): void {
69     if (value) {
70       this.filteredModels = value.modelList;
71       console.log(this.filteredModels);
72       this.fetchKnowledgeBase(value);
73     } else {
74       this.filteredModels = [];
75     }
76     this.selectedModel = null;
77     this.selectKnowledgeBase = null;
78   }
79
80   fetchKnowledgeBase(value): void {
81      this.http.get<any>(this.knowBaseUrl+value.maaSPlatformId).subscribe(
82       (response) => {
83         this.knowledgeBases = response.result_body;
84       },
85       (error) => {
86         this.message.error('Failed to fetch knowledge base');
87       }
88     );
89   }
90
91   handleCancel(): void {
92     this.showModel = false;
93     this.modalOpreation.emit({ "cancel": true });
94   }
95   handleOk(): void {
96     this.createApplication();
97   }
98
99   createApplication(){
100       const requestBody = {
101           applicationName: this.applicationName,
102           applicationDescription: this.applicationDescription,
103           applicationType: this.applicationType,
104           operatorName: this.selectedOperator.operatorName,
105           operatorId: this.selectedOperator.operatorId,
106           maaSPlatformId: this.selectedPlatform.maaSPlatformId,
107           maaSPlatformName: this.selectedPlatform.maaSPlatformName,
108           knowledgeBaseId: this.selectKnowledgeBase.knowledgeBaseId,
109           knowledgeBaseName: this.selectKnowledgeBase.knowledgeBaseName,
110           largeModelId: this.selectedModel.modelId,
111           largeModelName: this.selectedModel.modelName,
112           prompt: this.prompt,
113           temperature: this.temperature,
114           top_p: this.top_p,
115           openingRemarks: this.openingRemarks
116         };
117         console.log(requestBody);
118      this.http.post<any>(this.createApplicationUrl, requestBody).subscribe(
119       (response) => {
120         this.showModel = false;
121         this.modalOpreation.emit({ "cancel": false });
122         const resultHeader = {};
123         if(response.result_header.result_code===200){
124           this.message.success('Created successfully');
125         }else{
126           this.message.error(response.result_header.result_message);
127         }
128       },
129       (err) => {
130         this.showModel = false;
131         this.message.error('Created failed');
132       }
133     )
134   }
135 }