A method and system for calling power grid analysis tools based on large language model

Through the method of calling the grid analysis tool based on the large language model, the problems of inefficiency and lack of flexibility of the traditional methods are solved, and the efficient, accurate and automated calls of the grid analysis tools are achieved, meeting the analysis needs in the complex environment of the modern power grid.

CN119336796BActive Publication Date: 2025-02-28CHINA ELECTRIC POWER RESEARCH INSTITUTE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411879998.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-19
Publication Date
2025-02-28
Estimated Expiration
2044-12-19

AI Technical Summary

Technical Problem

The traditional grid analysis tool call method is inefficient and lacks flexibility, making it difficult to meet the needs of complex environments of modern power grids and massive data processing.

Method used

The grid analysis tool calling method based on the large language model is adopted. By collecting and standardizing the interface information of the grid analysis tool, calling instructions are generated, and using the instruction data set to fine-tune the large language model to automatically call the grid analysis tool, improving the accuracy and efficiency of the analysis.

Benefits of technology

It improves the accuracy of calling grid analysis tools and user interaction convenience, realizes digital and automated security assessment, and meets the analysis needs in complex modern power grid environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for calling a power grid analysis tool based on a large language model, belonging to the field of electric power automation technology. The method includes collecting interface information of various power grid analysis tools, standardizing the interface information, and establishing an interface information library; generating a calling instruction of the power grid analysis tool according to the interface information library, and classifying and marking the calling instruction to form an instruction data set; using the instruction data set to fine-tune the parameters of the power grid analysis tool calling the large language model to obtain an optimized large language model; after inputting the instruction, retrieving and returning a group of instructions corresponding to the input instruction semantics from the instruction data set, and generating a power grid analysis tool calling structured statement by performing multiple rounds of interaction with the optimized power grid analysis tool calling the large language model; and executing a calling operation on the corresponding power grid analysis tool according to the generated power grid analysis tool calling structured statement. The present invention improves the accuracy and efficiency of power grid analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of electric power automation, and in particular relates to a method and system for calling a power grid analysis tool based on a large language model. Background Art

[0002] With the rapid development of power systems and the continuous advancement of power grid technology, the operational safety of power grids has become a matter of great concern to the society. In the traditional power grid management process, power grid analysis tools are widely used to monitor and maintain the stable operation of power grids, such as static safety analysis and N-1 over-limit scanning. However, in the face of increasingly complex power grid environments and massive amounts of data information, traditional power grid analysis tool calling methods have limitations such as low efficiency and insufficient flexibility, which are difficult to fully meet the needs of modern power grids. Specifically, low efficiency means that traditional power grid analysis tools often need to perform complex calculations on a large amount of power grid data, which leads to low computational efficiency. In addition, in a distributed power grid environment, data transmission delays and bandwidth limitations can also affect the real-time performance of analysis tools. Insufficient flexibility means that with the continuous changes in the power grid structure and the access to new energy sources, traditional tools often find it difficult to quickly adapt to these changes, resulting in inaccurate analysis results. At the same time, different power grid regions and operators may have specific analysis needs, but traditional tools often lack sufficient flexibility to meet these customized needs. In addition, traditional methods are difficult to cope with massive data. As the rapid growth of power grid data puts higher demands on storage resources, traditional methods face storage bottlenecks when processing big data. Processing and analyzing massive amounts of data requires efficient data processing algorithms and powerful computing capabilities, and traditional tools are unable to cope with this. As the scale and complexity of power grids increase, the real-time requirements for power grid analysis tools are becoming increasingly high, and power grid analysis tools need to accurately reflect the actual operating status and characteristics of the power grid. Summary of the invention

[0003] The purpose of the present invention is to address the problems in the above-mentioned prior art and provide a method and system for calling a power grid analysis tool based on a large language model, which can accurately understand the user's intention and automatically call the corresponding power grid analysis tool according to the context and data intelligent reasoning, so as to improve the accuracy and efficiency of power grid analysis and realize digital and automated safety assessment.

[0004] In order to achieve the above object, the present invention has the following technical solutions:

[0005] In a first aspect, a method for calling a power grid analysis tool based on a large language model is provided, comprising:

[0006] Collect the interface information of each power grid analysis tool, standardize the interface information of the power grid analysis tool, and establish an interface information library;

[0007] Generate calling instructions of the power grid analysis tool according to the interface information library, and classify and mark the calling instructions of the power grid analysis tool to form an instruction data set;

[0008] The command data set is used to fine-tune the parameters of the pre-established large language model called by the power grid analysis tool, so as to obtain an optimized large language model called by the power grid analysis tool;

[0009] After the command is input, a set of commands corresponding to the input command semantics is retrieved and returned from the command data set, and multiple rounds of interactions are performed with the optimized power grid analysis tool call large language model to generate a structured statement for calling the power grid analysis tool;

[0010] According to the generated power grid analysis tool calling structured statement, a calling operation is performed on the corresponding power grid analysis tool.

