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-04-17 10:53:19 +08:00
|
|
|
import { uiTarsPlanningPrompt } from '@/ai-model/prompt/ui-tars-planning';
|
|
|
|
import { afterEach, beforeEach, 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-04-17 10:53:19 +08:00
|
|
|
// Store original env values
|
|
|
|
const originalEnvValues = {
|
|
|
|
MIDSCENE_USE_QWEN_VL: process.env.MIDSCENE_USE_QWEN_VL,
|
|
|
|
MIDSCENE_USE_DOUBAO_VISION: process.env.MIDSCENE_USE_DOUBAO_VISION,
|
|
|
|
MIDSCENE_USE_VLM_UI_TARS: process.env.MIDSCENE_USE_VLM_UI_TARS,
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
// Set all configs to false before each test
|
|
|
|
Object.keys(originalEnvValues).forEach((key) => {
|
|
|
|
process.env[key] = 'false';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
// Restore original values after each test
|
|
|
|
Object.entries(originalEnvValues).forEach(([key, value]) => {
|
|
|
|
process.env[key] = value ?? 'false';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2025-02-21 09:56:09 +08:00
|
|
|
it('planning - 4o', async () => {
|
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 () => {
|
|
|
|
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', () => {
|
2025-04-17 10:53:19 +08:00
|
|
|
process.env.MIDSCENE_USE_QWEN_VL = 'true';
|
2025-04-08 17:56:15 +08:00
|
|
|
const prompt = systemPromptToLocateElement(true);
|
|
|
|
expect(prompt).toMatchSnapshot();
|
|
|
|
});
|
2025-04-17 10:53:19 +08:00
|
|
|
|
|
|
|
it('ui-tars planning', () => {
|
|
|
|
const prompt = uiTarsPlanningPrompt;
|
|
|
|
expect(prompt).toMatchSnapshot();
|
|
|
|
});
|
2025-01-02 21:23:30 +08:00
|
|
|
});
|