Code repairing method, electronic equipment and computer readable storage medium
The initial code file is repaired through the target code repair model and a code change file is generated, which solves the problem that the code file generated by the code model in the existing technology cannot be directly adopted, improves the code repair efficiency and project development speed, and saves labor costs.
Patent Information
- Application Number
- CN202411408278.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2024-11-08
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing code models can only generate code files, which cannot be directly adopted by users, resulting in high labor costs and low efficiency in maintaining and updating code projects.
By obtaining the initial code file and modifying requirements, using the object code repair model to code repair the initial code file, and generate a code change file to indicate the code difference between the object code file and the initial code file. Users can directly adopt the code change file to achieve the Code fix.
It improves the efficiency of code repair, accelerates the project development process, saves labor costs, and solves the problem that the code files generated by the code model cannot be directly adopted.
Smart Images

Figure CN118916068A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the fields of large model technology and computer technology, and in particular to a code repair method, an electronic device and a computer-readable storage medium. Background Art
[0002] In the field of software development, the maintenance and update of code projects is an ongoing process. In daily code project development scenarios, developers will modify the project based on the requirements raised by the project manager or the defects reported by users. This process involves steps such as analyzing requirements, locating code, modifying code, and generating change forms, and is an indispensable part of software development.
[0003] Currently, when developers modify code projects, they use existing code models to analyze code modification requirements and generate modified code files. However, if users want to adopt the modified code files, they can only manually modify the corresponding code files based on the modified code files, which increases the workload and complexity of users and leads to low efficiency in code project maintenance and update.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present application provide a code repair method, an electronic device, and a computer-readable storage medium to at least solve the technical problem in the related art that the code model can only generate a code file, and the user cannot directly adopt the code file, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0006] According to one aspect of an embodiment of the present application, a code repair method is provided, comprising: obtaining an initial code file and a modification requirement, wherein the modification requirement is a modification requirement for the initial code file; performing code repair on the initial code file based on the modification requirement using a target code repair model to obtain a code change file; wherein the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in an initial code file sample is modified into a target code snippet, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after performing code repair on the initial code file.
[0007] According to another aspect of an embodiment of the present application, a code repair method is also provided, comprising: obtaining a code repair request through a first application programming interface; returning a code repair response through a second application programming interface; wherein the request data carried in the code repair request comprises: an initial code file and a modification requirement, and the response data carried in the code repair response comprises: a code change file, the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file based on the modification requirement using a target code repair model, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified to a target code snippet, the code change file is used to represent the code difference between the target code file and the initial code file, and the target code file is obtained after performing code repair on the initial code file.
[0008] According to another aspect of an embodiment of the present application, a code repair method is also provided, comprising: obtaining a currently input code repair dialogue request; returning a code repair dialogue reply in response to the code repair dialogue request; wherein the request data carried in the code repair dialogue request comprises: an initial code file and a modification requirement, and the information carried in the code repair dialogue reply comprises: a code change file, the modification requirement being a modification requirement for the initial code file, the code change file being obtained by performing code repair on the initial code file using a target code repair model based on the modification requirement, the target code repair model being obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file being used to indicate that a specified code snippet in an initial code file sample is modified into a target code snippet, the code change file being used to represent the code difference between the target code file and the initial code file, the target code file being obtained by performing code repair on the initial code file; and displaying the code change file in a graphical user interface.
[0009] According to another aspect of an embodiment of the present application, a model training method is also provided, including: obtaining an initial code file sample and a modification requirement sample, wherein the modification requirement sample is a modification requirement for the initial code file sample; generating a modification suggestion file based on the initial code file sample and the modification requirement sample, wherein the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified into a target code fragment; training an initial code repair model based on the modification suggestion file to obtain a code change file, wherein the code change file is used to represent the code difference between the target code file sample and the initial code file sample, and the target code file sample is obtained after code repair is performed on the initial code file sample; generating a target code repair model based on the code change file.
[0010] According to another aspect of an embodiment of the present application, an electronic device is also provided, including: a memory storing an executable program; and a processor for running the program, wherein when the program is running, any one of the above-mentioned code repair methods or any one of the above-mentioned model training methods is executed.
[0011] According to another aspect of an embodiment of the present application, a computer-readable storage medium is also provided, which includes a stored executable program, wherein when the executable program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned code repair methods or any one of the above-mentioned model training methods.
[0012] According to another aspect of an embodiment of the present application, a computer program product is also provided, including a computer program, which, when executed by a processor, implements any one of the above-mentioned code repair methods or executes any one of the above-mentioned model training methods.
[0013] In an embodiment of the present application, an initial code file and a modification requirement for the initial code file are obtained, and then a target code repair model is used to perform code repair on the initial code file based on the modification requirement, thereby obtaining a code change file for representing the code difference between the target code file and the initial code file, wherein the target code file is obtained after code repairing the initial code file, the target code repair model is obtained after training the initial code repair model based on a modification suggestion file, and the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified to a target code fragment, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, allowing users to directly adopt the code modification method of the code change file to solve the shortcomings in the existing project, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, and further solving the technical problem in the related art that the code model can only generate code files, and users cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0014] It is easy to notice that the above general description and the following detailed description are only for the purpose of exemplifying and explaining the present application, and do not constitute a limitation of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0016] Figure 1 is a schematic diagram of an application scenario of a code repair method according to an embodiment of the present application;
[0017] Figure 2 is a flow chart of a code repair method according to an embodiment of the present application;
[0018] Figure 3 is a flowchart of a code repair method according to an embodiment of the present application;
[0019] Figure 4 is a flow chart of a code repair method according to an embodiment of the present application;
[0020] Figure 5 is a flow chart of a code repair method according to an embodiment of the present application;
[0021] Figure 6 is a flow chart of a model training method according to an embodiment of the present application;
[0022] Figure 7 is a structural schematic diagram of a code repair device according to an embodiment of the present application;
[0023] Figure 8 is a schematic structural diagram of another code repair device according to an embodiment of the present application;
[0024] Fig. 9 is a structural schematic diagram of yet another code repair device according to an embodiment of the present application;
[0025] Fig.10 is a structural schematic diagram of a model training device according to an embodiment of the present application;
[0026] Fig.11 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] 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 drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] The technical solution provided in this application is mainly implemented using large-scale model technology. The large model here refers to a deep learning model with large-scale model parameters, which can usually contain hundreds of millions, tens of billions, hundreds of billions, trillions or even more than 10 trillion model parameters. The large model can also be called a foundation model / foundation model. The large model is pre-trained with large-scale unlabeled corpus to produce a pre-trained model with more than 100 million parameters. This model can adapt to a wide range of downstream tasks, and the model has good generalization ability, such as large-scale language model (Large Language Model, LLM), multi-modal pre-training model, etc.
[0030] It should be noted that when the large model is actually applied, the pre-trained model can be fine-tuned through a small number of samples so that the large model can be applied to different tasks. For example, the large model can be widely used in natural language processing (NLP), computer vision, speech processing and other fields, and can be specifically applied to computer vision tasks such as visual question answering (VQA), image caption (IC), image generation, etc. It can also be widely used in natural language processing tasks such as text-based sentiment classification, text summary generation, and machine translation. Therefore, the main application scenarios of the large model include but are not limited to digital assistants, intelligent robots, search, online education, office software, e-commerce, intelligent design, etc. In the embodiment of the present application, the code repair model is used to repair the code file (such as code update, code deletion, code addition, etc.) in the code repair scenario as an example for explanation.
[0031] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following explanations:
[0032] Intelligent Coding Assistant: Using artificial intelligence (AI) and machine learning technology, it provides functions such as automatic code completion, code snippet generation, real-time error detection and correction, and code optimization to help developers reduce repetitive work and significantly improve programming efficiency and code quality.
[0033] Code change form: also known as diff form. Diff is the abbreviation of "difference", which is widely used in software development to represent the differences between files. The diff tool compares the contents of two files and generates a list showing the differences between the two files. This list is usually called a "diff file".
[0034] git tool: is an open source distributed version control system used to effectively and quickly handle version management of projects from small to large.
[0035] git patch: is a file containing file difference information, describing how to change from one version of a file to another version of a file. This difference information can be used to apply the changes to other copies in order to synchronize the changes.
[0036] Markdown format: is a lightweight markup language.
[0037] The code repair model in the related art has the following defects.
[0038] Defect 1: The output of the model does not include an overall plan for the repair results, so users cannot have an intuitive and macroscopic understanding of the model modification results.
[0039] Defect 2: The output of the model does not include the change form (i.e., diff form), so users cannot directly adopt the change results. They can only manually modify the file through the code output by the model, resulting in high labor costs and low code repair efficiency.
[0040] With respect to the above-mentioned defects, no effective solution has been proposed before the present application.
[0041] According to an embodiment of the present application, a code repair method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0042] Considering the huge number of model parameters of the large model and the limited computing resources of the mobile terminal, the above code repair method provided in the embodiment of the present application can be applied to Figure 1 The application scenarios shown are not limited to these. Figure 1 In the application scenario shown, the large model is deployed in the server 10, and the server 10 can be connected to one or more client devices 20 through a local area network connection, a wide area network connection, an Internet connection, or other types of data networks. The client device 20 here may include but is not limited to: a smart phone, a tablet computer, a laptop computer, a PDA, a personal computer, a smart home device, a vehicle-mounted device, etc. The client device 20 can interact with the user through a graphical user interface to implement the call of the large model, thereby implementing the method provided in the embodiment of the present application.
[0043] In an embodiment of the present application, a system consisting of a client device and a server can execute the following steps: the client device executes the steps of obtaining the modification requirements input by the user in the graphical user interface, and obtaining the initial code file to be modified corresponding to the modification requirements, and sending the initial code file and the modification requirements to the server; the server executes the steps of performing code repair on the initial code file based on the modification requirements using a target code repair model to obtain a code change file, and returning the code change file to the client device. It should be noted that when the operating resources of the client device can meet the deployment and operating conditions of the large model, the embodiment of the present application can be carried out in the client device.
[0044] Under the above operating environment, this application provides Figure 2 The code fix shown. Figure 2 is a flow chart of a code repair method according to an embodiment of the present application. Figure 2 As shown, the method may include the following steps:
[0045] Step S21, obtaining an initial code file and a modification requirement, wherein the modification requirement is a modification requirement for the initial code file;
[0046] Step S22, based on the modification requirements, the target code repair model is used to perform code repair on the initial code file to obtain a code change file; wherein, the target code repair model is obtained by training the initial code repair model based on the modification suggestion file, the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified to a target code fragment, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after code repair is performed on the initial code file.
[0047] In the embodiment of the present application, the initial code file can be understood as a code file to be repaired, that is, a code file that needs to be repaired, and the initial code file is used to implement the instructions and logic of the software function. Exemplarily, the initial code file can be a code file of an existing project, which is used to implement the software function of the existing project.
[0048] It is understandable that the initial code file may include multiple types of files, each of which has a specific function and purpose, such as source code files, header files, resource files, configuration files, document files, script files, etc., which are not limited here.
[0049] Modification requirements are the requirements for modifying the initial code files. Modification requirements can be understood as modification requirements suggestions put forward by R&D personnel for existing projects or defects raised by users for existing projects. The initial code files are repaired based on the modification requirements so that the repaired code files can meet the requirements of R&D personnel and users.
[0050] Optionally, the modification requirements may include requirement text, project tree structure and project meta information. Among them, the requirement text may be an introduction to development requirements or defect problems, the requirement text may be in text form in various languages, or audio files in various languages may be converted into text form, which is not limited here. The project tree structure can be understood as a hierarchical structure of project files and directories. Exemplarily, the project tree structure may include the organizational structure, file name, content introduction, etc. of each file in an existing project, which is not limited here. Project meta information is used to describe the basic information of the project. Exemplarily, the project meta information may include the framework on which the project depends and the version information of the third-party packages on which the project depends, which is not limited here.
[0051] The target code repair model can be understood as an intelligent coding assistant proposed in the embodiment of the present application. The target code repair model can perform code repair on the code file to be modified according to the input modification requirements, thereby outputting a code change file.
[0052] The target code repair model is obtained by training the initial code repair model based on the modification suggestion file, which can be understood as training the initial code repair model according to the modification suggestion file, so as to obtain the target code repair model. Among them, the initial code repair model can be understood as the code repair model before training. The target code repair model can be a large model or other deep learning model, which is not limited here.
[0053] The modification suggestion file is generated based on the initial code file sample and the modification requirement sample, and the modification suggestion file is used to indicate that the specified code snippet in the initial code file sample is modified to the target code snippet. It can be understood that when training the code repair model, a modification suggestion file can be generated based on the initial code file sample and the modification requirement sample, and the modification suggestion file is used to indicate which code snippet in which code file sample in the initial code file sample should be modified to what. Exemplarily, each line in the code file is usually marked with a line number, and the code snippet to be modified can be determined by indicating the line number in the initial code file, which is not limited here.
[0054] The target code repair model in the embodiment of the present application can output a code change file, which is used to represent the code difference between the target code file and the initial code file. The code change file can be understood as a diff file, which is used to show the difference between the target code file and the initial code file. The target code file is obtained after the initial code file is repaired, which can be understood as the target code file being the code file after the initial code file is repaired based on the modification requirements.
[0055] In an embodiment of the present application, an initial code file and modification requirements for the initial code file are obtained, and then a target code repair model is used to perform code repair on the initial code file based on the modification requirements, thereby obtaining a code change file for representing the code difference between the target code file and the initial code file. The code change file enables the user to directly adopt the code modification method, that is, directly replace the initial code file with the target code file, thereby resolving the shortcomings existing in the existing project, thereby improving the efficiency of code repair, accelerating the entire project development process, and saving manpower.
[0056] The above-mentioned code repair method provided in the embodiment of the present application can be applied to, but is not limited to, application scenarios involving code repair of projects or products in the fields of e-commerce services, educational services, legal services, medical services, conference services, social network services, financial product services, logistics services and navigation services, for example: code repair application scenarios for e-commerce service projects or products, code repair application scenarios for educational service projects or products, code repair application scenarios for legal service projects or products, etc., which are not limited here.
[0057] According to an embodiment of the present application, an initial code file and modification requirements for the initial code file are obtained, and then a target code repair model is used to perform code repair on the initial code file based on the modification requirements, thereby obtaining a code change file for representing the code difference between the target code file and the initial code file, wherein the target code file is obtained after code repairing the initial code file, the target code repair model is obtained after training the initial code repair model based on a modification suggestion file, and the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified to a target code fragment, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, allowing users to directly adopt the code modification method of the code change file to solve the shortcomings in existing projects, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, and further solving the technical problem in the related art that the code model can only generate code files, and users cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0058] In an optional embodiment, the code repair method further includes the following method steps:
[0059] Step S23, in response to receiving the adopting change instruction, performing code repair on the initial code file based on the code change file to obtain a target code file.
[0060] In the embodiment of the present application, after the code change file is obtained through the target code repair model, if an adopt change instruction is received, the initial code file will be repaired based on the code change file to obtain the target code file.
[0061] The adopt change instruction can be understood as an instruction generated by a user trigger, and the adopt change instruction is used to instruct to repair the initial code file based on the code change file. Exemplarily, the code change file can be in the standard form of git patch. After the user obtains the code change file, the user can use the git tool to directly modify the initial code file, thereby modifying the initial code file into a target code file.
[0062] In an optional embodiment, in step S22, the target code repair model is used to repair the initial code file based on the modification requirements to obtain the code change file, including the following method steps:
[0063] Step S221, generating a modification plan for the initial code file using the target code repair model based on the modification requirements, and determining candidate code segments from the initial code file using the target code repair model based on the modification requirements, wherein the modification plan includes at least one modification step, and the candidate code segments include code segments to be modified corresponding to any modification step;
[0064] Step S222, generating a modification suggestion file based on the modification plan and the candidate code snippets;
[0065] Step S223: Generate a code change file based on the modification suggestion file.
[0066] In the embodiment of the present application, when the target code repair model is used to repair the initial code file based on the modification requirements to obtain the code change file, the target code repair model is used to generate a modification plan for the initial code file based on the modification requirements, and the target code repair model is used to determine the candidate code fragments from the initial code file based on the modification requirements. Among them, the modification plan includes at least one modification step, and the modification plan can be understood as a detailed plan for the subsequent modification content. The modification plan may include multiple steps, and each step includes a modification plan for which part of the content of which code file.
[0067] The candidate code snippets include the code snippets to be modified corresponding to any modification step. It can be understood that each modification step corresponds to a code snippet to be modified. The candidate code snippets include the code snippets to be modified corresponding to multiple modification steps.
[0068] Exemplarily, the target code repair model can generate a modification plan for the initial code file based on the requirement text, project tree structure and project meta-information, and can determine candidate code snippets from the initial code file based on the requirement text, project tree structure and project meta-information.
[0069] After determining the modification plan and candidate code snippets, the target code repair model will generate a modification suggestion file based on the modification plan and candidate code snippets, that is, the target code repair model will determine which part of the candidate code snippets should be modified based on the modification plan and candidate code snippets. Finally, a code change file is generated based on the modification suggestion file, that is, the code difference between the code snippet before and after the modification is presented through the modification method indicated by the modification suggestion file to obtain a code change file.
[0070] In an optional embodiment, in step S221, determining the candidate code snippet from the initial code file based on the modification requirement includes the following method steps:
[0071] Step S2211, generating a search request based on the modification requirement, wherein the search request is used to request a code search for the initial code file;
[0072] Step S2212, translating the modification requirement based on the search request and the preset language form to obtain a requirement translation text;
[0073] Step S2213: searching the initial code file based on the search request and the required translation text to obtain candidate code snippets.
[0074] In an embodiment of the present application, when determining candidate code snippets from an initial code file based on modification requirements, a retrieval request can be generated based on the modification requirements, wherein the retrieval request is used to request code retrieval of the initial code file, that is, a retrieval request for requesting code retrieval of the initial code file is generated based on the requirement text, the project tree structure and the project meta-information.
[0075] Then, based on the search request and the preset language form, the modification requirement is translated to obtain the requirement translation text, which can be understood as then translating the requirement text based on the search request and the preset language form to obtain the requirement translation text. The preset language form can be English, Chinese, Japanese, etc., which is not limited here. By interpreting the requirement text and translating it into text in the preset language form, it is convenient to search the code of the entire project so as to search for the code snippets that need to be modified.
[0076] After obtaining the required translation text, the initial code file is searched based on the search request and the required translation text to obtain candidate code snippets.
[0077] In an optional embodiment, in step S2213, searching the initial code file based on the search request and the required translation text to obtain the candidate code snippet includes the following method steps:
[0078] Step S22131, segmenting the initial code file based on the code language of the initial code file to obtain segmented code segments, wherein the code logics between the segmented code segments are independent of each other, and the code length of the segmented code segments is less than a preset code length;
[0079] Step S22132: searching the segmented code snippets based on the search request and the required translation text to obtain candidate code snippets.
[0080] In the embodiment of the present application, when the initial code file is searched based on the search request and the required translation text to obtain the candidate code fragments, the initial code file can be segmented based on the code language of the initial code file to obtain segmented code fragments, which can be understood as performing more accurate code segmentation and segmentation on the initial code file according to the characteristics of the code language to obtain segmented code fragments. Among them, the code logics between the segmented code fragments are independent of each other, and the code length of the segmented code fragments is less than the preset code length. It can be understood that each code fragment obtained after segmenting the initial code file has relatively complete independent logic and relatively short content.
[0081] After the segmented code snippets are obtained, the segmented code snippets are retrieved based on the search request and the required translation text, thereby obtaining candidate code snippets.
[0082] In an optional embodiment, in step S22132, searching the segmented code snippets based on the search request and the required translation text to obtain the candidate code snippets includes the following method steps:
[0083] Step S221321, determining a correlation value between the segmented code fragment and the required translation text based on the search request;
[0084] Step S221322, sorting the segmented code fragments based on the correlation values to obtain a sorting result;
[0085] Step S221323, determining candidate code snippets based on the segmented code snippets within a preset ranking range in the sorting results.
[0086] In an embodiment of the present application, when the segmented code fragments are retrieved based on the search request and the required translation text to obtain the candidate code fragments, the correlation value between the segmented code fragments and the required translation text can be determined based on the search request, which can be understood as determining whether each segmented code fragment includes a code fragment that needs to be repaired, that is, determining the degree of correlation between each segmented code fragment and the required translation text to obtain the correlation value. By determining the correlation value between each segmented code fragment and the required translation text, it is possible to accurately determine whether each segmented code fragment includes a code fragment that needs to be repaired. It can be understood that the larger the correlation value, the more likely it is that the segmented code fragment includes a code fragment that needs to be repaired.
[0087] After determining the relevance value corresponding to each segmented code snippet, the segmented code snippets are sorted based on the relevance value to obtain a sorting result. It can be understood that each segmented code snippet is sorted according to the size of the relevance value corresponding to each segmented code snippet. For example, each segmented code snippet can be sorted from large to small according to the relevance value to obtain a sorting result, thereby facilitating and quickly retrieving the code snippet that needs to be repaired.
[0088] After the sorting results are obtained, candidate code snippets are determined based on the segmented code snippets within a preset ranking range in the sorting results. Exemplarily, the preset ranking range may be the K segmented code snippets with the highest correlation values in the sorting results, where K is a positive integer. That is, the K code snippets with the highest correlation values in the sorting results are selected as candidate code snippets, thereby improving the accuracy and efficiency of code repair.
[0089] In an optional embodiment, in step S221321, determining the correlation value between the segmented code fragment and the required translation text based on the search request includes the following method steps:
[0090] Step S2213211, determining the correlation value between the segmented code fragment and the required translation text based on the search request and a preset search algorithm, wherein the preset search algorithm includes at least one of the following: a text content search algorithm and a vector search algorithm.
[0091] In the embodiment of the present application, when determining the correlation value between the segmented code fragment and the required translation text based on the search request, the correlation value between the segmented code fragment and the required translation text can be determined based on the search request and a preset search algorithm. The preset search algorithm includes at least one of the following: a text content search algorithm and a vector search algorithm.
[0092] Among them, the text content retrieval algorithm directly relies on the text content of the document for retrieval. For example, during the retrieval, the code logic, code snippets, etc. that match the text content of the required translation text will be searched in the segmented code fragments according to the text content of the required translation text, so as to determine the degree of matching and obtain the correlation value.
[0093] The vector retrieval algorithm converts both the segmented code snippets and the required translation text into vectors of the same dimension through the Vector Space Model (VSM), which are represented in a common multidimensional space. During retrieval, the relevance value is obtained by calculating the similarity (such as cosine similarity) between the segmented code snippet vector and the required translation text vector.
[0094] It is understandable that the preset search algorithm may also include other algorithms, which are not limited here. The correlation values between the segmented code snippets and the required translation text are determined by a plurality of preset search algorithms, thereby improving the search efficiency and the search accuracy.
[0095] It can be seen that in the embodiment of the present application, when searching for segmented code snippets and obtaining candidate code snippets, two steps of segmentation and retrieval recall will be performed in sequence. When segmenting the snippets, more accurate code segmentation will be performed based on the characteristics of the specific code language, so that each segmented snippet has a relatively complete independent logic and the content is relatively short. When retrieving and recalling, a variety of retrieval methods (such as text content-based retrieval, vector-based retrieval, etc.) will be combined in the form of multi-way recall to try to balance the efficiency and recall rate of retrieval as much as possible, so that the snippets that really need to be modified are recalled among the higher-ranked snippets, and the K code snippets with the highest relevance are returned as candidates.
[0096] In an optional embodiment, in step S222, generating a modification suggestion file based on the modification plan and the candidate code snippets includes the following method steps:
[0097] Step S2221, determining a modified code snippet from the candidate code snippets based on the modification plan, wherein the modified code snippet corresponds to the modification step one by one;
[0098] Step S2222, based on the modification plan and the modified code snippet, generating a file path of the code file to which the modified code snippet belongs, a starting line number and an ending line number of the modified code snippet, and a target code snippet corresponding to the modified code snippet;
[0099] Step S2223, generating a modification suggestion file based on the file path of the code file to which the modified code snippet belongs, the starting line number and the ending line number of the modified code snippet, and the target code snippet corresponding to the modified code snippet.
[0100] In the embodiment of the present application, when a modification suggestion file is generated based on the modification plan and the candidate code snippets, the modified code snippets are determined from the candidate code snippets based on the modification plan, wherein the modified code snippets correspond to the modification steps one by one. It is understandable that only some or all of the candidate code snippets may really need to be repaired, so based on the modification plan, the code snippets that really need to be modified corresponding to each modification step are searched in the candidate code snippets, thereby obtaining the modified code snippets.
[0101] After obtaining the modified code snippet, the file path of the code file to which the modified code snippet belongs, the starting line number and the ending line number of the modified code snippet, and the target code snippet corresponding to the modified code snippet are generated based on the modification plan and the modified code snippet. This can be understood as generating relevant content for indicating what kind of modified code snippet the code snippet to be repaired should be modified into. Among them, the target code snippet is the code snippet obtained after the modified code snippet is repaired, and the target code snippet corresponds to the modified code snippet one by one.
[0102] Finally, a modification suggestion file is generated based on the file path of the code file to which the modified code snippet belongs, the starting line number and the ending line number of the modified code snippet, and the target code snippet corresponding to the modified code snippet.
[0103] It can be seen that when generating a modification suggestion file, the code snippet corresponding to each modification step will be found from the candidate code snippets based on the modification plan, and the modified code that the code snippet should be modified into will be output, that is, the path of the code file to be modified, the starting line number and the ending line number of the code snippet to be modified, and the modified code snippet will be output.
[0104] It can be understood that when the code snippet at the specified line and the modified code snippet indicate the same code snippet, the target code snippet corresponding to the modified code snippet is the same as the target code snippet after the code snippet at the specified line is modified.
[0105] In an optional embodiment, the code repair method further includes the following method steps:
[0106] Step S2224, output the natural language explanation corresponding to the modification step.
[0107] In an embodiment of the present application, while generating a modification suggestion file, a natural language explanation corresponding to the modification steps can also be output, that is, the meaning of the modification steps explained in natural language is output and displayed to the user to help the user understand the specific content of the modification steps.
[0108] Exemplarily, the natural language interpretation may be in Chinese, English, Japanese, etc., which is not limited here.
[0109] In an optional embodiment, in step S223, generating a code change file based on the modification suggestion file includes the following method steps:
[0110] Step S2231, generating a code change file based on the modification suggestion file, the candidate code snippets and the initial code file.
[0111] In the embodiment of the present application, when generating a code change file, the purpose of using candidate code snippets is to enable the model to know the form and content of the code before modification, so as to facilitate the model to determine which ones need to be modified. The purpose of using the initial code file is to enable the model to obtain more information and improve the accuracy of the generated code change file.
[0112] Therefore, a code change file is jointly generated based on the modification suggestion file, the candidate code snippets and the initial code file, so that the user can directly adopt the code change file and manage it using the git tool, making this method more standardized and universal.
[0113] Figure 3 is a flowchart of a code repair method according to an embodiment of the present application, such as Figure 3 As shown, an embodiment of the present application proposes a method for automatically generating warehouse-level code repair suggestions, which is mainly based on an existing large code model to construct a multi-agent framework, and solves complex project development problems through mutual collaboration between multiple agents. Specifically, the following agents are included: a demand analysis agent, a code retrieval agent, a modification suggestion agent, and a change generation agent.
[0114] Among them, the demand analysis agent is used to accept the user's user requirements (i.e., modification requirements), that is, it mainly receives the requirement text, project tree structure and project meta information. Among them, the requirement text may be a brief introduction to development requirements or a defect problem introduction. The project tree structure contains the organizational structure, file name, and content introduction of each file in the project. The project meta information includes the framework that the project depends on, the version information of the third-party package that the project depends on, etc. Then, the demand analysis agent will generate a detailed modification plan and a request for retrieval of the project code (i.e., retrieval request) based on the user requirements and the code repository (i.e., the initial code file) of the project corresponding to the user requirements. Among them, the modification plan is a detailed plan for subsequent modifications, which may include multiple steps, and each step will include a modification plan for which file and which content. The retrieval request interprets the requirement text and translates it into English, so as to facilitate the retrieval of the code of the entire project and search for the code fragments that need to be modified.
[0115] The code retrieval agent will perform two steps, namely, segmentation and retrieval and recall, on the code files in the code repository according to the retrieval request generated by the demand analysis agent, thereby returning candidates for code snippets that need to be modified (i.e., candidate code snippets). Exemplarily, the code retrieval agent generally returns the K most relevant code snippets as candidates. Among them, the segmentation step needs to perform more accurate code segmentation based on the characteristics of the specific code language, so that each segmented snippet has relatively complete independent logic and relatively short content. The retrieval and recall step may combine multiple retrieval methods (such as text content-based retrieval, vector-based retrieval, etc.) in the form of multi-way recall, taking into account the efficiency and recall rate of retrieval as much as possible, so that the snippets that really need to be modified are recalled in the higher-ranked snippets.
[0116] The modification suggestion agent will find the code snippet corresponding to each modification step (i.e., the modified code snippet) based on the modification plan generated by the demand analysis agent and the K code snippets retrieved and recalled by the code retrieval agent, and output what kind of modified code the modified code snippet should be modified into, that is, output the path of the code file to be modified and the starting and ending lines of the modified code snippet, and output the content of the modified code snippet, that is, output the modification suggestion. At the same time, it will also output a natural language explanation to show it to the user to help the user understand the specific content of the modification step, that is, output the modification explanation.
[0117] The change generation agent will generate a change form (i.e., code change form, also known as diff form) based on the modification suggestions output by the modification suggestion agent. This form is the most concise expression of the modification of a piece of code. Furthermore, the change generation agent will generate the change form of this modification based on the modification suggestions output by the modification suggestion agent, the retrieved code snippet corresponding to the modification, and the pre-modification file content corresponding to the modification. With this change form, users can directly adopt this change, so that they can use the git tool for management, which is more standardized and universal.
[0118] It can be seen that with the cooperation of the above four agents, it is possible to generate code modification suggestions based on the project code and the requirements proposed by the user and finally output the change form, so as to solve complex project development problems more quickly and efficiently. Through the overall linkage of the four agents, especially the demand analysis agent will predict the overall plan of the overall modification process, so as to help users have an intuitive and macro understanding of the code modification results. In addition, the change generation agent will convert the modification suggestions into a change form so that users can directly adopt the code modification, thereby solving the shortcomings of the existing products.
[0119] Exemplarily, when training a modification suggestion agent, the modification suggestion agent may be required to select one or more for modification based on the input user demand request, the information of the code repository, and the retrieved fragments that are helpful for the change. Specifically, the modification suggestion agent may be required to first analyze the user demand in general, and then for each change, first give the change plan, then give the change content, and finally summarize all the change contents. Moreover, when generating the change content for each change, if the content to be modified is not too long, the changed code fragment may be directly output; if the content to be modified is very long or scattered, the code before and after the modification may be output, and most of the code that does not need to be modified may be omitted with the comment "... Here is the omitted code...". In addition, the modification suggestion agent may be required to provide the file path information, starting line number, and ending line number of the class or function when necessary, and organize them into the form of "[`class_name`](file: / / xxx#Lxx-Lxx)", "[`method_name`](file: / / xxx#Lxx-Lxx)". At the same time, the modification suggestion agent is required to reply in Chinese and finally return the result in markdown format.
[0120] Accordingly, the modification suggestion intelligent body will output the following content: first, it will output the overall change plan generated by the overall analysis of user needs, and then output the specific change content. When outputting the change content, the corresponding natural language explanation and code modification form will be output for each change content. When it comes to new functions, the natural language explanation of the new functions and the code snippets involved will also be output. When it comes to function modifications, the natural language explanation of the function modifications and the code snippets involved will also be output. Optionally, the functions involved in the natural language explanation can be highlighted and configured with a jump index. If the user clicks on the function in the natural language explanation, they can jump to the corresponding code snippet and locate the line where the function is located. After the change content is output, a paragraph of explanation summarizing all the changes will also be output.
[0121] For example, when training a change generation agent, the change generation agent can be required to generate a code modification diff format based on user requirements, the code snippet before modification, and the modification suggestion, and finally return the result in markdown format. Accordingly, the change generation agent will output the difference between the code before modification and the code after modification, that is, a diff file.
[0122] It is understandable that the above training methods are only examples and are not limited here.
[0123] It is easy to understand that the beneficial effects of the code repair method provided by the present application include the following points.
[0124] Beneficial effect (1): The embodiment of the present application proposes a multi-agent-based framework for automatically generating repository-level code repair suggestions, which can accelerate the entire project development process and save manpower.
[0125] Beneficial effect (2): In the embodiment of the present application, the demand analysis intelligent system can predict the overall plan of the overall modification process, helping users to have an intuitive and macroscopic understanding of the code modification results.
[0126] Beneficial effect (3): In the embodiment of the present application, the change generation agent converts modification suggestions into change forms so that users can directly adopt the code modifications, saving manpower and improving code repair efficiency.
[0127] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0128] In addition, it should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.
[0129] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0130] According to the embodiment of the present application, there is also provided Figure 4 A code repair method shown in Figure 4is a flowchart of another code repair method according to an embodiment of the present application, such as Figure 4 As shown, the method includes:
[0131] Step S41, obtaining a code repair request through a first application programming interface;
[0132] Step S42, returning a code repair response through a second application programming interface; wherein the request data carried in the code repair request includes: an initial code file and a modification requirement, and the response data carried in the code repair response includes: a code change file, the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file based on the modification requirement using a target code repair model, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified to a target code snippet, the code change file is used to indicate a code difference between the target code file and the initial code file, and the target code file is obtained by performing code repair on the initial code file.
[0133] The first application programming interface and the second application programming interface may be the same application programming interface or different application programming interfaces. In an optional embodiment, the interface parameters in the first application programming interface and the second application programming interface may include but are not limited to: interface global identifier, interface signature key, interface timestamp, interface request identifier, system call credential identifier, etc. The first application programming interface may use GET or POST as the interface request method to obtain the file processing request. The second application programming interface may use JSON format to feedback the file processing response.
[0134] A code repair request can be understood as a request for repairing the initial code file based on the modification requirements. The request data carried in the code repair request includes: the initial code file and the modification requirements. A code repair response can be understood as a reply to the code repair request. The response data carried in the code repair response includes: the code change file.
[0135] In the embodiment of the present application, the initial code file can be understood as a code file to be repaired, that is, a code file that needs to be repaired, and the initial code file is used to implement the instructions and logic of the software function. Exemplarily, the initial code file can be a code file of an existing project, which is used to implement the software function of the existing project.
[0136] It is understandable that the initial code file may include multiple types of files, each of which has a specific function and purpose, such as source code files, header files, resource files, configuration files, document files, script files, etc., which are not limited here.
[0137] Modification requirements are the requirements for modifying the initial code files. Modification requirements can be understood as modification requirements suggestions put forward by R&D personnel for existing projects or defects raised by users for existing projects. The initial code files are repaired based on the modification requirements so that the repaired code files can meet the requirements of R&D personnel and users.
[0138] Optionally, the modification requirements may include requirement text, project tree structure and project meta information. Among them, the requirement text may be an introduction to development requirements or defect problems, the requirement text may be in text form in various languages, or audio files in various languages may be converted into text form, which is not limited here. The project tree structure can be understood as a hierarchical structure of project files and directories. Exemplarily, the project tree structure may include the organizational structure, file name, content introduction, etc. of each file in an existing project, which is not limited here. Project meta information is used to describe the basic information of the project. Exemplarily, the project meta information may include the framework on which the project depends and the version information of the third-party packages on which the project depends, which is not limited here.
[0139] The target code repair model can be understood as an intelligent coding assistant proposed in the embodiment of the present application. The target code repair model can perform code repair on the code file to be modified according to the input modification requirements, thereby outputting a code change file.
[0140] The target code repair model is obtained by training the initial code repair model based on the modification suggestion file, which can be understood as training the initial code repair model according to the modification suggestion file, so as to obtain the target code repair model. Among them, the initial code repair model can be understood as the code repair model before training. The target code repair model can be a large model or other deep learning model, which is not limited here.
[0141] The modification suggestion file is generated based on the initial code file sample and the modification requirement sample, and the modification suggestion file is used to indicate that the specified code snippet in the initial code file sample is modified to the target code snippet. It can be understood that when training the code repair model, a modification suggestion file can be generated based on the initial code file sample and the modification requirement sample, and the modification suggestion file is used to indicate which code snippet in which code file sample in the initial code file sample should be modified to what. Exemplarily, each line in the code file is usually marked with a line number, and the code snippet to be modified can be determined by indicating the line number in the initial code file, which is not limited here.
[0142] The target code repair model in the embodiment of the present application can output a code change file, which is used to represent the code difference between the target code file and the initial code file. The code change file can be understood as a diff file, which is used to show the difference between the target code file and the initial code file. The target code file is obtained after the initial code file is repaired, which can be understood as the target code file being the code file after the initial code file is repaired.
[0143] In the embodiment of the present application, a code repair request carrying an initial code file and a modification requirement is obtained through a first application programming interface, and then a code repair response carrying a code change file is returned through a second application programming interface, wherein the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file using a target code repair model based on the modification requirement, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified to a target code snippet, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained by performing code repair on the initial code file. Thus, through the code change file, the user can directly adopt the code modification method, that is, directly replace the initial code file with the target code file, thereby solving the shortcomings existing in the existing project, thereby improving the efficiency of code repair, accelerating the entire project development process, and saving manpower.
[0144] The above-mentioned code repair method provided in the embodiment of the present application can be applied to, but is not limited to, application scenarios involving code repair of projects or products in the fields of e-commerce services, educational services, legal services, medical services, conference services, social network services, financial product services, logistics services and navigation services, for example: code repair application scenarios for e-commerce service projects or products, code repair application scenarios for educational service projects or products, code repair application scenarios for legal service projects or products, etc., which are not limited here.
[0145] According to an embodiment of the present application, a code repair request carrying an initial code file and a modification requirement is obtained through a first application programming interface, and then a code repair response carrying a code change file is returned through a second application programming interface, wherein the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file using a target code repair model based on the modification requirement, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is generated based on an initial code file sample and a modification requirement sample, the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified to a target code fragment, the code change file is used to indicate a code difference between the target code file and the initial code file, and the target code file is obtained after performing code repair on the initial code file, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, allowing users to directly adopt the code modification method of the code change file to solve the shortcomings in the existing project, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, thereby solving the technical problem in the related art that the code model can only generate code files, and users cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0146] It should be noted that the preferred implementation of this embodiment can refer to the relevant description in the embodiment, which will not be repeated here.
[0147] According to the embodiment of the present application, there is also provided Figure 5 One way to fix the code is shown. Figure 5 is a flowchart of another code repair method according to an embodiment of the present application, such as Figure 5 As shown, the method includes:
[0148] Step S51, obtaining the currently input code repair dialogue request;
[0149] Step S52, in response to the code repair dialogue request, returning a code repair dialogue reply; wherein the request data carried in the code repair dialogue request includes: an initial code file and a modification requirement, and the information carried in the code repair dialogue reply includes: a code change file, the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file using a target code repair model based on the modification requirement, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified into a target code snippet, the code change file is used to indicate a code difference between the target code file and the initial code file, and the target code file is obtained by performing code repair on the initial code file;
[0150] Step S53: display the code change file in the graphical user interface.
[0151] In the embodiment of the present application, the code repair dialogue request can be understood as a dialogue request initiated by a user when talking to an intelligent robot. The request data carried in the code repair dialogue request includes: an initial code file and a modification requirement. The code repair dialogue request is used to request code repair of the initial code file based on the modification requirement. The code repair dialogue reply can be understood as a reply to the code repair dialogue request. The information carried in the code repair dialogue reply includes: a code change file.
[0152] In the embodiment of the present application, the initial code file can be understood as a code file to be repaired, that is, a code file that needs to be repaired, and the initial code file is used to implement the instructions and logic of the software function. Exemplarily, the initial code file can be a code file of an existing project, which is used to implement the software function of the existing project.
[0153] It is understandable that the initial code file may include multiple types of files, each of which has a specific function and purpose, such as source code files, header files, resource files, configuration files, document files, script files, etc., which are not limited here.
[0154] Modification requirements are the requirements for modifying the initial code files. Modification requirements can be understood as modification requirements suggestions put forward by R&D personnel for existing projects or defects raised by users for existing projects. The initial code files are repaired based on the modification requirements so that the repaired code files can meet the requirements of R&D personnel and users.
[0155] Optionally, the modification requirements may include requirement text, project tree structure and project meta information. Among them, the requirement text may be an introduction to development requirements or defect problems, the requirement text may be in text form in various languages, or audio files in various languages may be converted into text form, which is not limited here. The project tree structure can be understood as a hierarchical structure of project files and directories. Exemplarily, the project tree structure may include the organizational structure, file name, content introduction, etc. of each file in an existing project, which is not limited here. Project meta information is used to describe the basic information of the project. Exemplarily, the project meta information may include the framework on which the project depends and the version information of the third-party packages on which the project depends, which is not limited here.
[0156] The target code repair model can be understood as an intelligent coding assistant proposed in the embodiment of the present application. The target code repair model can perform code repair on the code file to be modified according to the input modification requirements, thereby outputting a code change file.
[0157] The target code repair model is obtained by training the initial code repair model based on the modification suggestion file, which can be understood as training the initial code repair model according to the modification suggestion file, so as to obtain the target code repair model. Among them, the initial code repair model can be understood as the code repair model before training. The target code repair model can be a large model or other deep learning model, which is not limited here.
[0158] The modification suggestion file is generated based on the initial code file sample and the modification requirement sample, and the modification suggestion file is used to indicate that the specified code snippet in the initial code file sample is modified to the target code snippet. It can be understood that when training the code repair model, a modification suggestion file can be generated based on the initial code file sample and the modification requirement sample, and the modification suggestion file is used to indicate which code snippet in which code file sample in the initial code file sample should be modified to what. Exemplarily, each line in the code file is usually marked with a line number, and the code snippet to be modified can be determined by indicating the line number in the initial code file, which is not limited here.
[0159] The target code repair model in the embodiment of the present application can output a code change file, which is used to represent the code difference between the target code file and the initial code file. The code change file can be understood as a diff file, which is used to show the difference between the target code file and the initial code file. The target code file is obtained after the initial code file is repaired, which can be understood as the target code file being the code file after the initial code file is repaired based on the modification requirements.
[0160] In the embodiment of the present application, by obtaining the currently input code repair dialogue request, and then responding to the code repair dialogue request, a code repair dialogue reply is returned, wherein the request data carried in the code repair dialogue request includes: the initial code file and the modification requirements, and the information carried in the code repair dialogue reply includes: the code change file, the modification requirements are the modification requirements for the initial code file, the code change file is obtained by using the target code repair model to repair the initial code file based on the modification requirements, the target code repair model is obtained by training the initial code repair model based on the modification suggestion file, the modification suggestion file is used to indicate that the specified code fragment in the initial code file sample is modified to the target code fragment, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after the code repair of the initial code file. Finally, the code change file is displayed in the graphical user interface to feedback to the user. Thus, the code change file can enable the user to directly adopt the code modification method, that is, directly replace the initial code file with the target code file, thereby solving the shortcomings existing in the existing project, thereby improving the efficiency of code repair, accelerating the entire project development process, and saving manpower.
[0161] The above-mentioned code repair method provided in the embodiment of the present application can be applied to, but is not limited to, application scenarios involving code repair of projects or products in the fields of e-commerce services, educational services, legal services, medical services, conference services, social network services, financial product services, logistics services and navigation services, for example: code repair application scenarios for e-commerce service projects or products, code repair application scenarios for educational service projects or products, code repair application scenarios for legal service projects or products, etc., which are not limited here.
[0162] According to an embodiment of the present application, a code repair dialogue request currently input is obtained, and then a code repair dialogue reply is returned in response to the code repair dialogue request, wherein the request data carried in the code repair dialogue request includes: an initial code file and a modification requirement, and the information carried in the code repair dialogue reply includes: a code change file, the modification requirement is a modification requirement for the initial code file, the code change file is obtained by repairing the initial code file based on the modification requirement using a target code repair model, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified to a target code snippet, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained by repairing the initial code file based on the modification requirement. Finally, the code change file is displayed in the graphical user interface for feedback to the user, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, allowing the user to directly adopt the code modification method of the code change file to solve the shortcomings in the existing project, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, and further solving the technical problem in the related technology that the code model can only generate code files, and the user cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0163] It should be noted that the preferred implementation of this embodiment can refer to the relevant description in the embodiment, which will not be repeated here.
[0164] According to the embodiment of the present application, there is also provided Figure 6 A model training method shown. Figure 6 is a flow chart of a model training method according to an embodiment of the present application, such as Figure 6 As shown, the method includes:
[0165] Step S61, obtaining an initial code file sample and a modification requirement sample, wherein the modification requirement sample is a modification requirement for the initial code file sample;
[0166] Step S62, generating a modification suggestion file based on the initial code file sample and the modification requirement sample, wherein the modification suggestion file is used to instruct to modify a specified code segment in the initial code file sample into a target code segment;
[0167] Step S63, training the initial code repair model based on the modification suggestion file to obtain a code change file, wherein the code change file is used to represent the code difference between the target code file sample and the initial code file sample, and the target code file sample is obtained after code repairing the initial code file sample;
[0168] Step S64: Generate a target code repair model based on the code change file.
[0169] In the embodiment of the present application, in the model training process, the initial code file sample and the modification requirement sample are used for model training. Among them, the initial code file sample can be understood as the code file sample to be repaired, that is, the code file sample with the repair requirement.
[0170] It is understandable that the initial code file sample may include multiple types of file samples, each of which has a specific function and purpose, such as source code file samples, header file samples, resource file samples, configuration file samples, document file samples, script file samples, etc., which are not limited here.
[0171] The modification requirement sample is a modification requirement for the initial code file sample. The modification requirement sample can be understood as a modification requirement suggestion put forward by R&D personnel for an existing project or a defect problem put forward by a user for an existing project. The initial code file sample is repaired based on the modification requirement sample, so that the repaired code file sample can meet the requirements of R&D personnel and users.
[0172] Optionally, the modified requirement sample may include a requirement text sample, a project tree structure sample, and a project meta information sample. Among them, the requirement text sample may be an introduction to development requirements or an introduction to defect problems, the requirement text sample may be in text form in various languages, or audio files in various languages may be converted into text form, which is not limited here. The project tree structure sample may be understood as a hierarchical structure of project files and directories. Exemplarily, the project tree structure sample may include the organizational structure, file name, content introduction, etc. of each file in an existing project, which is not limited here. The project meta information sample is used to describe the basic information of the project. Exemplarily, the project meta information sample may include the framework on which the project depends and the version information of the third-party packages on which the project depends, which is not limited here.
[0173] A modification suggestion file is generated based on the initial code file sample and the modification requirement sample, wherein the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified to a target code snippet. It can be understood that when training a code repair model, a modification suggestion file can be generated based on the initial code file sample and the modification requirement sample, and the modification suggestion file is used to indicate which code snippet in which code file sample in the initial code file sample should be modified to what. Exemplarily, each line in a code file is usually marked with a line number, and the code snippet to be modified can be determined by indicating the line number in the initial code file, which is not limited here.
[0174] The initial code repair model is trained based on the modification suggestion file to obtain a code change file, wherein the initial code repair model can be understood as the code repair model before training. The code change file is used to represent the code difference between the target code file and the initial code file. The code change file can be understood as a diff file, which is used to show the difference between the target code file and the initial code file. The target code file is obtained after the initial code file is repaired. It can be understood that the target code file is the code file after the initial code file is repaired based on the modification requirements.
[0175] A target code repair model is generated based on the code change file, wherein the target code repair model can be understood as an intelligent coding assistant proposed in an embodiment of the present application, and the target code repair model can perform code repair on the code file to be modified according to the input modification requirements, thereby outputting a code change file. Exemplarily, the intelligent coding assistant proposed in an embodiment of the present application is based on advanced artificial intelligence technology, and through an in-depth understanding of the developer's programming intent and contextual information, it can realize functions such as automatic code completion, unit test generation, and project-level code modification suggestion generation, significantly improving the developer's coding efficiency. The target code repair model can be a large model or other deep learning model, which is not limited here. It is understandable that the target code repair model in the embodiment of the present application can output a code change file.
[0176] In an embodiment of the present application, an initial code file sample and a modification requirement sample are obtained, wherein the modification requirement sample is the modification requirement for the initial code file sample, and then a modification suggestion file is generated based on the initial code file sample and the modification requirement sample, wherein the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified into a target code fragment, and then the initial code repair model is trained based on the modification suggestion file to obtain a code change file, wherein the code change file is used to represent the code difference between the target code file sample and the initial code file sample, and the target code file sample is obtained after code repair of the initial code file sample, and finally a target code repair model is generated based on the code change file, thereby enabling users to directly adopt the code modification method through the code change file, that is, directly replace the initial code file with the target code file, thereby solving the shortcomings existing in the existing project, thereby improving the efficiency of code repair, accelerating the entire project development process, and saving manpower.
[0177] The above-mentioned model training method provided in the embodiment of the present application can be applied to, but is not limited to, application scenarios involving code repair model training in the fields of e-commerce services, educational services, legal services, medical services, conference services, social network services, financial product services, logistics services and navigation services, for example: code repair model training application scenarios related to e-commerce services, code repair model training application scenarios related to educational services, code repair model training application scenarios related to legal services, etc., which are not limited here.
[0178] According to an embodiment of the present application, an initial code file sample and a modification requirement sample are obtained, wherein the modification requirement sample is a modification requirement for the initial code file sample, and then a modification suggestion file is generated based on the initial code file sample and the modification requirement sample, wherein the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified into a target code snippet, and then the initial code repair model is trained based on the modification suggestion file to obtain a code change file, wherein the code change file is used to represent the code difference between the target code file sample and the initial code file sample, and the target code file sample is obtained after code repairing the initial code file sample, and finally a target code repair model is generated based on the code change file, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, so that users can directly adopt the code modification method of the code change file to solve the shortcomings in the existing project, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, and further solving the technical problem in the related art that the code model can only generate code files, and users cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0179] It should be noted that the preferred implementation of this embodiment can refer to the relevant description in the embodiment, which will not be repeated here.
[0180] According to an embodiment of the present application, a device embodiment for implementing the above-mentioned code repair method is also provided. Figure 7 is a schematic diagram of the structure of a code repair device according to an embodiment of the present application, such as Figure 7 As shown, the device comprises:
[0181] The first acquisition module 701 is used to acquire an initial code file and a modification requirement, wherein the modification requirement is a modification requirement for the initial code file;
[0182] The repair module 702 is used to perform code repair on the initial code file using a target code repair model based on the modification requirements to obtain a code change file; wherein the target code repair model is obtained by training the initial code repair model based on the modification suggestion file, the modification suggestion file is used to indicate that a code snippet of a specified line in a specified code file sample in the initial code file sample is modified to a target code snippet, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after code repair is performed on the initial code file.
[0183] Optionally, the above-mentioned repair module 702 is also used to: generate a modification plan for the initial code file based on the modification requirements using the target code repair model, and determine candidate code fragments from the initial code file based on the modification requirements using the target code repair model, wherein the modification plan includes at least one modification step, and the candidate code fragment includes the code fragment to be modified corresponding to any modification step; generate a modification suggestion file based on the modification plan and the candidate code fragment; and generate a code change file based on the modification suggestion file.
[0184] Optionally, the above-mentioned repair module 702 is also used to: generate a retrieval request based on the modification requirement, wherein the retrieval request is used to request a code retrieval of the initial code file; translate the modification requirement based on the retrieval request and the preset language form to obtain the requirement translation text; retrieve the initial code file based on the retrieval request and the requirement translation text to obtain a candidate code fragment.
[0185] Optionally, the above-mentioned repair module 702 is also used to: segment the initial code file based on the code language of the initial code file to obtain segmented code fragments, wherein the code logic between the segmented code fragments is independent of each other, and the code length of the segmented code fragments is less than the preset code length; retrieve the segmented code fragments based on the retrieval request and the required translation text to obtain candidate code fragments.
[0186] Optionally, the repair module 702 is further used to: determine a correlation value between the segmented code fragments and the required translation text based on the search request; sort the segmented code fragments based on the correlation value to obtain a sorting result; and determine candidate code fragments based on the segmented code fragments within a preset ranking range in the sorting result.
[0187] Optionally, the repair module 702 is further used to determine a correlation value between the segmented code fragment and the required translation text based on a search request and a preset search algorithm, wherein the preset search algorithm includes at least one of the following: a text content search algorithm and a vector search algorithm.
[0188] Optionally, the above-mentioned repair module 702 is also used to: determine the modified code snippet from the candidate code snippets based on the modification plan, wherein the modified code snippet corresponds one-to-one to the modification step; based on the modification plan and the modified code snippet, generate the file path of the code file to which the modified code snippet belongs, the starting line number and the ending line number of the modified code snippet, and the target code snippet corresponding to the modified code snippet; based on the file path of the code file to which the modified code snippet belongs, the starting line number and the ending line number of the modified code snippet, and the target code snippet corresponding to the modified code snippet, generate a modification suggestion file.
[0189] Optionally, the device further includes: an output module, configured to output a natural language explanation corresponding to the modification step.
[0190] Optionally, the repair module 702 is further configured to generate a code change file based on the modification suggestion file, the candidate code snippets and the initial code file.
[0191] Optionally, the device further includes: a receiving module, configured to, in response to receiving an adopting change instruction, perform code repair on the initial code file based on the code change file to obtain a target code file.
[0192] According to an embodiment of the present application, an initial code file and modification requirements for the initial code file are obtained, and then a target code repair model is used to perform code repair on the initial code file based on the modification requirements, thereby obtaining a code change file for representing the code difference between the target code file and the initial code file, wherein the target code file is obtained after code repairing the initial code file, the target code repair model is obtained after training the initial code repair model based on a modification suggestion file, and the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified to a target code fragment, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, allowing users to directly adopt the code modification method of the code change file to solve the shortcomings in existing projects, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, and further solving the technical problem in the related art that the code model can only generate code files, and users cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0193] It should be noted that the first acquisition module 701 and the repair module 702 correspond to step S21 and step S22 in the embodiment, and the two modules and the corresponding steps implement the same examples and application scenarios, but are not limited to the contents disclosed in the above embodiment. It should be noted that the above modules or units can be hardware components or software components stored in a memory and processed by one or more processors, and the above modules can also run in the server 10 provided in the embodiment.
[0194] According to an embodiment of the present application, another device embodiment for implementing the above-mentioned code repair method is also provided. Figure 8 is a schematic diagram of the structure of another code repair device according to an embodiment of the present application, such as Figure 8 As shown, the device comprises:
[0195] A second acquisition module 801 is used to acquire a code repair request through a first application programming interface;
[0196] The first return module 802 is used to return a code repair response through a second application programming interface; wherein the request data carried in the code repair request includes: an initial code file and a modification requirement, and the response data carried in the code repair response includes: a code change file, the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file based on the modification requirement using a target code repair model, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified to a target code snippet, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after performing code repair on the initial code file.
[0197] According to an embodiment of the present application, a code repair request carrying an initial code file and a modification requirement is obtained through a first application programming interface, and then a code repair response carrying a code change file is returned through a second application programming interface, wherein the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file based on the modification requirement using a target code repair model, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified to a target code snippet, the code change file is used to indicate a code difference between the target code file and the initial code file, and the target code file is obtained by performing code repair on the initial code file, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, allowing users to directly adopt the code modification method of the code change file to solve the shortcomings in the existing project, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, thereby solving the technical problem in the related art that the code model can only generate a code file, and the user cannot directly adopt the code file, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0198] It should be noted that the second acquisition module 801 and the first return module 802 correspond to step S41 and step S42 in the embodiment, and the two modules and the corresponding steps implement the same examples and application scenarios, but are not limited to the contents disclosed in the above embodiment. It should be noted that the above modules or units can be hardware components or software components stored in a memory and processed by one or more processors, and the above modules can also run in the server 10 provided in the embodiment.
[0199] According to an embodiment of the present application, another device embodiment for implementing the above-mentioned code repair method is also provided. Fig. 9is a schematic diagram of the structure of another code repair device according to an embodiment of the present application, such as Fig. 9 As shown, the device comprises:
[0200] The third acquisition module 901 is used to acquire the currently input code repair dialogue request;
[0201] The second return module 902 is used to respond to the code repair dialogue request and return a code repair dialogue reply; wherein the request data carried in the code repair dialogue request includes: an initial code file and a modification requirement, and the information carried in the code repair dialogue reply includes: a code change file, the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file using a target code repair model based on the modification requirement, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified into a target code snippet, the code change file is used to indicate a code difference between the target code file and the initial code file, and the target code file is obtained by performing code repair on the initial code file;
[0202] The display module 903 is used to display the code change file in the graphical user interface.
[0203] According to an embodiment of the present application, a code repair dialogue request currently input is obtained, and then a code repair dialogue reply is returned in response to the code repair dialogue request, wherein the request data carried in the code repair dialogue request includes: an initial code file and a modification requirement, and the information carried in the code repair dialogue reply includes: a code change file, the modification requirement is a modification requirement for the initial code file, the code change file is obtained by performing code repair on the initial code file based on the modification requirement using a target code repair model, the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a code snippet in an initial code file sample is modified into a target code snippet, the code change file is used to indicate a code difference between a target code file and an initial code file, and the target code file is obtained by performing code repair on the initial code file. Finally, the code change file is displayed in the graphical user interface for feedback to the user, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, allowing the user to directly adopt the code modification method of the code change file to solve the shortcomings in the existing project, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, and further solving the technical problem in the related technology that the code model can only generate code files, and the user cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0204] It should be noted that the third acquisition module 901, the second return module 902 and the display module 903 correspond to steps S51 to S53 in the embodiment, and the three modules and the corresponding steps implement the same examples and application scenarios, but are not limited to the contents disclosed in the above embodiment. It should be noted that the above modules or units can be hardware components or software components stored in a memory and processed by one or more processors, and the above modules can also run in the server 10 provided in the embodiment.
[0205] It should be noted that the preferred implementation scheme involved in the above embodiments of the present application is the same as the scheme provided in the embodiments, as well as the application scenario and implementation process, but is not limited to the scheme provided in the embodiments.
[0206] According to an embodiment of the present application, another device embodiment for implementing the above-mentioned model training method is also provided. Fig.10 is a structural diagram of a model training device according to an embodiment of the present application, such as Fig.10 As shown, the device comprises:
[0207] The fourth acquisition module 1001 is used to acquire an initial code file sample and a modification requirement sample, wherein the modification requirement sample is a modification requirement for the initial code file sample;
[0208] A first generating module 1002 is used to generate a modification suggestion file based on the initial code file sample and the modification requirement sample, wherein the modification suggestion file is used to indicate that a specified code segment in the initial code file sample is modified into a target code segment;
[0209] A training module 1003 is used to train the initial code repair model based on the modification suggestion file to obtain a code change file, wherein the code change file is used to represent the code difference between the target code file sample and the initial code file sample, and the target code file sample is obtained after repairing the initial code file sample;
[0210] The second generating module 1004 is used to generate a target code repair model based on the code change file.
[0211] According to an embodiment of the present application, an initial code file sample and a modification requirement sample are obtained, wherein the modification requirement sample is a modification requirement for the initial code file sample, and then a modification suggestion file is generated based on the initial code file sample and the modification requirement sample, wherein the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified into a target code snippet, and then the initial code repair model is trained based on the modification suggestion file to obtain a code change file, wherein the code change file is used to represent the code difference between the target code file sample and the initial code file sample, and the target code file sample is obtained after code repairing the initial code file sample, and finally a target code repair model is generated based on the code change file, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, so that users can directly adopt the code modification method of the code change file to solve the shortcomings in the existing project, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, and further solving the technical problem in the related art that the code model can only generate code files, and users cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0212] It should be noted that the fourth acquisition module 1001, the first generation module 1002, the training module 1003 and the second generation module 1004 correspond to steps S61 to S64 in the embodiment, and the four modules and the corresponding steps implement the same examples and application scenarios, but are not limited to the contents disclosed in the above embodiment. It should be noted that the above modules or units can be hardware components or software components stored in a memory and processed by one or more processors, and the above modules can also run in the server 10 provided in the embodiment.
[0213] The embodiment of the present application may provide an electronic device, which may be any electronic device in a group of electronic devices. Optionally, in this embodiment, the electronic device may also be replaced by a terminal device such as a mobile terminal. Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices in a computer network.
[0214] In this embodiment, the above-mentioned electronic device can execute the program code of the following steps in the code repair method: obtaining an initial code file and a modification requirement, wherein the modification requirement is a modification requirement for the initial code file; performing code repair on the initial code file based on the modification requirement using a target code repair model to obtain a code change file; wherein the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified into a target code fragment, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after performing code repair on the initial code file.
[0215] Optionally, Fig.11 is a structural block diagram of an electronic device according to an embodiment of the present application. Fig.11 As shown, taking electronic device A as an example, the electronic device A may include: one or more (only one is shown in the figure) processors 1102, a memory 1104, a storage controller, and a peripheral interface, wherein the peripheral interface is connected to a radio frequency module, an audio module, and a display.
[0216] Among them, the memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the code repair method and device in the embodiment of the present application. The processor executes various functional applications and data processing by running the stored software programs and modules, that is, realizing the above-mentioned code repair method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories can be connected to the electronic device A via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0217] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: obtain the initial code file and the modification requirements, wherein the modification requirements are the modification requirements for the initial code file; based on the modification requirements, use the target code repair model to perform code repair on the initial code file to obtain a code change file; wherein the target code repair model is obtained by training the initial code repair model based on the modification suggestion file, the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified into a target code fragment, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after performing code repair on the initial code file.
[0218] According to an embodiment of the present application, an initial code file and modification requirements for the initial code file are obtained, and then a target code repair model is used to perform code repair on the initial code file based on the modification requirements, thereby obtaining a code change file for representing the code difference between the target code file and the initial code file, wherein the target code file is obtained after code repairing the initial code file, the target code repair model is obtained after training the initial code repair model based on a modification suggestion file, and the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified to a target code fragment, thereby achieving the purpose of efficiently and quickly repairing the code file to be repaired based on the code change file, allowing users to directly adopt the code modification method of the code change file to solve the shortcomings in existing projects, thereby achieving the technical effect of improving the efficiency of code repair, accelerating the entire project development process and saving manpower, and further solving the technical problem in the related art that the code model can only generate code files, and users cannot directly adopt the code files, resulting in high labor costs and low efficiency in code project maintenance and updating.
[0219] It can be understood by those skilled in the art that Fig.11 The structure shown is for illustration only, and the electronic device A may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, or other terminal devices. Fig.11 It does not limit the structure of the above electronic device. For example, the electronic device A may also include Fig.11 More or fewer components (such as network interfaces, display devices, etc.) shown in, or with Fig.11 Different configurations are shown.
[0220] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0221] The embodiment of the present application further provides a computer-readable storage medium. Optionally, in this embodiment, the computer-readable storage medium can be used to store the program code executed by the code repair method provided in the first embodiment.
[0222] Optionally, in this embodiment, the computer-readable storage medium may be located in any one of the computer terminals in a computer terminal group in a computer network, or in any one of the mobile terminals in a mobile terminal group.
[0223] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code for performing the following steps: obtaining an initial code file and a modification requirement, wherein the modification requirement is a modification requirement for the initial code file; performing code repair on the initial code file using a target code repair model based on the modification requirement to obtain a code change file; wherein the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified into a target code snippet, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after performing code repair on the initial code file.
[0224] An embodiment of the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements any one of the above-mentioned code repair methods.
[0225] Optionally, in this embodiment, the computer program product is a program code for executing the following steps when executed by a processor: obtaining an initial code file and a modification requirement, wherein the modification requirement is a modification requirement for the initial code file; performing code repair on the initial code file using a target code repair model based on the modification requirement to obtain a code change file; wherein the target code repair model is obtained by training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified into a target code snippet, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after performing code repair on the initial code file.
[0226] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0227] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0228] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, 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 units or modules, which can be electrical or other forms.
[0229] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0230] In addition, each functional unit 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.
[0231] 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 for a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk, etc., which can store program code.
[0232] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A code repair method, characterized in that: include: Obtaining an initial code file and a modification requirement, wherein the modification requirement is a modification requirement for the initial code file; Based on the modification requirements, the target code repair model is used to perform code repair on the initial code file to obtain a code change file; Among them, the target code repair model is obtained after training the initial code repair model based on the modification suggestion file, the modification suggestion file is used to indicate that a specified code fragment in the initial code file sample is modified into a target code fragment, the code change file is used to represent the code difference between the target code file and the initial code file, and the target code file is obtained after code repair of the initial code file.
2. The code repair method according to claim 1, characterized in that: The code repairing of the initial code file by using the target code repair model based on the modification requirement to obtain the code change file includes: Generate a modification plan for the initial code file using the target code repair model based on the modification requirement, and determine candidate code segments from the initial code file using the target code repair model based on the modification requirement, wherein the modification plan includes at least one modification step, and the candidate code segments include code segments to be modified corresponding to any of the modification steps; generating the modification suggestion file based on the modification plan and the candidate code snippets; The code change file is generated based on the modification suggestion file.
3. The code repair method according to claim 2, characterized in that: Determining the candidate code snippet from the initial code file based on the modification requirement includes: Generate a search request based on the modification requirement, wherein the search request is used to request code search for the initial code file; Translate the modification requirement based on the search request and the preset language form to obtain a requirement translation text; The initial code file is searched based on the search request and the required translation text to obtain the candidate code fragment.
4. The code repair method according to claim 3, characterized in that: The retrieving the initial code file based on the retrieval request and the required translation text to obtain the candidate code fragment comprises: Segmenting the initial code file based on the code language of the initial code file to obtain segmented code segments, wherein the code logics between the segmented code segments are independent of each other, and the code length of the segmented code segments is less than a preset code length; The segmented code fragments are retrieved based on the search request and the required translation text to obtain the candidate code fragments.
5. The code repair method according to claim 4, characterized in that: The retrieving the segmented code fragments based on the retrieval request and the required translation text to obtain the candidate code fragments includes: Determine a correlation value between the segmented code snippet and the required translation text based on the search request; Sorting the segmented code fragments based on the correlation values to obtain a sorting result; The candidate code segments are determined based on the segmented code segments within a preset ranking range in the sorting results.
6. The code repair method according to claim 5, characterized in that: The determining of the correlation value between the segmented code fragment and the required translation text based on the search request includes: The correlation value between the segmented code fragment and the required translation text is determined based on the search request and a preset search algorithm, wherein the preset search algorithm includes at least one of the following: a text content search algorithm and a vector search algorithm.
7. The code repair method according to claim 2, characterized in that: Generating the modification suggestion file based on the modification plan and the candidate code snippets includes: Determining a modified code segment from the candidate code segments based on the modification plan, wherein the modified code segment corresponds to the modification step one by one; Based on the modification plan and the modified code snippet, generate a file path of a code file to which the modified code snippet belongs, a starting line number and an ending line number of the modified code snippet, and a target code snippet corresponding to the modified code snippet; The modification suggestion file is generated based on the file path of the code file to which the modified code snippet belongs, the starting line number and the ending line number of the modified code snippet, and the target code snippet corresponding to the modified code snippet.
8. The code repair method according to claim 7, characterized in that: The method further comprises: Output the natural language explanation corresponding to the modification step.
9. The code repair method according to any one of claims 2 to 8, characterized in that: Generating the code change file based on the modification suggestion file includes: The code change file is generated based on the modification suggestion file, the candidate code snippets and the initial code file.
10. The code repair method according to claim 1, characterized in that: The method further comprises: In response to receiving the adopt change instruction, code repair is performed on the initial code file based on the code change file to obtain the target code file.
11. A code repair method, characterized in that: include: obtaining a code fix request via a first application programming interface; returning a code repair response via a second application programming interface; Among them, the request data carried in the code repair request includes: an initial code file and a modification requirement, and the response data carried in the code repair response includes: a code change file, the modification requirement is a modification requirement for the initial code file, the code change file is obtained after code repairing the initial code file using a target code repair model based on the modification requirement, the target code repair model is obtained after training the initial code repair model based on a modification suggestion file, the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified to a target code snippet, the code change file is used to indicate the code difference between the target code file and the initial code file, and the target code file is obtained after code repairing the initial code file.
12. A code repair method, characterized in that: include: Get the currently entered code fix dialog request; In response to the code repair dialogue request, returning a code repair dialogue reply; The request data carried in the code repair dialogue request includes: an initial code file and a modification requirement; the information carried in the code repair dialogue reply includes: a code change file; the modification requirement is a modification requirement for the initial code file; the code change file is obtained by performing code repair on the initial code file using a target code repair model based on the modification requirement; the target code repair model is obtained by training the initial code repair model based on a modification suggestion file; the modification suggestion file is used to indicate that a specified code snippet in the initial code file sample is modified into a target code snippet; the code change file is used to indicate a code difference between a target code file and the initial code file; the target code file is obtained by performing code repair on the initial code file; The code change file is displayed in a graphical user interface.
13. A model training method, characterized in that: include: Acquire an initial code file sample and a modification requirement sample, wherein the modification requirement sample is a modification requirement for the initial code file sample; Generate a modification suggestion file based on the initial code file sample and the modification requirement sample, wherein the modification suggestion file is used to instruct to modify a specified code segment in the initial code file sample into a target code segment; The initial code repair model is trained based on the modification suggestion file to obtain a code change file, wherein the code change file is used to represent the code difference between the target code file sample and the initial code file sample, and the target code file sample is obtained after code repair is performed on the initial code file sample; A target code repair model is generated based on the code change file.
14. An electronic device, characterized in that: include: A memory storing an executable program; A processor, used to run the program, wherein when the program is running, it executes the code repair method described in any one of claims 1 to 12 or executes the model training method described in claim 13.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored executable program, wherein when the executable program is running, the device where the computer-readable storage medium is located is controlled to execute the code repair method described in any one of claims 1 to 12 or the model training method described in claim 13.
16. A computer program product, characterized in that It includes a computer program, which, when executed by a processor, implements the code repair method described in any one of claims 1 to 12 or executes the model training method described in claim 13.
Citation Information
Patent Citations
Code defect repairing method and device, computer equipment and readable storage medium
CN116661853A
Log-based code repair method, system, equipment and medium
CN117076324A
Code generation optimization method and device for large language model, equipment and medium
CN117724695A
Cited By
Code modification strategy determination method and device, equipment, medium and program product
CN119513709A
Large language model-based code development method and related device
WO2026130394A1
Code task processing method, code error correction method and code processing model training method
WO2026170912A1
Code defect repair method and system based on multi-agent collaboration, electronic device, storage medium, and program product
WO2026184307A1
