Minimization modification program repairing method, device and system based on large language model and storage medium

Through the iterative increment minimization modification strategy and code equivalence comparison mechanism, the problems of poor consistency, excessive modification and high randomness in the program repair method of large language model are solved, and efficient and accurate program repair is achieved, suitable for Software development and education scenarios.

CN119415074AActive Publication Date: 2025-02-11YANSHAN UNIV

Patent Information

Application Number
CN202411515816.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-02-11
Estimated Expiration
2044-10-29

AI Technical Summary

Technical Problem

The existing program repair methods based on large language models have problems such as poor consistency, excessive modification and high randomness, which leads to inconsistent repair results and is difficult to achieve minimal modification.

Method used

The minimization modification strategy and code equivalence comparison mechanism of iterative increments are adopted to achieve minimal modification of the program by gradually increasing the number of lines of code allowed to be modified, and the abstract syntax tree analysis is used to compare the code to be repaired and historical repair records. , improve repair consistency and efficiency.

Benefits of technology

It improves the consistency and accuracy of repair results, reduces randomness and resource consumption, and achieves minimized code modification, which is suitable for software development and programming education scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415074A_ABST
    Figure CN119415074A_ABST
Patent Text Reader

Abstract

The invention discloses a minimization modification program repairing method, device and system based on a large language model and a storage medium. The method comprises the steps that a to-be-repaired program and problem description are obtained; initializing the modification line number to be limited to be 1, and setting the temperature of the large language model to be 0; determining all information of the current defect code; based on the set maximum modification line number, reasoning is conducted through a large language model to generate a repair result; verifying the correctness of the repair result by using the test case; when the repair result is correct, the correct repair result is stored in a database, and when the repair result is wrong, 1 is added to the number of modification lines, the large language model conducts reasoning again based on all information of the current defect code, the repair result is updated, and the correctness of the updated repair result is verified through a test case; and if the current modification line number is greater than the set maximum modification line number, directly ending the repair process. According to the method, the program repairing correctness can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence and software engineering technology, and in particular to a method, device, system and storage medium for minimizing program modification based on a large language model. Background Art

[0002] The Large Language Model is a natural language processing model based on deep learning, and its core structure is usually based on the Transformer architecture. Transformer is a neural network structure based on the self-attention mechanism, mainly composed of multiple layers of encoders and decoders.

[0003] At present, the application methods of large language models in the field of program repair can be divided into the following two categories:

[0004] The first category is direct code generation: such as OpenAI's ChatGPT, which can directly generate complete programs based on natural language descriptions or partial codes. Although this method is powerful, it may over-modify the original code when fixing specific errors.

[0005] The second category is multi-round interactive repair: Some studies propose to interact with LLM through multi-round dialogues to gradually refine the repair plan.

[0006] Although these methods have made significant progress in the field of program repair, the following key issues still exist:

[0007] a) Poor consistency: For similar codes, LLM may generate different repair solutions, which lacks consistency in repair results. And due to the randomness of large language models, even for the same input, LLM may produce different outputs in different runs, which is easy to mislead students, especially in educational scenarios.

[0008] b) Excessive modification: LLM tends to generate complete code snippets, which may introduce unnecessary changes and make it impossible for the source code author to accurately capture the specific location of defects in the source code and how to modify them. In educational scenarios, this will have a significant negative impact on students and may even affect other functional logic of the original program, making it difficult to achieve gradual and minimal code modification.

[0009] These problems limit the application of LLM-based program repair technology in actual software development and maintenance, especially in scenarios that require high consistency, controllability, and efficiency. Therefore, how to improve the consistency of repairs, reduce randomness, and minimize modifications has become a key issue that needs to be solved in this field. Summary of the invention

[0010] In order to solve the above problems, the present invention provides a method, device, system and storage medium for minimizing program modification based on a large language model, aiming to achieve at least one of the following purposes:

[0011] 1) Improve the consistency of repair results and provide consistent repair solutions for similar errors.

[0012] 2) Reduce the randomness of the repair process and improve repeatability, especially in educational scenarios to avoid misleading students.

[0013] 3) Minimize code modifications and help developers or students accurately locate and understand defects in the code.

[0014] 4) Maintain the original code structure and functional logic to avoid introducing unnecessary changes.

[0015] 5) Improve repair efficiency and reduce resource consumption.

[0016] In order to achieve the above object, the technical solution adopted by the present invention is as follows:

[0017] According to a first solution of the present invention, a method for repairing a program with minimal modification based on a large language model is provided, the method comprising:

