Skip to content

Commit

Permalink
[Recording] Fix documentation for recording. (microsoft#2931)
Browse files Browse the repository at this point in the history
# Description

Fix documentation for recording.

# 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
crazygao authored Apr 24, 2024
1 parent 8103545 commit 3b961d3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 18 deletions.
55 changes: 43 additions & 12 deletions docs/dev/dev_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

## Set up process

- First create a new [conda](https://conda.io/projects/conda/en/latest/user-guide/getting-started.html) environment. Please specify python version as 3.9.
`conda create -n <env_name> python=3.9`.
- Activate the env you created.
- In root folder, run `python scripts/dev-setup/main.py` to install the packages and dependencies; if you are using Visual Studio Code, it is recommended to add `--vscode` (which is `python scripts/dev-setup/main.py --vscode`) to enable VS Code to recognize the packages.
Select either Conda or Poetry to set up your development environment.

1. Conda environment setup
- First create a new [conda](https://conda.io/projects/conda/en/latest/user-guide/getting-started.html) environment. Please specify python version as 3.8/3.9/3.10/3.11.
`conda create -n <env_name> python=3.9`.
- Activate the env you created.
- In root folder, run `python scripts/dev-setup/main.py` to install the packages and dependencies; if you are using Visual Studio Code, it is recommended to add `--vscode` (which is `python scripts/dev-setup/main.py --vscode`) to enable VS Code to recognize the packages.

2. Poetry environment setup
- Install [poetry](https://python-poetry.org/docs/). Please specify python version as 3.8/3.9/3.10/3.11.
- Each folder under [src](../../src/) (except the promptflow folder) is a separate package, so you need to install the dependencies for each package.
- `poetry install -C promptflow-core -E <extra> --with dev,test`
- `poetry install -C promptflow-devkit -E <extra> --with dev,test`
- `poetry install -C promptflow-azure -E <extra> --with dev,test`

## How to run tests

Expand All @@ -21,11 +31,19 @@ After above setup process is finished. You can use `pytest` command to run test,

### Run tests via command

- Run all tests under a folder: `pytest src/promptflow/tests -v`
- Run a single test: ` pytest src/promptflow/tests/promptflow_test/e2etests/test_executor.py::TestExecutor::test_executor_basic_flow -v`
1. Conda environment
- Run all tests under a folder: `pytest src/promptflow/tests -v`, `pytest src/promptflow-devkit/tests -v`
- Run a single test: ` pytest src/promptflow/tests/promptflow_test/e2etests/test_executor.py::TestExecutor::test_executor_basic_flow -v`

2. Poetry environment: there is limitation for running tests in src/promptflow folder, you can only run tests under other package folders.
- for example: under the target folder `promptflow-devkit`, you can run `poetry run pytest tests/sdk_cli_test -v`

### Run tests in VSCode

---

#### Conda environment

1. Set up your python interperter

- Open the Command Palette (Ctrl+Shift+P) and select `Python: Select Interpreter`.
Expand Down Expand Up @@ -76,6 +94,16 @@ Open `.vscode/settings.json`, write `"--ignore=src/promptflow/tests/sdk_cli_azur

![img2](../media/dev_setup/set_up_pycharm_2.png)

---

#### Poetry environment

VSCode could pick up the correct environment automatically if you open vscode/pycharm under the package folders.

There are some limitations currently, intellisense may not work properly in poetry environment.

PyCharm behaves differently from VSCode, it will automatically picks up the correct environment.

## How to write docstring

A clear and consistent API documentation is crucial for the usability and maintainability of our codebase. Please refer to [API Documentation Guidelines](./documentation_guidelines.md) to learn how to write docstring when developing the project.
Expand All @@ -90,11 +118,11 @@ A clear and consistent API documentation is crucial for the usability and mainta
- Flow run: `src/promptflow/tests/sdk_cli_test/e2etests/`
- Flow run in azure: `src/promptflow/tests/sdk_cli_azure_test/e2etests/`
- Test file name and the test case name all start with `test_`.
- A basic test example, see [test_connection.py](../../src/promptflow/tests/sdk_cli_test/e2etests/test_connection.py).
- A basic test example, see [test_connection.py](../../src/promptflow-devkit/tests/sdk_cli_test/e2etests/test_connection.py).

### Test structure

In the future, tests will under corresponding source folder, and test_configs are shared among different test folders:
Tests are under corresponding source folder, and test_configs are shared among different test folders:

- src/promptflow/
- test_configs/
Expand All @@ -117,11 +145,14 @@ In the future, tests will under corresponding source folder, and test_configs ar
- unittests/
- src/promptflow-devkit/
- tests/
- executable/ # Test with promptflow-devkit[executable] installed.
- sdk_cli_tests/
- e2etests/
- unittests/
- src/promptflow-azure/
- tests/ # promptflow-azure doesn't have extra-requires, so all tests are under the test folder.
- e2etests/
- unittests/
- tests/
- sdk_cli_azure_test/
- e2etests/
- unittests/

Principal #1: Put the tests in the same folder as the code they are testing, to ensure code can work within minor environment requirements.

Expand Down
18 changes: 12 additions & 6 deletions docs/dev/replay-e2e-test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Replay end-to-end tests

* This document introduces replay tests for those located in [sdk_cli_azure_test](../../src/promptflow/tests/sdk_cli_azure_test/e2etests/) and [sdk_cli_test](../../src/promptflow/tests/sdk_cli_test/e2etests/).
* This document introduces replay tests for those located in [sdk_cli_azure_test](../../src/promptflow-azure/tests/sdk_cli_azure_test/e2etests/) and [sdk_cli_test](../../src/promptflow-devkit/tests/sdk_cli_test/e2etests/).
* The primary purpose of replay tests is to avoid the need for credentials, Azure workspaces, OpenAI tokens, and to directly test prompt flow behavior.
* Although there are different techniques behind recording/replaying, there are some common steps to run the tests in replay mode.
* The key handle of replay tests is the environment variable `PROMPT_FLOW_TEST_MODE`.
Expand All @@ -22,17 +22,23 @@ There are 3 representative values of the environment variable `PROMPT_FLOW_TEST_
- `record`: Tests run against the real backend, and network traffic will be sanitized (filter sensitive and unnecessary requests/responses) and recorded to local files (recordings).
- `replay`: There is no real network traffic between SDK/CLI and the backend, tests run against local recordings.

## Supported modules
* [promptflow-devkit](../../src/promptflow-devkit)
* [promptflow-azure](../../src/promptflow-azure)

## Update test recordings

To record a test, don’t forget to clone the full repo and set up the proper test environment following [dev_setup.md](./dev_setup.md):
1. Prepare some data.
1. Ensure you have installed dev version of promptflow-recording package.
* If it is not installed, run `pip install -e src/promptflow-recording` in the root directory of the repo.
2. Prepare some data.
* If you have changed/affected tests in __sdk_cli_test__: Copy or rename the file [dev-connections.json.example](../../src/promptflow/dev-connections.json.example) to `connections.json` in the same folder.
* If you have changed/affected tests in __sdk_cli_azure_test__: prepare your Azure ML workspace, make sure your Azure CLI logged in, and set the environment variable `PROMPT_FLOW_SUBSCRIPTION_ID`, `PROMPT_FLOW_RESOURCE_GROUP_NAME`, `PROMPT_FLOW_WORKSPACE_NAME` and `PROMPT_FLOW_RUNTIME_NAME` (if needed) pointing to your workspace.
2. Record the test.
3. Record the test.
* Specify the environment variable `PROMPT_FLOW_TEST_MODE` to `'record'`. If you have a `.env` file, we recommend specifying it there. Here is an example [.env file](../../src/promptflow/.env.example). Then, just run the test that you want to record.
3. Once the test completed.
* If you have changed/affected tests in __sdk_cli_azure_test__: There should be one new YAML file located in `src/promptflow/tests/test_configs/recordings/`, containing the network traffic of the test.
* If you have changed/affected tests in __sdk_cli_test__: There may be changes in the folder `src/promptflow/tests/test_configs/node_recordings/`. Don’t worry if there are no changes, because similar LLM calls may have been recorded before.
4. Once the test completed.
* If you have changed/affected tests in __sdk_cli_azure_test__: There should be one new YAML file located in [Azure recording folder](../../src/promptflow-recording/recordings/azure/), containing the network traffic of the test.
* If you have changed/affected tests in __sdk_cli_test__: There may be changes in the folder [Local recording folder](../../src/promptflow-recording/recordings/local/). Don’t worry if there are no changes, because similar LLM calls may have been recorded before.

## Techniques behind replay test

Expand Down

0 comments on commit 3b961d3

Please sign in to comment.