Code review method and system based on local large language model
By conducting code reviews using a local large language model, building detection rules, and generating formatted reports, we address data security risks caused by cloud dependencies and ensure the security and quality of local code reviews.
Patent Information
- Application Number
- CN202510692831.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-27
- Publication Date
- 2025-09-05
AI Technical Summary
Current code review methods rely on large language models in the cloud, which carries the risk of code data leakage or loss due to cloud server crashes or attacks, reducing user data security.
Use local large language models for code review, build code detection rules and local large language models, perform code review directly on local devices, including code style, sensitive information and security vulnerability detection, generate text format reports and convert them into PDF or HTML format.
Without relying on cloud servers, it improves the security of user data, prevents code data leakage or loss, and improves code quality and reliability.
Smart Images

Figure CN120597282A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of code review, and in particular to a code review method and system based on a local large language model. Background Art
[0002] During the software development process, code review is a critical step in ensuring code quality, and its effectiveness directly impacts software reliability and maintainability. Current automated code review methods primarily rely on large language models. Leveraging their powerful natural language processing and code analysis capabilities, large language models integrate multiple functions, including code parsing, semantic understanding, problem review, and remediation suggestion generation. Furthermore, they automatically generate clearly structured and detailed review reports based on pre-set formatting requirements, providing developers with comprehensive and accurate feedback on code quality. However, most of the currently widely used large language models rely on cloud servers for operation. This operating mode requires users to upload their code data to the cloud servers for processing. If the cloud servers crash or are attacked, users' code data may be at risk of being leaked or lost, reducing user data security. Summary of the Invention
[0003] In response to the above-mentioned defects, the present invention proposes a code review method and system based on a local large language model, aiming to solve the problem that the current code review method mainly relies on a large language model, which requires users to upload the code to a cloud server for processing. Once the cloud server crashes or is attacked, there may be a risk of code leakage or loss, resulting in reduced user data security.
[0004] To achieve this object, the present invention adopts the following technical solutions:
[0005] A code review method based on a local large language model includes the following steps:
[0006] Step S1: Obtain the code file submitted by the user;
[0007] Step S2: Construct code detection rules, wherein the code detection rules include code style detection rules, sensitive information detection rules, and security vulnerability detection rules;
[0008] Step S3: Build a local large language model;
[0009] Step S4: Input the code file and code detection rules submitted by the user into the local large language model for code review, and output a code review report in text format;
[0010] Step S5: Convert the code review report in text format to obtain a code review report in PDF or HTML format.
[0011] Preferably, step S1 includes the following sub-steps: obtaining the code file submitted by the user through a local code hosting service platform built based on Git.
[0012] Preferably, in step S2, the code style detection rules include prohibiting the use of a mixture of pinyin and English when naming the code, prohibiting the direct use of Chinese, and uniformly naming the method names, parameter names, member variables and local variables of the code in lowerCamelCase format; the sensitive information detection rules include prohibiting the appearance of passwords and API key information in the code text; the security vulnerability detection rules include enforcing the use of security functions in the code text.
[0013] Preferably, in step S4, the following sub-steps are specifically included: step S41: parsing the code file submitted by the user to obtain a parsed code file; step S42: according to the code detection rules, comparing and analyzing each character in the parsed code file one by one to obtain the code review result; step S43: generating a code review report in text format based on the code review result.
[0014] Preferably, step S5 specifically includes the following sub-steps: using a Java library to convert the code review report in text format into a code review report in PDF or HTML format.
[0015] Another aspect of the present application provides a code review system based on a local large language model, the system comprising:
[0016] Acquisition module, used to obtain code files submitted by users;
[0017] The first building module is used to build code detection rules, wherein the code detection rules include code style detection rules, sensitive information detection rules, and security vulnerability detection rules;
[0018] The second building block is used to build a local large language model;
[0019] The code review module is used to input the code files and code detection rules submitted by users into the local large language model for code review and output the code review report in text format;
[0020] The format conversion module is used to convert the code review report in text format to obtain the code review report in PDF or HTML format.
[0021] Preferably, the acquisition module includes: an acquisition submodule, which is used to acquire the code files submitted by the user through a local code hosting service platform built based on Git.
[0022] Preferably, in the first building block, the code style detection rules include prohibiting the use of a mixture of pinyin and English when naming the code, prohibiting the direct use of Chinese for naming, and uniformly naming the code method names, parameter names, member variables and local variables in lowerCamelCase format; the sensitive information detection rules include prohibiting the appearance of passwords and API key information in the code text; the security vulnerability detection rules include enforcing the use of security functions in the code text.
[0023] Preferably, the code review module includes: a parsing submodule, which is used to parse the code file submitted by the user to obtain the parsed code file; a comparative analysis submodule, which is used to compare and analyze each character in the parsed code file one by one according to the code detection rules to obtain the code review result; and a generation submodule, which is used to generate a code review report in text format based on the code review result.
[0024] Preferably, the format conversion module includes: a format conversion submodule, which is used to convert the code review report in text format into the code review report in PDF or HTML format using a Java library.
[0025] The technical solutions provided by the embodiments of the present application may have the following beneficial effects:
[0026] This solution implements code file review by building code detection rules and a local large language model. The code files and code detection rules submitted by users are then fed into the local large language model for processing. Compared to traditional code review methods based on large language models, this solution uses a local large language model for code review. This model can perform code review directly on the local device without relying on cloud servers, effectively preventing the risk of code data being leaked or lost due to cloud server crashes or attacks, thereby improving user data security. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a flowchart of the steps of the code review method based on the local large language model. DETAILED DESCRIPTION
[0028] The embodiments of the present invention are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention and are not to be construed as limiting the present invention.
[0029] A code review method based on a local large language model includes the following steps:
[0030] Step S1: Obtain the code file submitted by the user;
[0031] Step S2: Construct code detection rules, wherein the code detection rules include code style detection rules, sensitive information detection rules, and security vulnerability detection rules;
[0032] Step S3: Build a local large language model;
[0033] Step S4: Input the code file and code detection rules submitted by the user into the local large language model for code review, and output a code review report in text format;
[0034] Step S5: Convert the code review report in text format to obtain a code review report in PDF or HTML format.
[0035] This solution uses a code review method based on a local large language model, such as Figure 1 As shown, the first step is to obtain the code files submitted by the user. In this embodiment, obtaining the user-submitted code files facilitates subsequent code analysis and review. The second step is to construct code detection rules, which include code style detection rules, sensitive information detection rules, and security vulnerability detection rules. In this embodiment, constructing code detection rules provides a clear basis and standard for subsequent code review. The third step is to construct a local large language model. In this embodiment, a local large language model refers to a large language model deployed on local devices, such as personal computers, servers, and mobile devices. It can run directly locally without relying on cloud servers and provide users with natural language processing-related services. By constructing a local large language model, code reviews can be conducted on local devices, reducing dependence on external services and thus improving the security of user data. The fourth step is to input the user-submitted code files and code detection rules into the local large language model for code review, and output a code review report in text format. In this embodiment, the local large language model can quickly analyze the user-submitted code files based on the code detection rules, promptly identifying potential syntax errors, logical vulnerabilities, and coding standard issues, allowing users to make timely corrections, thereby improving the overall quality of the code. The fifth step is to convert the code review report in text format to obtain a code review report in PDF or HTML format. In this embodiment, by converting the code review report in text format into a code review report in PDF or HTML format, it is convenient to archive and store the code review report, providing strong support for subsequent review, tracing and management.
[0036] This solution implements code file review by building code detection rules and a local large language model. The code files and code detection rules submitted by users are then fed into the local large language model for processing. Compared to traditional code review methods based on large language models, this solution uses a local large language model for code review. This model can perform code review directly on the local device without relying on cloud servers, effectively preventing the risk of code data being leaked or lost due to cloud server crashes or attacks, thereby improving user data security.
[0037] Preferably, step S1 includes the following sub-steps: obtaining the code file submitted by the user through a local code hosting service platform built on Git. In this embodiment, Git is a distributed version control system. The local code hosting service platform is built on Git. With the help of tools such as git commands and diff commands provided by Git, the latest version of the code submitted by the user can be actively obtained, which can avoid the subsequent full scan of all codes in the entire code library. Only the latest code submitted this time needs to be reviewed. This can not only reduce the code review time, but also reduce the resource consumption during the code review process.
[0038] Preferably, in step S2, the code style detection rules include prohibiting the use of a mixture of pinyin and English when naming the code, prohibiting the direct use of Chinese in naming, and uniformly naming the code method names, parameter names, member variables and local variables in lowerCamelCase format; the sensitive information detection rules include prohibiting the appearance of passwords and API key information in the code text; the security vulnerability detection rules include enforcing the use of security functions in the code text.
[0039] In this example, prohibiting the use of mixed pinyin and English names in code naming, prohibiting the use of direct Chinese names, and uniformly naming method names, parameter names, member variables, and local variables in the code using lowerCamelCase format helps improve code readability and maintainability. Prohibiting the use of passwords and API key information in code text helps prevent the leakage of user privacy data or corporate secrets. Enforcing the use of secure functions in code text helps improve code security and reliability.
[0040] Preferably, in step S4, the following sub-steps are specifically included: step S41: parsing the code file submitted by the user to obtain a parsed code file; step S42: according to the code detection rules, comparing and analyzing each character in the parsed code file one by one to obtain a code review result; step S43: generating a code review report in text format based on the code review result.
[0041] In this embodiment, in step S41, since the code file is usually written in a specific programming language syntax and contains various elements such as keywords, variables, functions and control structures. By parsing the code file submitted by the user, the various elements of the code text can be accurately identified, avoiding review errors caused by misunderstandings of the code syntax and structure. In step S42, by comparing and analyzing each character in the parsed code file one by one, errors or inappropriate places in the code file can be found, thereby improving the reliability and stability of the code file. In step S43, by generating a code review report in text format, clear feedback information can be provided to the user, allowing the user to quickly understand the quality status of the code file and make targeted modifications.
[0042] Preferably, in step S5, the following sub-steps are specifically included: using a Java library to convert the code review report in text format into a code review report in PDF or HTML format. In this embodiment, by using a Java library, it can be ensured that the converted code review report in PDF or HTML format has a unified format and style. Further explanation, if it is necessary to convert the code review report in text format into a code review report in PDF format, the iText library is used for conversion, wherein the iText library is a powerful Java library. If it is necessary to convert the code review report in text format into a code review report in HTML format, the Java built-in I / O library is used for string splicing.
[0043] Another aspect of the present application provides a code review system based on a local large language model, the system comprising:
[0044] Acquisition module, used to obtain code files submitted by users;
[0045] The first building module is used to build code detection rules, wherein the code detection rules include code style detection rules, sensitive information detection rules, and security vulnerability detection rules;
[0046] The second building block is used to build a local large language model;
[0047] The code review module is used to input the code files and code detection rules submitted by users into the local large language model for code review and output the code review report in text format;
[0048] The format conversion module is used to convert the code review report in text format to obtain the code review report in PDF or HTML format.
[0049] This solution uses a code review system based on a local large language model. This system implements code file review through the collaboration of an acquisition module, a first construction module, a second construction module, a code review module, and a format conversion module. This solution utilizes a local large language model for code review, enabling it to be performed directly on the local device without relying on a cloud server. This effectively prevents the risk of user code data being leaked or lost due to cloud server crashes or attacks, thereby improving user data security.
[0050] Preferably, the acquisition module includes an acquisition submodule for acquiring user-submitted code files through a local code hosting service platform built on Git. In this embodiment, by setting up the acquisition submodule, the code acquired is the latest version of the code submitted by the user, which can avoid the need to subsequently scan all the code in the entire code base. Only the latest code submitted this time needs to be reviewed. This not only reduces code review time, but also reduces resource consumption during the code review process.
[0051] Preferably, in the first building block, the code style detection rules include prohibiting the use of a mixture of pinyin and English when naming the code, prohibiting the direct use of Chinese, and uniformly naming the code method names, parameter names, member variables and local variables in lowerCamelCase format; the sensitive information detection rules include prohibiting the appearance of passwords and API key information in the code text; the security vulnerability detection rules include enforcing the use of security functions in the code text.
[0052] In this example, prohibiting the use of mixed pinyin and English names in code naming, prohibiting the use of direct Chinese names, and uniformly naming method names, parameter names, member variables, and local variables in the code using lowerCamelCase format helps improve code readability and maintainability. Prohibiting the use of passwords and API key information in code text helps prevent the leakage of user privacy data or corporate secrets. Enforcing the use of secure functions in code text helps improve code security and reliability.
[0053] Preferably, the code review module includes: a parsing submodule, which is used to parse the code file submitted by the user to obtain a parsed code file; a comparative analysis submodule, which is used to compare and analyze each character in the parsed code file one by one according to the code detection rules to obtain a code review result; and a generation submodule, which is used to generate a code review report in text format based on the code review result.
[0054] In this embodiment, by setting up a parsing submodule, it is possible to accurately identify the various elements of the code text, avoiding review errors caused by misunderstandings of the code syntax and structure. By setting up a comparative analysis submodule, it is possible to discover errors or inappropriate places in the code file, thereby improving the reliability and stability of the code file. By setting up a generation submodule, it is possible to provide users with clear feedback information, allowing users to quickly understand the quality status of the code file and make targeted modifications.
[0055] Preferably, the format conversion module includes: a format conversion submodule for converting the code review report in text format into a code review report in PDF or HTML format using a Java library. In this embodiment, by setting the format conversion submodule, it can be ensured that the converted code review report in PDF or HTML format has a unified format and style.
[0056] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing module, each unit may exist physically separately, or two or more units may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or in the form of software functional modules. If the integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may also be stored in a computer-readable storage medium.
[0057] Although the embodiments of the present invention have been shown and described above, it will be understood that the above embodiments are exemplary and are not to be construed as limitations on the present invention. A person skilled in the art may change, modify, replace and modify the above embodiments within the scope of the present invention.
Claims
1. A code review method based on a local large language model, characterized by: The following steps are involved: Step S1: Obtain the code file submitted by the user; Step S2: Construct code detection rules, wherein the code detection rules include code style detection rules, sensitive information detection rules, and security vulnerability detection rules; Step S3: Build a local large language model; Step S4: Input the code file and code detection rules submitted by the user into the local large language model for code review, and output a code review report in text format; Step S5: Convert the code review report in text format to obtain a code review report in PDF or HTML format.
2. The code review method based on a local large language model according to claim 1, characterized in that: In step S1, the following sub-steps are included: obtaining the code file submitted by the user through a local code hosting service platform built based on Git.
3. The code review method based on a local large language model according to claim 1, characterized in that: In step S2, the code style detection rules include prohibiting the use of a mixture of pinyin and English in code naming, prohibiting the use of Chinese characters directly in naming, and uniformly naming method names, parameter names, member variables, and local variables in the code in lowerCamelCase format; Sensitive information detection rules include prohibiting passwords and API key information from appearing in code text; Security vulnerability detection rules include enforcing the use of safe functions in code text.
4. The code review method based on a local large language model according to claim 1, characterized in that: In step S4, the following sub-steps are specifically included: Step S41: Parse the code file submitted by the user to obtain a parsed code file; Step S42: According to the code detection rules, each character in the parsed code file is compared and analyzed one by one to obtain the code review result; Step S43: Generate a code review report in text format based on the code review results.
5. The code review method based on a local large language model according to claim 1, characterized in that: In step S5, the following sub-steps are specifically included: using a Java library to convert the code review report in text format into a code review report in PDF or HTML format.
6. A code review system based on a local large language model, using the code review method based on a local large language model according to any one of claims 1 to 5, characterized in that: The system comprises: Acquisition module, used to obtain code files submitted by users; The first building module is used to build code detection rules, wherein the code detection rules include code style detection rules, sensitive information detection rules, and security vulnerability detection rules; The second building block is used to build a local large language model; The code review module is used to input the code files and code detection rules submitted by users into the local large language model for code review and output the code review report in text format; The format conversion module is used to convert the code review report in text format to obtain the code review report in PDF or HTML format.
7. The code review system based on a local large language model according to claim 6, characterized in that: The acquisition module includes: an acquisition submodule, which is used to acquire the code files submitted by the user through a local code hosting service platform built based on Git.
8. The code review system based on a local large language model according to claim 6, characterized in that: In the first building block, the code style detection rules include prohibiting the use of a mixture of pinyin and English in code naming, prohibiting the direct use of Chinese naming, and uniformly naming the method names, parameter names, member variables, and local variables of the code in lowerCamelCase format; Sensitive information detection rules include prohibiting passwords and API key information from appearing in code text; Security vulnerability detection rules include enforcing the use of safe functions in code text.
9. The code review system based on a local large language model according to claim 6, characterized in that: The code review module includes: The parsing submodule is used to parse the code file submitted by the user and obtain the parsed code file; The comparison and analysis submodule is used to compare and analyze each character in the parsed code file one by one according to the code detection rules to obtain the code review results; The generation submodule is used to generate a code review report in text format based on the code review results.
10. The code review system based on a local large language model according to claim 6, characterized in that: The format conversion module includes: a format conversion submodule, which is used to convert the code review report in text format into the code review report in PDF or HTML format using a Java library.