[0018] Get the fix and problem description;

[0019] Initialize the modification row limit to 1 and set the temperature of the large language model to 0;

[0020] Determine all information of the current defect code according to the program to be repaired and the problem description; wherein all information of the current defect code includes defect code information in the program to be repaired and error repair results of previous rounds;

[0021] Based on the set maximum number of modified lines, the large language model generates a repair result by reasoning in response to all the information of the current defect code input;

[0022] The correctness of the repair result is verified by using test cases; if the repair result is correct, the correct repair result is saved in the database; if the repair result is wrong, the number of modified rows is increased by 1, the large language model is re-reasoned based on all information of the current defect code, the repair result is updated, and the correctness of the updated repair result is verified by using test cases;

[0023] If the current number of modified rows is greater than the set maximum number of modified rows, the repair process ends directly.

[0024] Furthermore, before determining all information of the current defect code according to the program to be repaired and the problem description, the method includes:

[0025] Obtaining abstract syntax trees in all historical repair records; wherein the abstract syntax trees in the historical repair records are obtained by converting programs successfully repaired by the historical repair records;

[0026] The program to be repaired is converted into an abstract syntax tree and compared with the abstract syntax tree in the historical repair record. If there is an abstract syntax tree that is exactly the same as the current abstract syntax tree in all historical repair records, the repair result in the corresponding historical repair record will be directly used as the repair result of the current program to be repaired, and the repair process will be terminated.

[0027] Furthermore, the maximum number of modified rows is set as follows:

[0028] Based on the boosted word, the maximum number of modified lines in the prompt word that the large language model generates results according to the current settings.

[0029] Further, the problem is described as:

[0030] Given a matrix of data, find a non-empty submatrix in the matrix that maximizes the sum of the elements in the non-empty submatrix.

[0031] Furthermore, the large language model includes:

[0032] The input processing layer is used to convert the input text data into a word sequence; wherein the input text data is the program to be repaired, the problem description and the set maximum number of modified lines;

[0033] An embedding layer for converting the word sequence into a vector representation;

[0034] A self-attention mechanism layer, in response to the input of the embedding layer, calculates the relationship between each element in the input sequence through a multi-head attention mechanism;

[0035] A feedforward neural network, for processing the output of the self-attention mechanism layer;

[0036] Layer normalization and residual connection layers are used to stabilize the training process and alleviate the gradient vanishing problem;

[0037] Multi-layer stacking, including multiple stacked Transformer layers;

[0038] The output layer generates the probability distribution of the next word through the softmax function.

[0039] According to a second technical solution of the present invention, there is provided a program repair device with minimized modification based on a large language model, the device comprising:

[0040] A text acquisition module is configured to acquire a program to be repaired and a description of a problem;

[0041] The initialization module is configured to initialize the modification row limit to 1 and set the temperature of the large language model to 0;

[0042] An information determination module is configured to determine all information of the current defect code according to the program to be repaired and the problem description; wherein all information of the current defect code includes defect code information in the program to be repaired and error repair results of previous rounds;

[0043] A reasoning and repairing module is configured to generate a repair result by reasoning based on a set maximum number of modified lines and responding to all information of the input current defect code using the large language model;

[0044] The iterative repair module is configured to verify the correctness of the repair result by using a test case; if the repair result is correct, the correct repair result is saved in the database; if the repair result is wrong, the number of modified rows is increased by 1, the large language model is re-reasoned based on all information of the current defect code, the repair result is updated, and the correctness of the updated repair result is verified by using a test case;

[0045] The iteration termination module is configured to directly terminate the repair process if the current number of modified rows is greater than the set maximum number of modified rows.

[0046] Furthermore, the device further comprises an equivalence comparison module, and the equivalence comparison module is configured to:

[0047] Obtaining abstract syntax trees in all historical repair records; wherein the abstract syntax trees in the historical repair records are obtained by converting programs successfully repaired by the historical repair records;

[0048] The program to be repaired is converted into an abstract syntax tree and compared with the abstract syntax tree in the historical repair record. If there is an abstract syntax tree that is exactly the same as the current abstract syntax tree in all historical repair records, the repair result in the corresponding historical repair record will be directly used as the repair result of the current program to be repaired, and the repair process will be terminated.

[0049] Furthermore, the problem is described as: given a matrix of data, find a non-empty submatrix in the matrix so that the sum of the elements in the non-empty submatrix is ​​maximized.

