Code review method and device based on large language model

By introducing an event callback interface and a branch filtering mechanism, code change content is automatically obtained and filtered, segmented, and sent to a large language model for intelligent review. This solves the problem of insufficient automation in code review in existing technologies and improves review efficiency and system stability.

CN122111446APending Publication Date: 2026-05-29IND BANK CO

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
IND BANK CO
Filing Date
2026-03-19
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Current code review technologies rely on manual triggering, resulting in insufficient automation. They suffer from repetitive reviews, input length limitations, and high coupling between model interfaces, making it difficult to meet the needs of efficient, reliable, and highly scalable intelligent code review in complex R&D scenarios.

Method used

By introducing an event callback interface to automatically obtain code change content, filtering based on branch information, eliminating invalid files, splitting valid code and sending it to a large language model for review, constructing prompt words and calling the model, the review process is automated.

Benefits of technology

It improves the automation of code review, reduces redundant calculation overhead, enhances system stability and adaptability, enables batch processing of long code changes, and generates complete review reports.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122111446A_ABST
    Figure CN122111446A_ABST
Patent Text Reader

Abstract

The application discloses a code review method and device based on a large language model, and the method comprises the following steps: obtaining event callback interface information, corresponding changed code files and branch information; filtering the event callback interface information based on the branch information to obtain filtered changed code files; determining the validity of the changed code files according to the file name and file content of the filtered changed code files; if there is a valid code file, the valid code file is segmented and sent to a large language model development platform, so that the large language model development platform constructs prompt words based on the valid code file and calls a corresponding large language model to obtain a review result. The application can realize automatic identification, filtering and intelligent review of code submission change content, and improves the automation degree and review efficiency of the code review process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of software engineering and artificial intelligence technology, and in particular to a code review method and apparatus based on a large language model. Background Technology

[0002] During software development, merge requests or pull requests in the codebase usually require timely, comprehensive and reliable code review to identify potential defects, security risks and non-standard implementations, thereby ensuring code quality and reducing subsequent maintenance costs.

[0003] In existing technologies, changed code is usually checked through manual review or in combination with static analysis tools. Some solutions have begun to introduce artificial intelligence or large language models to analyze the differences in the code and write the review comments back to the code platform in the form of comments. However, the overall process mostly relies on manual triggering or simple interface calls, and a unified event-driven scheduling and engineering management mechanism has not yet been formed.

[0004] However, the aforementioned existing technologies still generally suffer from problems such as insufficient automation of triggering mechanisms, the same code being easily reviewed repeatedly during multi-level branching processes, significant impact from model input length limitations when facing large-scale changes or long text inputs, lack of queued scheduling and persistent state management of tasks leading to insufficient system stability and fault tolerance, and high coupling between model interfaces and prompt word configurations, making it difficult to achieve flexible switching and unified management. Therefore, they are unable to meet the needs of intelligent code review that is efficient, reliable, and highly scalable in complex R&D scenarios.

[0005] This section is intended to provide background or context for the embodiments of the invention set forth in the claims. The description herein is not an admission that it is prior art simply because it is included in this section. Summary of the Invention

[0006] This invention provides a code review method based on a large language model, which can automatically identify, filter, and intelligently review code submission changes, thereby improving the automation and efficiency of the code review process.

[0007] This code review method based on a large language model includes: Retrieve event callback interface information and its corresponding modified code files and branch information; The event callback interface information is filtered based on the branch information to obtain the filtered modified code file; Based on the filename and content of the filtered modified code file, the validity of the modified code file is determined. If a valid code file exists, the valid code file is segmented and sent to the large language model development platform, so that the large language model development platform can construct prompt words based on the valid code file and call the corresponding large language model to obtain the review result.

[0008] In some embodiments, obtaining the event callback interface information and its corresponding modified code file and branch information includes: Identify the corresponding code platform based on the obtained event callback interface information; Based on the data structure type corresponding to the code platform, the event callback interface information is parsed to obtain the modified code file and branch information; The event status of the parsed event callback interface information is marked as accepted and stored in the database.

[0009] In some embodiments, the step of filtering the event callback interface information based on the branch information to obtain the filtered modified code file includes: Based on the branch information and branch type, determine whether the branch information has undergone code review; if so, filter the event callback interface information corresponding to the branch information and mark the event status of the event callback interface information as rejected; if not, add the modified code file of the event callback interface information to the processing queue.

[0010] In some embodiments, determining the validity of the modified code file based on its filename and content after filtering includes: The modified code file is retrieved from the processing queue. Based on the filename, it is determined whether the modified code file is a text comment file or a script file. If so, the modified code file is filtered. If not, the modified code file is determined to be a valid code file. Based on the content of the file, determine whether the modified code file is an invalid development file; if so, filter the modified code file; if not, determine the modified code file as a valid code file.

[0011] In some embodiments, the method further includes: if no valid code file exists, marking the event status of the event callback interface information as a rejected state.

[0012] In some embodiments, the step of splitting the valid code file and sending it to the large language model development platform includes: The number of tokens in the valid code file is determined; if the number of tokens is greater than a first preset threshold, the valid code file is divided into multiple sub-segments, and an audit request corresponding to each sub-segment is constructed. The sub-segments and their corresponding review requests are sent to the large language model development platform in a preset order.

