Code processing method, device, equipment and medium based on large language model

Through the code processing method based on the large language model, the problem of time-consuming and unstable results in the existing technology is solved, and fast and stable code analysis and optimization are achieved.

CN118964222BActive Publication Date: 2025-02-14ZHEJIANG HUIRONG NETWORK TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411459456.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-18
Publication Date
2025-02-14
Estimated Expiration
2044-10-18

AI Technical Summary

Technical Problem

The existing technology takes a long time to analyze code during software development, and is limited by the developer's experience level, resulting in unstable analysis results.

Method used

The code processing method based on the large language model is adopted, and by receiving code analysis requests, code segmentation, quality detection, identification determination, analysis unit fragment acquisition and large language model analysis are carried out to generate analysis response data.

Benefits of technology

It simplifies the code analysis process, saves code analysis time, improves the stability of analysis results, and is suitable for developers of different levels of experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118964222B_ABST
    Figure CN118964222B_ABST
Patent Text Reader

Abstract

The present disclosure provides a code processing method, apparatus, device and medium based on a large language model, including: receiving a code analysis request sent by a first user device, wherein the code analysis request sent by the first user device includes: a first target code; performing code segmentation on the first target code to obtain multiple code unit segments; performing quality detection on each code unit segment to obtain a quality detection value corresponding to each code unit segment; determining a corresponding code analysis identifier based on the quality detection value corresponding to each code unit segment; obtaining an analysis unit segment from multiple code unit segments based on the code analysis identifier corresponding to each code unit segment; determining analysis response data corresponding to the analysis unit segment based on the analysis unit segment and a large language model; and sending analysis response data corresponding to the analysis unit segment to the first user device. Thus, the problem of unstable analysis results caused by developers with different experiences performing code analysis is effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present disclosure relate to the field of artificial intelligence technology, and in particular, to a code processing method, apparatus, device, and medium applicable to a large language model-based code processing method. Background Art

[0002] During the software development process, developers usually have the need for code analysis. For example, after writing the code, developers want to know whether the code they wrote has security or performance issues, or in which aspects it can be further optimized.

[0003] In the related art, when performing code analysis, it is mainly implemented through manual evaluation by developers, that is, manually testing the quality of each code snippet, and then determining whether the code snippet needs code analysis to complete the analysis operation of the entire code.

[0004] However, the existing analysis methods are time-consuming and limited by the experience level of developers, resulting in unstable analysis results. Summary of the invention

[0005] The embodiments described herein provide a code processing method, apparatus, device, and medium based on a large language model, which overcome the above-mentioned problems.

[0006] In a first aspect, according to the content of the present disclosure, a code processing method based on a large language model is provided, comprising:

[0007] Receiving a code analysis request sent by a first user device, where the code analysis request sent by the first user device includes: a first target code;

[0008] In response to the code analysis request sent by the first user device, code segmentation is performed on the first target code based on a preset segmentation dimension to obtain a plurality of code unit fragments, each of the code unit fragments being an independent running code based on realizing different functional requirements;

[0009] Performing quality detection on each of the code unit segments to obtain a quality detection value corresponding to each of the code unit segments;

[0010] Determine, based on the quality detection value corresponding to each of the code unit segments, a code analysis identifier corresponding to each of the code unit segments, wherein the code analysis identifier corresponding to the code unit segment is used to describe whether a code analysis operation needs to be performed on the code unit segment;

[0011] Based on the code analysis identifier corresponding to each of the code unit fragments, obtaining an analysis unit fragment from the plurality of code unit fragments, wherein the code analysis identifier corresponding to the analysis unit fragment is used to describe that a code analysis operation needs to be performed on the corresponding code unit fragment;

[0012] Determining analysis response data corresponding to the analysis unit segment based on the analysis unit segment and the large language model;

[0013] Sending analysis response data corresponding to the analysis unit fragment to the first user equipment.

[0014] In a second aspect, according to the content of the present disclosure, a code processing device based on a large language model is provided, comprising:

[0015] A receiving module, configured to receive a code analysis request sent by a first user device, wherein the code analysis request sent by the first user device includes: a first target code;

[0016] a segmentation module, configured to respond to the code analysis request sent by the first user device, and segment the first target code based on a preset segmentation dimension to obtain a plurality of code unit segments, each of which is an independent running code based on realizing different functional requirements;

[0017] A detection module, used to perform quality detection on each of the code unit segments to obtain a quality detection value corresponding to each of the code unit segments;

[0018] A first determination module is used to determine a code analysis identifier corresponding to each of the code unit segments based on a quality detection value corresponding to each of the code unit segments, wherein the code analysis identifier corresponding to the code unit segment is used to describe whether a code analysis operation needs to be performed on the code unit segment;

[0019] An acquisition module, configured to acquire an analysis unit segment from the plurality of code unit segments based on a code analysis identifier corresponding to each of the code unit segments, wherein the code analysis identifier corresponding to the analysis unit segment is used to describe that a code analysis operation needs to be performed on the corresponding code unit segment;

[0020] A second determination module, configured to determine analysis response data corresponding to the analysis unit segment based on the analysis unit segment and the large language model;

[0021] A sending module is used to send analysis response data corresponding to the analysis unit fragment to the first user equipment.

[0022] In a third aspect, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps of the code processing method based on a large language model in any of the above embodiments are implemented.

[0023] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the code processing method based on a large language model in any of the above embodiments are implemented.

