Code review method and device, electronic equipment, storage medium and program product

By generating code summary and similarity search in the knowledge base, code review is automated, and the problems of high time and resource consumption and subjectivity of results caused by manual review are solved, and efficient and objective code review is achieved.

CN119645476APending Publication Date: 2025-03-18DOUYIN VISION CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311198190.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-15
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

Among the existing code review methods, due to the reliance on manual review, there are problems such as long time consumption, more resource consumption, and strong subjectivity of the review results.

Method used

By determining the object code to be reviewed, generating its code summary, and performing a similarity search in the knowledge base, obtaining the knowledge base context, and ultimately generating the code review results based on the object code and the knowledge base context.

Benefits of technology

It realizes the automation of code review, reduces time and resource consumption, and improves the objectivity of review results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119645476A_ABST
    Figure CN119645476A_ABST
Patent Text Reader

Abstract

The invention provides a code review method and device, electronic equipment, a storage medium and a program product. The method comprises the steps that a to-be-reviewed target code is determined; obtaining a code abstract of the target code based on the target code; determining a knowledge base, and performing similarity search based on the code abstract and the knowledge base to obtain a knowledge base context; and obtaining a code review result based on the target code and the knowledge base context. According to the method and the device, the automation of code review can be realized, the time consumption is relatively short, the resource consumption is relatively low, and the objectivity of the review result is relatively high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of electronic computers and Internet technology, and in particular to a code review method, device, electronic device, storage medium and program product. Background Art

[0002] This section is intended to provide a background or context to the embodiments of the disclosure that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.

[0003] Code review refers to a systematic review of computer source code, with the aim of finding and correcting errors that were not discovered during the software development process and improving software quality.

[0004] Code review is usually conducted through peer review, which refers to a method in which the code author's peers, such as technical experts, check the code written by the code author.

[0005] However, since peer review is conducted manually, it takes a long time and consumes a lot of resources, and the review results are highly subjective. Summary of the invention

[0006] In view of this, the purpose of the present disclosure is to propose a code review method, device, electronic device, storage medium and program product, which at least to a certain extent solve one of the technical problems in the related art.

[0007] Based on the above purpose, the first aspect of the exemplary embodiment of the present disclosure provides a code review method, including:

[0008] Identify the object code to be reviewed;

[0009] Based on the target code, obtaining a code summary of the target code;

[0010] Determine a knowledge base, perform a similarity search based on the code summary and the knowledge base, and obtain a knowledge base context;

[0011] A code review result is obtained based on the target code and the knowledge base context.

[0012] Based on the same inventive concept, the second aspect of the exemplary embodiment of the present disclosure provides a code review device, including:

[0013] an object code determination module, configured to determine an object code to be examined;

[0014] A code summary determination module is configured to obtain a code summary of the target code based on the target code;

[0015] A knowledge base context determination module is configured to determine a knowledge base, perform a similarity search based on the code summary and the knowledge base, and obtain a knowledge base context;

[0016] The code review result determination module is configured to obtain a code review result based on the target code and the knowledge base context.

[0017] Based on the same inventive concept, a third aspect of the exemplary embodiment of the present disclosure provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method described in the first aspect is implemented.

[0018] Based on the same inventive concept, a fourth aspect of the exemplary embodiments of the present disclosure provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method described in the first aspect.

[0019] Based on the same inventive concept, a fifth aspect of the exemplary embodiments of the present disclosure provides a computer program product, including computer program instructions. When the computer program instructions are executed on a computer, the computer executes the method described in the first aspect.

[0020] From the above, it can be seen that the code review method, device, electronic device, storage medium and program product provided by the embodiment of the present disclosure include: determining the target code to be reviewed; based on the target code, obtaining the code summary of the target code; determining the knowledge base, performing similarity search based on the code summary and the knowledge base to obtain the knowledge base context; based on the target code and the knowledge base context, obtaining the code review result. Through the present disclosure, the automation of code review can be achieved, with shorter time consumption, lower resource consumption, and more objectivity of the review result. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the present disclosure or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0022] Figure 1 A schematic diagram of an application scenario of a peer review method provided by an exemplary embodiment of the present disclosure;

[0023] Figure 2 A schematic diagram of an application scenario of a code review method provided by an exemplary embodiment of the present disclosure;

[0024] Figure 3 A flowchart of a code review method provided for an exemplary embodiment of the present disclosure;

[0025] Figure 4 A schematic diagram of a flow chart of a knowledge base context determination method provided for an exemplary embodiment of the present disclosure;

[0026] Figure 5 Another flowchart of a knowledge base context determination method provided for an exemplary embodiment of the present disclosure;

[0027] Figure 6 A schematic diagram of a code review result provided for an exemplary embodiment of the present disclosure;

[0028] Figure 7 Another flowchart of a code review method provided for an exemplary embodiment of the present disclosure;

[0029] Figure 8 Another flowchart of a code review method provided for an exemplary embodiment of the present disclosure;

