-
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.
Merge branch 'main' into dev_container
- Loading branch information
Showing
75 changed files
with
1,754 additions
and
191 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Add conditional control to a flow | ||
|
||
:::{admonition} Experimental feature | ||
This is an experimental feature, and may change at any time. Learn [more](faq.md#stable-vs-experimental). | ||
::: | ||
|
||
In Prompt flow, we support control logic by activate config, like if-else, switch. Activate config enables conditional execution of nodes within your flow, ensuring that specific actions are taken only when the specified conditions are met. | ||
|
||
This guide will help you learn how to use activate config to add conditional control to your flow. | ||
|
||
## Prerequisites | ||
|
||
Please ensure that your promptflow version is greater than `0.1.0b5`. | ||
|
||
## Usage | ||
|
||
Each node in your flow can have an associated activate config, specifying when it should execute and when it should bypass. If a node has activate config, it will only be executed when the activate condition is met. The configuration consists of two essential components: | ||
- `activate.when`: The condition that triggers the execution of the node. It can be based on the outputs of a previous node, or the inputs of the flow. | ||
- `activate.is`: The condition's value, which can be a constant value of string, boolean, integer, double. | ||
|
||
You can manually change the flow.dag.yaml in the flow folder or use the visual editor in VS Code Extension to add activate config to nodes in the flow. | ||
|
||
::::{tab-set} | ||
:::{tab-item} YAML | ||
:sync: YAML | ||
|
||
You can add activate config in the node section of flow yaml. | ||
```yaml | ||
activate: | ||
when: ${node.output} | ||
is: true | ||
``` | ||
::: | ||
:::{tab-item} VS Code Extension | ||
:sync: VS Code Extension | ||
- Click `Visual editor` in the flow.dag.yaml to enter the flow interface. | ||
![visual_editor](../media/how-to-guides/conditional-flow-with-activate/visual_editor.png) | ||
|
||
- Click on the `Activation config` section in the node you want to add and fill in the values for "when" and "is". | ||
![activate_config](../media/how-to-guides/conditional-flow-with-activate/activate_config.png) | ||
|
||
::: | ||
|
||
:::: | ||
|
||
### Further details and important notes | ||
1. If the node using the python tool has an input that references a node that may be bypassed, please provide a default value for this input. This helps prevent errors in the current node due to missing parameters. | ||
|
||
![provide_default_value](../media/how-to-guides/conditional-flow-with-activate/provide_default_value.png) | ||
|
||
2. Please avoid directly connecting nodes that might be bypassed to the flow's outputs. This can lead to flow failures due to a lack of valid values on the flow output. | ||
|
||
![output_bypassed](../media/how-to-guides/conditional-flow-with-activate/output_bypassed.png) | ||
|
||
3. In a conditional flow, if a node is bypassed, it status will be marked as `Bypassed`, as shown in the figure below. There are three situations in which the node will be bypassed. | ||
![bypassed_nodes](../media/how-to-guides/conditional-flow-with-activate/bypassed_nodes.png) | ||
|
||
|
||
(1) If a node has activate config and the value of `activate.when` is equals to `activate.is`, it will be bypassed. | ||
|
||
(2) If a node has activate config and the node pointed to by `activate.when` is bypassed, it will be bypassed. | ||
|
||
![activate_when_bypassed](../media/how-to-guides/conditional-flow-with-activate/activate_when_bypassed.png) | ||
|
||
(3) If a node does not have activate config but depends on other nodes that have been bypassed, it will be bypassed. | ||
|
||
![dependencies_bypassed](../media/how-to-guides/conditional-flow-with-activate/dependencies_bypassed.png) | ||
|
||
|
||
|
||
## Example flow | ||
|
||
Let's illustrate how to use activate config with practical examples. | ||
|
||
- If-Else scenario: Learn how to develop a conditional flow for if-else scenarios. [View Example](https://github.com/microsoft/promptflow/tree/main/examples/flows/standard/conditional-flow-for-if-else) | ||
- Switch scenario: Explore conditional flow for switch scenarios. [View Example](https://github.com/microsoft/promptflow/tree/main/examples/flows/standard/conditional-flow-for-switch) | ||
|
||
|
||
## Next steps | ||
|
||
- [Run and evaluate a flow](./run-and-evaluate-a-flow.md) |
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,58 @@ | ||
# Add 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. | ||
|
||
Adding a custom tool icon is optional. If you do not provide one, the system uses a default icon. | ||
|
||
## Prerequisites | ||
|
||
- Create a tool package as described in [Create and Use Tool Package](create-and-use-tool-package.md). | ||
- Prepare a custom tool icon image. The image should meet following requirements: | ||
- The image should be in `PNG` or `JPG` format. | ||
- 16x16 pixel image to avoid distortion from resizing. | ||
- Avoid complex images with much detail or contrast as they may not resize well. | ||
You could see for example. | ||
- Install dependencies of generating icon data URI: | ||
|
||
``` | ||
pip install pillow | ||
``` | ||
## Generate a tool icon data URI | ||
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, this makes it easier to check the image's data URI: | ||
``` | ||
python <path-to-scripts>\tool\convert_image_to_data_url.py --image-path <image_input_path> -o <html_output_path> | ||
``` | ||
For example: | ||
``` | ||
python D:\proj\github\promptflow\scripts\tool\convert_image_to_data_url.py --image-path D:\proj\github\promptflow\examples\tools\tool-package-quickstart\my_tool_package\icons\custom-tool-icon.png -o output.html | ||
``` | ||
The content of `output.html` looks like the following, and you can open it in a web browser to see the result. | ||
```html | ||
<html> | ||
<body> | ||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACq0lEQVR4nKWTPWxTVxiGn3N/bF/fGyd2YxsQ5LdSmoqGgKJMEQNZYGBFkVhY2JGYmFG3ioWZpWukqqpaqaVKq6pFIAECAkSxMA6RHZP4Jnbs+O/6xvdjcCLKT6ee7ZwjvfrOc55XiYjwP5bx740IZDf3+PVZicdrVeK2yfzJJBem02iaQv1XQCCCCNz+Lce91R1mRvtYd5uEDIfl9SqpWIjZLxOIgPooRQtE0JQiU6xx91mJfNkjZoX47vIkM2Nx6l6Xmz9kWHywgVIQBB++WImI1Nv7fP/XOqah0fKFdH8YQwXcf1Vh6WWZTrfLaDLK4rVZrJD+wSQGwJrbQtc0rs4PAXDr5xy/PHW5NJsmGQuhNI0/XrisFmtMjwxwOLVCYXTaTdq+kHagXq0iAo4phE2dn564XD8/zLlTRwn8gK1dQaHQtfcgDDMcwQo1Wc43mEp16YpibdsjEKHdEX5/8YZEpIhjCckBi9a+ibfvETEsIobdY1Bp+Pz4cAvP67C522IsbeN1A0zd5r77LWF7hebe1xxJrzKRmON56W/OHDnHwskbaCIQt03OTsbJljxeuz4rxSYXp2JcmYszedQhrNscj/ehJIKuQpiaBegHEFVPoOHBKOPpKMXdNtlSmzt/bpC0XTb9LxgcmGDq2CT5mpC0hhiO1UhGe8ANBYgCQ1dcnR9iJGnxT6ZMrtLmbV1H78/QrD0nagQ82ljCP+HzqLBEsB8wP7bQ+8ZDpoauuHA6xfnpFA3Px4mY3M2cJbeTZjTxFQYm44lv0MRkPDH1aRcOtdaUwon0rgrbBdbd10S1AXJbWRxzkLXNLDEz1VP54wDtQLHuQUl36xUKpTzl6jYFN89OdYeCm6eyV3mv8mdKxuFxueHS8PawTJuW3yAacmh26jiRfhL2IO8AhSUo7nmFnjUAAAAASUVORK5CYII=" alt="My Image"> | ||
</body> | ||
</html> | ||
``` | ||
|
||
## Use the tool icon data URI in the tool YAML | ||
In the auto-generated tool YAML file, customize the tool icon by adding the data URI: | ||
```yaml | ||
hello_world.tools.hello_world_tool.get_greeting_message | ||
function: get_greeting_message | ||
inputs: | ||
connection: | ||
type: | ||
- CustomConnection | ||
input_text: | ||
type: | ||
- string | ||
module: hello_world.tools.hello_world_tool | ||
name: Hello World Tool | ||
description: This is hello world tool | ||
type: python | ||
icon: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACq0lEQVR4nKWTPWxTVxiGn3N/bF/fGyd2YxsQ5LdSmoqGgKJMEQNZYGBFkVhY2JGYmFG3ioWZpWukqqpaqaVKq6pFIAECAkSxMA6RHZP4Jnbs+O/6xvdjcCLKT6ee7ZwjvfrOc55XiYjwP5bx740IZDf3+PVZicdrVeK2yfzJJBem02iaQv1XQCCCCNz+Lce91R1mRvtYd5uEDIfl9SqpWIjZLxOIgPooRQtE0JQiU6xx91mJfNkjZoX47vIkM2Nx6l6Xmz9kWHywgVIQBB++WImI1Nv7fP/XOqah0fKFdH8YQwXcf1Vh6WWZTrfLaDLK4rVZrJD+wSQGwJrbQtc0rs4PAXDr5xy/PHW5NJsmGQuhNI0/XrisFmtMjwxwOLVCYXTaTdq+kHagXq0iAo4phE2dn564XD8/zLlTRwn8gK1dQaHQtfcgDDMcwQo1Wc43mEp16YpibdsjEKHdEX5/8YZEpIhjCckBi9a+ibfvETEsIobdY1Bp+Pz4cAvP67C522IsbeN1A0zd5r77LWF7hebe1xxJrzKRmON56W/OHDnHwskbaCIQt03OTsbJljxeuz4rxSYXp2JcmYszedQhrNscj/ehJIKuQpiaBegHEFVPoOHBKOPpKMXdNtlSmzt/bpC0XTb9LxgcmGDq2CT5mpC0hhiO1UhGe8ANBYgCQ1dcnR9iJGnxT6ZMrtLmbV1H78/QrD0nagQ82ljCP+HzqLBEsB8wP7bQ+8ZDpoauuHA6xfnpFA3Px4mY3M2cJbeTZjTxFQYm44lv0MRkPDH1aRcOtdaUwon0rgrbBdbd10S1AXJbWRxzkLXNLDEz1VP54wDtQLHuQUl36xUKpTzl6jYFN89OdYeCm6eyV3mv8mdKxuFxueHS8PawTJuW3yAacmh26jiRfhL2IO8AhSUo7nmFnjUAAAAASUVORK5CYII= | ||
``` | ||
## 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/contributing/custom-tool-with-icon-in-extension.png) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Develop a tool | ||
We provide guides on how to develop a tool and use it. | ||
|
||
```{toctree} | ||
:maxdepth: 1 | ||
:hidden: | ||
create-and-use-tool-package | ||
add-a-tool-icon | ||
``` |
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.