Power dispatching data processing and analysis method and system based on large language model, terminal and storage medium
By using large language models to process users' natural language query and unstructured data in the power data analysis system, the problem that existing systems cannot accurately understand natural language query is solved, precise retrieval and flexible question-and-answer are realized, and multiple data analysis is supported. Requirements and simplify user operation processes.
Patent Information
- Application Number
- CN202411265155.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2025-02-11
AI Technical Summary
The existing power data analysis system cannot accurately understand users' natural language queries, resulting in inaccurate search results, difficult to deal with complex and changeable analysis needs, and high maintenance costs, making it difficult to meet the needs of real-time analysis.
The power scheduling data processing and analysis method based on the large language model is adopted. By receiving the information input by the user, the type is judged, and the non-query-type information is converted into a target vector for matching. When the query information is selected, the appropriate database is selected for SQL query. The LLM model extracts and summarizes the query results and generates analysis suggestions.
It realizes accurate retrieval and flexible Q&A of natural language, supports a variety of data analysis needs, simplifies user operation processes, enhances user experience, and can quickly adjust and optimize data processing processes according to different scenarios.
Smart Images

Figure CN119417009A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data processing and analysis, and specifically relates to a method, system, terminal and storage medium for processing and analyzing electric power dispatching data based on a large language model. Background Art
[0002] In the power industry, one of the main challenges of data processing and analysis is dealing with complex natural language queries and large amounts of unstructured data. Traditional data processing methods usually rely on keyword matching and fixed query patterns, which limits the ability to process complex queries and understand unstructured data. In addition, existing systems are often unable to interact directly through natural language, resulting in users facing complex operations and understanding barriers during query and data analysis.
[0003] Specifically, existing power data analysis systems usually adopt the following methods: (1) Retrieval system based on keyword matching: This system can only match based on the keywords entered by the user, and cannot understand the user's true intention, resulting in inaccurate retrieval results. (2) Analysis system based on rule engine: This system requires a large number of rules to be defined in advance, which is difficult to cope with complex and changing analysis needs, and the maintenance cost is high. (3) Analysis system based on machine learning: This system requires a large amount of training data, and the model training time is long, which is difficult to meet the needs of real-time analysis. Summary of the invention
[0004] In view of the problems in the prior art that the user's natural language queries cannot be accurately understood, resulting in inaccurate retrieval results, difficulty in handling complex and changeable analysis requirements, high maintenance costs and difficulty in meeting real-time analysis needs, the present invention provides a power dispatching data processing and analysis method, system, terminal and storage medium based on a large language model to solve the above technical problems.
[0005] In a first aspect, the present invention provides a method for processing and analyzing power dispatching data based on a large language model, comprising: Step S1, receiving information input by the user; Step S2, determining whether there is a file in the information input by the user: if there is no file, determining the type of information according to the prompt word in the information input by the user, if it is non-query information, executing step S31, if it is query information, executing step S32; if there is a file, executing step S33; Step S31, converting the non-query information into a target vector, matching the target vector with a vector in a pre-stored vector library, performing a similarity judgment, and outputting a result based on the judgment; Step S32: based on the query type information, select a corresponding pre-stored database as the database to be queried, extract the query requirements of the query type information, extract the corresponding schema from the database to be queried based on the query requirements, input the schema and the query requirements into the LLM model, the LLM model extracts the SQL query statement, returns the idea and the SQL in json format, parses the SQL and executes the SQL query to obtain the query result, the LLM model summarizes the content of the query result in natural language, and outputs it according to the query requirements; Step S33: read the file in the information input by the user, convert the file into df, extract the file information based on df and construct prompt, call the LLM model to generate analysis suggestions, and output the analysis suggestions.
[0006] Furthermore, in step S31, the target vector is matched with the vectors in the pre-stored vector library, and similarity judgment is performed, and the judgment output result includes: If it is determined that the target vector is greater than or equal to a preset threshold, the fault handling solution corresponding to the vector with the highest similarity in the pre-stored fault vector library is output; If it is determined that the target vector is less than a preset threshold, the similarity between the target vector and the image in the pre-stored image vector library is calculated: If the similarity is greater than or equal to a preset threshold, outputting the image with the highest similarity in the pre-stored image vector library; If the similarity is less than a preset threshold, the question type information is converted into a prompt in the ReAct Prompt format and input into a pre-built-in LLM model; The LLM model determines whether a tool needs to be called based on the prompt. If a tool needs to be called, the corresponding tool is selected, and the tool is used to obtain the corresponding result and output it; if a tool does not need to be called, the result is output directly.
[0007] Furthermore, the method for similarity determination in step S31 includes: Convert the non-query information into a target vector ; Get the vector from the pre-stored vector library , where i=1,2…,n; Using the formula Calculate the target vector With the vector The cosine similarity of is the dot product of two vectors, For vector and vector The module length, The value range is between -1 and 1, where 1 means they are exactly the same, 0 means they are completely unrelated, and -1 means they are completely opposite.
[0008] Furthermore, the output according to the query requirement in step S32 further includes: Determine whether there is a visualization requirement in the query requirement: If there is a need for visualization, the query results are converted into df and the Agent is constructed using ReAct technology; The visualization requirement is transmitted to the Agent, and the Agent generates a graph and / or a table; Saving the graph and / or table and outputting it to a user; If there is no visualization requirement, a prompt is constructed based on the query results to summarize the results and output them.
[0009] Furthermore, step S33 also includes: Step S331, accepting questions from the user regarding the file, and constructing an Agent based on the questions; Step S332: Agent generates the required code and determines whether an answer is obtained: Step S333: If yes, output the answer; Step S334: If not, correct the code in the Agent or generate a new code, and execute step S332 until the iteration limit is reached or the answer is output; Step S335: If the iteration limit is reached, a failure notification is returned.
[0010] In a second aspect, the present invention provides a power dispatching data processing and analysis system based on a large language model, comprising: A user input receiving module, used to receive information input by a user; A user input classification module is used to determine whether there is a file in the information input by the user: if there is no file, the type of information is determined according to the prompt word in the information input by the user, if it is non-query information, the first execution unit is executed, if it is query information, the second execution unit is executed; if there is a file, the third execution unit is executed; A first execution unit, configured to convert the non-query information into a target vector, match the target vector with a vector in a pre-stored vector library, perform similarity judgment, and output a result based on the judgment; The second execution unit is used to select a corresponding pre-stored database as a database to be queried based on the query type information, extract the query requirements of the query type information, extract the corresponding schema from the database to be queried based on the query requirements, input the schema and the query requirements into the LLM model, the LLM model extracts the SQL query statement, returns the idea and the json format of the SQL, parses the SQL and executes the SQL query to obtain the query result, and the LLM model summarizes the content of the query result in natural language and outputs it according to the query requirements; The third execution unit is used to read the file in the information input by the user, convert the file into df, extract the file information based on df and construct prompt, call the LLM model to generate analysis suggestions, and output the analysis suggestions.
[0011] Furthermore, the first execution unit includes: A first judgment module, configured to output a fault handling solution corresponding to a vector with the highest similarity in a pre-stored fault vector library if it is judged that the target vector is greater than or equal to a preset threshold; The second judgment unit is used to calculate the similarity between the target vector and the pictures in the pre-stored picture vector library if it is judged that the target vector is less than a preset threshold: If the similarity is greater than or equal to a preset threshold, outputting the image with the highest similarity in the pre-stored image vector library; A model calling unit, configured to convert the question type information into a prompt in a ReAct Prompt format and input the information into a pre-built-in LLM model if the similarity is less than a preset threshold; The LLM model determines whether a tool needs to be called based on the prompt. If a tool needs to be called, the corresponding tool is selected, and the tool is used to obtain the corresponding result and output it; if a tool does not need to be called, the result is output directly.
[0012] Further, the first execution unit includes: a similarity determination module; Similarity judgment module, including: A target vector conversion unit, used to convert the non-query information into a target vector ; Pre-stored vector acquisition unit, used to obtain vectors in the pre-stored vector library , where i=1,2…,n; Similarity calculation unit, used to use the formula Calculate the target vector With the vector The cosine similarity of is the dot product of two vectors, For vector and vector The module length, The value range is between -1 and 1, where 1 means they are exactly the same, 0 means they are completely unrelated, and -1 means they are completely opposite.
[0013] In a third aspect, a terminal is provided, including: processor, memory, wherein: The memory is used to store computer programs. The processor is used to call and run the computer program from the memory, so that the terminal executes the above-mentioned terminal method.
[0014] According to a fourth aspect, a computer storage medium is provided, wherein the computer-readable storage medium stores information, and when the computer-readable storage medium is run on a computer, the computer executes the methods described in the above aspects.
[0015] The beneficial effects of the present invention are that the power dispatching data processing and analysis method, system, terminal and storage medium based on the large language model provided by the present invention classify natural language and convert it into vectors or query statements, thereby realizing accurate retrieval, flexible question and answer and real-time analysis. Allow users to interact directly with the system through natural language, simplify the operation process, and enhance the user experience. It can process various structured and unstructured data and support various data analysis needs, including but not limited to fault plan query, image retrieval, database analysis and data visualization. The highly flexible and scalable technical framework can quickly adjust and optimize the data processing process according to different application scenarios and user needs. In addition, the design principle of the present invention is reliable, the structure is simple, and it has a very broad application prospect. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0017] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention.
[0018] Figure 2 FIG. 1 is a schematic flow chart of step S31 of a method according to an embodiment of the present invention.
[0019] Figure 3 FIG. 1 is a schematic flow chart of step S32 of a method according to an embodiment of the present invention.
[0020] Figure 4 FIG. 4 is a schematic flow chart of step S33 of a method according to an embodiment of the present invention.
[0021] Figure 5 is another schematic flow chart of a method according to an embodiment of the present invention.
[0022] Figure 6 is a schematic block diagram of a system according to an embodiment of the present invention.
[0023] Figure 7 A schematic diagram of the structure of a terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0025] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0026] LLM (Large Language Model): A large language model is an artificial intelligence algorithm based on deep learning. It can model natural language text by training a large amount of text data to learn the grammar, semantics and context information of the language. This model has a wide range of applications in the field of natural language processing, including but not limited to text generation, text classification, machine translation, sentiment analysis, etc.
[0027] Embedding model: It is a model that maps high-dimensional sparse features (such as vocabulary, images, user information, etc.) to a low-dimensional dense space. In this low-dimensional space, the similarity between different features can be measured by the distance between their vectors. Embedding models are widely used in natural language processing, recommendation systems, computer vision and other fields.
[0028] RAG technology (Retrieval-Augmented Generation): is a deep learning method that combines information retrieval and text generation. It is mainly used to improve the performance of natural language processing tasks, especially in question-answering systems and dialogue generation.
[0029] ReAct Prompt technology (Reasoning and Acting Prompt): is a method for enhancing the generation capability of large language models (LLMs), aiming to improve the performance of models in complex reasoning and task execution. It emphasizes improving the effectiveness of models by introducing reasoning and action mechanisms. ReAct Prompt mainly consists of three parts. The first part is reasoning: before generating a response, the model first analyzes and reasons about the question or task. This process enables the model to understand the structure and context of the question, thereby generating a more logical answer. The second part is action: based on the result of reasoning, the model can take action. This may include choosing a certain way to perform the task or adopting a specific strategy to generate output. The third part is prompt design: ReAct Prompt technology emphasizes designing specific input prompts to guide the model to reason and act. In this design, prompts can contain explicit information or structures to facilitate the model to understand the required operations.
[0030] Schema: refers to the structural definition of the database, including the table name, fields, data types, relationships, and constraints.
[0031] df (dataframe): is a two-dimensional table-like data structure, similar to an Excel spreadsheet, used to store and process tabular data. df consists of rows and columns, where rows represent data records and columns represent attributes or features, where columns can contain different data types, such as integers, floating-point numbers, strings, Boolean values, etc. Rows and columns can have index functions to facilitate data access and indexing.
[0032] Agent: is a system development process that includes designing, implementing, and optimizing a program or system that can perform tasks autonomously.
[0033] The method for processing and analyzing electric power dispatching data based on a large language model provided in the embodiment of the present invention is executed by a computer device. Accordingly, the system for processing and analyzing electric power dispatching data based on a large language model runs in the computer device.
[0034] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention. Figure 1 The execution subject may be a power dispatch data processing and analysis system based on a large language model. According to different requirements, the order of the steps in the flow chart may be changed, and some may be omitted.
[0035] To facilitate understanding of the present invention, the following is a further description of the method for processing and analyzing electric power dispatching data based on a large language model provided by the present invention, based on the principle of the method for processing and analyzing electric power dispatching data based on a large language model and in combination with the process of processing and analyzing the electric power dispatching data in the embodiment.
[0036] The LLM used in the present invention selects the Qwen2-72b model, which is an open source LLM from Alibaba Cloud. It has good Chinese support and semantic understanding capabilities. More importantly, the model has been specially trained for tool calls and can realize various tool call functions. The Embedding model selects infgrad / stella-base-zh-v2, which has good performance and a weight of only 0.2Gb, suitable for CPU environments. When LLM executes agent tasks, the intermediate process of LLM calling tools can be printed out to improve user experience. The vector database is FAISS, which is an efficient, flexible and easy-to-use vector search library.
[0037] Specifically, the power dispatching data processing and analysis method based on the large language model includes: Step S1: receiving information input by a user.
[0038] Step S2, determine whether there is a file in the information input by the user: if there is no file, determine the type of information according to the prompt word in the information input by the user, if it is non-query information, execute step S31, if it is query information, execute step S32; if there is a file, execute step S33.
[0039] Specifically, since LLM naturally possesses various natural language processing skills and can further complete specific tasks in a generated form, the first two of the "determining the type of information based on the information input by the user" mentioned here are actually completed by calling LLM, while the third one does not need to determine the type of information because it requires uploading a file. The examples of prompt words used are as follows: System: Please judge the user's intention according to the user's instructions and return it in json User: Based on the user instructions, determine whether the user's intention is related to the following task types: Type 1 ``` Query the image.
[0040] Check the fault handling methods. The fault types include: power failure, capacitor switch tripping, grounding transformer tripping, PT failure, single-phase grounding, low backup protection tripping, main protection action tripping and other seven types.
[0041] Daily chat.
[0042] All other issues.
[0043] ``` Type 2 ``` Query grid line data Query coal-to-electricity data Query reload and overload data Query work order data (such as fault repair) Query power grid data, number of substations, lines, transformers, etc. Query fault and trip data Query the data of users and stations affected when a fault occurs. The fault can be of various types. Defect Query ``` If you are unsure, return to 3.
[0044] Please return in the following json format: { "intention": task type (Arabic number), } Please make sure to return only json without any extra information.
[0045] The user instructions are as follows: {The question actually entered by the user} By parsing the content returned by LLM, you can determine the category to which the user's question belongs.
[0046] Step S31: convert the non-query information into a target vector, match the target vector with a vector in a pre-stored vector library, perform a similarity judgment, and output a result based on the judgment.
[0047] The similarity judgment method includes: Convert the non-query information into a target vector . Get the vector from the pre-stored vector library , where i=1,2…,n. Use the formula Calculate the target vector With the vector The cosine similarity of is the dot product of two vectors, For vector and vector The module length, The value range is between -1 and 1, where 1 means they are exactly the same, 0 means they are completely unrelated, and -1 means they are completely opposite.
[0048] Specifically, the similarity comparison method using cosine similarity can effectively process data in high-dimensional space and is independent of the length of the vector. It is only based on the angular difference between vectors. This is particularly important for semantic retrieval because it allows the system to go beyond simple prompt word matching and more accurately understand and respond to user queries.
[0049] If it is determined that the target vector is greater than or equal to a preset threshold, the fault handling plan corresponding to the vector with the highest similarity in the pre-stored fault vector library is output; if it is determined that the target vector is less than the preset threshold, the similarity between the target vector and the image in the pre-stored image vector library is calculated: if the similarity is greater than or equal to the preset threshold, the image with the highest similarity in the pre-stored image vector library is output; if the similarity is less than the preset threshold, the question type information is converted into a Prompt in the ReAct Prompt format and input into a pre-built-in LLM model; the LLM model determines whether a tool needs to be called based on the Prompt. If a tool needs to be called, the corresponding tool is selected, and the corresponding result is obtained and output using the tool; if the tool does not need to be called, the result is directly output.
[0050] Specifically, the above method uses the Embedding model to convert the user input into a vector, that is, convert the natural language input by the user into a vector form, which can be expressed as , and matches it with the pre-defined vector library to achieve efficient semantic retrieval. Once the similarity with a certain content is greater than the set threshold, it is judged as a hit and the content corresponding to the information is returned.
[0051] The vector libraries used for comparison include: fault vector library and image vector library, which are used to store fault cases and image data related to the power industry. Specifically, the fault vector library collects the names of faults encountered by various lines in history and the corresponding treatment methods, converts the fault names into vectors with the help of the embedding model, and stores them in the fault vector database. The image database mainly includes various grid structure diagrams and various auxiliary images used in daily work, names the images appropriately for the content, converts the fault names into vectors with the help of the embedding model, and stores them in the image vector database.
[0052] The method of the LLM model based on Prompt to determine whether the tool needs to be called is: By constructing prompt words in the ReAct format, LLM can be used as an intelligent agent to complete the tool calling function. This method is a general intelligent agent construction method called "ReAct prompting": Suppose a tool is provided to query weather information, and the reference prompt words are as follows: System: Answer the following questions to the best of your ability. You have the following tools: {'name': 'get_current_weather', 'description': 'Get the currentweather in a given location', 'parameters': {'type': 'object', 'properties':{'location': {'type': 'string', 'description': 'The city, eg Beijing'}, 'unit': {'type': 'string', 'enum': ['celsius', 'fahrenheit']}}, 'required': ['location']}} Answer in the following format: Thought: Thinking about what you should do Action: The name of the tool, must be one of [get_current_weather] Action Input: Tool input Observation: The results returned by the tool ... (The Thought / Action / Action Input / Observation process can be repeated zero or more times) Final Answer: The final answer to the input question start! User: What's the weather like in Shanghai? LLM will return Thought, Action, and Action Input in sequence. You can set "Observation" as the stop word of LLM. When LLM outputs Observation, LLM output is terminated. The tool call is completed by parsing the Action and ActionIput parameters. The tool call result is spliced to Observation and input into LLM again as the tool call result. The call is terminated when the LLM return content does not contain Observation but contains Final Answer. The Final Answer content is parsed and returned as the final result.
[0053] The enhanced retrieval function of RAG technology supports LLM to provide more accurate and relevant information when processing complex queries, which is expressed as Response = RAG (LLM, ExternalData, TaskPrompt). The ReAct Prompt technology is used to build a specific format of prompt, which enables LLM to call external tools such as search engines, code interpreters, and image queries according to specific task requirements to achieve intelligent execution of complex tasks, which is expressed as Output = ReActPrompt (LLM, ExternalTool, TaskPrompt).
[0054] The above method can directly communicate with LLM and use LLM's text generation, encoding, chat and other capabilities. It can also refer to historical processing solutions and provide fault handling plans. It can also query the pictures contained in the library, such as grid structure diagrams, circuit diagrams, etc. It can also enhance the capabilities of LLM by making various tools, such as querying real-time information, calculating mathematical problems, etc.
[0055] Specifically, Figure 2 As shown, the above contents are illustrated with specific examples: Example 1: Answer questions about fault handling plans.
[0056] The user initiated a request: "What should I do if the entire XX station loses power?" Call the Embedding model to convert the query "The entire XX station has lost power. What should I do?" into a vector in the embedding space, and calculate the cosine similarity between the vector and other vectors in the fault vector library through similarity query to find the query statement with the highest similarity. Calculate whether the statement with the highest similarity reaches a certain threshold (taking 0.8 as an example). Here, the threshold is reached because the user's question is highly similar to the corresponding question in the fault vector library. Return the solution corresponding to the fault query with the highest similarity. Return the answer to the user: 1. Impact of the accident: XXXXX. 2. Solution: XXXXX Example 2: Answer questions about grid structure diagrams.
[0057] The user initiates a request: "I would like to know the grid structure diagram of Gansu Province." First, the fault vector library is calculated and compared, but the similarity does not reach the threshold. The cosine similarity between the problem vector and the vector in the image vector library is calculated through similarity query, and the title corresponding to the image with the highest similarity is found. Calculate whether the image with the highest similarity reaches a certain threshold (also taking 0.8 as an example), and here it is determined that the threshold is reached. Find the image in the corresponding image storage path. Return the answer to the user: Here is the image you want to see: XXXXX.
[0058] Example 3: Answering user questions with real-time queries.
[0059] The user initiated a request: "Is there any recent news related to the power industry?" After calculation in the fault vector library and the image vector library, the similarity did not reach a certain threshold. Call the LLM model, combine the user input with the pre-selected tool to construct a Prompt in the ReAct Prompt format, and pass it to LLM. LLM determines the need to call the search tool to query relevant information based on the user input. LLM chooses to call the search tool and enters: Recent news related to the power industry. The search engine returns the result: "China Electricity Council released the "National Electricity Supply and Demand Situation Analysis and Forecast Report for the Third Quarter of 2023", XXXXXX, etc." LLM summarizes and organizes the answers based on the received search results. Return the answer generated by LLM to the user: Hello, the following is recent news related to the power industry XXXXX.
[0060] Example 4: The user just wants to chat, without a specific query.
[0061] User initiates a request: "Hello." After calculation in the fault vector library and the image vector library, the similarity does not reach a certain threshold. Call LLM, combine the user input with the pre-selected tool to construct a prompt in the ReAct Prompt format and pass it to LLM. LLM determines that there is no need to call the tool based on the user input, so it can answer the question directly. Return the answer to the user: Hello, how can I help you? Step S32: based on the query type information, select a corresponding pre-stored database as the database to be queried, extract the query requirements of the query type information, extract the corresponding schema in the database to be queried based on the query requirements, input the schema and the query requirements into the LLM model, the LLM model extracts the SQL query statement, returns the idea and SQL in json format, parses the SQL and executes the SQL query to obtain the query result, the LLM model uses natural language to summarize the content of the query result, and outputs it according to the query requirements.
[0062] Specifically, the above method uses the user's natural language query to convert into SQL query to obtain relevant data from the database. The query results are described in natural language and the table content is summarized. The database query results are passed to Python and converted into pandas dataframe (hereinafter referred to as df). If the user needs to draw a graph, Python is used to generate a visual chart.
[0063] The above content can be used for intent recognition: determine whether the user has query / visualization needs, and decompose two types of needs from the user's original question. Database query: extract the schema of the database to be queried, and pass it to LLM together with the extracted query requirements. LLM generates the corresponding query statement based on the database table structure information, executes the query statement, and obtains the corresponding query result. Natural language summary: construct a prompt, pass the query results to LLM, and ask LLM to summarize the table content. Visualization chart: convert the queried table into df, construct an agent through ReAct Prompt technology, and input the extracted visualization requirements as the user's question. The agent will get an explanation of the behavior pattern, a list of available tools (only one python interpreter), and an available df and its first five lines of content display. On this basis, the agent can generate the corresponding python code by judging the df field content, call the third-party library to manipulate the df to complete the visualization, and save the chart in the specified location.
[0064] Specifically, Figure 3 As shown, the above contents are illustrated with specific examples: Example 1: The user wants to query the load in a certain area within a certain period of time, but there is no visualization requirement.
[0065] The user initiates a request: "What is the load situation in XX City in September 2023?" Select Database: Select the load database.
[0066] Intent recognition: Extract query requirements {query the load status of XX city in September 2023} and visualization requirements {none} Database query: Pass the schema and query requirements corresponding to the load database to LLM.
[0067] Parse LLM output: Extract SQL query statements from LLM output and execute the corresponding queries.
[0068] Query results: Get the query return results and pass them to LLM, requiring LLM to summarize the table contents using natural language.
[0069] Visualization: Since the visualization requirement is "None", this step is not executed.
[0070] The answer is returned to the user: The query results are as follows: XXXXXXX. The table content shows the load status of XX City in September 2023, including XXXXX.
[0071] Example 2: The user wants to query the fault status of a certain line section and requires a pie chart to be drawn.
[0072] The user initiates a request: "What faults are there on line XX? Please draw a pie chart based on the fault types." Select Database: Select the faulty database.
[0073] Intent recognition: extract query requirements {query the fault status of XX line} and visualization requirements {draw a pie chart based on the fault type of XX line}.
[0074] Database query: Pass the schema and query requirements corresponding to the faulty database to LLM.
[0075] Parse LLM output: Extract SQL query statements from LLM output and execute the corresponding queries.
[0076] Query results: Get the query return results and pass them to LLM, requiring LLM to summarize the table contents using natural language.
[0077] Visual query: Convert the SQL query results into df, and construct the Agent with the first five rows of df and the visualization requirements.
[0078] Visualization results: The agent draws the corresponding table according to the visualization requirements and saves it in the specified location. It then extracts the result and displays it to the user.
[0079] The answer is returned to the user: The query results are as follows: XXXXX. The table content shows the fault status of the XX line, where XXXXX. A pie chart is drawn based on the fault type of the XX line as follows: XXXXX.
[0080] Step S33: read the file in the information input by the user, convert the file into df, extract the file information based on df and construct prompt, call the LLM model to generate analysis suggestions, and output the analysis suggestions. Construct Agent based on the file type information, generate results based on Agent and output them.
[0081] Specifically, file upload supports file formats such as csv, xlsx, etc. The above method can perform the following functions: Data analysis: Propose analysis suggestions, such as data cleaning, statistical analysis, data visualization, etc. Natural language query: Query the content of the uploaded data through natural language.
[0082] Read structured data through pandas and convert it into df. Extract the header information, field type, and the first few lines of data to construct a prompt to ask LLM to give analysis suggestions. Extract the df summary and user query to construct an agent to implement data analysis.
[0083] Specifically, Figure 4 As shown, the above contents are illustrated with specific examples: For ease of explanation, the following query is based on a load data set uploaded by the user, which includes an Excel spreadsheet of load data for more than ten regions in the past five years (based on 96-point statistics, that is, 96 data items per region per day).
[0084] First, LLM is called to analyze the table and give suggestions to the user: According to the table overview, the analysis methods for this table may include: Time series analysis: XXXX. Inter-regional comparative analysis: XXXX. Data visualization: XXXX.
[0085] Example 1: The user wants to query the average load of a certain place during a certain period of time and calculate the year-on-year change.
[0086] The user initiated a request: "What is the average load in the XX region in September 2023? How has it changed year-on-year?" Agent action: Extract the average load of region XX in September 2023 and calculate the average value.
[0087] Agent observation: Observed the average load in September 2023.
[0088] Action: Extract the average load of region XX in September 2022 and calculate the average value.
[0089] Observations: Average load observed for September 2022.
[0090] Action: Calculate the rate of change from the 2023 data to the 2022 data.
[0091] Observation: The rate of change is observed.
[0092] Return the answer to the user: The average load in XX region in September 2023 is XXXX, an increase / decrease of XX.X% year-on-year.
[0093] Example 2: The user wants to analyze the data and give a pie chart.
[0094] A user initiated a request: "Please analyze the average load values of different regions in the fourth quarter of 2023 and draw a pie chart to show it." Action: Calculate the average load values for the fourth quarter of 2023 for different regions.
[0095] Observe: Observe the results.
[0096] Action: Draw a pie chart based on the calculation results and save it to the corresponding location.
[0097] Observe: Observe until the drawing is completed.
[0098] The answer is returned to the user: The average load values of different regions in the fourth quarter of 2023 are as follows: XXXXX. The corresponding pie chart is as follows: XXXXX.
[0099] The overall architecture is as follows Figure 5 shown.
[0100] In some embodiments, the power dispatch data processing and analysis system 200 based on a large language model may include a plurality of functional modules composed of computer program segments. The computer program of each program segment in the power dispatch data processing and analysis system 200 based on a large language model may be stored in a memory of a computer device and executed by at least one processor to execute (see Figure 1 Description) Function of power dispatching data processing and analysis based on large language model.
[0101] In this embodiment, the power dispatching data processing and analysis system 200 based on the large language model can be divided into multiple functional modules according to the functions it performs, such as Figure 6 As shown. The functional modules may include: a user input receiving module 210, a user input classification module 220 and an execution module 230. The module referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, which are stored in a memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.
[0102] A user input receiving module, used to receive information input by a user; A user input classification module is used to determine whether there is a file in the information input by the user: if there is no file, the type of information is determined according to the prompt word in the information input by the user, if it is non-query information, the first execution unit is executed, if it is query information, the second execution unit is executed; if there is a file, the third execution unit is executed; A first execution unit, configured to convert the non-query information into a target vector, match the target vector with a vector in a pre-stored vector library, perform similarity judgment, and output a result based on the judgment; The second execution unit is used to select a corresponding pre-stored database as a database to be queried based on the query type information, extract the query requirements of the query type information, extract the corresponding schema from the database to be queried based on the query requirements, input the schema and the query requirements into the LLM model, the LLM model extracts the SQL query statement, returns the idea and the json format of the SQL, parses the SQL and executes the SQL query to obtain the query result, and the LLM model summarizes the content of the query result in natural language and outputs it according to the query requirements; The third execution unit is used to read the file in the information input by the user, convert the file into df, extract the file information based on df and construct prompt, call the LLM model to generate analysis suggestions, and output the analysis suggestions.
[0103] The first execution unit comprises: A first judgment module, configured to output a fault handling solution corresponding to a vector with the highest similarity in a pre-stored fault vector library if it is judged that the target vector is greater than or equal to a preset threshold; The second judgment unit is used to calculate the similarity between the target vector and the pictures in the pre-stored picture vector library if it is judged that the target vector is less than a preset threshold: If the similarity is greater than or equal to a preset threshold, outputting the image with the highest similarity in the pre-stored image vector library; A model calling unit, configured to convert the question type information into a prompt in a ReAct Prompt format and input the information into a pre-built-in LLM model if the similarity is less than a preset threshold; The LLM model determines whether a tool needs to be called based on the prompt. If a tool needs to be called, the corresponding tool is selected, and the tool is used to obtain the corresponding result and output it; if a tool does not need to be called, the result is output directly.
[0104] The first execution unit includes: a similarity judgment module; Similarity judgment module, including: A target vector conversion unit, used to convert the non-query information into a target vector ; Pre-stored vector acquisition unit, used to obtain vectors in the pre-stored vector library , where i=1,2…,n; Similarity calculation unit, used to use the formula Calculate the target vector With the vector The cosine similarity of is the dot product of two vectors, For vector and vector The module length, The value range is between -1 and 1, where 1 means they are exactly the same, 0 means they are completely unrelated, and -1 means they are completely opposite.
[0105] Figure 7 A schematic diagram of the structure of a terminal 300 provided in an embodiment of the present invention. The terminal 300 can be used to execute the power dispatching data processing and analysis method based on a large language model provided in an embodiment of the present invention.
[0106] The terminal 300 may include: a processor 310, a memory 320 and a communication module 330. These components communicate via one or more buses. Those skilled in the art will appreciate that the server structure shown in the figure does not limit the present invention, and it may be a bus structure or a star structure, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0107] The memory 320 can be used to store the execution information of the processor 310. The memory 320 can be implemented by any type of volatile or non-volatile storage terminal or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. When the execution information in the memory 320 is executed by the processor 310, the terminal 300 can execute some or all of the steps in the following method embodiments.
[0108] The processor 310 is the control center of the storage terminal, and uses various interfaces and lines to connect various parts of the entire electronic terminal. It runs or executes software programs and / or modules stored in the memory 320, and calls data stored in the memory to perform various functions of the electronic terminal and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of multiple packaged ICs with the same or different functions. For example, the processor 310 can only include a central processing unit (CPU). In the embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.
[0109] The communication module 330 is used to establish a communication channel so that the storage terminal can communicate with other terminals, receive user data sent by other terminals or send user data to other terminals.
[0110] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0111] Therefore, the present invention realizes accurate retrieval, flexible question and answer and real-time analysis by classifying natural language and converting it into vectors or query statements. Allow users to interact with the system directly through natural language, simplify the operation process, and enhance the user experience. It can process various structured and unstructured data and support multiple data analysis needs, including but not limited to fault plan query, image retrieval, database analysis and data visualization. The highly flexible and scalable technical framework can quickly adjust and optimize the data processing process according to different application scenarios and user needs. The technical effects that can be achieved by this embodiment can be found in the description above, which will not be repeated here.
[0112] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present invention, in essence or in other words, the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes, including some information to enable a computer terminal (which can be a personal computer, a server, or a second terminal, a network terminal, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.
[0113] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the terminal embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.
[0114] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or modules, which can be electrical, mechanical or other forms.
[0115] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0116] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0117] Although the present invention has been described in detail by referring to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, a person of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions shall be within the scope of the present invention. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, and all of these shall be within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A method for processing and analyzing power dispatching data based on a large language model, characterized in that: include: Step S1, receiving information input by the user; Step S2, determining whether there is a file in the information input by the user: if there is no file, determining the type of information according to the prompt word in the information input by the user, if it is non-query information, executing step S31, if it is query information, executing step S32; if there is a file, executing step S33; Step S31, converting the non-query information into a target vector, matching the target vector with a vector in a pre-stored vector library, performing a similarity judgment, and outputting a result based on the judgment; Step S32: based on the query type information, select a corresponding pre-stored database as the database to be queried, extract the query requirements of the query type information, extract the corresponding schema from the database to be queried based on the query requirements, input the schema and the query requirements into the LLM model, the LLM model generates a solution to the problem and a corresponding SQL query statement according to the query requirements, and returns the idea and SQL in json format, obtains SQL by parsing json and executes SQL query to obtain the query result, the LLM model summarizes the content of the query result in natural language, and outputs it according to the query requirements; Step S33: read the file in the information input by the user, convert the file into df, extract the file information based on df and construct prompt, call the LLM model to generate analysis suggestions, and output the analysis suggestions.
2. The method according to claim 1, characterized in that: Step S31 matches the target vector with the vectors in the pre-stored vector library and performs similarity judgment, and outputs the result based on the judgment, including: If it is determined that the target vector is greater than or equal to a preset threshold, then the fault handling solution corresponding to the vector with the highest similarity in the pre-stored fault vector library is output; If it is determined that the target vector is less than a preset threshold, the similarity between the target vector and the image in the pre-stored image vector library is calculated: If the similarity is greater than or equal to a preset threshold, output the image with the highest similarity in the pre-stored image vector library; If the similarity is less than a preset threshold, the question type information is converted into a prompt in the ReAct Prompt format and input into a pre-built-in LLM model; The LLM model determines whether a tool needs to be called based on the prompt. If a tool needs to be called, the corresponding tool is selected, and the tool is used to obtain the corresponding result and output it; if a tool does not need to be called, the result is output directly.
3. The method according to claim 1, characterized in that The method for similarity determination in step S31 includes: Convert the non-query information into a target vector ; Get the vector from the pre-stored vector library , where i=1,2…,n; Using the formula Calculate the target vector With the vector The cosine similarity of is the dot product of two vectors, For vector and vector The module length, The value range is between -1 and 1, where 1 means they are exactly the same, 0 means they are completely unrelated, and -1 means they are completely opposite.
4. The method according to claim 1, characterized in that After the output according to the query requirement in step S32, the following is further included: Determine whether there is a visualization requirement in the query requirement: If there is a need for visualization, the query results are converted into df and the Agent is constructed using ReAct technology; The visualization requirement is transmitted to the Agent, and the Agent generates a graph and / or a table; Saving the graph and / or table and outputting it to a user; If there is no visualization requirement, a prompt is constructed based on the query results to summarize the results and output them.
5. The method according to claim 1, characterized in that After step S33, the following steps are also included: Step S331, accepting questions from the user regarding the file, and constructing an Agent based on the questions; Step S332: Agent generates the required code and determines whether an answer is obtained: Step S333: If yes, output the answer; Step S334: If not, correct the code in the Agent or generate a new code, and execute step S332 until the iteration limit is reached or the answer is output; Step S335: If the iteration limit is reached, a failure notification is returned.
6. A power dispatching data processing and analysis system based on a large language model, characterized in that: include: A user input receiving module, used to receive information input by a user; A user input classification module is used to determine whether there is a file in the information input by the user: if there is no file, the type of information is determined according to the prompt word in the information input by the user, if it is non-query information, the first execution unit is executed, if it is query information, the second execution unit is executed; if there is a file, the third execution unit is executed; A first execution unit, configured to convert the non-query information into a target vector, match the target vector with a vector in a pre-stored vector library, perform similarity judgment, and output a result based on the judgment; The second execution unit is used to select a corresponding pre-stored database as a database to be queried based on the query type information, extract the query requirements of the query type information, extract the corresponding schema from the database to be queried based on the query requirements, input the schema and the query requirements into the LLM model, the LLM model extracts the SQL query statement, returns the idea and the json format of the SQL, parses the SQL and executes the SQL query to obtain the query result, and the LLM model summarizes the content of the query result in natural language and outputs it according to the query requirements; The third execution unit is used to read the file in the information input by the user, convert the file into df, extract the file information based on df and construct prompt, call the LLM model to generate analysis suggestions, and output the analysis suggestions.
7. The system according to claim 5, characterized in that The first execution unit comprises: A first judgment module, configured to output a fault handling solution corresponding to a vector with the highest similarity in a pre-stored fault vector library if it is judged that the target vector is greater than or equal to a preset threshold; The second judgment unit is used to calculate the similarity between the target vector and the pictures in the pre-stored picture vector library if it is judged that the target vector is less than a preset threshold: If the similarity is greater than or equal to a preset threshold, output the image with the highest similarity in the pre-stored image vector library; A model calling unit, configured to convert the question type information into a Prompt in a ReActPrompt format and input the Prompt into a pre-built-in LLM model if the similarity is less than a preset threshold; The LLM model determines whether a tool needs to be called based on the prompt. If a tool needs to be called, the corresponding tool is selected, and the tool is used to obtain the corresponding result and output it; if a tool does not need to be called, the result is output directly.
8. The system according to claim 5, characterized in that The first execution unit includes: a similarity judgment module; Similarity judgment module, including: A target vector conversion unit, used to convert the non-query information into a target vector ; Pre-stored vector acquisition unit, used to obtain vectors in the pre-stored vector library , where i=1,2…,n; Similarity calculation unit, used to use the formula Calculate the target vector With the vector The cosine similarity of is the dot product of two vectors, For vector and vector The module length, The value range is between -1 and 1, where 1 means they are exactly the same, 0 means they are completely unrelated, and -1 means they are completely opposite.
9. A terminal, characterized in that: include: A memory for storing a power dispatching data processing and analysis program based on a large language model; A processor is used to implement the steps of the power dispatching data processing and analysis method based on a large language model as described in any one of claims 1 to 5 when executing the power dispatching data processing and analysis program based on a large language model.
10. A computer-readable storage medium storing a computer program, characterized in that: The readable storage medium stores a large language model-based power dispatching data processing and analysis program, which, when executed by a processor, implements the steps of the large language model-based power dispatching data processing and analysis method as described in any one of claims 1 to 5.
Citation Information
Cited By
Large language model assisted power system frequency stability regulation and control method, apparatus and device, and storage medium
CN120320358A
Data query method and device based on large language model and storage medium
CN120508640A
Digital base query method and device based on large language model, equipment and medium
CN120892459A