[0030] Fig. 9 A schematic diagram of a structure of a code review device provided for an exemplary embodiment of the present disclosure;

[0031] Fig.10 A schematic structural diagram of an electronic device provided by an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0032] It is understandable that before using the technical solutions disclosed in the embodiments of this application, the type, scope of use, usage scenarios, etc. of the personal information involved in this application should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0033] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present application according to the prompt message.

[0034] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0035] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation method of the present application. Other methods that meet the relevant laws and regulations may also be applied to the implementation method of the present application.

[0036] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.

[0037] In order to make the purpose, technical solutions and advantages of the present disclosure more clear, the principles and spirit of the present disclosure will be described with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present disclosure, and are not intended to limit the scope of the present disclosure in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0038] It should be understood herein that any number of elements in the drawings is for illustration rather than limitation, and any naming is only for distinction rather than having any limiting meaning.

[0039] The principle and spirit of the present disclosure are explained in detail below with reference to several representative embodiments of the present disclosure.

[0040] As described in the background art, code review refers to a systematic review of computer source code, the purpose of which is to find and modify errors that are not discovered during the software development process and improve software quality.

[0041] In the related art, code review is usually performed in the form of peer review, wherein peer review refers to a method in which the code author's peers, such as technical experts, check the code written by the code author.

[0042] refer to Figure 1 , as a specific example of a peer review method, in which the code author first sends the code to be reviewed to the reviewer; the reviewer reviews the code to be reviewed, obtains the code review result, and sends the code review result to the code author; the code author modifies the code based on the code review result, obtains the modified code, and sends the modified code to the reviewer; the reviewer reviews the modified code again, if the modified code passes the review, the code that passes the review is obtained, if there are still problems in the modified code that fails to pass the review, the code review result is sent to the code author again, and the code author modifies the code based on the code review result again, and the cycle repeats until the code passes the review.

[0043] The inventors of the present disclosure have found that peer review is conducted manually, which results in a long time consumption, high resource consumption, and a high degree of subjectivity in the review results. Specifically:

[0044] Time-consuming: Code review can be time-consuming, especially when dealing with large code bases or complex changes. Reviewers need to spend time and energy to carefully review the code, which may affect the overall development speed and project progress.

[0045] Resource consumption: Code review requires the participation of multiple team members, including the author and the reviewer. This can be a burden on team resources, especially in large teams or organizations with limited staff.

[0046] Review results are subjective: Reviewers may have personal biases or preferences that may influence their feedback. This bias may lead to inconsistencies in the review process and may affect the objectivity of the feedback provided.

[0047] In order to solve the above problems, the present disclosure provides a code review solution, which specifically includes: determining the target code to be reviewed; based on the target code, obtaining the code summary of the target code; determining a knowledge base, performing similarity search based on the code summary and the knowledge base, and obtaining the knowledge base context; based on the target code and the knowledge base context, obtaining the code review result. Through the present disclosure, the automation of code review can be realized, with shorter time consumption, lower resource consumption, and stronger objectivity of the review result.

[0048] After introducing the basic principles of the present disclosure, various non-limiting embodiments of the present disclosure are described in detail below.

[0049] refer to Figure 2 , which is a schematic diagram of an application scenario of the code review method provided by the exemplary embodiment of the present disclosure.

[0050] This application scenario includes a local terminal device 210 and a server 220. The local terminal device 210 and the server 220 may be connected via a wired or wireless communication network to achieve data interaction.

[0051] The local terminal device 210 may be an electronic device with data transmission and multimedia input / output functions close to the user side, such as a desktop computer, a mobile phone, a mobile computer, a tablet computer, a media player, a car computer, a smart wearable device, a personal digital assistant (PDA) or other electronic devices capable of implementing the above functions. The electronic device may include a processor and a display screen with a touch input function, the display screen is used to present a graphical user interface, the graphical user interface may display a code review interface, and the processor is used to process code review data, generate a graphical user interface, and control the display of the graphical user interface on the display screen.

[0052] Server 220 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), as well as big data and artificial intelligence platforms.

[0053] The code review method may be executed on the local terminal device 210 or the server 220 .

[0054] When the code review method is run on the server 220, the server 220 is used to provide code review services to users of terminal devices. The terminal device is installed with a client that communicates with the server 220. The user can enter at least one section of code to be reviewed or at least one URL (Uniform Resource Locator) through the client. After clicking the review button, if the user enters the code to be reviewed, the client uses the code to be reviewed as the target code; if the user enters the URL, the source code of the webpage is first obtained, and then the source code of the webpage is used as the target code, wherein the source code of the webpage includes the source code of the webpage itself and / or the source code stored in the webpage. The client sends the target code to the server 220.

[0055] The server 220 determines the target code to be reviewed; based on the target code, obtains a code summary of the target code; determines a knowledge base, performs a similarity search based on the code summary and the knowledge base, and obtains a knowledge base context; based on the target code and the knowledge base context, obtains a code review result. The server 220 can also send the code review result to the client, and the client displays the code review result to the user to help the user modify the target code. The terminal device can be the local terminal device 210 mentioned above.

