@@ -57,7 +57,8 @@ marked.setOptions({
-
+
LLM 服务
@@ -65,7 +66,8 @@ marked.setOptions({
-
+
语音转文本
@@ -295,50 +297,66 @@ export default {
const chunk = decoder.decode(value, { stream: true });
- // data: {"type": "plain", "data": "helloworld"}
- let chunk_json = JSON.parse(chunk.replace('data: ', ''));
+ // 可能有多行
- if (chunk_json.type === 'heartbeat') {
- continue; // 心跳包
- }
- if (chunk_json.type === 'error') {
- console.error('Error received:', chunk_json.data);
- continue;
- }
+ let lines = chunk.split('\n\n');
- if (chunk_json.type === 'image') {
- let img = chunk_json.data.replace('[IMAGE]', '');
- let bot_resp = {
- type: 'bot',
- message: `

`
+ console.log('SSE数据:', lines);
+
+ for (let i = 0; i < lines.length; i++) {
+ let line = lines[i].trim();
+
+ if (!line) {
+ continue;
}
- this.messages.push(bot_resp);
- } else if (chunk_json.type === 'record') {
- let audio = chunk_json.data.replace('[RECORD]', '');
- let bot_resp = {
- type: 'bot',
- message: `
`
+
+ console.log(line)
+
+ // data: {"type": "plain", "data": "helloworld"}
+ let chunk_json = JSON.parse(line.replace('data: ', ''));
+
+ if (chunk_json.type === 'heartbeat') {
+ continue; // 心跳包
}
- this.messages.push(bot_resp);
- } else if (chunk_json.type === 'plain') {
- if (!in_streaming) {
- message_obj = {
+ if (chunk_json.type === 'error') {
+ console.error('Error received:', chunk_json.data);
+ continue;
+ }
+
+ if (chunk_json.type === 'image') {
+ let img = chunk_json.data.replace('[IMAGE]', '');
+ let bot_resp = {
type: 'bot',
- message: ref(chunk_json.data),
+ message: `

`
}
- this.messages.push(message_obj);
- in_streaming = true;
- } else {
- message_obj.message.value += chunk_json.data;
+ this.messages.push(bot_resp);
+ } else if (chunk_json.type === 'record') {
+ let audio = chunk_json.data.replace('[RECORD]', '');
+ let bot_resp = {
+ type: 'bot',
+ message: `
`
+ }
+ this.messages.push(bot_resp);
+ } else if (chunk_json.type === 'plain') {
+ if (!in_streaming) {
+ message_obj = {
+ type: 'bot',
+ message: ref(chunk_json.data),
+ }
+ this.messages.push(message_obj);
+ in_streaming = true;
+ } else {
+ message_obj.message.value += chunk_json.data;
+ }
+ } else if (chunk_json.type === 'end') {
+ in_streaming = false;
+ continue;
}
- } else if (chunk_json.type === 'end') {
- in_streaming = false;
- continue;
+ this.scrollToBottom();
}
- this.scrollToBottom();
}
},