[0050] According to a third technical solution of the present invention, a system for minimizing program modifications based on a large language model is provided, the system comprising: a memory for storing a computer program; and a processor for executing the computer program to implement the method described above.

[0051] According to a fourth technical solution of the present invention, a non-transitory computer-readable storage medium storing instructions is provided. When the instructions are executed by a processor, the method described above is executed.

[0052] The present invention has at least the following beneficial effects:

[0053] The present invention designs a minimization modification strategy based on iterative increments and a code equivalence comparison mechanism, wherein the minimization modification strategy based on iterative increments realizes the minimization modification of the program by gradually increasing the number of lines of code allowed to be modified, thereby ensuring the accuracy and comprehensibility of the repair. The code equivalence comparison mechanism utilizes abstract syntax tree (AST) analysis to compare the code to be repaired with the historical repair record to improve the consistency and efficiency of the repair. These two core technical key points cooperate with each other to form an innovative and efficient minimization program repair method. This method can not only improve the accuracy and consistency of the repair, but also reduce the reasoning and calculation cost of large models. It is particularly suitable for software development and programming education scenarios, improves the availability of program repair tools, and reduces application costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 A flowchart of a method for repairing a program with minimal modification based on a large language model according to an embodiment of the present invention is shown.

[0055] Figure 2 A flow chart of a code equivalence comparison mechanism according to an embodiment of the present invention is shown.

[0056] Figure 3 A schematic diagram of a defect code according to an embodiment of the present invention is shown.

[0057] Figure 4 A prompt word structure diagram according to an embodiment of the present invention is shown.

[0058] Figure 5 A test result diagram of a program repair method with minimized modification based on a large language model according to an embodiment of the present invention is shown.

[0059] Figure 6 The structure diagram of a program repair device with minimized modification based on a large language model according to an embodiment of the invention is shown.

[0060] Figure 7 Another structural diagram of a program repairing device with minimized modification based on a large language model according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0061] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.

[0062] The specific implementation of the present invention is further described in detail below in conjunction with the drawings and examples.

[0063] The embodiment of the present invention provides a method for repairing programs with minimal modification based on a large language model. Figure 1 , is a flowchart of a method for repairing a program with minimal modification based on a large language model, the method for repairing a program with minimal modification based on a large language model comprising the following steps:

[0064] S100. Obtain the program to be repaired and the problem description.

[0065] In this embodiment, the program to be repaired may be a defective part of a program, and the code corresponding to the defective part is used as the program to be repaired, while the function and purpose to be achieved by the defective part are reflected in the problem description.

[0066] In some embodiments, the problem description may be: given a matrix of data, find a non-empty submatrix in the matrix such that the sum of the elements in the non-empty submatrix is ​​maximized.

[0067] Exemplarily, the problem description includes a description of the problem and also includes a definition of the input format and the output format.

[0068] S200, initialize and modify the row limit to 1, and set the temperature of the large language model to 0;

[0069] In this embodiment, step S200 is an initialization step for the large language model. The temperature of the large language model is set to 0, which effectively reduces the randomness of the repair process, improves the predictability and repeatability of the results, and avoids misleading students. And the number of modified lines is initialized to 1, so that in the process of repairing the program, the modification is minimized, the structure and functional logic of the original code are maintained as much as possible, and potential problems caused by excessive modification are avoided.

[0070] When using a large language model for code repair, temperature is a key parameter that controls the certainty of the repair result. This key parameter adjusts the output probability distribution of the model through the following formula:

[0071] P'(x)=exp(log(P(x)) / T)

[0072] Where T is the temperature value, P(x) is the original probability distribution, P'(x) is the adjusted probability distribution, and exp is the empirical function.

[0073] Lower temperature values ​​(such as 0.1-0.3) will make the model more inclined to choose high-probability outputs, resulting in more certain and conservative code repair results. In particular, when the temperature T is set to 0, the model will always choose the output with the highest probability, that is, adopt a completely deterministic greedy decoding strategy. This feature is particularly important in code repair scenarios, which not only allows code repairs to maintain a high degree of accuracy and consistency, but also avoids potential errors that may be caused by introducing unnecessary creative changes.

[0074] Therefore, in the present invention, the selection of temperature parameters focuses on ensuring the reliability and certainty of the code repair output.

[0075] In some embodiments, the large language model includes the following seven structural layers:

[0076] The input processing layer is used to convert the input text into a sequence of tokens.

[0077] Embedding layer, which converts tokens into vector representations.

