-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Executor] Allow run async tools in executor (#1099)
# Description In current implementation, pf assume all the tools are normal functions/methods. When user provides an async function decorated by @tool, the behavior of pf would be strange. In this PR, we checked the function type of the passed function, then go to a different call stack to ensure async function works well. TODO: Currently if one async tool call another async tool, there would be no traces support. We need to adjust the logic to add such support. # 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. --------- Co-authored-by: Heyi Tang <[email protected]>
- Loading branch information
Showing
7 changed files
with
139 additions
and
27 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
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
12 changes: 12 additions & 0 deletions
12
src/promptflow/tests/test_configs/flows/async_tools/async_passthrough.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,12 @@ | ||
from promptflow import tool | ||
import asyncio | ||
|
||
|
||
@tool | ||
async def passthrough_str_and_wait(input1: str, wait_seconds=3) -> str: | ||
assert isinstance(input1, str), f"input1 should be a string, got {input1}" | ||
print("Wait for", wait_seconds, "seconds") | ||
for i in range(wait_seconds): | ||
print(i) | ||
await asyncio.sleep(1) | ||
return input1 |
36 changes: 36 additions & 0 deletions
36
src/promptflow/tests/test_configs/flows/async_tools/flow.dag.yaml
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,36 @@ | ||
inputs: | ||
input_str: | ||
type: string | ||
default: Hello | ||
outputs: | ||
ouput1: | ||
type: string | ||
reference: ${async_passthrough1.output} | ||
output2: | ||
type: string | ||
reference: ${async_passthrough2.output} | ||
nodes: | ||
- name: async_passthrough | ||
type: python | ||
source: | ||
type: code | ||
path: async_passthrough.py | ||
inputs: | ||
input1: ${inputs.input_str} | ||
wait_seconds: 3 | ||
- name: async_passthrough1 | ||
type: python | ||
source: | ||
type: code | ||
path: async_passthrough.py | ||
inputs: | ||
input1: ${async_passthrough.output} | ||
wait_seconds: 3 | ||
- name: async_passthrough2 | ||
type: python | ||
source: | ||
type: code | ||
path: async_passthrough.py | ||
inputs: | ||
input1: ${async_passthrough.output} | ||
wait_seconds: 3 |