Power grid analytical tool invoking method and system based on large language model

By collecting and standardizing the interface information of power grid analysis tools through large language model technology, generating call commands and conducting multi-round interactions, the problems of low efficiency and complex user interaction in traditional power grid analysis tools are solved, realizing efficient, flexible and intelligent calling of power grid analysis tools.

WO2026130481A1PCT designated stage Publication Date: 2026-06-25CHINA ELECTRIC POWER RESEARCH INSTITUTE CO LTD

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
CHINA ELECTRIC POWER RESEARCH INSTITUTE CO LTD
Filing Date
2025-12-18
Publication Date
2026-06-25

Smart Images

  • Figure CN2025143659_25062026_PF_FP_ABST
    Figure CN2025143659_25062026_PF_FP_ABST
Patent Text Reader

Abstract

Provided are a power grid analytical tool invoking method and system based on a large language model. The method comprises: collecting interface information of power grid analytical tools, performing standardization processing on the interface information, and establishing an interface information base; on the basis of the interface information base, generating invocation instructions for the power grid analytical tools, and classifying and annotating the invocation instructions to form an instruction data set; using the instruction data set to fine-tune parameters of a large language model for power grid analytical tool invocation, so as to obtain an optimized large language model; after an instruction is inputted, retrieving and returning, from the instruction data set, a set of instructions corresponding to the semantics of the inputted instruction, and by means of multiple rounds of interactions with the optimized large language model for power grid analytical tool invocation, generating structured statements for power grid analytical tool invocation; and, on the basis of the generated structured statements for power grid analytical tool invocation, executing an invocation operation on a corresponding power grid analytical tool.
Need to check novelty before this filing date? Find Prior Art

Description

A Method and System for Calling Power Grid Analysis Tools Based on Large Language Models

[0001] This disclosure claims priority to Chinese patent application No. 202411879998.7, filed on December 19, 2024, the entire contents of which are incorporated herein by reference. Technical Field

[0002] This disclosure relates to the field of power automation technology, and in particular to a method and system for invoking power grid analysis tools based on a large language model. Background Technology

[0003] 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 public concern. In traditional power grid management, power grid analysis tools are widely used to monitor and maintain the stable operation of the power grid, such as static security analysis and N-1 over-limit scanning. Summary of the Invention

[0004] This disclosure provides a method and system for invoking power grid analysis tools based on a large language model.

[0005] Firstly, a method for invoking power grid analysis tools based on a large language model is provided. The method includes: collecting interface information of various power grid analysis tools and standardizing this information to establish an interface information database; generating invoking instructions for the power grid analysis tools based on the interface information database, and classifying and labeling these instructions to form an instruction dataset; fine-tuning the parameters of a pre-established large language model for power grid analysis tool invoking using the instruction dataset to obtain an optimized large language model for power grid analysis tool invoking; after inputting an instruction, retrieving and returning a set of instructions semantically corresponding to the input instruction from the instruction dataset, and generating a structured statement for power grid analysis tool invoking through multiple rounds of interaction with the optimized large language model for power grid analysis tool invoking; and executing an invoking operation on the corresponding power grid analysis tool based on the generated structured statement for power grid analysis tool invoking.

[0006] In some embodiments, when collecting interface information of various power grid analysis tools, an interface information collection template is defined to collect interface information. The interface information collection template includes field names and corresponding descriptions. The field names include interface name, function description, 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 parameters is a list of input information required by the interface, the description corresponding to the output parameters is a list of output information of the interface, the description corresponding to the parameter types is the data type of the input or output parameters, and the description corresponding to the calling methods is the way to call the interface.

[0007] In some embodiments, in the step of standardizing the interface information of the power grid analysis tools, the input parameters of the same functional interfaces of different power grid analysis tools have unified parameter names and data types; an interface mapping table is established, and the interface mapping enables the use of a unified calling method when calling different power grid analysis tools; the result data returned by the interface is marked in two ways: one is dictionary data stored in key-value format, where the key is the data key and the value is a data structure containing three attributes, namely data type, data length, and data value; the other is vector data. <vector>The data is stored in a format that contains a two-dimensional table. 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 specific field of a specific row in the two-dimensional table. This data is represented by a data structure that contains four attributes: data type, data length, data value, and attribute name.

[0008] In some embodiments, the step of generating invocation instructions for power grid analysis tools based on the interface information database, and classifying and labeling the invocation instructions for power grid analysis tools to form an instruction dataset includes: 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 syntax structure and placeholders for inserting specific parameters;

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

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

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