[0024] The code processing method based on a large language model provided in an embodiment of the present application receives a code analysis request sent by a first user device, wherein the code analysis request sent by the first user device includes: a first target code; in response to the code analysis request sent by the first user device, code segmentation is performed on the first target code based on a preset segmentation dimension to obtain a plurality of code unit fragments, each of which is an independently running code based on different functional requirements; quality detection is performed on each of the code unit fragments to obtain a quality detection value corresponding to each of the code unit fragments; based on the quality detection value corresponding to each of the code unit fragments, a code analysis identifier corresponding to each of the code unit fragments is determined, and the code analysis identifier corresponding to the code unit fragment is used to describe whether the code unit fragment needs to perform a code analysis operation; based on the code analysis identifier corresponding to each of the code unit fragments, an analysis unit fragment is obtained from the plurality of code unit fragments, and the code analysis identifier corresponding to the analysis unit fragment is used to describe that the corresponding code unit fragment needs to perform a code analysis operation; based on the analysis unit fragments and the large language model, analysis response data corresponding to the analysis unit fragments is determined; and the analysis response data corresponding to the analysis unit fragments is sent to the first user device. In this way, the analysis requirements of the split code unit fragments are identified, and the analysis code fragments with analysis requirements are intelligently analyzed through the large language model to obtain the corresponding analysis response data, which simplifies the code analysis process, saves code analysis time, and effectively solves the problem of unstable analysis results caused by code analysis by developers with different experiences.

[0025] The above description is only an overview of the technical solution of the embodiment of the present application. In order to more clearly understand the technical means of the embodiment of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiment of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly described below. It should be noted that the drawings described below only relate to some embodiments of the present disclosure, but are not intended to limit the present disclosure, wherein:

[0027] Figure 1 It is a flowchart of a code processing method based on a large language model provided by the present disclosure;

[0028] Figure 2 It is a structural schematic diagram of a code processing device based on a large language model provided by the present disclosure;

[0029] Figure 3 It is a structural schematic diagram of a computer device provided by the present disclosure.

[0030] It should be noted that the elements in the drawings are schematic and not drawn to scale. DETAILED DESCRIPTION

[0031] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work also fall within the scope of protection of the present disclosure.

[0032] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by a person skilled in the art to which the subject matter of the present disclosure belongs. It will be further understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the specification and the relevant art, and will not be interpreted in an idealized or overly formal form unless otherwise explicitly defined herein. As used herein, a statement that two or more parts are "connected" or "coupled" together shall mean that the parts are joined together directly or through one or more intermediate components.

[0033] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase "embodiments" in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0034] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists, A and B exist at the same time, and B exists. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship. Terms such as "first" and "second" are only used to distinguish one component (or a part of a component) from another component (or another part of a component).

[0035] In the description of the present application, unless otherwise specified, “plurality” means more than two (including two), and similarly, “plurality groups” means more than two (including two).

[0036] Currently, developers need to spend a lot of time reading the code in detail to understand and master the code developed by others. For the code written by oneself, if you want to understand the optimization space, you can only rely on your personal development experience. The quality of code written by developers with different experience levels varies significantly, which affects the overall quality of the project and development efficiency.

[0037] In this embodiment, developers can quickly analyze and optimize the code, significantly saving time and improving code quality. Specifically, quickly understand and interpret the code: through automated tools, quickly interpret the code, highlight key logic and functional points, and help developers quickly master the code structure and business logic. Code quality assessment and optimization suggestions: automatically analyze security and performance issues in the code, and provide targeted optimization suggestions to help developers improve code quality.

[0038] In the modern software development environment, the complexity of projects and the increase in the amount of code make code management and quality control more important. This embodiment realizes intelligent analysis and optimization of code by combining advanced artificial intelligence technologies such as natural language processing and machine learning. Specific functions include: Automatic code comment generation: Automatically generate detailed comments and documents based on code logic to help developers quickly understand the code. Code review and evaluation: Through static analysis and dynamic analysis techniques, detect potential problems in the code, including security vulnerabilities, performance bottlenecks, code duplication, etc. Optimization suggestion generation: Based on best practices and optimization algorithms, provide specific optimization suggestions, such as code refactoring, security enhancement, performance optimization, etc.

[0039] Through these functions, this embodiment not only improves the readability and maintainability of the code, but also improves the overall efficiency and product quality of the development team. Developers can focus more on the implementation of core business logic without spending a lot of energy on understanding and optimizing the code, thereby accelerating the project delivery cycle and improving market competitiveness.

[0040] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0041] Figure 1 is a flowchart of a code processing method based on a large language model provided by an embodiment of the present disclosure, such as Figure 1 As shown, the specific process of the code processing method based on the large language model includes:

[0042] S110. Receive a code analysis request sent by a first user device, where the code analysis request sent by the first user device includes: a first target code.

[0043] The first target code is a complete code for realizing multiple functional requirements, and each functional requirement may correspond to an independent running code. That is, the first target code may include: multiple independent running codes, and each independent running code may realize different functional requirements respectively.

[0044] It should be noted that after receiving the first target code, the first target code may be preprocessed to check the code integrity and compatibility.

[0045] S120: In response to a code analysis request sent by the first user device, code segmentation is performed on the first target code based on a preset segmentation dimension to obtain a plurality of code unit segments.