[0013] In some embodiments, the large language model development platform constructs prompt words based on the valid code file and calls the corresponding large language model to obtain the review result, including: The language type of the sub-fragment is determined based on its file extension. The corresponding large language model is invoked according to the pre-configured model mapping strategy and the language type; wherein, the model mapping strategy includes the mapping relationship between the language type and the large language model; Configure corresponding prompts for each of the aforementioned review requests according to the preset prompt template; The prompt words are input into the large language model to obtain the review results.

[0014] In some embodiments, the method further includes: Determine whether each of the aforementioned review requests has received a corresponding review result; if so, organize and process the review results to obtain a review report. If any audit request fails to obtain a corresponding audit result, determine whether the number of retries for the audit request exceeds a second preset threshold; if so, mark the event status of the event callback interface information corresponding to the audit request as a rejected state. If the second preset threshold is not exceeded, the review request will be added to the processing queue for re-review.

[0015] This invention also provides a code review device based on a large language model, which can automatically identify, filter and intelligently review code submission changes, thereby improving the automation and efficiency of the code review process.

[0016] This code review device based on a large language model includes: The acquisition module is used to acquire event callback interface information and its corresponding modified code files and branch information; The branch filtering module is used to filter the event callback interface information based on the branch information to obtain the filtered modified code file; The code validity determination module is used to determine the validity of the modified code file based on the file name and content of the filtered modified code file. If a valid code file exists, the valid code file is segmented and sent to the large language model development platform, so that the large language model development platform can construct prompt words based on the valid code file and call the corresponding large language model to obtain the review result.

[0017] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described code review method based on a large language model.

[0018] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described code review method based on a large language model.

[0019] This invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described code review method based on a large language model.

[0020] The code review method and apparatus based on a large language model provided in this invention introduces an event callback interface to automatically trigger merge requests from remote code repository platforms and automatically acquire changed code, reducing manual intervention. By filtering based on branch information, it controls repeated review of the same changed code during multi-level branch flow, reducing the overhead of redundant calculations in the code review system. By determining the validity of changed code files, it eliminates non-source code files and files without actual development value, reducing the involvement of irrelevant data in subsequent processing. Valid code files are segmented according to the number of tokens and sent to the large language model development platform for prompt word construction and model invocation. This enables batch processing of long code changes under the condition of limited input length in the large language model, improving the processing adaptability and result organization completeness of the changed code review process. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 This is a schematic diagram illustrating the execution process of the code review method based on a large language model in an embodiment of the present invention; Figure 2 This is a flowchart illustrating a code review method based on a large language model in one embodiment of the present invention; Figure 3 This is a flowchart illustrating a code review method based on a large language model in another embodiment of the present invention; Figure 4 This is a flowchart illustrating a code review method based on a large language model in another embodiment of the present invention; Figure 5 This is a flowchart illustrating a code review method based on a large language model in another embodiment of the present invention; Figure 6 This is a flowchart illustrating a code review method based on a large language model in another embodiment of the present invention; Figure 7 This is a flowchart illustrating a code review method based on a large language model in another embodiment of the present invention; Figure 8 This is an example of intelligent code review when merging requests in the GitLab library in this embodiment of the invention; Figure 9 This is an example of intelligent code review when merging requests in the collaborative R&D platform of this invention. Figure 10 This is a schematic diagram of the code review device based on a large language model in an embodiment of the present invention; Figure 11 This is a schematic diagram of the physical structure of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0022] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. Here, the illustrative embodiments and their descriptions are used to explain the present invention, but are not intended to limit the present invention. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of this application can be arbitrarily combined with each other. The acquisition, storage, use, and processing of data in the technical solutions of this application all comply with relevant laws and regulations. The user information in the embodiments of this application is obtained through legal and compliant means, and the acquisition, storage, use, and processing of user information have been authorized and agreed upon by the customer.

[0023] To facilitate understanding of the technical solution provided in this application, the relevant content of the technical solution in this application will be explained below.

[0024] To address the problems in existing code review technologies, such as reliance on manual triggering, the tendency for duplicate reviews during multi-level branching processes, interference from invalid files with review results, constraints on code content due to the input length of large language models when handling large-scale changes or long texts, and insufficient stability and fault tolerance of code review systems due to the lack of queued scheduling and failure retry mechanisms, this application provides a code review method based on large language models.

[0025] When a user initiates a merge request on a remote code repository platform, the platform sends corresponding event callback interface information (HTTP request) to the code review system via an event callback interface. Upon receiving this information, the code review system parses it to obtain the changed code files and branch information. Based on the branch information, it filters the event callback information to prevent the same changed code from being reviewed repeatedly during multi-level branching. Subsequently, the changed code files are validated, eliminating non-source code files and files with no practical development value. Valid code files are segmented based on their number of tokens, and the segments are sent to the large language model development platform in a preset order. The platform constructs prompt words based on the language type of the valid code files and a pre-configured model mapping strategy, and then calls the corresponding large language model to generate the review result. This technical solution automates the acquisition and processing of changed code, improving the automation level of the code review process, resource utilization efficiency, and system stability.