[0012] Access the interface information database and extract the interface information for each interface; generate the calling instructions for the power grid analysis tool based on the instruction template and interface information; the steps for classifying and labeling the calling instructions for the power grid analysis tool include: defining several rules to classify the generated calling instructions according to their corresponding functions and uses; applying the defined rules to assign multi-dimensional labels to each calling instruction; and integrating the generated calling instructions and their corresponding labels into a structured dataset to obtain the instruction dataset.

[0013] In some embodiments, in the step of fine-tuning the parameters of a pre-established power grid analysis tool invocation language model using an instruction dataset to obtain an optimized power grid analysis tool invocation language model, several templates are defined to guide the power grid analysis tool invocation language model in generating answers in the power grid analysis domain. The templates are pre-designed text fragments containing placeholders for inserting specific information, which is keywords or parameters related to the power grid analysis tool invocation instructions. The format includes prompt templates, questions, thought chains, and answers. The fine-tuning process involves combining the pre-established power grid analysis tool invocation language model with the instruction dataset. The purpose of the fine-tuning is to enable the power grid analysis tool invocation language model to understand and generate outputs consistent with the power grid analysis tool invocation instructions. The fine-tuning process is based on the following expression:

[0014] In the formula, L(θ) represents the loss function, θ is the parameter of the large language model called by the power grid analysis tool, N is the total number of samples in the instruction dataset, and x i It is the input of the i-th sample, y i It is the corresponding target output, T i It is the corresponding prompt word template, representing the probability that the model generates the correct output given the input and the prompt word template; during the fine-tuning process, the parameters θ of the large language model called by the power grid analysis tool are adjusted to minimize the loss function, so that the power grid analysis tool calls the large language model to generate the target instruction.

[0015] In some embodiments, retrieving and returning a set of instructions corresponding to the semantics of the input instructions from the instruction dataset includes:

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

[0017] In the formula, A and B are the vector representations of the two instructions, A·B represents the dot product of the vectors, and ||A|| and ||B|| are the norm or length of the vectors, respectively. Based on the calculated similarity, the instructions with the highest similarity are selected as the search results.

[0018] In some embodiments, the step of retrieving and returning a set of instructions corresponding to the semantics of the input instructions from the instruction dataset, and generating structured statements for the power grid analysis tool through multi-round interactions with the optimized power grid analysis tool's large language model, includes:

[0019] A context environment is constructed, which includes the user's original command, historical interaction records, and possible user intents. Based on the retrieved command, an optimized power grid analysis tool is used to invoke a large language model to generate a series of potential structured statements according to the constructed context environment. These structured statements are interpretations of the user command and have a format that the power grid analysis tool can understand and execute. For each generated structured statement, an evaluation function is defined to measure its matching degree with the user intent. The expression of the evaluation function is as follows: Score(S, C) = f(S) + g(S, C)

[0020] In the formula, S is the generated structured statement, C is the context environment, f(S) is the quality scoring function of the structured statement itself, and g(S,C) is the scoring function of the relevance of the statement to 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 or modification instructions are provided to update the context, and the interaction phase is re-executed to generate a new structured statement. After multiple rounds of interaction, the structured statement called by the power grid analysis tool is generated.

[0021] Secondly, a power grid analysis tool invocation system based on a large language model is provided. The system includes: an interface information collection and standardization processing module, an invocation instruction classification and annotation module, a power grid analysis tool invocation large language model parameter fine-tuning module, a power grid analysis tool invocation structured statement generation module, and an invocation execution module.

[0022] The interface information collection and standardization processing module is configured to collect interface information from various power grid analysis tools, standardize the interface information of the power grid analysis tools, and establish an interface information database.

[0023] The instruction classification and annotation module is configured to generate instruction calls for the power grid analysis tool based on the interface information database, and to classify and annotate the instruction calls for the power grid analysis tool to form an instruction dataset.

[0024] The power grid analysis tool invocation large language model parameter fine-tuning module is configured to use the instruction dataset to fine-tune the pre-established power grid analysis tool invocation large language model parameters to obtain an optimized power grid analysis tool invocation large language model.

[0025] The power grid analysis tool calls the structured statement generation module, which is configured to retrieve and return a set of instructions corresponding to the semantics of the input instruction from the instruction dataset after the input instruction is input, and generate the power grid analysis tool call structured statement through multiple rounds of interaction with the optimized power grid analysis tool call large language model.

[0026] The call execution module is configured to execute call operations on the corresponding power grid analysis tool by calling the structured statement generated by the power grid analysis tool.

[0027] Thirdly, an electronic device is provided, comprising a processor and a memory, wherein the processor is used to execute a computer program stored in the memory to implement the method for invoking the power grid analysis tool based on a large language model.

