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

PF Recording/Replaying part for sdk_cli #719

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
523c02e
TEMP PASS
crazygao Sep 28, 2023
aa959ee
Current Fix
crazygao Oct 11, 2023
37229ad
Fix
crazygao Oct 13, 2023
9973fa0
Remove ununsed items
crazygao Oct 13, 2023
d311941
Fix
crazygao Oct 13, 2023
e52fc0e
Merge branch 'main' into yigao/recording_draft
crazygao Oct 13, 2023
dc4d181
Fix
crazygao Oct 16, 2023
26b07a7
Fix
crazygao Oct 16, 2023
48e6d07
Fix Connection Override
crazygao Oct 16, 2023
632dd31
Commit
crazygao Oct 17, 2023
6d5c03f
Fix
crazygao Oct 17, 2023
d5d608a
Fix
crazygao Oct 17, 2023
9f0eeee
Fix
crazygao Oct 18, 2023
f3e6cd9
Merge branch 'main' into yigao/recording_draft
crazygao Oct 18, 2023
f74a03b
Fix
crazygao Oct 20, 2023
5131bd7
Merge branch 'main' into yigao/recording_draft
crazygao Oct 20, 2023
48b5355
Fix
crazygao Oct 20, 2023
57d10c4
Fix
crazygao Oct 20, 2023
bdf4981
Fix Names
crazygao Oct 20, 2023
6d49afc
Fix pipeline
crazygao Oct 20, 2023
215f57e
Fix Upload
crazygao Oct 20, 2023
ca5081b
Fix upload
crazygao Oct 20, 2023
930bcb8
Fix
crazygao Oct 20, 2023
f5ef438
get items
crazygao Oct 20, 2023
da1f5a0
Fix
crazygao Oct 20, 2023
13e53aa
Fix Mode
crazygao Oct 20, 2023
f2101fd
Fix
crazygao Oct 23, 2023
aaaadb9
Merge branch 'main' into yigao/recording_draft
crazygao Oct 23, 2023
79ff7b6
Fix
crazygao Oct 23, 2023
c8cf75a
Merge branch 'main' into yigao/recording_draft
crazygao Oct 23, 2023
6673310
Fix Comments
crazygao Oct 23, 2023
f38a89f
Fix nits
crazygao Oct 23, 2023
8a6b456
Fix tests
crazygao Oct 23, 2023
f118d7b
Merge branch 'main' into yigao/recording_draft
crazygao Oct 23, 2023
38a9206
Fix test
crazygao Oct 23, 2023
6f9c0a1
fix nits
crazygao Oct 23, 2023
fa10237
Fix
crazygao Oct 23, 2023
ad4a4e3
Fix
crazygao Oct 24, 2023
55761ba
Fix
crazygao Oct 24, 2023
b40ddc8
Fix
crazygao Oct 24, 2023
2b69b18
Fix
crazygao Oct 24, 2023
b6f75ec
Fix
crazygao Oct 24, 2023
d682da9
Fix
crazygao Oct 24, 2023
9e918e5
refactor
crazygao Oct 25, 2023
a92fd7c
Merge branch 'main' into yigao/recording_draft
crazygao Oct 25, 2023
9fff444
no changing production
crazygao Oct 25, 2023
b808a53
refactor
crazygao Oct 26, 2023
dab04b5
Merge branch 'main' into yigao/recording_draft
crazygao Oct 26, 2023
73fe306
Mark instable in replay mode
crazygao Oct 26, 2023
f0a3162
Mark Instable, 24 tests in total
crazygao Oct 26, 2023
45bd5b7
Fix
crazygao Oct 26, 2023
471a966
Fix
crazygao Oct 27, 2023
9fa75df
Merge branch 'main' into yigao/recording_draft
crazygao Oct 27, 2023
cb64c6c
Fix
crazygao Oct 27, 2023
14e4b95
Fix
crazygao Oct 27, 2023
3456ed6
Fix Comments
crazygao Oct 30, 2023
2086f19
Merge branch 'main' into yigao/recording_draft
crazygao Oct 30, 2023
5fb93e0
Fix error
crazygao Oct 30, 2023
4ff7d8d
Fix Comments
crazygao Oct 30, 2023
3a36c7e
Fix nit
crazygao Oct 30, 2023
d3b4c4a
Merge branch 'main' into yigao/recording_draft
crazygao Oct 30, 2023
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
6 changes: 3 additions & 3 deletions .github/actions/step_sdk_setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: step_sdk_setup_win
name: step_sdk_setup
inputs:
scriptPath:
required: false
Expand Down Expand Up @@ -30,7 +30,7 @@ runs:
if: inputs.setupType == 'promptflow_with_extra'
shell: pwsh
run: |
Set-PSDebug -Trace 2
Set-PSDebug -Trace 1
pip install -r ./dev_requirements.txt
echo "########### pip list (Before) ###########"
pip list
Expand All @@ -44,7 +44,7 @@ runs:
if: inputs.setupType == 'promptflow_dev'
shell: pwsh
run: |
Set-PSDebug -Trace 2
Set-PSDebug -Trace 1
pip install -r ./dev_requirements.txt
python ./setup.py bdist_wheel
$package = Get-ChildItem ./dist | ? { $_.Name.Contains('.whl')}
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/promptflow-replay-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: promptflow-replay-test
on:
pull_request:
paths:
- src/promptflow/**
- scripts/**
- .github/workflows/promptflow-replay-test.yml
workflow_dispatch:
env:
testWorkingDirectory: ${{ github.workspace }}/src/promptflow
PYTHONPATH: ${{ github.workspace }}/src/promptflow
IS_IN_CI_PIPELINE: "true"
PF_RECORDING_MODE: "replay"
crazygao marked this conversation as resolved.
Show resolved Hide resolved
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Display and Set Environment Variables
run: |
export pyVersion="3.9";
env | sort >> $GITHUB_OUTPUT
id: display_env
shell: bash -el {0}
- name: Python Setup - ${{ matrix.os }} - Python Version ${{ steps.display_env.outputs.pyVersion }}
uses: "./.github/actions/step_create_python_environment"
with:
pythonVersion: ${{ steps.display_env.outputs.pyVersion }}
- name: Build wheel
uses: "./.github/actions/step_sdk_setup"
with:
setupType: promptflow_with_extra
scriptPath: ${{ env.testWorkingDirectory }}
- name: Upload Wheel
if: always()
uses: actions/upload-artifact@v3
with:
name: wheel
path: |
${{ github.workspace }}/src/promptflow/dist/*.whl
${{ github.workspace }}/src/promptflow-tools/dist/*.whl
sdk_cli_tests:
needs: build
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Display and Set Environment Variables
run: |
export pyVersion="3.9";
env | sort >> $GITHUB_OUTPUT
id: display_env
shell: bash -el {0}
- name: Python Setup - ${{ matrix.os }} - Python Version ${{ steps.display_env.outputs.pyVersion }}
uses: "./.github/actions/step_create_python_environment"
with:
pythonVersion: ${{ steps.display_env.outputs.pyVersion }}
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: wheel
path: artifacts
- name: Install wheel
shell: pwsh
working-directory: artifacts
run: |
Set-PSDebug -Trace 1
pip install -r ${{ github.workspace }}/src/promptflow/dev_requirements.txt
gci ./promptflow -Recurse | % {if ($_.Name.Contains('.whl')) {python -m pip install "$($_.FullName)[azure]"}}
gci ./promptflow-tools -Recurse | % {if ($_.Name.Contains('.whl')) {python -m pip install $_.FullName}}
pip freeze
- name: Run Test
shell: pwsh
working-directory: ${{ env.testWorkingDirectory }}
run: |
gci env:* | sort-object name
$env:PYTHONPATH=""
echo '{}' > ${{ github.workspace }}/src/promptflow/connections.json
python "../../scripts/building/run_coverage_tests.py" `
-p promptflow `
-t ${{ github.workspace }}/src/promptflow/tests/sdk_cli_test `
-l eastus `
-m "unittest or e2etest" `
--coverage-config ${{ github.workspace }}/src/promptflow/tests/sdk_cli_test/.coveragerc

4 changes: 2 additions & 2 deletions scripts/building/run_coverage_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
help="Pytest marker to identify the tests to run",
default="all",
)
parser.add_argument("-n", help="Pytest number of process to run the tests", default="15")
parser.add_argument("-n", help="Pytest number of process to run the tests", default="auto")
crazygao marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument(
"--model-name",
help="The model file name to run the tests",
Expand Down Expand Up @@ -72,7 +72,7 @@
"-n",
args.n,
"--dist",
crazygao marked this conversation as resolved.
Show resolved Hide resolved
"loadgroup",
"loadfile",
"--log-level=info",
"--log-format=%(asctime)s %(levelname)s %(message)s",
"--log-date-format=[%Y-%m-%d %H:%M:%S]",
Expand Down
1 change: 0 additions & 1 deletion src/promptflow/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pytest-nunit
pytest
pydash
wheel
azure-mgmt-storage==21.0.0
# Note: This is possibly-insecure, do not add this to setup.
keyrings.alt

Expand Down
6 changes: 3 additions & 3 deletions src/promptflow/promptflow/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
ToolsManager,
builtins,
collect_package_tools,
gen_dynamic_list,
gen_tool_by_source,
register_apis,
register_builtins,
register_connections,
gen_dynamic_list,
)
from promptflow._core.tracer import Tracer
from promptflow._sdk._constants import LOCAL_MGMT_DB_PATH
Expand Down Expand Up @@ -83,6 +83,7 @@
logger,
update_log_path,
)
from promptflow._utils.multimedia_utils import _create_image_from_file, is_multimedia_dict
from promptflow._utils.utils import (
AttrDict,
camel_to_snake,
Expand All @@ -96,12 +97,11 @@
from promptflow.executor._errors import InputNotFound
from promptflow.executor._tool_invoker import DefaultToolInvoker
from promptflow.storage._cache_storage import LocalCacheStorage
from promptflow.storage._run_storage import DefaultRunStorage
from promptflow.storage._sqlite_client import (
INDEX,
PRIMARY_KEY,
DuplicatedPrimaryKeyException,
NotFoundException,
SqliteClient,
)
from promptflow.storage._run_storage import DefaultRunStorage
from promptflow._utils.multimedia_utils import is_multimedia_dict, _create_image_from_file
1 change: 0 additions & 1 deletion src/promptflow/promptflow/_sdk/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ def _gen_dynamic_list(function_config: Dict) -> List:
from promptflow._cli._utils import get_workspace_triad_from_local

workspace_triad = get_workspace_triad_from_local()

crazygao marked this conversation as resolved.
Show resolved Hide resolved
if workspace_triad.subscription_id and workspace_triad.resource_group_name and workspace_triad.workspace_name:
return gen_dynamic_list(func_path, func_kwargs, workspace_triad._asdict())
# if no workspace triple available, just skip.
Expand Down
6 changes: 6 additions & 0 deletions src/promptflow/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from _pytest.monkeypatch import MonkeyPatch
from filelock import FileLock
from pytest_mock import MockerFixture
from sdk_cli_test.recording_utilities import is_replaying

from promptflow._cli._utils import AzureMLWorkspaceTriad
from promptflow._constants import PROMPTFLOW_CONNECTIONS
Expand Down Expand Up @@ -68,6 +69,11 @@ def env_with_secrets_config_file():

@pytest.fixture
def azure_open_ai_connection() -> AzureOpenAIConnection:
if is_replaying():
return AzureOpenAIConnection(
api_key="dummy_key",
api_base="dummy_base",
)
return ConnectionManager().get("azure_open_ai_connection")


Expand Down
52 changes: 51 additions & 1 deletion src/promptflow/tests/sdk_cli_test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@
from promptflow._telemetry.telemetry import TELEMETRY_ENABLED
from promptflow._utils.utils import environment_variable_overwrite

from .recording_utilities import (
is_recording,
is_replaying,
mock_bulkresult_get_openai_metrics,
mock_flowoperations_test,
mock_get_local_connections_from_executable,
mock_persist_node_run,
mock_toolresolver_resolve_tool_by_node,
mock_update_run_func,
)

PROMOTFLOW_ROOT = Path(__file__) / "../../.."
RUNTIME_TEST_CONFIGS_ROOT = Path(PROMOTFLOW_ROOT / "tests/test_configs/runtime")
RECORDINGS_TEST_CONFIGS_ROOT = Path(PROMOTFLOW_ROOT / "tests/test_configs/node_recordings").resolve()
CONNECTION_FILE = (PROMOTFLOW_ROOT / "connections.json").resolve().absolute().as_posix()
MODEL_ROOT = Path(PROMOTFLOW_ROOT / "tests/test_configs/flows")

Expand Down Expand Up @@ -70,7 +82,7 @@ def local_custom_connection(local_client, azure_open_ai_connection):
@pytest.fixture
def setup_local_connection(local_client):
global _connection_setup
if _connection_setup:
if is_replaying():
return
connection_dict = json.loads(open(CONNECTION_FILE, "r").read())
for name, _dct in connection_dict.items():
Expand All @@ -80,6 +92,15 @@ def setup_local_connection(local_client):
_connection_setup = True


@pytest.fixture
def remove_local_connection(local_client):
crazygao marked this conversation as resolved.
Show resolved Hide resolved
local_client.connections.delete("azure_open_ai_connection")
local_client.connections.delete("serp_connection")
local_client.connections.delete("custom_connection")
local_client.connections.delete("gpt2_connection")
local_client.connections.delete("open_ai_connection")


@pytest.fixture
def flow_serving_client(mocker: MockerFixture):
model_path = (Path(MODEL_ROOT) / "basic-with-connection").resolve().absolute().as_posix()
Expand Down Expand Up @@ -127,3 +148,32 @@ def serving_client_llm_chat(mocker: MockerFixture):
@pytest.fixture
def serving_client_python_stream_tools(mocker: MockerFixture):
return create_client_by_model("python_stream_tools", mocker)


@pytest.fixture
def mock_for_recordings(request: pytest.FixtureRequest, mocker: MockerFixture) -> None:
crazygao marked this conversation as resolved.
Show resolved Hide resolved
crazygao marked this conversation as resolved.
Show resolved Hide resolved
recording_folder: Path = RECORDINGS_TEST_CONFIGS_ROOT / request.cls.__name__
crazygao marked this conversation as resolved.
Show resolved Hide resolved
if is_recording():
recording_folder.mkdir(parents=True, exist_ok=True)
mocker.patch(
"promptflow._sdk.operations._local_storage_operations.LocalStorageOperations.persist_node_run",
mock_persist_node_run(recording_folder),
)
mocker.patch(
"promptflow._sdk.operations._flow_operations.FlowOperations._test",
mock_flowoperations_test(recording_folder),
)

if is_replaying():
mocker.patch(
"promptflow._core.run_tracker.RunTracker._update_flow_run_info_with_node_runs", mock_update_run_func
)
mocker.patch("promptflow.executor._result.BulkResult.get_openai_metrics", mock_bulkresult_get_openai_metrics)

mocker.patch(
"promptflow.executor._tool_resolver.ToolResolver.resolve_tool_by_node",
mock_toolresolver_resolve_tool_by_node(recording_folder),
)
mocker.patch(
"promptflow._sdk._utils.get_local_connections_from_executable", mock_get_local_connections_from_executable
)
Loading
Loading