Skip to content

Commit

Permalink
[SDK/CLI] Use local flow folder name instead of display name to creat…
Browse files Browse the repository at this point in the history
…e remote file share flow folder (#1703)

# Description
Fix #1610
Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.
  • Loading branch information
0mza987 authored Jan 10, 2024
1 parent 9bcbdb0 commit 71cc2cf
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 181 deletions.
6 changes: 4 additions & 2 deletions src/promptflow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

### Improvements

- [SDK/CLI] For `pfazure flow create` used by non-msft tenant user, use user name instead of user object id in the remote flow folder path. (e.g. `Users/<user-name>/promptflow`).
- [SDK/CLI] For `pfazure flow create`, when flow has unknown attribute, log warning instead of raising error.
- [SDK/CLI] For `pfazure flow create`:
- If used by non-msft tenant user, use user name instead of user object id in the remote flow folder path. (e.g. `Users/<user-name>/promptflow`).
- When flow has unknown attributes, log warning instead of raising error.
- Use local flow folder name and timestamp as the azure flow file share folder name.
- [SDK/CLI] For `pf/pfazure run create`, when run has unknown attribute, log warning instead of raising error.

## 1.3.0 (2023.12.27)
Expand Down
17 changes: 7 additions & 10 deletions src/promptflow/promptflow/azure/operations/_flow_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def create_or_update(self, flow: Union[str, Path], display_name=None, type=None,
flow, display_name, type, **kwargs
)
# upload to file share
file_share_flow_path = self._resolve_flow_code_and_upload_to_file_share(
flow=azure_flow, flow_display_name=flow_display_name
)
file_share_flow_path = self._resolve_flow_code_and_upload_to_file_share(flow=azure_flow)
if not file_share_flow_path:
raise FlowOperationError(f"File share path should not be empty, got {file_share_flow_path!r}.")

Expand Down Expand Up @@ -188,9 +186,8 @@ def _validate_flow_schema(source, display_name=None, type=None, **kwargs):
flow_dict = flow_entity._dump_for_validation()
return flow_dict

def _resolve_flow_code_and_upload_to_file_share(
self, flow: Flow, flow_display_name: str, ignore_tools_json=False
) -> str:
def _resolve_flow_code_and_upload_to_file_share(self, flow: Flow, ignore_tools_json=False) -> str:
remote_file_share_folder_name = f"{Path(flow.code).name}-{datetime.now().strftime('%m-%d-%Y-%H-%M-%S')}"
ops = OperationOrchestrator(self._all_operations, self._operation_scope, self._operation_config)
file_share_flow_path = ""

Expand Down Expand Up @@ -228,25 +225,25 @@ def _resolve_flow_code_and_upload_to_file_share(

# check if the file share directory exists
logger.debug("Checking if the file share directory exists.")
if storage_client._check_file_share_directory_exist(flow_display_name):
if storage_client._check_file_share_directory_exist(remote_file_share_folder_name):
raise FlowOperationError(
f"Remote flow folder {flow_display_name!r} already exists under "
f"Remote flow folder {remote_file_share_folder_name!r} already exists under "
f"'{storage_client.file_share_prefix}'. Please change the flow folder name and try again."
)

try:
logger.info("Uploading flow directory to file share.")
storage_client.upload_dir(
source=code.path,
dest=flow_display_name,
dest=remote_file_share_folder_name,
msg="test",
ignore_file=code._ignore_file,
show_progress=False,
)
except Exception as e:
raise FlowOperationError(f"Failed to upload flow to file share due to: {str(e)}.") from e

file_share_flow_path = f"{storage_client.file_share_prefix}/{flow_display_name}"
file_share_flow_path = f"{storage_client.file_share_prefix}/{remote_file_share_folder_name}"
logger.info(f"Successfully uploaded flow to file share path {file_share_flow_path!r}.")
return file_share_flow_path

Expand Down
20 changes: 10 additions & 10 deletions src/promptflow/tests/sdk_cli_azure_test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ def flow_serving_client_remote_connection(mocker: MockerFixture, remote_workspac


@pytest.fixture
def flow_serving_client_with_prt_config_env(mocker: MockerFixture, subscription_id, resource_group_name, workspace_name): # noqa: E501
def flow_serving_client_with_prt_config_env(
mocker: MockerFixture, subscription_id, resource_group_name, workspace_name
): # noqa: E501
connections = {
"PRT_CONFIG_OVERRIDE": f"deployment.subscription_id={subscription_id},"
f"deployment.resource_group={resource_group_name},"
f"deployment.workspace_name={workspace_name},"
"app.port=8088",
"PRT_CONFIG_OVERRIDE": f"deployment.subscription_id={subscription_id},"
f"deployment.resource_group={resource_group_name},"
f"deployment.workspace_name={workspace_name},"
"app.port=8088",
}
return create_serving_client_with_connections("basic-with-connection", mocker, connections)

Expand All @@ -191,7 +193,7 @@ def flow_serving_client_with_aml_resource_id_env(mocker: MockerFixture, remote_w
def serving_client_with_connection_name_override(mocker: MockerFixture, remote_workspace_resource_id):
connections = {
"aoai_connection": "azure_open_ai_connection",
"PROMPTFLOW_CONNECTION_PROVIDER": remote_workspace_resource_id
"PROMPTFLOW_CONNECTION_PROVIDER": remote_workspace_resource_id,
}
return create_serving_client_with_connections("llm_connection_override", mocker, connections)

Expand All @@ -209,9 +211,7 @@ def serving_client_with_connection_data_override(mocker: MockerFixture, remote_w
return create_serving_client_with_connections(model_name, mocker, connections)


def create_serving_client_with_connections(
model_name, mocker: MockerFixture, connections: dict = {}
):
def create_serving_client_with_connections(model_name, mocker: MockerFixture, connections: dict = {}):
from promptflow._sdk._serving.app import create_app as create_serving_app

model_path = (Path(MODEL_ROOT) / model_name).resolve().absolute().as_posix()
Expand Down Expand Up @@ -368,7 +368,7 @@ def created_flow(pf: PFClient, randstr: Callable[[str], str]) -> Flow:
assert result.display_name == flow_display_name
assert result.type == FlowType.STANDARD
assert result.tags == tags
assert result.path.endswith(f"/promptflow/{flow_display_name}/flow.dag.yaml")
assert result.path.endswith("flow.dag.yaml")

yield result

Expand Down
Loading

0 comments on commit 71cc2cf

Please sign in to comment.