[0028] Fourthly, a computer-readable storage medium is provided, the computer-readable storage medium storing at least one instruction, which, when executed by a processor, implements the method for invoking the power grid analysis tool based on a large language model. Attached Figure Description

[0029] To more clearly illustrate the technical solutions in this disclosure, the accompanying drawings used in some embodiments of this disclosure will be briefly described below. Obviously, the drawings described below are merely drawings of some embodiments of this disclosure, and those skilled in the art can obtain other drawings based on these drawings.

[0030] Figure 1 is a flowchart illustrating the process of a power grid analysis tool calling a large language model for fine-tuning according to some embodiments of the present disclosure.

[0031] Figure 2 is a flowchart illustrating the process of generating a power grid analysis tool that calls a structured statement according to some embodiments of the present disclosure. Detailed Implementation

[0032] To enable those skilled in the art to better understand the technical solutions of the embodiments of this disclosure, the technical solutions of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

[0033] In the description disclosed in this application, unless otherwise stated, the words "first," "second," etc. do not limit the quantity or order of execution, and the words "first," "second," etc., do not necessarily mean that they are different.

[0034] The slash " / " means "or". For example, A / B can mean either A or B. In this article, "and / or" is simply a way of describing the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: only A, only B, and A and B.

[0035] Power grid analysis tools are software systems used to conduct comprehensive security assessments of power systems. Through methods such as static security analysis and N-1 over-limit scanning, they comprehensively analyze aspects of the power grid, including power flow, power balance, and voltage stability. They identify potential security risks in both normal and fault states, providing early warnings and decision support for power grid dispatching and operation, thereby ensuring the reliable and stable operation of the power system. Power grid analysis tools typically require users to have a deep understanding of the power grid structure and related business processes, manually input relevant parameters, and interpret structured analysis results.

[0036] Faced with increasingly complex power grid environments and massive amounts of data, traditional power grid analysis tools suffer from limitations such as low efficiency and insufficient flexibility, making it difficult to fully meet the needs of modern power grids. Low efficiency refers to the fact that traditional power grid analysis tools often require complex calculations on large amounts of power grid data, leading to low computational efficiency. Furthermore, in distributed power grid environments, data transmission latency and bandwidth limitations also affect the real-time performance of analysis tools. Insufficient flexibility means that as the power grid structure continues to change and new energy sources are integrated, traditional tools often struggle to adapt quickly, resulting in inaccurate analysis results. Moreover, different power grid regions and operators may have specific analysis needs, but traditional tools often lack sufficient flexibility to meet these customized requirements. In addition, traditional methods struggle to handle massive amounts of data. With the rapid growth of power grid data, higher demands are placed on storage resources, and 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, in which traditional tools fall short. As the scale and complexity of power grids expand, the real-time requirements for power grid analysis tools become increasingly stringent, requiring these tools to accurately reflect the actual operating status and characteristics of the power grid.

[0037] With the development of artificial intelligence technology, combining power grid analysis tools with large language models can enable more intelligent and automated tool usage.

[0038] For example, some technologies propose "a graph database-based power grid network security analysis method and system," which uses a graph database approach to collect, clean, and store power grid network security data. It constructs Cypher statements for graph database query operations, including attack source IP addresses, target IP addresses, operating systems, Media Access Control (MAC) addresses, and threat intelligence nodes and relationships. These Cypher statements are then imported into the Neo4j graph database to build a knowledge graph, enabling full and incremental updates. Finally, the system is deployed using the Docker container engine, improving its flexibility and scalability. However, this approach has a relatively traditional data processing method and a low level of digitalization and automation. It uses a relational database management system like MySQL to store data, requiring manual data cleaning and lacking the use of big data and machine learning technologies for data analysis and processing, resulting in relatively low data processing efficiency and quality. Secondly, it lacks human-computer interaction and natural language processing capabilities. This approach primarily focuses on data collection, storage, and knowledge graph construction, without utilizing natural language processing technologies, and lacks human-computer interaction and intelligent question-answering capabilities. Finally, the tool invocation method in this approach is relatively simple, resulting in a low level of digitalization. Because this approach primarily uses predefined Cypher statements to invoke tools, the invocation method is relatively simple and rigid, lacking flexibility and digitalization.

