Skip to content

Commit

Permalink
update icon doc and gen meta
Browse files Browse the repository at this point in the history
update
  • Loading branch information
jiazengcindy committed Nov 16, 2023
1 parent 06c56a2 commit 1d63cf5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
34 changes: 33 additions & 1 deletion docs/how-to-guides/develop-a-tool/add-a-tool-icon.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Adding a custom tool icon is optional. If you do not provide one, the system use
pip install pillow
```

## Add tool icon with _icon_ parameter
## Add tool icon using command
### Add a tool icon regardless light or dark mode
Run the command below in your tool project directory to automatically generate your tool YAML, use _-i_ or _--icon_ parameter to add a custom tool icon:
```
python <path-to-scripts>\tool\generate_package_tool_meta.py -m <tool_module> -o <tool_yaml_path> -i <tool-icon-path>
Expand Down Expand Up @@ -49,6 +50,37 @@ my_tool_package.tools.my_tool_1.my_tool:
type: python
```
### Add tool icons for light and dark mode respectively
Run the command below in your tool project directory to automatically generate your tool YAML, use _--icon-light_ to add a custom tool icon in the light mode and use _--icon-dark_ to add a custom tool icon in the dark mode:
```
python <path-to-scripts>\tool\generate_package_tool_meta.py -m <tool_module> -o <tool_yaml_path> --icon-light <light-tool-icon-path> --icon-dark <dark-tool-icon-path>
```
Here we use [an existing tool project](https://github.com/microsoft/promptflow/tree/main/examples/tools/tool-package-quickstart) as an example.
```
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 --icon-light my_tool_package\icons\custom-tool-icon-light.png --icon-dark my_tool_package\icons\custom-tool-icon-dark.png
```

In the auto-generated tool YAML file, the light and dark custom tool icon data URIs are added in the `icon` field:
```yaml
my_tool_package.tools.my_tool_1.my_tool:
function: my_tool
icon:
dark: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAB00lEQVR4nI1SO2iTURT+7iNNb16a+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39ax5cy5i53bdnb39KXtLpr28OMLgiCfz78YHpmemi0W2piZWdIWaMmDCIDWet/ePUlS0toQUWM8yxG8jrVuw/qOTBw19rUiQUQoCGZm50z9txf8By3/K0Rh+PDRk8lv3+MoWklBBACmpmdKxcKn96O3b1SqC6FSyxOUgohk4pjZ9T8YeDX6ptye+PoSpNIrfkGv3747fOzk+UtXjTE+BM14M8tfl7BQR9VzUXEAAAAASUVORK5CYII=
inputs:
connection:
type:
- CustomConnection
input_text:
type:
- string
module: my_tool_package.tools.my_tool_1
name: my_tool
type: python
```
## Verify the tool icon in VS Code extension
Follow [steps](create-and-use-tool-package.md#use-your-tool-from-vscode-extension) to use your tool from VS Code extension. Your tool displays with the custom icon:
![custom-tool-with-icon-in-extension](../../media/how-to-guides/develop-a-tool/custom-tool-with-icon-in-extension.png)
Expand Down
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.
34 changes: 33 additions & 1 deletion scripts/tool/generate_package_tool_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@
"--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 you need to show different icons in dark and light mode, \n"
"please use `icon-light` and `icon-dark` parameter. \n"
"if not provided these icon parameters, the system will use the default icon.",
required=False)
parser.add_argument(
"--icon-light",
type=str,
help="your tool's icon image path in light mode, if you need to show the same icon in dark and light mode, \n"
"please use `icon` parameter, if not provided these icon parameters, the system will use the default icon.",
required=False)
parser.add_argument(
"--icon-dark",
type=str,
help="your tool's icon image path in dark mode, if you need to show the same icon in dark and light mode, \n"
"please use `icon` parameter, if not provided these icon parameters, the system will use the default icon.",
required=False)
parser.add_argument(
"--category",
Expand All @@ -54,8 +68,26 @@

icon = ""
if args.icon:
if args.icon_light or args.icon_dark:
raise ValueError("You cannot provide both `icon` and `icon-light` or `icon-dark`.")
from convert_image_to_data_url import check_image_type_and_generate_data_url # noqa: E402
icon = check_image_type_and_generate_data_url(args.icon)
elif args.icon_light:
if not args.icon_dark:
raise ValueError("You must provide both `icon-light` and `icon-dark`.")
from convert_image_to_data_url import check_image_type_and_generate_data_url # noqa: E402
icon = {
"light": check_image_type_and_generate_data_url(args.icon_light),
"dark": check_image_type_and_generate_data_url(args.icon_dark)
}
elif args.icon_dark:
if not args.icon_light:
raise ValueError("You must provide both `icon-light` and `icon-dark`.")
from convert_image_to_data_url import check_image_type_and_generate_data_url # noqa: E402
icon = {
"light": check_image_type_and_generate_data_url(args.icon_light),
"dark": check_image_type_and_generate_data_url(args.icon_dark)
}

if args.tool_type == "custom_llm":
tools_dict = generate_custom_llm_tools_in_module_as_dict(
Expand Down

0 comments on commit 1d63cf5

Please sign in to comment.