2025-04-08 17:56:15 +08:00
|
|
|
import { systemPromptToLocateElement } from '@/ai-model';
|
2025-02-21 09:56:09 +08:00
|
|
|
import {
|
|
|
|
automationUserPrompt,
|
|
|
|
generateTaskBackgroundContext,
|
|
|
|
planSchema,
|
|
|
|
systemPromptToTaskPlanning,
|
|
|
|
} from '@/ai-model/prompt/llm-planning';
|
2025-04-02 19:26:56 +08:00
|
|
|
import { systemPromptToLocateSection } from '@/ai-model/prompt/llm-section-locator';
|
2025-02-07 14:55:52 +08:00
|
|
|
import { describe, expect, it } from 'vitest';
|
2025-01-02 21:23:30 +08:00
|
|
|
|
2025-04-02 19:26:56 +08:00
|
|
|
describe('system prompts', () => {
|
2025-02-21 09:56:09 +08:00
|
|
|
it('planning - 4o', async () => {
|
2025-04-02 19:26:56 +08:00
|
|
|
// TODO: restore config
|
2025-02-21 09:56:09 +08:00
|
|
|
process.env.MIDSCENE_USE_QWEN_VL = 'false';
|
2025-03-17 19:19:54 +08:00
|
|
|
process.env.MIDSCENE_USE_DOUBAO_VISION = 'false';
|
2025-01-02 21:23:30 +08:00
|
|
|
const prompt = await systemPromptToTaskPlanning();
|
2025-01-30 14:14:14 +08:00
|
|
|
expect(prompt).toMatchSnapshot();
|
2025-01-02 21:23:30 +08:00
|
|
|
});
|
2025-02-21 09:56:09 +08:00
|
|
|
|
|
|
|
it('planning - 4o - response format', () => {
|
|
|
|
const schema = planSchema;
|
|
|
|
expect(schema).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('planning - qwen', async () => {
|
|
|
|
process.env.MIDSCENE_USE_QWEN_VL = 'true';
|
|
|
|
const prompt = await systemPromptToTaskPlanning();
|
|
|
|
expect(prompt).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('planning - background context', () => {
|
|
|
|
const context = generateTaskBackgroundContext(
|
|
|
|
'THIS IS USER INSTRUCTION',
|
|
|
|
'THIS IS WHAT HAS BEEN DONE',
|
2025-04-02 20:34:23 +08:00
|
|
|
'THIS IS BACKGROUND PROMPT',
|
2025-02-21 09:56:09 +08:00
|
|
|
);
|
|
|
|
expect(context).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('planning - user prompt - 4o', async () => {
|
|
|
|
process.env.MIDSCENE_USE_QWEN_VL = 'false';
|
2025-03-17 19:19:54 +08:00
|
|
|
process.env.MIDSCENE_USE_DOUBAO_VISION = 'false';
|
2025-02-21 09:56:09 +08:00
|
|
|
const prompt = automationUserPrompt();
|
|
|
|
const result = await prompt.format({
|
|
|
|
pageDescription: 'THIS IS PAGE DESCRIPTION',
|
|
|
|
taskBackgroundContext: 'THIS IS BACKGROUND CONTEXT',
|
2025-04-02 20:34:23 +08:00
|
|
|
userActionContext: 'THIS IS BACKGROUND PROMPT',
|
2025-02-21 09:56:09 +08:00
|
|
|
});
|
|
|
|
expect(result).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('planning - user prompt - qwen', async () => {
|
|
|
|
process.env.MIDSCENE_USE_QWEN_VL = 'true';
|
|
|
|
const prompt = automationUserPrompt();
|
|
|
|
const result = await prompt.format({
|
|
|
|
pageDescription: 'THIS IS PAGE DESCRIPTION',
|
|
|
|
taskBackgroundContext: 'THIS IS BACKGROUND CONTEXT',
|
|
|
|
});
|
|
|
|
expect(result).toMatchSnapshot();
|
|
|
|
});
|
2025-04-02 19:26:56 +08:00
|
|
|
|
|
|
|
it('section locator', () => {
|
|
|
|
const prompt = systemPromptToLocateSection();
|
|
|
|
expect(prompt).toMatchSnapshot();
|
|
|
|
});
|
2025-04-08 17:56:15 +08:00
|
|
|
|
|
|
|
it('locator - 4o', () => {
|
|
|
|
const prompt = systemPromptToLocateElement(false);
|
|
|
|
expect(prompt).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('locator - qwen', () => {
|
|
|
|
const prompt = systemPromptToLocateElement(true);
|
|
|
|
expect(prompt).toMatchSnapshot();
|
|
|
|
});
|
2025-01-02 21:23:30 +08:00
|
|
|
});
|