[0039] For example, some other technologies propose "a power grid security analysis method, device, and medium," which uses a multi-dimensional evaluation system to acquire raw load data and network topology parameters for power grid security analysis, determining all possible operating combinations. The operating performance of these combinations is then scored and evaluated, selecting the optimal combination with the highest comprehensive score. Finally, the optimized operating combinations for the dispatching day, the comprehensive score curve, line operation information, and percentage scores are output. This approach also constructs a security verification optimization model for future power flow uncertainties and proposes a mixed-integer programming solution based on the path tracing method, achieving comprehensive analysis of power grid security. However, this approach lacks natural language interaction capabilities. It primarily focuses on optimizing the power grid analysis model and algorithms, without utilizing natural language processing technology, and lacks human-computer interaction and intelligent question-and-answer capabilities. Users cannot communicate efficiently with the system through natural language, affecting the system's usability. Furthermore, this approach mainly uses pre-defined optimization models and algorithms for power grid analysis, resulting in a relatively rigid tool invocation method and a lack of flexibility and scalability. Furthermore, this approach primarily focuses on modeling and optimization methods for power grid analysis, lacking the ability to integrate and orchestrate different analytical tools.

[0040] To address these issues, this disclosure proposes a method for invoking power grid analysis tools based on a large language model. This method leverages large language model technology to resolve the problems of low efficiency, insufficient digitalization, and complex user interaction in current power grid analysis tool invocation processes within the field of power dispatch automation. By combining advanced large language model technology with power grid analysis tool interfaces, a digitally intelligent tool invocation framework is effectively constructed, achieving digitalization and automation of the tool invocation process.

[0041] Large Language Model (LLM) refers to a model with a large number of parameters trained using deep learning techniques. LLM can understand and generate natural language text. By pre-training on large-scale datasets, LLM learns the statistical laws of language, thereby being able to predict or generate text sequences based on a given context.

[0042] Please refer to Figures 1 and 2. The power grid analysis tool invocation method based on the large language model in this embodiment fully utilizes the powerful natural language processing capabilities of the large language model. Through fine-tuning and optimization, it achieves seamless integration with the power grid analysis tool, improving the accuracy of invocation and the convenience of user interaction. The method in this embodiment mainly includes the following steps S1 to S5.

[0043] In step S1, the interface information of each power grid analysis tool is collected, and the interface information of the power grid analysis tools is standardized to establish an interface information database.

[0044] In step S2, the calling instructions for the power grid analysis tool are generated based on the interface information database, and the calling instructions for the power grid analysis tool are classified and labeled to form an instruction dataset.

[0045] In step S3, the parameters of the pre-established power grid analysis tool invocation large language model are fine-tuned using the instruction dataset to obtain the optimized power grid analysis tool invocation large language model.

[0046] In step S4, after inputting the instruction, a set of instructions corresponding to the semantics of the input instruction are retrieved from the instruction dataset and returned. Through multiple rounds of interaction with the optimized power grid analysis tool's large language model, a structured statement for the power grid analysis tool is generated.

[0047] In step S5, the corresponding power grid analysis tool is invoked according to the generated power grid analysis tool invocation structured statement.

[0048] In some embodiments, in step S1, when collecting interface information of various power grid analysis tools, an interface information collection template is defined to collect interface information. The interface information collection template includes field names and corresponding descriptions.

[0049] In some embodiments, the field names include interface name, function description, input parameters, output parameters, parameter types, and calling methods. The interface name corresponds to a unique identifier for the interface; the function description corresponds to a detailed description of the interface's function; the input parameters correspond to a list of input information required by the interface; the output parameters correspond to a list of output information of the interface; the parameter types correspond to the data type of the input or output parameters; and the calling method corresponds to the specific way of calling the interface. An example of an interface information collection template is shown in Table 1.

[0050] Table 1

[0051] Information is collected based on the interface information collection template described above. Relevant power grid structured data interface documents are organized, interface information is extracted, and the information is filled in according to the interface information collection template.

[0052] In some embodiments, after standardizing the interface information of the power grid analysis tools in step S1, the input parameters of the same functional interfaces of different power grid analysis tools have unified parameter names and data types.

[0053] The parameter standardization process can be formally expressed as follows: standardized_param = standardize(parameter_name, parameter_type)

[0054] The `standardize` function converts the parameter name and type according to predefined standardization rules; `parameter_name` represents the parameter name, and `parameter_type` represents the parameter type.

[0055] Next, an interface mapping table is established to map similar or identical interfaces in different power grid analysis tools, ensuring a unified calling method when invoking different power grid analysis tools. The interface mapping table is shown in Table 2.

[0056] Table 2

[0057] The API returns two types of results: one is dictionary data stored in key-value format, where the key is the data key and the value is a data structure containing three attributes: data type, data length, and data value. The data value attribute can include a lightweight data exchange JSON string. The other type is vector data. <vector>The data is stored in a format that contains a two-dimensional table. 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 specific field of a specific row in the two-dimensional table. This data is represented by a data structure containing four attributes: data type, data length, data value, and attribute name. Examples of some interface return objects are shown in Table 3.

[0058] Table 3

