|
|
|
@ -110,26 +110,37 @@ export const callLocalChatAPI = async (prompt, onStreamData) => {
|
|
|
|
|
|
|
|
|
|
|
|
// 按行处理响应
|
|
|
|
// 按行处理响应
|
|
|
|
const lines = responseText.split(/\r?\n/)
|
|
|
|
const lines = responseText.split(/\r?\n/)
|
|
|
|
console.log('总行数:', lines.length)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
const line = lines[i]
|
|
|
|
const line = lines[i]
|
|
|
|
|
|
|
|
|
|
|
|
if (line.startsWith('event:')) {
|
|
|
|
if (line.startsWith('event:')) {
|
|
|
|
currentEvent = line.substring(6).trim()
|
|
|
|
currentEvent = line.substring(6).trim()
|
|
|
|
console.log(`第${i}行 - 事件类型:`, currentEvent)
|
|
|
|
|
|
|
|
} else if (line.startsWith('data:')) {
|
|
|
|
} else if (line.startsWith('data:')) {
|
|
|
|
const data = line.substring(5)
|
|
|
|
const data = line.substring(5)
|
|
|
|
console.log(`第${i}行 - 数据类型:${currentEvent}, 数据长度:${data.length}, 数据内容:${data.substring(0, 50)}...`)
|
|
|
|
// console.log(`第${i}行 - 数据类型:${currentEvent}, 数据长度:${data.length}, 数据内容:${data.substring(0, 50)}...`)
|
|
|
|
|
|
|
|
|
|
|
|
if (currentEvent === 'thought') {
|
|
|
|
if (currentEvent === 'thought') {
|
|
|
|
thoughtContent += data
|
|
|
|
thoughtContent += data
|
|
|
|
} else if (currentEvent === 'message') {
|
|
|
|
} else if (currentEvent === 'message') {
|
|
|
|
// 累加所有 message 数据,而不是只处理第一个
|
|
|
|
// 累加所有 message 数据,而不是只处理第一个
|
|
|
|
messageContent += data
|
|
|
|
messageContent += data
|
|
|
|
console.log(`messageContent 当前长度: ${messageContent.length}`)
|
|
|
|
// console.log(`messageContent 当前长度: ${messageContent.length}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (line.trim() && currentEvent === 'message') {
|
|
|
|
|
|
|
|
// 【新增】处理没有前缀但属于 message 的内容(后端格式问题)
|
|
|
|
|
|
|
|
// console.log(`第${i}行 - 无前缀但属于message, 内容长度:${line.length}, 内容:${line.substring(0, 50)}...`)
|
|
|
|
|
|
|
|
messageContent += line + '\n' // 添加换行符保持格式
|
|
|
|
|
|
|
|
// console.log(`messageContent 当前长度: ${messageContent.length}`)
|
|
|
|
|
|
|
|
} else if (line.trim() && currentEvent === 'thought') {
|
|
|
|
|
|
|
|
// 【新增】处理没有前缀但属于 thought 的内容(后端格式问题)
|
|
|
|
|
|
|
|
// console.log(`第${i}行 - 无前缀但属于thought, 内容长度:${line.length}, 内容:${line.substring(0, 50)}...`)
|
|
|
|
|
|
|
|
thoughtContent += line + '\n' // 添加换行符保持格式
|
|
|
|
|
|
|
|
// console.log(`thoughtContent 当前长度: ${thoughtContent.length}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 调试:打印解析结果
|
|
|
|
// 调试:打印解析结果
|
|
|
|
|