[0026] like Figures 1 to 2 As shown, this invention provides a code review method based on a large language model. The code review method includes steps 201 to 203.

[0027] Step 201: Obtain the event callback interface (Webhook) information and its corresponding modified code file and branch information.

[0028] Step 202: Filter the event callback interface information based on the branch information to obtain the filtered modified code file.

[0029] Step 203: Determine the validity of the filtered change code files based on their filenames and contents. If a valid code file exists, it is split and sent to the large language model development platform. The platform then constructs prompt words based on the valid code file and calls the corresponding large language model to obtain the review result.

[0030] According to the above embodiments, by introducing an event callback interface, the automatic triggering of merge requests from the remote code repository platform and the automatic acquisition of changed code are realized, reducing manual intervention. Through filtering based on branch information, duplicate reviews of the same changed code in multi-level branch flow are controlled, reducing the overhead of redundant calculations in the code review system. By determining the validity of changed code files, non-source code files and files without actual development value are eliminated, reducing the involvement of irrelevant data in subsequent processing. Valid code files are segmented according to the number of tokens and sent to the large language model development platform for prompt word construction and model invocation. This enables batch processing of long code changes under the condition of limited input length for the large language model, improving the processing adaptability and result organization completeness of the changed code review process.

[0031] In this embodiment of the invention, the event callback interface information is a request message based on the Hypertext Transfer Protocol (HTTP). The code review system pre-registers a callback address (Uniform Resource Locator, URL) with the remote code repository platform. When a user initiates a code merge request on the remote code repository platform, the remote code repository platform sends a corresponding HTTP request message (e.g., a POST request) to the code review system via the callback address to notify of the occurrence of the merge request event. The HTTP request message includes: an event type field, remote code repository platform identification information, branch information, changed code content field, merge request identifier or pull request identifier, etc. The code review system obtains and processes the changed code content based on the HTTP request message, thereby realizing automatic acquisition and real-time review of the changed code. Among them, the branch information typically includes: source branch and target branch, and the remote code repository platform includes: GitLab and Gitee, etc.

[0032] In some embodiments, such as Figure 3 As shown, step 201 includes steps 301 to 303.

[0033] Step 301: Identify the corresponding code platform based on the obtained event callback interface information.

[0034] Step 302: Based on the data structure type corresponding to the code platform, parse the event callback interface information to obtain the changed code file and branch information.

[0035] Step 303: Mark the event status of the parsed event callback interface information as accepted and store it in the database. The code platform is a remote code repository platform.

[0036] In this embodiment of the invention, the code review system internally includes a parsing module for resolving event callback interface information from different remote code repository platforms. For different types of remote code repository platforms, the code review system encapsulates corresponding parsing modules to parse the received Webhook information according to the event data structure type of each remote code repository platform. For example, when the code review system identifies the event source as a GitLab code repository, it calls the Webhook information parsing module corresponding to the GitLab code repository to identify the event type field in the Webhook information and determine whether it is an event type such as a Merge Request, Pull Request, or Push. Simultaneously, it extracts the changed code files and branch information corresponding to the event type. For other remote code repository platforms, a parsing module matching their interface specifications is also used for data parsing and field mapping, thereby uniformly converting event data from different platforms into a standardized data structure within the system.

[0037] Specifically, after receiving the event callback interface information, the code review system first performs a validity check on the HTTP request message, including checking the signature field or authentication field in the HTTP request header to confirm whether the HTTP request comes from a legitimate Webhook server, and prevents the request message from being forged or tampered with through the signature verification mechanism.

[0038] For example, the code review system also supports the identity authentication mechanism and access control policy corresponding to each remote code repository platform, including the legality verification of Webhook information based on access tokens, signature verification or key verification, so as to ensure the authenticity of the event source and the security and stability of the event processing process.

[0039] The code review system identifies the remote code repository platform type corresponding to the webhook information based on the event identifier field in the HTTP request header. For example, the X-Gitlab-Event field in the HTTP request header identifies the event source as the GitLab platform, and the X-Gitee-Event field in the HTTP request header identifies the event source as the Gitee platform.

[0040] When the remote code repository platform is identified as GitLab, the code review system parses the event data based on the `object_kind` and `merge_request` fields in the HTTP request body, extracting the event type, committer information, source branch, target branch, and the changed code files corresponding to the merge request. When the remote code repository platform is identified as Gitee, the code review system parses the merge request content based on the `pull_request` field in the HTTP request body, and extracts the corresponding branch information and changed code files.

[0041] After parsing, the code review system will persistently store the extracted branch information and modified code files in the local database, and mark the event status corresponding to the Webhook information as received (ACCEPT) to indicate that the event has passed the legality verification and entered the subsequent processing flow.

[0042] According to the above embodiments, by constructing an event parsing and unified modeling mechanism for multiple remote code repository platforms, unified access and standardized processing of different code repositories are achieved, enabling the code review system to be compatible with the data structures and interface specifications of various heterogeneous code repositories, thereby enhancing the scalability, compatibility and flexibility of the code review system.

[0043] In some embodiments, step 202 specifically includes: determining whether the branch information has undergone code review based on the branch information and branch type. If yes, filtering the event callback interface information corresponding to the branch information and marking the event status of the event callback interface information as rejected. If no, adding the modified code file of the event callback interface information to the processing queue.