[0059] Establish a standardized, encapsulated interface information database for power grid analysis tools. The database table structure contains all fields from the template described above. Enter the standardized interface information into the database to create a complete interface information database.

[0060] In some embodiments, step S2, the step of generating invocation instructions for the power grid analysis tool based on the interface information database, and classifying and labeling the invocation instructions to form an instruction dataset, includes:

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

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

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

[0064] Access the interface information database to extract interface information for each interface, including tool name, operation, parameter list, etc. Next, based on the instruction template and interface information, use string replacement or a template engine to generate the invocation instructions for the power grid analysis tool.

[0065] The steps for classifying and labeling the call instructions of power grid analysis tools include: defining a series of rules to classify the generated call instructions according to their corresponding functions and uses; then, applying the defined rules to assign multi-dimensional labels to each call instruction, such as "section", "limit", and "base state". Finally, the generated instructions and their corresponding labels are integrated into a structured dataset, typically in comma-separated values ​​(CSV) or JavaScript object notation (JSON) format, for subsequent model fine-tuning.

[0066] The following is an example of instructions for fine-tuning data:

[0067] Tool Description:

[0068] Interface name: getBaseOverLimit

[0069] Interface Description: Retrieve cross-sectional quota information

[0070] Interface input: {"param1": Section ID, "param2": Date}

[0071] API return type: Key-Value

[0072] Interface tags: cross-section, quota

[0073] In some embodiments, in step S3, the power grid analysis tool's invocation of the large language model is fine-tuned and optimized based on the prompt word templates. A series of templates are defined to guide the power grid analysis tool invoking the large language model to generate answers in the power grid analysis domain. The templates are pre-designed text fragments containing placeholders for inserting specific information, which are keywords or parameters related to the power grid analysis tool's invocation instructions. The format includes prompt word templates, questions, thought chains, and answers.

[0074] An example is shown below:

[0075] Question and answer data:

[0076] "Hint": "You are a knowledgeable power grid analysis assistant who can help users analyze the current operating status of the power grid."

[0077] Question: What is the current quota for the Hubei-Henan section?

[0078] "Mind Chain":[

[0079] "Thinking process": "To query the quota for a cross-section, you first need to know the time and the ID information corresponding to the cross-section."

[0080] "Thinking point 1": "We need to query the ID of the Hubei-Henan section."

[0081] "action1":"get_id",

[0082] "Input 1":"{"param1": Cross-section name}

[0083] Output 1:"{"Hubei-Henan Section":XX}

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

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

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

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

[0088] "Thinking point 3": "Need to query the quota for section ID XX under the date XX-XX-XX"

[0089] Action 3: "getBaseOverLimit",

[0090] "Enter 3":"{}

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

[0092] ]

[0093] Answer: "At the current time XX-XX-XX, the quota for the Hubei-Henan section with ID XX is XXXXXX."

[0094] The fine-tuning process involves combining a pre-established large language model for power grid analysis tool calls with a command dataset. The command dataset contains a large number of power grid analysis tool call command samples, which are typically labeled and organized in a specific format (such as JSON or CSV). The goal of fine-tuning is to enable the large language model for power grid analysis tool calls to understand and generate outputs that conform to the power grid analysis tool call commands. The fine-tuning process is based on the following expression:

[0095] In the formula, L(θ) represents the loss function, θ is the parameter of the large language model called by the power grid analysis tool, N is the total number of samples in the instruction dataset, and x i It is the input of the i-th sample, y i It is the corresponding target output, T i This refers to the corresponding prompt word template, representing the probability that the model will generate the correct output given the input and the prompt word template. During fine-tuning, the parameters θ of the large language model called by the power grid analysis tool are adjusted to minimize the loss function, enabling the power grid analysis tool to generate the target command using the large language model. This process uses either Adaptive Moment Estimation (Adam) or Stochastic Gradient Descent (SGD) gradient descent algorithms to iteratively update the model parameters. The base large language model used for fine-tuning is shown in Table 4.

[0096] Table 4

[0097] The parameters supported during the fine-tuning process are shown in Table 5.

[0098] Table 5

[0099] After sufficient training cycles and meticulous parameter tuning, an optimized large language model can be obtained. This model demonstrates better understanding and generation capabilities when calling power grid analysis tools, thus becoming 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.

[0100] In some embodiments, in step S4, after a user inputs an instruction, a set of instructions that are semantically close to or related to the input instruction are retrieved and returned from the constructed instruction dataset. First, the preprocessed user instruction text is converted into vectors using a word embedding model (such as a Word to Vector (Word2Vec) model, a Bidirectional Encoder Representations from Transformers (BERT) model, etc.). This can be achieved by converting each word into a fixed-dimensional vector and then merging all word vectors in an instruction (e.g., by averaging or weighted summation). Then, similarity calculation is performed. Since each known instruction in the instruction dataset is also converted into vector form and stored, when the user inputs a new instruction, the similarity between the input instruction vector and each known instruction vector in the instruction dataset can be calculated. The similarity calculation can use the cosine similarity formula:

