-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Implementing `dynamic_list` contract to unlock the scenario that any tool should be able to define the listing experience and the corresponding request to enable the dynamic listing feature. See more in #383 In this PR, we did following things: - implement `gen_dynamic_list` in `tools_manager`. - append ws triple to function input params, as user may call azure control plane api in the custom function to list Azure resources. - add an example tool with dynamic list input to `my_tool_package`. # 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).** - [X] **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
7 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
examples/tools/tool-package-quickstart/my_tool_package/tools/tool_with_dynamic_list_input.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,36 @@ | ||
from promptflow import tool | ||
from typing import List, Union, Dict | ||
|
||
|
||
def my_list_func(prefix: str = "", size: int = 10, **kwargs) -> List[Dict[str, Union[str, int, float, list, Dict]]]: | ||
"""This is a dummy function to generate a list of items. | ||
:param prefix: prefix to add to each item. | ||
:param size: number of items to generate. | ||
:param kwargs: other parameters. | ||
:return: a list of items. Each item is a dict with the following keys: | ||
- value: for backend use. Required. | ||
- display_value: for UI display. Optional. | ||
- hyperlink: external link. Optional. | ||
- description: information icon tip. Optional. | ||
""" | ||
import random | ||
|
||
words = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "kiwi", "lemon"] | ||
result = [] | ||
for i in range(size): | ||
random_word = f"{random.choice(words)}{i}" | ||
cur_item = { | ||
"value": random_word, | ||
"display_value": f"{prefix}_{random_word}", | ||
"hyperlink": f'https://www.google.com/search?q={random_word}', | ||
"description": f"this is {i} item", | ||
} | ||
result.append(cur_item) | ||
|
||
return result | ||
|
||
|
||
@tool | ||
def my_tool(input_text: list, input_prefix: str) -> str: | ||
return f"Hello {input_prefix} {','.join(input_text)}" |
35 changes: 35 additions & 0 deletions
35
...les/tools/tool-package-quickstart/my_tool_package/yamls/tool_with_dynamic_list_input.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,35 @@ | ||
my_tool_package.tools.tool_with_dynamic_list_input.my_tool: | ||
function: my_tool | ||
inputs: | ||
input_text: | ||
type: | ||
- list | ||
dynamic_list: | ||
# UX send dynamic_list content to backend. | ||
# specifies the function to generate dynamic list. format: <module>.<func> | ||
func_path: my_tool_package.tools.tool_with_dynamic_list_input.my_list_func | ||
func_kwargs: | ||
- name: prefix # Argument name to be passed to the function | ||
type: | ||
- string | ||
# if optional is not specified, default to false. | ||
# this is for UX pre-validaton. If optional is false, but no input. UX can throw error in advanced. | ||
optional: true | ||
reference: ${inputs.input_prefix} # Dynamic reference to another input parameter | ||
- name: size # Another argument name to be passed to the function | ||
type: | ||
- int | ||
optional: true | ||
default: 10 | ||
# enum and dynamic list may need below setting, default false. | ||
# allow user to enter input `index_path` value manually. | ||
allow_manual_entry: true | ||
is_multi_select: true | ||
# used to filter | ||
input_prefix: | ||
type: | ||
- string | ||
module: my_tool_package.tools.tool_with_dynamic_list_input | ||
name: My Tool with Dynamic List Input | ||
description: This is my tool with dynamic list input | ||
type: python |
12 changes: 12 additions & 0 deletions
12
examples/tools/tool-package-quickstart/tests/test_tool_with_dynamic_input.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 my_tool_package.tools.tool_with_dynamic_list_input import my_tool, my_list_func | ||
|
||
|
||
def test_my_tool(): | ||
result = my_tool(input_text=["apple", "banana"], input_prefix="My") | ||
assert result == 'Hello My apple,banana' | ||
|
||
|
||
def test_my_list_func(): | ||
result = my_list_func(prefix="My") | ||
assert len(result) == 10 | ||
assert "value" in result[0] |
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