Skip to content

Commit

Permalink
Add doc and support gen tool meta for category and tags. (microsoft#794)
Browse files Browse the repository at this point in the history
# Description

Add doc and support gen tool meta for category and tags.

# 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
- [ ] Pull request includes test coverage for the included changes.
  • Loading branch information
jiazengcindy authored Oct 19, 2023
1 parent 12b95cd commit eaa69d6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Add Category and Tags for Tool
Previously, all tools were listed at the top level. It would be challenging for users to find their desired tool, especially when dozens of tools are installed. To simplify the tool list and help users locate their target tools more easily, we've introduced `category` and `tags` features. The `category` feature helps organize tools into separate folders, while `tags` allow users to search and filter tools with matching tags.

| name | type | is_required | description |
| ---------| -----| ---------- | ----------- |
| category | str | false | A string that groups tools with similar characteristics. |
| tags | dict | false | A dictionary of key-value pairs to describe the different perspectives of the tool. |
> [!Note] If a tool isn't assigned a category, it will be displayed in the root folder. Similarly, if no tags are assigned, the tags field will remain empty.
## Prerequisites
- Please ensure that your [Prompt flow for VS Code](https://marketplace.visualstudio.com/items?itemName=prompt-flow.prompt-flow) is updated to version 1.1.0 or later.

## How to add category and tags for a tool
Run the command below in your tool project directory to automatically generate your tool YAML, use _-c_ or _--category_ to add category, and use _--tags_ to add tags for your tool:

```
python <path-to-scripts>\tool\generate_package_tool_meta.py -m <tool_module> -o <tool_yaml_path> --category <tool_category> --tags <tool_tags>
```

Here, we use [an existing tool](https://github.com/microsoft/promptflow/tree/main/examples/tools/tool-package-quickstart/my_tool_package/yamls/my_tool_1.yaml) as an example. If you wish to create your own tool, please refer to the [create and use tool package](create-and-use-tool-package.md#create-custom-tool-package) guide.
```
cd D:\proj\github\promptflow\examples\tools\tool-package-quickstart
python D:\proj\github\promptflow\scripts\tool\generate_package_tool_meta.py -m my_tool_package.tools.my_tool_1 -o my_tool_package\yamls\my_tool_1.yaml --category "test_tool" --tags "{'tag1':'value1','tag2':'value2'}"
```
In the auto-generated tool YAML file, the category and tags are shown as below:
```yaml
my_tool_package.tools.my_tool_1.my_tool:
function: my_tool
inputs:
connection:
type:
- CustomConnection
input_text:
type:
- string
module: my_tool_package.tools.my_tool_1
name: My First Tool
description: This is my first tool
type: python
# Category and tags are shown as below.
category: test_tool
tags:
tag1: value1
tag2: value2
```
## Tool with category and tags experience in VS Code extension
Follow the [steps](create-and-use-tool-package.md#use-your-tool-from-vscode-extension) to use your tool via the VS Code extension.
- Experience in the tool tree
![category_and_tags_in_tool_tree](../../media/how-to-guides/develop-a-tool/category_and_tags_in_tool_tree.png)
- Experience in the tool list
By clicking `More` in the visual editor, you can view your tools along with their category and tags:
![category_and_tags_in_tool_list](../../media/how-to-guides/develop-a-tool/category_and_tags_in_tool_list.png)
Furthermore, you have the option to search or filter tools based on tags:
![filter_tools_by_tag](../../media/how-to-guides/develop-a-tool/filter_tools_by_tag.png)
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ Alternatively, you can test your tool package using the script below to ensure t
* If you encounter a `403 Forbidden Error`, it's likely due to a naming conflict with an existing package. You will need to choose a different name. Package names must be unique on PyPI to avoid confusion and conflicts among users. Before creating a new package, it's recommended to search PyPI (https://pypi.org/) to verify that your chosen name is not already taken. If the name you want is unavailable, consider selecting an alternative name or a variation that clearly differentiates your package from the existing one.
## Advanced features
[Customize your tool icon](add-a-tool-icon.md)
[Customize your tool icon](add-a-tool-icon.md)
[Add category and tags for tool](add-category-and-tags-for-tool.md)
1 change: 1 addition & 0 deletions docs/how-to-guides/develop-a-tool/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ We provide guides on how to develop a tool and use it.
create-and-use-tool-package
add-a-tool-icon
add-category-and-tags-for-tool
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 19 additions & 3 deletions scripts/tool/generate_package_tool_meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import ast
import importlib
import json
import os
Expand Down Expand Up @@ -36,7 +37,18 @@
"--icon",
"-i",
type=str,
help="your tool's icon image path, if not provided, the system will use the default icon",
help="your tool's icon image path, if not provided, the system will use the default icon.",
required=False)
parser.add_argument(
"--category",
"-c",
type=str,
help="your tool's category, if not provided, the tool will be displayed under the root folder.",
required=False)
parser.add_argument(
"--tags",
type=ast.literal_eval,
help="your tool's tags. It should be a dictionary-like string, e.g.: --tags \"{'tag1':'v1','tag2':'v2'}\".",
required=False)
args = parser.parse_args()
m = importlib.import_module(args.module)
Expand All @@ -50,13 +62,17 @@
m,
name=args.name,
description=args.description,
icon=icon)
icon=icon,
category=args.category,
tags=args.tags)
else:
tools_dict = generate_python_tools_in_module_as_dict(
m,
name=args.name,
description=args.description,
icon=icon)
icon=icon,
category=args.category,
tags=args.tags)
# The generated dict cannot be dumped as yaml directly since yaml cannot handle string enum.
tools_dict = json.loads(json.dumps(tools_dict))
with open(args.output, "w") as f:
Expand Down

0 comments on commit eaa69d6

Please sign in to comment.