2024-11-20 16:00:34 +08:00
|
|
|
import { describeUserPage } from '@/ai-model/prompt/util';
|
2025-03-17 19:19:54 +08:00
|
|
|
import { vlLocateMode } from '@/env';
|
2025-03-07 17:20:18 +08:00
|
|
|
import { getContextFromFixture } from 'tests/evaluation';
|
2025-04-17 17:44:11 +08:00
|
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
|
|
|
|
// Mock vlLocateMode to return false during tests
|
|
|
|
vi.mock('@/env', async () => {
|
|
|
|
const actual = await vi.importActual('@/env');
|
|
|
|
return {
|
|
|
|
...actual,
|
|
|
|
vlLocateMode: () => false,
|
|
|
|
};
|
|
|
|
});
|
2024-11-20 16:00:34 +08:00
|
|
|
|
2025-04-17 10:53:19 +08:00
|
|
|
describe.skipIf(vlLocateMode())('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-03-17 19:19:54 +08:00
|
|
|
if (!vlLocateMode()) {
|
2025-01-02 21:23:30 +08:00
|
|
|
expect(description.length).toBeLessThan(lengthOfDescription * 0.8);
|
|
|
|
}
|
2024-11-20 16:00:34 +08:00
|
|
|
});
|
|
|
|
});
|