[0044] In this embodiment of the invention, during the software development process, code typically flows between multiple branches. For example, it may be merged from a feature branch to a development branch, then from the development branch to a release branch, and finally from the release branch to the main branch (main or master).

[0045] To ensure code quality, code review systems typically need to review changed code files at key merge nodes. However, in multi-level branching processes, the same changed code file may be merged multiple times between different branches. If a review process is triggered for each merge, it will lead to duplicate reviews and increase system resource consumption.

[0046] Therefore, in this embodiment of the invention, the code review system records the branch merge path to characterize the flow relationship of the changed code file between different branches, and determines whether the changed code file has completed the code review based on the branch merge path, thereby determining whether to trigger the review process again.

[0047] If the user provides the target branch parameter (target_branch) in the event callback interface information, that is, explicitly specifies the target branch that needs to be reviewed, there is no need to perform the above filtering operation; the changed code file can be directly added to the processing queue.

[0048] For example, taking the code flow path feature→develop→release→master as an example, when a merge request occurs for feature→develop, the code review system triggers the review process and records the branch merge path. When a subsequent merge request occurs for develop→release, the code review system determines, based on the recorded branch merge path, that the changed code file has already been reviewed on the upstream branch, thus filtering out the merge request. Similarly, when a merge request occurs for release→master, it can also be determined, based on the recorded branch merge path, that no repeated review is needed. If a user needs to perform a review on a specific target branch (e.g., release or master), they can set the target branch parameter (target_branch) when configuring the Webhook callback address to explicitly specify the branch type that needs to be reviewed.

[0049] When a branch is determined to be exempt from review, the code review system marks the event status corresponding to the event callback interface information as REJECT and terminates the subsequent review process. When the branch is not filtered, the code review system adds the modified code file corresponding to the event callback interface information to the processing queue for subsequent review processing.

[0050] According to the above embodiments, the code review system controls the branch processing logic through a branch filtering mechanism and implements persistent storage of branch merge paths in conjunction with a database. When a code commit occurs and triggers an event callback interface, the code review system identifies the branch merge path corresponding to the current merge operation based on the source branch and the target branch, and queries the database to see if a record matching the branch merge path exists. If the query result shows that the branch merge path already exists, it is determined that the changed code file has already completed the review process on the upstream branch, and a filtering operation is performed on the event callback interface information, preventing further review processes from being triggered. If no corresponding record exists in the database, the current branch merge path is recorded and the subsequent code review process is triggered. Through the above branch path identification and persistent management mechanism, control over duplicate review scenarios is achieved.

[0051] In some embodiments, such as Figure 4 As shown, the validity determination of the change code file based on the file name and content of the filtered change code file includes steps 401 to 402.

[0052] Step 401: Retrieve the modified code file from the processing queue. Determine whether the modified code file is a text comment file or a script file based on the filename. If yes, filter the modified code file. If no, determine the modified code file as a valid code file.

[0053] Step 402: Determine whether the modified code file is an invalid development file based on its content. If yes, filter the modified code file. If no, determine the modified code file as a valid code file.

[0054] In this embodiment of the invention, the code review system retrieves a modified code file from the processing queue and determines the validity of the file content. The processing queue adopts a first-in-first-out (FIFO) scheduling strategy to ensure that each modified code file is processed sequentially according to the order of receipt.

[0055] Specifically, the code review system identifies file types based on the filename and extension of the modified code file. When the modified code file is a text description file (e.g., README.md or CHANGELOG.md) or a script file (e.g., a non-business source code script file with the extension .sh or .bat), it is filtered. Furthermore, the system also judges the modified code file based on its content; if the content is an icon file, an image file, or a file containing only configuration data with no actual development value, it is also filtered.

[0056] After the above judgment, the unfiltered modified code files are identified as valid code files and enter the subsequent processing flow.

[0057] In some embodiments, if no valid code file exists, the event status corresponding to the event callback interface information is marked as rejected, and the review process is terminated.

[0058] According to the above embodiments, the filtering mechanism eliminates modified code files with no actual development value, ensuring that subsequent processing only targets valid code files, thereby reducing irrelevant data from participating in the subsequent review process. Furthermore, to improve the reliability of the code review system, a processing queue and event state storage mechanism are implemented. All modified code files are written to the processing queue before entering subsequent processing, and the event state corresponding to the event callback interface information is recorded and updated during processing. When situations such as large language model call failure, call timeout, or system abnormal restart occur, the code review system, based on the processing queue and stored event state information, restores unfinished tasks and reschedules them for execution to ensure the continuity of the review process. Through the above queue scheduling and state persistence management mechanism, control over the task processing process under abnormal scenarios is achieved.

[0059] In some embodiments, such as Figure 5 As shown, the process of splitting the valid code file and sending it to the large language model development platform includes steps 501 to 502.

[0060] Step 501: Determine the number of tokens in the valid code file. If the number of tokens exceeds the first preset threshold, divide the valid code file into multiple sub-segments and construct the corresponding review requests for each sub-segment.

[0061] Step 502: Send the sub-segments and their corresponding review requests to the large language model development platform in a preset order. The large language model development platform is the Dify platform, but this invention is not limited to this.

