bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 35쪽
alt="" width="375"><figcaption></figcaption></figure>
* Select the Context variable you want to modify and confirm
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2F9xSwboyyH30CgWnPFp7G%2Fimage.png?alt=media&token=16e9ea9b-e599-43fb-85bf-d92b1651bf6f" alt="" width="375"><figcaption></figcaption></figure>
* Assign a new value to the Context variable. The assignment method is the same as [#using-variables](#using-variables "mention")
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FKZeJbxMMyJB4wPh8ZAbj%2Fimage.png?alt=media&token=033a531b-6319-4f7d-bb21-53ffbe8531c0" alt="" width="375"><figcaption></figcaption></figure>
### Message
Control what content the chat agent replies to the user, which can include text, images, audio, and buttons.
* **Text** supports using expressions to reference variables, Markdown syntax, and a few HTML elements (`<img>`, `<audio>`, `<video>`, `<a>`, and you can set width and height for them).
* **Images** support using a single image or an array of images.
* **Audio** supports a single audio file.
* **Buttons** can create as many as you want; when users are interacting with the App, users can click buttons to transition to other States or rerun the current State.
Buttons are relatively more complex; their configuration includes Button Name, Button Prompt, and Payload fields. After configuration, you can connect the button on the canvas to the State it needs to transition to when clicked (it can be the same State). Advanced configurations for transitions can be made, which will be introduced in the next section on Transition.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2Fqm49mhw3ZbXUSYhGwC8S%2Fimage.png?alt=media&token=367db582-984b-47e7-93f7-d14ffeb1403c" alt="" width="375"><figcaption></figcaption></figure>
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FVkpcOgLUiLElcWbKMHXD%2Fimage.png?alt=media&token=e37bd5af-1080-460d-a137-a829db1ceb80" alt="" width="375"><figcaption></figcaption></figure>
**Payload** can create some variables when the user clicks. It generally has two use cases:
* **Perceiving User Actions**: For example, two buttons (Style 1, Style 2) correspond to the same variable (`style`) but with different data (1, 2). This way, clicking different buttons can transition to the same State but with different input data.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FUlSmUhyZF4PgN01RLAll%2Fimage.png?alt=media&token=d9999f37-941e-4ab0-b7ba-5733f8c9c9c8" alt="" width="375"><figcaption></figcaption></figure>
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2Fx1IulykTf41WTD17sGr7%2Fimage.png?alt=media&token=7a6171d6-bfa8-4a19-8a00-9787d9e74831" alt="" width="375"><figcaption></figcaption></figure>
* **Making Data Snapshots in Chat History**: Since each specific button creates and records the Payload when displayed, clicking buttons in the chat history can retrieve historical snapshot data.
## Transition
In the App Builder, transitions are represented by connections on the canvas. The right side represents outputs, and the left side represents inputs.
There are three types of transitions on the canvas, representing different trigger conditions:
* **CHAT**: Transition triggered after the user inputs content in the chat input box, achieved by connecting the circle on the right side of the simulated chat input box below the State node to another State. 
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FghUkFmlQ2zHxG0nzZm7d%2Fimage.png?alt=media&token=45072f23-8d37-4085-bfd4-2433e2d8f210" alt=""><figcaption></figcaption></figure>
* **ALWAYS**: Transition directly to another State after the State execution is complete, achieved by connecting State to State. 
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FVfSdJRTCWp4T1vyxI8R6%2Fimage.png?alt=media&token=9eebc5ee-a805-4c06-a62b-47e153c3eabd" alt=""><figcaption></figcaption></figure>
* **Custom Click Events**: Triggered when the user clicks a button, achieved by connecting the circle on the right side of the button to another State. 
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FVFiOj3VngutAkEvpGDpu%2Fimage.png?alt=media&token=289cdccc-24a0-4eaf-b0b4-6231ebf711aa" alt=""><figcaption></figcaption></figure>
### Editing Transition
Click the small square button at the midpoint of the connection line; a Transition editing form will pop up on the right. You can add conditional transitions and set target inputs.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FeSTjWuzjep0JZhoj47om%2Fimage.png?alt=media&token=0a294420-b3bf-48c5-9e77-e1362cccb7b4" alt=""><figcaption></figcaption></figure>
#### Conditional Transition
Transitions can conditionally jump to different States. A set of Conditions and Target State settings is called a Transition Case. For example, in the figure below, you can transition to the **winner** state or **continue** state based on whether the user's current score is greater than 10.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FOA5IS2dyI8brjA7DSraw%2Fimage.png?alt=media&token=3aa58b27-173d-4ed6-8cb7-de1f5462f806" alt="" width="375"><figcaption></figcaption></figure>
Enter logical expressions in the **Condition** (refer to [#expressions](#expressions "mention")) for judgment; the result of the expression should be `True` or `False`. During execution, Transition Cases are evaluated in order (from top to bottom in the interface); the first Transition Case whose Condition evaluates to `True` will take effect, and subsequent Transition Cases will not be evaluated.
If the Condition is left blank, it is equivalent to setting it as default `True`.
#### Target Inputs
When transitioning to the Target State, you can also assign values to its Inputs. This is similar to a function calling in programming and passing parameters during the call.
## Using Variables
For many fields, we support three modes of assignment:
* **UI Mode**: Directly edit in the form. 
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2F5qJsiDeIPZb0bGPNlWsN%2Fimage.png?alt=media&token=cfde3874-17a2-4f18-9800-44be2c57dc27" alt="" width="361"><figcaption></figcaption></figure>
* **Ref Mode**: Reference other variables. 
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FEuJHK9c8W2qlNgI4psPK%2Fimage.png?alt=media&token=4d1c9eb4-6c20-4428-8384-0f6ad462563d" alt="" width="367"><figcaption></figcaption></figure>
* **Code Mode**: Use programming language expressions to combine other variables or perform simple data processing through code. 
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FJFJnZrMHNspHwQRKKuNb%2Fimage.png?alt=media&token=5831eee1-b97e-43ba-82d9-8ef410f9df07" alt="" width="365"><figcaption></figcaption></figure>
You can usually switch modes by clicking on the right side or upper right corner of the field form item.
### Expressions
We support expressions, which is often a very powerful way of making state machine more controllable, and making it convenient for developers to perform simple calculations on variables.
In modes that support expressions, expressions are enclosed within double curly braces `{{ }}`. Variables can be referenced using `/`.
Common use cases for expressions include:
1. Concatenating text.
2. Accessing part of complex data, such as getting the first item of an array.
3. Calculating Conditions in Transitions.
For more complex calculation scenarios, we will later support a Code Runner Widget to execute functions.
> \[!TIP] We currently support expressions in the Python language. JavaScript expressions will be supported later. Python expressions currently support the following libraries:
>
> * builtins
> * marshal
> * math
> * time
## Using GPT widget
You need to click **Settings** to set the environment variable `OPENAI_API_KEY`.
{% hint style="info" %}
To use GPT models, currently you need to have your own OpenAI API Key. Due to the fact that ShellAgent is an open-sourced project, MyShell cannot provide limitless free API keys to everyone. However, we will connect the MyShell account's battery system with ShellAgent in the future, so that developers can use the batteries in their MyShell account to build with ShellAgent. 
{% endhint %}
{% hint style="info" %}
This API Key will only be used for building purposes in your local open-sourced project. Once you export the bot's JSON file from ShellAgent to MyShell's website, all API compute costs will still be hosted by MyShell.
{% endhint %}
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FSZfyvccpKrSw2MhiCyRN%2Fimage.png?alt=media&token=65f84db1-ebac-4f49-8423-3049126af348" alt="" width="365"><figcaption></figcaption></figure>
## FAQ
### How to Format Bot Messages
You can use Markdown in **Message.Text**.
If you need multimedia elements, you can add corresponding HTML elements. For example:
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2Ftfb0HbtDxGplQAgpT7W7%2Fimage.png?alt=media&token=0d8047ca-3904-40f5-b9c3-82c559de7699" alt="" width="367"><figcaption></figcaption></figure>
### How to Set Image Size in Bot Messages
Turn off the **Message.Image** switch, insert `<img />` in **Message.Text**, and set its width and height. For example:
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2Fm7s3feJcnrN9p9qiIdWB%2Fimage.png?alt=media&token=9083e945-93e4-4e92-8f54-caf42cc80225" alt="" width="375"><figcaption></figcaption></figure>
# Workflow
## Introduction
Currently, the Workflow mainly targets AI image generation. To reduce the learning curve for users, we chose to support ComfyUI's interaction style and be compatible with a large number of ComfyUI custom nodes. In addition, we are also working hard to implement other LLM-related (such as GPT) and tools (such as code block) Widgets.
The usage of Workflow is very similar to ComfyUI. We are compatible with a large number of ComfyUI custom nodes, but we currently do not support users directly downloading and running ComfyUI custom nodes.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FJj0qhQ4TDUuz7xwBdx6z%2Fimage.png?alt=media&token=77848fb6-39f4-4b63-b501-f2a93c16d511" alt=""><figcaption></figcaption></figure>
{% hint style="info" %}
We currently do not support users directly downloading and running ComfyUI custom nodes. If you really need some certain custom nodes, please contact [us](mailto:hance@myshell.ai), with your reasons, we will evaluate your request and support at our best effort. If the custom nodes you need are not related to AI models but are plugins that optimize the interaction experience or modify the UI, support may not be very timely.
{% endhint %}
## ComfyUI-like Interaction
Compared to the standard ComfyUI, we mainly added the start node and end node. These two nodes are mainly to facilitate packaging the entire workflow into a single node for use by the App Builder. For documentation conciseness, we will not detail the ComfyUI tutorial here, please find ComfyUI tutorials by yourself, there are plenty!
{% hint style="info" %}
If you do not intend to package the workflow into a widget for the App Builder, you can ignore the start and end nodes and edit the image flow in the ComfyUI way.
{% endhint %}
### Importing ComfyUI Workflow (beta)
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FzGmwlTcPsmtINyXuEvwl%2Fimage.png?alt=media&token=903a2b2e-20dc-4c1e-a292-ae2ce61aa178" alt="" width="375"><figcaption></figcaption></figure>
{% hint style="info" %}
Currently, we only support ComfyUI workflows exported in JSON format.
{% endhint %}
After importing, some ComfyUI nodes may not be supported.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FJ7gnQn5t2sTkmVjpm6fT%2Fimage.png?alt=media&token=5c3eff5e-fe5e-4446-a059-c36796f46c2f" alt="" width="375"><figcaption></figcaption></figure>
Since these unsupported nodes cannot run when the ShellAgent is deployed to the MyShell main site, we currently do not support one-click download of missing nodes, but will be supported soon.
We suggest:
1. Replace the node with another node that has the same function (if available).
2. Contact [us](mailto:hance@myshell.ai) to let ShellAgent and MyShell support the node simultaneously. It may take some time, so only do it when such node is very necessary.
For missing Models, you can download them in the Manager. See [#model-and-widget-management](#model-and-widget-management "mention")
## Start Node
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2F7KLR29i9U92nFsahtp6g%2Fimage.png?alt=media&token=14bc412b-86b5-4305-a2a8-c0e63c27b202" alt=""><figcaption></figcaption></figure>
The start node includes:
* **Input**: When you want to run the workflow as a single widget, you can specify which variables need to be input when calling the workflow widget through Input. Each input needs to specify its name and type, and you can add descriptions and validation items in more settings.
* **Context**: If there are some primitive variables that are used repeatedly within the workflow, you can choose to collect them all into the context. Each context variable needs to specify its name (including type) and its value.
### Using Input/Context Variables
For example, if you want to support users uploading images in Load Image, you can do this:
* Change the image of the Load Image widget to the widget's input.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FlsIcQorlKCVUOXZBDhpE%2Fimage.png?alt=media&token=41de165c-3945-4e10-ab12-40b9f3d45021" alt="" width="375"><figcaption></figcaption></figure>
* Connect the image in the start node's Input.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FZq7PHiYoZQoREYY6UuaP%2Fimage.png?alt=media&token=39093b84-b2cc-4076-bdb3-546cb647f29c" alt="" width="375"><figcaption></figcaption></figure>
Each variable has a type, and currently our variables support six types:
* text
* image
* audio
* video
* text\_file
* file
These types affect what the form item is when users input. For example, **text** is a text input box, and the other five are file uploads (different types support different file extensions and sizes).
{% hint style="info" %}
These variables are essentially treated as strings when associated. **text** is a text string, and the other five are paths to images/videos/files. Therefore, when using them, you need to use Load Image or Text Encode to input them into the image generation model.
{% endhint %}
## End Node
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FLTMp9KEQGSZeTwLFMO8F%2Fimage.png?alt=media&token=bf43cf5b-33a9-41bc-bb70-550e1855df38" alt="" width="375"><figcaption></figcaption></figure>
The Output of the end node is similar to the Input of the start node, indicating what the final output result of the workflow widget should be.
{% hint style="info" %}
The default type of Output is **unknown**. Because its type depends on the associated input variables, and many input variables are arrays, objects, or other composite types, we cannot represent them well at the moment. When the App Builder calls the output of this Workflow, you need to pay attention to the output of composite types.
{% endhint %}
## Run
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FRcPBB77CzyqU8HcPndev%2Fimage.png?alt=media&token=743aec9f-7f9c-459c-9fd9-9d603e3343dc" alt="" width="375"><figcaption></figcaption></figure>
Run the workflow; after filling in the specified parameters, you can execute it.
## Version Management
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FqITNytB2eu87fl2eTNO0%2Fimage.png?alt=media&token=d425bc12-6658-4a5f-bd45-0f992a82376e" alt="" width="369"><figcaption></figcaption></figure>
We also support version management of the workflow. Click **publish** to enter a name to specify the corresponding version. You can return to edit this version later.
## Model and Widget Management
Through **Manager**, you can manage local Models and Widgets.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FsgBrYzvK83J5n5z6lVgf%2Fimage.png?alt=media&token=1adb89fc-db13-4960-9c52-2b2cc9b7f108" alt=""><figcaption></figcaption></figure>
For models not listed in the list, you can customize the installation through **Install from Link** in the upper right corner.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FcSpVI84FXHXuEGnTIZZO%2Fimage.png?alt=media&token=bad9ef7c-6c6a-4a75-9eef-fe7f487ed4f8" alt=""><figcaption></figcaption></figure>
If you already have many downloaded models locally, you can adjust the model location by setting the **settings**.
<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FOtqBiUihbPBVz11JXthS%2Fimage.png?alt=media&token=c4621133-0ca5-4a22-a999-256c84b57c92" alt=""><figcaption></figcaption></figure>
# Build Custom Widget
## Development
### Example
Reference code:
<https://github.com/wl-zhao/proconfig-diffuser-imagen>
The code above provides a simple example of calling the `DiffusionPipeline` in diffusers. The core code is in:
<https://github.com/wl-zhao/proconfig-diffuser-imagen/blob/main/diffuser_widget.py>
### Development Process
1. Define the widget's name and category through `NAME` and `CATEGORY`.
2. Define input and output specifications via `InputsSchema` and `OutputsSchema`. Use pydantic syntax to define the schema for each field.
3. Implement the `execute` function to define the widget's actual execution logic. The function's inputs and outputs need to meet the previously defined input and output specifications.
4. In the root direct프로젝트로 돌아가기