[0046] Each code unit fragment is an independent running code based on realizing different functional requirements.

[0047] The preset segmentation dimension may be a segmentation basis set when segmenting the code, for example, the preset segmentation dimension may be a method dimension, that is, running the first target code may implement multiple methods, then the first target code is segmented into methods according to the implemented methods to obtain multiple code unit fragments, and running different code unit fragments may implement different methods; or, the preset segmentation dimension may be a function dimension, that is, the first target code is composed of multiple functions, and running each function may implement a function, then the first target code is segmented into functions according to the functions to obtain multiple code unit fragments, and each code unit fragment may correspond to a function; or, the preset segmentation dimension may be a module dimension, that is, the first target code is composed of multiple modules, and the logical principle of each module may implement a function, then the first target code is segmented into modules according to the modules to obtain multiple code unit fragments, and each code unit fragment may correspond to a module.

[0048] It should be noted that when the first target code is segmented, each method / function / module can be identified by parsing the code structure of the first target code.

[0049] S130: Perform quality detection on each code unit segment to obtain a quality detection value corresponding to each code unit segment.

[0050] Among them, performing quality detection on each code unit fragment to obtain a quality detection value corresponding to each code unit fragment may include: running each code unit fragment to obtain a corresponding running result; comparing the running result corresponding to each code unit fragment with its corresponding expected result; determining the quality detection value corresponding to each code unit fragment based on error data between the running result corresponding to each code unit fragment and its corresponding expected result; the larger the error data between the running result corresponding to the code unit fragment and its corresponding expected result, the smaller the quality detection value corresponding to the code unit fragment.

[0051] S140: Determine a code analysis identifier corresponding to each code unit segment based on the quality detection value corresponding to each code unit segment.

[0052] The code analysis identifier corresponding to the code unit fragment is used to describe whether the code unit fragment needs to perform a code analysis operation.

[0053] In some embodiments, determining a code analysis identifier corresponding to each code unit segment based on a quality detection value corresponding to each code unit segment includes:

[0054] Based on the quality detection value corresponding to each code unit fragment and the weight coefficient of the quality detection value corresponding to each code unit fragment in the quality detection values ​​corresponding to all code unit fragments, the analysis requirement description value corresponding to each code unit fragment is determined; if the analysis requirement description value corresponding to the code unit fragment is less than a preset analysis threshold, it is determined that the code analysis identifier corresponding to the code unit fragment is used to describe that the code unit fragment does not need to perform a code analysis operation; if the analysis requirement description value corresponding to the code unit fragment is greater than or equal to the preset analysis threshold, it is determined that the code analysis identifier corresponding to the code unit fragment is used to describe that the code unit fragment needs to perform a code analysis operation.

[0055] Among them, the weight coefficient of the quality detection value corresponding to a code unit segment in the quality detection values ​​corresponding to all code unit segments can be the ratio of the quality detection value corresponding to the code unit segment to the maximum quality detection value / quality detection mean among the quality detection values ​​corresponding to all code unit segments.

[0056] If the analysis requirement description value corresponding to the code unit fragment is less than the preset analysis threshold, the code analysis identifier corresponding to the code unit fragment is determined to be used to describe that the code unit fragment does not need to perform a code analysis operation, that is, the code analysis identifier corresponding to the code unit fragment is the first analysis identifier; if the analysis requirement description value corresponding to the code unit fragment is greater than or equal to the preset analysis threshold, the code analysis identifier corresponding to the code unit fragment is determined to be used to describe that the code unit fragment needs to perform a code analysis operation, that is, the code analysis identifier corresponding to the code unit fragment is the second analysis identifier.

[0057] Therefore, the code analysis identifier corresponding to each code unit segment is effectively measured through the quality detection value corresponding to each code unit segment and the relationship between the quality detection value corresponding to each code unit segment and the quality detection values ​​corresponding to all code unit segments.

[0058] In addition, determining the code analysis identifier corresponding to each code unit segment based on the quality detection value corresponding to each code unit segment may also include:

[0059] If the quality detection value corresponding to the code unit fragment is less than the preset analysis threshold, the code analysis identifier corresponding to the code unit fragment is determined to be used to describe that the code unit fragment does not need to perform a code analysis operation; if the quality detection value corresponding to the code unit fragment is greater than or equal to the preset analysis threshold, the code analysis identifier corresponding to the code unit fragment is determined to be used to describe that the code unit fragment needs to perform a code analysis operation.

[0060] S150: Acquire an analysis unit segment from multiple code unit segments based on the code analysis identifier corresponding to each code unit segment.

[0061] The code analysis identifier corresponding to the analysis unit segment is used to describe that the corresponding code unit segment needs to perform a code analysis operation, that is, the code analysis identifier corresponding to the analysis unit segment is a second analysis identifier.

[0062] Based on the code analysis identifier corresponding to each code unit fragment, obtaining an analysis unit fragment from multiple code unit fragments may include: obtaining a code unit fragment with a code analysis identifier as a second analysis identifier from multiple code unit fragments; and determining that the code unit fragment with the code analysis identifier as the second analysis identifier is the analysis unit fragment.

[0063] S160: Determine analysis response data corresponding to the analysis unit segment based on the analysis unit segment and the large language model.

[0064] Among them, the large language model can perform code analysis on the analysis unit fragment based on the input analysis unit fragment, analysis target, optimization target and configuration parameters, using the analysis target, optimization target and configuration parameters as analysis prompt words, and obtain the analysis response data corresponding to the analysis unit fragment.

