diff --git a/apps/site/docs/en/API.mdx b/apps/site/docs/en/API.mdx index 82f2d99d2..d54cae6ba 100644 --- a/apps/site/docs/en/API.mdx +++ b/apps/site/docs/en/API.mdx @@ -394,7 +394,6 @@ function aiAssert(assertion: string, errorMsg?: string, options?: { * `errorMsg?: string` - An optional error message to append if the assertion fails. * `options?: Object` - Optional, a configuration object containing: * `deepThink?: boolean` - If true, Midscene will enable AI model's [COT](https://www.wikiwand.com/en/articles/Chain_of_thought) mode, which makes AI model to think more deeply when asserting. Default: False. - * `keepRawResponse?: boolean` - If true, Midscene will keep the raw response from the AI model. Default: False. * Return Value: * Returns a Promise that resolves to void if the assertion passes; if it fails, an error is thrown with `errorMsg` and additional AI-provided information. diff --git a/apps/site/docs/zh/API.mdx b/apps/site/docs/zh/API.mdx index 5d8ce8c96..968c5db46 100644 --- a/apps/site/docs/zh/API.mdx +++ b/apps/site/docs/zh/API.mdx @@ -397,7 +397,6 @@ function aiAssert(assertion: string, errorMsg?: string, options?: { * errorMsg?: string - 当断言失败时附加的可选错误提示信息。 * options?: Object - 可选的配置对象,包含: * `deepThink?: boolean` - 是否开启深度思考。如果为 true,Midscene 启用 AI 模型的 [COT](https://www.wikiwand.com/en/articles/Chain_of_thought) 模式,使 AI 在断言时进行更深入的思考。默认值为 False。 - * `keepRawResponse?: boolean` - 是否保留 AI 的原始响应。如果为 true,Midscene 会保留 AI 的原始响应而不格式化。默认值为 False。 * 返回值: * 返回一个 Promise。当断言成功时解析为 void;若断言失败,则抛出一个错误,错误信息包含 `errorMsg` 以及 AI 生成的原因。 diff --git a/packages/core/src/ai-model/prompt/assertion.ts b/packages/core/src/ai-model/prompt/assertion.ts index 9eea1d3de..71f600f29 100644 --- a/packages/core/src/ai-model/prompt/assertion.ts +++ b/packages/core/src/ai-model/prompt/assertion.ts @@ -7,17 +7,35 @@ const defaultAssertionPrompt = const getDefaultAssertionResponseJsonFormat = ( deepThink: boolean, ) => `Return in the following JSON format: -{ - thought: string, // string, ${deepThink ? 'ALWAYS provide the reasoning process that led to the pass/fail conclusion. This should detail the step-by-step thinking.' : 'if the result is falsy, give the reason why it is falsy. Otherwise, put null.'} +${ + deepThink + ? `{ + thought: string, // string, ALWAYS provide the reasoning process that led to the pass/fail conclusion. This should detail the step-by-step thinking. pass: boolean, // whether the assertion is truthy -}`; +}` + : `{ + pass: boolean, // whether the assertion is truthy + thought: string, // string, if the result is falsy, give the reason why it is falsy. Otherwise, put null. + }` +} +`; -const getUiTarsAssertionResponseJsonFormat = () => `## Output Json String Format +const getUiTarsAssertionResponseJsonFormat = ( + deepThink: boolean, +) => `## Output Json String Format \`\`\` -"{ - "thought": "<>" +${ + deepThink + ? `{ + "thought": "<>", "pass": <>, -}" +}` + : `{ + "pass": <>, + "thought": "<>" + +}` +} \`\`\` ## Rules **MUST** follow @@ -31,7 +49,7 @@ export function systemPromptToAssert(model: { }) { return `${defaultAssertionPrompt} -${model.isUITars ? getUiTarsAssertionResponseJsonFormat() : getDefaultAssertionResponseJsonFormat(model.deepThink)}`; +${model.isUITars ? getUiTarsAssertionResponseJsonFormat(model.deepThink) : getDefaultAssertionResponseJsonFormat(model.deepThink)}`; } export const assertSchema: ResponseFormatJSONSchema = { diff --git a/packages/core/tests/unit-test/prompt/__snapshots__/assertion.test.ts.snap b/packages/core/tests/unit-test/prompt/__snapshots__/assertion.test.ts.snap index 4dc90b1ef..a3b62d2b5 100644 --- a/packages/core/tests/unit-test/prompt/__snapshots__/assertion.test.ts.snap +++ b/packages/core/tests/unit-test/prompt/__snapshots__/assertion.test.ts.snap @@ -5,10 +5,11 @@ exports[`Assertion prompt > return UI-Tars specific when it is UI-Tars 1`] = ` ## Output Json String Format \`\`\` -"{ - "thought": "<>" +{ "pass": <>, -}" + "thought": "<>" + +} \`\`\` ## Rules **MUST** follow @@ -22,10 +23,10 @@ exports[`Assertion prompt > return UI-Tars specific when it is UI-Tars and deepT ## Output Json String Format \`\`\` -"{ - "thought": "<>" +{ + "thought": "<>", "pass": <>, -}" +} \`\`\` ## Rules **MUST** follow @@ -39,7 +40,8 @@ exports[`Assertion prompt > return default when it is not UI-Tars 1`] = ` Return in the following JSON format: { - thought: string, // string, if the result is falsy, give the reason why it is falsy. Otherwise, put null. pass: boolean, // whether the assertion is truthy -}" + thought: string, // string, if the result is falsy, give the reason why it is falsy. Otherwise, put null. + } +" `;