[0056] In the above embodiment, the code review method is described by taking the code review method running on the server 220 as an example, but the present disclosure is not limited thereto. In some exemplary embodiments, the code review method may also be run on the local terminal device 210 .

[0057] The local terminal device 210 may include a display screen and a processor. The local terminal device 210 is installed with a client, and the user can input at least one code to be reviewed or at least one URL (Uniform Resource Locator) through the client. After clicking the review button, if the user inputs the code to be reviewed, the client uses the code to be reviewed as the target code; if the user inputs the URL, the source code of the webpage is first obtained, and then the source code of the webpage is used as the target code, wherein the source code of the webpage includes the source code of the webpage itself and / or the source code stored in the webpage. The client sends the target code to the processor.

[0058] The processor determines the target code to be reviewed; based on the target code, obtains a code summary of the target code; determines a knowledge base, performs a similarity search based on the code summary and the knowledge base to obtain a knowledge base context; and obtains a code review result based on the target code and the knowledge base context. The processor can also send the code review result to the client, and the client displays the code review result to the user through a display screen to help the user modify the target code.

[0059] Combine the following Figure 2 The code review method according to the exemplary embodiment of the present disclosure is described by using the application scenario. It should be noted that the above application scenario is only shown to facilitate understanding of the spirit and principle of the present disclosure, and the implementation of the present disclosure is not limited in this respect. On the contrary, the implementation of the present disclosure can be applied to any applicable scenario.

[0060] refer to Figure 3 , which is a flowchart of a code review method provided by an exemplary embodiment of the present disclosure.

[0061] The code review method includes the following steps:

[0062] Step S310: Determine the target code to be reviewed.

[0063] In this exemplary embodiment, the method for determining the target code to be examined includes:

[0064] The terminal device used by the user has a client installed. The user can input at least one code to be reviewed or at least one URL (Uniform Resource Locator) through the client. After clicking the review button, if the user inputs the code to be reviewed, the client uses the code to be reviewed as the target code; if the user inputs the URL, the source code of the webpage is first obtained, and then the source code of the webpage is used as the target code. The source code of the webpage includes the source code of the webpage itself and / or the source code stored in the webpage.

[0065] In specific implementation, the data form of the target code to be reviewed may include:

[0066] Source code, diff, path, etc.

[0067] Step S320: Based on the target code, obtain a code summary of the target code.

[0068] In this exemplary embodiment, the code summary of the target code refers to a natural statement that describes the function of the target code. The code summary can concisely describe the function of the code and has strong readability.

[0069] In this exemplary embodiment, the method for determining the code summary of the target code includes:

[0070] Determine the code review model;

[0071] Inputting the target code into the code review model to obtain the code summary output by the code review model;

[0072] The code review model is constructed based on a large language model framework.

[0073] In specific implementation, a large language model (LLM) refers to a deep learning model trained with a large amount of text data, which can generate natural language text or understand the meaning of language text. It can learn the grammar and semantics of natural language, so that it can generate human-readable text and can handle various natural language processing tasks, such as natural language generation, text classification, text summarization, machine translation, speech recognition, etc.

[0074] As a specific example, suppose that for a target code, the code summary of the target code output by the code review model is: the code mainly does the following things: update code logic, update package version number, update idl version number, update jsbauth, update byte_io, update tscheck, compatibility, unit test fix, search_id, bam, extract logmodel, README, unit test fix, test, search_id, remove ts-nocheck, search results page icon, remove console.log, chore:conflics, chore:talent_h5, chore:image and other tasks, and at the same time, it does code logic update, compatibility testing, unit test fix and other things.

[0075] Step S330: determine a knowledge base, perform a similarity search based on the code summary and the knowledge base, and obtain a knowledge base context.

[0076] In this exemplary embodiment, the knowledge base includes a first knowledge base and a second knowledge base;

[0077] The first knowledge base is a default knowledge base, and the second knowledge base is a user-specified knowledge base.

[0078] In specific implementation, the first knowledge base, i.e., the default knowledge base, is the knowledge base built into the code review model, i.e., the large language model. The present disclosure takes into account that in the process of code review, professional knowledge not included in the knowledge base built into the code review model, i.e., the large language model, may be involved. Therefore, a user-specified knowledge base, i.e., a custom knowledge base, is also provided to supplement professional knowledge and improve the accuracy of code review.

[0079] During specific implementation, the knowledge base includes best practices, coding standards, frequently asked questions, etc., which are used to guide code reviews and provide relevant suggestions.

[0080] In specific implementation, the data form of the knowledge in the first knowledge base may include:

[0081] React, ts official documentation, etc.

[0082] In specific implementation, the data form of the knowledge in the second knowledge base may include:

[0083] Documentation, etc.

[0084] refer to Figure 4 ,The knowledge base context determination method includes the following steps:

