MyShell 백서

MyShell

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 15쪽

xxxxxxxxxxxx', 'B. xxxxxxxxx', 'C. xxxxxxxxxxx', 'D. xxxxxxxxxx'], 'answer': '? (from ABCD)', 'explanation': 'why we choose ? (from ABCD) as answer, explain it.'}`", "user_prompt": "generate a four choice questions under the topic:{{context.user_given_note_topic??context.note_topic}}. The output should be a JSON format.", "function_description": "Generate a multiple-choice question. Output: JSON format question. containing question, choices, answer and explanation", "function_name": "GenerateMCQ", "function_parameters": [ { "name": "mcqtest", "type": "object", "properties": { "question": { "type": "string", "description": "the question" }, "choices": { "type": "array", "items": { "type": "string" }, "description": "the choices, must contain 4 choices, format should be A. xxx, B. xxx, C. xxx, D.xxx" }, "answer": { "type": "string", "description": "the answer, must chosen from A/B/C/D" }, "explanation": { "type": "string", "description": "the explanation" } }, "required": ["question", "choices", "answer", "explanation"], "description": "The generated question. The format is JSON, contains question, choices, answer and explanation." } ], "output_name": "llm_generated_question" } } ], ``` In the above example, we aim to generate the question, choices, answer and explanation, and the type of them are string array string string accordingly. We can adopt the OpenAI schema like above to define the desired structure recursively. # API Reference # Atomic State ## AtomicState An atomic state is a state executing real tasks, which usually are small functional modules, such as LLM module and TTS module. In an agent on MyShell, an entered atomic state usually means a sent message with buttons if specified. `AtomicState` <table><thead><tr><th width="149">Field's Name</th><th width="178">Type (Required/Optional)</th><th width="281">Description</th><th>Example</th></tr></thead><tbody><tr><td>id</td><td>string (Optional)</td><td>Globally unique identifier.</td><td>"1234_5678_9101"</td></tr><tr><td>type</td><td>"state" (Optional)</td><td>Specifies that this is an atomic state.</td><td>"state"</td></tr><tr><td>properties</td><td>Object (Optional)</td><td>Static config. Similar to metadata.</td><td></td></tr><tr><td>properties.is_final</td><td>boolean (Optional)</td><td>Flag to check if the current state is final. Default to false.</td><td>true</td></tr><tr><td>properties.cache</td><td>boolean (Optional)</td><td>Flag to enable cache mode. When set to true, the state will run only once and store the result.<br>Default to false.</td><td></td></tr><tr><td>inputs</td><td>Object (Optional)</td><td>Expected inputs, including user inputs and other states' outputs.</td><td></td></tr><tr><td>inputs.[input_name]</td><td>Input or Expression (Required)</td><td>Specification about each input.</td><td>{"type" : "IM", "user_input": true}</td></tr><tr><td>tasks</td><td>SupportModule[] (Optional)</td><td>Tasks executed in written order, involving no control ability such as if/else and loop.<br><br>Each element is configuration for supported modules, including LLMModule, LLMFunctionModule and TtsModule for now.</td><td></td></tr><tr><td>outputs</td><td>Object (Optional)</td><td>Output values, including state's outputs and modification to parent automata's context, if it has a parent automata.</td><td></td></tr><tr><td>outputs.[output_name]</td><td>Variable or Expression (Required)</td><td>Usually its an expression evaluating an intermediate variable.</td><td>{"context.prompt" : "{{reply}}"}</td></tr><tr><td>render</td><td>RenderConfig (Optional)</td><td>Controls how to display the result to the user.</td><td>{"text": "{{reply}}", "buttons": ["context": "Chat", "on_click": "start_chat"]}</td></tr><tr><td>transitions</td><td>Object (Optional)</td><td><p>Indicates how state flows responding to user action. transitions's keys are events which the state will handle, including events triggered by itself or its children states if its children states don't handle this event. <br><br>We treat both actual happened events and user intents as events.</p><p><br>AtomicState can trigger special events, including CHAT, ALWAYS</p></td><td></td></tr><tr><td>transitions[event]</td><td>Transition (Required)</td><td>It could simply a target state name, or a TransitionCase object.</td><td>{"start_chat" : {"target": "chat_page"}}</td></tr></tbody></table> Example: ```json { "inputs": { "user_input": { "type": "IM", "user_input": true } }, "tasks": [ { "module_type": "LLMFunctionModule", "module_config": { "model": "gpt-35-turbo-16k", "system_prompt": "{{context.system_prompt}}", "user_prompt": "{{context.prefix_prompt}}\n{{user_input}}\n{{context.suffix_prompt}}", "function_name": "reply_to_user", "function_description": "Generate reply to user.Always use this function.", "function_parameters": [ { "name": "reply", "type": "string", "description": "This is your reply to user. AWAYS IN ENGLISH" } ] } }, { "module_type": "TtsModule", "module_config": { "content": "{{reply}}", "tts_id": "2", "output_name": "reply_voice" } } ], "render": { "text": "{{reply}}", "audio": "{{reply_voice}}", "buttons": [ { "content": "Return", "description": "", "on_click": "return" } ] }, "transitions": { "CHAT": {}, "create_scenario": "new_scenario" } } ``` ## Inputs Each `Input` signifies that a variable is required for the state to function, and it is typically provided by user input. If there is user input whose type is not `"IM"`, then a transition to this state would prompt the opening of a modal, allowing the user to complete the input form. The primary distinction between `Input` and `Output` in this context is that `Input` generally includes additional fields that govern how the user should complete the input form. These fields could include things like data validation rules, default values, or specific instructions for the user, which provide guidance on the expected form and content of the input. `Output`, in contrast, typically refers to the information that is conveyed back to the user after processing their input or completing a particular state transition. `Input` | Field's Name | Type (Required/Optional) | Description | Example | | -------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | | type | "text" \| "image" \| "audio" \| ”IM" (Required) | The type of a given variable. "IM" refers to input that originates from the user's bot Instant Messaging interface. | "text" | | value | string (Optional) | <p>The value of a given variable. The type of the value depends on the type field. For text, value could be any string. For image, audio, value is string of URL. ForIM, value is usually undefined. <br>If the transition to the state specifies target\_inputs, value won’t be overridden.</p> | "Hello, World!" or "<https://example.com/audio.mp3>" | | default\_value | string (Optional) | <p>The default value of an input variable, which is used when no value is given. The type is same as value.<br>If the transition to the state specifies target\_inputs, default\_value will be overridden.</p> | "{{prompt}}" | | user\_input | Boolean (Optional) | An optional flag that indicates whether the input should come from the user. Defaults to false. | true | | name | string (Optional) | An optional string that serves as a label for the form input. | "username" | | description | string (Optional) | An optional string that serves as a description for the form input. | "Input your username here." | | choices | string\[] (Optional) | Allow users to select the value from given choices. | \["GPT", "Gemini"] | | validations | Validation\[] (Optional) | <p>Allow users to specify how this input should be validated. The validators are processed one by one. The first failed validation will produce corresponding error message. <br>If not specified, it is equivalent to set to <code>\[{"required": true}]</code></p> | \[{"required": false}, {"max\_length": 100}] | `Validation` | Field's Name | Type (Required/Optional) | Description | Example | | --------------- | ------------------------ | -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | | required | boolean (Optional) | Defaults to `true`. If set to `false`, the input is optional. | | | max\_length | number (Optional) | <p>The character limitation for a <code>text</code> input. <br>Defaults to 1500.</p> | "Hello, World!" or "<https://example.com/audio.mp3>" | | max\_file\_size | number (Optional) | The file size (in bytes) limitation for file-type inputs including `image`, `audio`, `video` and `file`. | 10 \* 1024 \* 1024 | | max\_number | number (Optional) | The max number for number and integer inputs. | 1500 | | min\_number | number (Optional) | The min number for number and integer inputs. | -1 | | error\_message | string (Optional) | (Coming soon) The error message the user would see when validation fails. | | ## Tasks We support LLM module, LLM Function module and TTS module for now. More kinds of modules and customized modules are coming very soon. To fully understand the configuration of these modules, you should refer to the [Modules](/create/pro-config-mode/basic/modules) section where detailed information about each module, including their inputs, outputs, and functionality, is provided. **Important Update**: In previous versions, we supported the `Object` type for defining `tasks`. Please be aware that the execution order cannot be guaranteed for the `Object` type and it will become deprecated in a future release. It is recommended to transition to using the `Array` type to ensure the execution order of `tasks`.&#x20; ## Outputs Currently, the use of context is necessary to store any output variables, as they are fundamentally kept within the parent automata's scope. However, in a few days, we will introduce support for isolated output variables that can be accessed through a prefix tied to the state name. `Variable` is a subset of `Input`, only including `type` and `value` fields. `Variable` | Field's Name | Type (Required/Optional) | Description | Example | | ------------ | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | | type | "text" | "image" | "audio" | | value | string (Optional) | The value of a given variable. The type of the value depends on the type field. For text, value could be any string. For image, audio, value is string of URL. ForIM, value is usually undefined. For expression, value is Expression. | "Hello, World!" or "<https://example.com/audio.mp3>" | ## Render `RenderConfig` is responsible for defining how a bot presents the results executed by a state to the user. It can specify content of the result, whether it's a text message, an audio message, or interactive buttons that facilitate transitions to different states or prompt further user interaction. `RenderConfig` | Field's Name | Type (Required/Optional) | Description | Example | | ------------ | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | | text | string (Optional) | The text that would be displayed on the render. | "This is the render text." | | image | string (Optional) | A URL string to an image that would be displayed on the render. | "<https://example.com/image.jpg>" | | audio | string (Optional) | A URL string to an audio file that would be played on the render. | "<https://example.com/audio.mp3>" | | buttons | Button\[] \| Button\[]\[] (Optional) | <p>An array or a matrix of Button objects that may appear on the render for interactive purposes.<br>If set as a matrix, each array of buttons will be displayed in a single row.</p> | | `Button` | Field's Name | Type (Required/Optional) | Description | Example | | ------------ | -------------------------- | ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | content | string (Required) | The visible text displayed on the button. | "Click Me" | | description | String (Optional) | A tooltip that appears when you hover over the button. | "This button triggers the next part of the process" | | on\_click | string \| Event (Required) | Defines the event that should be triggered when the button is clicked. You can pass data to Transition if needed. | "start\_chat" | `Event` | Field's Name | Type (Required/Optional) | Description | Example | | ------------ | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | | event | string (Required) | The event name. | "create\_page" | | payload | Object (Optional) | When triggering an event, you may pass data to the TransitionCase by setting values in payload. In TransitionCase , passed data can be accessed by the prefix `payload.` . | | # Transition The `Transition` type can be one of the following: * `string`: In this simplest case, the agent will transition to the provided target state. * `TransitionCase`: The agent will transition to the target state only if the `condition` is evaluated as `true`. The capability for a state to transition to any other state, including itself, hinges on being able to reference a target state, which can be done through either absolute indexing or relative indexing. Here's a bit more detail: * **Relative Indexing:** This method allows navigation amongst states in relation to the current state: * `sibling` refers to another state at the same level as the current one. * `.child` specifies a sub-state of the current state. * `sibling.child.grandchild` indicates a more complex path from a state at the same level to a grandchild state. * **Absolute Indexing:** This approach uses a unique identifier to directly reference any state, regardless of the current state: * `#id` directly points to a state with the specified identifier. * `#id.child` combines the use of an identifier with relative paths to specify a state that is a child of the identified state. This structure provides great flexibility in the flow control within an agent, permitting intricate navigation across the states depending on the desired agent behavior or user interactions. `TransitionCase` <table><thead><tr><th>Field's Name</th><th width="230">Type (Required/Optional)</th><th width="260">Description</th><th>Example</th></tr></thead><tbody><tr><td>target</td><td>string (Optional)</td><td>The target state to which the agent will transition. If not specified, the agent will transition to the current (self) state. Applies to TransitionCase type only.</td><td>"next_state"</td></tr><tr><td>condition</td><td>BoolExpression (Optional)</td><td>A condition that must be evaluated as true for the agent to transition to the target state. If not specified, the condition is treated as true. Applies to TransitionCase type only.</td><td></td></tr><tr><td>target_inputs</td><td><code>Object</code> (Optional)</td><td>Specify the value for the inputs of target state. It will override the default value of the input, but not the value of the input.</td><td></td></tr></tbody></table> `TransitionCase[]` The agent will evaluate the conditions of each `TransitionCase` in the given array one by one. It will transition to the target state of the first `TransitionCase` whose `condition` is satisfied. # Automata `Automata` shares many fields with `AtomicState`. It differs by: * the lack of `properties.is_chat_allowed` and `tasks` fields. * the different special event it can handle * `initial` , `states` and `context` fields. `Automata` (only difference) | Field's Name | Type (Required/Optional) | Description | Example | | ------------------------ | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | | type | "automata" (Optional) | Indicates the type of structure, which here would be 'automata'. | 'automata' | | context | Object (Optional) | These are variables that are shared among all child states. These can be of type Variable. The key should be in lowercase, snake\_case format. | { "prompt": { "type": "text" } } | | context\[variable\_name] | Variable (Required) | Variable can have an initial value or just a specified type. | { "type": "text", value: "Welcome" } | | initial | string (Required) | This is the name of the initial state that the automata should start in. | 'initial\_state' | | states | Object (Required) | This holds all available states in the automata. Each state could be an AtomicState or Automata | | | transitions | Object (Optional) | Automata can trigger special events, including DONE. | | # Context * USER\_LANGUAGE * MYSHELL\_USER\_NAME # Module The system currently supports a powerful customizable module to utilize any widget in MyShell workshop.&#x20; Other types of modules are essentially `AnyWidgetModule` without `widget_id`. `SupportModule` | Field's Name | JSON Type (Required/Optional) | Description | Example | | -------------- | ------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | | module\_type | "AnyWidgetModule" \| “LLMModule” \| “LLMFunctionModule” \| “TtsModule” \| “GoogleSearchModule”| (Required) | The module type defines the module config. | | | module\_config | “AnyWidgetConfig" \| “LLMConfig” \| “LLMFunctionConfig” \| “TTSConfig” \| “GoogleSearchConfig” \| (Required) | The configuration takes inputs and produces a result. All module\_config have a output\_name field for the execution result. | | | name | string (Optional) | The name of the module is primarily for identification and comprehension. | ‘generate\_img\_for\_user\_reply’ | # AnyWidget Module `AnyWidgetModule` allows you to utilize any widget in our workshop. It differs from other modules. Apart from `widget_id` and `output_name`, all other fields are specific to the individual widget in use. Consequently, it is not feasible to list field descriptions in advance. However, we can offer examples using common widgets and instructions on how to determine widget configurations. Please note that the outcomes generated by the `AnyWidgetModule` are contingent on the specific widget and its underlying AI models. Therefore, we are unable to assure that the widget configuration will consistently yield the anticipated results with your setup. We advise fine-tuning the parameters on the widget webpage and subsequently incorporating them into your Pro Config settings for optimal results. <figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FgNq0wqzGy6TeKbXeKAaq%2Fmelo_tts.png?alt=media&amp;token=2eeb0d59-7124-4f9a-b72f-4f20aaf0f5
프로젝트로 돌아가기