[0011] As a preferred scheme, when collecting the interface information of each power grid analysis tool, an interface information collection template is defined to collect the interface information, and the interface information collection template includes field names and corresponding descriptions; wherein the field names include interface names, function descriptions, input parameters, output parameters, parameter types and calling methods; the description corresponding to the interface name is a unique identifier of the interface, the description corresponding to the function description is a detailed description of the interface function, the description corresponding to the input parameter is a list of input information required for the interface, the description corresponding to the output parameter is a list of output information of the interface, the description corresponding to the parameter type is the data type of the input or output parameter, and the description corresponding to the calling method is a specific way to call the interface.

[0012] As a preferred solution, in the step of standardizing the interface information of the power grid analysis tool, the same function interface input parameters of different power grid analysis tools have unified parameter names and data types; an interface mapping table is established, and a unified calling method is used when calling different power grid analysis tools through interface mapping; the result data returned by the interface is marked into two types: one is dictionary data saved in the form of Key-Value, where Key is the data keyword and Value is a data structure containing three attributes, which are data type, data length and data value; the other is in the form of Vector <vector>The data is saved in the form of a two-dimensional table, where each element in the first-level Vector represents a row of data in the two-dimensional table, and each element in the second-level Vector represents the data in a certain field of a certain row in the two-dimensional table. This data is represented by a data structure, which contains four attributes, namely data type, data length, data value and attribute name.

[0013] As a preferred solution, the steps of generating the calling instructions of the power grid analysis tool according to the interface information library, and classifying and marking the calling instructions of the power grid analysis tool to form the instruction data set include: designing a set of instruction templates, each instruction template corresponding to a specific power grid analysis tool and operation; the instruction template includes a fixed grammatical structure and a placeholder for inserting specific parameters;

[0014] The formal expression of the instruction template is as follows:

[0015] <Tool Name><Operation><Parameter 1><Parameter 2>...<Parameter N>

[0016] Among them, <tool name>, <operation> and <parameters> are all filled in according to the specific instruction content;

[0017] Access the interface information library and extract the interface information of each interface; generate the calling instructions of the power grid analysis tool according to the instruction template and the interface information; the steps of classifying and labeling the calling instructions of the power grid analysis tool include: defining several rules to classify the generated calling instructions according to the corresponding functions and uses; applying the defined rules to label each calling instruction with a multi-dimensional label, integrating the generated calling instructions and the corresponding labels into a structured data set, and obtaining the instruction data set.

[0018] As a preferred solution, in the step of using the instruction data set to fine-tune the parameters of the pre-established power grid analysis tool calling the large language model to obtain the optimized power grid analysis tool calling the large language model, several templates are defined to guide the power grid analysis tool to call the large language model to generate answers in the field of power grid analysis. The template is a pre-designed text fragment, which contains a placeholder for inserting specific information. The specific information is a keyword or parameter related to the power grid analysis tool calling instruction, and the format includes a prompt word template, a question, a thinking chain, and an answer; the fine-tuning process involves combining the pre-established power grid analysis tool calling the large language model with the instruction data set, and the purpose of the fine-tuning is to enable the power grid analysis tool to call the large language model to understand and generate outputs that are consistent with the power grid analysis tool calling instruction; the fine-tuning process is based on the following expression:

[0019]

[0020] In the formula, represents the loss function, The power grid analysis tool calls the large language model parameters. is the total number of samples in the instruction dataset, It is The input of samples, is the corresponding target output, is the corresponding prompt word template, which indicates the probability that the model generates the correct output given the input and prompt word template; in the fine-tuning process, adjust the parameters of the large language model called by the power grid analysis tool To minimize the loss function, the power grid analysis tool calls the large language model to generate target instructions.

[0021] As a preferred solution, the retrieving and returning a set of instructions corresponding to the input instruction semantics from the instruction data set includes:

[0022] The word embedding model is used to convert the input instruction text into a vector, and then the similarity is calculated. In the instruction data set, each known instruction is also converted into a vector form and stored. The similarity between the input instruction vector and each known instruction vector in the instruction data set is calculated. The following cosine similarity calculation formula is used to calculate the similarity between vectors:

[0023]

[0024] In the formula, and is the vector representation of two instructions, represents the dot product of vectors, and and are the norm or length of the vector respectively; according to the calculated similarity, several instructions with the highest similarity are selected as the retrieval results.

[0025] As a preferred solution, the steps of retrieving and returning a set of instructions corresponding to the input instruction semantics from the instruction data set, and generating a structured statement for calling the power grid analysis tool by performing multiple rounds of interaction with the optimized power grid analysis tool calling large language model include:

[0026] A context environment is constructed, which includes the user's original instructions, historical interaction records and possible user intentions. Based on the retrieved instructions, the optimized power grid analysis tool is used to call the large language model, and a series of potential structured sentences are generated according to the constructed context environment. The structured sentences are interpretations of the user instructions and have a format that the power grid analysis tool can understand and execute. For the generated structured sentences, an evaluation function is defined to measure the matching degree with the user intention. The expression of the evaluation function is as follows:

[0027]

