blob: d4438c4f03555855ebc78a4b9856c9512257f53d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
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',
templateUrl: './robot.component.html',
styleUrls: ['./robot.component.less']
})
export class RobotComponent implements OnInit {
question: string;
communicationMessage: string;
chatHistory: { question: string, answer: string }[] = [];
apiUrl = '/api/usecaseui-llm-adaptation/v1/stream';
constructor(
private http: HttpClient,
private message: NzMessageService
) { }
ngOnInit() {}
submitQuestion() {
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 = '';
}
}
|