mirror of
https://github.com/web-infra-dev/midscene.git
synced 2026-01-07 12:41:08 +00:00
fix(core): distint prompt sequence when deepThink is true
This commit is contained in:
parent
b7145ead34
commit
7f3f9427f7
@ -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.
|
||||
|
||||
@ -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 生成的原因。
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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.
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user