[0028] In the formula, is the generated structured statement, is the context, is the quality scoring function of the structured sentence itself, and It is a scoring function of the relevance between the statement and the context; the best structured statement is selected based on the score and returned to the user; if the user is not satisfied with the provided structured statement, more information is provided or the instruction is modified to update the context, and the interaction phase is re-executed to generate a new structured statement. After completing multiple rounds of interaction, a structured statement is generated for the power grid analysis tool to call.

[0029] In a second aspect, a power grid analysis tool calling system based on a large language model is provided, comprising:

[0030] The interface information collection and standardization processing module is used to collect the interface information of each power grid analysis tool, standardize the interface information of the power grid analysis tool, and establish an interface information library;

[0031] A calling instruction classification and marking module is used to generate calling instructions of the power grid analysis tool according to the interface information library, and classify and mark the calling instructions of the power grid analysis tool to form an instruction data set;

[0032] The power grid analysis tool calls the large language model parameter fine-tuning module, which is used to use the instruction data set to fine-tune the pre-established power grid analysis tool calls the large language model parameters to obtain the optimized power grid analysis tool calls the large language model;

[0033] The power grid analysis tool call structured statement generation module is used to retrieve and return a set of instructions corresponding to the input instruction semantics from the instruction data set after the instruction is input, and generate the power grid analysis tool call structured statement by performing multiple rounds of interaction with the optimized power grid analysis tool call large language model;

[0034] The calling execution module is used to call the structured statement generated by the power grid analysis tool and perform the calling operation on the corresponding power grid analysis tool.

[0035] According to a third aspect, an electronic device is provided, comprising a processor and a memory, wherein the processor is configured to execute a computer program stored in the memory to implement the large language model-based power grid analysis tool calling method.

[0036] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores at least one instruction, and when the at least one instruction is executed by a processor, the method for calling a power grid analysis tool based on a large language model is implemented.

[0037] Compared with the prior art, the first aspect of the present invention has at least the following beneficial effects:

[0038] In view of the limitations of traditional power grid analysis tool calling methods in terms of digitalization and efficiency, the power grid analysis tool calling method based on the large language model of the present invention combines the power grid analysis tool calling with the large language model technology, fully utilizes the powerful natural language processing capabilities of the large language model, and realizes seamless docking with the power grid analysis tool through fine-tuning and optimization, thereby improving the accuracy of calling and the convenience of user interaction. The power grid analysis tool calling method based on the large language model of the present invention collects the interface information of each power grid analysis tool and performs standardized processing, classifies and labels the calling instructions of the power grid analysis tool to form an instruction data set, uses the instruction data set to fine-tune and optimize the parameters of the pre-established power grid analysis tool calling the large language model, retrieves and returns a set of instructions corresponding to the input instruction semantics from the instruction data set, and generates a power grid analysis tool calling structured statement by performing multiple rounds of interaction with the optimized power grid analysis tool calling the large language model, and finally executes the calling operation on the corresponding power grid analysis tool according to the generated power grid analysis tool calling structured statement to complete the power grid analysis task required by the user. Compared with traditional tool calling methods, the present invention can accurately analyze user needs through natural language processing technology and automatically retrieve and execute corresponding tool interfaces. It is significantly better than traditional power grid analysis tool calling methods in terms of accuracy, automation level and user experience.

[0039] It can be understood that the beneficial effects of the second to fourth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0041] Figure 1 Schematic diagram of a process of fine-tuning a large language model called by a power grid analysis tool according to an embodiment of the present invention;

[0042] Figure 2 A schematic diagram of a process of generating a power grid analysis tool calling a structured statement in an embodiment of the present invention. DETAILED DESCRIPTION

[0043] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0044] A power grid analysis tool refers to a software system used to conduct a comprehensive safety assessment of the power system. It uses methods such as static safety analysis and N-1 over-limit scanning to conduct a comprehensive analysis of the power grid's power flow, power balance, voltage stability, etc., identify potential safety hazards in the power grid under normal or accident conditions, and provide early warning and auxiliary decision support for power grid dispatching and operation, thereby ensuring the reliable and stable operation of the power system. Power grid analysis tools usually require users to have an in-depth understanding of the power grid structure and related businesses, manually input relevant parameters, and interpret structured analysis results. With the development of artificial intelligence technology, more digital and automated tool calls can be achieved by combining power grid analysis tools with large language models.

[0045] In the related prior art, for example, the patent application with publication number CN114844707A proposes "a method and system for analyzing power grid network security based on a graph database", which uses a graph database-based approach to collect, clean and store power grid network security data, and construct graph database query operation Cypher statements for nodes and relationships such as attack source address IP, attacked target address IP, operating system, media access control MAC address, threat intelligence, etc. These Cypher statements are then imported into the Neo4j graph database to construct a knowledge graph, achieving full and incremental updates; finally, the system's flexibility and scalability are improved by containerizing the application container engine Docker. However, the data processing method of this solution is relatively traditional, and the degree of digitalization and automation is low. This solution uses the relational database management system MySQL to store data, requires manual data cleaning, and does not use big data, machine learning and other technologies for data analysis and processing, so the data processing efficiency and quality are relatively low. Secondly, it lacks human-computer interaction and natural language processing capabilities. This solution mainly focuses on data collection, storage and knowledge graph construction, does not use natural language processing technology, and does not have the ability of human-computer interaction and intelligent question and answer. Finally, the tool calling method of this solution is relatively simple and the level of digital intelligence is low. Since this solution mainly uses predefined Cypher statements to implement tool calling, the calling method is relatively simple and rigid, lacking flexibility and digital intelligence.

