Code review method, device and electronic equipment
Code review and optimization through large model agents is solved, and the problem of high human resources and time consumption in traditional methods is achieved, efficient and automated code review and optimization is achieved, and the review accuracy and code quality are improved.
Patent Information
- Application Number
- CN202411868759.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-12-18
AI Technical Summary
Traditional code review and optimization have high requirements for human resources and time, and there are human subjectivity and bias, making it difficult to improve review efficiency.
By obtaining the code to be reviewed and its related background knowledge, using large-scale agents for code review and optimization, including business understanding, code review, code modification and testing, to achieve automated review and optimization.
It improves the efficiency of code review and optimization, reduces labor costs, avoids human subjectivity and bias, and ensures review accuracy and code quality.
Smart Images

Figure CN119322636B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a code review method, device and electronic device. Background Art
[0002] Traditional code review and code optimization consume a lot of human resources and time, and are subject to human subjectivity and bias. To improve the effectiveness of the review, more people and time need to be invested in the review. In addition, code review and optimization require high capabilities of reviewers and optimizers, who must not only have strong technical capabilities, but also have sufficient understanding of related businesses.
[0003] How to improve code review and optimization efficiency has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The embodiments of the present application provide a code review method, device and electronic device for improving the efficiency of code review and optimization.
[0005] In a first aspect, an embodiment of the present application provides a code review method, comprising:
[0006] Obtaining the code to be reviewed, the submission description corresponding to the code to be reviewed, and the target knowledge system category to which the code to be reviewed belongs;
[0007] According to the target knowledge system category, relevant background knowledge with a matching degree greater than a preset threshold with the code to be reviewed is obtained from the local knowledge base;
[0008] Inputting a first prompt word composed of the relevant background knowledge and the submitted description into an intelligent agent with a business understanding expert role predefined based on a large model, the intelligent agent with the business understanding expert role performs precision processing on the submitted description based on the first prompt word to obtain a submitted description after precision processing, wherein the matching degree between the submitted description after precision processing and the relevant background knowledge is greater than the matching degree between the submitted description before precision processing and the relevant background knowledge;
[0009] The relevant background knowledge, the submission description after precision processing, and the second prompt word composed of the code to be reviewed are input into an intelligent agent with code review expert responsibilities predefined based on the big model, and the intelligent agent with code review expert responsibilities performs a basic review on the code to be reviewed based on the second prompt word to obtain review suggestions;
[0010] The relevant background knowledge, the submission description after precise processing, the code to be reviewed and the third prompt word consisting of the review suggestions are input into an intelligent agent with code development expert responsibilities pre-defined based on the big model. The intelligent agent with code development expert responsibilities modifies the code to be reviewed based on the third prompt word to obtain the modified code.
[0011] In one possible implementation manner, after modifying the code to be reviewed to obtain the modified code, the method further includes:
[0012] Input the relevant background knowledge, the submission description after precision processing and the fourth prompt word composed of the modified code into an agent with code testing expert responsibilities predefined based on the big model to obtain a test plan for testing the modified code;
[0013] A test environment corresponding to the test scheme is built, and the modified code is tested using a preset tool set to obtain test results.
[0014] In one possible implementation manner, after obtaining the test result, the method further includes:
[0015] Determine whether the test results meet the expected requirements;
[0016] If not, feedback is given to the intelligent agent with the responsibility of code development expert, and the intelligent agent with the responsibility of code development expert modifies the modified code until the corresponding test results meet the expected requirements.
[0017] In one possible implementation manner, after determining whether the test result meets the expected requirement, the method further includes:
[0018] If yes, the modified code is used as the preliminary qualified code;
[0019] The preliminary qualified code and the relevant background knowledge are sent to at least one intelligent agent adjusted and optimized based on user needs predefined in the large model, and the preliminary qualified code is optimized respectively to obtain optimized code.
[0020] In one possible implementation, if the at least one agent that is adjusted and optimized based on user needs predefined in the large model includes an agent of a code performance optimization expert, an agent of a code resource optimization expert, and an agent of a code security performance optimization expert, then the preliminary qualified code is optimized respectively to obtain an optimized code, including:
[0021] The preliminary qualified code is optimized by the intelligent agent of the code performance optimization expert to obtain a first optimization result; the intelligent agent of the code performance optimization expert is obtained based on training and fine-tuning the large model for code performance optimization;
[0022] Optimizing the preliminary qualified code by the intelligent agent of the code resource optimization expert to obtain a second optimization result;
[0023] Optimizing the preliminary qualified code by the agent of the code security performance optimization expert to obtain a third optimization result;
[0024] The relevant background knowledge, the first optimization result, the second optimization result, the third optimization result and a fifth prompt word consisting of a preset decision weight are input into an intelligent agent with the highest decision-maker responsibility predefined based on the big model to obtain a code after the decision.
[0025] In one possible implementation manner, after obtaining the decided code, the method further includes:
[0026] Scan and detect the code after the decision is made to obtain a detection result;
[0027] Determine whether the test results meet the expected requirements;
[0028] If not, the information is fed back to the agent with the role of code development expert, and the agent with the role of code development expert modifies the modified code until the corresponding detection result meets the expected requirements;
[0029] If yes, the code after decision is used as the optimal code of the code to be reviewed.
[0030] In a second aspect, an embodiment of the present application provides a code review device, including:
[0031] A first acquisition unit is used to acquire the code to be reviewed, the submission description corresponding to the code to be reviewed, and the target knowledge system category to which the code to be reviewed belongs;
[0032] A second acquisition unit is used to acquire, from a local knowledge base, relevant background knowledge whose matching degree with the code to be reviewed is greater than a preset threshold according to the major category of the target knowledge system;
[0033] A precision processing unit, configured to input the first prompt word composed of the relevant background knowledge and the submitted description into an intelligent agent having the business understanding expert responsibilities predefined based on the large model, perform precision processing on the submitted description, and obtain a submitted description after precision processing;
[0034] A basic review unit, configured to input the relevant background knowledge, the submission description after precision processing, and the second prompt word composed of the code to be reviewed into an intelligent agent based on the code review expert responsibilities predefined in the big model, conduct a basic review on the code to be reviewed, and obtain review suggestions;
[0035] The modification unit is used to input the relevant background knowledge, the submission description after precision processing, the code to be reviewed and the third prompt word consisting of the review suggestions into an intelligent agent with code development expert responsibilities pre-defined based on the large model, modify the code to be reviewed, and obtain the modified code.
[0036] In one possible implementation manner, after the modification unit modifies the code to be reviewed to obtain the modified code, the apparatus further includes a testing unit, wherein the testing unit is configured to:
[0037] Input the relevant background knowledge, the submission description after precision processing and the fourth prompt word composed of the modified code into an agent with code testing expert responsibilities predefined based on the big model to obtain a test plan for testing the modified code;
[0038] A test environment corresponding to the test scheme is built, and the modified code is tested using a preset tool set to obtain test results.
[0039] In one possible implementation manner, after the testing unit obtains the test result, the device further includes a judging unit, wherein the judging unit is configured to:
[0040] Determine whether the test results meet the expected requirements;
[0041] If not, feedback is given to the intelligent agent with the responsibility of code development expert, and the intelligent agent with the responsibility of code development expert modifies the modified code until the corresponding test results meet the expected requirements.
[0042] In one possible implementation manner, after the judging unit judges whether the test result meets the expected requirement, the device further includes an optimizing unit, wherein the optimizing unit is configured to:
[0043] If yes, the modified code is used as the preliminary qualified code;
[0044] The preliminary qualified code and the relevant background knowledge are sent to at least one intelligent agent adjusted and optimized based on user needs predefined in the large model, and the preliminary qualified code is optimized respectively to obtain optimized code.
[0045] In one possible implementation, if the at least one agent that adjusts and optimizes based on user needs predefined in the large model includes an agent of a code performance optimization expert, an agent of a code resource optimization expert, and an agent of a code security performance optimization expert, the optimization unit is used to:
[0046] Optimizing the preliminary qualified code by the intelligent agent of the code performance optimization expert to obtain a first optimization result;
[0047] Optimizing the preliminary qualified code by the intelligent agent of the code resource optimization expert to obtain a second optimization result;
[0048] Optimizing the preliminary qualified code by the agent of the code security performance optimization expert to obtain a third optimization result;
[0049] The relevant background knowledge, the first optimization result, the second optimization result, the third optimization result and a fifth prompt word consisting of a preset decision weight are input into an intelligent agent with the highest decision-maker responsibility predefined based on the big model to obtain a code after the decision.
[0050] In one possible implementation manner, after the optimization unit obtains the code after the decision, the device further includes a scanning unit, and the scanning unit is used to:
[0051] Scan and detect the code after the decision is made to obtain a detection result;
[0052] Determine whether the test results meet the expected requirements;
[0053] If not, the information is fed back to the agent with the role of code development expert, and the agent with the role of code development expert modifies the modified code until the corresponding detection result meets the expected requirements;
[0054] If yes, the code after decision is used as the optimal code of the code to be reviewed.
[0055] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0056] Memory, used to store computer programs;
[0057] The processor is used to implement the method steps described in any one of the above items when executing the computer program stored in the memory.
[0058] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is used to enable a computer to execute the method steps described in any one of the above items.
[0059] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes: a computer program code, and when the computer program code is run on a computer, the computer executes any of the methods described above.
[0060] The beneficial effects of the embodiments of the present application are as follows:
[0061] The embodiment of the present application provides a code review method, device and electronic device. First, the code to be reviewed, the submission description corresponding to the code to be reviewed and the target knowledge system category to which the code to be reviewed belongs are obtained; then, according to the target knowledge system category, the relevant background knowledge with a matching degree greater than a preset threshold value is obtained from the local knowledge base; that is, the relevant background knowledge most relevant to the code to be reviewed is obtained from the local knowledge base; then, the first prompt word composed of the relevant background knowledge and the submission description is input into an intelligent agent with business understanding expert responsibilities predefined based on a large model, and the intelligent agent with business understanding expert responsibilities performs precise processing on the submission description based on the first prompt word, thereby obtaining a submission description after precise processing, and the matching degree between the submission description after precise processing and the relevant background knowledge is greater than the matching degree between the submission description before precise processing and the relevant background knowledge. In this way, it supports access to the business-related knowledge base to realize precise processing of the submission description, avoids the problem of low review accuracy caused by lack of business background knowledge, and provides a guarantee for the subsequent high-precision output of each intelligent agent predefined based on the large model.
[0062] Then, the relevant background knowledge, the submission description after precision processing, and the second prompt word composed of the code to be reviewed are input into the intelligent agent of the code review expert responsibility pre-defined based on the large model. The intelligent agent of the code review expert responsibility conducts a basic review of the code to be reviewed based on the second prompt word and obtains the review suggestion; in this way, the automatic output of the review suggestion is realized. Then, the relevant background knowledge, the submission description after precision processing, the code to be reviewed, and the third prompt word composed of the review code are input into the intelligent agent of the code development expert responsibility pre-defined based on the large model. The intelligent agent of the code development expert responsibility modifies the code to be reviewed based on the third prompt word, thereby obtaining the modified code. In this way, the automatic review and optimization of the code to be reviewed is realized, which greatly saves the labor cost and improves the efficiency of code review and optimization. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 A flowchart of one of the code review methods provided in an embodiment of the present application;
[0064] Figure 2 For Figure 1A flow chart of one of the methods after step S105;
[0065] Figure 3 For Figure 2 A flow chart of one of the methods after step S202;
[0066] Figure 4 For Figure 3 A flow chart of one of the methods after step S301;
[0067] Figure 5 for Figure 4 A method flow chart of step S402;
[0068] Figure 6 For Figure 5 A flowchart of one of the methods after step S504;
[0069] Figure 7 A method flow chart of the code review part in the code review method provided in an embodiment of the present application;
[0070] Figure 8 A method flow chart of the code optimization part in the code review method provided in an embodiment of the present application;
[0071] Fig. 9 A schematic diagram of a structure of a code review device provided in an embodiment of the present application;
[0072] Fig.10 A schematic diagram of a structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0073] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.
[0074] The terms "first" and "second" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of their variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in the present application can mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.
[0075] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description. It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, which should be considered as exemplary, and their purpose is only to illustrate the feasibility of the implementation of the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0076] In the technical solution of this application, the acquisition, transmission, storage, and use of data are in compliance with the requirements of relevant national laws and regulations.
[0077] In the related technologies, there are some automated code review methods, but they are not good enough in understanding the code business or are too specialized. The scope of the review is also quite limited, with very little content that can be reviewed, and the correctness needs to be considered, requiring users to manually check carefully one by one. In terms of optimization, some tools are generally used to perform standardized optimization on specific aspects, and the degree and scope of optimization are quite limited. In this case, code review and optimization still have a great cost in human resources and time.
[0078] In view of this, the present application provides a code review method, device and electronic device for improving the efficiency of code review and optimization.
[0079] like Figure 1 As shown, the embodiment of the present application provides a code review method, including:
[0080] S101: Obtaining a code to be reviewed, a submission description corresponding to the code to be reviewed, and a target knowledge system category to which the code to be reviewed belongs;
[0081] In the specific implementation process, the code to be reviewed input by the user, the submission description corresponding to the code to be reviewed, and the target knowledge system category to which the code to be reviewed belongs may be obtained. For example, the submission description of the code to be reviewed may be a business-related document, a project description document, etc. For example, the target knowledge system category may be transportation, medical, or school, which is not limited here.
[0082] S102: According to the target knowledge system category, relevant background knowledge whose matching degree with the code to be reviewed is greater than a preset threshold is obtained from the local knowledge base;
[0083] In the specific implementation process, the specific value of the preset threshold can be set according to actual application needs, and is not limited here.
[0084] S103: inputting the first prompt word composed of the relevant background knowledge and the submitted description into an intelligent agent with the business understanding expert role predefined based on the big model, and the intelligent agent with the business understanding expert role performs precision processing on the submitted description based on the first prompt word to obtain a submitted description after precision processing, wherein the matching degree between the submitted description after precision processing and the relevant background knowledge is greater than the matching degree between the submitted description before precision processing and the relevant background knowledge;
[0085] In the specific implementation process, the relevant background knowledge and the submission description can be combined into the first prompt word according to the preset template. Exemplarily, the preset template can be in the following format:
[0086] {"Relevant background knowledge": XXX,
[0087] "Commit description for this code": XXX
[0088] According to the relevant background knowledge, the code submission description is adjusted and modified more accurately, and the adjusted submission description is given; it is output in the following format: {Adjusted submission description: answer content}, where the answer content is replaced with the real answer to the above question
[0089] }
[0090] Then, the first prompt word is input into an intelligent agent with business understanding expert responsibilities predefined based on the large model. The intelligent agent with business understanding expert responsibilities performs precision processing on the submission description based on the first prompt word to obtain the submission description after precision processing; wherein, the matching degree between the submission description after precision processing and the relevant background knowledge is greater than the matching degree between the submission description before precision processing and the relevant background knowledge. Exemplarily, for the specific implementation process of precision processing, the submission description of the code to be reviewed can be improved by using a clear title, describing in detail and specifically the content of the code changes to be reviewed, explaining the reasons for the changes, and associating related background issues or tasks. In this way, the semantics of the improved submission description are more complete and more in line with the project background and actual business functions. In this way, a more accurate review result can be output during the subsequent code review.
[0091] S104: inputting the relevant background knowledge, the submission description after precision processing, and the second prompt word composed of the code to be reviewed into an intelligent agent with the responsibility of a code review expert predefined based on the big model, and the intelligent agent with the responsibility of a code review expert performs a basic review on the code to be reviewed based on the second prompt word to obtain a review suggestion;
[0092] In the specific implementation process, the relevant background knowledge, the submission description after precision processing, and the code to be reviewed can be used to form the second prompt word according to the preset template, and then the second prompt word is input into the intelligent agent with the code review expert responsibility predefined based on the large model. In this way, the intelligent agent with the code review expert responsibility can conduct a basic review of the code to be reviewed based on the second prompt word, thereby obtaining review suggestions. Exemplarily, the preset template that forms the second prompt word can be in the following format:
[0093] {"Relevant background knowledge": XXX,
[0094] "Commit description of this code": XXX (i.e. the refined commit description)
[0095] "Code to be reviewed": XXX
[0096] Combine relevant background knowledge with the submission description of this code to review the code from the aspects of logical correctness, basic specifications, and business requirements, and give review opinions; the answer format is as follows: {review opinion: answer content}, where the answer content is replaced with the actual answer to the above question
[0097] }
[0098] S105: The relevant background knowledge, the submission description after precision processing, the code to be reviewed and the third prompt word consisting of the review suggestions are input into an intelligent agent with the responsibility of code development expert pre-defined based on the big model. The intelligent agent with the responsibility of code development expert modifies the code to be reviewed based on the third prompt word to obtain the modified code.
[0099] In the specific implementation process, after the intelligent agent with the responsibility of code review expert conducts a basic review of the code to be reviewed based on the second prompt word and obtains the review suggestions, the third prompt word can be composed of relevant background knowledge, the submission description after precision processing, the code to be reviewed, and the suggestions to be reviewed according to the preset template. Then, the third prompt word is input into the intelligent agent with the responsibility of code development expert predefined based on the large model. In this way, the intelligent agent with the responsibility of code development expert can modify the code to be reviewed based on the third prompt word, thereby obtaining the modified code. Exemplarily, the preset template that constitutes the third prompt word can be in the following format:
[0100] {"Relevant background knowledge": XXX,
[0101] "Commit description of this code": XXX (i.e. the refined commit description)
[0102] "Code to be reviewed": XXX
[0103] "Existing problems and adjustment suggestions": XXXX (i.e. review suggestions)
[0104] Combined with relevant background knowledge, the code submission description, existing problems and adjustment suggestions are combined to modify and adjust the code to be reviewed. The adjusted code is output in the following format:
[0105] {Adjusted code is: answer content}, where the answer content is the actual adjusted code
[0106] }
[0107] In the embodiments of the present application, Figure 2 As shown, after the code to be reviewed is modified in step S105 and the modified code is obtained, the method further includes:
[0108] S201: inputting the relevant background knowledge, the submission description after precision processing, and the fourth prompt word composed of the modified code into an agent with code testing expert responsibilities predefined based on the big model to obtain a test plan for testing the modified code;
[0109] S202: Building a test environment corresponding to the test solution, and using a preset tool set to test the modified code to obtain a test result.
[0110] In the specific implementation process, the specific implementation process of step S201 to step S202 is as follows:
[0111] After obtaining the modified code, a test plan for the modified code can also be provided. Specifically, the relevant background knowledge, the submission description after precision processing, and the modified code can be combined into a fourth prompt word according to a preset template. Then, the fourth prompt word is input into an intelligent agent with the code testing expert responsibilities predefined based on the large model to obtain a test plan for testing the modified code. Exemplarily, the preset template that constitutes the fourth prompt word can be in the following format:
[0112] {"Relevant background knowledge": XXX,
[0113] "Commit description for this code": XXX (result generated in step 2)
[0114] "Code to be tested": XXX
[0115] Combined with relevant background knowledge and the submitted description of the code, provide a test plan for the code to be tested, including test methods, test codes, and methods for judging test results; output in the following format:
[0116] {"Test Method": XXX
[0117] "Test code": XXX
[0118] "Test result judgment method": XXX
[0119] }
[0120] }
[0121] Then, build a test environment corresponding to the test plan, and use the pre-set toolset to test the modified code to obtain the test results. Exemplarily, you can perform post-processing operations according to the output test plan, use the tools in the pre-set toolset, call the corresponding scripts and functions to build the test environment and run the test code, and finally obtain the test results. Exemplarily, the toolset can be some already developed small tools, applets or services, such as specification scanning. In the specific implementation process, the required toolset can be set according to the actual application needs, which is not limited here.
[0122] In the embodiments of the present application, Figure 3 As shown, after obtaining the test result through step S202, the method further includes:
[0123] S301: Determine whether the test result meets the expected requirements;
[0124] S302: If not, feedback is given to the intelligent agent with the responsibility of code development expert, and the intelligent agent with the responsibility of code development expert modifies the modified code until the corresponding test results meet the expected requirements.
[0125] In the specific implementation process, the specific implementation process of step S301 to step S302 is as follows:
[0126] After obtaining the test results, it can be determined whether the test results meet the expected requirements; if the test results do not meet the expected requirements, the judgment of the test results is fed back to the agent with the role of code development expert. Then, the agent with the role of code development expert modifies the modified code until the test results meet the expected requirements.
[0127] In the embodiments of the present application, Figure 4 As shown, after step S301: determining whether the test result meets the expected requirements, the method further includes:
[0128] S401: If yes, the modified code is used as a preliminary qualified code;
[0129] S402: Send the preliminary qualified code and the relevant background knowledge to at least one intelligent agent that is adjusted and optimized based on user needs predefined in a large model, optimize the preliminary qualified code respectively, and obtain optimized code.
[0130] In the specific implementation process, the specific implementation process of step S401 to step S402 is as follows:
[0131] If the test results meet the expected requirements, the modified code is used as the preliminary qualified code; then, further code optimization is performed. Specifically, the preliminary qualified code and related background knowledge may be sent to at least one intelligent agent that is adjusted and optimized based on user requirements pre-defined in the big model, and the preliminary qualified code is optimized separately to obtain the optimized code. Among them, the at least one intelligent agent that is adjusted and optimized based on user requirements pre-defined in the big model may be one, or two or more, which is not limited here. Exemplarily, different intelligent agents that are adjusted and optimized for user requirements may be created based on the big model according to the optimization direction required by the user. In this way, the optimized code can meet the corresponding needs of the user.
[0132] In one exemplary embodiment, Figure 5As shown, if the at least one agent adjusted and optimized based on the user demand predefined in the large model includes an agent of a code performance optimization expert, an agent of a code resource optimization expert, and an agent of a code security performance optimization expert, then in step S402, the preliminary qualified code is optimized respectively to obtain the optimized code, including:
[0133] S501: Optimizing the preliminary qualified code by the agent of the code performance optimization expert to obtain a first optimization result;
[0134] S502: Optimizing the preliminary qualified code by the agent of the code resource optimization expert to obtain a second optimization result;
[0135] S503: Optimizing the preliminary qualified code by the agent of the code security performance optimization expert to obtain a third optimization result;
[0136] S504: The fifth prompt word consisting of the relevant background knowledge, the first optimization result, the second optimization result, the third optimization result and the pre-set decision weight is input into the intelligent agent with the highest decision maker responsibility pre-defined based on the big model to obtain the code after the decision.
[0137] In the specific implementation process, the specific implementation process of step S501 to step S504 is as follows:
[0138] It should be noted that the execution order of steps S501 to S503 may be: first execute step S501, then execute step S502, and then execute step S503; or first execute step S502, then execute step S501, and then execute step S503; or execute steps S501, S502, and S503 simultaneously. Of course, the execution order of steps S501, S502, and S503 may also be set according to actual application needs, which is not limited here.
[0139] In one exemplary embodiment, the preliminary qualified code may be optimized by the agent of a code performance optimization expert to obtain a first optimization result; the agent of the code performance optimization expert focuses on optimizing the code in terms of the running performance of the code program. The preliminary qualified code may be optimized by the agent of a code resource optimization expert to obtain a second optimization result; the agent of the code resource optimization expert focuses on optimizing the code by reducing the resource overhead of the code program. The preliminary qualified code may be optimized by the agent of a code security performance optimization expert to obtain a third optimization result; the agent of the code security performance optimization expert focuses on optimizing the code from the aspect of the ability to prevent external attacks when the program is running. In practical applications, the three major optimization directions including performance optimization, resource optimization and security performance optimization can be solidified. In addition, users can also be supported to customize and formulate special optimization directions to meet specific needs. Of course, in each optimization direction, the optimized code and the description of the degree of optimization can be given in the end.
[0140] In the specific implementation process, the prompt words of the required template can be input into the corresponding optimization agent to obtain the optimized code. For example, the prompt words used for performance optimization, resource optimization and security performance optimization can be shown in the following format:
[0141] {
[0142] "Relevant background knowledge": XXX,
[0143] "Code to be optimized": XXXX (the preliminary qualified code mentioned above)
[0144] According to the relevant background knowledge, the optimized code is adjusted and optimized in terms of running performance, resource consumption, and security, and the optimized code and optimization description are output in the following format:
[0145] {"Optimized code": XXXXX
[0146] "Optimization Description": XXXXXX
[0147] }
[0148] }
[0149] Then, a multi-dimensional weight PK mechanism can be used to perform multi-dimensional weight PK on each upstream optimization code according to the weight ratio that the user emphasizes on different optimization directions, and finally make a decision to give the final version of the optimization code. Exemplarily, the relevant background knowledge, the first optimization result, the second optimization result, the third optimization result and the pre-set decision weight are combined into the fifth prompt word according to the preset template, and input into the intelligent agent with the highest decision maker responsibility pre-defined based on the large model to obtain the code after the decision. Among them, the decision weight of each optimization direction can be set according to the decision weight desired by the user, which is not limited here. Exemplarily, the preset template format used by the fifth prompt word is as follows:
[0150] {
[0151] “Relevant background knowledge”: relevant context
[0152] "Optimization information for each dimension": [{"Performance optimization code": code after performance optimization, "Optimization description": optimization situation}, {"Resource optimization code": code after resource optimization, "Optimization description": optimization situation}......]
[0153] "User's decision weight": decision weight information
[0154] Make decisions on the optimization codes in the optimization information of each dimension based on relevant background knowledge, and give the final version of the code after combining the user's decision weight. Output in the following format: {"Code after decision:" XXXX}
[0155] }
[0156] It should be noted that the PK trade-off of decision weights generally occurs when there is a conflict in code adjustments in different optimization directions. For example, performance optimization and resource optimization both make different modifications to the same piece of code; at this time, the agent with the highest decision-making responsibility can refer to the decision weight given by the user and make a judgment based on the situation descriptions of both performance optimization and resource optimization to determine the final code modification method.
[0157] In one exemplary embodiment, Figure 6 As shown, after obtaining the decided code in step S504, the method further includes:
[0158] S601: Scan and detect the code after the decision is made to obtain a detection result;
[0159] S602: Determine whether the detection result meets the expected requirements;
[0160] S603: If not, feedback is given to the intelligent agent with the role of code development expert, and the intelligent agent with the role of code development expert modifies the modified code until the corresponding detection result meets the expected requirement;
[0161] S604: If yes, the code after decision is used as the optimal code of the code to be reviewed.
[0162] In the specific implementation process, the specific implementation process of step S601 to step S604 is as follows:
[0163] After obtaining the code after the decision, the code after the decision can be scanned and tested to obtain the test results. Exemplarily, static defect scanning, sensitive word compliance scanning and other scanning tests can be performed, and custom software tools can be imported to test the code. Then, determine whether the test results meet the expected requirements. If the test results do not meet the expected requirements, they will be fed back to the intelligent agent with the responsibility of the code development expert, and the intelligent agent with the responsibility of the code development expert will modify the modified code until the corresponding test results meet the expected requirements. If the test results meet the expected requirements, the code after the decision is used as the optimal code for the code to be reviewed. In practical applications, the optimal code can be finally optimized after review. Subsequently, the final reviewed and optimized code and the modified submission description can be output and fed back to the user.
[0164] Combine the following Figure 7 and Figure 8 The method flow chart shown in FIG. 1 is used to explain the processing link of the code review method provided in the embodiment of the present application. Figure 7 As shown, the corresponding module can be recorded as a code review module. Specifically:
[0165] S1: Start;
[0166] S2: description of the code to be reviewed submitted; illustratively, the code to be reviewed, the corresponding submission description, and the major category of knowledge system to which the current code to be reviewed belongs, provided by the user, may be received; illustratively, the relevant background knowledge of the remaining code to be reviewed whose matching degree is greater than a preset threshold may be obtained from the local knowledge base according to the major category of knowledge system to which the code to be reviewed belongs;
[0167] S3: Description precision; For example, the aforementioned intelligent agent with business understanding expert responsibilities can be used to precisely process the submission description of the code to be reviewed;
[0168] S4: Basic review and suggestions. For example, the aforementioned intelligent agent with the code review expert role can be used to conduct a basic review of the code to be reviewed and obtain review suggestions.
[0169] S5: modify and generate new code; illustratively, the aforementioned intelligent agent with the code development expert role can be used to modify the code to be reviewed based on the review suggestions, thereby obtaining the modified code;
[0170] S6: Providing a test method; illustratively, an agent with the responsibility of a code testing expert may be used to test the modified code and provide a test method;
[0171] S7: Building a test environment to output test results; illustratively, a pre-set tool set may be used to test the modified code to obtain test results;
[0172] S8: Determine whether the test results meet expectations;
[0173] If not, feedback is given to the aforementioned agent with the code development expert role, and step S5 is continued until the corresponding test results meet the expected requirements;
[0174] If so, the modified code is used as the preliminary qualified code and sent to the code optimization module.
[0175] It should be noted that in steps S1 to S8, there is corresponding post-processing between each step to parse the results output by each agent, and obtain the corresponding results by matching the specified format content of the output; then, the process is directed to the agent in the next step.
[0176] In the specific implementation process, the code optimization part is as follows Figure 8 As shown, the corresponding module can be recorded as a code optimization module. Specifically:
[0177] S10: Start;
[0178] S20: Obtain preliminary qualified codes and relevant background knowledge;
[0179] S30: code optimization; illustratively, including step S31: performance optimization, step S32: resource optimization, step S33: security performance optimization and step S34: custom optimization; illustratively, the aforementioned code performance optimization expert agent can be used to optimize the performance of the preliminary qualified code; the aforementioned code resource optimization expert agent can be used to optimize the resources of the preliminary qualified code; the aforementioned code security performance optimization expert agent can be used to optimize the security performance of the preliminary qualified code;
[0180] S40: Multi-dimensional weighing PK; illustratively, the intelligent agent with the highest decision-maker role mentioned above can be used to make decisions on the results of optimization in various aspects, so as to obtain the code after the decision;
[0181] S50: Standard scanning; illustratively, a pre-set tool set may be used to perform standard scanning such as static defect scanning, sensitive word compliance scanning, etc.;
[0182] S60: test adjustment; illustratively, the results of the specification scan and the corresponding prompt words of the code to be tested are handed over to the intelligent agent with the role of code development expert used in the above code review module to modify and adjust the code;
[0183] S70: Determine whether the test result meets expectations. Exemplarily, after the agent with the role of code development expert modifies and adjusts the code, a subsequent test verification process is performed until the final test result meets expectations. The final reviewed and optimized code and the modified submission description are output and fed back to the user.
[0184] S80: End.
[0185] It should be noted that the code review and optimization method provided by the embodiment of the present application can be embedded in the functions provided by GitLab, and the CI process of GitLab can be triggered by triggering code submission or code merging operations, and the process of executing code review and optimization can be embedded in GitRunner therein, and finally the results of code review and optimization can be fed back to the user through GitLab's API interface. In this way, code review and code optimization can be performed automatically. In addition, the code review method provided by the embodiment of the present application can also be encapsulated into a service form, embedded in other systems besides GitLab, and the relevant API interface can be directly called by other entrances, and finally fed back after execution.
[0186] In addition, the code review method provided in the embodiment of the present application defines each role based on a large model and builds a complete link to achieve automated code review optimization; by importing the engineering-related knowledge base and submitting a precise description, the problem of low review accuracy caused by the lack of business background knowledge is solved, and there is no need to retrain specific models for specific engineering business each time, and it has wide applicability; code modification and code testing environments are added to the link, and the code is modified and verified according to review suggestions, etc. to ensure the correctness of the code; by accessing the tool set, it supports standardized operations such as static defect scanning and compliance scanning of the code; introduces a multi-dimensional trade-off PK mechanism to perform in-depth and balanced optimization of the code in each dimension; ultimately improves the efficiency of automated code review optimization, reduces labor costs, and improves the quality of review optimization.
[0187] Based on the big model, knowledge base and tool set, an efficient and complete automated code review optimization link is built. Based on the big model service definition, multi-professional positioning intelligent agents are automatically connected and operated under the review optimization framework link; support is provided for the precise submission of descriptions of access to business-related knowledge base information to ensure the high-precision output of each downstream intelligent agent; a circular automatic link is formed by automatically building a test environment to run test code and adjust and modify the code to verify correctness and repair anomalies; a multi-dimensional trade-off PK mechanism is introduced to ensure the quality of code optimization in each dimension and the user's decision-making bias on the final code; by supporting the import and use of customized tool sets, users are supported to conduct multi-faceted inspections of the code according to their own needs and adjust and repair them by themselves; the construction of the entire set of links ultimately solves the key pain points in the code review optimization process, such as business needs, professional and technical requirements, and high requirements for the correctness and standardization of the final code, and greatly saves labor costs, improves the efficiency of code review optimization, and ensures the quality after review optimization.
[0188] Based on the same inventive concept, Fig. 9 As shown, the embodiment of the present application provides a code review device, including:
[0189] The first acquisition unit 10 is used to acquire the code to be reviewed, the submission description corresponding to the code to be reviewed, and the target knowledge system category to which the code to be reviewed belongs;
[0190] The second acquisition unit 20 is used to acquire, from the local knowledge base, relevant background knowledge whose matching degree with the code to be reviewed is greater than a preset threshold according to the major category of the target knowledge system;
[0191] The precision processing unit 30 is used to input the first prompt word composed of the relevant background knowledge and the submitted description into an intelligent agent with business understanding expert responsibilities predefined based on the big model, perform precision processing on the submitted description, and obtain a submitted description after precision processing;
[0192] A basic review unit 40 is used to input the relevant background knowledge, the submission description after precision processing, and the second prompt word composed of the code to be reviewed into an intelligent agent based on the code review expert responsibilities predefined in the big model, perform a basic review on the code to be reviewed, and obtain review suggestions;
[0193] The modification unit 50 is used to input the relevant background knowledge, the submission description after precision processing, the code to be reviewed and the third prompt word consisting of the review suggestions into an intelligent agent with code development expert responsibilities pre-defined based on the large model, modify the code to be reviewed, and obtain the modified code.
[0194] In the embodiment of the present application, after the modification unit 50 modifies the code to be reviewed and obtains the modified code, the apparatus further includes a testing unit, which is used to:
[0195] Input the relevant background knowledge, the submission description after precision processing and the fourth prompt word composed of the modified code into an agent with code testing expert responsibilities predefined based on the big model to obtain a test plan for testing the modified code;
[0196] A test environment corresponding to the test scheme is built, and the modified code is tested using a preset tool set to obtain test results.
[0197] In the embodiment of the present application, after the testing unit obtains the test result, the device further includes a judging unit, and the judging unit is used to:
[0198] Determine whether the test results meet the expected requirements;
[0199] If not, feedback is given to the intelligent agent with the responsibility of code development expert, and the intelligent agent with the responsibility of code development expert modifies the modified code until the corresponding test results meet the expected requirements.
[0200] In the embodiment of the present application, after the judging unit judges whether the test result meets the expected requirement, the device further includes an optimizing unit, which is used to:
[0201] If yes, the modified code is used as the preliminary qualified code;
[0202] The preliminary qualified code and the relevant background knowledge are sent to at least one intelligent agent adjusted and optimized based on user needs predefined in the large model, and the preliminary qualified code is optimized respectively to obtain optimized code.
[0203] In an embodiment of the present application, if the at least one agent that adjusts and optimizes based on user needs predefined in the large model includes an agent of a code performance optimization expert, an agent of a code resource optimization expert, and an agent of a code security performance optimization expert, the optimization unit is used to:
[0204] Optimizing the preliminary qualified code by the intelligent agent of the code performance optimization expert to obtain a first optimization result;
[0205] Optimizing the preliminary qualified code by the intelligent agent of the code resource optimization expert to obtain a second optimization result;
[0206] Optimizing the preliminary qualified code by the agent of the code security performance optimization expert to obtain a third optimization result;
[0207] The relevant background knowledge, the first optimization result, the second optimization result, the third optimization result and a fifth prompt word consisting of a preset decision weight are input into an intelligent agent with the highest decision-maker responsibility predefined based on the big model to obtain a code after the decision.
[0208] In the embodiment of the present application, after the optimization unit obtains the code after the decision, the device further includes a scanning unit, and the scanning unit is used to:
[0209] Scan and detect the code after the decision is made to obtain a detection result;
[0210] Determine whether the test results meet the expected requirements;
[0211] If not, the information is fed back to the agent with the role of code development expert, and the agent with the role of code development expert modifies the modified code until the corresponding detection result meets the expected requirements;
[0212] If yes, the code after decision is used as the optimal code of the code to be reviewed.
[0213] Based on the same inventive concept, an electronic device is also provided in the embodiment of the present application, and the electronic device can implement the functions of the aforementioned code review method, referring to Fig.10 , the electronic device comprises:
[0214] Memory 100, used for storing computer programs;
[0215] The processor 200 is used to implement the steps of the code review method as described in any of the above items when executing the computer program stored in the memory.
[0216] The specific connection medium between the processor 200 and the memory 100 is not limited in the embodiment of the present application. Fig.10 In the example, the processor 200 and the memory 100 are connected via the bus 300. The bus 300 is connected to the memory 100 via the bus 300. Fig.10 The bus 300 is represented by a bold line, and the connection between other components is only for schematic illustration and is not intended to be limiting. The bus 300 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.10 Only one thick line is used in the figure, but it does not mean that there is only one bus 300 or one type of bus 300. Alternatively, the processor 200 may also be called a controller, and there is no limitation on the name.
[0217] In the embodiment of the present application, the memory 100 stores instructions that can be executed by the processor 200. When the processor 200 executes the computer program stored in the memory 100, the code review method discussed above can be executed. The processor 200 can implement Fig. 9 The functions of each module are shown in the figure.
[0218] Among them, the processor 200 is the control center of the device, and can use various interfaces and lines to connect various parts of the entire control device, and through running or executing computer programs stored in the memory 100 and calling data stored in the memory 100, the various functions of the device and process data, thereby monitoring the device as a whole.
[0219] In one possible design, the processor 200 may include one or more processing units, and the processor 200 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. In some embodiments, the processor 200 and the memory 100 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.
[0220] The memory 100, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 100 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. Alternatively, the memory 100 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 100 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0221] By designing and programming the processor, the code corresponding to the code review method described in the above embodiment can be fixed into the chip, so that the chip can execute the steps of the code review method discussed above when running. How to design and program the processor is a technology well known to those skilled in the art and will not be described here.
[0222] Based on the same inventive concept, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, and the computer program is used to enable a computer to execute the steps of the code review method discussed above.
[0223] In some possible implementations, various aspects of the code review method provided by the present application may also be implemented in the form of a program product, which includes program code. When the program product is run on an apparatus, the program code is used to enable the control device to execute the steps of the code review method according to various exemplary implementations of the present application described above in this specification.
[0224] The embodiment of the present application provides a code review method, device and electronic device. First, the code to be reviewed, the submission description corresponding to the code to be reviewed and the target knowledge system category to which the code to be reviewed belongs are obtained; then, according to the target knowledge system category, the relevant background knowledge with a matching degree greater than a preset threshold value is obtained from the local knowledge base; that is, the relevant background knowledge most relevant to the code to be reviewed is obtained from the local knowledge base; then, the first prompt word composed of the relevant background knowledge and the submission description is input into an intelligent agent with business understanding expert responsibilities predefined based on a large model, and the intelligent agent with business understanding expert responsibilities performs precise processing on the submission description based on the first prompt word, thereby obtaining a submission description after precise processing, and the matching degree between the submission description after precise processing and the relevant background knowledge is greater than the matching degree between the submission description before precise processing and the relevant background knowledge. In this way, it supports access to the business-related knowledge base to realize precise processing of the submission description, avoids the problem of low review accuracy caused by lack of business background knowledge, and provides a guarantee for the subsequent high-precision output of each intelligent agent predefined based on the large model.
[0225] Then, the relevant background knowledge, the submission description after precision processing, and the second prompt word composed of the code to be reviewed are input into the intelligent agent of the code review expert responsibility pre-defined based on the large model. The intelligent agent of the code review expert responsibility conducts a basic review of the code to be reviewed based on the second prompt word and obtains the review suggestion; in this way, the automatic output of the review suggestion is realized. Then, the relevant background knowledge, the submission description after precision processing, the code to be reviewed, and the third prompt word composed of the review code are input into the intelligent agent of the code development expert responsibility pre-defined based on the large model. The intelligent agent of the code development expert responsibility modifies the code to be reviewed based on the third prompt word, thereby obtaining the modified code. In this way, the automatic review and optimization of the code to be reviewed is realized, which greatly saves the labor cost and improves the efficiency of code review and optimization.
[0226] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0227] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0228] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0229] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0230] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A code review method, characterized in that: include: Obtaining the code to be reviewed, the submission description corresponding to the code to be reviewed, and the target knowledge system category to which the code to be reviewed belongs; wherein the submission description includes at least one of a business-related document and a project description document; According to the target knowledge system category, relevant background knowledge with a matching degree greater than a preset threshold with the code to be reviewed is obtained from the local knowledge base; Inputting a first prompt word composed of the relevant background knowledge and the submitted description into an intelligent agent with a business understanding expert role predefined based on a large model, the intelligent agent with the business understanding expert role performs precision processing on the submitted description based on the first prompt word to obtain a submitted description after precision processing, wherein the matching degree between the submitted description after precision processing and the relevant background knowledge is greater than the matching degree between the submitted description before precision processing and the relevant background knowledge; The relevant background knowledge, the submission description after precision processing, and the second prompt word composed of the code to be reviewed are input into an intelligent agent with code review expert responsibilities predefined based on the big model, and the intelligent agent with code review expert responsibilities performs a basic review on the code to be reviewed based on the second prompt word to obtain review suggestions; The relevant background knowledge, the submission description after precision processing, the code to be reviewed, and the third prompt word composed of the review suggestion are input into an agent with the responsibility of code development expert predefined based on the big model, and the agent with the responsibility of code development expert modifies the code to be reviewed based on the third prompt word to obtain the modified code; Input the relevant background knowledge, the submission description after precision processing and the fourth prompt word composed of the modified code into an agent with code testing expert responsibilities predefined based on the big model to obtain a test plan for testing the modified code; Building a test environment corresponding to the test scheme, and using a preset tool set to test the modified code to obtain test results; Determine whether the test results meet the expected requirements; If not, feedback is given to the intelligent agent with the role of code development expert, and the intelligent agent with the role of code development expert modifies the modified code until the corresponding test result meets the expected requirements; If yes, the modified code is used as the preliminary qualified code; The preliminary qualified code and the relevant background knowledge are sent to at least one intelligent agent adjusted and optimized based on user needs predefined in the large model, and the preliminary qualified code is optimized respectively to obtain optimized code.
2. The method according to claim 1, characterized in that If the at least one agent adjusted and optimized based on the user requirements predefined in the large model includes an agent of a code performance optimization expert, an agent of a code resource optimization expert, and an agent of a code security performance optimization expert, the preliminary qualified code is optimized respectively to obtain an optimized code, including: Optimizing the preliminary qualified code by the intelligent agent of the code performance optimization expert to obtain a first optimization result; Optimizing the preliminary qualified code by the intelligent agent of the code resource optimization expert to obtain a second optimization result; Optimizing the preliminary qualified code by the agent of the code security performance optimization expert to obtain a third optimization result; The relevant background knowledge, the first optimization result, the second optimization result, the third optimization result and a fifth prompt word consisting of a preset decision weight are input into an intelligent agent with the highest decision-maker responsibility predefined based on the big model to obtain a code after the decision.
3. The method according to claim 2, characterized in that After obtaining the code after the decision, the method further includes: Scan and detect the code after the decision is made to obtain a detection result; Determine whether the test results meet the expected requirements; If not, the information is fed back to the agent with the role of code development expert, and the agent with the role of code development expert modifies the modified code until the corresponding detection result meets the expected requirements; If yes, the code after decision is used as the optimal code of the code to be reviewed.
4. A code review device, characterized in that: include: A first acquisition unit is used to acquire the code to be reviewed, the submission description corresponding to the code to be reviewed, and the target knowledge system category to which the code to be reviewed belongs; wherein the submission description includes at least one of a business-related document and a project description document; A second acquisition unit is used to acquire, from a local knowledge base, relevant background knowledge whose matching degree with the code to be reviewed is greater than a preset threshold according to the major category of the target knowledge system; A precision processing unit, configured to input the first prompt word composed of the relevant background knowledge and the submitted description into an intelligent agent having the business understanding expert responsibilities predefined based on the large model, perform precision processing on the submitted description, and obtain a submitted description after precision processing; A basic review unit, configured to input the relevant background knowledge, the submission description after precision processing, and the second prompt word composed of the code to be reviewed into an intelligent agent based on the code review expert responsibilities predefined in the big model, conduct a basic review on the code to be reviewed, and obtain review suggestions; A modification unit, configured to input the relevant background knowledge, the submission description after precision processing, the code to be reviewed, and a third prompt word consisting of the review suggestion into an intelligent agent with code development expert responsibilities predefined based on the large model, modify the code to be reviewed, and obtain a modified code; The testing unit is used to input the relevant background knowledge, the submission description after precision processing, and the fourth prompt word composed of the modified code into an intelligent agent with code testing expert responsibilities predefined based on the large model, to obtain a test plan for testing the modified code; build a test environment corresponding to the test plan, and use a pre-set tool set to test the modified code to obtain a test result; A judging unit, used to judge whether the test result meets the expected requirements; if not, the result is fed back to the intelligent agent with the role of code development expert, and the intelligent agent with the role of code development expert modifies the modified code until the corresponding test result meets the expected requirements; if yes, the modified code is used as the preliminary qualified code; The preliminary qualified code and the relevant background knowledge are sent to at least one intelligent agent adjusted and optimized based on user needs predefined in the large model, and the preliminary qualified code is optimized respectively to obtain optimized code.
5. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to implement the method steps as described in any one of claims 1 to 3 when executing the computer program stored in the memory.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is used to enable a computer to execute the method steps according to any one of claims 1 to 3.
7. A computer program product, characterized in that The computer program product comprises: a computer program code, and when the computer program code is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Code quality control method and device based on large language model
CN117992069A
Code review method and device, equipment and storage medium
CN118860888A
Code generation method, device and equipment based on multi-agent language system
CN119065650A