[0078] The self-attention mechanism layer is used by the model to calculate the relationship between each element in the input sequence through a multi-head attention mechanism.

[0079] A feed-forward neural network is used to further process the output of the attention mechanism.

[0080] Layer normalization and residual connection layers are used to stabilize the training process and alleviate the gradient vanishing problem.

[0081] Multi-layer stacking layers are used to stack multiple Transformer layers so that the model can learn more complex language representations.

[0082] The output layer, as the final layer, generates the probability distribution of the next word through the softmax function.

[0083] The large language model learns rich language knowledge and patterns by pre-training on a large text corpus. After fine-tuning on specific tasks, these models can perform various natural language processing tasks, including text generation, question answering, summarization, etc. In the field of program repair, the large language model uses its powerful language understanding and generation capabilities to analyze code containing errors, understand problem descriptions, and generate corresponding repair plans.

[0084] S300. Determine all information of the current defect code according to the program to be repaired and the problem description; wherein all information of the current defect code includes defect code information in the program to be repaired and error repair results of previous rounds.

[0085] In this embodiment, all information of the current defect code includes the defect code, and part or all of the program to be repaired can be used as the defect code. The error repair result of the previous round is a repair result that was previously repaired based on the program to be repaired and the problem description using a large language model. The repair result did not pass the correctness verification, so it is used as the error repair result. Collecting the error repair results of the previous round can avoid the large language model from repairing the program to be repaired according to the previous repair method.

[0086] In some embodiments, Figure 2 As shown, before determining all information of the current defect code according to the program to be repaired and the problem description, the method includes:

[0087] S201, obtaining abstract syntax trees in all historical repair records; wherein the abstract syntax trees in the historical repair records are obtained by converting programs successfully repaired by the historical repair records;

[0088] S202. Convert the program to be repaired into an abstract syntax tree and compare it with the abstract syntax tree in the historical repair record. If there is an abstract syntax tree that is exactly the same as the current abstract syntax tree in all historical repair records, the repair result in the corresponding historical repair record is directly used as the repair result of the current program to be repaired, and the repair process ends.

[0089] In this embodiment, a code equivalence comparison mechanism is provided, and historical repair records are used to reduce repeated calculations, significantly improve repair efficiency, and reduce resource consumption. In addition, through code equivalence comparison and abstract syntax tree (AST) analysis, the consistency of repair is significantly improved. For logically equivalent errors, a consistent repair solution can be provided, which is particularly suitable for educational scenarios.

[0090] S400: Based on the set maximum number of modified lines, the large language model generates a repair result by reasoning in response to all the information of the input current defect code.

[0091] In this embodiment, the maximum number of modified lines is the maximum number of program lines that can be repaired during a program repair process. For example, if the maximum number of modified lines is set to 5, the maximum number of program lines that can be repaired is 5. During the program repair process, when the program is initially repaired, the number of modified lines is 1. During the continuous iteration process, the number of modified lines will increase as the program repair deepens. The increased number of modified lines shall not be greater than the set maximum number of modified lines to avoid excessive modification of the original program.

[0092] In some embodiments, the maximum number of modified lines is set by the following method: based on the boosted word, the maximum number of modified lines in the prompt word that requires the large language model to generate a result according to the current setting.

[0093] S500. Use test cases to verify the correctness of the repair result. If the repair result is correct, save the correct repair result to the database. If the repair result is wrong, add 1 to the number of modified rows. The large language model re-reasons based on all the information of the current defect code, updates the repair result, and uses test cases to verify the correctness of the updated repair result. If the current number of modified rows is greater than the set maximum number of modified rows, the repair process ends directly.

[0094] In this embodiment, step S500 is an iterative verification process, that is, using test cases to verify the repair results. If the repair result is correct, the repair program ends and the correct repair result is output. If the repair result is wrong, the number of modified rows must be changed, step S400 is re-executed and the repair result is updated until the number of modified rows reaches the set maximum number of modified rows.

[0095] Therefore, the present invention adopts an iterative incremental approach and a minimal modification strategy to ensure minimal interference with the original code. This helps developers and students accurately locate and understand defects in the code and learn how to perform appropriate repairs. The method provided by the present invention can effectively improve the correctness of program repairs and the similarity between the repaired code and the source code, while avoiding unnecessary patch generation processes, saving computing resources, and greatly improving the application value in actual development and education scenarios.

[0096] The following embodiment of the present invention will be combined with a specific example to verify the feasibility and advancement of the present invention.