[0085] Step S410: Encode the code summary to obtain a code summary vector.

[0086] In this exemplary embodiment, the method of encoding the code summary includes:

[0087] The code summary is embedded in the code.

[0088] In practice, in natural language processing tasks, a sentence can be represented as a vector composed of word embeddings. By calculating and comparing these vectors, information such as similarity and clustering can be extracted from the data. Embedding is a relatively low-dimensional space that can convert high-dimensional vectors into low-dimensional ones. Embedding makes it easier to implement machine learning on large inputs, such as sparse vectors representing words.

[0089] Step S420, determining a knowledge base text vector; wherein the knowledge base text vector is obtained based on the knowledge base processing.

[0090] In this exemplary embodiment, the knowledge base text vector is obtained based on the knowledge base processing, including:

[0091] Performing text segmentation on the knowledge base to obtain knowledge base text;

[0092] The knowledge base text is encoded to obtain the knowledge base text vector.

[0093] In this exemplary embodiment, the text segmentation method for the knowledge base includes at least two of the following:

[0094] Performing text segmentation on the knowledge base according to the rules;

[0095] or,

[0096] The knowledge base is subjected to text segmentation according to semantics.

[0097] In specific implementation, the knowledge base is segmented according to the rules, including:

[0098] Use rules to segment text based on common termination symbols of the code.

[0099] Such as: single-character sentence breakers, Chinese and English ellipsis, double quotes, etc.

[0100] In specific implementation, the knowledge base is segmented according to semantics, including:

[0101] Split text into semantically meaningful chunks (usually sentences).

[0102] Start combining these small chunks into a larger chunk until it reaches a certain size (measured by some function).

[0103] Once you've reached that size, set that block as its own text segment, then start creating a new text block with some overlap.

[0104] In this exemplary embodiment, the method of encoding the knowledge base text includes:

[0105] The knowledge base text is embedded in the encoding process.

[0106] In practice, in natural language processing tasks, a sentence can be represented as a vector composed of word embeddings. By calculating and comparing these vectors, information such as similarity and clustering can be extracted from the data. Embedding is a relatively low-dimensional space that can convert high-dimensional vectors into low-dimensional ones. Embedding makes it easier to implement machine learning on large inputs, such as sparse vectors representing words.

[0107] Step S430: Perform a similarity search on the code summary vector and the knowledge base text vector to obtain the knowledge base context.

[0108] In this exemplary embodiment, the method of performing similarity search on the code summary vector and the knowledge base text vector includes:

[0109] The semantic relationship between the code summary vector and the knowledge base text vector is detected to obtain the knowledge base text vector having similar features to the code summary vector.

[0110] In this exemplary embodiment, the knowledge base text vectors are stored in a vector database.

[0111] In a specific implementation, the text segmentation of the knowledge base to obtain the knowledge base text; encoding the knowledge base text to obtain the knowledge base text vector includes:

[0112] Performing text segmentation on the first knowledge base to obtain first knowledge base text;

[0113] Encoding the first knowledge base text to obtain a first knowledge base text vector;

[0114] The first knowledge base text vector is stored in a first vector database.

[0115] In this exemplary embodiment, the first vector database is constructed based on the Qdrant vector database framework.

[0116] In specific implementation, Qdrant is a vector similarity search engine and vector database. In the field of AI, vector databases are designed to more efficiently store and retrieve large-scale, high-dimensional vector data. Since traditional database systems are not good at processing vector data, specialized vector databases are needed to support the following application scenarios, such as semantic search, image retrieval, and recommendation systems. Unlike traditional databases, vector databases can use special index structures and similarity metrics to quickly find similar vectors in high-dimensional vector spaces.

[0117] As a concrete example, a memory-based Qdrant can be used directly in Python.

[0118] In this exemplary embodiment, the step of performing text segmentation on the knowledge base to obtain knowledge base text; and encoding the knowledge base text to obtain the knowledge base text vector includes:

[0119] Performing text segmentation on the second knowledge base to obtain a second knowledge base text;

[0120] Encoding the second knowledge base text to obtain a second knowledge base text vector;

[0121] The second knowledge base text vector is stored in a second vector database.

[0122] In this exemplary embodiment, the second vector database is constructed based on the Faiss vector database framework.

[0123] During specific implementation, the second vector database is in the local memory (CL).

[0124] In specific implementation, Faiss is an open source vector database, which is an efficient similarity retrieval and clustering engine for dense vectors. It supports not only CPU but also GPU. Faiss includes similarity vector query function, and the methods for measuring vector similarity are: L2 Euclidean distance, inner product, and cosine similarity. Storing a vector in Faiss actually stores the vector in the index structure of Faiss.

[0125] The database system specifically used for storing, indexing and querying vectors provided in the above embodiments can enable large models to store and read knowledge bases more efficiently and perform model fine-tuning at a lower cost.

[0126] refer to Figure 5 , which is another flow chart of a knowledge base context determination method provided by an exemplary embodiment of the present disclosure.

