SDK: validation action (#4203)
This commit is contained in:
committed by
GitHub
parent
7ef48c32e0
commit
4b99cd3f45
@@ -1,4 +1,4 @@
|
||||
Your are here to help the user determine if the current page has met the complete/terminte criterion. Use the criterions of complete/terminate, the content of the elements parsed from the page, the screenshots of the page, and user details to determine whether the criterions has been met.
|
||||
Your are here to help the user determine if the current page has met the complete/terminate criterion. Use the criterions of complete/terminate, the content of the elements parsed from the page, the screenshots of the page, and user details to determine whether the criterions has been met.
|
||||
|
||||
|
||||
Reply in JSON format with the following keys:
|
||||
@@ -9,7 +9,7 @@ Reply in JSON format with the following keys:
|
||||
[{
|
||||
"reasoning": str, // The reasoning behind the action. This reasoning must be user information agnostic. Mention why you chose the action type, and why you chose the element id. Keep the reasoning short and to the point.
|
||||
"confidence_float": float, // The confidence of the action. Pick a number between 0.0 and 1.0. 0.0 means no confidence, 1.0 means full confidence
|
||||
"action_type": str, // It's a string enum: "COMPLETE", "TERMINATE". "COMPLETE" is used when the current page info has met the complete criterion. If there is no complete criterion, use "COMPLETE" as long as the page info hasn't met the terminate criterion. "TERMINATE" is used to terminate with a failure when the current page info has met the terminate criterion. It there is no terminate criterion, use "TERMINATE" as long as the page info hasn't met the complete criterion.
|
||||
"action_type": str, // It's a string enum: "COMPLETE", "TERMINATE". Use "COMPLETE" when the complete criterion is met (if provided). Use "TERMINATE" when the terminate criterion is met (if provided), or when a complete criterion is provided but not met.
|
||||
}]
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +205,12 @@ async def run_sdk_action(
|
||||
prompt=action.prompt,
|
||||
)
|
||||
result = xpath_result
|
||||
elif action.type == "validate":
|
||||
validation_result = await page_ai.ai_validate(
|
||||
prompt=action.prompt,
|
||||
model=action.model,
|
||||
)
|
||||
result = validation_result
|
||||
elif action.type == "prompt":
|
||||
prompt_result = await page_ai.ai_prompt(
|
||||
prompt=action.prompt,
|
||||
|
||||
@@ -16,6 +16,7 @@ class SdkActionType(str, Enum):
|
||||
AI_ACT = "ai_act"
|
||||
EXTRACT = "extract"
|
||||
LOCATE_ELEMENT = "locate_element"
|
||||
VALIDATE = "validate"
|
||||
PROMPT = "prompt"
|
||||
|
||||
|
||||
@@ -152,6 +153,20 @@ class LocateElementAction(SdkActionBase):
|
||||
return None
|
||||
|
||||
|
||||
class ValidateAction(SdkActionBase):
|
||||
"""Validate action parameters."""
|
||||
|
||||
type: Literal["validate"] = "validate"
|
||||
prompt: str = Field(..., description="Validation criteria or condition to check")
|
||||
model: dict[str, Any] | None = Field(None, description="Optional model configuration")
|
||||
|
||||
def get_navigation_goal(self) -> str | None:
|
||||
return self.prompt
|
||||
|
||||
def get_navigation_payload(self) -> dict[str, Any] | None:
|
||||
return None
|
||||
|
||||
|
||||
class PromptAction(SdkActionBase):
|
||||
"""Prompt action parameters."""
|
||||
|
||||
@@ -177,6 +192,7 @@ SdkAction = Annotated[
|
||||
ActAction,
|
||||
ExtractAction,
|
||||
LocateElementAction,
|
||||
ValidateAction,
|
||||
PromptAction,
|
||||
],
|
||||
Field(discriminator="type"),
|
||||
|
||||
Reference in New Issue
Block a user