[0097] First, determine the problem description and defect code as shown in Table 1 and Figure 3 shown. Figure 3 In the figure, the bold underlined part is the line where the defect is located.

[0098] Table 1 Problem description examples

[0099]

[0100]

[0101] Based on Figure 4 The prompt word structure shown in the figure is used to input the title description, defect code and {x}, where {x} is the "number of modified lines limit" which is gradually iteratively increased. The initial value is 1 and it increases by 1 after each iteration. The title description is the problem description shown in Table 1, which can be input in the form of a table or text. The defect code is as follows: Figure 3 shown.

[0102] The large language model obtains the corresponding input according to the prompt word structure. An input example and output example are as follows:

[0103] Input example:

[0104] “You are a teaching assistant for a C++ course, helping students debug programs. Here is a program with a bug. Can you fix it?

[0105]

[0106]

[0107]

[0108] Can you fix the above defective code with just one line of modification? If you can't, please reply "Can't do it", otherwise just generate the complete code after the fix. "

[0109] Sample output:

[0110]

[0111]

[0112]

[0113] The output example is a program repair result output by the large language model. The program repair result is tested using a test case. The test result is as follows: Figure 5 shown.

[0114] The embodiment of the present invention also provides a program repair device based on a large language model with minimal modification, such as Figure 6 As shown, the device comprises:

[0115] The text acquisition module 601 is configured to acquire the program to be repaired and the problem description;

[0116] Initialization module 602 is configured to initialize the modification row limit to 1 and set the temperature of the large language model to 0;

[0117] The information determination module 603 is configured to determine all information of the current defect code according to the program to be repaired and the problem description; wherein all information of the current defect code includes defect code information in the program to be repaired and error repair results of the previous round;

[0118] The reasoning and repairing module 604 is configured to generate a repair result by reasoning based on the set maximum number of modified lines and responding to all the information of the current defect code input by the large language model;

[0119] The iterative repair module 605 is configured to verify the correctness of the repair result using a test case; if the repair result is correct, the correct repair result is saved to the database; if the repair result is wrong, the number of modified rows is increased by 1, and the large language model re-reasons based on all information of the current defect code, updates the repair result, and verifies the correctness of the updated repair result using a test case; if the current number of modified rows is greater than the set maximum number of modified rows, the repair process is terminated directly.

[0120] In some embodiments, Figure 7 As shown, the apparatus further includes an equivalence comparison module 606, and the equivalence comparison module 606 is configured to:

[0121] Obtaining abstract syntax trees in all historical repair records; wherein the abstract syntax trees in the historical repair records are obtained by converting programs successfully repaired by the historical repair records;

[0122] The program to be repaired is converted into an abstract syntax tree and compared with the abstract syntax tree in the historical repair record. If there is an abstract syntax tree that is exactly the same as the current abstract syntax tree in all historical repair records, the repair result in the corresponding historical repair record will be directly used as the repair result of the current program to be repaired, and the repair process will be terminated.

[0123] In some embodiments, the problem is described as: given a matrix of data, find a non-empty submatrix in the matrix such that the sum of the elements in the non-empty submatrix is ​​maximized.

[0124] It should be noted that the device described in this embodiment and the method described previously belong to the same technical concept, have the same technical principles, and can achieve the same beneficial effects, so they will not be repeated here.

[0125] An embodiment of the present invention further provides a program repair system with minimized modification based on a large language model, the system comprising: a memory for storing a computer program; and a processor for executing the computer program to implement the method described in any of the above embodiments.

[0126] An embodiment of the present invention further provides a non-transitory computer-readable storage medium storing instructions, and when the instructions are executed by a processor, the method described in any of the above embodiments is executed.

[0127] The above implementation modes are only used to illustrate the present invention, but not to limit the present invention. Ordinary technicians in the relevant technical field can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, all equivalent technical solutions also belong to the scope of the present invention. The patent protection scope of the present invention should be defined by the claims.

Claims

1. A method for minimizing program repair based on a large language model, characterized in that: The method comprises: Get the fix and problem description; Initialize the modification row limit to 1 and set the temperature of the large language model to 0; Determine all information of the current defect code according to the program to be repaired and the problem description; wherein all information of the current defect code includes defect code information in the program to be repaired and error repair results of previous rounds; Based on the set maximum number of modified lines, the large language model generates a repair result by reasoning in response to all the information of the current defect code input; The correctness of the repair result is verified by using test cases. If the repair result is correct, the correct repair result is saved to the database. If the repair result is wrong, the number of modified rows is increased by 1, and the large language model is re-reasoned based on all the information of the current defect code, the repair result is updated, and the correctness of the updated repair result is verified by using test cases. If the current number of modified rows is greater than the set maximum number of modified rows, the repair process is terminated directly.

