-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add input/output/error to root level api_calls (#1995)
# Description Add input/output to root level api_calls. Note that this is a short-term solution which uses inelegant way to generate flow level input/output/error. Long-term solution will be included in the next generation of trace. Normal case: ![image](https://github.com/microsoft/promptflow/assets/10575286/9c0d4b10-37fe-4dfb-befe-d3751d3978d8) Image case: ![image](https://github.com/microsoft/promptflow/assets/10575286/409b6f14-ef08-4fec-8ee6-c33515dd824a) Generator case: ![image](https://github.com/microsoft/promptflow/assets/10575286/f45eff5b-da18-4fe4-8b9b-3ac0e3e33ca8) # 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
1 parent
c8ea951
commit 2f6f724
Showing
5 changed files
with
87 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# --------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# --------------------------------------------------------- | ||
from copy import deepcopy | ||
|
||
from promptflow._core.generator_proxy import GeneratorProxy | ||
|
||
|
||
def _deep_copy_and_extract_items_from_generator_proxy(value: object) -> object: | ||
"""Deep copy value, and if there is a GeneratorProxy, deepcopy the items from it. | ||
:param value: Any object. | ||
:type value: Object | ||
:return: Deep copied value. | ||
:rtype: Object | ||
""" | ||
if isinstance(value, list): | ||
return [_deep_copy_and_extract_items_from_generator_proxy(v) for v in value] | ||
elif isinstance(value, dict): | ||
return {k: _deep_copy_and_extract_items_from_generator_proxy(v) for k, v in value.items()} | ||
elif isinstance(value, GeneratorProxy): | ||
return deepcopy(value.items) | ||
return deepcopy(value) |
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
38 changes: 38 additions & 0 deletions
38
src/promptflow/tests/executor/unittests/_utils/test_run_tracker_utils.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,38 @@ | ||
import pytest | ||
|
||
from promptflow._core.generator_proxy import GeneratorProxy | ||
from promptflow._utils.run_tracker_utils import _deep_copy_and_extract_items_from_generator_proxy | ||
|
||
|
||
@pytest.mark.unittest | ||
class TestDeepCopyAndExtract: | ||
def test_deep_copy_simple_value(self): | ||
value = 10 | ||
result = _deep_copy_and_extract_items_from_generator_proxy(value) | ||
assert value == result | ||
|
||
def test_deep_copy_list(self): | ||
value = [1, 2, 3] | ||
result = _deep_copy_and_extract_items_from_generator_proxy(value) | ||
assert value == result | ||
assert id(value) != id(result), "List should be deep copied" | ||
|
||
def test_deep_copy_dict(self): | ||
value = {"a": 1, "b": 2} | ||
result = _deep_copy_and_extract_items_from_generator_proxy(value) | ||
assert value == result | ||
assert id(value) != id(result), "Dict should be deep copied" | ||
|
||
def test_extract_generator_proxy_items(self): | ||
generator_proxy_value = GeneratorProxy(None) | ||
generator_proxy_value._items = [1, 2] | ||
expected = [1, 2] | ||
result = _deep_copy_and_extract_items_from_generator_proxy(generator_proxy_value) | ||
assert expected == result | ||
|
||
def test_composite(self): | ||
value = {"a": [1, 2, 3], "b": GeneratorProxy(None)} | ||
value["b"]._items = [1, 2] | ||
expected = {"a": [1, 2, 3], "b": [1, 2]} | ||
result = _deep_copy_and_extract_items_from_generator_proxy(value) | ||
assert expected == result |