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

Adding test to check fro PF eval dependencies on private API's #3135

Merged
merged 12 commits into from
May 9, 2024
11 changes: 11 additions & 0 deletions src/promptflow-azure/promptflow/azure/_pf_eval_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ---------------------------------------------------------
singankit marked this conversation as resolved.
Show resolved Hide resolved
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

# This file captures promptflow-evals dependencies on private API of promptflow.
# In case changes are made please reach out to promptflow-evals team to update the dependencies.

def _get_pf_evals_dependencies():
from promptflow.azure.operations._async_run_uploader import AsyncRunUploader

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

import tempfile
from pathlib import Path
from typing import Callable
from unittest.mock import patch
Expand Down Expand Up @@ -260,3 +260,45 @@ def test_upload_flex_flow_run_with_global_azureml(self, pf: PFClient, randstr: C

# check the run is uploaded to cloud.
Local2CloudTestHelper.check_local_to_cloud_run(pf, run)

@pytest.mark.skipif(condition=not pytest.is_live, reason="Bug - 3089145 Replay failed for test 'test_upload_run'")
def test_upload_run_pf_eval_dependencies(
self,
pf: PFClient,
randstr: Callable[[str], str],
):
# This test captures promptflow-evals dependencies on private API of promptflow.
# In case changes are made please reach out to promptflow-evals team to update the dependencies.

name = randstr("batch_run_name_for_upload")
local_pf = Local2CloudTestHelper.get_local_pf(name)
# submit a local batch run.
run = local_pf.run(
flow=f"{FLOWS_DIR}/simple_hello_world",
data=f"{DATAS_DIR}/webClassification3.jsonl",
name=name,
column_mapping={"name": "${data.url}"},
display_name="sdk-cli-test-run-local-to-cloud",
tags={"sdk-cli-test": "true"},
description="test sdk local to cloud",
)
assert run.status == RunStatus.COMPLETED

# check the run is uploaded to cloud
Local2CloudTestHelper.check_local_to_cloud_run(pf, run, check_run_details_in_cloud=True)

from promptflow.azure._pf_eval_dependencies import _get_pf_evals_dependencies
from promptflow._sdk._constants import Local2Cloud

async_uploader = _get_pf_evals_dependencies()._from_run_operations(run, pf.runs)
instance_results = local_pf.runs.get_details(run, all_results=True)

with tempfile.TemporaryDirectory() as temp_dir:
file_name = Local2Cloud.FLOW_INSTANCE_RESULTS_FILE_NAME
local_file = Path(temp_dir) / file_name
instance_results.to_json(local_file, orient="records", lines=True)

# overriding instance_results.jsonl file
remote_file = (f"{Local2Cloud.BLOB_ROOT_PROMPTFLOW}"
f"/{Local2Cloud.BLOB_ARTIFACTS}/{run.name}/{Local2Cloud.FLOW_INSTANCE_RESULTS_FILE_NAME}")
async_run_allowing_running_loop(async_uploader._upload_local_file_to_blob, local_file, remote_file)
16 changes: 16 additions & 0 deletions src/promptflow-devkit/promptflow/_sdk/_pf_evals_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

# This file captures promptflow-evals dependencies on private API of promptflow.
# In case changes are made please reach out to promptflow-evals team to update the dependencies.


def _get_pf_evals_dependencies():
wangchao1230 marked this conversation as resolved.
Show resolved Hide resolved
from promptflow._sdk._constants import LINE_NUMBER
from promptflow._sdk._constants import Local2Cloud

return {
"LINE_NUMBER": LINE_NUMBER,
"Local2Cloud": Local2Cloud
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
from promptflow._sdk._pf_evals_dependencies import _get_pf_evals_dependencies


@pytest.mark.unittest
class TestPromptflowEvalsDependencies:

def test_pf_eval_dependencies(self):
result = _get_pf_evals_dependencies()
assert result["LINE_NUMBER"] == "line_number"
assert result["Local2Cloud"].FLOW_INSTANCE_RESULTS_FILE_NAME == "instance_results.jsonl"
assert result["Local2Cloud"].BLOB_ROOT_PROMPTFLOW == "promptflow"
assert result["Local2Cloud"].BLOB_ARTIFACTS == "PromptFlowArtifacts"