[0101] In the formula, A and B are the vector representations of the two instructions, A·B represents the dot product of the vectors, and ||A|| and ||B|| are the norm or length of the vectors, respectively. Based on the similarity calculated above, the instructions with the highest similarity are selected as the search results. This result set can be further sorted according to similarity so that the most relevant instructions are displayed first.

[0102] In some embodiments, in step S4, the interactive system based on the LLaMA (Large Language Model Meta AI) large language model generates structured statements for calling power grid analysis tools from the user's unstructured instructions through multiple rounds of interaction with the user.

[0103] In some embodiments, for effective multi-round interaction, a contextual environment is first constructed, which includes the user's original instructions, historical interaction records, and possible user intents. Then, based on the instructions retrieved from the instruction dataset, a series of potential structured statements are generated using the LLaMA large language model, according to the constructed context. These structured statements are interpretations of the user instructions, designed to be converted into a format that the power grid analysis tool can understand and execute. For each round of generated structured statements, an evaluation function is defined to measure the degree of matching with the user intent; the expression of the evaluation function is as follows:

[0104] Score(S,C)=f(S)+g(S,C)

[0105] In the formula, S represents the generated structured statement, C represents the context, f(S) is the quality scoring function of the structured statement itself (e.g., syntactic correctness and execution feasibility), and g(S,C) is the scoring function for the relevance of the structured statement to the context (e.g., semantic matching between the structured statement and user instructions). The best structured statement is selected based on the scores and returned to the user. Positive and negative feedback from the user can be used for further fine-tuning and optimization of the model. If the user is not satisfied with the provided structured statement, they can provide more information or modify the instructions to update the context, re-execute the interaction phase, generate a new structured statement, and after multiple rounds of interaction, generate the final structured statement for the power grid analysis tool.

[0106] In some embodiments, traditional machine learning classification models, such as support vector machines (SVMs) or decision trees, can also be used to classify user input commands and map them to specific power grid analysis tool interfaces.

[0107] Alternatively, manually written fixed templates can be used to generate structured statements for calling power grid analysis tools.

[0108] Alternatively, a single-round recognition based on keyword extraction can be used instead of multi-round interaction with the optimized power grid analysis tool by calling a large language model. The user's input commands will be directly mapped to the interface of the power grid analysis tool.

[0109] In some embodiments, smaller, domain-specific optimized language models can be used to process user input commands instead of large language models such as LLaMA.

[0110] Compared to some other technologies, this disclosure discloses a method for invoking power grid analysis tools based on a large language model. This method utilizes prompt word templates and a large language model for multi-turn interactions, allowing users to communicate efficiently with the system using natural language, significantly improving the system's digital intelligence level. Leveraging the tool invoking capabilities of the large language model, diverse power grid analysis tool invoking statements can be intelligently matched and generated based on user commands, making the process more intelligent and flexible. Furthermore, it allows for the flexible integration and orchestration of various power grid analysis tools, enabling flexible combinations and collaborative optimization of tool functions.

[0111] Some embodiments of this disclosure also propose a power grid analysis tool invocation system based on a large language model. The system includes: an interface information collection and standardization processing module, an invocation instruction classification and annotation module, a power grid analysis tool invocation large language model parameter fine-tuning module, a power grid analysis tool invocation structured statement generation module, and an invocation execution module.

[0112] The interface information collection and standardization processing module is configured to collect interface information from various power grid analysis tools, standardize the interface information of the power grid analysis tools, and establish an interface information database.

[0113] The instruction classification and annotation module is configured to generate instruction calls for the power grid analysis tool based on the interface information database, and to classify and annotate the instruction calls for the power grid analysis tool to form an instruction dataset.

[0114] The power grid analysis tool calling large language model parameter fine-tuning module is configured to use the instruction dataset to fine-tune the pre-established power grid analysis tool calling large language model parameters to obtain an optimized power grid analysis tool calling large language model.

[0115] The power grid analysis tool calls the structured statement generation module, which is configured to retrieve and return a set of instructions corresponding to the semantics of the input instruction from the instruction dataset after the input instruction is input, and generate the power grid analysis tool call structured statement through multi-round interaction with the optimized power grid analysis tool call large language model.

[0116] The execution module is configured to invoke structured statements based on the generated power grid analysis tools, and to perform invocation operations on the corresponding power grid analysis tools.

