-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: tool meta generation perf optimization (#1250)
This pull request includes various changes to improve the functionality and structure of the codebase. The most important changes include adding a new test method to test the behavior of a specific method, updating a method to use a new type and adding a new parameter, and adding a new Python file with a function for parsing JSON. Perf change: - e2e time for pfutil command: ~10.10s => 5.74s (cut for 44%) - Measure-Command { C:\Users\yangtongxu\AppData\Local\miniconda3\envs\py39_promptflow\python.exe c:\Users\yangtongxu\.vscode\extensions\prompt-flow.prompt-flow-1.5.0\pfutil\pfutil.py tool -f hello.py -wd c:\Users\yangtongxu\code\promptflow\examples\flows\standard\basic-with-connection -o c:\Users\yangtongxu\code\promptflow\examples\flows\standard\basic-with-connection\.promptflow\flow.tools.json } Main code changes: * <a href="diffhunk://#diff-47208ac35b30920275fcd5e55d662647ef360129359bdc77fddd2a2157b6f47eR716-R777">`src/promptflow/promptflow/_sdk/_utils.py`</a>: Various changes to the `_utils.py` file, including adding a new function, updating import statements, improving print statements, removing unused imports, and adding new parameters to existing functions. <a href="diffhunk://#diff-47208ac35b30920275fcd5e55d662647ef360129359bdc77fddd2a2157b6f47eR716-R777">[1]</a> <a href="diffhunk://#diff-47208ac35b30920275fcd5e55d662647ef360129359bdc77fddd2a2157b6f47eR587-R601">[2]</a> <a href="diffhunk://#diff-47208ac35b30920275fcd5e55d662647ef360129359bdc77fddd2a2157b6f47eL13-R21">[3]</a> <a href="diffhunk://#diff-47208ac35b30920275fcd5e55d662647ef360129359bdc77fddd2a2157b6f47eL541-R540">[4]</a> <a href="diffhunk://#diff-47208ac35b30920275fcd5e55d662647ef360129359bdc77fddd2a2157b6f47eL4">[5]</a> <a href="diffhunk://#diff-47208ac35b30920275fcd5e55d662647ef360129359bdc77fddd2a2157b6f47eR612-R623">[6]</a> <a href="diffhunk://#diff-47208ac35b30920275fcd5e55d662647ef360129359bdc77fddd2a2157b6f47eL712-R831">[7]</a> * <a href="diffhunk://#diff-afdd40a5d0519512dcf9be48bd46c4caaa2291b808687de77896989af63f47e4L666-R676">`src/promptflow/promptflow/_sdk/operations/_flow_operations.py`</a>: Updating the `_generate_tools_meta` method to use the `ProtectedFlow` type, adding a new parameter `timeout` to the method, updating import statements, renaming and specifying the type of the `flow` parameter in the `validate` function, and adding a new decorator and default parameter to the `_generate_tools_meta` function. <a href="diffhunk://#diff-afdd40a5d0519512dcf9be48bd46c4caaa2291b808687de77896989af63f47e4L666-R676">[1]</a> <a href="diffhunk://#diff-afdd40a5d0519512dcf9be48bd46c4caaa2291b808687de77896989af63f47e4R30">[2]</a> <a href="diffhunk://#diff-afdd40a5d0519512dcf9be48bd46c4caaa2291b808687de77896989af63f47e4R687">[3]</a> <a href="diffhunk://#diff-afdd40a5d0519512dcf9be48bd46c4caaa2291b808687de77896989af63f47e4L17-R17">[4]</a> <a href="diffhunk://#diff-afdd40a5d0519512dcf9be48bd46c4caaa2291b808687de77896989af63f47e4L612-R624">[5]</a> <a href="diffhunk://#diff-afdd40a5d0519512dcf9be48bd46c4caaa2291b808687de77896989af63f47e4L637-R654">[6]</a> Testing improvements: * <a href="diffhunk://#diff-39113ef42bdaeb63710e4eaf72fec3120025601166fdfa766341820991ddf8a4R409-R424">`src/promptflow/tests/sdk_cli_test/e2etests/test_flow_local_operations.py`</a>: Added a new test method `test_flow_generate_tools_meta_timeout` to test the behavior of the `_generate_tools_meta` method when a timeout occurs. Configuration changes: * <a href="diffhunk://#diff-2db6949a5342d919228d12432f041bf65a32c0b39e293436513d98f312393ee8L140">`src/promptflow/tests/test_configs/flows/web_classification_invalid/flow.dag.yaml`</a>: Removed the line `- ../external_files/convert_to_dict.py` from the `additional_includes` section in `web_classification_invalid/flow.dag.yaml`. New file addition: * <a href="diffhunk://#diff-c799b04d98e08a0859bf37459811d6d30dbef1222236db6940916834b67a7e7eR1-R17">`src/promptflow/tests/test_configs/flows/web_classification_invalid/convert_to_dict.py`</a>: Added a new Python file `convert_to_dict.py` in the `web_classification_invalid` directory, which contains a function `convert_to_dict` that parses a string as JSON and returns the parsed JSON object or a default dictionary if parsing fails.# Description Please add an informative description that covers that changes made by the pull request and link all relevant issues. # All Promptflow Contribution checklist: - [x] **The pull request does not introduce [breaking changes].** - [ ] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [x] **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 - [x] Title of the pull request is clear and informative. - [x] 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 - [x] Pull request includes test coverage for the included changes.
- Loading branch information
Showing
5 changed files
with
167 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/promptflow/tests/test_configs/flows/web_classification_invalid/convert_to_dict.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import json | ||
import time | ||
|
||
from promptflow import tool | ||
|
||
|
||
# use this to test the timeout | ||
time.sleep(2) | ||
|
||
|
||
@tool | ||
def convert_to_dict(input_str: str): | ||
try: | ||
return json.loads(input_str) | ||
except Exception as e: | ||
print("input is not valid, error: {}".format(e)) | ||
return {"category": "None", "evidence": "None"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters