mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-27 13:52:49 +00:00
* fix: push again, user select option button and form input radio content overflow (#5601) * fix: push again, user select option button and form input radio content overflow * fix: use useCallback instead of useMemo, fix unnecessary delete * fix: Move the variable inside the component * fix: do not pass valueLabel to MySelect * ui * del collection api adapt * refactor: inherit permission (#5529) * refactor: permission update conflict check function * refactor(permission): app collaborator update api * refactor(permission): support app update collaborator * feat: support fe permission conflict check * refactor(permission): app permission * refactor(permission): dataset permission * refactor(permission): team permission * chore: fe adjust * fix: type error * fix: audit pagiation * fix: tc * chore: initv4130 * fix: app/dataset auth logic * chore: move code * refactor(permission): remove selfPermission * fix: mock * fix: test * fix: app & dataset auth * fix: inherit * test(inheritPermission): test syncChildrenPermission * prompt editor add list plugin (#5620) * perf: search result (#5608) * fix: table size (#5598) * temp: list value * backspace * optimize code --------- Co-authored-by: Archer <545436317@qq.com> Co-authored-by: 伍闲犬 <whoeverimf5@gmail.com> * fix: fe & member list (#5619) * chore: initv4130 * fix: MemberItemCard * fix: MemberItemCard * chore: fe adjust & init script * perf: test code * doc * fix debug variables (#5617) * perf: search result (#5608) * fix: table size (#5598) * fix debug variables * fix --------- Co-authored-by: Archer <545436317@qq.com> Co-authored-by: 伍闲犬 <whoeverimf5@gmail.com> * perf: member ui * fix: inherit bug (#5624) * refactor(permission): remove getClbsWithInfo, which is useless * fix: app list privateApp * fix: get infos * perf(fe): remove delete icon when it is disable in MemberItemCard * fix: dataset private dataset * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Archer <545436317@qq.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * perf: auto coupon * chore: upgrade script & get infos avatar (#5625) * fix: get infos * chore: initv4130 * feat: support WecomRobot publish, and fix AesKey can not save bug (#5526) * feat: resolve conflicts * fix: add param 'show_publish_wecom' * feat: abstract out WecomCrypto type * doc: wecom robot document * fix: solve instability in AI output * doc: update some pictures * feat: remove functions from request.ts to chat.ts and toolCall.ts * doc: wecom robot doc update * fix * delete unused code * doc: update version and prompt * feat: remove wecom crypto, delete wecom code in workflow * feat: delete unused codes --------- Co-authored-by: heheer <zhiyu44@qq.com> * remove test * rename init shell * feat: collection page store * reload sandbox * pysandbox * remove log * chore: remove useless code (#5629) * chore: remove useless code * fix: checkConflict * perf: support hidden type for RoleList * fix: copy node * update doc * fix(permission): some bug (#5632) * fix: app/dataset list * fix: inherit bug * perf: del app;i18n;save chat * fix: test * i18n * fix: sumper overflow return OwnerRoleVal (#5633) * remove invalid code * fix: scroll * fix: objectId * update next * update package * object id * mock redis * feat: add redis append to resolve wecom stream response (#5643) * feat: resolve conflicts * fix: add param 'show_publish_wecom' * feat: abstract out WecomCrypto type * doc: wecom robot document * fix: solve instability in AI output * doc: update some pictures * feat: remove functions from request.ts to chat.ts and toolCall.ts * doc: wecom robot doc update * fix * delete unused code * doc: update version and prompt * feat: remove wecom crypto, delete wecom code in workflow * feat: delete unused codes * feat: add redis append method --------- Co-authored-by: heheer <zhiyu44@qq.com> * cache per * fix(test): init team sub when creating mocked user (#5646) * fix: button is not vertically centered (#5647) * doc * fix: gridFs objectId (#5649) --------- Co-authored-by: Zeng Qingwen <143274079+fishwww-ww@users.noreply.github.com> Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com> Co-authored-by: heheer <heheer@sealos.io> Co-authored-by: 伍闲犬 <whoeverimf5@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: heheer <zhiyu44@qq.com>
441 lines
13 KiB
TypeScript
441 lines
13 KiB
TypeScript
import type { CompletionFinishReason } from '@fastgpt/global/core/ai/type';
|
|
import { parseLLMStreamResponse } from '@fastgpt/service/core/ai/utils';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
describe('Parse reasoning stream content test', async () => {
|
|
const partList = [
|
|
{
|
|
data: [{ content: '你好1' }, { content: '你好2' }, { content: '你好3' }],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '' }
|
|
},
|
|
{
|
|
data: [
|
|
{ reasoning_content: '这是' },
|
|
{ reasoning_content: '思考' },
|
|
{ reasoning_content: '过程' },
|
|
{ content: '你好1' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '这是思考过程' }
|
|
},
|
|
{
|
|
data: [
|
|
{ content: '<t' },
|
|
{ content: 'hink>' },
|
|
{ content: '这是' },
|
|
{ content: '思考' },
|
|
{ content: '过程' },
|
|
{ content: '</think>' },
|
|
{ content: '你好1' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '这是思考过程' }
|
|
},
|
|
{
|
|
data: [
|
|
{ content: '<think>' },
|
|
{ content: '这是' },
|
|
{ content: '思考' },
|
|
{ content: '过程' },
|
|
{ content: '</think>' },
|
|
{ content: '你好1' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '这是思考过程' }
|
|
},
|
|
{
|
|
data: [
|
|
{ content: '<think>这是' },
|
|
{ content: '思考' },
|
|
{ content: '过程' },
|
|
{ content: '</think>' },
|
|
{ content: '你好1' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '这是思考过程' }
|
|
},
|
|
{
|
|
data: [
|
|
{ content: '<think>这是' },
|
|
{ content: '思考' },
|
|
{ content: '过程</' },
|
|
{ content: 'think>' },
|
|
{ content: '你好1' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '这是思考过程' }
|
|
},
|
|
{
|
|
data: [
|
|
{ content: '<think>这是' },
|
|
{ content: '思考' },
|
|
{ content: '过程</think>' },
|
|
{ content: '你好1' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '这是思考过程' }
|
|
},
|
|
{
|
|
data: [
|
|
{ content: '<think>这是' },
|
|
{ content: '思考' },
|
|
{ content: '过程</think>你好1' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '这是思考过程' }
|
|
},
|
|
{
|
|
data: [
|
|
{ content: '<think>这是' },
|
|
{ content: '思考' },
|
|
{ content: '过程</th' },
|
|
{ content: '假的' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' },
|
|
{ content: '过程</think>你好1' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '你好1你好2你好3', reasoning: '这是思考过程</th假的你好2你好3过程' }
|
|
},
|
|
{
|
|
data: [
|
|
{ content: '<think>这是' },
|
|
{ content: '思考' },
|
|
{ content: '过程</th' },
|
|
{ content: '假的' },
|
|
{ content: '你好2' },
|
|
{ content: '你好3' }
|
|
],
|
|
correct: { answer: '', reasoning: '这是思考过程</th假的你好2你好3' }
|
|
}
|
|
];
|
|
|
|
// Remove think
|
|
partList.forEach((part, index) => {
|
|
it(`Reasoning test:${index}`, () => {
|
|
const { parsePart } = parseLLMStreamResponse();
|
|
|
|
let answer = '';
|
|
let reasoning = '';
|
|
part.data.forEach((item) => {
|
|
const formatPart = {
|
|
choices: [
|
|
{
|
|
delta: {
|
|
role: 'assistant',
|
|
content: item.content,
|
|
reasoning_content: item.reasoning_content
|
|
}
|
|
}
|
|
]
|
|
};
|
|
const { reasoningContent, content } = parsePart({
|
|
part: formatPart,
|
|
parseThinkTag: true,
|
|
retainDatasetCite: false
|
|
});
|
|
answer += content;
|
|
reasoning += reasoningContent;
|
|
});
|
|
expect(answer).toBe(part.correct.answer);
|
|
expect(reasoning).toBe(part.correct.reasoning);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Parse dataset cite content test', async () => {
|
|
const partList = [
|
|
{
|
|
// 完整的
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CITE)' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861](CITE)',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// 只要 objectId
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861]' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861]',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// 满足替换条件的
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861](',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// 满足替换条件的
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](C' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861](C',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// 满足替换条件的
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CI' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861](CI',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// 满足替换条件的
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CIT' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861](CIT',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// 满足替换条件的
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CITE' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861](CITE',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// 缺失结尾
|
|
data: [
|
|
{ content: '知识库问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CITE' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861](CITE',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// ObjectId 不正确
|
|
data: [
|
|
{ content: '知识库问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67882d' },
|
|
{ content: '6861](CITE)' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767882d6861](CITE)',
|
|
responseContent: '知识库问答系统[67e517e74767882d6861](CITE)'
|
|
}
|
|
},
|
|
{
|
|
// 其他链接
|
|
data: [{ content: '知识库' }, { content: '问答系统' }, { content: '[](https://fastgpt.cn)' }],
|
|
correct: {
|
|
content: '知识库问答系统[](https://fastgpt.cn)',
|
|
responseContent: '知识库问答系统[](https://fastgpt.cn)'
|
|
}
|
|
},
|
|
{
|
|
// 不完整的其他链接
|
|
data: [{ content: '知识库' }, { content: '问答系统' }, { content: '[](https://fastgp' }],
|
|
correct: {
|
|
content: '知识库问答系统[](https://fastgp',
|
|
responseContent: '知识库问答系统[](https://fastgp'
|
|
}
|
|
},
|
|
{
|
|
// 开头
|
|
data: [{ content: '[知识库' }, { content: '问答系统' }, { content: '[](https://fastgp' }],
|
|
correct: {
|
|
content: '[知识库问答系统[](https://fastgp',
|
|
responseContent: '[知识库问答系统[](https://fastgp'
|
|
}
|
|
},
|
|
{
|
|
// 结尾
|
|
data: [{ content: '知识库' }, { content: '问答系统' }, { content: '[' }],
|
|
correct: {
|
|
content: '知识库问答系统[',
|
|
responseContent: '知识库问答系统['
|
|
}
|
|
},
|
|
{
|
|
// 中间
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[' },
|
|
{ content: '问答系统]' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[问答系统]',
|
|
responseContent: '知识库问答系统[问答系统]'
|
|
}
|
|
},
|
|
{
|
|
// 双链接
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[](https://fastgpt.cn)' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CITE)' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[](https://fastgpt.cn)[67e517e74767063e882d6861](CITE)',
|
|
responseContent: '知识库问答系统[](https://fastgpt.cn)'
|
|
}
|
|
},
|
|
{
|
|
// 双链接缺失部分
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[](https://fastgpt.cn)' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CIT' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[](https://fastgpt.cn)[67e517e74767063e882d6861](CIT',
|
|
responseContent: '知识库问答系统[](https://fastgpt.cn)'
|
|
}
|
|
},
|
|
{
|
|
// 双Cite
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CITE)' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CITE)' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e74767063e882d6861](CITE)[67e517e74767063e882d6861](CITE)',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
},
|
|
{
|
|
// 双Cite-第一个假Cite
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '6861](CITE)' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CITE)' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[67e517e7476861](CITE)[67e517e74767063e882d6861](CITE)',
|
|
responseContent: '知识库问答系统[67e517e7476861](CITE)'
|
|
}
|
|
},
|
|
{
|
|
// [id](CITE)
|
|
data: [
|
|
{ content: '知识库' },
|
|
{ content: '问答系统' },
|
|
{ content: '[i' },
|
|
{ content: 'd](CITE)' },
|
|
{ content: '[67e517e747' },
|
|
{ content: '67063e882d' },
|
|
{ content: '6861](CITE)' }
|
|
],
|
|
correct: {
|
|
content: '知识库问答系统[id](CITE)[67e517e74767063e882d6861](CITE)',
|
|
responseContent: '知识库问答系统'
|
|
}
|
|
}
|
|
];
|
|
|
|
partList.forEach((part, index) => {
|
|
it(`Dataset cite test: ${index}`, () => {
|
|
const { parsePart } = parseLLMStreamResponse();
|
|
|
|
let answer = '';
|
|
let responseContent = '';
|
|
part.data.forEach((item, index) => {
|
|
const formatPart = {
|
|
choices: [
|
|
{
|
|
delta: {
|
|
role: 'assistant',
|
|
content: item.content,
|
|
reasoning_content: ''
|
|
},
|
|
finish_reason: (index === part.data.length - 1
|
|
? 'stop'
|
|
: null) as CompletionFinishReason
|
|
}
|
|
]
|
|
};
|
|
const { content, responseContent: newResponseContent } = parsePart({
|
|
part: formatPart,
|
|
parseThinkTag: false,
|
|
retainDatasetCite: false
|
|
});
|
|
answer += content;
|
|
responseContent += newResponseContent;
|
|
});
|
|
|
|
expect(answer).toEqual(part.correct.content);
|
|
expect(responseContent).toEqual(part.correct.responseContent);
|
|
});
|
|
});
|
|
});
|