[0127] Among them, during the specific implementation:

[0128] The target code to be reviewed is input into the code review model to obtain the code summary output by the code review model.

[0129] Encode the code summary to obtain a code summary vector.

[0130] Perform text segmentation on the default first knowledge base to obtain the first knowledge base text.

[0131] The first knowledge base text is encoded to obtain a first knowledge base text vector.

[0132] The text vectors of the first knowledge base are aggregated to obtain a first vector database.

[0133] Perform text segmentation on the second knowledge base specified by the user to obtain the second knowledge base text.

[0134] The second knowledge base text is encoded to obtain a second knowledge base text vector.

[0135] The second knowledge base text vectors are aggregated to obtain a second vector database.

[0136] The code summary vector, the first vector database and the second vector database are input into a similarity search function module, and similarity search processing is performed to obtain a knowledge base context output by the similarity search function module.

[0137] Step S340: Obtain code review results based on the target code and the knowledge base context.

[0138] In this exemplary embodiment, obtaining a code review result based on the target code and the knowledge base context includes:

[0139] splicing the target code and the knowledge base context to obtain a prompt word;

[0140] The prompt word is input into the code review model to obtain the code review result output by the code review model.

[0141] During specific implementation, the prompt word is input into the code review model, and the code review model performs reasoning based on the prompt word to obtain and output the code review result.

[0142] In this exemplary embodiment, the target code and the knowledge base context are concatenated to obtain a prompt word, including:

[0143] Determine a prompt word template corresponding to the code review model;

[0144] The target code and the knowledge base context are filled into the prompt word template to obtain the prompt word.

[0145] As a specific example, the prompt template is: Based on the known information above, answer the user's question concisely and professionally. If you cannot get an answer from it, please say "I cannot answer this question based on the known information" or "Not enough relevant information is provided". It is not allowed to add fabricated elements to the answer. The answer should be in Chinese.

[0146] In this exemplary embodiment, the code review result includes at least one of the following:

[0147] The code quality score of the target code and the problems and modification suggestions in the target code.

[0148] During specific implementation, the code review results may also include a code summary of the target code.

[0149] In specific implementation, the code review result can be sent to the client, and the client displays the code review result to the user to help the user modify the target code.

[0150] refer to Figure 6 , which is a schematic diagram of a code review result provided by an exemplary embodiment of the present disclosure.

[0151] Among them, during the specific implementation:

[0152] The code review results include the code quality score of the target code, the code summary of the target code, and the problems and modification suggestions in the target code.

[0153] like Figure 6 As shown, the code quality score of the target code is: 9.5 points;

[0154] The code summary of the target code is: This code mainly does the following things: update code logic, update package version number, update idl version number, update jsbauth, update byte_io, update tscheck, compatibility, single test fix, search_id, bam, extract logmodel, README, single test fix, test, search_id, remove ts-nocheck, search result page icon, remove console.log, chore:conflics, chore:talent_h5, chore:image and other tasks, and also does code logic update, compatibility test, single test fix and other things;

[0155] The problems and modification suggestions in the target code are as follows: 1. The code naming is not standardized, and some variables and method names do not match the definitions, and naming standards and comments are needed. Among them, "the code naming is not standardized, and some variables and method names do not match the definitions" is an existing problem, and "naming standards and comments are needed" is a modification suggestion for this problem.

[0156] refer to Figure 7 , which is another flowchart of the code review method provided by the exemplary embodiment of the present disclosure.

[0157] The code review method includes the following steps:

[0158] Step S710: Determine the target code to be reviewed.

[0159] In specific implementation, a client is installed in the terminal device used by the user, and the user can input at least one code to be reviewed or at least one URL (Uniform Resource Locator) through the client. After clicking the review button, if the user inputs the code to be reviewed, the client uses the code to be reviewed as the target code; if the user inputs the URL, the source code of the webpage is first obtained, and then the source code of the webpage is used as the target code. The source code of the webpage includes the source code of the webpage itself and / or the source code stored in the webpage.

[0160] In specific implementation, the data form of the target code to be reviewed may include:

[0161] Source code, diff, path, etc.

[0162] Step S720, determine a code review model, input the target code into the code review model, obtain the code summary output by the code review model, encode the code summary, and obtain a code summary vector, wherein the code review model is constructed based on a large language model framework.

[0163] In specific implementation, the code summary of the target code refers to a natural statement that describes the function of the target code. The code summary can concisely describe the function of the code and has strong readability.

[0164] In specific implementation, a large language model (LLM) refers to a deep learning model trained with a large amount of text data, which can generate natural language text or understand the meaning of language text. It can learn the grammar and semantics of natural language, so that it can generate human-readable text and can handle various natural language processing tasks, such as natural language generation, text classification, text summarization, machine translation, speech recognition, etc.

