summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaixiliu <liukaixi@chinamobile.com>2024-05-06 16:07:35 +0800
committerKaixi LIU <liukaixi@chinamobile.com>2024-05-06 08:42:53 +0000
commit02810f989a988ad918c439d37e779f6110815d05 (patch)
tree781ea58e4d3e91ee16023e46fe78630fe48b5458
parentfdefcecfc6d983f5e7e6d3a60a13dcfadc7a7721 (diff)
Add streaming processing
Issue-ID: USECASEUI-834 Change-Id: I25207cd6eea68a20424ee8da4590a8155fe08173 Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
-rw-r--r--usecaseui-portal/package.json9
-rw-r--r--usecaseui-portal/src/app/views/robot/robot.component.ts26
2 files changed, 20 insertions, 15 deletions
diff --git a/usecaseui-portal/package.json b/usecaseui-portal/package.json
index c7e2089d..5ed81ebc 100644
--- a/usecaseui-portal/package.json
+++ b/usecaseui-portal/package.json
@@ -29,7 +29,7 @@
"@ngx-translate/core": "^9.1.1",
"@ngx-translate/http-loader": "^2.0.1",
"@types/resize-observer-browser": "^0.1.6",
- "ng-multiselect-dropdown": "^0.2.14",
+ "angular2-datetimepicker": "^1.1.1",
"axios": "^0.19.0",
"core-js": "^2.4.1",
"d3": "^3.5.17",
@@ -39,13 +39,14 @@
"lodash": "^4.17.15",
"moment": "^2.24.0",
"mxgraph": "^4.2.2",
+ "ng-multiselect-dropdown": "^0.2.14",
"ng-zorro-antd": "^0.7.1",
"ngx-echarts": "^2.2.0",
"rxjs": "^5.5.12",
+ "sse.js": "^2.4.1",
+ "sweetalert2": "^4.3.3",
"vis": "^4.21.0",
- "zone.js": "^0.8.19",
- "angular2-datetimepicker": "^1.1.1",
- "sweetalert2": "^4.3.3"
+ "zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "~1.7.4",
diff --git a/usecaseui-portal/src/app/views/robot/robot.component.ts b/usecaseui-portal/src/app/views/robot/robot.component.ts
index 5304e876..d4438c4f 100644
--- a/usecaseui-portal/src/app/views/robot/robot.component.ts
+++ b/usecaseui-portal/src/app/views/robot/robot.component.ts
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { HttpClient } from '@angular/common/http';
+import { SSE } from "sse.js";
@Component({
selector: 'app-robot',
@@ -12,7 +13,7 @@ export class RobotComponent implements OnInit {
question: string;
communicationMessage: string;
chatHistory: { question: string, answer: string }[] = [];
- apiUrl = '/api/usecaseui-llm-adaptation/v1/getHelper';
+ apiUrl = '/api/usecaseui-llm-adaptation/v1/stream';
constructor(
private http: HttpClient,
@@ -21,15 +22,18 @@ export class RobotComponent implements OnInit {
ngOnInit() {}
submitQuestion() {
- this.http.post<any>(this.apiUrl,this.question,{ responseType: 'text' as 'json'}).subscribe((data) => {
- if(data==''){
- this.chatHistory.push({ question: this.question, answer: 'network error' });
- }else{
- this.chatHistory.push({ question: this.question, answer: data });
- }
- this.question = '';
- }, error => {
- this.message.error('error');
- });
+ var source = new SSE(this.apiUrl,{headers: {'Content-Type': 'text/plain'},payload: this.question,method:'POST'});
+ var lin = this.question;
+ const length = this.chatHistory.length;
+ source.addEventListener('message',(event)=>{
+ let newData = event.data.replace(/\\x0A/g,'\n');
+ const lengthNew = this.chatHistory.length;
+ if(length==lengthNew){
+ this.chatHistory.push({question:lin,answer:newData});
+ } else {
+ this.chatHistory[lengthNew-1].answer = newData;
+ }
+ });
+ this.question = '';
}
}