diff --git a/src/promptflow/CHANGELOG.md b/src/promptflow/CHANGELOG.md index 6292c450be4..df09ad4473b 100644 --- a/src/promptflow/CHANGELOG.md +++ b/src/promptflow/CHANGELOG.md @@ -2,9 +2,16 @@ ## 1.4.0 (Upcoming) +### Features Added + +- [Executor] Calculate system_metrics recursively in api_calls. +- [Executor] Add flow root level api_calls, so that user can overview the aggregated metrics of a flow. +- [Executor] Add @trace decorator to make it possible to log traces for functions that are called by tools. + ### Bugs Fixed - Fix unaligned inputs & outputs or pandas exception during get details against run in Azure. +- Fix loose flow path validation for run schema. ## 1.3.0 (2023.12.27) @@ -13,9 +20,6 @@ - Add support to configure prompt flow home directory via environment variable `PF_HOME_DIRECTORY`. - Please set before importing `promptflow`, otherwise it won't take effect. - [Executor] Handle KeyboardInterrupt in flow test so that the final state is Canceled. -- [Executor] Calculate system_metrics recursively in api_calls. -- [Executor] Add flow root level api_calls, so that user can overview the aggregated metrics of a flow. -- [Executor] Add @trace decorator to make it possible to log traces for functions that are called by tools. ### Bugs Fixed - [SDK/CLI] Fix single node run doesn't work when consuming sub item of upstream node diff --git a/src/promptflow/promptflow/_sdk/schemas/_run.py b/src/promptflow/promptflow/_sdk/schemas/_run.py index d4963583349..6287c273791 100644 --- a/src/promptflow/promptflow/_sdk/schemas/_run.py +++ b/src/promptflow/promptflow/_sdk/schemas/_run.py @@ -48,6 +48,23 @@ def _validate(self, value): ) +class RemoteFlowStr(fields.Str): + default_error_messages = { + "invalid_path": "Invalid remote flow path. Currently only azureml: is supported", + } + + def _validate(self, value): + # inherited validations like required, allow_none, etc. + super(RemoteFlowStr, self)._validate(value) + + if value is None: + return + if not isinstance(value, str) or not value.startswith("azureml:"): + raise self.make_error( + "invalid_path", + ) + + class RunSchema(YamlFileSchema): """Base schema for all run schemas.""" @@ -60,7 +77,7 @@ class RunSchema(YamlFileSchema): properties = fields.Dict(keys=fields.Str(), values=fields.Str(allow_none=True)) # endregion: common fields - flow = UnionField([LocalPathField(required=True), fields.Str(required=True)]) + flow = UnionField([LocalPathField(required=True), RemoteFlowStr(required=True)]) # inputs field data = UnionField([LocalPathField(), RemotePathStr()]) column_mapping = fields.Dict(keys=fields.Str) diff --git a/src/promptflow/tests/sdk_cli_test/unittests/test_run.py b/src/promptflow/tests/sdk_cli_test/unittests/test_run.py index 6de1203a24a..d4f7da8a93b 100644 --- a/src/promptflow/tests/sdk_cli_test/unittests/test_run.py +++ b/src/promptflow/tests/sdk_cli_test/unittests/test_run.py @@ -94,6 +94,20 @@ def test_dot_env_resolve(self): run = load_run(source=source, params_override=[{"name": run_id}]) assert run.environment_variables == {"FOO": "BAR"} + def test_run_invalid_flow_path(self): + run_id = str(uuid.uuid4()) + source = f"{RUNS_DIR}/bulk_run_invalid_flow_path.yaml" + with pytest.raises(ValidationError) as e: + load_run(source=source, params_override=[{"name": run_id}]) + assert "Can't find directory or file in resolved absolute path:" in str(e.value) + + def test_run_invalid_remote_flow(self): + run_id = str(uuid.uuid4()) + source = f"{RUNS_DIR}/bulk_run_invalid_remote_flow_str.yaml" + with pytest.raises(ValidationError) as e: + load_run(source=source, params_override=[{"name": run_id}]) + assert "Invalid remote flow path. Currently only azureml: is supported" in str(e.value) + def test_data_not_exist_validation_error(self): source = f"{RUNS_DIR}/sample_bulk_run.yaml" with pytest.raises(ValidationError) as e: diff --git a/src/promptflow/tests/test_configs/runs/bulk_run_invalid_flow_path.yaml b/src/promptflow/tests/test_configs/runs/bulk_run_invalid_flow_path.yaml new file mode 100644 index 00000000000..d6d4d3756d1 --- /dev/null +++ b/src/promptflow/tests/test_configs/runs/bulk_run_invalid_flow_path.yaml @@ -0,0 +1,11 @@ +name: flow_run_20230629_101205 +description: sample bulk run +# flow relative to current working directory should not be supported. +flow: tests/test_configs/flows/web_classification +data: ../datas/webClassification1.jsonl +column_mapping: + url: "${data.url}" +variant: ${summarize_text_content.variant_0} + +# run config: env related +environment_variables: env_file diff --git a/src/promptflow/tests/test_configs/runs/bulk_run_invalid_remote_flow_str.yaml b/src/promptflow/tests/test_configs/runs/bulk_run_invalid_remote_flow_str.yaml new file mode 100644 index 00000000000..ed607e14e99 --- /dev/null +++ b/src/promptflow/tests/test_configs/runs/bulk_run_invalid_remote_flow_str.yaml @@ -0,0 +1,11 @@ +name: flow_run_20230629_101205 +description: sample bulk run +# invalid remote flow format should not be supported. +flow: invalid_remote_flow +data: ../datas/webClassification1.jsonl +column_mapping: + url: "${data.url}" +variant: ${summarize_text_content.variant_0} + +# run config: env related +environment_variables: env_file