[0165] In the specific implementation, the code summary is embedded. In natural language processing tasks, a sentence can be represented as a vector composed of word embeddings. By calculating and comparing these vectors, information such as similarity and clustering can be extracted from the data. Embedding is a relatively low-dimensional space that can convert high-dimensional vectors into low dimensions. Embedding makes it easier to implement machine learning on large inputs, such as sparse vectors representing words.

[0166] Step S730, determine a first knowledge base, perform text segmentation on the first knowledge base to obtain the first knowledge base text, encode the first knowledge base text to obtain the knowledge base text vector, and store the first knowledge base text vector in a first vector database, wherein the first knowledge base is a default knowledge base.

[0167] During specific implementation, the first knowledge base, i.e., the default knowledge base, is the knowledge base built into the code review model, i.e., the large language model.

[0168] In specific implementation, the first knowledge base includes best practices, coding standards, frequently asked questions, etc., which are used to guide code reviews and provide relevant suggestions.

[0169] In specific implementation, the data form of the knowledge in the first knowledge base may include:

[0170] React, ts official documentation, etc.

[0171] In the specific implementation, the first knowledge base text is embedded. In natural language processing tasks, a sentence can be represented as a vector composed of word embeddings. By calculating and comparing these vectors, information such as similarity and clustering can be extracted from the data. Embedding is a relatively low-dimensional space that can convert high-dimensional vectors into low dimensions. Embedding makes it easier to implement machine learning on large inputs, such as sparse vectors representing words.

[0172] In the specific implementation, the first vector database is built based on the Qdrant vector database framework. Qdrant is a vector similarity search engine and vector database. In the field of AI, vector databases are designed to more efficiently store and retrieve large-scale, high-dimensional vector data. Since traditional database systems are not good at processing vector data, specialized vector databases are needed to support the following application scenarios, such as semantic search, image retrieval, and recommendation systems. Unlike traditional databases, vector databases can use special index structures and similarity metrics to quickly find similar vectors in high-dimensional vector spaces.

[0173] Step S740, determine a second knowledge base, perform text segmentation on the second knowledge base to obtain the second knowledge base text, encode the second knowledge base text to obtain the knowledge base text vector, and store the second knowledge base text vector in a second vector database, wherein the second knowledge base is a knowledge base specified by the user.

[0174] During the specific implementation, considering that the code review process may involve professional knowledge that is not available in the knowledge base built into the code review model, i.e., the large language model, a user-specified knowledge base, i.e., a custom knowledge base, is also provided to supplement professional knowledge and improve the accuracy of code review.

[0175] In specific implementation, the second knowledge base includes best practices, coding standards, frequently asked questions, etc., which are used to guide code reviews and provide relevant suggestions.

[0176] In specific implementation, the data form of the knowledge in the second knowledge base may include:

[0177] Documentation, etc.

[0178] In the specific implementation, the second knowledge base text is embedded. In natural language processing tasks, a sentence can be represented as a vector composed of word embeddings. By calculating and comparing these vectors, information such as similarity and clustering can be extracted from the data. Embedding is a relatively low-dimensional space that can convert high-dimensional vectors into low dimensions. Embedding makes it easier to implement machine learning on large inputs, such as sparse vectors representing words.

[0179] In the specific implementation, the second vector database is constructed based on the Faiss vector database framework. Faiss is an open source vector database, which is an efficient similarity retrieval and clustering engine for dense vectors. It supports not only CPU but also GPU. Faiss includes similarity vector query function, and the methods for measuring vector similarity are: L2 Euclidean distance, inner product, and cosine similarity. Storing a vector in faiss is actually storing the vector in the index structure of faiss.

[0180] During specific implementation, the second vector database is in the local memory (CL).

[0181] Step S750: Perform a similarity search based on the code summary vector, the first vector database, and the second vector database to obtain a knowledge base context.

[0182] In a specific implementation, the semantic relationship between the code summary vector and the knowledge base text vector is detected to obtain the knowledge base text vector having similar features to the code summary vector.

[0183] Step S760: splice the target code and the knowledge base context to obtain prompt words, input the prompt words into the code review model, and obtain the code review result output by the code review model.

[0184] During specific implementation, determining a prompt word template corresponding to the code review model;

[0185] The target code and the knowledge base context are filled into the prompt word template to obtain the prompt word.

[0186] In specific implementation, the code review results include at least one of the following:

[0187] The code quality score of the target code and the problems and modification suggestions in the target code.

[0188] During specific implementation, the code review results may also include a code summary of the target code.

[0189] refer to Figure 8 , which is another flowchart of the code review method provided by the exemplary embodiment of the present disclosure.

[0190] Among them, during the specific implementation:

[0191] Receive the target code to be reviewed input by the user.

[0192] The target code to be reviewed is input into the code review model to obtain a code summary output by the code review model; wherein, in order to perform similarity search, the code summary needs to be encoded and vectorized to obtain a code summary vector.

[0193] The default first knowledge base is processed offline to obtain a first vector database; wherein the offline processing includes: performing text segmentation on the default first knowledge base to obtain a first knowledge base text; encoding the first knowledge base text to obtain a first knowledge base text vector; and summarizing the first knowledge base text vector to obtain a first vector database.