[0117] Some embodiments of this disclosure also propose an electronic device including a processor and a memory, the processor being used to execute a computer program stored in the memory to implement the method for invoking the power grid analysis tool based on a large language model.

[0118] Some embodiments of this disclosure also propose a computer-readable storage medium (including a non-transitory computer-readable storage medium) storing at least one instruction that, when executed by a processor, implements the method for invoking the power grid analysis tool based on a large language model.

[0119] The computer program includes computer program code, which may be in the form of source code, object code, executable file, or some intermediate form. The computer-readable storage medium may include any entity or device capable of carrying the computer program code, media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory, random access memory, electrical carrier signal, telecommunication signal, and software distribution medium, etc.

[0120] It should be noted that the content of the computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium may not include electrical carrier signals and telecommunication signals. For ease of explanation, the above content only shows the parts related to the embodiments of this disclosure; for specific technical details not disclosed, please refer to the method section of the embodiments of this disclosure. This computer-readable storage medium is non-transitory and can be stored in a storage device formed by various electronic devices, enabling the execution process described in the method of the embodiments of this disclosure.

[0121] Those skilled in the art will understand that embodiments of this disclosure can be provided as methods, systems, or computer program products. Therefore, this disclosure can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this disclosure can take the form of a computer program product embodied 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.

[0122] This disclosure is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more flowchart illustrations and / or one or more block diagrams.

[0123] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.

[0124] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.

[0125] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this disclosure and not to limit them. Although this disclosure has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the implementation methods of this disclosure. Any modifications or equivalent substitutions that do not depart from the spirit and scope of this disclosure should be covered within the protection scope of the claims of this disclosure.< / vector> < / vector>

Claims

1. A power grid analysis tool calling method based on a large language model, comprising: collecting interface information of each power grid analysis tool, and standardizing the interface information of the power grid analysis tool to establish an interface information library; generating a calling instruction of the power grid analysis tool according to the interface information library, classifying and labeling the calling instruction of the power grid analysis tool to form an instruction data set; fine-tuning pre-established power grid analysis tool calling large language model parameters using the instruction data set to obtain an optimized power grid analysis tool calling large language model; after inputting an instruction, retrieving and returning a set of instructions corresponding to the semantic of the input instruction from the instruction data set, and generating a power grid analysis tool calling structured statement through multiple rounds of interaction with the optimized power grid analysis tool calling large language model; performing a calling operation on the corresponding power grid analysis tool according to the generated power grid analysis tool calling structured statement.

2. The power grid analysis tool invocation method based on a large language model according to claim 1, wherein, When collecting the interface information of each power grid analysis tool, an interface information collection template is defined for interface information collection, 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 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 list of input information required by the interface, the description corresponding to the output parameter is the list of output information of the interface, the description corresponding to the parameter type is the data type of the input parameter or the output parameter, and the description corresponding to the calling method is the way to call the interface.

3. The power grid analysis tool invocation method based on a large language model according to claim 1 or 2, wherein, In the step of standardizing the interface information of the power grid analysis tools, the same function interface input parameters of different power grid analysis tools are made to have uniform parameter names and data types; an interface mapping table is established, and the interface mapping is used to make the calling of different power grid analysis tools use a uniform calling mode; the returned result data of the interface is marked as two kinds: one is dictionary data saved in a Key-Value form, wherein Key is a data keyword, and Value is a data structure containing three attributes, i.e. a data type, a data length and a data value; the other is Vector <vector>The data saved in the form contains a two-dimensional table data, wherein 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 data in a field of a row in the two-dimensional table. The data is represented by a data structure, which includes four attributes: data type, data length, data value, and attribute name.< / vector> 4. The power grid analysis tool invocation method based on a large language model according to any one of claims 1 to 3, wherein, The step of generating a calling instruction of the power grid analysis tool according to the interface information library, and classifying and labeling the calling instruction of the power grid analysis tool to form an instruction data set, comprises: designing a set of instruction templates, each instruction template in the set of instruction templates corresponds to a specific power grid analysis tool and operation; the instruction template includes a fixed syntax structure and placeholders for inserting specific parameters; The formal expression of the instruction template is as follows: <tool name> <operation> <parameter1> <parameter2>... <parameterN> Wherein, <tool name>, <operation> and <parameter> are contents filled according to specific instruction content. Accessing the interface information base, extracting the interface information of each interface; generating 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, comprising: defining a plurality of rules, classifying the generated calling instructions according to the corresponding functions and purposes; 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 to obtain an instruction data set.