[0065] In some embodiments, the analysis unit fragment corresponds to an analysis requirement parameter, which is used to describe the analysis characteristics and optimization requirements of the analysis unit fragment. The analysis characteristics are the analysis goals mentioned above, which may specifically include: code quality, performance optimization, security testing, etc. The optimization requirements are the optimization goals mentioned above, which may specifically include: reducing code complexity, improving operating efficiency, enhancing maintainability, etc.

[0066] Based on the analysis unit segment and the large language model, analysis response data corresponding to the analysis unit segment is determined, including:

[0067] Based on the analysis requirement parameters corresponding to the analysis unit fragments, the optimization configuration parameters corresponding to the analysis unit fragments when performing code optimization are determined; natural language processing is performed on the analysis unit fragments, the analysis requirement parameters and the optimization configuration parameters; the analysis unit fragments, the analysis requirement parameters and the optimization configuration parameters after natural language processing are input into the large language model, and the analysis response data corresponding to the analysis unit fragments are determined based on the output results of the large language model.

[0068] The optimization configuration parameters are used to describe the reference rules used when optimizing the analysis unit fragments, that is, to configure the parameters related to the optimization target, which may include: code style specifications, performance benchmarks, security policies, etc.

[0069] Therefore, by performing natural language processing on the analysis unit fragments, analysis requirement parameters and optimization configuration parameters, the analysis unit fragments, analysis requirement parameters and optimization configuration parameters input into the large language model are natural language descriptions that can be understood by the large language model, which facilitates effective processing by the model.

[0070] It should be noted that when inputting a large language model, you can use a pre-built API (Application Program Interface) request, use the processed natural language fragment as a request parameter, call the API interface of the large language model, and pass the request parameter to the model for processing. In addition, by managing API requests, you can ensure the validity and security of the request.

[0071] S170. Send analysis response data corresponding to the analysis unit fragment to the first user equipment.

[0072] When the analysis response data corresponding to the analysis unit fragment is sent to the first user device, the analysis response data corresponding to the analysis unit fragment can be cleaned to remove duplicate / useless data to ensure the accuracy and readability of the data, and displayed to the first user device in the form of charts, reports, etc., so as to provide intuitive analysis results.

[0073] In this embodiment, a code analysis request sent by a first user device is received, wherein the code analysis request sent by the first user device includes: a first target code; in response to the code analysis request sent by the first user device, code segmentation is performed on the first target code based on a preset segmentation dimension to obtain a plurality of code unit fragments, each of which is an independently running code based on different functional requirements; quality detection is performed on each of the code unit fragments to obtain a quality detection value corresponding to each of the code unit fragments; based on the quality detection value corresponding to each of the code unit fragments, a code analysis identifier corresponding to each of the code unit fragments is determined, and the code analysis identifier corresponding to the code unit fragment is used to describe whether the code unit fragment needs to perform a code analysis operation; based on the code analysis identifier corresponding to each of the code unit fragments, an analysis unit fragment is obtained from a plurality of code unit fragments, and the code analysis identifier corresponding to the analysis unit fragment is used to describe that the corresponding code unit fragment needs to perform a code analysis operation; based on the analysis unit fragments and the large language model, analysis response data corresponding to the analysis unit fragments is determined; and analysis response data corresponding to the analysis unit fragments is sent to the first user device. In this way, the analysis requirements of the split code unit fragments are identified, and the analysis code fragments with analysis requirements are intelligently analyzed through the large language model to obtain the corresponding analysis response data, which simplifies the code analysis process, saves code analysis time, and effectively solves the problem of unstable analysis results caused by code analysis by developers with different experiences.

[0074] In some embodiments, the analysis response data corresponding to the analysis unit segment includes: code analysis results and code optimization tips.

[0075] The method of this embodiment also includes:

[0076] Receive a code optimization request from the first user device in response to analysis response data corresponding to the analysis unit fragment; in response to the code optimization request, perform code optimization on the analysis unit fragment based on the analysis response data corresponding to the analysis unit fragment to obtain a code optimization result for the analysis unit fragment; and send the code optimization result for the analysis unit fragment to the first user device.

[0077] When the optimization indication of the analysis unit fragment is received from the first user device, the analysis unit fragment is optimized according to the analysis response data corresponding to the analysis unit fragment, so as to realize intelligent code optimization and effectively improve the code optimization efficiency.

[0078] In some embodiments, the code analysis result is used to describe the execution level coefficient of the analysis unit segment that needs to perform code optimization operations. For example, the lower the execution level coefficient, the smaller the optimization requirement of the corresponding analysis unit segment.

[0079] The code of the analysis unit fragment is optimized based on the analysis response data corresponding to the analysis unit fragment, including:

[0080] Obtain a weight coefficient of the quality detection value corresponding to the analysis unit fragment in the quality detection values ​​corresponding to all code unit fragments; determine the optimization requirement description value corresponding to the analysis unit fragment based on the execution level coefficient of the code optimization operation required to be performed on the analysis unit fragment and the weight coefficient of the quality detection value corresponding to the analysis unit fragment in the quality detection values ​​corresponding to all code unit fragments; if the optimization requirement description value corresponding to the analysis unit fragment is less than a preset optimization threshold, perform code optimization on the analysis unit fragment based on a preset optimization strategy; if the optimization requirement description value corresponding to the analysis unit fragment is greater than or equal to the preset optimization threshold, perform code optimization on the analysis unit fragment based on a code optimization prompt.

