Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
update
  • Loading branch information
jiazengcindy committed Nov 16, 2023
1 parent 1d63cf5 commit c381f87
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
11 changes: 6 additions & 5 deletions docs/how-to-guides/develop-a-tool/add-a-tool-icon.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Adding a Tool Icon
A tool icon serves as a graphical representation of your tool in the user interface (UI). Follow this guidance to add a custom tool icon when developing your own tool package.
A tool icon serves as a graphical representation of your tool in the user interface (UI). This document offers guidance on integrating a tool icon when developing your own tool package. It offers instructions on how to add a single icon that seamlessly adapts to both dark and light modes. Additionally, the document also provides detailed steps on how to add distinct icons for dark and light modes separately.

Adding a custom tool icon is optional. If you do not provide one, the system uses a default icon.

## 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.0.10 or a more recent version.
- Create a tool package as described in [Create and Use Tool Package](create-and-use-tool-package.md).
- Prepare custom icon image that meets these requirements:
- Prepare custom icon images that meet these requirements:

- Use PNG, JPG or BMP format.
- 16x16 pixels to prevent distortion when resizing.
Expand All @@ -24,7 +24,7 @@ Adding a custom tool icon is optional. If you do not provide one, the system use
### 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>
python <promptflow github repo>\scripts\tool\generate_package_tool_meta.py -m <tool_module> -o <tool_yaml_path> -i <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.
```
Expand Down Expand Up @@ -53,7 +53,7 @@ my_tool_package.tools.my_tool_1.my_tool:
### 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>
python <promptflow github repo>\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.
```
Expand All @@ -80,6 +80,7 @@ my_tool_package.tools.my_tool_1.my_tool:
name: my_tool
type: python
```
Note: If you specify only a light icon without a dark icon, the defined icon will be used in light mode, while the system default icon will be used in dark mode. Similarly, if only a dark icon is specified, the defined icon will be used in dark mode, and the system default icon will be used in light mode.
## 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:
Expand All @@ -89,7 +90,7 @@ Follow [steps](create-and-use-tool-package.md#use-your-tool-from-vscode-extensio
### Can I preview the tool icon image before adding it to a tool?
Yes, you could run below command under the root folder to generate a data URI for your custom tool icon. Make sure the output file has an `.html` extension.
```
python <path-to-scripts>\tool\convert_image_to_data_url.py --image-path <image_input_path> -o <html_output_path>
python <promptflow github repo>\scripts\tool\convert_image_to_data_url.py --image-path <image_input_path> -o <html_output_path>
```
For example:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This document is dedicated to guiding you through the process of categorizing an
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>
python <promptflow github repo>\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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ git clone https://github.com/microsoft/promptflow.git
### Create custom tool package
Run below command under the root folder to create your tool project quickly:
```
python <path-to-scripts>\tool\generate_tool_package_template.py --destination <your-tool-project> --package-name <your-package-name> --tool-name <your-tool-name> --function-name <your-tool-function-name>
python <promptflow github repo>\scripts\tool\generate_tool_package_template.py --destination <your-tool-project> --package-name <your-package-name> --tool-name <your-tool-name> --function-name <your-tool-function-name>
```
For example:
```
Expand Down Expand Up @@ -69,7 +69,7 @@ hello-world-proj/

> [!Note] If you create a new tool, don't forget to also create the corresponding tool YAML. You can run below command under your tool project to auto generate your tool YAML. You may want to specify `-n` for `name` and `-d` for `description`, which would be displayed as the tool name and tooltip in prompt flow UI.
```
python <path-to-scripts>\tool\generate_package_tool_meta.py -m <tool_module> -o <tool_yaml_path> -n <tool_name> -d <tool_description>
python <promptflow github repo>\scripts\tool\generate_package_tool_meta.py -m <tool_module> -o <tool_yaml_path> -n <tool_name> -d <tool_description>
```
For example:
```
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-guides/develop-a-tool/customize_an_llm_tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Here we use [an existing tool package](https://github.com/microsoft/promptflow/t
2. Generate the custom LLM tool YAML.
Run the command below in your tool project directory to automatically generate your tool YAML, use _-t "custom_llm"_ or _--tool-type "custom_llm"_ to indicate this is a custom LLM tool:
```
python <path-to-scripts>\tool\generate_package_tool_meta.py -m <tool_module> -o <tool_yaml_path> -t "custom_llm"
python <promptflow github repo>\scripts\tool\generate_package_tool_meta.py -m <tool_module> -o <tool_yaml_path> -t "custom_llm"
```
Here we use [an existing tool](https://github.com/microsoft/promptflow/blob/main/examples/tools/tool-package-quickstart/my_tool_package/yamls/tool_with_custom_llm_type.yaml) as an example.
```
Expand Down
31 changes: 14 additions & 17 deletions scripts/tool/generate_package_tool_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"-i",
type=str,
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"
"please use `icon-light` and `icon-dark` parameters. \n"
"if not provided these icon parameters, the system will use the default icon.",
required=False)
parser.add_argument(
Expand Down Expand Up @@ -72,22 +72,19 @@
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)
}
elif args.icon_light or args.icon_dark:
if args.icon_light:
from convert_image_to_data_url import check_image_type_and_generate_data_url # noqa: E402
if type(icon) == dict:
icon["light"] = check_image_type_and_generate_data_url(args.icon_light)
else:
icon = {"light": check_image_type_and_generate_data_url(args.icon_light)}
if args.icon_dark:
from convert_image_to_data_url import check_image_type_and_generate_data_url # noqa: E402
if type(icon) == dict:
icon["dark"] = check_image_type_and_generate_data_url(args.icon_dark)
else:
icon = {"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 c381f87

Please sign in to comment.