[0062] In this embodiment of the invention, because the large language model has an input length limit on the number of input tokens, long code files cannot be processed in a single request. Therefore, the code review system judges the number of tokens in valid code files. When the number of tokens in a valid code file exceeds a preset maximum token threshold, the code review system segments the valid code file based on the preset token count, dividing the valid code file into multiple sub-segments, ensuring that the number of tokens in each sub-segment does not exceed the maximum input length allowed by the large language model.

[0063] When a valid code file or a code block composed of multiple code segments still exceeds the maximum term threshold after initial segmentation, the code review system performs Abstract Syntax Tree (AST) analysis on the code content to identify function boundaries or syntax structure boundaries in the code, and further segments the valid code file or code block based on the identified function boundary locations.

[0064] Once a valid code file is divided into multiple sub-segments, the code review system sorts the sub-segments according to their relative positions within the original code file. This ensures that subsequent review processes maintain consistency with the logical order of the original code file. Following the Application Programming Interface (API) call specifications of the large language model development platform, the code review system encapsulates the review requests corresponding to each sub-segment and sends them sequentially to the platform in the sorted order to initiate code review requests.

[0065] The review request includes input parameters describing the code content and control parameters related to workflow execution (such as inputs, response_mode, and user parameters). After receiving the response result (e.g., status_code is 200) from the large language model development platform, the code review system determines whether the review request was successfully executed based on the status information in the response message, and proceeds to the next processing step accordingly.

[0066] According to the above embodiments, by using the segmentation method based on the combination of word count and syntactic structure, the integrity of the semantic structure of the code is maintained as much as possible while meeting the input length limit of the large language model, so as to facilitate subsequent code review and processing.

[0067] In some embodiments, such as Figure 6 As shown, the large language model development platform constructs prompt words based on valid code files and calls the corresponding large language model to obtain the review results, including steps 601 to 604.

[0068] Step 601: Determine the language type of the sub-fragment based on its file extension.

[0069] Step 602: Invoke the corresponding large language model according to the pre-configured model mapping strategy and language type. The model mapping strategy includes the mapping relationship between language type and large language model.

[0070] Step 603: Configure corresponding prompts for each review request according to the preset prompt template.

[0071] Step 604: Input the prompt words into the large language model to obtain the review results.

[0072] In this embodiment of the invention, the large language model development platform receives the review request and corresponding code sub-segment sent by the code review system through the application programming interface, and performs legality verification on the review request to ensure the integrity and validity of the requested data.

[0073] Specifically, the large language model development platform first determines whether the corresponding workflow is in a published state. Only when the workflow is in a published state is it allowed to receive and execute API call requests from the code review system. Subsequently, the platform performs integrity checks on the required parameters in the review request. Required parameters include at least input parameters, response mode parameters, and user identifier parameters to ensure that the data structure of the review request conforms to the application programming interface (API) call specification. When a review request has missing parameters or the request format does not conform to the API call specification, the large language model development platform returns the corresponding error response information. The code review system processes the review request according to the type of error response information, including resending the review request or terminating the current review process.

[0074] The large language model development platform first identifies the programming language type of the code fragment based on the file extension of the valid code file corresponding to the code fragment (e.g., .js, .ts, .py, .cpp, etc.). Then, according to the pre-configured model mapping strategy, the platform selects a large language model that matches the programming language type and calls the corresponding large language model application interface to perform the code review task.

[0075] Specifically, the model mapping strategy includes the mapping relationship between programming language types and target large language models.

[0076] For example, when the identified programming language is a front-end development language such as JavaScript, React, Vue, or Angular, the large language model development platform calls the Qwen large language model. When the identified programming language is C, C++, Rust, Python, Go, Java, or related code based on PyTorch or TensorFlow frameworks, the large language model development platform calls the DeepSeek large language model. When the programming language type of a code sub-segment cannot be identified, the DeepSeek large language model is called by default to perform code review; this invention is not limited to this.

[0077] After determining the target large language model, the large language model development platform performs input format adaptation processing on the code fragments in the review request according to the application interface call specification corresponding to the target large language model, so as to generate a request data structure that conforms to the interface specification of the large language model, thereby realizing interface compatibility and call execution between the code fragments and the large language model.

[0078] Furthermore, the large language model development platform generates corresponding prompts for each review request based on pre-configured prompt templates, in order to guide the large language model to perform code review tasks on the changed code.

[0079] For example, the content of the prompt word template is as follows: You are a senior programmer, and now you are to act as a code review expert to review code for issues.

[0080] The code changes will be provided as a git patch, the details of which are as follows: Based on the git patch and related context information, review the given changes to the code, with the following specific requirements: 1. Do not review anything other than changes to the code.

[0081] 2. Do not output the line number of each line of code in the output content.

[0082] 3. Skip files that are fine and do not reply to them.

[0083] 4. No need to reply with the modified code.

[0084] 5. Output in Chinese using Markdown unordered list format, divided into 5 points: change summary, potential code bugs, code security risks, code evaluation, and code optimization suggestions.

[0085] 6. In the section on potential bugs and code optimization suggestions, first indicate the file name and line number of the problem (enclosed in backticks), and then provide the error or optimization suggestion.