[0081] The weight coefficient of the quality detection value corresponding to the analysis unit segment in the quality detection values ​​corresponding to all code unit segments may be the ratio of the quality detection value corresponding to the analysis unit segment to the maximum quality detection value / quality detection mean among the quality detection values ​​corresponding to all code unit segments.

[0082] Determining the optimization requirement description value corresponding to the analysis unit fragment based on the execution level coefficient of the code optimization operation that needs to be performed by the analysis unit fragment and the weight coefficient of the quality detection value corresponding to the analysis unit fragment in the quality detection values ​​corresponding to all code unit fragments may include: determining the optimization requirement description value corresponding to the analysis unit fragment as the product of the execution level coefficient of the code optimization operation that needs to be performed by the analysis unit fragment and the weight coefficient of the quality detection value corresponding to the analysis unit fragment in the quality detection values ​​corresponding to all code unit fragments.

[0083] Thus, when the optimization requirement description value corresponding to the analysis unit fragment is less than the preset optimization threshold, it indicates that the optimization requirement of the analysis unit fragment is relatively low. At this time, code optimization can be performed based on a pre-set simple preset optimization strategy; when the optimization requirement description value corresponding to the analysis unit fragment is greater than or equal to the preset optimization threshold, it indicates that the optimization requirement of the analysis unit fragment is relatively high. At this time, code optimization can be performed based on code optimization prompts to facilitate meeting different optimization requirements of the code.

[0084] In addition, the code optimization of the analysis unit fragment based on the analysis response data corresponding to the analysis unit fragment may also include:

[0085] Obtain the weight coefficient of the quality detection value corresponding to the analysis unit fragment in the quality detection values ​​corresponding to all code unit fragments; if the weight coefficient is less than a preset optimization threshold, perform code optimization on the analysis unit fragment based on a preset optimization strategy; if the weight coefficient is greater than or equal to the preset optimization threshold, perform code optimization on the analysis unit fragment based on the code optimization prompt.

[0086] In some embodiments, the method of this embodiment further includes:

[0087] Receive a code analysis request sent by a second user device, the code analysis request sent by the second user device includes: a second target code; obtain a similarity characterization value between the first target code and the second target code; if the similarity characterization value between the first target code and the second target code is greater than or equal to a preset characterization threshold, determine that the analysis response data corresponding to the analysis unit fragment is the analysis response data corresponding to the second target code; and send the analysis response data corresponding to the second target code to the second user device.

[0088] The similarity characterization value between the first target code and the second target code can be determined based on the similarity of the functional requirements between the independent running code in the first target code and the independent running code in the second target code. That is, the higher the similarity of the functional requirements between the independent running code in the first target code and the independent running code in the second target code, the greater the similarity characterization value between the first target code and the second target code; correspondingly, the lower the similarity of the functional requirements between the independent running code in the first target code and the independent running code in the second target code, the smaller the similarity characterization value between the first target code and the second target code.

[0089] Therefore, when it is determined that the similarity characterization value between the first target code and the second target code is large, it is considered that the first target code is basically similar to the second target code. At this time, the code analysis result of the first target code can be used as the code analysis result of the second target code, so as to effectively improve the analysis efficiency of other codes.

[0090] In some embodiments, the method of this embodiment further includes:

[0091] If the similarity characterization value between the first target code and the second target code is less than a preset characterization threshold, the analysis response data corresponding to the analysis unit fragment is adjusted to obtain the analysis response data corresponding to the second target code; and the analysis response data corresponding to the second target code is sent to the second user device.

[0092] Among them, when the similarity representation value between the first target code and the second target code is less than a preset representation threshold, the difference code between the second target code and the first target code can be determined, and the relevant information of the difference code can be input into the large language model, and based on the response data output by the large language model, the analysis response data corresponding to the analysis unit fragment is adjusted to effectively obtain the analysis response data corresponding to the second target code.

[0093] In summary, this embodiment has the following advantages.

[0094] Efficient understanding and interpretation of code: Through automated tools, complex code can be quickly parsed and interpreted, key business logic can be highlighted, and the time required for developers to understand the code can be significantly reduced. This is especially suitable for iterative projects involving multiple developers, which helps to quickly grasp the overall picture of the code. Comprehensive code quality assessment: Using advanced natural language processing and machine learning technologies, security vulnerabilities, performance bottlenecks, and duplicate code in the code can be automatically detected. Specific improvement suggestions are provided to ensure that the code is in the best state in terms of security, performance, and maintainability. Optimize the development process: Through automated analysis and optimization tools, developers can focus on the implementation of core business logic without having to spend a lot of energy on understanding and optimizing the code. This not only improves development efficiency, but also shortens the project delivery cycle. Improve code quality: Model-based intelligent analysis and optimization helps standardize code quality, reduce quality differences caused by different developer experience levels, provide consistent and high-quality code, and improve the reliability and maintainability of the overall project. User-friendly result display: The cleaned and processed analysis results are presented to users in a clear and easy-to-understand form, which facilitates quick optimization measures. The user feedback mechanism further optimizes the analysis and optimization process and continuously improves the overall effect of the system.

