summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views
diff options
context:
space:
mode:
Diffstat (limited to 'usecaseui-portal/src/app/views')
-rw-r--r--usecaseui-portal/src/app/views/robot/robot.component.ts26
1 files changed, 15 insertions, 11 deletions
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 = '';
}
}