[0046] For example, the patent application with the publication number "CN115954868A" proposes "a method, device and medium for power grid security analysis", which uses a multi-dimensional evaluation system to obtain the original load data and network topology parameters in the power grid security analysis and determine all possible startup combinations. Then the operation of the startup combination is scored and evaluated to select the optimal startup combination with the highest comprehensive score; finally, the optimized startup combination, comprehensive score curve, line operation information and percentage score that meet the requirements are output. This solution also constructs a safety verification optimization model for future power flow uncertainty, proposes a mixed integer programming solution based on the path tracking method, and realizes a comprehensive analysis of power grid security. However, this solution lacks natural language interaction capabilities. This solution mainly focuses on the optimization of power grid analysis models and algorithms, does not use natural language processing technology, does not have the ability of human-computer interaction and intelligent question and answer, and users cannot communicate efficiently with the system through natural language, which affects the ease of use and user experience of the system. At the same time, this solution mainly uses preset optimization models and algorithms to implement power grid analysis, and the tool calling method is relatively rigid, lacking flexibility and scalability. In addition, this solution mainly focuses on the modeling and optimization methods of power grid analysis and lacks the ability to integrate and orchestrate different analysis tools.

[0047] The embodiment of the present invention proposes a method for calling a power grid analysis tool based on a large language model, and solves the problems of low efficiency, low degree of digitalization, and high complexity of user interaction in the calling process of existing power grid analysis tools in the field of power dispatching automation based on the large language model technology. By combining advanced large language model technology with the power grid analysis tool interface, a digitalized tool calling framework is effectively constructed, realizing the digitalization and automation of the tool calling process.

[0048] A large language model (LLM) is a model with a large number of parameters that is trained using deep learning technology. The large language model can understand and generate natural language text. The large language model learns the statistical laws of language by pre-training on large-scale data sets, so that it can predict or generate text sequences based on a given context.

[0049] See also Figure 1 and Figure 2 The method for calling a power grid analysis tool based on a large language model in an embodiment of the present invention makes full use of the powerful natural language processing capability of the large language model, realizes seamless connection with the power grid analysis tool through fine-tuning and optimization, and improves the accuracy of calling and the convenience of user interaction. The method in an embodiment of the present invention mainly includes the following steps:

[0050] S1. Collect the interface information of each power grid analysis tool, standardize the interface information of the power grid analysis tool, and establish an interface information library;

[0051] S2. Generate a call instruction of a power grid analysis tool according to the interface information library, and classify and mark the call instruction of the power grid analysis tool to form an instruction data set;

[0052] S3, using the instruction data set to fine-tune the parameters of the pre-established power grid analysis tool calling the large language model, to obtain an optimized power grid analysis tool calling the large language model;

[0053] S4, after inputting the command, retrieve and return a set of commands corresponding to the input command semantics from the command data set, and generate a structured statement for calling the power grid analysis tool by performing multiple rounds of interaction with the optimized power grid analysis tool calling large language model;

[0054] S5. According to the generated power grid analysis tool calling structured statement, a calling operation is performed on the corresponding power grid analysis tool.

[0055] In a possible implementation manner, in step S1, when collecting interface information of each power grid analysis tool, an interface information collection template is defined to collect the interface information. The interface information collection template includes field names and corresponding descriptions.

[0056] Furthermore, the field names include interface name, function description, input parameter, output parameter, parameter type, and calling method, etc. The description corresponding to the interface name is the unique identifier of the interface, the description corresponding to the function description is the detailed description of the interface function, the description corresponding to the input parameter is the input information list required by the interface, the description corresponding to the output parameter is the output information list of the interface, the description corresponding to the parameter type is the data type of the input or output parameter, and the description corresponding to the calling method is the specific way to call the interface. An example of an interface information collection template is shown in Table 1.

[0057] Table 1

[0058]

[0059] Information is collected based on the above interface information collection template, relevant power grid structured data interface documents are sorted out, interface information is extracted, and filled in according to the interface information collection template.

[0060] In a possible implementation, after the interface information of the power grid analysis tool is standardized in step S1, the same functional interface input parameters of different power grid analysis tools have unified parameter names and data types.

[0061] The process of parameter standardization is formally expressed as follows:

[0062]

[0063] in, The function converts parameter names and types according to predefined standardization rules; Indicates the parameter name. Indicates the parameter type.

[0064] Next, an interface mapping table is established to map interfaces with similar or identical functions in different power grid analysis tools, so that a unified calling method is used when calling different power grid analysis tools. The interface mapping table is shown in Table 2.

[0065] Table 2

[0066]