[0086] The format is as follows:

[0087] `[ <filename> : <number> ]` <comment>

[0088] Please strictly adhere to the following output format: # :robot: Suggestions for a code quality inspection robot for the technical platform The following comments were automatically generated by an AI code reviewer: ### :memo: 1. Change Summary: {Change Summary}; ### :bug: 2. Potential code bugs: {potential code bugs}; ### :lock: 3. Code security risks: {Code security risks}; ### :bulb: 4. Code Evaluation: {Code Evaluation}; ### :art: 5. Code optimization suggestions: {Code optimization suggestions}.

[0089] The large language model development platform initiates a dialogue request to the target large language model based on pre-configured interface call parameters and completed prompt words to perform code review tasks. After receiving the review results from the large language model, the platform formats the results to ensure they conform to preset structured format requirements, guaranteeing consistency in content organization and semantic expression. Subsequently, the platform returns the review results to the code review system via an application programming interface (API) for further processing.

[0090] According to the above embodiments, the Dify platform is a development and management platform for large language model applications, used for unified management and invocation of various large language model interfaces. By integrating multiple large language model service interfaces, the Dify platform achieves unified access and invocation management for different large language models. The code review system dynamically invokes the large language model interfaces based on the Dify platform and supports switching and parameter configuration of different large language models, thereby decoupling the code review system from the large language models. The code review system builds and manages prompt word templates through the Dify platform, thereby achieving dynamic configuration, updating, and version management of prompt words. The visual configuration interface provided by the Dify platform is used to edit and manage prompt word content and related parameters, allowing adjustment of prompt word configuration or switching of target large language models without modifying the code review system's program logic.

[0091] In some embodiments, such as Figure 7 As shown, the code review method based on the large language model also includes steps 701 to 703.

[0092] Step 701: Determine whether each audit request has received its corresponding audit result. If so, organize and process the audit results to obtain an audit report.

[0093] Step 702: If any review request fails to obtain a corresponding review result, determine whether the number of retries for the review request exceeds the second preset threshold. If so, mark the event status of the event callback interface information corresponding to the review request as rejected.

[0094] Step 703: If the second preset threshold is not exceeded, add the review request to the processing queue for re-review processing.

[0095] In this embodiment of the invention, the code review system determines whether each code sub-segment corresponding to the current review request has successfully obtained its corresponding review result. When all code sub-segments have successfully obtained their review results, the code review system summarizes and assembles the review results to generate complete review content. When any code sub-segment fails to obtain its review result, the code review system triggers a retry mechanism to reprocess the failed review request.

[0096] Specifically, the code review system determines whether the number of failed retries for the current review request exceeds the preset maximum number of retries. When the number of failed retries exceeds the preset maximum number of retries (e.g., 4 times), the code review system marks the event status of the event callback interface information corresponding to the review request as REJECT and terminates the subsequent review process. When the number of failed retries does not exceed the maximum number of retries, the code review system adds the corresponding review request back to the processing queue and re-executes the code review processing flow.

[0097] After all code sub-snippets have successfully received their review results, the code review system structures and merges these results to generate a complete review report. The review report includes, but is not limited to, a change summary, potential code defects, code security risks, code quality evaluation, and code optimization suggestions.

[0098] After the review report is generated, the code review system returns the report to the corresponding remote code repository via the remote code repository platform interface, so that it can be displayed to the user as the code review comments. After completing the above processing, the code review system updates the event status corresponding to the event callback interface information to the completed status (DONE) to indicate that the current event processing flow has ended.

[0099] According to the above embodiments, by uniformly judging and summarizing the review results of code sub-segments, and introducing a retry mechanism and maximum retry count control when review failures occur, reliable management of the code review task execution process is achieved. After all sub-segments have been reviewed, the review results are structured, merged, and a complete review report is generated. The review comments are then returned through the remote code repository platform interface, thus forming a complete automated review process. Simultaneously, through event status updates and process control mechanisms, the code review system can effectively manage the task execution status, allowing it to continue processing unfinished tasks even in the event of exceptions or call failures, thereby improving the stability of the code review process and the continuity of task processing.

[0100] In some embodiments, when the code review system restarts due to abnormal failure, operation and maintenance, or other reasons, the code review system queries the event callback interface information with the event status in the local database as "ACCEPT" and performs recovery processing on the event callback interface information.

[0101] Specifically, the code review system re-executes branch filtering on the branch information in the restored event callback interface, and adds the filtered modified code files back to the processing queue to continue the subsequent code review process. This task recovery mechanism ensures that unfinished review tasks can continue to be processed even if the code review system restarts abnormally.

[0102] In some embodiments, such as Figure 8 As shown, the code review method based on a large language model provided by this invention can be implemented in practical applications through interface communication between a Git-based remote code repository platform (such as GitLab and Gitee) and a large language model development platform.

[0103] The following section explains how code review systems are applied, using typical application scenarios as examples.

