feat: webchat stream is ok

This commit is contained in:
Dong_master
2025-08-01 11:33:16 +08:00
committed by Junyan Qin
parent b45cc59322
commit c6deed4e6e
4 changed files with 14 additions and 13 deletions

View File

@@ -201,15 +201,17 @@ export default function DebugDialog({
(data) => {
// 处理流式响应数据
if (data.message) {
accumulatedContent += data.message;
accumulatedContent += data.message.content;
// 更新bot消息
setMessages((prevMessages) => {
const updatedMessages = [...prevMessages];
const botMessageIndex = updatedMessages.findIndex(
(msg) =>
msg.id === botMessageId && msg.role === 'assistant',
);
// const botMessageIndex = updatedMessages.findIndex(
// (msg) =>
// msg.id === botMessageId && msg.role === 'assistant',
// );
// 使用索引来更新消息而不是id匹配
const botMessageIndex = updatedMessages.length - 1;
if (botMessageIndex !== -1) {
const updatedBotMessage = {

View File

@@ -359,14 +359,12 @@ class HttpClient {
messageChain: object[],
pipelineId: string,
timeout: number = 15000,
is_stream: boolean = false,
): Promise<ApiRespWebChatMessage> {
return this.post(
`/api/v1/pipelines/${pipelineId}/chat/send`,
{
session_type: sessionType,
message: messageChain,
is_stream: is_stream,
},
{
timeout,
@@ -432,10 +430,10 @@ class HttpClient {
// 处理完整的JSON对象
const lines = buffer.split('\n\n');
buffer = lines.pop() || '';
buffer = '';
for (const line of lines) {
if (line.startsWith('data: ')) {
if (line.startsWith('data:')) {
try {
const data = JSON.parse(line.slice(6));