Skip to content

Commit 7286b57

Browse files
ottomaoclaude
andauthored
fix(core): strengthen language control in aiDescribe prompt (#2067)
The previous prompt had "Use ${language}." appended to the first sentence, which was ambiguous and easily overridden by the all-English few-shot examples. This change: - Separates the language instruction into a standalone "IMPORTANT" directive - Adds a redundant reminder in the GUIDELINES section - Provides Chinese examples when preferredLanguage is Chinese, so the few-shot signal aligns with the language instruction https://claude.ai/code/session_01A2hhpJ74in5M6cL2Qj2HrR Co-authored-by: Claude <noreply@anthropic.com>
1 parent 02f12fe commit 7286b57

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

packages/core/src/ai-model/prompt/describe.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
import { getPreferredLanguage } from '@midscene/shared/env';
22

3+
const examplesMap: Record<string, string[]> = {
4+
Chinese: [
5+
'"登录表单中的"登录"按钮"',
6+
'"搜索输入框,placeholder 为"请输入关键词""',
7+
'"顶部导航栏中文字为"首页"的链接"',
8+
'"联系表单中的提交按钮"',
9+
'"aria-label 为"打开菜单"的菜单图标"',
10+
],
11+
English: [
12+
'"Login button with text \'Sign In\'"',
13+
'"Search input with placeholder \'Enter keywords\'"',
14+
'"Navigation link with text \'Home\' in header"',
15+
'"Submit button in contact form"',
16+
'"Menu icon with aria-label \'Open menu\'"',
17+
],
18+
};
19+
20+
const getExamples = (language: string) => {
21+
const examples = examplesMap[language] || examplesMap.English;
22+
return examples.map((e) => `- ${e}`).join('\n');
23+
};
24+
325
export const elementDescriberInstruction = () => {
26+
const preferredLanguage = getPreferredLanguage();
27+
428
return `
5-
Describe the element in the red rectangle for precise identification. Use ${getPreferredLanguage()}.
29+
Describe the element in the red rectangle for precise identification.
30+
31+
IMPORTANT: You MUST write the description in ${preferredLanguage}.
632
733
CRITICAL REQUIREMENTS:
834
1. UNIQUENESS: The description must uniquely identify this element on the current page
@@ -28,13 +54,10 @@ GUIDELINES:
2854
- Avoid page-specific or temporary content
2955
- Don't mention the red rectangle or selection box
3056
- Focus on stable, reusable characteristics
57+
- **Write the description in ${preferredLanguage}**
3158
3259
EXAMPLES:
33-
- "Login button with text 'Sign In'"
34-
- "Search input with placeholder 'Enter keywords'"
35-
- "Navigation link with text 'Home' in header"
36-
- "Submit button in contact form"
37-
- "Menu icon with aria-label 'Open menu'"
60+
${getExamples(preferredLanguage)}
3861
3962
Return JSON:
4063
{

packages/core/tests/unit-test/prompt/__snapshots__/describe.test.ts.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
exports[`elementDescriberInstruction > should return the correct instruction 1`] = `
44
"
5-
Describe the element in the red rectangle for precise identification. Use English.
5+
Describe the element in the red rectangle for precise identification.
6+
7+
IMPORTANT: You MUST write the description in English.
68
79
CRITICAL REQUIREMENTS:
810
1. UNIQUENESS: The description must uniquely identify this element on the current page
@@ -28,6 +30,7 @@ GUIDELINES:
2830
- Avoid page-specific or temporary content
2931
- Don't mention the red rectangle or selection box
3032
- Focus on stable, reusable characteristics
33+
- **Write the description in English**
3134
3235
EXAMPLES:
3336
- "Login button with text 'Sign In'"

0 commit comments

Comments
 (0)