[0095] Figure 2 A structural diagram of a code processing device based on a large language model provided in this embodiment, the code processing device based on a large language model may include: a receiving module 210, a segmentation module 220, a detection module 230, a first determination module 240, an acquisition module 250, a second determination module 260 and a sending module 270.

[0096] The receiving module 210 is used to receive a code analysis request sent by a first user equipment, where the code analysis request sent by the first user equipment includes: a first target code.

[0097] The segmentation module 220 is used to respond to the code analysis request sent by the first user device, segment the first target code based on a preset segmentation dimension, and obtain multiple code unit fragments, each of which is an independent running code based on implementing different functional requirements.

[0098] The detection module 230 is used to perform quality detection on each code unit segment to obtain a quality detection value corresponding to each code unit segment.

[0099] The first determination module 240 is used to determine a code analysis identifier corresponding to each code unit segment based on the quality detection value corresponding to each code unit segment, and the code analysis identifier corresponding to the code unit segment is used to describe whether the code unit segment needs to perform a code analysis operation.

[0100] The acquisition module 250 is used to acquire an analysis unit segment from multiple code unit segments based on the code analysis identifier corresponding to each code unit segment. The code analysis identifier corresponding to the analysis unit segment is used to describe that the corresponding code unit segment needs to perform a code analysis operation.

[0101] The second determination module 260 is used to determine the analysis response data corresponding to the analysis unit segment based on the analysis unit segment and the large language model.

[0102] The sending module 270 is configured to send analysis response data corresponding to the analysis unit segment to the first user equipment.

[0103] In this embodiment, optionally, the analysis unit segment corresponds to an analysis requirement parameter, and the analysis requirement parameter is used to describe the analysis characteristics and optimization requirements of the analysis unit segment.

[0104] The second determining module 260 is specifically configured to:

[0105] Based on the analysis requirement parameters corresponding to the analysis unit fragment, the optimization configuration parameters corresponding to the analysis unit fragment when performing code optimization are determined, and the optimization configuration parameters are used to describe the reference rules based on which the analysis unit fragment is optimized; natural language processing is performed on the analysis unit fragment, the analysis requirement parameters and the optimization configuration parameters; the analysis unit fragment, the analysis requirement parameters and the optimization configuration parameters after natural language processing are input into the large language model, and the analysis response data corresponding to the analysis unit fragment is determined based on the output result of the large language model.

[0106] In this embodiment, optionally, the first determining module 240 is specifically configured to:

[0107] Based on the quality detection value corresponding to each code unit fragment and the weight coefficient of the quality detection value corresponding to each code unit fragment in the quality detection values ​​corresponding to all code unit fragments, the analysis requirement description value corresponding to each code unit fragment is determined; if the analysis requirement description value corresponding to the code unit fragment is less than a preset analysis threshold, it is determined that the code analysis identifier corresponding to the code unit fragment is used to describe that the code unit fragment does not need to perform a code analysis operation; if the analysis requirement description value corresponding to the code unit fragment is greater than or equal to the preset analysis threshold, it is determined that the code analysis identifier corresponding to the code unit fragment is used to describe that the code unit fragment needs to perform a code analysis operation.

[0108] In this embodiment, optionally, the analysis response data corresponding to the analysis unit segment includes: code analysis results and code optimization tips.

[0109] Also includes: Optimization module.

[0110] The receiving module 210 is further configured to receive a code optimization request from the first user equipment in response to the analysis response data corresponding to the analysis unit segment.

[0111] The optimization module is used to respond to the code optimization request and optimize the code of the analysis unit fragment based on the analysis response data corresponding to the analysis unit fragment to obtain the code optimization result of the analysis unit fragment.

[0112] The sending module 270 is further configured to send the code optimization result of the analysis unit segment to the first user equipment.

[0113] In this embodiment, optionally, the code analysis result is used to describe the execution level coefficient of the code optimization operation that needs to be performed on the analysis unit segment.

[0114] Optimization module, specifically used for:

[0115] Obtain a weight coefficient of the quality detection value corresponding to the analysis unit fragment in the quality detection values ​​corresponding to all code unit fragments; determine the optimization requirement description value corresponding to the analysis unit fragment based on the execution level coefficient of the code optimization operation required to be performed on the analysis unit fragment and the weight coefficient of the quality detection value corresponding to the analysis unit fragment in the quality detection values ​​corresponding to all code unit fragments; if the optimization requirement description value corresponding to the analysis unit fragment is less than a preset optimization threshold, perform code optimization on the analysis unit fragment based on a preset optimization strategy; if the optimization requirement description value corresponding to the analysis unit fragment is greater than or equal to the preset optimization threshold, perform code optimization on the analysis unit fragment based on a code optimization prompt.

[0116] In this embodiment, optionally, it also includes: a third determination module.

[0117] The receiving module 210 is further configured to receive a code analysis request sent by a second user device, where the code analysis request sent by the second user device includes: a second target code.

[0118] The acquisition module 250 is further configured to acquire similarity characterization values ​​of the first target code and the second target code.

[0119] The third determination module is used to determine that the analysis response data corresponding to the analysis unit segment is the analysis response data corresponding to the second target code if the similarity characterization value between the first target code and the second target code is greater than or equal to a preset characterization threshold.

[0120] The sending module 270 is further configured to send analysis response data corresponding to the second target code to the second user equipment.

[0121] In this embodiment, optionally, it also includes: an adjustment module.

