Power system code review method and system based on large model prompt word optimization
By constructing a power business knowledge base and a defect-layered experience base, and combining template library construction, context processing, and DevOps integration, the power system code review is optimized using a large model. This solves the problems of high false alarm rate, high missed detection rate, and low iteration efficiency in power system code review, and achieves efficient and accurate power system code review.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NARI INFORMATION & COMM TECH
- Filing Date
- 2026-03-13
- Publication Date
- 2026-07-21
Smart Images

Figure CN122432010A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of power systems and artificial intelligence, and in particular to a power system code review method and system based on large model prompt word optimization. Background Technology
[0002] Currently, the power industry is comprehensively promoting digital transformation and smart grid construction. New businesses such as renewable energy grid-connected dispatching and the power Internet of Things are developing rapidly, significantly increasing the code complexity of real-time control systems and business management systems for power systems. These systems directly control core physical equipment such as relay protection and circuit breakers, and have strict requirements on concurrent control, timing logic, and response speed of code execution. Their software quality is directly related to the safety of power grid operation.
[0003] Because it involves core power grid data and infrastructure security, power codes must simultaneously meet both routine security testing and mandatory industry standard requirements. For example, substation automation communication codes must comply with the IEC 61850 series standards, and business management systems must meet the GB / T 25000.51-2016 software quality standard. These compliance reviews have become a bottleneck in power software delivery.
[0004] To alleviate the pressure of manual review, the industry has introduced artificial intelligence and large-scale model technology. An AI framework based on retrieval enhancement and code abstraction syntax tree understanding has been piloted in some business systems. However, existing tools rely on training with general-purpose code libraries, and their prompt word templates have not established an effective mapping with power business entities, making it difficult to identify power-specific defects such as "missing double confirmation mechanisms," "violations of five-prevention logic," and "abnormal synchronization of relay protection signals." Meanwhile, facing vulnerabilities in power IoT protocols or high-risk concurrent vulnerabilities, existing tools lack layered iteration and response mechanisms tailored to power scenarios, resulting in high false negative and false positive rates. The following issues also exist: 1. Insufficient adaptability to power services: Using generic prompt templates without incorporating mandatory power standards such as IEC 61850 and GB / T 25000.51-2016 leads to a high false negative rate for power-specific defects; 2. Limited context fusion: Failing to combine the structural features of the power code abstract syntax tree with the collaborative association of power service constraint information results in a high false positive rate for defect identification; 3. Lack of dynamic optimization of prompt words: Fixed prompt word parameters, without layered optimization according to power defect priority or adaptation to differences in power sub-scenarios, lead to slow adaptation speed for new defects and insufficient accuracy in identifying high-risk defects; 4. Insufficient engineering iteration loop: Lacking a continuous iteration mechanism of "review feedback → knowledge update → prompt word optimization" results in low sample efficiency for prompt word optimization and poor long-term adaptability. Summary of the Invention
[0005] Purpose of the invention: The purpose of this invention is to provide a power system code review method and system based on large-model prompt word optimization that solves the problems of insufficient adaptation between prompt words and business scenarios in power system code review, relatively single context fusion dimension of prompt word optimization technology, and lack of specific adaptation of prompt word optimization feedback iteration mechanism for power scenarios.
[0006] Technical solution: The power system code review method based on large model prompt word optimization described in this invention includes:
[0007] Basic resource layer, core function layer, and engineering integration layer;
[0008] The basic resource layer includes: a power business knowledge base and a power defect layered experience base;
[0009] The core functional layer includes: a template library construction module, a context processing module, a PowerPrompt-DAEL optimization module, and a prompt word generation module;
[0010] The engineering integration layer includes: a DevOps integration module and a feedback processing module.
[0011] Furthermore, the power business knowledge base includes: a standard document sub-base, a historical defect sub-base, and a knowledge graph sub-base;
[0012] The power defect stratification experience database includes: a high-risk defect sub-database, a medium-risk defect sub-database, and a low-risk defect sub-database.
[0013] Furthermore, the template library construction module includes:
[0014] Scenario requirements analysis and template design: Real-time control scenarios focus on compliance verification of timing logic and power communication protocols, while business system scenarios focus on compliance verification of power industry software quality specifications. A priority inspection strategy for high-risk defects is determined by combining power industry defect classification standards. Template design includes semantic parsing templates to guide the model in extracting power-specific entities and control flows; rule matching templates to associate specific standard clauses for defect inspection; and recommendations to generate template outputs containing standard code snippets for repair solutions.
[0015] Content embedding and verification: Standard clauses are associated through a scenario-defect-standard mapping table, and compliant code snippets are embedded; the coverage of power history code test templates is selected, and expert reviews are organized. If the review fails, iterative optimization is carried out.
[0016] Furthermore, the context processing module extracts code structure features through an abstract syntax tree, retrieves business constraints from a knowledge base, and dynamically fuses them according to scenarios, including:
[0017] Structural feature extraction: The code is converted into an abstract syntax tree, the nodes are traversed to record the call relationship and reference chain, and the control flow, complexity, and variable dependencies are extracted from the abstract syntax tree and converted into natural language descriptions;
[0018] Business context retrieval and fusion: Convert code into vector representation, match knowledge base through dense paragraph retrieval model, recall standard terms, historical cases, knowledge graph related information, and integrate into structured description; identify code scenario type, and fuse structured description and business description according to preset weights;
[0019] Compliance verification: Verify the double confirmation and five-prevention logic terms through the power terminology dictionary to ensure no omissions; verify the validity of the clauses by connecting to the power grid standard library, and replace invalid clauses with the latest ones; check whether the context contains control flow, variable dependencies, and business constraints, and supplement the context information if missing; if it fails, it will be automatically supplemented and re-verified until it passes, and output a fusion context that conforms to power specifications.
[0020] Furthermore, the PowerPrompt-DAEL optimization module utilizes a dual-branch network to generate scenario-specific parameters, evaluates the optimization effect hierarchically, and ensures parameter iteration stability through gradient optimization, including: dual-branch policy network, hierarchical value evaluation network, and algorithm iteration;
[0021] The dual-branch strategy network generates scenario-based prompt word adjustment parameters: based on the LSTM network encoding historical structure trajectories, it outputs structural parameters; it identifies the scenario type through a scenario classifier and outputs business parameters; it assigns weights based on the similarity between the branch outputs and the scenario labels, and merges them into adjustment actions.
[0022] The hierarchical value assessment network calculates a global value score based on "defect identification accuracy, power rule coverage, and response time"; outputs a scenario-specific value score based on scenario type; and merges the global value score and the scenario-specific value score according to a preset weight ratio.
[0023] Furthermore, the algorithm iteration first initializes by generating parameters through a dual-branch network, calls the code big model to perform code review, and obtains the code review results; calculates the reward value based on global and scenario indicators, and samples in a hierarchical manner according to priority; calculates the value loss and strategy loss, updates the network parameters, and softly updates the target network; when the improvement of the comprehensive value score is less than the threshold for several consecutive rounds, the algorithm iteration is determined to have converged, and the optimal parameters are output.
[0024] Furthermore, the prompt word generation module will inject the context and optimized parameters into the template, and output the target prompt word after verification with power terminology and standard clauses.
[0025] Furthermore, the DevOps integration module automatically triggers the review process when code is submitted via GitLab Webhook, synchronizing the review results of the large code model to the tools commonly used by developers.
[0026] Furthermore, the feedback processing module collects data on human corrections to the AI review results, selects high-value samples to update the experience base and knowledge base, forming a closed loop of "AI review - human feedback - data iteration".
[0027] A power system code review system based on large model prompt word optimization, comprising:
[0028] The power scenario template library construction module is used to build a three-level progressive task prompt template library consisting of semantic parsing, rule matching, and suggestion generation.
[0029] Context processing module: used to extract the abstract syntax tree structure features of the power code to be reviewed and retrieve the corresponding power business constraint information from the power business knowledge base;
[0030] PowerPrompt-DAEL Algorithm Optimization Module: Used to generate prompts and adjust parameters for power scenarios through a dual-branch strategy network of structural adaptation and business adaptation;
[0031] Prompt word generation module: It is used to inject context data and prompt word parameters into the three-level task prompt template corresponding to the power scenario. After verifying the accuracy of power terminology and compliance with standard clauses, it generates target optimized prompt words for power system code review.
[0032] DevOps integration module: used to connect with the R&D pipeline of power companies, triggering the code review process when code is submitted, and synchronizing the review results to the merge request page and defect tracking system;
[0033] Feedback Iteration Processing Module: Used to collect correction and annotation data of code review results by humans, screen samples to update the power defect stratification experience library, feed back new power defect cases and updated industry standard clauses to the power business knowledge base, and trigger periodic fine-tuning of prompt word templates and optimization algorithms;
[0034] Basic resource support module: used for storing and managing the power business knowledge base and the power defect layered experience base.
[0035] Beneficial Effects: Compared with existing technologies, this invention has the following significant advantages: 1. Relying on the three-dimensional power-specific library of "standards-cases-knowledge graph" in the basic resource layer, it improves the relevance of prompt words to power business, effectively reduces the high-risk defect omission problem caused by the lack of industry-specific knowledge in general templates, and reduces the risk of false alarms caused by single-dimensional context; 2. Through a dual-branch strategy network and a hierarchical value assessment system, it responds to the dynamic changes in power scenarios in real time; 3. Combined with the DevOps automatic triggering mechanism and manual feedback closed loop in the engineering integration layer, it reduces the cost of manual intervention while ensuring the long-term stability of code review results, solving the problem of the effect decay of general solutions once they are implemented. Attached Figure Description
[0036] Figure 1 This is a basic resource layer structure diagram of the present invention;
[0037] Figure 2 This is a structural diagram of the core functional layer of the present invention;
[0038] Figure 3 This is a diagram of the engineered integrated layer structure of the present invention;
[0039] Figure 4 This is a flowchart illustrating the scenario requirements analysis and template design process for this invention.
[0040] Figure 5 This is a flowchart illustrating the content embedding and validity verification process of the present invention.
[0041] Figure 6 This is a flowchart of the structural feature extraction process of the present invention;
[0042] Figure 7 This is a flowchart illustrating the business context retrieval and fusion process of the present invention;
[0043] Figure 8 This is a flowchart illustrating the compliance verification process of the present invention.
[0044] Figure 9 This is the network diagram of the dual-branch strategy of the present invention;
[0045] Figure 10 This is a hierarchical value assessment network diagram for the present invention;
[0046] Figure 11 This is a flowchart of the algorithm iteration process of the present invention. Detailed Implementation
[0047] The technical solution of the present invention will be further described below with reference to the accompanying drawings.
[0048] like Figure 1 , Figure 2 , Figure 3As shown, the power system code review method based on large model prompt word optimization described in this invention includes: a basic resource layer, a core function layer, and an engineering integration layer.
[0049] The basic resource layer provides power-specific data support for core functions and includes two types of libraries:
[0050] The power business knowledge base includes: a standards document sub-base storing mandatory standards such as the International Electrotechnical Commission's power communication protocol (IEC 61850) and software quality requirements (GB / T 25000.51); a historical defect sub-base containing real-world power grid defect cases, each including code snippets, defect types, and remediation solutions; and a knowledge graph sub-base using equipment, protocols, and defects as triples to support related queries. All three are linked through a unified ID, providing compliance evidence and case references for audits.
[0051] Power Defect Hierarchical Experience Database: Defects are classified according to their impact on power grid security, with high-risk sub-database samples accounting for 60%, ensuring that core defects receive priority resources in optimization and solving the problem of quantity over priority in general databases.
[0052] The core functional layer is the core of prompt word optimization, and it works in collaboration with four modules: template library construction module, context processing module, PowerPrompt-DAEL optimization module, and prompt word generation module.
[0053] The template library construction module breaks down the review task into three levels of templates: semantic parsing (extracting business entities), rule matching (associating standard clauses), and suggestion generation (outputting repair solutions). These templates are customized according to real-time control and business system scenarios to solve the problem of insufficient business adaptability of general templates.
[0054] The scenario requirements analysis clarifies that real-time control scenarios need to focus on timing logic and IEC61850 protocol compliance, while business system scenarios need to focus on GB / T25000.51 compliance and performance optimization. High-risk defects are prioritized for inspection based on the "State Grid Defect Classification Standard." In the three-level template design, semantic parsing templates guide the model to extract power-specific entities and control flows; rule matching templates are associated with specific standard clauses to check defects; it is recommended to generate template outputs containing standard code snippets for repair solutions to lower the model's understanding threshold, such as... Figure 4 As shown.
[0055] Content embedding associates standard clauses through a scenario-defect-standard mapping table, embedding core entities such as circuit breakers and five-proof logic, and pre-setting compliant code snippets such as double confirmation and five-proof logic to ensure the template has depth in power business. For effectiveness verification, 100 historical power code samples (covering two scenarios) are selected to test template coverage (target ≥95%). Experts review business adaptability and instruction clarity (target average score ≥85 points). If a sample fails, iterative optimization is performed. Finally, the template is launched and supports version management, adapting to standard updates. Figure 5 As shown.
[0056] The context processing module extracts code structure features through an Abstract Syntax Tree (AST), retrieves business constraints from the knowledge base, and dynamically fuses them according to scenarios (real-time scenario business weight 0.6, business scenario structure weight 0.6) to avoid missed defects caused by a single dimension, such as... Figure 7 As shown.
[0057] The context processing module includes:
[0058] Structural Feature Extraction: The code is converted into an AST using ANTLR, marking the positions of functions, variables, and branch nodes. Node traversal records call relationships and reference chains. Control flow, complexity, and variable dependencies are extracted from the AST and converted into natural language descriptions to ensure the model understands code structural defects, such as… Figure 6 As shown.
[0059] Business context retrieval: CodeBERT pre-trained with power corpus is converted into 768-dimensional vectors. The DPR model is used to match the knowledge base to recall the top 3 standard terms, top 2 historical cases, and knowledge graph related information, which are then integrated into a structured description.
[0060] Dual-channel fusion: Automatically identify scenarios through code keywords or project tags. Real-time scenarios are weighted at 0.6 for business and 0.4 for structure. Business scenarios are weighted the other way around, splicing the structure and business description to ensure that the context covers both the structure and business dimensions.
[0061] Compliance verification: This involves ensuring no omissions of terms such as double confirmation and five-prevention logic through a power terminology dictionary; verifying the validity of clause IDs by connecting to the power grid standard library and replacing invalid clauses; checking the context for control flow, variable dependencies, and business constraints, and completing any missing information. The processing logic is as follows: if compliance verification fails, automatic completion is performed, and verification is repeated until it passes, outputting a fusion context that conforms to power regulations, such as... Figure 8 As shown;
[0062] PowerPrompt-DAEL optimization module: Reinforcement learning dynamically optimizes prompt word parameters, solving the problem that general algorithms cannot adapt to the dynamic needs of power scenarios.
[0063] The PowerPrompt-DAEL optimization module includes: a dual-branch policy network (responsible for generating scenario-based prompt words and adjusting parameters), a hierarchical value evaluation network (quantifying the effect of the adjustment action), and an algorithm iteration (achieving dynamic optimization of prompt word parameters through a cycle of generating action, evaluating effect, and optimizing parameters).
[0064] The dual-branch strategy network includes, for example: Figure 9 As shown:
[0065] Structure adaptation branch: Encode historical structure trajectories using an LSTM network, learn the relationship between structure and parameters, and output structure parameters.
[0066] Business adaptation branch: Identify scene types through a scene classifier (fully connected + Softmax) and output business parameters, such as increasing the standard reference strength for real-time scenes.
[0067] Attention fusion: Weights are assigned based on the similarity between the branch output and the scene label, and then fused into a 5-dimensional adjustment action to ensure that the parameters are adapted to the current scene.
[0068] The hierarchical value assessment network includes, for example: Figure 10 As shown:
[0069] Global performance evaluation: The global value score Q1 is calculated by combining "defect identification accuracy (0.6 weight), power rule coverage (0.3 weight), and response time (0.1 weight)" to ensure optimal overall performance.
[0070] Scenario-specific assessment: Real-time scenario calculation of timing logic defect identification rate, business scenario calculation of "GB / T25000.51 compliance clause matching rate", output scenario-specific value score Q2, highlighting the core indicators of the scenario.
[0071] Comprehensive evaluation: The overall value score Q_total is obtained by combining the global value score Q1 and the scenario-specific value score Q2 with a weight of 7:3, balancing overall effectiveness and scenario focus.
[0072] Q2 is the scenario-specific evaluation value score output by the hierarchical value assessment network in the algorithm. In real-time scenarios, it is an optimized prompt word that guides the large model to improve the accuracy of identifying core high-risk temporal logic defects in real-time scenarios. In business scenarios, it is an optimized prompt word that guides the large model to improve the matching coverage and compliance verification accuracy of the effective compliance clauses of the standard.
[0073] The algorithm iteration includes initialization, action generation and execution, reward calculation and sampling, parameter optimization, and convergence determination, such as... Figure 11As shown. Initialization settings include network parameters (He initialization), target network (copying current parameters), and hierarchical experience base (loading 1000 power defect samples) to ensure a stable iteration start point; action generation and execution generate parameters through a dual-branch network, call the code large model for review, and obtain defect identification results (accuracy, coverage, etc.); reward calculation and sampling calculate rewards based on global + scenario indicators, and after accumulating 500 samples, sample by priority (high-risk accounts for 60%) to ensure that core defects are optimized first; parameter optimization calculates value loss (MSE) and policy loss (-E[Q_total]), updates the network with the Adam optimizer (learning rate 0.001), and uses gradient pruning (threshold 0.3) to prevent oscillation; soft update of the target network ( Ensure parameter smoothing;
[0074] If the Q_total improvement is ≤2% for 5 consecutive rounds, the system is considered to have converged, and the optimal parameters are output.
[0075] The prompt word generation module will inject context and optimized parameters into the template, and output the target prompt word after verification with power terminology and standard clauses to ensure compliance with industry standards.
[0076] The engineering integration layer enables seamless integration of the technical solution with the existing R&D processes of power companies, including a DevOps integration module and a feedback processing module.
[0077] The DevOps integration module automatically triggers the review process when code is committed via GitLabWebhook, synchronizing the review results of the large code model to commonly used tools by developers, reducing manual operation costs.
[0078] The feedback processing module collects data from human corrections to the AI review results (marking correct / missed / false alarms), selects high-value samples to update the experience base and knowledge base, forming a closed loop of "AI review - human feedback - data iteration" to solve the problem of model effectiveness decaying with business changes.
[0079] A power system code review system based on large model prompt word optimization, comprising the following modules:
[0080] The power scenario template library building module is used to build a three-level progressive task prompt template library for two core scenarios: real-time control system and business management system of power system. It includes semantic parsing, rule matching and suggestion generation. The templates are built with mandatory standard clauses of the power industry, typical business entity examples and compliance repair code snippets, and complete the construction, verification and version iteration management of customized prompt templates for power scenarios.
[0081] The context processing module is used to extract the abstract syntax tree structure features of the power code to be reviewed, simultaneously retrieve the corresponding power business constraint information from the power business knowledge base, dynamically allocate the fusion weight of the structure features and business constraint information according to the power scenario to which the code to be reviewed belongs, complete the fusion processing of dual-channel context information and compliance verification, and output fusion context data adapted to the power scenario.
[0082] The PowerPrompt-DAEL algorithm optimization module is used to generate prompt word adjustment parameters adapted to the power scenario through a dual-branch strategy network of structural adaptation and business adaptation. It combines a hierarchical value evaluation network with global effectiveness and scenario-specific dual dimensions to quantify the parameter adjustment effect. Based on the reinforcement learning mechanism, it completes the dynamic iterative optimization of the core parameters of the prompt words and outputs the optimal prompt word parameters adapted to the current review task.
[0083] The prompt word generation module is used to inject the integrated context data and optimal prompt word parameters into the three-level task prompt template corresponding to the power scenario. After double verification of the accuracy of power terminology and compliance with standard clauses, it generates target optimized prompt words for power system code review, driving the large code model to complete the automated power code review task.
[0084] The DevOps integration module is used to connect to the existing R&D pipeline of power companies through standardized interfaces. It automatically triggers the code review process when code is submitted, and synchronizes the review results output by the code model to the merge request page and defect tracking system used by the developers, so as to realize the automated triggering of review tasks and the visualization of results.
[0085] The feedback and iteration processing module is used to collect correction and annotation data of code review results by humans, select high-value samples to update the power defect stratification experience library, and simultaneously feed back new power defect cases and updated industry standard clauses to the power business knowledge base, triggering periodic fine-tuning of prompt word templates and optimization algorithms to achieve continuous iterative optimization of the system's review capabilities.
[0086] The basic resource support module is used to store and manage the power business knowledge base and the power defect hierarchical experience base. The power business knowledge base includes a sub-library of mandatory standard documents in the power industry, a sub-library of historical defect cases, and a sub-library of equipment-protocol-defect association knowledge graph. The power defect hierarchical experience base stores samples in hierarchical order according to the impact level of defects on power grid security, providing power-specific data support for the entire process of system operation.
[0087] This invention provides standard-case-graph data support for the core functional layer based on the basic resource layer. The core functional layer generates optimized prompts based on the data, driving the large code model to complete the review. The engineering integration layer feeds back the review results to the R&D process and feeds back the basic resource layer through manual data correction, realizing a closed-loop iteration throughout the entire process. This achieves the core objectives of reducing the power-specific defect miss rate to below 8%, the defect identification false alarm rate to below 12%, stabilizing the high-risk defect identification accuracy at above 92%, and significantly shortening the adaptation cycle for new defects. It can solve the problems of low efficiency, poor quality consistency, and high defect miss rate in traditional code review, as well as the insufficient adaptation of existing AI review technology to the characteristics of the power industry.
[0088] Example 1
[0089] This embodiment is a partial alternative to the basic resource layer.
[0090] (1) Replace the knowledge graph sub-base with a pre-trained corpus on electricity and a lightweight retrieval database;
[0091] Constructing a pre-training corpus: Collect IEC61850 protocol documents, power grid defect reports from the past 5 years, and open-source power code libraries, and use the cleaned data as incremental pre-training corpus for CodeBERT.
[0092] Build a lightweight search library: retain the key-value pair index of "standard clause ID-content" and "defect type-case code", and realize fast keyword search through Elasticsearch.
[0093] Compared to the original solution, which uses a knowledge graph of equipment, protocols, and defects to achieve business-related retrieval, this solution replaces the knowledge graph with a pre-trained power corpus and keyword retrieval database, thus reducing the cost of graph construction and long-term maintenance.
[0094] (2) Replace the historical defect sub-library with a dynamic rule engine and a defect tag library;
[0095] Develop a dynamic rule engine: convert power defect rules such as missing double confirmations into a configurable JSON format, allowing business personnel to modify the rules online.
[0096] Build a defect tag library: label each defect with "electricity risk level", "related standard clauses" and "typical code snippets", and link it with the rule engine to directly match the tags during retrieval.
[0097] This solution replaces the traditional method with a dynamic rule engine and a defect tag library, which can improve the efficiency of defect rule updates.
[0098] Example 2
[0099] This embodiment is a partial alternative to the core functional layer.
[0100] (1) Replace the original three-level template with a two-level task template + scene filtering mechanism;
[0101] Design a two-level template: the first level is the parsing and matching template, and the second level is the suggested generated template.
[0102] Add a scene filtering mechanism: Before a template is called, irrelevant templates are automatically filtered out by protocol keywords or project tags in the code.
[0103] Compared to the original solution, which broke down the review task into a three-level template process of semantic parsing, rule matching, and suggestion generation, this solution simplifies it to a two-level template process of parsing and matching, coupled with a scenario filtering mechanism. The two-level template reduces the model's understanding steps, while the scenario filtering mechanism ensures accurate adaptation of the template to the business scenario. Although the template breakdown granularity is coarser than the original solution, precise keyword filtering still avoids the business mismatch problem of general templates, and the length of prompt words can be shortened by 25%, the review response speed is improved by 15%, and the complexity of template design can be reduced.
[0104] (2) The original scheme “AST-dual-channel fusion” was replaced by fixed weight fusion + scenario verification.
[0105] Set a fixed fusion weight: information fusion will be performed uniformly according to "40% for structural context + 60% for business context".
[0106] Add a scene verification mechanism: After fusion, the scene-feature matching table is used for verification.
[0107] This solution uses fixed weights to reduce the resource overhead of dynamic calculations, while scenario verification compensates for the lack of flexibility caused by fixed weights. Although the adaptation accuracy is slightly lower than the original solution (error ≤ 5%), it can meet more than 80% of power audit scenarios, and has a lower deployment threshold, making it more suitable for small and medium-sized R&D teams.
[0108] (3) The PowerPrompt-DAEL optimization module is replaced with Q-learning algorithm + hierarchical reward.
[0109] Define the Q-learning state space: use AST features (nesting depth, number of branches) + scene labels + historical rewards as the state input of the algorithm.
[0110] Design a tiered reward mechanism: global rewards (accuracy + coverage) account for 70%, and scenario-specific rewards account for 30%, which are directly used to update the Q table.
[0111] Optimize parameter iteration logic: Select parameter adjustment actions according to the ε-greedy strategy, and set the convergence condition as reward fluctuation ≤3% for 5 consecutive rounds.
[0112] Q-learning eliminates the need for complex dual-branch networks, achieving parameter optimization solely through Q-table iterations. Hierarchical rewards ensure adaptation to specific scenario requirements. While its convergence speed is slightly slower than the original scheme (1-2 more iterations), it reduces computational resource consumption by 60%, making it more suitable for low-computing-power servers within power grids, and still dynamically responding to scenario needs.
[0113] Example 3
[0114] This embodiment provides an alternative to the engineered integration layer.
[0115] The original solution of GitLabWebhook + Jira was replaced by Jenkins pipeline integration and a self-developed feedback dashboard.
[0116] Integration with the Jenkins pipeline: An "AI review node" is inserted into the Jenkins build process. Review is automatically triggered after code submission, and the review results are directly written to the build log. Jenkins is a commonly used CI / CD tool in power companies, while the self-developed Kanban board is fully adapted to intranet security requirements. Although the tool ecosystem is less rich than GitLab + Jira, it can seamlessly integrate into existing R&D processes, ensuring a closed-loop operation of review-feedback-iteration, and ensuring that data is never stored on the external network, complying with power data security regulations.
[0117] Develop a self-developed feedback dashboard: Build a lightweight web dashboard (deployed on the power intranet) to display AI review results, manual correction records, and defect trends. Support reviewers to annotate and provide feedback online, and feedback data is automatically synchronized to the basic resource library.
[0118] Jenkins is a commonly used CI / CD tool in power companies, while the self-developed Kanban board is fully adapted to internal network security requirements. Although its tool ecosystem is less rich than GitLab + Jira, it can be seamlessly integrated into existing R&D processes, ensuring a closed-loop operation of review-feedback-iteration, and data is never stored on the external network, complying with power data security specifications.
[0119] Example 4
[0120] This embodiment provides a complete alternative.
[0121] The original solution's "knowledge base retrieval" was replaced with "pre-trained empowered model", "three-level template" was replaced with "fixed template + scene filtering", the PowerPrompt-DAEL algorithm was replaced with Q-learning algorithm, and "GitLab + Jira" was replaced with "Jenkins + self-developed Kanban".
[0122] Base layer: Construct a large pre-trained power model (based on CodeBERT incremental training of IEC61850 / GB standard corpus) + dynamic rule engine.
[0123] Core functional layer: Input code → Jenkins triggers automatic review → Fixed secondary template + scene filtering → Q-learning optimizes prompt word parameters → Generate target prompt words → Model execution review.
[0124] Engineering integration layer: Review results are synchronized to the self-developed feedback dashboard → manual annotation feedback → automatic update of rule engine and model pre-training corpus, forming a closed loop.
Claims
1. A power system code review method based on large model prompt word optimization, characterized in that, include: Basic resource layer, core function layer, and engineering integration layer; The basic resource layer includes: a power business knowledge base and a power defect layered experience base; The core functional layer includes: a template library construction module, a context processing module, a PowerPrompt-DAEL optimization module, and a prompt word generation module; The engineering integration layer includes: a DevOps integration module and a feedback processing module.
2. The power system code review method according to claim 1, characterized in that, The power business knowledge base includes: a standard document sub-base, a historical defect sub-base, and a knowledge graph sub-base; The power defect stratification experience database includes: a high-risk defect sub-database, a medium-risk defect sub-database, and a low-risk defect sub-database.
3. The power system code review method according to claim 1, characterized in that, The template library construction module includes: Scenario requirements analysis and template design: Real-time control scenarios focus on compliance verification of timing logic and power communication protocols, while business system scenarios focus on compliance verification of power industry software quality specifications. A priority inspection strategy for high-risk defects is determined by combining power industry defect classification standards. Template design includes semantic parsing templates to guide the model in extracting power-specific entities and control flows; rule matching templates to associate specific standard clauses for defect inspection; and recommendations to generate template outputs containing standard code snippets for repair solutions. Content embedding and verification: Standard clauses are associated through a scenario-defect-standard mapping table, and compliant code snippets are embedded; the coverage of power history code test templates is selected, and expert reviews are organized. If the review fails, iterative optimization is carried out.
4. The power system code review method according to claim 1, characterized in that, The context processing module extracts code structure features through an abstract syntax tree, retrieves business constraints from a knowledge base, and dynamically integrates them according to scenarios, including: Structural feature extraction: The code is converted into an abstract syntax tree, the nodes are traversed to record the call relationship and reference chain, and the control flow, complexity, and variable dependencies are extracted from the abstract syntax tree and converted into natural language descriptions; Business context retrieval and fusion: Convert code into vector representation, match knowledge base through dense paragraph retrieval model, recall standard terms, historical cases, knowledge graph related information, and integrate into structured description; identify code scenario type, and fuse structured description and business description according to preset weights; Compliance verification: Verify the double confirmation and five-prevention logic terms through the power terminology dictionary to ensure no omissions; verify the validity of the clauses by connecting to the power grid standard library, and replace invalid clauses with the latest ones; check whether the context contains control flow, variable dependencies, and business constraints, and supplement the context information if missing; if it fails, it will be automatically supplemented and re-verified until it passes, and output a fusion context that conforms to power specifications.
5. The power system code review method according to claim 1, characterized in that, The PowerPrompt-DAEL optimization module uses a dual-branch network to generate scenario-specific parameters, evaluates the optimization effect hierarchically, and ensures parameter iteration stability through gradient optimization, including: dual-branch policy network, hierarchical value evaluation network, and algorithm iteration; The dual-branch strategy network generates scenario-based prompt word adjustment parameters: based on the LSTM network encoding historical structure trajectories, it outputs structural parameters; it identifies the scenario type through a scenario classifier and outputs business parameters; it assigns weights based on the similarity between the branch outputs and the scenario labels, and merges them into adjustment actions. The hierarchical value assessment network calculates a global value score based on "defect identification accuracy, power rule coverage, and response time"; outputs a scenario-specific value score based on scenario type; and merges the global value score and the scenario-specific value score according to a preset weight ratio.
6. The power system code review method according to claim 5, characterized in that, The algorithm iteration first initializes the algorithm by generating parameters through a dual-branch network, then calls the large code model to perform code review and obtain the code review results; the reward value is calculated based on global and scenario metrics, and sampling is performed hierarchically according to priority. Calculate the value loss and policy loss, update the network parameters, and perform soft updates to the target network; When the increase in the comprehensive value score is less than the threshold for multiple consecutive rounds, the algorithm is considered to have converged and the optimal parameters are output.
7. The power system code review method according to claim 1, characterized in that, The prompt word generation module will inject the context and optimized parameters into the template, and output the target prompt word after verification with power terminology and standard clauses.
8. The power system code review method according to claim 1, characterized in that, The DevOps integration module automatically triggers the review process when code is submitted via GitLab Webhook, synchronizing the review results of the large code model to the tools commonly used by developers.
9. The power system code review method according to claim 1, characterized in that, The feedback processing module collects data on human corrections to the AI review results, selects high-value samples to update the experience base and knowledge base, forming a closed loop of "AI review - human feedback - data iteration".
10. A power system code review system based on large model prompt word optimization, characterized in that, include: The power scenario template library construction module is used to build a three-level progressive task prompt template library consisting of semantic parsing, rule matching, and suggestion generation. Context processing module: used to extract the abstract syntax tree structure features of the power code to be reviewed and retrieve the corresponding power business constraint information from the power business knowledge base; PowerPrompt-DAEL Algorithm Optimization Module: Used to generate prompts and adjust parameters for power scenarios through a dual-branch strategy network of structural adaptation and business adaptation; Prompt word generation module: It is used to inject context data and prompt word parameters into the three-level task prompt template corresponding to the power scenario. After verifying the accuracy of power terminology and compliance with standard clauses, it generates target optimized prompt words for power system code review. DevOps integration module: used to connect with the R&D pipeline of power companies, triggering the code review process when code is submitted, and synchronizing the review results to the merge request page and defect tracking system; Feedback Iteration Processing Module: Used to collect correction and annotation data of code review results by humans, screen samples to update the power defect stratification experience library, feed back new power defect cases and updated industry standard clauses to the power business knowledge base, and trigger periodic fine-tuning of prompt word templates and optimization algorithms; Basic resource support module: used for storing and managing the power business knowledge base and the power defect layered experience base.