去中心化全栈瓜

devgua

MyShell Advanced - Introduction to Pro Config

Preface#

myshell

First, I would like to recommend an introductory tutorial on MyShell by Jiao Ge from the Robot community, titled “MyShell Tool Bot Creation Guide”.

This tutorial provides a guide on how to create tool bots on the MyShell platform. MyShell is a decentralized generative AI creator platform that offers various AI large models for users to use for free. The author shares their experience transitioning from ChatGPT to MyShell, highlighting the advantages of MyShell, including free access to multiple AI large models, avoiding account suspension risks, earning points rewards, community support, and cost savings. The article also introduces how to write effective prompts, define roles, rules and workflows, as well as how to choose models and enhance prompts.

Additionally, Jiao Ge shares some of the tool bots they have created, providing advice on how to test, promote, and look forward to the future. Finally, the article discusses prompt writing techniques for the Claude3 model, including the use of XML tags and marking input variables.

When we use MyShell to create character bots, mastering the above content can generally help us achieve our character goals. However, the downside is that AI is uncontrollable in many processes, and when building a bot, we also need some program logic to help us control the bot's interactions with users.

Thus, this article will formally discuss the Pro Config mode. This mode will balance programming logic with flexible interactions of AI prompt logic.

Hello World#

First Example#

Since the Pro Config mode is quite similar to programming logic, it is hoped that you have some coding foundation so that you can quickly grasp the JSON description of Pro Config and implement development.

We will quickly conduct a Hello World practice in the habit of a coder.

{
  "type": "automata",
  "id": "hello_demo",
  "initial": "home_page_state",
  "inputs": {},
  "outputs": {},
  "transitions": {},
  "states": {
    "home_page_state": {
      "inputs": {},
      "tasks": [],
      "outputs": {},
      "render": {
        "text": "Hello World! Welcome to this demo. Click 'Start' to chat!",
        "buttons": [
          {
            "content": "Start",
            "description": "Click to Start.",
            "on_click": "start_demo"
          }
        ]
      },
      "transitions": {
        "start_demo": "home_page_state"
      }
    }
  }
}

By inputting the above configuration into our bot's developer mode, we will achieve the following effect:

image

Now, let’s explain the meaning of the above JSON:

  • First, we define this segment of JSON as an automaton (Automata), and in Pro Config, each automaton can be defined using JSON;
  • In this automaton, we define what kind of text the bot needs to output, i.e., the text field; we define a Button, and in the on_click automaton, we define what state it will transition to when clicked;

Thus, we have completed the writing of the Hello World example for the Pro Config mode.

Atomic State and Automata#

In the Hello World example above, we have roughly understood what an automaton is. In summary, it is an abstraction used to control the bot to enter different states.

Next, let’s introduce the concept of Atomic State. To put it simply, it describes the relationship with automata as an automaton can contain different atomic states. If the automaton is used to describe the switching relationships between different states, then the atomic state is used to describe the abstraction of a certain complex state.

Here we will briefly understand this concept, and it will be introduced in detail when used later.

Of course, if you want to learn more, you can directly refer to MyShell's official documentation.

Defining Inputs/Outputs#

In the Hello World example above, we defined the atomic state with the text field and the Button field, and we see that there are other fields as well.

image

Now, let’s introduce the roles of the inputs and outputs fields.

Talk is cheap, let’s look at the following code directly:

{
  "type": "automata",
  "id": "hello_demo",
  "initial": "home_page_state",
  "inputs": {},
  "outputs": {},
  "transitions": {},
  "states": {
    "home_page_state": {
      "inputs": {
        "intro_message": {
          "type": "text",
          "user_input": true,
          "default_value": "Hi, this is your Pro Config Tutorial Bot"
        },
        "tts_widget_url": {
          "type": "text",
          "user_input": true,
          "default_value": "https://app.myshell.ai/widget/mEjUNr"
        }
      },
      "tasks": [],
      "outputs": {
        "intro_message": "{{intro_message}}",
        "voice_id": "{{tts_widget_url}}"
      },
      "render": {
        "text": "Hello Word! Welcome to this demo. Click 'Start' to chat!",
        "buttons": [
          {
            "content": "Start",
            "description": "Click to Start.",
            "on_click": "start_demo"
          }
        ]
      },
      "transitions": {
        "start_demo": "home_page_state"
      }
    }
  }
}

Replacing the previous Hello World code with this code, we will find that after the user clicks the Start Button, an interactive form will pop up:

image

This form is the effect we achieved through the above code. Let’s interpret some key parts of the code:

  • inputs: Here we set two fields, intro_message and tts_widget_url, which are actually the titles of the two text boxes for input. The type field is text, indicating this is a text box, user_input indicates whether user input is required, and default_value is the preset value.

