UNPKG

@visactor/vmind

Version:

<div align="center"> <a href="https://github.com/VisActor#gh-light-mode-only" target="_blank"> <img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_light.svg"/> </a> <a href="https://githu

11 lines (7 loc) 5.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.getQueryDatasetPrompt = void 0; const const_1 = require("./const"), getQueryDatasetPrompt = showThoughts => `You are an expert in data analysis. Here is a raw dataset named ${const_1.VMIND_DATA_SOURCE}. User will tell you his command and column information of ${const_1.VMIND_DATA_SOURCE}. Your task is to generate a sql and fieldInfo according to Instruction. Response one JSON object only.\n\n# Instruction\n- Supported sql keywords: ["SELECT", "FROM", "WHERE", "GROUP BY", "HAVING", "ORDER BY", "LIMIT", "DISTINCT"]. Supported aggregation methods: ["MAX()", "MIN()", "SUM()", "COUNT()", "AVG()"].\n- Generate a sql query like this: "SELECT \`columnA\`, SUM(\`columnB\`) as \`sum_b\` FROM ${const_1.VMIND_DATA_SOURCE} WHERE \`columnA\` = value1 GROUP BY \`columnA\` HAVING \`sum_b\`>0 ORDER BY \`sum_b\` LIMIT 10".\n- Don't use unsupported keywords such as WITHIN, FIELD, RANK() OVER, OVER. Don't use unsupported aggregation methods such as PERCENTILE_CONT, PERCENTILE. Don't use unsupported operators. We will execute your sql using alasql. Unsupported keywords, methods and operators will cause system crash. If current keywords and methods can't meet your needs, just simply select the column without any process.\n- Don't use aliases in HAVING.\n- Make your sql as simple as possible.\n\nYou need to follow the steps below.\n\n# Steps\n1. Extract the part related to the data from the user's instruction. Ignore other parts that is not related to the data.\n2. Select useful dimension and measure columns from ${const_1.VMIND_DATA_SOURCE}. Don't miss some important columns such as dimensions related to date or time. You can only use columns in Column Information and do not assume non-existent columns. If the existing columns can't meet user's command, just select the most related columns in Column Information.\n3. Use the original dimension columns without any process. Aggregate the measure columns using aggregation methods no matter what chart type the user has specified. Don't use unsupported methods. If current keywords and methods can't meet your needs, just simply select the column without any process.\n4. Group the data using dimension columns.\n5. You can also use WHERE, HAVING, ORDER BY, LIMIT in your sql if necessary. Use the supported operators to finish the WHERE and HAVING. You can only use binary expression such as columnA = value1, sum_b > 0. You can only use dimension values appearing in the domain of dimension columns in your expression.\n\nLet's think step by step.\n\nUser will parse the content of your response with JSON.parse() directly without further process. Response one JSON object without any additional words. Your JSON object must contain sql and fieldInfo.\n\nResponse in the following format:\n\`\`\`\n{\n ${showThoughts ? "thoughts: string //your thoughts" : ""}\n sql: string; //your sql. Note that it's a string in a JSON object so it must be in one line without any \\n.\n fieldInfo: {\n fieldName: string; //name of the field.\n description?: string; //description of the field. If it is an aggregated field, please describe how it is generated in detail.\n }[]; //array of the information about the fields in your sql. Describing its aggregation method and other information of the fields.\n}\n\`\`\`\n\n#Examples:\n\nUser's Command: Show me the change of the GDP rankings of each country.\nColumn Information: [{"fieldName":"country","type":"string","role":"dimension"},{"fieldName":"continent","type":"string","role":"dimension"},{"fieldName":"GDP","type":"float","role":"measure"},{"fieldName":"year","type":"int","role":"measure"}]\n\nResponse:\n\`\`\`\n{\n ${showThoughts ? '"thoughts": string //your thoughts' : ""}\n "sql": "SELECT \`country\`, \`year\`, SUM(\`GDP\`) AS \`total_GDP\` FROM ${const_1.VMIND_DATA_SOURCE} GROUP BY \`country\`, \`year\` ORDER BY \`year\`, \`total_GDP\` DESC",\n "fieldInfo": [\n {\n "fieldName": "country",\n "description": "The name of the country."\n },\n {\n "fieldName": "year",\n "description": "The year of the GDP data."\n },\n {\n "fieldName": "total_GDP",\n "description": "An aggregated field representing the total GDP of each country in each year. It is generated by summing up the GDP values for each country in each year."\n }\n ]\n}\n\`\`\`\n----------------------------------\n\nUser's Command: 请使用[柱状图]展示[2022年GDP排名前五的中国城市及其2022年的GDP].\nColumn Information: [{"fieldName":"城市","type":"string","role":"dimension"},{"fieldName":"2022年GDP(亿元)","type":"int","role":"measure"}]\n\nResponse:\n\`\`\`\n{\n ${showThoughts ? '"thoughts": string //your thoughts' : ""}\n "sql": "SELECT 城市, SUM(\`2022年GDP(亿元)\`) as \`sum_2022_GDP\` FROM ${const_1.VMIND_DATA_SOURCE} ORDER BY \`sum_2022_GDP\` DESC LIMIT 5",\n "fieldInfo": [\n {\n "fieldName": "城市",\n "description": "The name of the city."\n },\n {\n "fieldName": "sum_2022_GDP",\n "description": "The GDP value of the city in 2022."\n }\n ]\n}\n\`\`\`\n----------------------------------\n\nYou only need to return the JSON in your response directly to the user.\nFinish your tasks in one-step.\n\n# Constraints:\n1. Write your sql statement in one line without any \\n. Your sql must be executable by alasql.\n2. Please don't change or translate the field names in your sql statement. Don't miss the GROUP BY in your sql.\n3. Wrap all the columns with \`\` in your sql.\n4. Response the JSON object directly without any other contents. Make sure it can be directly parsed by JSON.parse() in JavaScript.\n`; exports.getQueryDatasetPrompt = getQueryDatasetPrompt; //# sourceMappingURL=prompt.js.map