[0104] The code review system is deployed as a GitLab platform webhook event listener service. When a developer commits code to the GitLab codebase and initiates a merge request, the code review system receives the corresponding code commit event notification via the webhook mechanism. It then obtains the code diff information (diff) and commit context information corresponding to the merge request through the GitLab application programming interface (API). This includes, for example, the committing user information, source branch name, target branch name, and commit time. Subsequently, the code review system filters and segments the obtained code diff content, and uses the large language model development platform to call the target large language model to execute the code review task. The code review content includes, but is not limited to, code style checks, potential defect identification, security risk analysis, and duplicate code detection.

[0105] After completing the code review, the code review system receives the structured review results returned by the large language model and writes the review results to the corresponding merge request page through the GitLab application programming interface. These results are then displayed to the code reviewers in the form of code comments, hints, or review suggestions. In this way, code reviewers can directly view the automatically generated code review comments within the GitLab platform interface and use these comments to conduct subsequent code reviews and make decisions.

[0106] According to the above embodiments, by integrating the code review system with the remote code repository platform through an interface, automatic listening to code submission events and automatic writing back and display of review results are realized, thereby forming an automated code review process based on a large language model.

[0107] In some embodiments, such as Figure 9 As shown, the code review method based on a large language model provided by this invention can be applied to an enterprise-level R&D collaboration platform environment.

[0108] Specifically, internal developers use code hosting services based on Gitee code repositories, and their code review processes are integrated into the company's self-built one-stop R&D collaboration platform. This collaborative R&D platform is used to uniformly integrate and manage process tools, development tools, and testing tools used in the software development process, supporting collaborative management throughout the entire R&D delivery process.

[0109] In the above application scenarios, the code review system is integrated into the merge request page of the collaborative R&D platform and presented as an independent functional module, such as displaying code review results information in an independent tab.

[0110] When a user initiates a merge request in the Gitee code repository, the code review system receives the corresponding event notification through the Webhook interface provided by the Gitee platform. Based on pre-configured prompt templates, it then calls the large language model to perform code analysis. Subsequently, the code review system receives the structured review results returned by the large language model and sends them back to the collaborative development platform, where they are displayed in a separate functional module for code reviewers to view. The review results include, but are not limited to, a summary of changes, warnings of potential code defects, code optimization suggestions, and code risk warnings.

[0111] According to the above embodiments, by integrating the code review system with the enterprise's internal R&D collaboration platform, cross-platform access to code review capabilities is achieved, enabling the code review system to provide a unified code review result display and interaction method in the enterprise's internal R&D platform environment while being compatible with the Gitee code repository interface.

[0112] This application provides a code review device based on a large language model, applied to the aforementioned code review method based on a large language model. This code review device and the code review method based on a large language model in one embodiment of this application are based on the same inventive concept and have similar problem-solving principles. Therefore, the implementation of the code review device based on a large language model is the same as the implementation of the code review method based on a large language model in one embodiment of this application, and repeated details will not be described again. As used below, the terms "unit" or "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the system described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0113] like Figure 10 As shown, the code review device 1000 based on a large language model includes: an acquisition module 1001, a branch filtering module 1002, and a code validity determination module 1003.

[0114] The acquisition module 1001 is used to acquire event callback interface information and its corresponding modified code files and branch information.

[0115] The branch filtering module 1002 is used to filter the event callback interface information based on the branch information to obtain the filtered modified code file.

[0116] The code validity determination module 1003 is used to determine the validity of the filtered modified code files based on their filenames and contents. If a valid code file exists, it is split and sent to the large language model development platform. The platform then constructs prompt words based on the valid code file and calls the corresponding large language model to obtain the review result.

[0117] In some embodiments, the acquisition module 1001 includes: The platform identification submodule is used to identify the corresponding code platform based on the obtained event callback interface information.

[0118] The event parsing submodule is used to parse event callback interface information based on the data structure type corresponding to the code platform, and obtain the changed code file and branch information.

[0119] The status recording submodule is used to mark the event status of the parsed event callback interface information as accepted and store it in the database.

[0120] In some embodiments, the branch filtering module 1002 is specifically used to determine whether a branch information should be merged based on the branch information and branch type. If yes, it filters the event callback interface information corresponding to the branch information and marks the event status of the event callback interface information as rejected. If no, it adds the change code file of the event callback interface information to the processing queue.

[0121] In some embodiments, the code validity determination module 1003 includes: The filename determination submodule retrieves the modified code file from the processing queue and determines whether the modified code file is a text comment file or a script file based on the filename. If so, the modified code file is filtered out. If not, the modified code file is determined to be a valid code file.

[0122] The file content determination submodule is used to determine whether a modified code file is an invalid development file based on its content. If so, the modified code file is filtered out. If not, the modified code file is determined to be a valid code file.

[0123] In some embodiments, the apparatus further includes an invalid file processing module. If no valid code file exists, the invalid file processing module marks the event status of the event callback interface information as a rejected state.

[0124] In some embodiments, the code validity determination module 1003 includes: The lexical count determination submodule is used to determine the number of lexical items in a valid code file. If the number of lexical items exceeds a first preset threshold, the valid code file is divided into multiple sub-segments, and a review request corresponding to each sub-segment is constructed.

[0125] The review request sending submodule is used to send the sub-segments and their corresponding review requests to the large language model development platform in a preset order.

[0126] In some embodiments, the code validity determination module 1003 includes: The language recognition submodule is used to determine the language type of a sub-segment based on its file extension.