[0194] Offline processing is performed on the second knowledge base specified by the user to obtain a second vector database; wherein the offline processing includes: text segmentation of the second knowledge base specified by the user to obtain second knowledge base text; encoding the second knowledge base text to obtain second knowledge base text vectors; and summarizing the second knowledge base text vectors to obtain a second vector database.

[0195] The code summary vector, the first vector database and the second vector database are input into a similarity search function module, and similarity search processing is performed to obtain a knowledge base context output by the similarity search function module.

[0196] The knowledge base context and the target code to be reviewed are input into the prompt word generation function module to obtain the prompt word.

[0197] The prompt words are input into the code review model to obtain the code review results output by the code review model.

[0198] Output code review results to users.

[0199] From the above description, it can be seen that the code review method provided by the embodiment of the present disclosure includes: determining the target code to be reviewed; based on the target code, obtaining the code summary of the target code; determining the knowledge base, performing similarity search based on the code summary and the knowledge base, and obtaining the knowledge base context; based on the target code and the knowledge base context, obtaining the code review result. Through the present disclosure, the automation of code review can be achieved, with shorter time consumption, lower resource consumption, and stronger objectivity of the review result.

[0200] Furthermore, the present disclosure can also provide targeted suggestions and repair solutions to help developers solve problems and improve the standardization of development.

[0201] It should be noted that the method of the embodiment of the present disclosure can be performed by a single device, such as a computer or a server. The method of the present embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present disclosure, and the multiple devices will interact with each other to complete the described method.

[0202] It should be noted that the above describes some embodiments of the present disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0203] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a code review device.

[0204] refer to Fig. 9 , which is a structural diagram of a code review device provided by an exemplary embodiment of the present disclosure.

[0205] The code review device includes the following modules:

[0206] The target code determination module 910 is configured to determine the target code to be reviewed;

[0207] A code summary determination module 920 is configured to obtain a code summary of the target code based on the target code;

[0208] The knowledge base context determination module 930 is configured to determine a knowledge base, perform a similarity search based on the code summary and the knowledge base, and obtain a knowledge base context;

[0209] The code review result determination module 940 is configured to obtain a code review result based on the target code and the knowledge base context.

[0210] In some exemplary embodiments, the code summary determination module 920 is configured to:

[0211] Determine the code review model;

[0212] Inputting the target code into the code review model to obtain the code summary output by the code review model;

[0213] The code review model is constructed based on a large language model framework.

[0214] In some exemplary embodiments, the code review result determination module 940 is configured to:

[0215] splicing the target code and the knowledge base context to obtain a prompt word;

[0216] The prompt word is input into the code review model to obtain the code review result output by the code review model.

[0217] In some exemplary embodiments, the code review result determination module 940 is configured to:

[0218] Determine a prompt word template corresponding to the code review model;

[0219] The target code and the knowledge base context are filled into the prompt word template to obtain the prompt word.

[0220] In some exemplary embodiments, the knowledge base includes a first knowledge base and a second knowledge base;

[0221] The first knowledge base is a default knowledge base, and the second knowledge base is a user-specified knowledge base.

[0222] In some exemplary embodiments, the knowledge base context determination module 930 is configured to:

[0223] Encoding the code summary to obtain a code summary vector;

[0224] Determine a knowledge base text vector; wherein the knowledge base text vector is obtained based on the knowledge base processing;

[0225] A similarity search is performed on the code summary vector and the knowledge base text vector to obtain the knowledge base context.

[0226] In some exemplary embodiments, the knowledge base context determination module 930 is configured to:

[0227] Performing text segmentation on the knowledge base to obtain knowledge base text;

[0228] The knowledge base text is encoded to obtain the knowledge base text vector.

[0229] In some exemplary embodiments, the knowledge base text vectors are stored in a vector database.

[0230] For the convenience of description, the above device is described by dividing it into various modules according to its functions. Of course, when implementing the present disclosure, the functions of each module can be implemented in the same or multiple software and / or hardware.

[0231] The device of the above embodiment is used to implement the corresponding code review method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.

[0232] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, the present disclosure also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the code review method described in any of the above embodiments is implemented.

[0233] Fig.10 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.

[0234] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0235] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.

[0236] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.

[0237] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).

[0238] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).

[0239] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0240] The electronic device of the above embodiment is used to implement the corresponding code review method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.

[0241] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the code review method described in any of the above embodiments.

[0242] The above-mentioned non-transitory computer-readable storage medium can be any available medium or data storage device that can be accessed by a computer, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)), etc.

[0243] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the code review method described in any embodiment in the above exemplary method part, and have the beneficial effects of the corresponding method embodiment, which will not be repeated here.