When we set this up, after the user fills in the expression and clicks save, the input values will be saved as the variables intro_message and tts_widget_url, which we can reference in other expressions using the variable expression {{<variable>}}.

  • outputs: This variable represents the conversation content initiated by the bot based on our text template after the user fills in the expression. Just like this:

image

As we mentioned earlier, we can use {{<variable>}} to reference the variables we constructed, and there is nothing difficult about it; I believe you will understand at a glance.

MyShell officially uses double curly braces {{expression}} to wrap expressions to assign the value of output variables to them. This expression should be written in JavaScript, following the ECMAScript 5.1 standard, as MyShell currently only supports this version.

Building Workflows#

Creating a Chatbot#

In Pro Config, workflows can connect multiple modules to handle the events we need to process. Below, we will use a chatbot example to explain how to use workflows.

{
  "type": "automata",
  "id": "chat_demo",
  "initial": "chat_page_state",
  "inputs": {},
  "outputs": {},
  "transitions": {},
  "states": {
    "chat_page_state": {
      "inputs": {
        "user_message": {
          "type": "IM",
          "user_input": true
        }
      },
      "tasks": [
        {
          "name": "generate_reply",
          "module_type": "AnyWidgetModule",
          "module_config": {
            "widget_id": "1744214024104448000",
            "system_prompt": "You are a teacher teaching Pro Config.",
            "user_prompt": "{{user_message}}",
            "output_name": "reply"
          }
        },
        {
          "name": "generate_voice",
          "module_type": "AnyWidgetModule",
          "module_config": {
            "content": "{{reply}}",
            "widget_id": "1743159010695057408",
            "output_name": "reply_voice"
          }
        }
      ],
      "render": {
        "text": "{{reply}}",
        "audio": "{{reply_voice}}"
      },
      "transitions": {
        "CHAT": "chat_page_state"
      }
    }
  }
}

This code will implement a Pro Config Teacher role.

image

Workflow Analysis#

Let’s explain each module one by one:

"inputs": {
  "user_message": {
    "type": "IM",
    "user_input": true
  }
}

In the inputs module, we define type as IM, which means instant messaging type. This type indicates that the bot can accept input in the form of messages sent to the bot.

"transitions": {
  "CHAT": "chat_page_state"
}

Next, let’s look at the definition of state transitions in transitions. Here, we set the event CHAT directly to the previously defined chat_page_state. This means that when the user sends a message in the chat, the state will be re-evaluated, and the sent message will be passed as input to this state. Then, user_message will be passed to the task.

"tasks": [
  {
    "name": "generate_reply",
    "module_type": "AnyWidgetModule",
    "module_config": {
      "widget_id": "1744214024104448000",
      "system_prompt": "You are a teacher teaching Pro Config.",
      "user_prompt": "{{user_message}}",
      "output_name": "reply"
    }
  },
  {
    "name": "generate_voice",
    "module_type": "AnyWidgetModule",
    "module_config": {
      "content": "{{reply}}",
      "widget_id": "1743159010695057408",
      "output_name": "reply_voice"
    }
  }
]

Next, let’s look at the tasks section. This part contains multiple modules to be executed. For each module, we need to specify module_type and module_config. The name is an optional field and not required.

For demonstration, in the first task, we provided a preset prompt - "You are a teacher teaching Pro Config.", giving this prompt to our bot to specify its role.

In the second task, we want to send a voice reply. At this point, we can use MyShell's TSS Widget to set up a voice response. If you have a preferred TSS voice you want to use, you can find it in MyShell's workshop and simply introduce it using its widget_id.

image

Here, I briefly introduced two modules used for replies. If you are interested in modules for handling events, you can visit the official documentation to study the module modules.

After both tasks are completed, two variables reply and reply_voice will be generated according to our definition and presented to the user as follows:

"render": {
  "text": "{{reply}}",
  "audio": "{{reply_voice}}"
}

Throughout the process, we note that the bot also implicitly handles a "black box" event - the special event CHAT. It is precisely because this special event is executed that it can transition to chat_page_state according to our rules and execute the corresponding tasks.

I believe that through this example, you have a general understanding of the entire workflow of using Pro Config bots. Once you learn this, you can start writing your own bots and implement a general processing framework.

Summary#

Through this article, we have learned the basic concepts and application methods of the Pro Config mode on the MyShell platform. Through a Hello World example and a chatbot example, we demonstrated how to use automata and atomic states in the Pro Config mode to control the bot to enter different states and handle user inputs and outputs. Through these examples, we can not only quickly get started with the Pro Config mode but also gain a deeper understanding of its working principles.

In the next article, we will continue to discuss some detailed fields, such as how to specifically define transitions, the specific usage of expressions and variables, how to integrate other widgets, and so on. Let’s encourage each other.

Reference#


Additionally, we hope more developers will participate in the co-construction of MyShell's Bot market. The invitation link click here. More Airdrop activities will be waiting for you to participate in the future.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.