[0127] The model selection submodule is used to call the corresponding large language model according to the pre-configured model mapping strategy and language type. The model mapping strategy includes the mapping relationship between language type and large language model.

[0128] The prompt word configuration submodule is used to configure corresponding prompt words for each review request based on the preset prompt word template.

[0129] The model call submodule is used to input prompt words into the large language model to obtain the review results.

[0130] In some embodiments, the device further includes: The result judgment module is used to determine whether each review request has obtained the corresponding review result. If so, the review results are organized and processed to obtain the review report.

[0131] The retry judgment module is used to determine whether the number of retries for any review request exceeds a second preset threshold if no review result is obtained. If so, the event status of the event callback interface information corresponding to the review request is marked as rejected.

[0132] The task retry module is used to add the review request to the processing queue for re-review if the second preset threshold is not exceeded.

[0133] Figure 11 This is a schematic diagram of the physical structure of a computer device provided in an embodiment of the present invention, such as... Figure 11 As shown, the computer device 1100 includes a processor 1101, a memory 1102, and a bus 1103.

[0134] The processor 1101 and the memory 1102 communicate with each other via the bus 1103.

[0135] The processor 1101 is used to call program instructions in the memory 1102 to execute the methods provided in the above-described method embodiments.

[0136] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described code review method based on a large language model.

[0137] This invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described code review method based on a large language model.

[0138] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0139] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0140] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0141] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0142] In the description of this specification, references to terms such as "an embodiment," "a specific embodiment," "some embodiments," "for example," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0143] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.< / comment> < / number> < / filename>

Claims

1. A code review method based on a large language model, characterized in that, include: Retrieve event callback interface information and its corresponding modified code files and branch information; The event callback interface information is filtered based on the branch information to obtain the filtered modified code file; The validity of the modified code file is determined based on the filename and content of the filtered modified code file; If a valid code file exists, the valid code file is segmented and sent to the large language model development platform, so that the large language model development platform can construct prompt words based on the valid code file and call the corresponding large language model to obtain the review result.

2. The method according to claim 1, characterized in that, The process of obtaining event callback interface information and its corresponding modified code files and branch information includes: Identify the corresponding code platform based on the obtained event callback interface information; Based on the data structure type corresponding to the code platform, the event callback interface information is parsed to obtain the modified code file and branch information; The event status of the parsed event callback interface information is marked as accepted and stored in the database.

3. The method according to claim 1, characterized in that, The step of filtering the event callback interface information based on the branch information to obtain the filtered modified code file includes: Based on the branch information and branch type, determine whether the branch information has undergone code review; if so, filter the event callback interface information corresponding to the branch information and mark the event status of the event callback interface information as rejected; if not, add the modified code file of the event callback interface information to the processing queue.

4. The method according to claim 3, characterized in that, The step of determining the validity of the modified code file based on its filename and content after filtering includes: The modified code file is retrieved from the processing queue. Based on the filename, it is determined whether the modified code file is a text comment file or a script file. If so, the modified code file is filtered. If not, the modified code file is determined to be a valid code file. Based on the content of the file, determine whether the modified code file is an invalid development file; if so, filter the modified code file; if not, determine the modified code file as a valid code file.

5. The method according to claim 1, characterized in that, Also includes: If no valid code file exists, the event status of the event callback interface information will be marked as rejected.

6. The method according to claim 1, characterized in that, The step of splitting the valid code file and sending it to the large language model development platform includes: The number of tokens in the valid code file is determined; if the number of tokens is greater than a first preset threshold, the valid code file is divided into multiple sub-segments, and an audit request corresponding to each sub-segment is constructed. The sub-segments and their corresponding review requests are sent to the large language model development platform in a preset order.

7. The method according to claim 6, characterized in that, The large language model development platform constructs prompt words based on the valid code file and calls the corresponding large language model to obtain the review results, including: The language type of the sub-fragment is determined based on its file extension. The corresponding large language model is invoked according to the pre-configured model mapping strategy and the language type; wherein, the model mapping strategy includes the mapping relationship between the language type and the large language model; Configure corresponding prompts for each of the aforementioned review requests according to the preset prompt template; The prompt words are input into the large language model to obtain the review results.

8. The method according to claim 6, characterized in that, Also includes: Determine whether each of the aforementioned review requests has received a corresponding review result; if so, organize and process the review results to obtain a review report. If any audit request fails to obtain the corresponding audit result, determine whether the number of retries for the audit request exceeds the second preset threshold. If so, mark the event status of the event callback interface information corresponding to the audit request as a rejected state; If the second preset threshold is not exceeded, the review request will be added to the processing queue for re-review.

9. A code review device based on a large language model, characterized in that, include: The acquisition module is used to acquire event callback interface information and its corresponding modified code files and branch information; The branch filtering module is used to filter the event callback interface information based on the branch information to obtain the filtered modified code file; The code validity determination module is used to determine the validity of the modified code file based on the file name and file content of the filtered modified code file; If a valid code file exists, the valid code file is segmented and sent to the large language model development platform, so that the large language model development platform can construct prompt words based on the valid code file and call the corresponding large language model to obtain the review result.

10. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 8.

12. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 8.