mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 07:16:04 +00:00
feat: webchat stream is ok
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user