[0244] Based on the same inventive concept, corresponding to the code review method described in any of the above embodiments, the present disclosure also provides a computer program product, which includes computer program instructions. In some embodiments, the computer program instructions can be executed by one or more processors of a computer so that the computer and / or the processor executes the code review method. Corresponding to the execution subject corresponding to each step in each embodiment of the code review method, the processor that executes the corresponding step may belong to the corresponding execution subject.

[0245] The computer program product of the above embodiment is used to enable the computer and / or the processor to execute the code review method described in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0246] Those skilled in the art will appreciate that the embodiments of the present disclosure may be implemented as a system, method, or computer program product. Therefore, the present disclosure may be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software, generally referred to herein as a "circuit," "module," or "system." In addition, in some embodiments, the present disclosure may also be implemented in the form of a computer program product in one or more computer-readable media, which contains computer-readable program code.

[0247] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive examples) of computer-readable storage media may include, for example: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device.

[0248] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0249] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0250] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0251] It should be understood that each box in the flowchart and / or block diagram and the combination of boxes 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 or other programmable data processing device to produce a machine, and these computer program instructions are executed by a computer or other programmable data processing device to produce a device that implements the functions / operations specified in the boxes in the flowchart and / or block diagram.

[0252] These computer program instructions may also be stored in a computer-readable medium that enables a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable medium produce a product that includes an instruction device that implements the functions / operations specified in the blocks in the flowchart and / or block diagram.

[0253] Computer program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby enabling the instructions executed on the computer or other programmable device to provide a process for implementing the functions / operations specified in the blocks in the flowchart and / or block diagram.

[0254] In addition, although the operations of the disclosed method are described in a particular order in the accompanying drawings, this does not require or imply that the operations must be performed in this particular order, or that all the operations shown must be performed to achieve the desired results. On the contrary, the steps depicted in the flow chart can be performed in a different order. Additionally or alternatively, some steps can be omitted, multiple steps can be combined into one step, and / or one step can be decomposed into multiple steps.

[0255] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the embodiments of the present disclosure do not represent any order, quantity or importance, but are only used to distinguish different components. "Including" or "comprising" and similar words mean that the elements or objects appearing in front of the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connecting" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly. The article "one" or "a" before an element does not exclude the existence of multiple such elements.

[0256] Although the spirit and principle of the present disclosure have been described with reference to several specific embodiments, it should be understood that the present disclosure is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and such division is only for the convenience of expression. The present disclosure is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the attached claims. The scope of the attached claims conforms to the broadest interpretation, thereby including all such modifications and equivalent structures and functions.

Claims

1. A code review method, characterized in that: include: Identify the object code to be reviewed; Based on the target code, obtaining a code summary of the target code; Determine a knowledge base, perform a similarity search based on the code summary and the knowledge base, and obtain a knowledge base context; A code review result is obtained based on the target code and the knowledge base context.

2. The method according to claim 1, characterized in that The step of obtaining a code summary of the target code based on the target code comprises: Determine the code review model; Inputting the target code into the code review model to obtain the code summary output by the code review model; The code review model is constructed based on a large language model framework.

3. The method according to claim 2, characterized in that The obtaining of code review results based on the target code and the knowledge base context includes: splicing the target code and the knowledge base context to obtain a prompt word; The prompt word is input into the code review model to obtain the code review result output by the code review model.

4. The method according to claim 3, characterized in that The target code and the knowledge base context are spliced ​​to obtain prompt words, including: Determine a prompt word template corresponding to the code review model; The target code and the knowledge base context are filled into the prompt word template to obtain the prompt word.

5. The method according to claim 1, characterized in that The knowledge base includes a first knowledge base and a second knowledge base; The first knowledge base is a default knowledge base, and the second knowledge base is a user-specified knowledge base.

6. The method according to claim 1, characterized in that The performing similarity search based on the code summary and the knowledge base to obtain the knowledge base context includes: Encoding the code summary to obtain a code summary vector; Determine a knowledge base text vector; wherein the knowledge base text vector is obtained based on the knowledge base processing; A similarity search is performed on the code summary vector and the knowledge base text vector to obtain the knowledge base context.

7. The method according to claim 6, characterized in that The knowledge base text vector is obtained based on the knowledge base processing, including: Performing text segmentation on the knowledge base to obtain knowledge base text; The knowledge base text is encoded to obtain the knowledge base text vector.

8. The method according to claim 6, characterized in that The knowledge base text vectors are stored in a vector database.

9. A code review device, characterized in that: include: an object code determination module, configured to determine an object code to be examined; A code summary determination module is configured to obtain a code summary of the target code based on the target code; A knowledge base context determination module is configured to determine a knowledge base, perform a similarity search based on the code summary and the knowledge base, and obtain a knowledge base context; The code review result determination module is configured to obtain a code review result based on the target code and the knowledge base context.

10. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method according to any one of claims 1 to 8 is implemented.

11. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to cause a computer to execute the method according to any one of claims 1 to 8.

12. A computer program product, characterized in that The method comprises computer program instructions, which, when executed on a computer, cause the computer to execute the method according to any one of claims 1 to 8.