[0067] The result data returned by the interface is marked as two types: one is dictionary data saved in Key-Value format, where Key is the data keyword and Value is a data structure containing three attributes, namely data type, data length and data value. The data value attribute can include a string in lightweight data exchange JSON format. The other is in Vector format. <vector>The data stored in the form of a two-dimensional table contains data in which each element in the first-level Vector represents a row of data in the two-dimensional table, and each element in the second-level Vector represents the data in a certain field of a row in the two-dimensional table. This data is represented by a data structure, which contains four attributes, namely data type, data length, data value and attribute name. Some examples of interface return objects are shown in Table 3:

[0068] Table 3

[0069]

[0070] Establish a standardized and encapsulated interface information library for power grid analysis tools. The database table structure contains all the fields in the above template. Perform data entry, input the standardized interface information into the database, and establish a complete interface information library.

[0071] In a possible implementation manner, the step of generating a call instruction of a power grid analysis tool according to an interface information library in step S2, and classifying and labeling the call instruction of the power grid analysis tool to form an instruction data set includes:

[0072] Design a set of instruction templates, each of which corresponds to a specific power grid analysis tool and operation; the instruction template includes a fixed grammatical structure and placeholders for inserting specific parameters. The formal expression of the instruction template is as follows:

[0073] <Tool Name><Operation><Parameter 1><Parameter 2>...<Parameter N>

[0074] Among them, <tool name>, <operation> and <parameters> are all filled in according to the specific instruction content.

[0075] Access the interface information library and extract the interface information of each interface, including tool name, operation, parameter list, etc. Next, according to the instruction template and interface information, use string replacement or template engine to generate the calling instruction of the power grid analysis tool.

[0076] The steps of classifying and labeling the call instructions of the power grid analysis tool include: defining a series of rules to classify the generated call instructions according to the corresponding functions and uses; then, applying the defined rules to label each call instruction with multi-dimensional labels, such as "section", "limit", "base state", etc. Finally, the generated instructions and corresponding labels are integrated into a structured data set, usually in comma-separated value CSV or JavaScript object representation JSON format, for subsequent model fine-tuning.

[0077] An example of instruction fine-tuning data is as follows:

[0078] Tool Description:

[0079] Interface name: getBaseOverLimit

[0080] Interface description: Get section limit information

[0081] Interface input: {"param1": section ID, "param2": date}

[0082] Interface return type: Key-Value

[0083] Interface labels: Section, Limit

[0084] In a possible implementation, step S3 fine-tunes and optimizes the power grid analysis tool to call the large language model based on the prompt word template, and defines a series of templates to guide the power grid analysis tool to call the large language model to generate answers in the field of power grid analysis. The template is a pre-designed text fragment that contains placeholders for inserting specific information. The specific information is keywords or parameters related to the power grid analysis tool call instruction. The format includes prompt word template, question, thought chain, and answer.

[0085] An example of this is shown below:

[0086] Question and answer data:

[0087] "Prompt words": "You are a knowledgeable power grid analysis assistant who can help users analyze the current operation of the power grid."

[0088] "Question":"What is the current limit for the Hubei-Henan section?

