Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move action type validate in workflow runtime #1235

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions skyvern/forge/sdk/workflow/models/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from skyvern.forge.sdk.settings_manager import SettingsManager
from skyvern.forge.sdk.workflow.context_manager import WorkflowRunContext
from skyvern.forge.sdk.workflow.exceptions import (
FailedToParseActionInstruction,
InvalidEmailClientConfiguration,
InvalidFileType,
NoValidEmailRecipient,
Expand All @@ -56,6 +57,7 @@
OutputParameter,
WorkflowParameter,
)
from skyvern.webeye.actions.actions import ActionType
from skyvern.webeye.browser_factory import BrowserState

LOG = structlog.get_logger()
Expand Down Expand Up @@ -1299,6 +1301,38 @@ class ActionBlock(BaseTaskBlock):
block_type: Literal[BlockType.ACTION] = BlockType.ACTION

async def execute(self, workflow_run_id: str, **kwargs: dict) -> BlockResult:
try:
prompt = prompt_engine.load_prompt("infer-action-type", navigation_goal=self.navigation_goal)
# TODO: no step here, so LLM call won't be saved as an artifact
json_response = await app.LLM_API_HANDLER(prompt=prompt)
if json_response.get("error"):
raise FailedToParseActionInstruction(
reason=json_response.get("thought"), error_type=json_response.get("error")
)

action_type: str = json_response.get("action_type") or ""
action_type = ActionType[action_type.upper()]

prompt_template = ""
if action_type == ActionType.CLICK:
prompt_template = TaskPromptTemplate.SingleClickAction
elif action_type == ActionType.INPUT_TEXT:
prompt_template = TaskPromptTemplate.SingleInputAction
elif action_type == ActionType.UPLOAD_FILE:
prompt_template = TaskPromptTemplate.SingleUploadAction
elif action_type == ActionType.SELECT_OPTION:
prompt_template = TaskPromptTemplate.SingleSelectAction

if not prompt_template:
raise Exception(
f"Not supported action for action block. Currently we only support [click, input_text, upload_file, select_option], but got [{action_type}]"
)
except Exception as e:
return self.build_block_result(
success=False, failure_reason=str(e), output_parameter_value=None, status=BlockStatus.failed
)

self.prompt_template = prompt_template
return await super().execute(workflow_run_id=workflow_run_id, kwargs=kwargs)


Expand Down
30 changes: 0 additions & 30 deletions skyvern/forge/sdk/workflow/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
WorkflowRunNotFound,
)
from skyvern.forge import app
from skyvern.forge.prompts import prompt_engine
from skyvern.forge.sdk.artifact.models import ArtifactType
from skyvern.forge.sdk.core import skyvern_context
from skyvern.forge.sdk.core.security import generate_skyvern_signature
Expand All @@ -24,7 +23,6 @@
from skyvern.forge.sdk.schemas.tasks import ProxyLocation, Task
from skyvern.forge.sdk.workflow.exceptions import (
ContextParameterSourceNotDefined,
FailedToParseActionInstruction,
InvalidWorkflowDefinition,
WorkflowDefinitionHasDuplicateParameterKeys,
WorkflowDefinitionHasReservedParameterKeys,
Expand Down Expand Up @@ -66,7 +64,6 @@
WorkflowRunStatusResponse,
)
from skyvern.forge.sdk.workflow.models.yaml import BLOCK_YAML_TYPES, ForLoopBlockYAML, WorkflowCreateYAMLRequest
from skyvern.webeye.actions.actions import ActionType
from skyvern.webeye.browser_factory import BrowserState

LOG = structlog.get_logger()
Expand Down Expand Up @@ -1372,34 +1369,7 @@ async def block_yaml_to_block(
if not block_yaml.navigation_goal:
raise Exception("empty action instruction")

prompt = prompt_engine.load_prompt("infer-action-type", navigation_goal=block_yaml.navigation_goal)
# TODO: no step here, so LLM call won't be saved as an artifact
json_response = await app.LLM_API_HANDLER(prompt=prompt)
if json_response.get("error"):
raise FailedToParseActionInstruction(
reason=json_response.get("thought"), error_type=json_response.get("error")
)

action_type: str = json_response.get("action_type") or ""
action_type = ActionType[action_type.upper()]

prompt_template = ""
if action_type == ActionType.CLICK:
prompt_template = TaskPromptTemplate.SingleClickAction
elif action_type == ActionType.INPUT_TEXT:
prompt_template = TaskPromptTemplate.SingleInputAction
elif action_type == ActionType.UPLOAD_FILE:
prompt_template = TaskPromptTemplate.SingleUploadAction
elif action_type == ActionType.SELECT_OPTION:
prompt_template = TaskPromptTemplate.SingleSelectAction

if not prompt_template:
raise Exception(
f"Not supported action for action block. Currently we only support [click, input_text, upload_file, select_option], but got [{action_type}]"
)

return ActionBlock(
prompt_template=prompt_template,
label=block_yaml.label,
url=block_yaml.url,
title=block_yaml.title,
Expand Down
Loading