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

use jinja template for workflow parameter #1272

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
30 changes: 30 additions & 0 deletions skyvern/forge/sdk/workflow/models/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import filetype
import structlog
from email_validator import EmailNotValidError, validate_email
from jinja2 import Template
from playwright.async_api import Error
from pydantic import BaseModel, Field

Expand Down Expand Up @@ -216,6 +217,15 @@ def get_all_parameters(

return parameters

@staticmethod
def format_task_block_parameter_template_from_workflow_run_context(
potential_template: str | None, workflow_run_context: WorkflowRunContext
) -> str | None:
if not potential_template:
return potential_template
template = Template(potential_template)
return template.render(workflow_run_context.values)

@staticmethod
async def get_task_order(workflow_run_id: str, current_retry: int) -> tuple[int, int]:
"""
Expand Down Expand Up @@ -289,6 +299,26 @@ async def execute(self, workflow_run_id: str, **kwargs: dict) -> BlockResult:
)
self.download_suffix = download_suffix_parameter_value

self.url = self.format_task_block_parameter_template_from_workflow_run_context(self.url, workflow_run_context)
self.totp_identifier = self.format_task_block_parameter_template_from_workflow_run_context(
self.totp_identifier, workflow_run_context
)
self.download_suffix = self.format_task_block_parameter_template_from_workflow_run_context(
self.download_suffix, workflow_run_context
)
self.navigation_goal = self.format_task_block_parameter_template_from_workflow_run_context(
self.navigation_goal, workflow_run_context
)
self.data_extraction_goal = self.format_task_block_parameter_template_from_workflow_run_context(
self.data_extraction_goal, workflow_run_context
)
self.complete_criterion = self.format_task_block_parameter_template_from_workflow_run_context(
self.complete_criterion, workflow_run_context
)
self.terminate_criterion = self.format_task_block_parameter_template_from_workflow_run_context(
self.terminate_criterion, workflow_run_context
)

# TODO (kerem) we should always retry on terminated. We should make a distinction between retriable and
# non-retryable terminations
while will_retry:
Expand Down