mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-14 15:11:13 +00:00
fix: 修复最后一个流为[xxxx]格式时会重复输出1次 (#5673)
* fix: 修复最后一个流为[xxxx]格式时会重复输出1次 issue #5292 当最后一个流中包含[xxxx]格式时,会输出2次。第一次在parseCite方法中if (isStreamEnd) {分支内输出,第二次在调用getResponseData时会输出buffer中的内容,导致重复。 * add test case --------- Co-authored-by: archer <545436317@qq.com>
This commit is contained in:
@@ -243,6 +243,7 @@ export const parseLLMStreamResponse = () => {
|
|||||||
// 结束时,返回所有剩余内容
|
// 结束时,返回所有剩余内容
|
||||||
if (isStreamEnd) {
|
if (isStreamEnd) {
|
||||||
const content = citeBuffer + text;
|
const content = citeBuffer + text;
|
||||||
|
citeBuffer = ''; // 清空缓冲区,避免重复输出
|
||||||
return {
|
return {
|
||||||
content: removeDatasetCiteText(content, false)
|
content: removeDatasetCiteText(content, false)
|
||||||
};
|
};
|
||||||
|
@@ -158,9 +158,7 @@ describe('Parse dataset cite content test', async () => {
|
|||||||
data: [
|
data: [
|
||||||
{ content: '知识库' },
|
{ content: '知识库' },
|
||||||
{ content: '问答系统' },
|
{ content: '问答系统' },
|
||||||
{ content: '[67e517e747' },
|
{ content: '[67e517e74767063e882d6861](CITE)' }
|
||||||
{ content: '67063e882d' },
|
|
||||||
{ content: '6861](CITE)' }
|
|
||||||
],
|
],
|
||||||
correct: {
|
correct: {
|
||||||
content: '知识库问答系统[67e517e74767063e882d6861](CITE)',
|
content: '知识库问答系统[67e517e74767063e882d6861](CITE)',
|
||||||
@@ -400,6 +398,19 @@ describe('Parse dataset cite content test', async () => {
|
|||||||
content: '知识库问答系统[id](CITE)[67e517e74767063e882d6861](CITE)',
|
content: '知识库问答系统[id](CITE)[67e517e74767063e882d6861](CITE)',
|
||||||
responseContent: '知识库问答系统'
|
responseContent: '知识库问答系统'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// [id](CITE)
|
||||||
|
data: [
|
||||||
|
{ content: '知识库' },
|
||||||
|
{ content: '问答系统' },
|
||||||
|
{ content: '[i' },
|
||||||
|
{ content: 'd](CITE)' }
|
||||||
|
],
|
||||||
|
correct: {
|
||||||
|
content: '知识库问答系统[id](CITE)',
|
||||||
|
responseContent: '知识库问答系统'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -409,7 +420,8 @@ describe('Parse dataset cite content test', async () => {
|
|||||||
|
|
||||||
let answer = '';
|
let answer = '';
|
||||||
let responseContent = '';
|
let responseContent = '';
|
||||||
part.data.forEach((item, index) => {
|
const list = [...part.data, { content: '' }];
|
||||||
|
list.forEach((item, index) => {
|
||||||
const formatPart = {
|
const formatPart = {
|
||||||
choices: [
|
choices: [
|
||||||
{
|
{
|
||||||
@@ -418,9 +430,7 @@ describe('Parse dataset cite content test', async () => {
|
|||||||
content: item.content,
|
content: item.content,
|
||||||
reasoning_content: ''
|
reasoning_content: ''
|
||||||
},
|
},
|
||||||
finish_reason: (index === part.data.length - 1
|
finish_reason: (index === list.length - 2 ? 'stop' : null) as CompletionFinishReason
|
||||||
? 'stop'
|
|
||||||
: null) as CompletionFinishReason
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user