2. The method for repairing a program with minimal modification based on a large language model as claimed in claim 1, characterized in that: Before determining all information of the current defect code according to the program to be repaired and the problem description, the method includes: Obtaining abstract syntax trees in all historical repair records; wherein the abstract syntax trees in the historical repair records are obtained by converting programs successfully repaired by the historical repair records; The program to be repaired is converted into an abstract syntax tree and compared with the abstract syntax tree in the historical repair record. If there is an abstract syntax tree that is exactly the same as the current abstract syntax tree in all historical repair records, the repair result in the corresponding historical repair record will be directly used as the repair result of the current program to be repaired, and the repair process will be terminated.

3. The method for repairing a program with minimal modification based on a large language model as claimed in claim 1, characterized in that: The maximum number of modified rows is set by the following method: Based on the boosted word, the maximum number of modified lines in the prompt word that the large language model generates results according to the current settings.

4. The method for repairing a program with minimal modification based on a large language model as claimed in claim 3, characterized in that: The problem is described as: Given a matrix of data, find a non-empty submatrix in the matrix that maximizes the sum of the elements in the non-empty submatrix.

5. The method for repairing a program with minimal modification based on a large language model as claimed in claim 1, characterized in that: The large language model includes: The input processing layer is used to convert the input text data into a word sequence; wherein the input text data is the program to be repaired, the problem description and the set maximum number of modified lines; An embedding layer for converting the word sequence into a vector representation; A self-attention mechanism layer, in response to the input of the embedding layer, calculates the relationship between each element in the input sequence through a multi-head attention mechanism; A feedforward neural network, for processing the output of the self-attention mechanism layer; Layer normalization and residual connection layers are used to stabilize the training process and alleviate the gradient vanishing problem; Multi-layer stacking, including multiple stacked Transformer layers; The output layer generates the probability distribution of the next word through the softmax function.

6. A program repair device with minimal modification based on a large language model, characterized in that: The device: A text acquisition module is configured to acquire a program to be repaired and a description of a problem; The initialization module is configured to initialize the modification row limit to 1 and set the temperature of the large language model to 0; An information determination module is configured to determine all information of the current defect code according to the program to be repaired and the problem description; wherein all information of the current defect code includes defect code information in the program to be repaired and error repair results of previous rounds; A reasoning and repairing module is configured to generate a repair result by reasoning based on a set maximum number of modified lines and responding to all information of the input current defect code using the large language model; The iterative repair module is configured to use test cases to verify the correctness of the repair result; if the repair result is correct, the correct repair result is saved to the database; if the repair result is wrong, the number of modified rows is increased by 1, and the large language model re-reasons based on all information of the current defect code, updates the repair result, and uses test cases to verify the correctness of the updated repair result; if the current number of modified rows is greater than the set maximum number of modified rows, the repair process is directly terminated.

7. The device according to claim 6, characterized in that The device also includes an equivalence comparison module, which is configured to: Obtaining abstract syntax trees in all historical repair records; wherein the abstract syntax trees in the historical repair records are obtained by converting programs successfully repaired by the historical repair records; The program to be repaired is converted into an abstract syntax tree and compared with the abstract syntax tree in the historical repair record. If there is an abstract syntax tree that is exactly the same as the current abstract syntax tree in all historical repair records, the repair result in the corresponding historical repair record will be directly used as the repair result of the current program to be repaired, and the repair process will be terminated.

8. The device according to claim 6, characterized in that The problem is described as: given a matrix of data, find a non-empty submatrix in the matrix so that the sum of the elements in the non-empty submatrix is ​​maximized.

9. A minimal modification program repair system based on a large language model, characterized in that: The system comprises: Memory for storing computer programs; A processor, configured to execute the computer program to implement the method according to any one of claims 1 to 5. 10 . A non-transitory computer-readable storage medium storing instructions, which, when executed by a processor, executes the method according to claim 1 .

Citation Information

Patent Citations

  • Warehouse-level code defect automatic repairing method based on large language model

    CN117851101A

  • Method and system for automatically generating reusable API based on code snippets

    CN117892031A

Cited By

  • Method and device for testing large language model, computer equipment, storage medium and program product

    CN120705072A