[0089] "Thinking Chain":[

[0090] "Thinking process": "To query the section limit, you need to know the time and the ID information corresponding to the section."

[0091] "Thinking 1": "Need to query the ID of the Hubei-Henan section"

[0092] "Action 1":"get_id",

[0093] "Input 1":"{"param1":section name}

[0094] "Output 1":"{"E-Yu section":XX}

[0095] "Thinking 2": "Need to query the current date"

[0096] "Action 2":"get_date",

[0097] "Input 2":"{"param1":Section ID, "param2":Date}

[0098] "Output 2":"{"date":XX-XX-XX}

[0099] "Thinking 3": "Need to query the section limit of ID XX on the date XX-XX-XX"

[0100] "Action 3": "getBaseOverLimit",

[0101] "Input 3":"{}

[0102] "Output 3":"{"Limit":XXXXXX} ]

[0104] "Answer":"The current time is XX-XX-XX, and the limit of the Hubei-Henan section with ID XX is XXXXXX"

[0105] The fine-tuning process involves combining the pre-established large language model for power grid analysis tool calls with the instruction dataset, which contains a large number of power grid analysis tool call instruction samples, which are usually annotated and organized in a certain format (such as JSON or CSV). The purpose of fine-tuning is to enable the large language model for power grid analysis tool calls to understand and generate outputs that are consistent with the power grid analysis tool call instructions; the fine-tuning process is based on the following expression:

[0106]

[0107] In the formula, represents the loss function, The power grid analysis tool calls the large language model parameters. is the total number of samples in the instruction dataset, It is The input of samples, is the corresponding target output, is the corresponding prompt word template, which indicates the probability that the model generates the correct output given the input and prompt word template; in the fine-tuning process, adjust the parameters of the large language model called by the power grid analysis tool To minimize the loss function, the power grid analysis tool calls the large language model to generate target instructions. This process uses the gradient descent algorithm, which is the adaptive moment estimation Adam or the stochastic gradient descent SGD, to iteratively update the model parameters. The base large language model used for fine-tuning is shown in Table 4:

[0108] Table 4

[0109]

[0110] The parameters supported by the fine-tuning process are shown in Table 5:

[0111] Table 5

[0112]

[0113] After sufficient training cycles and careful parameter adjustment, an optimized large language model can be obtained, which shows better understanding and generation capabilities in the call of power grid analysis tools, and becomes the large language model for power grid analysis tool calls. This model can be directly applied to automated power grid analysis tasks to improve the efficiency and accuracy of power grid analysis.

[0114] In one possible implementation, in step S4, after the user inputs an instruction, a set of instructions that are semantically close or related to the input instruction is retrieved and returned from the constructed instruction data set. First, the preprocessed user instruction text is converted into a vector using a word embedding model (such as a word vector model Word2Vec, a bidirectional encoder model BERT, etc.). This can be achieved by converting each word into a vector of fixed dimension, and then merging all word vectors in an instruction (for example, by averaging or weighted summing). Then, a similarity calculation is performed. Since each known instruction in the instruction data set is also converted into a vector form and stored, when the user enters a new instruction, the similarity between the input instruction vector and each known instruction vector in the instruction data set can be calculated. The cosine similarity calculation formula can be used for similarity calculation:

[0115]

[0116] In the formula, and is the vector representation of two instructions, represents the dot product of vectors, and and are the norm or length of the vector respectively; according to the similarity calculated above, several instructions with the highest similarity are selected as the search results. This result set can be further sorted according to the similarity so that the most relevant instructions are displayed at the front.

[0117] In a possible implementation, step S4 is based on the interactive system of the LLaMA large language model, which generates a structured statement for calling the power grid analysis tool from the user's unstructured instructions through multiple rounds of interaction with the user.

[0118] Specifically, in order to conduct effective multi-round interactions, a context environment is first constructed, which includes the user's original instructions, historical interaction records, and possible user intentions. Then, based on the instructions retrieved from the instruction dataset, the LLaMA large language model is used to generate a series of potential structured sentences according to the constructed context. These sentences are interpretations of user instructions, designed to be converted into a format that can be understood and executed by power grid analysis tools. For each round of generated structured sentences, an evaluation function is defined to measure the degree of match with user intentions. The expression of the evaluation function is as follows:

[0119]

[0120] In the formula, is the generated structured statement, is the context, is the quality scoring function of the structured statement itself, such as the grammatical correctness and execution feasibility of the structured statement, and It is a scoring function of the relevance of structured statements to context, such as the semantic match between structured statements and user instructions. The best structured statement is selected based on the score and returned to the user. The user's positive and negative feedback can be used to further fine-tune and optimize the model. If the user is not satisfied with the structured statement provided, he can provide more information or modify the instruction to update the context, re-execute the interaction phase, generate a new structured statement, and after completing multiple rounds of interaction, generate the final structured statement for the power grid analysis tool to call.

[0121] In some other possible implementations, a traditional machine learning classification model, such as a support vector machine (SVM) or a decision tree, may also be used to classify user input instructions and map them to a specific power grid analysis tool interface.

[0122] Alternatively, a manually written fixed template may be used to generate structured statements for calling power grid analysis tools.

[0123] Alternatively, a single round of recognition based on keyword extraction may be used instead of multiple rounds of interaction with the optimized power grid analysis tool by calling the large language model, and the user's input instructions will be directly mapped to the interface of the power grid analysis tool.

[0124] In some other possible implementations, a smaller language model optimized for a specific domain may be used to process user input instructions instead of a large language model such as LLaMA.

[0125] Compared with the prior art, the power grid analysis tool calling method based on the large language model of the present invention uses prompt word templates to call the large language model with the power grid analysis tool for multiple rounds of interaction. Users can communicate efficiently with the system through natural language, which greatly improves the digital intelligence level of the system and user experience. By utilizing the tool calling capability of the large language model, it is possible to intelligently match and generate a variety of power grid analysis tool calling statements according to user instructions, making the power grid analysis tool calling process more intelligent and flexible. At the same time, various power grid analysis tools can be flexibly integrated and arranged to achieve flexible combination and coordinated optimization of tool functions.

[0126] Another embodiment of the present invention further provides a power grid analysis tool calling system based on a large language model, comprising:

[0127] The interface information collection and standardization processing module is used to collect the interface information of each power grid analysis tool, standardize the interface information of the power grid analysis tool, and establish an interface information library;

[0128] A calling instruction classification and marking module is used to generate calling instructions of the power grid analysis tool according to the interface information library, and classify and mark the calling instructions of the power grid analysis tool to form an instruction data set;

[0129] The power grid analysis tool calls the large language model parameter fine-tuning module, which is used to use the instruction data set to fine-tune the pre-established power grid analysis tool calls the large language model parameters to obtain the optimized power grid analysis tool calls the large language model;

[0130] The power grid analysis tool call structured statement generation module is used to retrieve and return a set of instructions corresponding to the input instruction semantics from the instruction data set after the instruction is input, and generate the power grid analysis tool call structured statement by performing multiple rounds of interaction with the optimized power grid analysis tool call large language model;

[0131] The calling execution module is used to call the structured statement generated by the power grid analysis tool and perform the calling operation on the corresponding power grid analysis tool.

[0132] Another embodiment of the present invention further provides an electronic device, including a processor and a memory, wherein the processor is used to execute a computer program stored in the memory to implement the large language model-based power grid analysis tool calling method.

[0133] Another embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one instruction, and when the at least one instruction is executed by a processor, the method for calling a power grid analysis tool based on a large language model is implemented.

[0134] The computer program includes computer program code, which may be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may include: any entity or device, medium, USB flash drive, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, electric carrier signal, telecommunication signal and software distribution medium, etc. that can carry the computer program code. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals. For ease of explanation, the above content only shows the part related to the embodiment of the present invention. For specific technical details not disclosed, please refer to the method part of the embodiment of the present invention. The computer-readable storage medium is non-temporary and can be stored in a storage device formed by various electronic devices, which can realize the execution process recorded in the method of the embodiment of the present invention.

[0135] It should be understood by those skilled in the art that the embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware aspects. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0136] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the process in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0137] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0138] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0139] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.< / vector> < / vector>

