diff options
author | kaixiliu <liukaixi@chinamobile.com> | 2024-11-29 17:32:22 +0800 |
---|---|---|
committer | kaixiliu <liukaixi@chinamobile.com> | 2024-11-29 17:32:27 +0800 |
commit | e5de10348e38a4cac9f70da856ab7c6941bfc347 (patch) | |
tree | 4aa7bc3808b54653f4a8f068a1903094b38d574b /usecaseui-portal/src/app/views/maas/use/use-application.component.ts | |
parent | 35d38716bfb367497f563bc4081109f6053c43af (diff) |
add maas knowledge base, Knowledge Assistant, application and update link
Issue-ID: USECASEUI-844
Change-Id: I1dc2b4bc12f364d017b24b2752acfef63e27ad94
Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
Diffstat (limited to 'usecaseui-portal/src/app/views/maas/use/use-application.component.ts')
-rw-r--r-- | usecaseui-portal/src/app/views/maas/use/use-application.component.ts | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/usecaseui-portal/src/app/views/maas/use/use-application.component.ts b/usecaseui-portal/src/app/views/maas/use/use-application.component.ts new file mode 100644 index 00000000..f2b147c5 --- /dev/null +++ b/usecaseui-portal/src/app/views/maas/use/use-application.component.ts @@ -0,0 +1,74 @@ +import { Component, OnInit } from '@angular/core'; +import { NzMessageService } from 'ng-zorro-antd'; +import { HttpClient } from '@angular/common/http'; +import { SSE } from "sse.js"; +import { ActivatedRoute } from '@angular/router'; +import { IntentManagementService } from '../../../core/services/intentManagement.service' + + +@Component({ + selector: 'app-use-application', + templateUrl: './use-application.component.html', + styleUrls: ['./use-application.component.less'] +}) +export class UseApplicationComponent implements OnInit { + + question: string; + communicationMessage: string; + chatHistory: { question: string, answer: string }[] = []; + apiUrl = '/api/usecaseui-llm-adaptation/v1/application/chat'; + queryParams: { id?: string; name?: string } = {}; + selectedName: string | null = null; + options: any[] = []; + + constructor( + private http: HttpClient, + private message: NzMessageService, + private route: ActivatedRoute, + private myhttp: IntentManagementService, + ) { } + ngOnInit() { + this.getIntentManagementData(); + this.route.queryParams.subscribe(params => { + this.queryParams = params; + console.log(params.id); + this.selectedName = this.queryParams.id ; + }); + } + + submitQuestion() { + const chatParam = { + applicationId: this.queryParams.id, + question: this.question + }; + var source = new SSE(this.apiUrl,{headers: {'Content-Type': 'application/json'},payload: JSON.stringify(chatParam),method:'POST'}); + var lin = this.question; + const length = this.chatHistory.length; + source.addEventListener('message',(event)=>{ + const existingEntryIndex = this.chatHistory.findIndex(entry => entry.question === lin); + console.log(event.data); + if (existingEntryIndex !== -1) { + this.chatHistory[existingEntryIndex].answer += event.data.replace(/__SPACE__/g, ' '); + } else { + this.chatHistory.push({ question: lin, answer: event.data }); + } + }); + this.question = ''; + } + + getIntentManagementData():void{ + this.myhttp.getAllApplication() + .subscribe( + (data) => { + this.options = data.result_body.map(item => ({ + nzValue: item.applicationId, + nzLabel: item.applicationName + })); + + }, + () => { + this.message.error('Failed to obtain intent data'); + } + ) + } +} |