[0122] The adjustment module is used to adjust the analysis response data corresponding to the analysis unit segment to obtain the analysis response data corresponding to the second target code if the similarity characterization value between the first target code and the second target code is less than a preset characterization threshold.

[0123] The sending module 270 is further configured to send analysis response data corresponding to the second target code to the second user equipment.

[0124] The code processing device based on the large language model provided in the present disclosure can execute the above method embodiments. Its specific implementation principles and technical effects can be found in the above method embodiments, and the present disclosure will not repeat them here.

[0125] The present application also provides a computer device. Figure 3 , Figure 3 This is a basic structural block diagram of the computer device in this embodiment.

[0126] The computer device includes a memory 310 and a processor 320 that are connected to each other through a system bus. It should be noted that the figure only shows a computer device with a memory 310 and a processor 320, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.

[0127] Computer devices can be computing devices such as desktop computers, notebooks, PDAs, and cloud servers. Computer devices can interact with users through keyboards, mice, remote controls, touch pads, or voice control devices.

[0128] The memory 310 includes at least one type of readable storage medium, and the readable storage medium includes a non-volatile memory or a volatile memory, such as a flash memory, a hard disk, a multimedia card, a card-type memory (such as an SD or DX memory, etc.), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc., and the RAM may include a static RAM or a dynamic RAM. In some embodiments, the memory 310 may be an internal storage unit of a computer device, such as a hard disk or a memory of the computer device. In other embodiments, the memory 310 may also be an external storage device of a computer device, such as a plug-in hard disk, a smart memory card (SMC), a secure digital (SD) card, or a flash card (Flash Card), etc., equipped on the computer device. Of course, the memory 310 may also include both an internal storage unit of the computer device and an external storage device thereof. In this embodiment, the memory 310 is generally used to store an operating system and various application software installed on the computer device, such as the program code of the above method, etc. In addition, the memory 310 may also be used to temporarily store various data that have been output or are to be output.

[0129] The processor 320 is generally used to perform the overall operation of the computer device. In this embodiment, the memory 310 is used to store program codes or instructions, the program code includes computer operation instructions, and the processor 320 is used to execute the program codes or instructions stored in the memory 310 or process data, such as running the program code of the above method.

[0130] In this article, the bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus system can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0131] Another embodiment of the present application also provides a computer-readable medium, which may be a computer-readable signal medium or a computer-readable medium. A processor in a computer reads a computer-readable program code stored in the computer-readable medium, so that the processor can execute the functional actions specified in each step or a combination of steps in the above method; and generate a device for implementing the functional actions specified in each block or a combination of blocks in the block diagram.

[0132] Computer-readable media include but are not limited to electronic, magnetic, optical, electromagnetic, infrared memory or semiconductor systems, devices or apparatuses, or any appropriate combination of the foregoing, the memory is used to store program codes or instructions, the program codes include computer operating instructions, and the processor is used to execute the program codes or instructions of the above methods stored in the memory.

[0133] For the definitions of memory and processor, please refer to the description of the aforementioned computer device embodiment and will not be repeated here.

[0134] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0135] Each functional unit or module in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0136] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., and other media that can store program codes.

[0137] In the claims, any reference symbols placed between brackets shall not be construed as limiting the claims. The word "comprising" described in the present application does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present application can be implemented with the aid of hardware comprising several different elements and with the aid of a suitably programmed computer. In a unit claim that lists a number of devices, several units of these devices may be embodied by the same hardware item. The use of first, second, and third, etc. does not indicate any order, and these words may be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be understood as limitations on the order of execution.

[0138] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A code processing method based on a large language model, characterized in that: include: Receiving a code analysis request sent by a first user device, where the code analysis request sent by the first user device includes: a first target code; In response to the code analysis request sent by the first user device, code segmentation is performed on the first target code based on a preset segmentation dimension to obtain a plurality of code unit fragments, each of the code unit fragments being an independent running code based on realizing different functional requirements; Performing quality detection on each of the code unit segments to obtain a quality detection value corresponding to each of the code unit segments; Based on the quality detection value corresponding to each of the code unit fragments, a code analysis identifier corresponding to each of the code unit fragments is determined, and the code analysis identifier corresponding to the code unit fragment is used to describe whether the code unit fragment needs to perform a code analysis operation; the determining the code analysis identifier corresponding to each of the code unit fragments based on the quality detection value corresponding to each of the code unit fragments includes: determining the analysis requirement description value corresponding to each of the code unit fragments based on the quality detection value corresponding to each of the code unit fragments and the weight coefficient of the quality detection value corresponding to each of the code unit fragments in the quality detection values ​​corresponding to all of the code unit fragments; if the analysis requirement description value corresponding to the code unit fragment is less than a preset analysis threshold, determining that the code analysis identifier corresponding to the code unit fragment is used to describe that the code unit fragment does not need to perform a code analysis operation; if the analysis requirement description value corresponding to the code unit fragment is greater than or equal to the preset analysis threshold, determining that the code analysis identifier corresponding to the code unit fragment is used to describe that the code unit fragment needs to perform a code analysis operation; Based on the code analysis identifier corresponding to each of the code unit fragments, obtaining an analysis unit fragment from the plurality of code unit fragments, wherein the code analysis identifier corresponding to the analysis unit fragment is used to describe that a code analysis operation needs to be performed on the corresponding code unit fragment; Determining analysis response data corresponding to the analysis unit segment based on the analysis unit segment and the large language model; Sending analysis response data corresponding to the analysis unit fragment to the first user equipment.

