-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into yigao/recording_draft
- Loading branch information
Showing
22 changed files
with
326 additions
and
22 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
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
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
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
Oops, something went wrong.