fix(core): distint prompt sequence when deepThink is true

This commit is contained in:
quanruzhuoxiu 2025-06-04 16:27:35 +08:00
parent b7145ead34
commit 7f3f9427f7
4 changed files with 36 additions and 18 deletions

View File

@ -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.

View File

@ -397,7 +397,6 @@ function aiAssert(assertion: string, errorMsg?: string, options?: {
* errorMsg?: string - 当断言失败时附加的可选错误提示信息。
* options?: Object - 可选的配置对象,包含:
* `deepThink?: boolean` - 是否开启深度思考。如果为 trueMidscene 启用 AI 模型的 [COT](https://www.wikiwand.com/en/articles/Chain_of_thought) 模式,使 AI 在断言时进行更深入的思考。默认值为 False。
* `keepRawResponse?: boolean` - 是否保留 AI 的原始响应。如果为 trueMidscene 会保留 AI 的原始响应而不格式化。默认值为 False。
* 返回值:
* 返回一个 Promise。当断言成功时解析为 void若断言失败则抛出一个错误错误信息包含 `errorMsg` 以及 AI 生成的原因。

View File

@ -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": "<<is a string, give the reason why the assertion is falsy or truthy. Otherwise.>>"
${
deepThink
? `{
"thought": "<<is a string, ALWAYS provide the reasoning process that led to the pass/fail conclusion. This should detail the step-by-step thinking.>>",
"pass": <<is a boolean value from the enum [true, false], true means the assertion is truthy>>,
}"
}`
: `{
"pass": <<is a boolean value from the enum [true, false], true means the assertion is truthy>>,
"thought": "<<is a string, give the reason why the assertion is falsy or truthy. Otherwise.>>"
}`
}
\`\`\`
## 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 = {

View File

@ -5,10 +5,11 @@ exports[`Assertion prompt > return UI-Tars specific when it is UI-Tars 1`] = `
## Output Json String Format
\`\`\`
"{
"thought": "<<is a string, give the reason why the assertion is falsy or truthy. Otherwise.>>"
{
"pass": <<is a boolean value from the enum [true, false], true means the assertion is truthy>>,
}"
"thought": "<<is a string, give the reason why the assertion is falsy or truthy. Otherwise.>>"
}
\`\`\`
## 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": "<<is a string, give the reason why the assertion is falsy or truthy. Otherwise.>>"
{
"thought": "<<is a string, ALWAYS provide the reasoning process that led to the pass/fail conclusion. This should detail the step-by-step thinking.>>",
"pass": <<is a boolean value from the enum [true, false], true means the assertion is truthy>>,
}"
}
\`\`\`
## 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.
}
"
`;