2. The method according to claim 1, characterized in that The analysis unit fragments correspond to analysis requirement parameters, and the analysis requirement parameters are used to describe the analysis characteristics and optimization requirements of the analysis unit fragments; The determining, based on the analysis unit segment and the large language model, analysis response data corresponding to the analysis unit segment includes: Based on the analysis requirement parameters corresponding to the analysis unit fragments, determining the optimization configuration parameters corresponding to the analysis unit fragments when performing code optimization, wherein the optimization configuration parameters are used to describe the reference rules based on which the analysis unit fragments are optimized; Performing natural language processing on the analysis unit fragment, the analysis requirement parameter, and the optimization configuration parameter; The analysis unit fragment, the analysis requirement parameter and the optimization configuration parameter after natural language processing are input into the large language model, and the analysis response data corresponding to the analysis unit fragment is determined based on the output result of the large language model.

3. The method according to claim 1, characterized in that The analysis response data corresponding to the analysis unit segment includes: code analysis results and code optimization tips; The method further comprises: receiving a code optimization request from the first user equipment in response to analysis response data corresponding to the analysis unit segment; In response to the code optimization request, code optimization is performed on the analysis unit fragment based on the analysis response data corresponding to the analysis unit fragment to obtain a code optimization result of the analysis unit fragment; Sending a code optimization result of the analysis unit segment to the first user equipment.

4. The method according to claim 3, characterized in that The code analysis result is used to describe the execution level coefficient of the code optimization operation required to be performed by the analysis unit segment; The performing code optimization on the analysis unit fragment based on the analysis response data corresponding to the analysis unit fragment comprises: Obtaining a weight coefficient of the quality detection value corresponding to the analysis unit segment in the quality detection values ​​corresponding to all the code unit segments; Determine the optimization requirement description value corresponding to the analysis unit segment based on the execution level coefficient of the code optimization operation required to be performed by the analysis unit segment and the weight coefficient of the quality detection value corresponding to the analysis unit segment in the quality detection values ​​corresponding to all the code unit segments; If the optimization requirement description value corresponding to the analysis unit fragment is less than a preset optimization threshold, code optimization is performed on the analysis unit fragment based on a preset optimization strategy; If the optimization requirement description value corresponding to the analysis unit segment is greater than or equal to the preset optimization threshold, code optimization is performed on the analysis unit segment based on the code optimization hint.

5. The method according to claim 1, characterized in that: Also includes: Receiving a code analysis request sent by a second user device, where the code analysis request sent by the second user device includes: a second target code; Obtaining similarity characterization values ​​of the first target code and the second target code; If the similarity characterization value between the first target code and the second target code is greater than or equal to a preset characterization threshold, determining that the analysis response data corresponding to the analysis unit segment is the analysis response data corresponding to the second target code; Send analysis response data corresponding to the second target code to the second user equipment.

6. The method according to claim 5, characterized in that Also includes: If the similarity characterization value between the first target code and the second target code is less than the preset characterization threshold, data adjustment is performed on the analysis response data corresponding to the analysis unit segment to obtain the analysis response data corresponding to the second target code; Send analysis response data corresponding to the second target code to the second user equipment.

7. A code processing device based on a large language model, characterized in that: include: A receiving module, configured to receive a code analysis request sent by a first user device, wherein the code analysis request sent by the first user device includes: a first target code; a segmentation module, configured to respond to the code analysis request sent by the first user device, and segment the first target code based on a preset segmentation dimension to obtain a plurality of code unit segments, each of which is an independent running code based on realizing different functional requirements; A detection module, used to perform quality detection on each of the code unit segments to obtain a quality detection value corresponding to each of the code unit segments; A first determination module is configured to determine a code analysis identifier corresponding to each code unit fragment based on a quality detection value corresponding to each code unit fragment, wherein the code analysis identifier corresponding to the code unit fragment is used to describe whether the code unit fragment needs to perform a code analysis operation; the first determination module is specifically configured to: determine an analysis requirement description value corresponding to each code unit fragment based on a quality detection value corresponding to each code unit fragment and a weight coefficient of the quality detection value corresponding to each code unit fragment in the quality detection values ​​corresponding to all code unit fragments; if the analysis requirement description value corresponding to the code unit fragment is less than a preset analysis threshold, determine that the code analysis identifier corresponding to the code unit fragment is used to describe that the code unit fragment does not need to perform a code analysis operation; if the analysis requirement description value corresponding to the code unit fragment is greater than or equal to the preset analysis threshold, determine that the code analysis identifier corresponding to the code unit fragment is used to describe that the code unit fragment needs to perform a code analysis operation; An acquisition module, configured to acquire an analysis unit segment from the plurality of code unit segments based on a code analysis identifier corresponding to each of the code unit segments, wherein the code analysis identifier corresponding to the analysis unit segment is used to describe that a code analysis operation needs to be performed on the corresponding code unit segment; A second determination module, configured to determine analysis response data corresponding to the analysis unit segment based on the analysis unit segment and the large language model; A sending module is used to send analysis response data corresponding to the analysis unit fragment to the first user equipment.

8. A computer device, characterized in that: The method comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, a code processing method based on a large language model as described in any one of claims 1 to 6 is implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the code processing method based on a large language model as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Code defect detection method and device based on large model and related equipment

    CN117743164A