mirror of
https://github.com/web-infra-dev/midscene.git
synced 2026-01-06 12:11:08 +00:00
feat(core): support error message for ai assert in yaml (#774)
This commit is contained in:
parent
5451c27db4
commit
8f4e722239
@ -248,6 +248,7 @@ tasks:
|
||||
|
||||
# perform an assertion
|
||||
- aiAssert: <prompt>
|
||||
errorMessage: <error-message> # optional, the error message to print when the assertion fails
|
||||
|
||||
# sleep for a number of milliseconds
|
||||
- sleep: <ms>
|
||||
|
||||
@ -84,7 +84,10 @@ while (user.length > 0) {
|
||||
// Check if we've gone through all users in the current list
|
||||
if (currentUserIndex >= user.length) {
|
||||
// Scroll down to load more users
|
||||
await agent.aiScroll('scroll down one screen')
|
||||
await agent.aiScroll({
|
||||
direction: 'down',
|
||||
scrollType: 'once',
|
||||
})
|
||||
|
||||
// Get the updated user list
|
||||
user = await agent.aiQuery('string[], the unfollowed user names in the list')
|
||||
|
||||
@ -249,6 +249,7 @@ tasks:
|
||||
|
||||
# 执行一个断言
|
||||
- aiAssert: <prompt>
|
||||
errorMessage: <error-message> # 可选,当断言失败时打印的错误信息。
|
||||
|
||||
# 等待一定时间
|
||||
- sleep: <ms>
|
||||
|
||||
@ -83,7 +83,10 @@ while (user.length > 0) {
|
||||
// 检查是否已经遍历了当前列表中的所有用户
|
||||
if (currentUserIndex >= user.length) {
|
||||
// 向下滚动一屏
|
||||
await agent.aiScroll('向下滚动一屏')
|
||||
await agent.aiScroll({
|
||||
direction: 'down',
|
||||
scrollType: 'once',
|
||||
})
|
||||
|
||||
// 获取更新后的用户列表
|
||||
user = await agent.aiQuery('string[], 列表中所有未关注用户')
|
||||
|
||||
@ -14,7 +14,6 @@ import { elementDescriberInstruction } from '@/ai-model/prompt/describe';
|
||||
import type {
|
||||
AIDescribeElementResponse,
|
||||
AIElementResponse,
|
||||
AISingleElementResponse,
|
||||
AIUsageInfo,
|
||||
BaseElement,
|
||||
DetailedLocateParam,
|
||||
|
||||
@ -85,6 +85,7 @@ export interface MidsceneYamlFlowItemAIAction {
|
||||
|
||||
export interface MidsceneYamlFlowItemAIAssert {
|
||||
aiAssert: string;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
export interface MidsceneYamlFlowItemAIQuery {
|
||||
|
||||
@ -146,12 +146,13 @@ export class ScriptPlayer<T extends MidsceneYamlScriptEnv> {
|
||||
} else if ('aiAssert' in (flowItem as MidsceneYamlFlowItemAIAssert)) {
|
||||
const assertTask = flowItem as MidsceneYamlFlowItemAIAssert;
|
||||
const prompt = assertTask.aiAssert;
|
||||
const msg = assertTask.errorMessage;
|
||||
assert(prompt, 'missing prompt for aiAssert');
|
||||
assert(
|
||||
typeof prompt === 'string',
|
||||
'prompt for aiAssert must be a string',
|
||||
);
|
||||
await agent.aiAssert(prompt);
|
||||
await agent.aiAssert(prompt, msg);
|
||||
} else if ('aiQuery' in (flowItem as MidsceneYamlFlowItemAIQuery)) {
|
||||
const queryTask = flowItem as MidsceneYamlFlowItemAIQuery;
|
||||
const prompt = queryTask.aiQuery;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user