Claims

1. A method for calling a power grid analysis tool based on a large language model, characterized in that: include: Collect the interface information of each power grid analysis tool, standardize the interface information of the power grid analysis tool, and establish an interface information library; Generate calling instructions of the power grid analysis tool according to the interface information library, and classify and mark the calling instructions of the power grid analysis tool to form an instruction data set; The command data set is used to fine-tune the parameters of the pre-established large language model called by the power grid analysis tool, so as to obtain an optimized large language model called by the power grid analysis tool; After the command is input, a set of commands corresponding to the input command semantics is retrieved and returned from the command data set, and multiple rounds of interactions are performed with the optimized power grid analysis tool call large language model to generate a structured statement for calling the power grid analysis tool; According to the generated power grid analysis tool calling structured statement, a calling operation is performed on the corresponding power grid analysis tool; The steps of retrieving and returning a set of instructions corresponding to the input instruction semantics from the instruction data set, and generating a structured statement for calling the power grid analysis tool by performing multiple rounds of interaction with the optimized power grid analysis tool calling large language model include: A context environment is constructed, which includes the user's original instructions, historical interaction records and possible user intentions. Based on the retrieved instructions, the optimized power grid analysis tool is used to call the large language model, and a series of potential structured sentences are generated according to the constructed context environment. The structured sentences are interpretations of the user instructions and have a format that the power grid analysis tool can understand and execute. For the generated structured sentences, an evaluation function is defined to measure the matching degree with the user intention. The expression of the evaluation function is as follows: In the formula, is the generated structured statement, is the context, is the quality scoring function of the structured sentence itself, and It is a scoring function of the relevance between structured statements and context; the best structured statement is selected based on the score and returned to the user; if the user is not satisfied with the provided structured statement, more information is provided or the instruction is modified to update the context, and the interaction phase is re-executed to generate a new structured statement. After completing multiple rounds of interaction, a structured statement is generated for the power grid analysis tool to call.

2. The method for calling a power grid analysis tool based on a large language model according to claim 1, characterized in that: When collecting the interface information of each power grid analysis tool, an interface information collection template is defined to collect the interface information, and the interface information collection template includes field names and corresponding descriptions; wherein the field names include interface names, function descriptions, input parameters, output parameters, parameter types, and calling methods; the description corresponding to the interface name is a unique identifier of the interface, the description corresponding to the function description is a detailed description of the interface function, the description corresponding to the input parameter is a list of input information required by the interface, the description corresponding to the output parameter is a list of output information of the interface, the description corresponding to the parameter type is a data type of the input or output parameter, and the description corresponding to the calling method is a specific way to call the interface.

3. The method for calling a power grid analysis tool based on a large language model according to claim 1, characterized in that: In the step of standardizing the interface information of the power grid analysis tool, the same function interface input parameters of different power grid analysis tools have unified parameter names and data types; an interface mapping table is established, and a unified calling method is used when calling different power grid analysis tools through interface mapping; the result data returned by the interface is marked into two types: one is dictionary data saved in the form of Key-Value, where Key is a data keyword and Value is a data structure containing three attributes, which are data type, data length and data value; the other is in the form of Vector <vector> The data is saved in the form of a two-dimensional table, where each element in the first-level Vector represents a row of data in the two-dimensional table, and each element in the second-level Vector represents the data in a certain field of a certain row in the two-dimensional table. This data is represented by a data structure, which contains four attributes, namely data type, data length, data value and attribute name.< / vector> 4. The method for calling a power grid analysis tool based on a large language model according to claim 1, characterized in that: The steps of generating the calling instructions of the power grid analysis tool according to the interface information library, and classifying and marking the calling instructions of the power grid analysis tool to form the instruction data set include: designing a set of instruction templates, each instruction template corresponding to a specific power grid analysis tool and operation; the instruction template includes a fixed grammatical structure and a placeholder for inserting specific parameters; The formal expression of the instruction template is as follows: <Tool Name> <Operation> <Parameter 1> <Parameter 2> ... <Parameter N> Among them, <tool name>, <operation> and <parameters> are all filled in according to the specific instruction content; Access the interface information library and extract the interface information of each interface; generate the calling instructions of the power grid analysis tool according to the instruction template and the interface information; the steps of classifying and labeling the calling instructions of the power grid analysis tool include: defining several rules to classify the generated calling instructions according to the corresponding functions and uses; applying the defined rules to label each calling instruction with a multi-dimensional label, integrating the generated calling instructions and the corresponding labels into a structured data set, and obtaining the instruction data set.

