Code generation method and apparatus
By combining a large language model with a code generation program, and utilizing code requirement information and prompts to generate and optimize code configurations, the problems of low code generation quality and efficiency are solved, achieving high-quality and efficient code generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2026-03-20
AI Technical Summary
In existing technologies, the quality of generated code is difficult to meet specific needs, and the generation efficiency is low, which cannot effectively improve code development efficiency.
Code configuration is generated using a large language model. By combining a code generation program and a code modification module, code configuration is generated and optimized using code requirement information, configuration generation prompts, and code modification prompts to improve quality.
It improves the quality and efficiency of code generation, making the generated code more in line with requirements and enhancing development efficiency.
Smart Images

Figure CN119781772B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present document relates to the technical field of software development, and particularly relates to a code generation method and device. BACKGROUND
[0002] Code generation has a wide range of applications in software development projects. Through code generation, code can be quickly generated to help developers improve code development efficiency. Among them, using machine learning or artificial intelligence technology to automatically generate code to learn the structure and function of the code, and automatically generating corresponding code according to the input instructions or requirements, is an important code generation method. With the increasing application of code generation, how to improve the quality of code generation has become the focus of software development projects. SUMMARY
[0003] One or more embodiments of the present specification provide a code generation method, comprising: inputting code requirement information and configuration generation prompt words into a large language model to generate code configuration. Inputting the code configuration into a code generation program to generate initial code. Inputting the initial code, example code and code modification prompt words into the large language model to modify the code, and obtaining target code.
[0004] One or more embodiments of the present specification provide a code generation device, comprising: a configuration generation module configured to input code requirement information and configuration generation prompt words into a large language model to generate code configuration. A code generation module configured to input the code configuration into a code generation program to generate initial code. A code modification module configured to input the initial code, example code and code modification prompt words into the large language model to modify the code, and obtain target code.
[0005] One or more embodiments of the present specification provide a code generation device, comprising: a processor; and a memory configured to store computer executable instructions that, when executed, cause the processor to: input code requirement information and configuration generation prompt words into a large language model to generate code configuration. Inputting the code configuration into a code generation program to generate initial code. Inputting the initial code, example code and code modification prompt words into the large language model to modify the code, and obtain target code.
[0006] The one or more embodiments of the specification provide a computer readable storage medium for storing computer executable instructions, the computer executable instructions, when executed, implement the following process: inputting code requirement information and configuration generation prompt words into a large language model to generate code configuration, obtaining code configuration. Input the code configuration into the code generation program to generate the code, and obtain the initial code. Input the initial code, example code and code modification prompt word into the large language model to modify the code, and obtain the target code. BRIEF DESCRIPTION OF DRAWINGS
[0007] In order to more clearly illustrate the technical solutions in the one or more embodiments of the specification or the prior art, the drawings needed to be used in the embodiment or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments described in the specification, and those skilled in the art can also obtain other drawings according to these drawings without creative labor.
[0008] Figure 1 A schematic diagram of an embodiment environment for providing a code generation method for the one or more embodiments of the specification is provided.
[0009] Figure 2 A code generation method processing flowchart for the one or more embodiments of the specification is provided.
[0010] Figure 3 A code generation method processing flowchart for the one or more embodiments of the specification is provided.
[0011] Figure 4 A schematic diagram of an embodiment environment for providing a code generation method for the one or more embodiments of the specification is provided.
[0012] Figure 5 A schematic diagram of a code generation device for the one or more embodiments of the specification is provided. DETAILED DESCRIPTION
[0013] In order to make the person skilled in the art better understand the technical solutions in the one or more embodiments of the specification, the technical solutions in the one or more embodiments of the specification will be described clearly and completely below in conjunction with the drawings in the one or more embodiments of the specification. Obviously, the described embodiments are only some embodiments of the specification, not all embodiments. Based on the one or more embodiments of the specification, all other embodiments obtained by those skilled in the art without creative labor should belong to the protection scope of the present document.
[0014] The code generation method provided by one or more embodiments of the present specification can be applied to the implementation environment of a code generation system, and the implementation environment at least includes Figure 1
[0015] The code generation module 101, the large language model 102, and the code generation program 103 can also include a local code repository 104 for storing example code.
[0016] The code generation module 101 is configured to obtain code requirement information, generate configuration generation prompt words and code modification prompt words, input the code requirement information and the configuration generation prompt words into the large language model 102, obtain the code configuration generated by the large language model 102 and input the code configuration into the code generation program 103, obtain the initial code generated by the code generation program 103, and input the initial code, the example code and the code modification prompt words into the large language model 102; the large language model 102 is configured to generate and output the code configuration according to the input code requirement information and the configuration generation prompt words, and output the target code according to the input initial code, the example code and the code modification prompt words; and the code generation program 103 is configured to generate the initial code according to the input code configuration.
[0017] In the implementation environment, during the code generation process, the code generation module 101 obtains the code requirement information for code generation, inputs the code requirement information and the configuration generation prompt words into the large language model 102, and generates the code configuration through the large language model 102. After the large language model 102 generates and outputs the code configuration, the code configuration is input into the code generation program 103, the code generation is performed through the code generation program 103 to obtain the initial code generated for the current code requirement information. Thereafter, the example code can be obtained from the local code repository 104, and the initial code, the example code and the code modification prompt words are input into the large language model 102. The large language model 102 is prompted to perform corresponding code modification on the initial code by referring to the input example code through the code modification prompt words. In this way, the cooperation of the large language model 102 and the code generation program 103 realizes high-quality code generation.
[0018] One or more embodiments of the code generation method provided by the present specification are as follows:
[0019] Referring to Figure 2 The code generation method provided by the present embodiment specifically includes steps S202 to S206.
[0020] In step S202, the code requirement information and the configuration generation prompt words are input into the large language model to generate the code configuration, and the code configuration is obtained.
[0021] The code requirement information described in the embodiment refers to the requirements and specifications of the code in the software development process in order to make the code meet specific requirements; for example, the functional code requirement is to make the code meet the corresponding function, taking the login function requirement as an example, if the code requirement contains the login function, the code must be able to implement the login function; for another example, the non-functional code requirement is to make the code meet the non-functional requirements in the corresponding angle, taking the performance requirement as an example, if the code requirement contains the response time of not more than 2 seconds, the response time of the code in the running process must be within 2 seconds.
[0022] Optionally, the code requirement information includes code requirement description information, in addition, the code requirement information can also include at least one of the code requirement description information and the code storage path information and the code structure position information, that is, the code requirement information includes the code requirement description information and the code storage path information, or the code requirement information includes the code requirement description information and the code structure position information, or the code requirement information includes the code requirement description information, the code storage path information and the code structure position information.
[0023] Among them, the code requirement description information can contain the description field of the functional code requirement and / or the non-functional code requirement; the code storage path information refers to the storage path information of the code to be generated in the code repository; the code structure position information refers to the specific position information of the code to be generated in the code file or the code project, for example, the code structure position information can be to generate the corresponding code between xx1 class and xx2 class in xx code file.
[0024] In specific implementation, in the process of code generation, the code configuration is generated by the large language model, and the code is generated based on the generated code configuration, here, the generation of the code configuration by the large language model can improve the efficiency of the code configuration generation; in the process of generating the code configuration by the large language model, the code requirement information and the configuration generation prompt word are input into the large language model to generate the code configuration, and the code configuration is obtained.
[0025] Among them, the large language model can be a pre-trained large language model (Large Language Model, LLM), such as a large language model adopting the Transformer architecture; on the basis of the pre-trained large language model, the pre-trained model is fine-tuned (Supervised Fine-Tuning, SFT) for specific tasks, that is, a large language model capable of processing specific tasks to adapt to specific fields or task requirements can be obtained, the pre-trained large language model is fine-tuned in the code field in the embodiment, so as to obtain a code large language model capable of code-related processing in the code field, that is, the large language model can be a code large language model.
[0026] Specifically, in the process of code configuration generation by the large language model, the code configuration is obtained by inputting the code requirement information and the configuration generation prompt word into the large language model for code configuration generation, wherein the configuration generation prompt word is a prompt word for prompting the large language model to generate code according to the input code requirement information;
[0027] Further, in the scenario of code configuration generation by the large language model and code generation by the code generation program in the present embodiment, and considering that the input specifications or contents of different code generation tools may be different in actual application, in order to make the code generated by the code generation program more consistent with the code requirement, in the process of code configuration generation by the large language model, the configuration generation prompt word can also be used to prompt the large language model to generate code configuration adapted to the code generation program for subsequent code generation. Optionally, the configuration generation prompt word is used to prompt the large language model to generate code configuration adapted to the code generation program according to the input code requirement information.
[0028] Based on this, on the basis that the generated code configuration is as adapted to the code generation program for subsequent code generation as possible, the code generation by the code generation program according to the adapted code configuration is also more accurate, so that the code generated by the code generation program can be more consistent with the code requirement.
[0029] Step S204: inputting the code configuration into the code generation program for code generation to obtain initial code.
[0030] In the specific execution process, after the code requirement information and the configuration generation prompt word are input into the large language model for code configuration generation to obtain code configuration, the code configuration generated by the large language model is input into the code generation program for code generation to obtain the initial code generated and output by the code generation program. The initial code is the code generated for the code requirement information, and the form of the initial code can be source code or encoded code.
[0031] The code generation program refers to a tool application program for code generation, such as MyBatis Generator (code autogenerator).
[0032] Step S206: inputting the initial code, the example code and the code modification prompt word into the large language model for code modification to obtain target code.
[0033] In specific implementation, after the initial code is generated by the code generation program through the code configuration generated by the large language model, in order to improve the code quality of the initial code, the initial code and the code modification prompt are input into the large language model, and the initial code generated above is modified and optimized by the large language model to improve the code quality. The code modification prompt can be a prompt for instructing the large language model to modify the input initial code.
[0034] Further, in order to make the code modified by the large language model as much as possible to meet the code requirements, the large language model can also be input with example code, so that the large language model can modify the input initial code more specifically on the basis of analyzing and understanding the example code. In this case, the code prompt can also be a prompt for instructing the large language model to modify the input initial code by referring to the input example code.
[0035] Specifically, to further improve the specificity of the large language model in modifying the input initial code, the code modification method for modifying the input initial code can be added to the code modification prompt. Based on this, after the code modification prompt containing the code modification method and the initial code are input into the large language model, the large language model can modify the initial code according to the code modification method contained in the code modification prompt. Optionally, the code modification prompt is used to prompt the large language model to modify the input initial code by referring to the input example code and according to the code modification method contained in the code modification prompt.
[0036] Optionally, the code modification method includes at least one of the following: code specification modification, code rewriting, code comment modification, and code reduction.
[0037] The code specification modification refers to modifying the code specification of the input initial code by referring to the code specification of the example code, so that the code specification of the modified initial code is as same as the code specification of the example code as possible. The code specification can be the naming specification, indentation and space specification, code structure specification, etc. in the initial code.
[0038] The code rewriting refers to reconstructing or modifying the input initial code by referring to the example code, so as to improve the code structure of the initial code or improve the performance, such as reducing the complexity of the initial code to meet the new technical standards.
[0039] The code comment modification refers to modifying the code comment in the input initial code by referring to the example code, such as modifying the line comment, block comment, and document comment of the initial code, so that the modified code comment style is consistent with the style of the example code.
[0040] Code pruning refers to deleting redundant code in the initial code on the basis of analyzing and identifying the initial code, such as deleting interface call example code of an interface in the initial code or deleting algorithm example code of an algorithm in the initial code.
[0041] In a specific implementation process, on the basis that the code modification manner includes code specification modification, code rewriting, code comment modification and / or code pruning, the code modification prompt word containing the code modification manner is input into the large language model, and then the large language model performs code modification on the input initial code according to one or more code modification manners contained in the code modification prompt word.
[0042] Specifically, in an optional implementation manner provided by the embodiment, the code modification includes at least one of the following implementation manners:
[0043] determining the code specification of the example code, and performing code specification modification on the initial code according to the code specification;
[0044] performing code correlation analysis on the initial code and the example code, and performing code rewriting on the initial code according to the analysis result;
[0045] determining the code comment specification of the example code, and performing code comment specification modification on the code comment of the initial code according to the code comment specification;
[0046] performing code parsing on the initial code, and performing code pruning on the initial code according to the code parsing result.
[0047] In addition, in the process of code modification by the large language model, in the case that the code modification prompt word contains multiple code modification manners, that is, in the process of performing code modification on the input initial code by using multiple code modification manners, the initial code can be modified according to multiple (at least two) code modification manners to obtain the target code. Optionally, the code modification prompt word is used to instruct the large language model to perform code modification on the output initial code by referring to the input example code and according to multiple code modification manners in sequence; wherein the multiple code modification manners and the modification order are obtained from the input code modification prompt word.
[0048] Taking the case that the code modification prompt word contains the four code modification manners of code specification modification, code rewriting, code comment modification and code pruning as an example, in this case, the code modification performed by the large language model includes:
[0049] determining the code specification of the example code, and performing code specification modification on the initial code according to the code specification to obtain the first code;
[0050] performing code correlation analysis on the first code and the example code, and performing code rewriting on the first code according to the analysis result to obtain the second code;
[0051] determine a code comment specification of the example code, and perform code comment specification modification on code comments of the second code according to the code comment specification to obtain third code;
[0052] perform code parsing on the third code, and perform code reduction on the third code according to a code parsing result to obtain target code.
[0053] It should be noted that in addition to the above-provided code modification prompt word containing the four code modification modes of code specification modification, code rewriting, code comment modification and code reduction, the code modification prompt word can also include any two or any three of the four code modification modes, and the code modification performed by the large language model in the case of containing any two or any three of the code modification prompt words is similar to the above code modification implementation mode containing the four code modification modes, for example, in the case of containing code rewriting and code reduction, the code modification performed by the large language model includes: performing code association analysis on the initial code and the example code, performing code rewriting on the initial code according to the analysis result to obtain rewritten code, performing code parsing on the rewritten code, and performing code reduction on the rewritten code according to the code parsing result to obtain target code.
[0054] In actual application, the example code is input to the large language model, so that the large language model can modify the input initial code more targetedly on the basis of analyzing and understanding the example code, and improve the quality of the target code obtained after the large language model performs code modification, specifically, the example code input to the large language model can be code belonging to the same code project as the initial code, in this case, the code modification performed by the large language model is to modify the initial code by referring to the project code of the same code project, so that the consistency between the target code obtained after the code modification and the example code is higher.
[0055] In addition, the example code input to the large language model can also be code belonging to a different code project from the initial code, that is, project code of other code project (third-party project code), in this case, the code modification performed by the large language model is to modify the initial code by referring to the code of other code project, so that the quality of the target code obtained after the code modification is higher.
[0056] Optionally, the example code includes: project code belonging to the same code project as the initial code, and / or third-party project code of a third-party code project.
[0057] The following describes the specific implementation process of the code modification performed by the large language model in the case of the example code being project code and third-party project code respectively.
[0058] (1) In the case of the example code being project code, on the basis that the code modification manner includes code specification modification, code rewriting, code comment modification, and / or code deletion, the code modification prompt word containing the code modification manner is input into the large language model, and then the large language model performs code modification on the input initial code according to one or more code modification manners contained in the code modification prompt word.
[0059] Specifically, in an optional implementation manner provided by the embodiment, the code modification includes at least one of the following implementation manners:
[0060] determining the code specification of the project code, and performing code specification modification on the initial code according to the code specification;
[0061] performing code association analysis on the initial code and the project code, and performing code rewriting on the initial code according to the analysis result;
[0062] determining the code comment specification of the project code, and performing code comment specification modification on the code comment of the initial code according to the code comment specification;
[0063] performing code parsing on the initial code, and performing code deletion on the initial code according to the code parsing result.
[0064] In addition, in the process of code modification performed by the large language model, in the case that the code modification prompt word contains multiple code modification manners, that is, in the process of performing code modification on the input initial code by using multiple code modification manners, the initial code can be modified according to multiple (at least two) code modification manners to obtain the target code. Optionally, the code modification prompt word is used to instruct the large language model to perform code modification on the output initial code by referring to the input example code and according to multiple code modification manners in sequence; wherein the multiple code modification manners and the modification order are obtained from the input code modification prompt word.
[0065] Taking the case that the code modification prompt word contains code specification modification, code rewriting, code comment modification, and code deletion as an example, in this case, the code modification performed by the large language model includes:
[0066] determining the code specification of the project code, and performing code specification modification on the initial code according to the code specification to obtain first code;
[0067] performing code association analysis on the first code and the project code, and performing code rewriting on the first code according to the analysis result to obtain second code;
[0068] determine a code comment specification of the project code, and perform code comment specification modification on the code comment of the second code according to the code comment specification to obtain third code;
[0069] perform code parsing on the third code, and perform code reduction on the third code according to a code parsing result to obtain target code.
[0070] It should be noted that in addition to the above-provided code modification prompt word containing the four code modification modes of code specification modification, code rewriting, code comment modification and code reduction, the code modification prompt word can also include any two or any three of the four code modification modes, and the code modification performed by the large language model in the case of containing any two or any three of the code modification prompt words is similar to the code modification implementation mode of the code modification prompt word containing the four code modification modes, for example, in the case of containing code rewriting and code reduction in the code modification prompt word, the code modification performed by the large language model includes: performing code association analysis on the initial code and the project code, performing code rewriting on the initial code according to the analysis result to obtain rewritten code, performing code parsing on the rewritten code, and performing code reduction on the rewritten code according to the code parsing result to obtain target code.
[0071] (2) In the case of the example code being third-party project code, the initial code can be modified in code specification, code comment and / or code reduction by referring to the third-party project code, that is, at least one of the three code modification modes of code specification modification, code comment modification and code reduction can be written in the code modification prompt word, and based on this, the code modification prompt word containing the code modification mode is input into the large language model, and the large language model modifies the input initial code according to the at least one code modification mode contained in the code modification prompt word.
[0072] Specifically, in an optional implementation of the embodiment provided by the present embodiment, the code modification includes at least one of the following implementation modes: determining the code specification of the third-party project code, and modifying the initial code in code specification according to the code specification; determining the code comment specification of the third-party project code, and modifying the code comment of the initial code in code comment specification according to the code comment specification; performing code parsing on the initial code, and reducing the initial code in code according to the code parsing result.
[0073] Optionally, the code modification prompt word is used to instruct the large language model to modify the output initial code in multiple (at least two) code modification modes in turn by referring to the input example code; wherein the multiple code modification modes and the modification order are obtained from the input code modification prompt word.
[0074] Taking the code modification prompt word containing three code modification manners of code specification modification, code comment modification and code deletion as an example, in this case, the code modification performed by the large language model comprises: determining the code specification of the third-party project code, and performing code specification modification on the initial code according to the code specification to obtain first code; determining the code comment specification of the third-party project code, and performing code comment specification modification on the code comment of the first code according to the code comment specification to obtain second code; performing code parsing on the second code, and performing code deletion on the second code according to the code parsing result to obtain target code.
[0075] It should be noted that in addition to the above-provided code modification implementation manner in which the code modification prompt word contains three code modification manners of code specification modification, code comment modification and code deletion, the code modification prompt word can also include any two of code specification modification, code comment modification and code deletion. In the case where the code modification prompt word contains any two, the code modification performed by the large language model is similar to the above-mentioned code modification implementation manner in which the code modification prompt word contains three code modification manners. For example, in the case where the code modification prompt word contains code specification modification and code deletion, the code modification performed by the large language model comprises: determining the code specification of the third-party project code, and performing code specification modification on the initial code according to the code specification to obtain first code; performing code parsing on the first code, and performing code deletion on the first code according to the code parsing result to obtain target code.
[0076] In summary, the code generation method, in the process of code generation, inputs the code requirement information and the configuration generation prompt word into the large language model, generates the code configuration by means of the large language model, thereby improving the efficiency of code configuration generation, and inputs the code configuration obtained by the large language model into the code generation program to generate the initial code. Further, the code requirement information, the example code and the configuration generation prompt word are input into the large language model, so that the large language model can modify the input initial code more specifically on the basis of analyzing and understanding the example code, thereby improving the code quality of the target code obtained finally through the cooperation of the large language model and the code generation program in code configuration generation, code generation and code modification.
[0077] To further improve the specificity of the large language model in modifying the input initial code, the code modification manner of modifying the input initial code can also be added to the code modification prompt word. Based on this, the code modification prompt word containing the code modification manner and the initial code are input into the large language model, and the large language model can modify the initial code more specifically according to the code modification manner contained in the code modification prompt word.
[0078] The code generation method provided in the embodiment is described below in the application of a code generation scenario, combined with Figure 3 The code generation method provided in the embodiment is described below in the application of a code generation scenario, combined with Figure 3 The code generation method applied to the code generation scenario specifically includes the following steps.
[0079] In step S302, code requirement information is obtained, and a configuration generation prompt word of a code large language model is generated.
[0080] Optionally, the code requirement information includes code requirement description information, code storage path information, and code structure position information; and the configuration generation prompt word is used to prompt the code large language model to generate a code configuration adapted to a code generation tool according to the input code requirement information.
[0081] In step S304, the code requirement information and the configuration generation prompt word are input into the code large language model to generate a code configuration.
[0082] In step S306, the code configuration is input into the code generation tool to generate initial source code.
[0083] In step S308, example source code is obtained, and a code modification prompt word of the code large language model is generated.
[0084] Optionally, the code modification prompt word is used to prompt the code large language model to refer to the input example source code and modify the input initial source code according to a code modification manner contained in the code modification prompt word.
[0085] In step S310, the initial source code, the example source code, and the code modification prompt word are input into the code large language model to modify the code, and target source code is obtained.
[0086] Optionally, the code modification includes at least one of the following implementation manners: determining a code specification of the example source code, and modifying the initial source code according to the code specification; performing code correlation analysis on the initial source code and the example source code, and rewriting the initial source code according to an analysis result; determining a code comment specification of the example source code, and modifying a code comment of the initial source code according to the code comment specification; and performing code parsing on the initial source code, and deleting the initial source code according to a code parsing result.
[0087] It should be noted that any one of steps S302 to S310 or a combination of any multiple steps can be combined with any one of steps S202 to S206 or any multiple steps to form a new implementation manner according to the needs of implementation deployment. In addition, any one or any multiple technical features in steps S302 to S310 can be combined with any one or multiple technical features provided in steps S202 to S206 to form a new implementation manner according to the actual deployment needs. Alternatively, any one or any multiple technical features in steps S302 to S310 can be replaced by any one or multiple technical features provided in steps S202 to S206 to form a new implementation manner according to the actual deployment needs, which will not be described one by one here.
[0088] The code generation apparatus provided in the specification implements, for example:
[0089] In the above embodiment, a code generation method is provided, and a code generation apparatus corresponding thereto is also provided, which will be described below with reference to the accompanying drawings.
[0090] Reference Figure 4 which shows a schematic diagram of an embodiment of a code generation apparatus provided in the present embodiment.
[0091] Since the apparatus embodiment corresponds to the method embodiment, it is described more simply, and the related parts can be referred to the corresponding description of the method embodiment provided above. The apparatus embodiment described below is only illustrative.
[0092] The code generation apparatus provided in the present embodiment comprises:
[0093] The configuration generation module 402 is configured to input the code requirement information and the configuration generation prompt word into a large language model to generate a code configuration.
[0094] The code generation module 404 is configured to input the code configuration into a code generation program to generate an initial code.
[0095] The code modification module 406 is configured to input the initial code, the example code and the code modification prompt word into the large language model to modify the code and obtain a target code.
[0096] The code generation apparatus provided in the specification implements, for example:
[0097] Corresponding to the above-described code generation method, based on the same technical concept, one or more embodiments of the specification also provide a code generation device for executing the above-provided code generation method,Figure 5 A structural diagram of a code generation device is provided for one or more embodiments of the present specification.
[0098] The code generation device provided by the embodiment includes:
[0099] As shown in Figure 5 The code generation device can have great differences due to different configurations or performances, and can include one or more processors 501 and memories 502, and the memories 502 can store one or more storage applications or data. The memory 502 can be temporary storage or persistent storage. The application stored in the memory 502 can include one or more modules (not shown in the figure), and each module can include a series of computer executable instructions in the code generation device. Further, the processor 501 can be configured to communicate with the memory 502 and execute a series of computer executable instructions in the memory 502 on the code generation device. The code generation device can also include one or more power supplies 503, one or more wired or wireless network interfaces 504, one or more input / output interfaces 505, one or more keyboards 506, etc.
[0100] In one specific embodiment, the code generation device includes a memory and one or more programs, wherein one or more programs are stored in the memory, and one or more programs can include one or more modules, and each module can include a series of computer executable instructions in the code generation device, and the one or more processors configured to execute the one or more programs include computer executable instructions for:
[0101] Inputting the code requirement information and the configuration generation prompt into the large language model to generate a code configuration;
[0102] Inputting the code configuration into the code generation program to generate a code, and obtaining an initial code;
[0103] Inputting the initial code, the example code and the code modification prompt into the large language model to modify the code, and obtaining a target code.
[0104] The computer readable storage medium provided by the present specification can be implemented as follows:
[0105] According to the above description, based on the same technical concept, the present specification one or more embodiments also provide a computer readable storage medium.
[0106] The computer readable storage medium provided by the embodiment is used for storing computer executable instructions, and the computer executable instructions realize the following process when executed.
[0107] The code requirement information and the configuration generation prompt word are input into the large language model to generate a code configuration, and the code configuration is obtained.
[0108] The code configuration is input into a code generation program to generate a code, and the initial code is obtained.
[0109] The initial code, the example code and the code modification prompt word are input into the large language model to modify the code, and the target code is obtained.
[0110] It should be noted that the embodiment of the computer readable storage medium in the specification and the embodiment of the code generation method in the specification are based on the same inventive concept, so the specific implementation of the embodiment can be referred to the implementation of the corresponding method, and the repeated part will not be described.
[0111] The computer program product provided by the embodiment of the specification is as follows:
[0112] According to the code generation method described above, based on the same technical concept, one or more embodiments of the specification also provide a computer program product.
[0113] A computer program product includes a computer program / instruction, which, when executed by a processor, realizes the following steps:
[0114] The code requirement information and the configuration generation prompt word are input into the large language model to generate a code configuration, and the code configuration is obtained.
[0115] The code configuration is input into a code generation program to generate a code, and the initial code is obtained.
[0116] The initial code, the example code and the code modification prompt word are input into the large language model to modify the code, and the target code is obtained.
[0117] It should be noted that the embodiment of the computer readable storage medium in the specification and the embodiment of the code generation method in the specification are based on the same inventive concept, so the specific implementation of the embodiment can be referred to the implementation of the corresponding method, and the repeated part will not be described.
[0118] The various embodiments in the specification are described in progressive manner, and the same or similar parts among the various embodiments can be referred to each other, and each embodiment focuses on the difference from other embodiments, such as the device embodiment, the equipment embodiment, the computer readable storage medium embodiment, the computer program product embodiment, which are similar to the method embodiment, so the description is relatively simple, and the related content in the device embodiment, the equipment embodiment, the computer readable storage medium embodiment and the computer program product embodiment can be referred to the part of the description of the method embodiment.
[0119] The above describes specific embodiments of the specification. Other embodiments are within the scope of the appended claims. In some cases, the acts or steps recited in the claims can be performed in a different order than the order in which they are recited and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous or necessary.
[0120] In the 1930s, it was clear to distinguish whether an improvement in a technology was in hardware (e.g., improvement in circuit structure of diodes, transistors, switches, etc.) or in software (e.g., improvement in method flow). However, as technology has evolved, many improvements in method flow today can be considered as direct improvements in hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using hardware entity modules. For example, a programmable logic device (PLD) (e.g., a field programmable gate array (FPGA)) is an integrated circuit whose logic function is determined by user programming of the device. A digital system is "integrated" on a PLD by the designer programming it, rather than by asking a chip manufacturer to design and fabricate a custom integrated circuit chip. Moreover, instead of manually fabricating integrated circuit chips, this programming is now mostly implemented using "logic compiler" software, which is similar to software compilers used in program development, and the original code before compilation is written in a specific programming language, which is called a hardware description language (HDL), and there are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc., and the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should be aware that only a little logical programming of the method flow in the above-mentioned hardware description languages and programming into an integrated circuit can easily obtain a hardware circuit that implements the logical method flow.
[0121] The controller can be implemented in any suitable way, for example, the controller can take the form of a microprocessor or processor and a computer readable medium storing computer readable program code, such as software or firmware, executable by the (micro)processor, logic gates, switches, an application specific integrated circuit (ASIC), a programmable logic controller and an embedded microcontroller, examples of which include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that, in addition to implementing the controller in pure computer readable program code, it is possible to implement the same functionality in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers and embedded microcontrollers by logically programming the method steps. Such a controller can therefore be considered to be a hardware component, and the means included therein for implementing the various functions can also be considered to be structures within the hardware component. Alternatively, or even additionally, the means for implementing the various functions can be considered to be both a software module implementing the method and a structure within the hardware component.
[0122] The systems, apparatuses, modules or units illustrated by the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer can be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0123] For the sake of description, the above apparatuses are described in various units by functions respectively. Of course, the functions of each unit can be implemented in the same or multiple software and / or hardware in implementing the embodiments of the present specification.
[0124] Those skilled in the art will understand that one or more embodiments of the present specification can be provided as a method, a system or a computer program product. Therefore, one or more embodiments of the present specification can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present specification can take the form of a computer program product implemented on one or more computer readable storage media (including but not limited to disk storage, CD-ROMs, optical storage devices, etc.) containing computer usable program code.
[0125] The specification is presented with reference to flow diagrams and / or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the specification. It will be understood that each block of the flow diagrams and / or block diagrams, and combinations of blocks in the flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing system or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks. Figure 1 The flow diagrams and / or block diagrams in the specification can present a method, apparatus (system) and / or computer program product according to embodiments of the specification. It will be understood that each block of the flow diagrams and / or block diagrams, and combinations of blocks in the flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing system or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks. Figure 1 The flow diagrams and / or block diagrams in the specification can present a method, apparatus (system) and / or computer program product according to embodiments of the specification. It will be understood that each block of the flow diagrams and / or block diagrams, and combinations of blocks in the flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing system or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks.
[0126] These computer program instructions can also be loaded into a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks. Figure 1 The flow diagrams and / or block diagrams in the specification can present a method, apparatus (system) and / or computer program product according to embodiments of the specification. It will be understood that each block of the flow diagrams and / or block diagrams, and combinations of blocks in the flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing system or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks. Figure 1 The flow diagrams and / or block diagrams in the specification can present a method, apparatus (system) and / or computer program product according to embodiments of the specification. It will be understood that each block of the flow diagrams and / or block diagrams, and combinations of blocks in the flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing system or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks.
[0127] These computer program instructions can also be loaded into a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks. Figure 1 The flow diagrams and / or block diagrams in the specification can present a method, apparatus (system) and / or computer program product according to embodiments of the specification. It will be understood that each block of the flow diagrams and / or block diagrams, and combinations of blocks in the flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing system or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks. Figure 1 The flow diagrams and / or block diagrams in the specification can present a method, apparatus (system) and / or computer program product according to embodiments of the specification. It will be understood that each block of the flow diagrams and / or block diagrams, and combinations of blocks in the flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing system or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks.
[0128] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0129] The memory can include non-persistent memory, Random Access Memory (RAM), and / or non-volatile memory, such as Read Only Memory (ROM) or flash memory, among others. The memory is an example of computer-readable media.
[0130] Computer-readable media includes permanent and non-permanent, movable and non-movable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer-readable storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible by a computing device. According to the definition herein, computer-readable media does not include transitory media such as modulated data signals and carriers.
[0131] It should also be noted that the terms "comprising", "containing", or any other variant thereof are intended to cover non-exclusive inclusion, such that processes, methods, articles or devices that comprise a list of elements not only include those elements, but also include other elements not expressly listed or inherent to such processes, methods, articles or devices. Without more limitations, the element defined by the phrase "comprising at least one" does not exclude the presence of additional identical elements in the process, method, article or device that includes the element.
[0132] One or more embodiments of the present specification can be described in the general context of computer-executable instructions being executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform particular tasks or implement particular abstract data types. One or more embodiments of the present specification can also be practiced in a distributed computing environment, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media, including storage devices.
[0133] The above only describes the embodiments of the present document and is not intended to limit the present document. For those skilled in the art, the present document can have various changes and variations. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present document shall be included in the scope of claims of the present document.
Claims
1. A code generation method, comprising: Input the code requirements information and configuration generation prompts into the large language model to generate the code configuration. The code configuration is input into a code generation program to generate initial code. The initial code, sample code, and code modification prompts are input into the large language model to modify the code and obtain the target code. The code modification includes: determining the code style of the example code and modifying the initial code according to the code style to obtain the first code; determining the code comment style of the example code and modifying the code comments of the first code according to the code comment style to obtain the second code; parsing the second code and deleting code from the second code according to the code parsing results to obtain the target code.
2. The code generation method according to claim 1, wherein the code requirement information includes: Code requirement description information, code storage path information, and code structure location information.
3. The code generation method according to claim 1, wherein the configuration generation prompt is used to prompt the large language model to generate code configuration adapted to the code generation program based on the input code requirement information.
4. The code generation method according to claim 1, wherein the code modification prompt is used to prompt the large language model to modify the input initial code according to the input example code and the code modification method contained in the code modification prompt.
5. The code generation method according to claim 4, wherein the code modification method includes at least one of the following: code style modification, code rewriting, code comment modification, and code deletion.
6. The code generation method according to claim 1, wherein the code modification includes at least one of the following implementation methods: Determine the coding style of the example code, and modify the initial code according to the coding style; Perform code association analysis on the initial code and the example code, and rewrite the initial code based on the analysis results; Determine the code commenting style of the example code, and modify the code comments of the initial code according to the code commenting style; The initial code is parsed, and code deletion is performed based on the parsing results.
7. A code generation apparatus, comprising: The configuration generation module is configured to input code requirement information and configuration generation prompts into a large language model to generate code configuration and obtain the code configuration. The code generation module is configured to input the code configuration into the code generation program to generate code and obtain initial code. The code modification module is configured to input the initial code, sample code, and code modification prompts into the large language model to modify the code and obtain the target code. The code modification includes: determining the code style of the example code and modifying the initial code according to the code style to obtain the first code; determining the code comment style of the example code and modifying the code comments of the first code according to the code comment style to obtain the second code; parsing the second code and deleting code from the second code according to the code parsing results to obtain the target code.
8. A code generation device, comprising: processor; And, a memory configured to store computer-executable instructions, which, when executed, cause the processor to: Input the code requirements information and configuration generation prompts into the large language model to generate the code configuration. The code configuration is input into a code generation program to generate initial code. The initial code, sample code, and code modification prompts are input into the large language model to modify the code and obtain the target code. The code modification includes: determining the code style of the example code and modifying the initial code according to the code style to obtain the first code; determining the code comment style of the example code and modifying the code comments of the first code according to the code comment style to obtain the second code; parsing the second code and deleting code from the second code according to the code parsing results to obtain the target code.
9. A computer-readable storage medium for storing computer-executable instructions that, when executed, implement the steps of the method of claim 1.
Citation Information
Patent Citations
Training method and device for security code generation model
CN117369783A
Code change label generation method, device and equipment
CN117725920A