Report generation method, device and storage medium based on large language model
Through the report generation method based on the large language model, SQLAlchemy and large language model are used for data analysis and chart drawing, the problems of low timeliness and high thresholds for data report generation in the existing technology are solved, and the ability of users to quickly obtain professional reports is realized. .
Patent Information
- Application Number
- CN202411420705.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-10-12
AI Technical Summary
The existing data report generation scheme cannot meet the timeliness and low threshold requirements at the same time. Users need professional skills to quickly obtain data reports, resulting in low timeliness and high learning thresholds.
Using a report generation method based on a large language model, by receiving question data, using SQLAlchemy mapping tool to query the database, generate SQL query instructions, and combine it with a large language model for data analysis and chart drawing, and generate visual analysis reports, reducing data analysis and processing The threshold for reporting has increased the timeliness.
Users can quickly obtain professional visual data analysis reports without professional skills, which improves understanding of the company's business and market dynamics and solves the problems of timeliness and low thresholds.
Smart Images

Figure CN118917296B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent information generation, and in particular to a report generation method, device and storage medium based on a large language model. Background Art
[0002] Existing intelligent data analysis platforms require users to use professional skills (such as BI, basic database instructions, etc.) to configure the database. If users use visual components to assist users in light coding, it will take too long, which reduces the requirements for professional skills but increases the user's time cost.
[0003] Data reports require statistical data and chart analysis from various platforms, but data processing is too time-consuming, which will lead to low timeliness and lack of flexibility. In order to pursue the timeliness of data reports, mastering professional skills leads to a high learning threshold, which hinders the applicability of data report production. Therefore, in view of the technical problem that the existing data report generation solution cannot meet the timeliness and low threshold requirements at the same time, a new technology is needed to solve the current problem. Summary of the invention
[0004] The main purpose of the present invention is to solve the technical problem that the existing data report generation solution cannot meet the timeliness and low threshold requirements at the same time.
[0005] A first aspect of the present invention provides a report generation method based on a large language model, comprising the steps of:
[0006] Receive question data;
[0007] Based on the question data and a preset SQLAlchemy mapping tool, query a data table in a preset StarRocks database to obtain query schema meta-information, and perform query assembly processing on a preset prompt word set according to the query schema meta-information to generate SQL prompt words;
[0008] Transmitting the SQL prompt word to a preset large language model, and receiving the SQL query instruction fed back by the large language model;
[0009] Based on the SQL query instruction, data query processing is performed on the StarRocks database to obtain numerical data;
[0010] Combining the numerical data with the question data to generate parsed question words, transmitting the parsed question words to a preset large language model, and receiving text analysis data fed back by the large language model;
[0011] According to a preset visualization algorithm, the numerical data is processed by graphing to obtain graph data;
[0012] The chart data and the text analysis data are integrated and processed to generate analysis report data corresponding to the question data.
[0013] Optionally, in a first implementation of the first aspect of the present invention, the performing a chart drawing process on the numerical data according to a preset visualization algorithm to obtain the chart data includes:
[0014] Analyze the numerical data to obtain the type of display chart corresponding to the numerical data;
[0015] Based on the chart type, the numerical data is plotted to obtain chart data.
[0016] Optionally, in a second implementation of the first aspect of the present invention, analyzing the numerical data to obtain a display chart type corresponding to the numerical data includes:
[0017] Analyze the data dimension of the numerical data to obtain a data dimension vector;
[0018] Based on the data dimension vector, the type of display chart corresponding to the numerical data is obtained.
[0019] Optionally, in a third implementation of the first aspect of the present invention, the plotting of the numerical data based on the chart type to obtain the chart data includes:
[0020] According to the type of the chart, the numerical data is plotted using the pyecharts database to generate an html file;
[0021] Using Selenium components to simulate opening the HTML file and generate a simulated preview interface;
[0022] Taking a screenshot of the simulated preview interface to generate screenshot data, and uploading the screenshot data to a cloud database to obtain a storage URL address;
[0023] The stored URL address is determined as chart data.
[0024] Optionally, in a fourth implementation of the first aspect of the present invention, uploading the screenshot data to a cloud database to obtain a storage URL address includes:
[0025] The screenshot data is uploaded to the OSS database to obtain a storage URL address.
[0026] Optionally, in a fifth implementation of the first aspect of the present invention, the drawing and processing of the numerical data using the pyecharts database according to the chart type to generate an html file includes:
[0027] Based on the data structure corresponding to the chart type, encapsulating the numerical data to obtain encapsulated data;
[0028] The packaged data is drawn and processed using the pyecharts database to generate an html file.
[0029] Optionally, in a sixth implementation of the first aspect of the present invention, after receiving the question data and before querying a data table in a preset StarRocks database based on the question data and a preset SQLAlchemy mapping tool to obtain query schema meta information, the method further includes:
[0030] Analyze the question field of the question data, and determine whether the question field is a preset valid field;
[0031] When the question field is not a valid field, the processing of the question data is stopped, and abnormal question information is sent to the port corresponding to the question data;
[0032] When the question field is a valid field, the question data is marked as qualified data.
[0033] Optionally, in a seventh implementation manner of the first aspect of the present invention, after integrating the chart data and the text analysis data to generate analysis report data corresponding to the question data, the method further includes:
[0034] The analysis report data is sent to the port corresponding to the question data.
[0035] A second aspect of the present invention provides a report generation device based on a large language model, comprising: a memory and at least one processor, wherein instructions are stored in the memory, and the memory and the at least one processor are interconnected via lines; the at least one processor calls the instructions in the memory so that the report generation device based on the large language model executes the above-mentioned report generation method based on the large language model.
[0036] A third aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned report generation method based on a large language model.
[0037] In the embodiment of the present invention, natural language is used as the initial language for data processing, the SQLAlchemy mapping tool is used to operate the database, and a large language model is used as a tool for data analysis, which can lower the threshold for data analysis and processing, and at the same time improve the timeliness of users obtaining data reports. Users do not need professional skills, and can get a professional visual data analysis report very flexibly and quickly by simply asking questions, helping users to obtain more timely and accurate information about the company's relevant business conditions and market dynamics, so as to make relevant decisions more timely, solving the technical problem that the existing data report generation solution cannot meet the timeliness and low threshold requirements at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a schematic diagram of a first embodiment of a report generation method based on a large language model in an embodiment of the present invention;
[0039] Figure 2 It is a schematic diagram of a specific embodiment of step 106 of the report generation method based on a large language model in an embodiment of the present invention;
[0040] Figure 3 It is a schematic diagram of a specific embodiment of step 1061 of the report generation method based on a large language model in an embodiment of the present invention;
[0041] Figure 4 It is a schematic diagram of a specific embodiment of step 1062 of the report generation method based on a large language model in an embodiment of the present invention;
[0042] Figure 5 The figure is a schematic diagram of an embodiment of a report generating device based on a large language model in an embodiment of the present invention. DETAILED DESCRIPTION
[0043] The embodiments of the present invention provide a report generation method, device and storage medium based on a large language model.
[0044] The embodiments disclosed in the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments disclosed in the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments disclosed in the present invention are only for exemplary purposes and are not intended to limit the scope of protection disclosed in the present invention.
[0045] In the description of the embodiments disclosed in the present invention, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below.
[0046] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the report generation method based on the large language model in the embodiment of the present invention includes:
[0047] 101. Receive question data;
[0048] In this embodiment, question data is received, and the question data uses natural language "provide a report on the financial data and market share of Company X".
[0049] Furthermore, after step 101 and before step 102, the following specific implementations are also included:
[0050] 1011. Analyze the question field of the question data, and determine whether the question field is a preset valid field;
[0051] 1012. When the question field is not a valid field, stop processing the question data, and send abnormal question information to the port corresponding to the question data;
[0052] 1013. When the question field is a valid field, mark the question data as qualified data.
[0053] In steps 1011-1013, the question domain of the question data is analyzed to determine whether the question domain is a legal and valid domain. If it involves sensitive and illegal domains, the question data is stopped from being processed. For example, if you want to query and analyze the non-performing loan rate of Y Bank in a certain area, you can set it as sensitive domain and not process it, and send abnormal question information to the port corresponding to the question data. If you want to query the 10-year trade export growth data and export types of a trading company, the question data will be marked as qualified data.
[0054] 102. Based on the question data and a preset SQLAlchemy mapping tool, query a data table in a preset StarRocks database to obtain query schema meta-information, and perform query assembly processing on a preset prompt word set according to the query schema meta-information to generate SQL prompt words;
[0055] In this embodiment, SQLAlchemy is a Python ORM (object-relational mapping) tool that provides the function of mapping Python classes to database tables. The query data "Issue a report on the financial data and market share of Company X" generates corresponding query instructions for the financial data and market share of Company X based on the created and defined mapping data. Based on the query instructions, the schema meta-information of the database table is obtained from the schema meta-information in the StarRocks database, and the query SQL prompt words are assembled based on the data in the built-in prompt word set.
[0056] 103. Transmit the SQL prompt word to a preset large language model, and receive an SQL query instruction fed back by the large language model;
[0057] In this embodiment, the SQL prompt word is transmitted to the large language model, the large language model completes the construction of the SQL query instruction, and the SQL query instruction fed back by the large language model is received.
[0058] 104. Based on the SQL query instruction, perform data query processing on the StarRocks database to obtain numerical data;
[0059] In this embodiment, the SQL query instruction is an instruction that can be processed by the StarRocks database, for example:
[0060] SELECT column1, column2, ...
[0061] FROM table_Xcompany
[0062] WHERE condition;
[0063] Select the label to query the required column1 and column2 data from the set Xcompany table and obtain the data stored in the StarRocks database.
[0064] 105. Combine the numerical data and the question data to generate parsed question words, transmit the parsed question words to a preset large language model, and receive text analysis data fed back by the large language model;
[0065] In this embodiment, the analysis question words are generated by combining the data of column 1 and column 2 and the question data "Issue a report on the financial data and market share of Company X". The analysis question words are written into the preset large language model, and the large language model performs the latest market interpretation of the data trend based on the numerical data and analysis requirements, and gives relevant suggestions, etc. Finally, the relevant text analysis data is received from the large language model.
[0066] 106. Performing a chart drawing process on the numerical data according to a preset visualization algorithm to obtain chart data;
[0067] In this embodiment, the question is combined with the semantic model to determine the type of chart suitable for data display, the numerical data is encapsulated into the data structure required by the corresponding chart, the encapsulated data is drawn, and the icon data is generated.
[0068] See also Figure 2 , Figure 2 The following is a schematic diagram of a specific embodiment of step 106 of the report generation method based on a large language model in an embodiment of the present invention. Step 106 includes the following specific embodiments:
[0069] 1061. Analyze the numerical data to obtain a display chart type corresponding to the numerical data;
[0070] 1062. Based on the chart type, plot the numerical data to obtain chart data.
[0071] In steps 1061-1062, based on the question data of "issuing a report on the financial data and market share of Company X", the data of column 1 and column 2 are analyzed in one of the following types: a bar chart, a line chart, a pie chart, a bar chart, a scatter chart, an area chart, a radar chart, a box plot, a data table, a cross table, a frequency table, a summary table, a comparison table, a sorted table, a formatted table, etc. Then, based on the selected type, the data of column 1 and column 2 are plotted to obtain the relevant chart type.
[0072] See also Figure 3 , Figure 3 The figure is a schematic diagram of a specific embodiment of step 1061 of the report generation method based on a large language model in an embodiment of the present invention. Step 1061 includes the following specific embodiments:
[0073] 10611. Analyze the data dimension of the numerical data to obtain a data dimension vector;
[0074] 10612. Based on the data dimension vector, obtain the type of display chart corresponding to the numerical data.
[0075] In steps 10611-10612, the numerical data has three subjects and 102 corresponding data, and the data dimension vector is marked as [3,102,102,102]. Based on the [3,102,102,102] vector structure, according to the set rules, the numerical data is matched to display a scatter plot.
[0076] See also Figure 4 , Figure 4 The following is a schematic diagram of a specific embodiment of step 1062 of the report generation method based on a large language model in an embodiment of the present invention. Step 1062 includes the following specific embodiments:
[0077] 10621. According to the type of the chart, the numerical data is plotted using the pyecharts database to generate an HTML file;
[0078] 10622. Using the Selenium component to simulate opening the HTML file, and generate a simulated preview interface;
[0079] 10623. Taking a screenshot of the simulation preview interface to generate screenshot data, and uploading the screenshot data to a cloud database to obtain a storage URL address;
[0080] 10624. Determine the stored URL address as chart data.
[0081] In steps 10621-10624, the display is set to a scatter plot, and the numerical data is plotted using the pyecharts database to generate an html file. The Selenium component is used to simulate opening the html file, and a screenshot of the simulated interface is taken. After saving it in a graphic format such as jpg or png, the screenshot data is uploaded to the cloud database. After the cloud database completes the storage, the storage URL address is obtained from the cloud database. The subsequent report generation takes the graphic data from the storage URL address, so the storage URL address is determined as the chart data.
[0082] Specifically, step 10623 includes the following specific implementation methods:
[0083] 106231. Upload the screenshot data to the OSS database to obtain a storage URL address.
[0084] In step 106231, the OSS database is the Alibaba Cloud database. After the screenshot data is uploaded to Alibaba Cloud, the storage URL address is obtained.
[0085] Specifically, step 10621 includes the following specific implementation methods:
[0086] 106211. Based on the data structure corresponding to the chart type, encapsulate the numerical data to obtain encapsulated data;
[0087] 106212. Use the pyecharts database to draw the packaged data and generate an html file.
[0088] In steps 106211-106212, the data graph is a scatter graph, the chart data is encapsulated into a scatter graph data structure, and the encapsulated data of the X-axis data and the Y-axis data structure are obtained. Then, the pyecharts database is used to draw the encapsulated data and generate an html file.
[0089] 107. Integrate the chart data and the text analysis data to generate analysis report data corresponding to the question data.
[0090] In this embodiment, the image and text analysis data from the URL address of the chart data are combined, and the text analysis data is text that performs trend analysis on different data in the chart to obtain analysis report data corresponding to the question data.
[0091] Furthermore, after step 107, the following specific implementations are also included:
[0092] 1071. The analysis report data is sent to the port corresponding to the question data.
[0093] In step 1071, the generated charts, data market interpretations and related suggestions are combined to generate a data analysis report, which is returned by the robot to the user asking the question.
[0094] In the embodiment of the present invention, natural language is used as the initial language for data processing, the SQLAlchemy mapping tool is used to operate the database, and a large language model is used as a tool for data analysis, which can lower the threshold for data analysis and processing, and at the same time improve the timeliness of users obtaining data reports. Users do not need professional skills, and can get a professional visual data analysis report very flexibly and quickly by simply asking questions, helping users to obtain more timely and accurate information about the company's relevant business conditions and market dynamics, so as to make relevant decisions more timely, solving the technical problem that the existing data report generation solution cannot meet the timeliness and low threshold requirements at the same time.
[0095] Figure 51 is a schematic diagram of the structure of a report generation device based on a large language model provided by an embodiment of the present invention. The report generation device 500 based on a large language model may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 (for example, one or more mass storage devices) storing application programs 533 or data 532. Among them, the memory 520 and the storage medium 530 may be temporary storage or permanent storage. The program stored in the storage medium 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the report generation device 500 based on a large language model. Furthermore, the processor 510 may be configured to communicate with the storage medium 530 to execute a series of instruction operations in the storage medium 530 on the report generation device 500 based on a large language model.
[0096] The report generation device 500 based on the large language model may also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input and output interfaces 560, and / or one or more operating systems 531, such as Windows Serve, Mac OS X, Unix, Linux, Free BSD, etc. It can be understood by those skilled in the art that Figure 5 The structure of the report generation device based on a large language model shown does not constitute a limitation on the report generation device based on a large language model, and may include more or less components than those shown in the figure, or combine some components, or arrange the components differently.
[0097] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the report generation method based on a large language model.
[0098] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0099] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.
[0100] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A report generation method based on a large language model, characterized in that: Includes steps: Receive question data; Based on the question data and a preset SQLAlchemy mapping tool, query a data table in a preset StarRocks database to obtain query schema meta-information, and perform query assembly processing on a preset prompt word set according to the query schema meta-information to generate SQL prompt words, wherein the SQLAlchemy mapping tool is an object-relational mapping tool for mapping Python classes to database tables; Transmitting the SQL prompt word to a preset large language model, and receiving the SQL query instruction fed back by the large language model; Based on the SQL query instruction, data query processing is performed on the StarRocks database to obtain numerical data; Combining the numerical data with the question data to generate parsed question words, transmitting the parsed question words to a preset large language model, and receiving text analysis data fed back by the large language model; According to a preset visualization algorithm, the numerical data is processed by graphing to obtain graph data; The chart data and the text analysis data are integrated and processed to generate analysis report data corresponding to the question data.
2. The report generation method based on a large language model according to claim 1, characterized in that: The process of drawing a chart on the numerical data according to a preset visualization algorithm to obtain chart data includes: Analyze the numerical data to obtain the type of display chart corresponding to the numerical data; Based on the chart type, the numerical data is plotted to obtain chart data.
3. The report generation method based on a large language model according to claim 2, characterized in that: The analyzing the numerical data to obtain the display chart types corresponding to the numerical data includes: Analyze the data dimension of the numerical data to obtain a data dimension vector; Based on the data dimension vector, the type of display chart corresponding to the numerical data is obtained.
4. The report generation method based on a large language model according to claim 2, characterized in that: The plotting of the numerical data based on the chart type to obtain chart data includes: According to the type of the chart, the numerical data is plotted using the pyecharts database to generate an html file; Using Selenium components to simulate opening the HTML file and generate a simulated preview interface; Taking a screenshot of the simulated preview interface to generate screenshot data, and uploading the screenshot data to a cloud database to obtain a storage URL address; The stored URL address is determined as chart data.
5. The report generation method based on a large language model according to claim 4, characterized in that: The step of uploading the screenshot data to a cloud database to obtain a storage URL address includes: The screenshot data is uploaded to the OSS database to obtain a storage URL address.
6. The report generation method based on a large language model according to claim 4, characterized in that: According to the type of the chart, the numerical data is plotted using the pyecharts database to generate an html file, including: Based on the data structure corresponding to the chart type, encapsulating the numerical data to obtain encapsulated data; The packaged data is drawn using the pyecharts database to generate an HTML file.
7. The report generation method based on a large language model according to claim 1, characterized in that: After receiving the question data, and before querying the data table in the preset StarRocks database based on the question data and the preset SQLAlchemy mapping tool to obtain the query schema meta information, the method further includes: Analyze the question field of the question data, and determine whether the question field is a preset valid field; When the question field is not a valid field, the processing of the question data is stopped, and abnormal question information is sent to the port corresponding to the question data; When the question field is a valid field, the question data is marked as qualified data.
8. The report generation method based on a large language model according to claim 1, characterized in that: After the chart data and the text analysis data are integrated and processed to generate analysis report data corresponding to the question data, the method further includes: The analysis report data is sent to the port corresponding to the question data.
9. A report generation device based on a large language model, characterized in that: The report generation device based on the large language model comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instructions in the memory to enable the large language model-based report generation device to execute the large language model-based report generation method according to any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the report generation method based on a large language model as described in any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Method for interactively generating data report and computing equipment
CN116756169A
Data visualization analysis method based on natural language large model
CN117235248A