integrate parameters to support legacy tasks with parameters (#3567)
This commit is contained in:
@@ -1350,6 +1350,18 @@ def __build_base_task_statement(
|
||||
) -> list[cst.Arg]:
|
||||
block_type = block.get("block_type")
|
||||
prompt = block.get("prompt") if block_type == "task_v2" else block.get("navigation_goal")
|
||||
# add parameters to prompt
|
||||
parameters = block.get("parameters", [])
|
||||
navigation_payload = {}
|
||||
# make all parameters as jinja2 template parameters in the generated code
|
||||
for parameter in parameters:
|
||||
parameter_key = parameter["key"]
|
||||
navigation_payload[parameter_key] = "{{" + parameter_key + "}}"
|
||||
|
||||
if navigation_payload:
|
||||
prompt = prompt or ""
|
||||
prompt = f"{prompt}\n{navigation_payload}"
|
||||
|
||||
args = [
|
||||
cst.Arg(
|
||||
keyword=cst.Name("prompt"),
|
||||
|
||||
@@ -509,7 +509,7 @@ class SkyvernPage:
|
||||
if ai_infer and intention:
|
||||
try:
|
||||
prompt = context.prompt if context else None
|
||||
data = _get_context_data(data)
|
||||
data = data or {}
|
||||
if (totp_identifier or totp_url) and context and organization_id and task_id:
|
||||
verification_code = await poll_verification_code(
|
||||
organization_id=organization_id,
|
||||
@@ -535,7 +535,6 @@ class SkyvernPage:
|
||||
script_generation_input_text_prompt = prompt_engine.load_prompt(
|
||||
template="script-generation-input-text-generatiion",
|
||||
intention=intention,
|
||||
data=data,
|
||||
goal=prompt,
|
||||
)
|
||||
json_response = await app.SINGLE_INPUT_AGENT_LLM_API_HANDLER(
|
||||
@@ -620,7 +619,8 @@ class SkyvernPage:
|
||||
if ai_infer and intention and task and step:
|
||||
try:
|
||||
prompt = context.prompt if context else None
|
||||
data = _get_context_data(data)
|
||||
# data = _get_context_data(data)
|
||||
data = data or {}
|
||||
refreshed_page = await self.scraped_page.generate_scraped_page_without_screenshots()
|
||||
self.scraped_page = refreshed_page
|
||||
element_tree = refreshed_page.build_element_tree()
|
||||
|
||||
@@ -1114,6 +1114,7 @@ async def run_task(
|
||||
prompt: str,
|
||||
url: str | None = None,
|
||||
max_steps: int | None = None,
|
||||
download_suffix: str | None = None,
|
||||
totp_identifier: str | None = None,
|
||||
totp_url: str | None = None,
|
||||
label: str | None = None,
|
||||
@@ -1133,6 +1134,7 @@ async def run_task(
|
||||
url=url,
|
||||
label=cache_key,
|
||||
)
|
||||
prompt = _render_template_with_label(prompt, cache_key)
|
||||
# set the prompt in the RunContext
|
||||
context = skyvern_context.ensure_context()
|
||||
context.prompt = prompt
|
||||
@@ -1190,6 +1192,7 @@ async def download(
|
||||
prompt: str,
|
||||
url: str | None = None,
|
||||
complete_on_download: bool = True,
|
||||
download_suffix: str | None = None,
|
||||
max_steps: int | None = None,
|
||||
totp_identifier: str | None = None,
|
||||
totp_url: str | None = None,
|
||||
@@ -1198,7 +1201,6 @@ async def download(
|
||||
) -> None:
|
||||
cache_key = cache_key or label
|
||||
cached_fn = script_run_context_manager.get_cached_fn(cache_key)
|
||||
|
||||
context: skyvern_context.SkyvernContext | None
|
||||
if cache_key and cached_fn:
|
||||
# Auto-create workflow block run and task if workflow_run_id is available
|
||||
@@ -1208,6 +1210,7 @@ async def download(
|
||||
url=url,
|
||||
label=cache_key,
|
||||
)
|
||||
prompt = _render_template_with_label(prompt, cache_key)
|
||||
# set the prompt in the RunContext
|
||||
context = skyvern_context.ensure_context()
|
||||
context.prompt = prompt
|
||||
@@ -1265,6 +1268,7 @@ async def action(
|
||||
prompt: str,
|
||||
url: str | None = None,
|
||||
max_steps: int | None = None,
|
||||
download_suffix: str | None = None,
|
||||
totp_identifier: str | None = None,
|
||||
totp_url: str | None = None,
|
||||
label: str | None = None,
|
||||
@@ -1281,6 +1285,7 @@ async def action(
|
||||
url=url,
|
||||
label=cache_key,
|
||||
)
|
||||
prompt = _render_template_with_label(prompt, cache_key)
|
||||
# set the prompt in the RunContext
|
||||
context = skyvern_context.ensure_context()
|
||||
context.prompt = prompt
|
||||
@@ -1346,12 +1351,14 @@ async def login(
|
||||
cached_fn = script_run_context_manager.get_cached_fn(cache_key)
|
||||
if cache_key and cached_fn:
|
||||
# Auto-create workflow block run and task if workflow_run_id is available
|
||||
# render template with label
|
||||
workflow_run_block_id, task_id, step_id = await _create_workflow_block_run_and_task(
|
||||
block_type=BlockType.LOGIN,
|
||||
prompt=prompt,
|
||||
url=url,
|
||||
label=cache_key,
|
||||
)
|
||||
prompt = _render_template_with_label(prompt, cache_key)
|
||||
# set the prompt in the RunContext
|
||||
context = skyvern_context.ensure_context()
|
||||
context.prompt = prompt
|
||||
@@ -1424,6 +1431,7 @@ async def extract(
|
||||
url=url,
|
||||
label=cache_key,
|
||||
)
|
||||
prompt = _render_template_with_label(prompt, cache_key)
|
||||
# set the prompt in the RunContext
|
||||
context = skyvern_context.ensure_context()
|
||||
context.prompt = prompt
|
||||
@@ -1546,27 +1554,27 @@ def _render_template_with_label(template: str, label: str | None = None) -> str:
|
||||
context = skyvern_context.current()
|
||||
if context and context.workflow_run_id:
|
||||
workflow_run_context = app.WORKFLOW_CONTEXT_MANAGER.get_workflow_run_context(context.workflow_run_id)
|
||||
block_reference_data: dict[str, Any] = workflow_run_context.get_block_metadata(label)
|
||||
template_data = workflow_run_context.values.copy()
|
||||
if label in template_data:
|
||||
current_value = template_data[label]
|
||||
if isinstance(current_value, dict):
|
||||
block_reference_data.update(current_value)
|
||||
else:
|
||||
LOG.warning(
|
||||
f"Script service: Parameter {label} has a registered reference value, going to overwrite it by block metadata"
|
||||
)
|
||||
|
||||
if label:
|
||||
block_reference_data = workflow_run_context.get_block_metadata(label)
|
||||
if label in template_data:
|
||||
current_value = template_data[label]
|
||||
if isinstance(current_value, dict):
|
||||
block_reference_data.update(current_value)
|
||||
else:
|
||||
LOG.warning(
|
||||
f"Script service: Parameter {label} has a registered reference value, going to overwrite it by block metadata"
|
||||
)
|
||||
|
||||
template_data[label] = block_reference_data
|
||||
|
||||
# inject the forloop metadata as global variables
|
||||
if "current_index" in block_reference_data:
|
||||
template_data["current_index"] = block_reference_data["current_index"]
|
||||
if "current_item" in block_reference_data:
|
||||
template_data["current_item"] = block_reference_data["current_item"]
|
||||
if "current_value" in block_reference_data:
|
||||
template_data["current_value"] = block_reference_data["current_value"]
|
||||
# inject the forloop metadata as global variables
|
||||
if "current_index" in block_reference_data:
|
||||
template_data["current_index"] = block_reference_data["current_index"]
|
||||
if "current_item" in block_reference_data:
|
||||
template_data["current_item"] = block_reference_data["current_item"]
|
||||
if "current_value" in block_reference_data:
|
||||
template_data["current_value"] = block_reference_data["current_value"]
|
||||
return render_template(template, data=template_data)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user