bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 53쪽
lty": 0,
"presence_penalty": 0,
"output_name": "result"
}
}
],
"outputs": { "context.llm_result": "{{result}}" },
"transitions": { "ALWAYS": "post_llm_state" }
},
"llm_b_state": {
"tasks": [
{
"name": "slerp_l2_13b",
"module_type": "LlmWidgetModule",
"module_config": {
"widget_id": "1744214446286311424",
"system_prompt": "You are an annoying tsundere assistant.",
"user_prompt": "{{context.user_prompt}}",
"memory": "",
"top_p": 1.0,
"temperature": 0.75,
"frequency_penalty": 0,
"presence_penalty": 0,
"output_name": "result"
}
}
],
"outputs": { "context.llm_result": "{{result}}" },
"transitions": { "ALWAYS": "post_llm_state" }
},
"llm_c_state": {
"tasks": [
{
"name": "airoboros_70b",
"module_type": "LlmWidgetModule",
"module_config": {
"widget_id": "1744214372646916096",
"system_prompt": "You are a cool dude answering the user with swag.",
"user_prompt": "{{context.user_prompt}}",
"memory": "",
"top_p": 1.0,
"temperature": 0.5,
"frequency_penalty": 0,
"presence_penalty": 0,
"output_name": "result"
}
}
],
"outputs": { "context.llm_result": "{{result}}" },
"transitions": { "ALWAYS": "post_llm_state" }
},
"post_llm_state": {
"render": {
"text": "{{context.llm_result.trim().replace(/[áàãâäå]/g, 'a').replace(/ç/g, 'c').replace(/ð/g, 'd').replace(/éèêë/g, 'e').replace(/íìîï/g, 'i').replace(/ñ/g, 'n').replace(/óòôöõø/g, 'o').replace(/úùûü/g, 'u').replace(/ýÿ/g, 'y').replace(/æ/g, 'ae').replace(/œ/g, 'oe').replace(/ß/g, 'ss')}}"
},
"transitions": {
"CHAT": "chat_state"
}
}
}
}
```
In the above config, we first define two context variables in the automata, **`user_prompt`** and **`llm_result`**. We use these to pass information across states. Since we split up our "functions" with states for maintainability and future extendability, we have to use such variables.
The **`home_state`** is basic and self-explanatory. After the user chats in the home state, we move to the **`chat_state`**. In this state, we process the user input, set up the **`context.user_prompt`** variable, and finally jump to the state that initiates the random selection, **`random_llm_state`**. Note that the **`random_llm_state`** only does one thing, and that's the selection. This is because if we ever needed the random LLM from another state we could just jump to it, like grouping a function.
#### **The random chooser state**
The **`random_llm_state`** first uses an output variable to set the random number to. Note that **this is important** not just to avoid repeating the formula on each condition, but because we must generate one random number **once** and then use it in every condition, the same random number. We use an output instead of an input since transition conditions can't use inputs.
In the random generation formula we do a simple scaling to the number of LLMs we have. **`Math.random()`** generates a random number between 0 (inclusive) and 1 (exclusive), so we multiply it by 3 since we have 3 LLMs, so now it's between 0 and 3. This makes it easier to choose in the conditions.
Remember that the conditions are executed sequentially, so even though the second condition (rng<2) is also true when the number is 0, it must "pass" the first condition first to arrive there, so it is fine. This scheme makes it easier to conditionally exclude some LLMs depending on factors such as them not being suitable for certain scenarios; you can just add the condition at the end such as **`rng<2 && some_other_condition`**.
#### **The LLM states**
Each LLM has its own state, and is chosen by **`random_llm_state`**. The job of these states is strictly to process the user input with the given LLM, and store the result into the **`context.llm_result`** context variable. Nothing more. Note how these states are simply chained together via ALWAYS transitions, which enables us to plug them in various ways and avoid repeating ourselves.
The LLM states then jump to the post-processing state, **`post_llm_state`**, where we do a simple post process before going back to chat.
#### **The post-processing state**
**`post_llm_state`** comes after the LLM states; here we post process the result stored in **`context.llm_result`** in each LLM state, by replacing some accent characters with their ASCII equivalent. This is not terribly important, it's just to illustrate a possible post-processing done in JavaScript on the LLM outputs. You can do a lot more complicated things here before presenting it to the user.
This state also renders the text that's visible to the user before waiting for chat again.
Now when you test this example:
* If you get a response that acts like a polite helpful assistant, it means Mixtral was chosen.
* If you get a response that acts like an annoying tsundere, it means Slerp was chosen.
* If you get a response that acts like a swagster, it means Airoboros was chosen.
There is no memory, so you can repeat the same message to test.
---
[Next Page](https://docs.myshell.ai/llms-full.txt/2)
# Function Calling
#### **Functional Calling can be a very useful technique to obtain structured output from an LLM. We can find detailed documentation about function-calling in the following two reference.**
> Reference
>
> [https://www.promptingguide.ai/applications/function\_calling](https://www.promptingguide.ai/applications/function_calling**)
>
> [https://platform.openai.com/docs/api-reference/chat/create](https://platform.openai.com/docs/api-reference/chat/create**)
In this section, we will provide an example of advanced usage of function calling, and we hope this can serve as a good starting point for you to write your own Pro Config.
````json
{
"type": "automata",
"id": "studymate_bot",
"initial": "home_page_state",
"inputs": {},
"outputs": {},
"context": {
"general_purpose_widget_id":"",
"advanced_task_widget_id":"",
"memory":"{{[]}}",
"note_topic":"",
"user_given_note_topic":null,
"number_of_questions":"",
"difficulty_level":"",
"questions_string_sample": "{\"question\": \"Which of the following statements is not correct? \\n A. The execution of an Automata starts from the `initial` state. \\n B. An Automata can contain multiple AtomicStates. \\n C. Each AtomicState must define both inputs and outputs. \\n D. We can define transitions in either Automata or AtomicState.\", \"answer\": \"C\", \"explanation\": \"Both inputs and outputs in an AtomicState are optional.\"}",
"questions_string_sample_another": "{\"question\": \"You are building an AutomicState, please choose the correct order of execution: \\n A. inputs -> tasks -> outputs -> render \\n B. render -> inputs -> tasks -> outputs. \\n C. tasks -> inputs -> outputs -> render. \\n D. render -> tasks -> inputs -> outputs\", \"answer\": \"A\", \"explanation\": \"The correct order is `inputs -> tasks -> outputs -> render`. Please refer to `Expressions and Variables`\"}, {\"question\": \"Which of the following expressions is not correct (assume all the variables exist)? \\n A. context.variable \\n B. variable \\n C. variable1 + variable2 \\n D. np.array(variable)\", \"answer\": \"D\", \"explanation\": \"Our expression supports JavaScript grammar.\"}",
"questions": "",
"question_idx": "",
"chosen_answer": "",
"correct_answer": "",
"correct_count": "",
"google_search_raw_result":"",
"json_regex":"{{\$$.*?\$$}}",
"json_flags":"s",
"json_match":""
},
"transitions": {
"go_home": "home_page_state",
"submit_note":"submit_note_state",
"prequiz":"pre_quiz_page",
"get_quiz":"quiz_page_state",
"continue": "continue_state"
},
"states": {
"home_page_state": {
"inputs": {
"intro_message": {
"type": "text",
"user_input": false,
"default_value": "Hi, this is your studymate chatbot"
},
"general_purpose_widget_id": {
"type": "text",
"user_input": false,
"default_value": "1744214024104448000",
"description": "widget id for the main widget(LLM)"
},
"advanced_task_widget_id": {
"type": "text",
"user_input": false,
"default_value": "1744214047475109888",
"description": "widget id for the advanced tasks widget(LLM)"
},
"topic":{
"type": "text",
"user_input": true,
"default_value": "{{context.note_topic}}"
}
},
"outputs": {
"context.general_purpose_widget_id": "{{general_purpose_widget_id}}",
"context.advanced_task_widget_id": "{{advanced_task_widget_id}}",
"context.user_given_note_topic":"{{topic}}",
"context.note_topic":"{{topic}}",
"context.question_idx": "{{0}}",
"context.correct_count": "{{0}}",
"context.json_match":"{{new RegExp(context.json_regex, context.json_flags)}}"
},
"render": {
"text": "Welcome to the Study Mate Chatbot, continue by pasting your note",
"buttons": [
{
"content": "🏠Home",
"description": "Go to back to 🏠Home",
"on_click": "go_home"
},
{
"content": "Take Quiz",
"description": "Skip submitting note and take quiz on {{topic}}",
"on_click": "prequiz"
}
]
},
"transitions": {
"CHAT": "submit_note_state"
}
},
"submit_note_state":{
"inputs": {
"user_note":{
"type": "IM",
"user_input": true
}
},
"tasks": [
{
"name": "generate_reply",
"module_type": "AnyWidgetModule",
"module_config": {
"widget_id": "{{context.general_purpose_widget_id}}",
"system_prompt": "You are a summary-giving machine, summarising notes given and also giving main key points.",
"user_prompt": "{{user_note}}",
"output_name": "reply"
}
},
{
"name": "generate_topic",
"module_type": "AnyWidgetModule",
"module_config": {
"widget_id": "{{context.general_purpose_widget_id}}",
"system_prompt": "You are a summary-giving encyclopedia, identify the topic of the given note.",
"user_prompt": "{{user_note}}",
"output_name": "note_topic"
}
},
{
"name": "generate_voice",
"module_type": "AnyWidgetModule",
"module_config": {
"content": "{{reply}}",
"widget_id": "1743159010695057408",
"output_name": "reply_voice"
}
}
],
"outputs": {
"context.note_topic":"{{note_topic}}",
"context.google_search_raw_result":"{{google_search_raw_result}}"
},
"render": {
"text": "{{reply}}",
"audio": "{{reply_voice}}",
"buttons": [
{
"content": "Quiz",
"description": "Attempt quiz on {{context.note_topic??note_topic}}",
"on_click": "prequiz"
}
]
}
},
"pre_quiz_page":{
"inputs": {
"difficulty_level":{
"type": "text",
"choices": ["easy","medium","hard"],
"default_value": "medium",
"description": "Choose the difficulty level for your quiz",
"user_input": true
},
"number_of_questions":{
"type": "text",
"default_value": "10",
"description": "Enter the number of questions you want to attempt in this quiz",
"user_input": true
}
},
"tasks": [
{
"name": "generate_multiple_choice_question",
"module_type": "AnyWidgetModule",
"module_config": {
"widget_id": "{{context.advanced_task_widget_id}}",
"system_prompt": "You are my question bank, generating dynamic {{difficulty_level}} level questions based on the topic provided, you will generate a question with several choices (as mcq test) and output it in JSON format. the format is `{'question': 'here is the question', 'choices': ['A. 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"
}
}
],
"outputs": {
"context.number_of_questions":"{{number_of_questions}}",
"context.difficulty_level":"{{difficulty_level}}",
"context.questions":"{{llm_generated_question.mcqtest}}"
},
"render": {
"text": "```json\n{{JSON.stringify(context.questions, null, 2)}}\n```",
"buttons": [
{
"content": "Start Quiz",
"description": "Start untimed quiz {{context.questions}}",
"on_click":"get_quiz"
}
]
}
},
"quiz_page_state": {
"outputs": {
"context.correct_answer": "{{context.questions[context.question_idx]['answer']}}"
},
"render": {
"text": "{{context.question_idx + 1}}. {{context.questions[context.question_idx]['question']}}",
"buttons": [
{
"content": "A.",
"description": "Choose A.",
"on_click": "check_answer",
"UNSTABLE_button_id": "A"
},
{
"content": "B.",
"description": "Choose B.",
"on_click": "check_answer",
"UNSTABLE_button_id": "B"
},
{
"content": "C.",
"description": "Choose C.",
"on_click": "check_answer",
"UNSTABLE_button_id": "C"
},
{
"content": "D.",
"description": "Choose D.",
"on_click": "check_answer",
"UNSTABLE_button_id": "D"
}
]
},
"transitions": {
"check_answer": "analyze_answer_state"
}
},
"analyze_answer_state": {
"inputs": {
"button_id": {
"type": "text",
"user_input": false,
"value": "UNSTABLE_button_id"
}
},
"outputs": {
"context.chosen_answer": "{{button_id}}",
"context.is_correct": "{{button_id == context.correct_answer}}"
},
"render": {
"text": "Check answer state."
},
"transitions": {
"ALWAYS": [
{
"target": "correct_answer_state",
"condition": "{{context.is_correct}}"
},
{
"target": "wrong_answer_state",
"condition": "{{true}}"
}
]
}
},
"correct_answer_state": {
"outputs": {
"context.question_idx": "{{(context.question_idx + 1) % context.questions.length}}",
"context.correct_count": "{{context.correct_count + 1}}"
},
"render": {
"text": "Congratulations! You have chosen the correct answer {{context.correct_answer}}",
"buttons": [
{
"content": "Continue",
"description": "continue",
"on_click": "continue"
}
]
}
},
"wrong_answer_state": {
"outputs": {
"context.question_idx": "{{(context.question_idx + 1) % context.questions.length}}"
},
"render": {
"text": "Oh No! The chosen answer is {{context.chosen_answer}}, while the correct one is {{context.correct_answer}}.",
"buttons": [
{
"content": "Continue",
"description": "continue",
"on_click": "continue"
}
]
}
},
"continue_state": {
"render": {
"text": "Click to Next Question"
},
"transitions": {
"ALWAYS": [
{
"target": "quiz_page_state",
"condition": "{{context.question_idx > 0}}"
},
{
"target": "finish_state",
"condition": "{{context.correct_count == context.questions.length}}"
},
{
"target": "review_state",
"condition": "{{true}}"
}
]
}
},
"finish_state": {
"render": {
"text": "Congratulations you scored {{context.correct_count}}/{{context.questions.length}}",
"buttons": [
{
"content": "🏠Home",
"description": "Back to Home",
"on_click": "go_home"
}
]
}
},
"review_state": {
"outputs": {
"context.memory": "{{[]}}"
},
"render": {
"text": "{{context.intro_message}}"
}
}
}
}
````
The above example is from a bot called StudyMate made by a participant of Pro Config Learning Lab. In this app, the user can input any topic and choose a difficulty level, and some quizzes can be dynamically generated accordingly. The core to parse the results into structured quizes are achieved using function-calling as:
```json
"tasks": [
{
"name": "generate_multiple_choice_question",
"module_type": "AnyWidgetModule",
"module_config": {
"widget_id": "{{context.advanced_task_widget_id}}",
"system_prompt": "You are my question bank, generating dynamic {{difficulty_level}} level questions based on the topic provided, you will generate a question with several choices (as mcq test) and output it in JSON format. the format is `{'question': 'here is the question', 'choices': ['A. 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 참조
# 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><프로젝트로 돌아가기