Skip to content

Commit 7440a06

Browse files
committed
Merge branch 'main' into feat/extension-bridge-mode
2 parents aa26c5d + a1042c8 commit 7440a06

File tree

9 files changed

+88
-230
lines changed

9 files changed

+88
-230
lines changed

packages/midscene/src/ai-model/coze/index.ts

Lines changed: 0 additions & 107 deletions
This file was deleted.

packages/midscene/src/ai-model/inspect.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ export async function AiInspectElement<
124124
multi: boolean;
125125
targetElementDescription: string;
126126
callAI?: typeof callAiFn<AIElementResponse | [number, number]>;
127-
useModel?: 'coze' | 'openAI';
128127
quickAnswer?: AISingleElementResponse;
129128
}): Promise<{
130129
parseResult: AIElementResponse;
@@ -195,9 +194,8 @@ export async function AiExtractElementInfo<
195194
>(options: {
196195
dataQuery: string | Record<string, string>;
197196
context: UIContext<ElementType>;
198-
useModel?: 'coze' | 'openAI';
199197
}) {
200-
const { dataQuery, context, useModel } = options;
198+
const { dataQuery, context } = options;
201199
const systemPrompt = systemPromptToExtract();
202200

203201
const { screenshotBase64 } = context;
@@ -256,9 +254,8 @@ export async function AiAssert<
256254
>(options: {
257255
assertion: string;
258256
context: UIContext<ElementType>;
259-
useModel?: 'coze' | 'openAI';
260257
}) {
261-
const { assertion, context, useModel } = options;
258+
const { assertion, context } = options;
262259

263260
assert(assertion, 'assertion should be a string');
264261

packages/midscene/src/ai-model/openai/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { findElementSchema } from '../prompt/element_inspector';
4141
import { planSchema } from '../prompt/planning';
4242
import { assertSchema } from '../prompt/util';
4343

44-
export function checkAIConfig(preferVendor?: 'coze' | 'openAI') {
44+
export function checkAIConfig(preferVendor?: 'openAI') {
4545
if (preferVendor && preferVendor !== 'openAI') return false;
4646
if (getAIConfig(OPENAI_API_KEY)) return true;
4747
if (getAIConfig(MIDSCENE_USE_AZURE_OPENAI)) return true;
Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AiAssert } from '@/ai-model';
2-
import { preferCozeModel } from '@/ai-model/coze';
32
/* eslint-disable max-lines-per-function */
43
import { describe, expect, it, vi } from 'vitest';
54
import { getPageDataOfTestName } from '../evaluate/test-suite/util';
@@ -9,38 +8,28 @@ vi.setConfig({
98
hookTimeout: 30 * 1000,
109
});
1110

12-
const modelList: Array<'openAI' | 'coze'> = ['openAI'];
11+
describe('assert', () => {
12+
it('todo pass', async () => {
13+
const { context } = await getPageDataOfTestName('todo');
1314

14-
if (preferCozeModel('coze')) {
15-
modelList.push('coze');
16-
}
17-
18-
modelList.forEach((model) => {
19-
describe('assert', () => {
20-
it('todo pass', async () => {
21-
const { context } = await getPageDataOfTestName('todo');
22-
23-
const {
24-
content: { pass },
25-
} = await AiAssert({
26-
assertion: 'Three tasks have been added',
27-
context,
28-
useModel: model,
29-
});
30-
expect(pass).toBe(true);
15+
const {
16+
content: { pass },
17+
} = await AiAssert({
18+
assertion: 'Three tasks have been added',
19+
context,
3120
});
21+
expect(pass).toBe(true);
22+
});
3223

33-
it('todo error', async () => {
34-
const { context } = await getPageDataOfTestName('todo');
24+
it('todo error', async () => {
25+
const { context } = await getPageDataOfTestName('todo');
3526

36-
const {
37-
content: { pass, thought },
38-
} = await AiAssert({
39-
assertion: 'There are four tasks in the task list',
40-
context,
41-
useModel: model,
42-
});
43-
expect(pass).toBe(false);
27+
const {
28+
content: { pass, thought },
29+
} = await AiAssert({
30+
assertion: 'There are four tasks in the task list',
31+
context,
4432
});
33+
expect(pass).toBe(false);
4534
});
4635
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { plan } from '@/ai-model';
2+
/* eslint-disable max-lines-per-function */
3+
import { describe, expect, it, vi } from 'vitest';
4+
import { makePlanResultStable } from '../../util';
5+
import { getPageDataOfTestName, repeat } from './../test-suite/util';
6+
7+
vi.setConfig({
8+
testTimeout: 180 * 1000,
9+
hookTimeout: 30 * 1000,
10+
});
11+
12+
describe('automation - planning input', () => {
13+
repeat(5, () =>
14+
it('input value', async () => {
15+
const { context } = await getPageDataOfTestName('todo');
16+
const instructions = [
17+
'In the taskbar, type learning english',
18+
'In the taskbar, type learning english and hit Enter key',
19+
];
20+
21+
for (const instruction of instructions) {
22+
const { actions } = await plan(instruction, { context });
23+
const res = makePlanResultStable(actions);
24+
expect(res).toMatchSnapshot();
25+
}
26+
}),
27+
);
28+
29+
repeat(5, () =>
30+
it('input value Add, delete, correct and check', async () => {
31+
const { context } = await getPageDataOfTestName('todo-input-with-value');
32+
const instructions = [
33+
'Append "tomorrow" to the existing content in the task input box',
34+
'Replace "English" with "Skiing" in the existing content of the task input box',
35+
'Delete "English" from the existing content in the task input box',
36+
];
37+
38+
for (const instruction of instructions) {
39+
const { actions } = await plan(instruction, { context });
40+
const res = makePlanResultStable(actions);
41+
expect(res).toMatchSnapshot();
42+
}
43+
}),
44+
);
45+
});

packages/midscene/tests/ai/evaluate/planning-input.test.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AiExtractElementInfo } from '@/ai-model';
2-
import { preferCozeModel } from '@/ai-model/coze';
32
import { describe, expect, it, vi } from 'vitest';
43
import { getPageDataOfTestName } from '../evaluate/test-suite/util';
54

@@ -8,46 +7,35 @@ vi.setConfig({
87
hookTimeout: 30 * 1000,
98
});
109

11-
const modelList: Array<'openAI' | 'coze'> = ['openAI'];
10+
describe('extract', () => {
11+
it('todo', async () => {
12+
const { context } = await getPageDataOfTestName('todo');
1213

13-
if (preferCozeModel('coze')) {
14-
modelList.push('coze');
15-
}
16-
17-
modelList.forEach((model) => {
18-
describe(`assert ${model}`, () => {
19-
it('todo', async () => {
20-
const { context } = await getPageDataOfTestName('todo');
21-
22-
const { parseResult } = await AiExtractElementInfo({
23-
dataQuery: 'Array<string>, Complete task list, string is the task',
24-
context,
25-
useModel: model,
26-
});
27-
expect(parseResult).toMatchSnapshot();
14+
const { parseResult } = await AiExtractElementInfo({
15+
dataQuery: 'Array<string>, Complete task list, string is the task',
16+
context,
2817
});
18+
expect(parseResult).toMatchSnapshot();
19+
});
2920

30-
it('online order', async () => {
31-
const { context } = await getPageDataOfTestName('online_order');
21+
it('online order', async () => {
22+
const { context } = await getPageDataOfTestName('online_order');
3223

33-
const { parseResult } = await AiExtractElementInfo({
34-
dataQuery: '{name: string, price: string}[], 饮品名称和价格',
35-
context,
36-
useModel: model,
37-
});
38-
expect(parseResult).toMatchSnapshot();
24+
const { parseResult } = await AiExtractElementInfo({
25+
dataQuery: '{name: string, price: string}[], 饮品名称和价格',
26+
context,
3927
});
28+
expect(parseResult).toMatchSnapshot();
29+
});
4030

41-
it('todo obj', async () => {
42-
const { context } = await getPageDataOfTestName('todo');
31+
it('todo obj', async () => {
32+
const { context } = await getPageDataOfTestName('todo');
4333

44-
const { parseResult } = await AiExtractElementInfo({
45-
dataQuery:
46-
'{checked: boolean; text: string}[],Complete task list, string is the task',
47-
context,
48-
useModel: model,
49-
});
50-
expect(parseResult).toMatchSnapshot();
34+
const { parseResult } = await AiExtractElementInfo({
35+
dataQuery:
36+
'{checked: boolean; text: string}[],Complete task list, string is the task',
37+
context,
5138
});
39+
expect(parseResult).toMatchSnapshot();
5240
});
5341
});

packages/midscene/tests/ai/util.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { preferCozeModel } from '@/ai-model/coze';
21
import type { PlanningAction } from '@/types';
32

43
export function makePlanResultStable(plans: PlanningAction[]) {
@@ -15,7 +14,3 @@ export function makePlanResultStable(plans: PlanningAction[]) {
1514
return plan;
1615
});
1716
}
18-
19-
export const modelList: Array<'openAI' | 'coze'> = preferCozeModel('coze')
20-
? ['openAI', 'coze']
21-
: ['openAI'];

0 commit comments

Comments
 (0)