5. The method for calling a power grid analysis tool based on a large language model according to claim 1, characterized in that: In the step of using the instruction data set to fine-tune the parameters of the pre-established power grid analysis tool calling the large language model to obtain the optimized power grid analysis tool calling the large language model, several templates are defined to guide the power grid analysis tool to call the large language model to generate answers in the field of power grid analysis. The template is a pre-designed text fragment, which contains a placeholder for inserting specific information. The specific information is a keyword or parameter related to the power grid analysis tool calling instruction, and the format includes a prompt word template, a question, a thinking chain, and an answer; the fine-tuning process involves combining the pre-established power grid analysis tool calling the large language model with the instruction data set, and the purpose of the fine-tuning is to enable the power grid analysis tool to call the large language model to understand and generate outputs that are consistent with the power grid analysis tool calling instruction; the fine-tuning process is based on the following expression: In the formula, represents the loss function, It is the power grid analysis tool that calls the large language model parameters. is the total number of samples in the instruction dataset, It is The input of samples, is the corresponding target output, is the corresponding prompt word template, which indicates the probability that the model generates the correct output given the input and prompt word template; in the fine-tuning process, adjust the parameters of the large language model called by the power grid analysis tool To minimize the loss function, the power grid analysis tool calls the large language model to generate target instructions.

6. The method for calling a power grid analysis tool based on a large language model according to claim 1, characterized in that: The retrieving and returning a set of instructions corresponding to the input instruction semantics from the instruction data set comprises: The word embedding model is used to convert the input instruction text into a vector, and then the similarity is calculated. In the instruction data set, each known instruction is also converted into a vector form and stored. The similarity between the input instruction vector and each known instruction vector in the instruction data set is calculated. The following cosine similarity calculation formula is used to calculate the similarity between vectors: In the formula, and is the vector representation of two instructions, represents the dot product of vectors, and and are the norm or length of the vector respectively; according to the calculated similarity, several instructions with the highest similarity are selected as the retrieval results.

7. A power grid analysis tool calling system based on a large language model, characterized in that: include: The interface information collection and standardization processing module is used to collect the interface information of each power grid analysis tool, standardize the interface information of the power grid analysis tool, and establish an interface information library; A calling instruction classification and marking module is used to generate calling instructions of the power grid analysis tool according to the interface information library, and classify and mark the calling instructions of the power grid analysis tool to form an instruction data set; The power grid analysis tool calls the large language model parameter fine-tuning module, which is used to use the instruction data set to fine-tune the pre-established power grid analysis tool calls the large language model parameters to obtain the optimized power grid analysis tool calls the large language model; The power grid analysis tool call structured statement generation module is used to retrieve and return a set of instructions corresponding to the input instruction semantics from the instruction data set after the instruction is input, and generate the power grid analysis tool call structured statement by performing multiple rounds of interaction with the optimized power grid analysis tool call large language model; The steps of retrieving and returning a set of instructions corresponding to the input instruction semantics from the instruction data set, and generating a structured statement for calling the power grid analysis tool by performing multiple rounds of interaction with the optimized power grid analysis tool calling large language model include: A context environment is constructed, which includes the user's original instructions, historical interaction records and possible user intentions. Based on the retrieved instructions, the optimized power grid analysis tool is used to call the large language model, and a series of potential structured sentences are generated according to the constructed context environment. The structured sentences are interpretations of the user instructions and have a format that the power grid analysis tool can understand and execute. For the generated structured sentences, an evaluation function is defined to measure the matching degree with the user intention. The expression of the evaluation function is as follows: In the formula, is the generated structured statement, is the context, is the quality scoring function of the structured sentence itself, and It is a scoring function of the relevance between structured statements and contexts; the best structured statement is selected based on the score and returned to the user; if the user is not satisfied with the structured statement provided, more information is provided or the instruction is modified to update the context, and the interaction phase is re-executed to generate a new structured statement. After completing multiple rounds of interaction, a structured statement is generated for the power grid analysis tool to call; The calling execution module is used to call the structured statement generated by the power grid analysis tool and perform the calling operation on the corresponding power grid analysis tool.

8. An electronic device, characterized in that: The invention comprises a processor and a memory, wherein the processor is used to execute a computer program stored in the memory to implement the method for calling a power grid analysis tool based on a large language model as claimed in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction, and when the at least one instruction is executed by a processor, the method for calling a power grid analysis tool based on a large language model as claimed in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Grid network security analysis method and system based on graph database

    CN114844707A

  • Power grid safety analysis method and device and medium

    CN115954868A

  • Data processing method and apparatus

    CN108897897A

  • Cross-platform instruction and unified interface configuration system

    CN112148349A