MyShell 백서

MyShell

원문

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

kip during the workflow. When a widget is set to cache mode, it will be called only once and store the outputs in our database. If the `module_config` is not changed, further calling the widget will simply return the previously stored outputs and cost zero battery. The cache mode is very useful when you are building the workflow. The `cache` flag can be set either in the `automata` (when you want to use cache in the whole Pro Config) or in `state` (when you want to use cache in a specific state) or the `module_config` (when you want to debug a specific module). Note that the priority of the `debug` flag is `module_config > state > automata` , which means the value of `cache` set in the former would overwrite that in the latter. Taking the simple demo in [Building Workflow](/ko/create/pro-config-mode/tutorial/building-workflow) as an example: ```json { "type": "automata", "id": "chat_demo", "initial": "chat_page_state", "properties": { "cache": true }, "states": { "chat_page_state": { "inputs": { "user_message": { "type": "IM", "user_input": true } }, "tasks": [ { "name": "generate_reply", "module_type": "AnyWidgetModule", "module_config": { "widget_id": "1744214024104448000", // GPT 3.5 "system_prompt": "You are a teacher teaching Pro Config.", "user_prompt": "{{user_message}}", "output_name": "reply", "cache": true } }, { "name": "generate_voice", "module_type": "AnyWidgetModule", "module_config": { "widget_id": "1743159010695057408", // TTS widget (Samantha) "content": "{{reply}}", "output_name": "reply_voice", "cache": true } } ], "render": { "text": "{{reply}}", "audio": "{{reply_voice}}" }, "transitions": { "CHAT": "chat_page_state" } } } } ``` here the two modules are set into cache mode and how it becomes: <figure><img src="https://github.com/myshell-ai/myshell_gitbook_doc/blob/main/MyShell/product-manual/create/pro-config-mode-beta/.gitbook/assets/image%20(22).png" alt=""><figcaption></figcaption></figure> We can see that both the results of LLM and TTS stay the same after the second chat. If we want to run the LLM, we can just set the debug as false: ```json { "name": "generate_reply", "module_type": "AnyWidgetModule", "module_config": { "widget_id": "1744214024104448000", // GPT 3.5 "system_prompt": "You are a teacher teaching Pro Config.", "user_prompt": "{{user_message}}", "output_name": "reply", "cache": false } }, ``` The results are as follows: <figure><img src="https://github.com/myshell-ai/myshell_gitbook_doc/blob/main/MyShell/product-manual/create/pro-config-mode-beta/.gitbook/assets/image%20(23).png" alt=""><figcaption></figcaption></figure> The response of LLM varies based on the user's input, while the output of TTS stays the same because the TTS widget is still in `cache` mode. # 지식 베이스 에이전트 Use [Knowledge Base Agent](https://app.myshell.ai/bot/n6jmQn/309) to manage knowledge bases with domain-specific data or to handle different opinions. ### Guide #### Get Started <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/EFH7ehjWZDNKTDfbPY3F/kb-list-kbs.png" alt=""><figcaption><p>List knowledge bases</p></figcaption></figure> #### Create New Knowledge Base A meaningful name is helpful for your bases. After creation, the agent will display your current knowledge bases including their names and tokens.&#x20; The token (for example, `myshell_f5ac9afa_5c1f_4ef6_ae80_2120e2b2671e` in the picture below) will be used in the [LLM Widget](/ko/create/pro-config-mode/api-reference/module/anywidget-module/llm-widget#config)' `knowledge_base_token` field.&#x20; <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/3ZO61wQ9fAzF0EGKoDBN/kb-create-base.png" alt=""><figcaption><p>Create Base</p></figcaption></figure> #### List Source and Add Source To modify sources of the new knowledge base, `List Source` button will guide to a detailed operation panel. Currently we support: * Add Gitbook links as sources * Upload files as sources * Re-sync link sources * Delete sources <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/01ksi9CvGRnmYiCgXkku/kb-list-source.png" alt=""><figcaption><p>List Source</p></figcaption></figure> #### Upload File as Source You can upload text files or PDF files as sources. Text files include md, txt, csv and json. {% hint style="info" %} Other text file types can be converted to supported types. Widgets like [MS Word to Markdown](https://app.myshell.ai/widget/jQBbEv) might be helpful. {% endhint %} <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/WU2XZRbI63xrJjQGcAn6/kb-add-text-source.png" alt=""><figcaption><p>Upload text file</p></figcaption></figure> #### Add Gitbook Link as Source Currently we only support Gitbook web pages as knowledge base sources. For Gitbook links, we will fetch the target page and all its subpages. {% hint style="info" %} If the page is updated, you can click `Re-Sync Source` button to update the source. {% endhint %} <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/wuJ4YSxR54iYZXkQPPSZ/kb-add-gitbook-source.png" alt=""><figcaption><p>Gitbook Link</p></figcaption></figure> #### Refresh after Processing After adding a source, the agent will tell you that it is being processed. <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/inwvQZLnft0lP0z4R32G/kb-processing-source.png" alt=""><figcaption><p>Processing</p></figcaption></figure> You can refresh to see if it's ready to use. <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/vTRckaFgtRosAYYCJJ7a/kb-refresh-status.png" alt=""><figcaption><p>Refresh</p></figcaption></figure> #### Use in Widgets When sources are ready, you can copy the knowledge base's token and configure the LLM widget. Note the `"knowledge_base_token"` field in the widget config. ```json { "id": "llm_widget_template", "initial": "home_state", "states": { "home_state": { "inputs": { "input_message": { "type": "IM", "user_input": true } }, "tasks": [ { "name": "llm_widget_example_task", "module_type": "AnyWidgetModule", "module_config": { "widget_id": "1744214047475109888", "user_prompt": "{{input_message}}", // the text inputted into prompt widget, you can get it from user input or upper state "system_prompt": "Act as ...", // Optional field. You can input system prompt of agent. "top_p": 0.5, // Optional field. Default value is 0.5 "temperature": 0.5, // Optional field. Default value is 0.5 "frequency_penalty": 0, // Optional field. Default value is 0 "presence_penalty": 0, // Optional field. Default value is 0 "knowledge_base_token": "", // Your token here "output_name": "result" } } ], "render": { "text": "{{result}}", // it's a string produced by prompt widget. "buttons": [ { "content": "Chat Again", "description": "", "on_click": "rerun" } ] }, "transitions": { "rerun": "home_state", "CHAT": "home_state" } } } } ``` # 크롤러 위젯 In this section, we will build a webpage summarizer agent utilizing the Crawler widget in pro config. The crawler widget is used to crawl webpages and get raw content of a webpage. We can then pass on this content to LLMs like GPT-3.5 or GPT-4 to summarize it into a couple of paragraphs. Before we build the summarizer using pro config, let’s take a look at the Crawler widget specifically. ## **Using the Crawler Widget** Head to the [**Crawler widget page**](https://app.myshell.ai/robot-workshop/widget/1781991963803181056) on MyShell app. You should see a screen similar to the following: <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/r0kc1Uewrc4K5XUwfmKn/image.png" alt=""><figcaption></figcaption></figure> Crawler widget page on MyShell. Now, click on **Start** and you should see a form similar to the following: <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/m7UJMd31881DHbUy6Nnq/image.png" alt=""><figcaption></figcaption></figure> Input form for Crawler widget. Enter an URL. For example, we have entered “[**https://docs.myshell.ai**](https://docs.myshell.ai)**”** which is MyShell documentation website homepage. Now, click on **Generate**. After a few seconds of loading, you should see a response similar to the following: <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/fZNdYi3LFgFfXJOKTZj8/image.png" alt=""><figcaption></figcaption></figure> Response from the Crawler widget. This doesn’t look pretty. Worry not! We just wanted to show you how the response of the Crawler widget looks like. Looking at it, it’s a JSON with a markdown\_string property with the content and other details of the webpage. It’s always a good practice to see how a widget responds before using it in pro config. Now, let’s use this widget in pro config and use an LLM to summarize this JSON for us. ## **Using Crawler widget in Pro Config** The usage for this widget in pro config is quite simple, as the only input for this widget is the URL, so the module configuration for using this widget should look like this: ```json { "widget_id": "1781991963803181056", "url": "&lt;url_goes_here&gt;", "output_name": "&lt;variable_name_goes_here&gt;" } ``` Now, let's use this configuration in a pro config boilerplate: ```json { "type": "automata", "id": "web-page-summarizer", "initial": "homepage", "properties": { "cache": true }, "states": { "homepage": { "inputs": { "url": { "type": "text", "user_input": true } }, "tasks": [ { "name": "crawl_website", "module_type": "AnyWidgetModule", "module_config": { "widget_id": "1781991963803181056", "url": "{{ url }}", "output_name": "crawled_content" } }, { "name": "summarize_crawled_website", "module_type": "AnyWidgetModule", "module_config": { "widget_id": "1744214047475109888", "system_prompt": "Provided is a crawled webpage, provide the user with the summary of the content of the webpage. Avoid mentioning about HTML specific things and stick to content summaries.", "user_prompt": "{{ JSON.stringify(crawled_content) }}", "output_name": "summary" } } ], "render": { "text": "{{ summary }}", "buttons": [ { "content": "Summarize another page", "on_click": "go_to_homepage" } ] }, "transitions": { "go_to_homepage": "homepage" } } } } ``` In the above code, we are doing the following: * We are using cache mode during testing, this is helpful for debugging. If you want to learn more, check the [**cache mode page in documentation**](https://myshell-wiki.gitbook.io/proconfig-tutorial/tools/cache-mode). * Asking the user for an URL to crawl using an input prompt. * Initializing the tasks, first being crawling the URL provided using the Crawler widget (widget ID: 1781991963803181056) and saving the object received as response in a variable called crawled\_content. * We are then converting this crawled\_content object to a JSON string and passing it as a user prompt to GPT-4 widget (widget ID: 1744214047475109888) and asking it to summarize the webpage for us. We are saving the output from GPT-4 in summary. * We are outputting the summary as a chat message through render. Now, if you run the pro config and pass an URL, you should see a proper summary for the URL provided (in this case, the URL provided is “[**https://docs.myshell.ai**](https://docs.myshell.ai)**”**): <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/C5OuApMB2mVOP89nXJlC/image.png" alt=""><figcaption></figcaption></figure> Response from the webpage summarizer agent. Of course, you can play around with different LLMs and optimize how they work to get better results that match your expectations. This tutorial aimed to help you get to the finish line, feel free to add levels of complexity to this agent and make the ideal webpage summarizer! ## **Conclusion** Crawler widget is a very powerful widget that allows you to access external data and process it in your pro config. # Example # Function Calling Example 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. > ### [&#xD;](<https://www.promptingguide.ai/applications/function_calling&#xD;&#xA;&#xD;&#xA;https://platform.openai.com/docs/api-reference/chat/create>)Reference > > <https://www.promptingguide.ai/applications/function_calling> > > <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": [ { "type": "string", "name":"question", "description": "the question" }, { "type": "array", "name":"choices", "items": { "type": "string" }, "description": "the choices, must contain 4 choices, format should be A. xxx, B. xxx, C. xxx, D.xxx" }, { "type": "string", "name":"answer", "description": "the answer, must chosen from A/B/C/D" }, { "type": "string", "name":"explanation", "description": "the 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": { "event": "check_answer", "payload": { "button_id": "A" } } }, { "content":
프로젝트로 돌아가기