2024-11-20 16:00:34 +08:00
|
|
|
import { describeUserPage } from '@/ai-model/prompt/util';
|
2025-02-21 09:56:09 +08:00
|
|
|
import { getAIConfigInBoolean } from '@/env';
|
2025-02-10 16:36:12 +08:00
|
|
|
import { getContextFromFixture } from '@/evaluation';
|
2024-11-20 16:00:34 +08:00
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
|
|
|
|
describe('prompt utils', () => {
|
2024-12-08 20:12:17 +08:00
|
|
|
let lengthOfDescription: number;
|
2024-11-20 16:00:34 +08:00
|
|
|
it('describe context', async () => {
|
2025-02-10 16:36:12 +08:00
|
|
|
const context = await getContextFromFixture('taobao');
|
2024-11-20 16:00:34 +08:00
|
|
|
const { description } = await describeUserPage(context.context);
|
2024-12-08 20:12:17 +08:00
|
|
|
|
|
|
|
lengthOfDescription = description.length;
|
|
|
|
const stringLengthOfEachItem =
|
|
|
|
lengthOfDescription / context.context.content.length;
|
|
|
|
expect(description).toBeTruthy();
|
2025-02-07 14:55:52 +08:00
|
|
|
expect(stringLengthOfEachItem).toBeLessThan(250);
|
2024-12-08 20:12:17 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('describe context, length = 100, filterNonTextContent = true', async () => {
|
2025-02-10 16:36:12 +08:00
|
|
|
const context = await getContextFromFixture('taobao');
|
2024-12-08 20:12:17 +08:00
|
|
|
|
|
|
|
const { description } = await describeUserPage(context.context, {
|
|
|
|
truncateTextLength: 100,
|
|
|
|
filterNonTextContent: true,
|
|
|
|
});
|
2024-11-20 16:00:34 +08:00
|
|
|
|
|
|
|
const stringLengthOfEachItem =
|
|
|
|
description.length / context.context.content.length;
|
|
|
|
expect(description).toBeTruthy();
|
|
|
|
expect(stringLengthOfEachItem).toBeLessThan(160);
|
2024-12-08 20:12:17 +08:00
|
|
|
|
2025-02-21 09:56:09 +08:00
|
|
|
if (!getAIConfigInBoolean('MATCH_BY_POSITION')) {
|
2025-01-02 21:23:30 +08:00
|
|
|
expect(description.length).toBeLessThan(lengthOfDescription * 0.8);
|
|
|
|
}
|
2024-11-20 16:00:34 +08:00
|
|
|
});
|
|
|
|
});
|