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

support both yaml and yml postfix #2750

Merged
merged 6 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
19 changes: 13 additions & 6 deletions src/promptflow-core/promptflow/_utils/flow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
import hashlib
import itertools
import json
import os
import re
Expand Down Expand Up @@ -87,13 +88,19 @@ def resolve_flow_path(

if flow_path.is_dir():
flow_folder = flow_path
dag_file_exist = (flow_folder / FLOW_DAG_YAML).is_file()
flex_file_exist = (flow_folder / FLOW_FLEX_YAML).is_file()
flow_file = FLOW_FLEX_YAML if flex_file_exist else FLOW_DAG_YAML
if dag_file_exist and flex_file_exist:
flow_file = FLOW_DAG_YAML
flow_file_list = []
for flow_name, suffix in itertools.product([FLOW_DAG_YAML, FLOW_FLEX_YAML], [".yaml", ".yml"]):
flow_file_name = flow_name.replace(".yaml", suffix)
if (flow_folder / flow_file_name).is_file():
Fixed Show fixed Hide fixed
Dismissed Show dismissed Hide dismissed
flow_file_list.append(flow_file_name)

if len(flow_file_list) == 1:
flow_file = flow_file_list[0]
elif len(flow_file_list) > 1:
raise ValidationException(
f"Both {FLOW_DAG_YAML} and {FLOW_FLEX_YAML} exist in {flow_path}. "
f"Please specify a file or remove the extra YAML.",
f"Multiple files {', '.join(flow_file_list)} exist in {flow_path}. "
f"Please specify a file or remove the extra YAML file.",
privacy_info=[str(flow_path)],
)
elif flow_path.is_file() or flow_path.suffix.lower() in FLOW_FILE_SUFFIX:
Expand Down
6 changes: 6 additions & 0 deletions src/promptflow/tests/sdk_cli_test/e2etests/test_flow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ def test_eager_flow_test_with_yaml(self):
result = _client._flows._test(flow=flow_path, inputs={"input_val": "val1"})
assert result.run_info.status.value == "Completed"

def test_eager_flow_test_with_yml(self):
clear_module_cache("entry")
flow_path = Path(f"{EAGER_FLOWS_DIR}/simple_with_yml/").absolute()
result = _client._flows._test(flow=flow_path, inputs={"input_val": "val1"})
assert result.run_info.status.value == "Completed"

def test_eager_flow_test_with_primitive_output(self):
clear_module_cache("entry")
flow_path = Path(f"{EAGER_FLOWS_DIR}/primitive_output/").absolute()
Expand Down
8 changes: 7 additions & 1 deletion src/promptflow/tests/sdk_cli_test/unittests/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ def test_multiple_flow_load(self):
with pytest.raises(ValidationException) as e:
load_flow(EAGER_FLOWS_DIR / "multiple_flow_yaml")

assert "Both flow.dag.yaml and flow.flex.yaml exist in " in str(e.value)
assert "Multiple files flow.dag.yaml, flow.flex.yaml exist in " in str(e.value)

def test_multiple_flex_load(self):
with pytest.raises(ValidationException) as e:
load_flow(EAGER_FLOWS_DIR / "multiple_flex_yaml")

assert "Multiple files flow.flex.yaml, flow.flex.yml exist in " in str(e.value)

def test_specify_flow_load(self):
load_flow(EAGER_FLOWS_DIR / "multiple_flow_yaml" / "flow.dag.yaml")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
entry: entry:my_flow

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

def my_flow(input_val: str = "gpt") -> str:
"""Simple flow without yaml."""
return f"Hello world! {input_val}"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
entry: entry:my_flow
Loading