5. The power grid analysis tool invocation method based on a large language model according to any one of claims 1 to 4, wherein, In the step of fine-tuning the pre-established power grid analysis tool calling large language model parameters using the instruction data set to obtain an optimized power grid analysis tool calling large language model, a plurality of templates are defined for guiding the power grid analysis tool calling large language model to generate answers in the power grid analysis field. The templates are pre-designed text segments and contain placeholders for inserting specific information, which is keywords or parameters related to power grid analysis tool calling instructions. The format includes prompt word templates, questions, thought chains, and answers. The fine-tuning process involves using the pre-established power grid analysis tool calling large language model in combination with the instruction data set. The purpose of fine-tuning is to enable the power grid analysis tool calling large language model to understand and generate outputs that conform to the power grid analysis tool calling instructions. The fine-tuning process is based on the following expression: In the formula, L(θ) represents a loss function, θ is a parameter of calling a large language model by a power grid analysis tool, N is a total number of samples in an instruction data set, x i is an input of the i th sample, y i is a corresponding target output, T i is a corresponding prompt word template, and represents a probability that the model generates a correct output under the condition of a given input and the prompt word template. In the fine-tuning process, the power grid analysis tool calling large language model parameters θ are adjusted to minimize the loss function, so that the power grid analysis tool calling large language model generates target instructions.

6. The power grid analysis tool invocation method based on a large language model according to any one of claims 1 to 5, wherein, The step of retrieving and returning a set of instructions corresponding to the semantics of the input instruction from the instruction data set comprises: The input instruction text is converted into a vector by using a word embedding model, and then similarity calculation is performed; in the instruction data set, each known instruction is also converted into a vector form and stored; the similarity of the input instruction vector and each known instruction vector in the instruction data set is calculated; the similarity between vectors is calculated by using the following cosine similarity calculation formula: In the formula, A and B are the vector expressions of two instructions, A·B represents the dot product of the vectors, and ||A|| and ||B|| are the norms or lengths of the vectors, respectively; according to the calculated similarity, a plurality of instructions with the highest similarity are selected as the retrieval results.

7. The power grid analysis tool invocation method based on a large language model according to any one of claims 1 to 6, wherein, The step of retrieving and returning a set of instructions corresponding to the semantics of the input instruction from the instruction data set, and generating a power grid analysis tool calling structured statement through multiple rounds of interaction with the optimized power grid analysis tool calling large language model, comprises: A context environment is constructed, which includes the user's original instruction, historical interaction record and possible user intent; based on the retrieved instructions, the optimized power grid analysis tool calling large language model is used to generate a series of potential structured statements according to the constructed context environment; the structured statement is an explanation of the user's instruction and has a format that can be understood and executed by the power grid analysis tool; for the generated structured statement, an evaluation function is defined to measure the matching degree with the user's intent, and the expression of the evaluation function is as follows: Score(S,C)=f(S)+g(S,C) In the formula, S is the generated structured statement, C is the context environment, f(S) is the quality score function of the structured statement itself, and g(S,C) is the score function of the structured statement and the context relevance; the best structured statement is selected according to the score and returned to the user; if the user is not satisfied with the provided structured statement, more information or modified instructions are provided to update the context, and the interaction stage is re-executed to generate new structured statements; after multiple rounds of interaction, the power grid analysis tool calling structured statement is generated.

8. A power grid analysis tool calling system based on a large language model, comprising: An interface information collection and standardization processing module configured to collect interface information of each power grid analysis tool, and to standardize the interface information of the power grid analysis tool, and to establish an interface information base; A calling instruction classification and labeling module configured to generate calling instructions of the power grid analysis tool according to the interface information base, and to classify and label the calling instructions of the power grid analysis tool, and to form an instruction data set; The power grid analysis tool calling large language model parameter fine-tuning module is configured to fine-tune the pre-established power grid analysis tool calling large language model parameters by using the instruction data set to obtain an optimized power grid analysis tool calling large language model. The power grid analysis tool calling structured statement generation module is configured to retrieve and return a set of instructions corresponding to the semantic of the input instruction from the instruction data set after the input instruction, and generate a power grid analysis tool calling structured statement by interacting with the optimized power grid analysis tool calling large language model for multiple rounds. The calling execution module is configured to perform a calling operation on the corresponding power grid analysis tool according to the generated power grid analysis tool calling structured statement. 9.An electronic device comprising a processor and a memory, wherein the processor is configured to execute a computer program stored in the memory to implement the power grid analysis tool calling method based on a large language model according to any one of claims 1 to 7.

10. A computer readable storage medium, wherein, The computer readable storage medium stores at least one instruction, and the at least one instruction is executed by the processor to implement the power grid analysis tool calling method based on a large language model according to any one of claims 1 to 7.