Code generation method and device

By using large language models to generate code configuration and modify codes during the code generation process, the problem of insufficient code quality in the existing technology is solved, and more efficient and high-quality code generation is achieved.

CN119781772AActive Publication Date: 2025-04-08ALIPAY (HANGZHOU) INFORMATION TECH CO LTD

Patent Information

Application Number
CN202411864390.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-17
Publication Date
2025-04-08
Estimated Expiration
2044-12-17

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively improve the code quality during the code generation process, resulting in insufficient efficiency and quality of the generated code.

Method used

By inputting code requirements information and configuration generation prompt words into the large language model, generating code configuration, and inputting the code configuration into the code generation program to generate initial code, and then inputting the initial code, sample code and code modification prompt words into the large language model for code modification, to obtain the target code.

Benefits of technology

The quality and efficiency of code generation are improved. Through the analysis and modification of large language models, the generated target code is more in line with the code needs and has higher quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781772A_ABST
    Figure CN119781772A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code generation method and device.The code generation method comprises the steps that in the code generation process, code requirement information and configuration generation cue words are input into a large language model, code configuration generation is conducted through the large language model, and code configuration is obtained; and inputting the code configuration into a code generation program for code generation to obtain an initial code, and further inputting the initial code, an example code and a code modification prompt word into a large language model for code modification to obtain a target code, so that high-quality code generation is performed through the cooperation of the code large model and the code generation program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This document relates to the field of software development technology, and in particular to a code generation method and device. Background Art

[0002] Code generation is widely used in software development projects. Code can be generated quickly through code generation, helping 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 generate corresponding code according to the input instructions or requirements is an important code generation method. As the application of code generation becomes more and more common, how to improve the quality of code generation has become the focus of software development projects. Summary of the invention

[0003] One or more embodiments of the present specification provide a code generation method, including: inputting code requirement information and configuration generation prompt words into a large language model to generate code configuration, and obtain code configuration. Inputting the code configuration into a code generation program to generate code, and obtain initial code. Inputting the initial code, sample code, and code modification prompt words into the large language model to modify the code, and obtain target code.

[0004] One or more embodiments of the present specification provide a code generation device, including: a configuration generation module, configured to input code requirement information and configuration generation prompt words into a large language model to generate code configuration, and obtain code configuration. A code generation module, configured to input the code configuration into a code generation program to generate code, and obtain initial code. A code modification module, configured to input the initial code, sample 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, including: a processor; and a memory configured to store computer executable instructions, wherein when the computer executable instructions are executed, the processor: inputs code requirement information and configuration generation prompt words into a large language model to generate code configuration, and obtains code configuration. Inputs the code configuration into a code generation program to generate code, and obtains initial code. Inputs the initial code, sample code, and code modification prompt words into the large language model to modify the code, and obtains target code.

[0006] One or more embodiments of the present specification provide a computer-readable storage medium for storing computer-executable instructions, which implement the following process when executed: input code requirement information and configuration generation prompt words into a large language model to generate code configuration and obtain code configuration. Input the code configuration into a code generation program to generate code and obtain initial code. Input the initial code, sample code and code modification prompt words into the large language model to modify the code and obtain target code. BRIEF DESCRIPTION OF THE DRAWINGS

[0007] In order to more clearly illustrate one or more embodiments of the present specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present specification. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative labor. Figure 1 A schematic diagram of an implementation environment of a code generation method provided for one or more embodiments of this specification; Figure 2 A code generation method processing flow chart provided for one or more embodiments of this specification; Figure 3 A code generation method processing flow chart applied to a code generation scenario provided by one or more embodiments of this specification; Figure 4 A schematic diagram of an embodiment of a code generation device provided in one or more embodiments of this specification; Figure 5 A schematic diagram of the structure of a code generation device provided in one or more embodiments of this specification. DETAILED DESCRIPTION

[0008] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the technical solutions in one or more embodiments of this specification will be clearly and completely described below in conjunction with the drawings in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this document.

[0009] The code generation method provided in one or more embodiments of this specification can be applied to the implementation environment of the code generation system. Figure 1 , the implementation environment at least includes: The code generation module 101, the large language model 102, the code generation program 103, and the local code repository 104 for storing sample codes may also be included; Among them, the code generation module 101 is used to obtain code requirement information, generate configuration generation prompt words and code modification prompt words, and input the code requirement information and configuration generation prompt words to the large language model 102, obtain the code configuration generated by the large language model 102 and input it to the code generation program 103, obtain the initial code generated by the code generation program 103, and input the initial code, sample code and code modification prompt words to the large language model 102; the large language model 102 is used to generate and output the code configuration according to the input code requirement information and configuration generation prompt words, and perform code modification and output the target code according to the input initial code, sample code and code modification prompt words; the code generation program 103 is used to generate the initial code according to the input code configuration.

[0010] In this implementation environment, during the code generation process, the code generation module 101 obtains code requirement information for code generation, and inputs the code requirement information and configuration generation prompt words into the large language model 102, and performs code configuration generation 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, and 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 sample code can be obtained from the local code repository 104, and the initial code, the sample code and the code modification prompt words are input into the large language model 102. The code modification prompt words are used to prompt the large language model 102 to make corresponding code modifications to the initial code based on the reference input sample code, so as to achieve high-quality code generation through the cooperation of the large language model 102 and the code generation program 103.

[0011] One or more embodiments of a code generation method provided in this specification are as follows: Reference Figure 2 The code generation method provided in this embodiment specifically includes steps S202 to S206.

[0012] Step S202: input the code requirement information and configuration generation prompt words into the large language model to generate code configuration and obtain code configuration.

[0013] The code requirement information described in this embodiment refers to the requirements and specifications for the code in the software development process in order to make the code meet specific needs; for example, the role of functional code requirements is to enable the code to meet the corresponding functions. Taking the login function requirement as an example, if the code requirement includes the login function, the code must be able to implement the login function; for another example, the role of non-functional code requirements is to enable the code to meet non-functional requirements from the corresponding angles. Taking the performance requirement as an example, if the code requirement includes a response time of no more than 2 seconds, the response time of the code during operation must be within 2 seconds.

[0014] Optionally, the code requirement information includes code requirement description information. In addition, the code requirement information may also include the code requirement description information and at least one of the code storage path information and the code structure location 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 location information, or the code requirement information includes the code requirement description information, the code storage path information and the code structure location information.

[0015] Among them, the code requirement description information may include description fields of functional code requirements and / or non-functional code requirements; the code storage path information refers to the storage path information of the code to be generated in the code repository; the code structure location information refers to the specific location information of the code to be generated in the code file or code project, for example, the code structure location information can be the corresponding code generated between class xx1 and class xx2 in the xx code file.

[0016] In specific implementation, during the process of code generation, code configuration is generated through a large language model, and code generation is performed based on the generated code configuration. Here, the generation of code configuration with the help of a large language model can improve the efficiency of code configuration generation. Specifically, in the process of code configuration generation through a large language model, code requirement information and configuration generation prompt words are input into the large language model to generate code configuration to obtain the code configuration.

[0017] Among them, the large language model can be a pre-trained large language model (LLM), such as a large language model using a 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 to obtain a large language model that can handle specific tasks to adapt to specific fields or task requirements. In this embodiment, the pre-trained large language model is fine-tuned in the code field to obtain a code large language model that can perform code-related processing in the code field, that is, the large language model can be a code large language model.

[0018] Specifically, in the process of performing code configuration generation through the large language model, the code configuration is obtained by inputting code requirement information and configuration generation prompt words into the large language model for code configuration generation, wherein the configuration generation prompt words refer to prompting the large language model to perform code generation according to the input code requirement information; Further, in the scenario where the code configuration is generated by the large language model in the present embodiment and the code is generated by the code generation program, and considering that the input specifications or contents of different code generation tools in actual applications may be different, in order to make the code generated by the code generation program more in line with the code requirements, in the process of performing code configuration generation by the large language model, the large language model may be prompted to generate a code configuration that is adapted to the code generation program that performs code generation subsequently by configuring a prompt word. Optionally, the configuration generates a prompt word to prompt the large language model to generate a code configuration that is adapted to the code generation program according to the input code requirement information; Based on this, on the basis that the generated code configuration is adapted as much as possible to the code generation program for subsequent code generation, the code generation performed 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 better meet the code requirements.

[0019] Step S204: input the code configuration into a code generation program to generate code and obtain an initial code.

[0020] During the specific execution process, after the code requirement information and configuration generation prompt words are input into the large language model for code configuration generation to obtain the 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 refers to the code generated for the code requirement information. The initial code can be in the form of source code or encoded code.

[0021] The code generation program refers to a tool application for code generation, such as MyBatis Generator (automatic code generator).

[0022] Step S206: input the initial code, sample code and code modification prompt words into the large language model to perform code modification to obtain a target code.

[0023] In a specific implementation, after the initial code is generated by the large language model through the code generation configuration in conjunction with the code generation program, in order to improve the code quality of the initial code, the initial code and the code modification prompt words are input into the large language model, and the ability of the large language model is used to modify and optimize the initial code generated above to improve the code quality; wherein the code modification prompt words can be prompt words used to instruct the large language model to modify the input initial code.

[0024] Furthermore, in order to make the code obtained by the large language model through code modification meet the code requirements as much as possible, sample code can also be input into the large language model, so that the large language model can make more targeted modifications to the input initial code based on the analysis and understanding of the sample code; in this case, the code prompt word can also be a prompt word used to instruct the large language model to make code modifications to the input initial code with reference to the input sample code.

[0025] Specifically, in order to further improve the pertinence of the large language model in making code modifications to the input initial code, a code modification method for making changes to the input initial code can also be added to the code modification prompt word. Based on this, after the code modification prompt word containing the code modification method and the initial code are input into the large language model, the large language model can make corresponding code modifications to the initial code according to the code modification method contained in the code modification prompt word. Optionally, the code modification prompt word is used to prompt the large language model to refer to the input sample code and make code modifications to the input initial code according to the code modification method contained in the code modification prompt word.

[0026] Optionally, the code modification method includes at least one of the following: code standard modification, code rewriting, code comment modification, and code deletion.

[0027] Among them, code specification modification refers to modifying the code specification of the input initial code with reference to the code specification of the sample code, so that the code specification of the modified initial code is as similar as possible to the code specification of the sample code. The code specification can specifically be the naming specification, indentation and space specification, code structure specification, etc. in the initial code.

[0028] Code rewriting refers to reconstructing or modifying the input initial code with reference to sample code to improve the code structure or performance of the initial code, such as reducing the complexity of the initial code to make it meet new technical standards.

[0029] Code comment modification refers to modifying the code comments in the input initial code with reference to the sample code, such as modifying the line comments, block comments, and document comments of the initial code to make the modified code comment style consistent with the style of the sample code.

[0030] Code reduction refers to deleting redundant code in the initial code based on analyzing and identifying the initial code, such as deleting the interface call sample code of an interface in the initial code, or deleting the algorithm sample code of an algorithm in the initial code.

[0031] During the specific execution process, on the basis of code modification methods including code standard modification, code rewriting, code comment modification and / or code deletion, after a code modification prompt word containing a code modification method is input into the large language model, the large language model performs code modification on the input initial code according to one or more code modification methods contained in the code modification prompt word.

[0032] Specifically, in an optional implementation manner provided in this embodiment, code modification includes at least one of the following implementation manners: Determine the code standards for the sample code and modify the initial code according to the code standards; Conduct code correlation analysis on the initial code and sample code, and rewrite the initial code based on the analysis results; Determine the code comment standard of the sample code, and modify the code comment standard of the initial code according to the code comment standard; The initial code is parsed and the initial code is reduced according to the parsing result.

[0033] In addition, when the large language model is modifying the code, if the code modification prompt contains multiple code modification methods, that is, when the input initial code is modified using multiple code modification methods, the initial code can be modified in sequence according to multiple (at least two) code modification methods to obtain the target code. Optionally, the code modification prompt is used to instruct the large language model to modify the output initial code in sequence according to multiple code modification methods with reference to the input sample code; wherein the multiple code modification methods and modification order are obtained from the input code modification prompt.

[0034] For example, the code modification prompt words include code standard modification, code rewriting, code comment modification, and code deletion. In this case, the code modification performed by the large language model includes: Determine a code specification of the sample code, and modify the initial code according to the code specification to obtain a first code; Performing code association analysis on the first code and the sample code, and rewriting the first code according to the analysis result to obtain the second code; Determine a code comment standard of the sample code, and modify the code comment of the second code according to the code comment standard to obtain a third code; The third code is parsed, and the third code is pruned according to the parsing result to obtain the target code.

[0035] It should be noted that, in addition to the code modification implementation method in which the code modification prompt words provided above include the four code modification methods of code standard modification, code rewriting, code comment modification and code deletion, the code modification prompt words may also include any two or any three of the four code modification methods of code standard modification, code rewriting, code comment modification and code deletion. The code modification performed by the large language model when the code modification prompt words include any two or any three of the four code modification methods is similar to the code modification implementation method in which the code modification prompt words include the four code modification methods. For example, when the code modification prompt words include code rewriting and code deletion, the code modification performed by the large language model includes: performing code association analysis on the initial code and the sample code, rewriting the initial code according to the analysis results to obtain the rewritten code, parsing the rewritten code, and deleting the rewritten code according to the code parsing results to obtain the target code.

[0036] In practical applications, sample codes are input to the large language model so that the large language model can make more targeted modifications to the input initial code based on the analysis and understanding of the sample codes, with reference to the sample codes, thereby improving the quality of the target code obtained after the large language model makes code modifications. Specifically, the sample code input to the large language model may be code belonging to the same code project as the initial code. In this case, the code modification made by the large language model is to modify the initial code with reference to the project code of the same code project, so that the target code obtained after the code modification is more consistent with the sample code. In addition, the sample 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 projects (third-party project code). In this case, the code modification performed by the large language model is to modify the initial code with reference to the code of other code projects, so that the quality of the target code obtained by code modification is higher.

[0037] Optionally, sample 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.

[0038] The following describes the specific implementation process of code modification performed by the large language model in two cases: the sample code is project code and the sample code is a third-party project code.

[0039] (1) When the sample code is a project code, on the basis of the code modification methods including code specification modification, code rewriting, code comment modification and / or code deletion, after a code modification prompt word containing the code modification method is input into the large language model, the large language model performs code modification on the input initial code according to one or more code modification methods contained in the code modification prompt word.

[0040] Specifically, in an optional implementation manner provided in this embodiment, code modification includes at least one of the following implementation manners: Determine the code standards for the project code and modify the initial code according to the code standards; Conduct code correlation analysis on the initial code and project code, and rewrite the initial code based on the analysis results; Determine the code comment standards for the project code, and modify the code comment standards for the initial code according to the code comment standards; The initial code is parsed and the initial code is reduced according to the parsing result.

[0041] In addition, when the large language model is modifying the code, if the code modification prompt contains multiple code modification methods, that is, when the input initial code is modified using multiple code modification methods, the initial code can be modified in sequence according to multiple (at least two) code modification methods to obtain the target code. Optionally, the code modification prompt is used to instruct the large language model to modify the output initial code in sequence according to multiple code modification methods with reference to the input sample code; wherein the multiple code modification methods and modification order are obtained from the input code modification prompt.

[0042] For example, the code modification prompt words include code standard modification, code rewriting, code comment modification, and code deletion. In this case, the code modification performed by the large language model includes: Determine the code standard of the project code, and modify the initial code according to the code standard to obtain the first code; Performing code correlation analysis on the first code and the project code, and rewriting the first code according to the analysis result to obtain a second code; Determine a code comment specification of the project code, and modify the code comment specification of the second code according to the code comment specification to obtain a third code; The third code is parsed, and the third code is pruned according to the parsing result to obtain the target code.

[0043] It should be noted that, in addition to the code modification implementation method in which the code modification prompt words provided above include the four code modification methods of code standard modification, code rewriting, code comment modification and code deletion, the code modification prompt words may also include any two or any three of the four code modification methods of code standard modification, code rewriting, code comment modification and code deletion. The code modification performed by the large language model when the code modification prompt words include any two or any three of the four code modification methods is similar to the code modification implementation method in which the code modification prompt words include the four code modification methods. For example, when the code modification prompt words include code rewriting and code deletion, the code modification performed by the large language model includes: performing code association analysis on the initial code and the project code, rewriting the initial code according to the analysis results to obtain the rewritten code, parsing the rewritten code, and deleting the rewritten code according to the code parsing results to obtain the target code.

[0044] (2) When the sample code is a third-party project code, the initial code may be modified in code standard, code comment and / or code deletion with reference to the third-party project code. That is, at least one of the three code modification methods, code standard modification, code comment modification and code deletion, may be written in the code modification prompt word. Based on this, after the code modification prompt word containing the code modification method is input into the large language model, the large language model performs code modification on the input initial code according to at least one code modification method contained in the code modification prompt word.

[0045] Specifically, in an optional implementation manner provided by this embodiment, code modification includes at least one of the following implementation methods: determining the code specifications of the third-party project code, and modifying the initial code according to the code specifications; determining the code comment specifications of the third-party project code, and modifying the code comment specifications of the initial code according to the code comment specifications; performing code parsing on the initial code, and deleting the initial code according to the code parsing results.

[0046] Optionally, the code modification prompt word is used to instruct the large language model to refer to the input sample code and modify the output initial code in sequence according to multiple (at least two) code modification methods; wherein the multiple code modification methods and the modification order are obtained from the input code modification prompt word.

[0047] Taking the example that the code modification prompt words include three code modification methods: code standard modification, code comment modification and code deletion, in this case, the code modification performed by the large language model includes: determining the code standard of the third-party project code, and modifying the initial code according to the code standard to obtain a first code; determining the code comment standard of the third-party project code, and modifying the code comment of the first code according to the code comment standard to obtain a second code; performing code analysis on the second code, and deleting the second code according to the code analysis result to obtain a target code.

[0048] It should be noted that, in addition to the code modification implementation method in which the code modification prompt words provided above include the three code modification methods of code standard modification, code comment modification and code deletion, the code modification prompt words may also include any two of the code standard modification, code comment modification and code deletion. The code modification performed by the large language model when the code modification prompt words include any two of the three code modification methods is similar to the code modification implementation method in which the code modification prompt words include the three code modification methods. For example, when the code modification prompt words include code standard modification and code deletion, the code modification performed by the large language model includes: determining the code standard of the third-party project code, and performing code standard modification on the initial code according to the code standard to obtain a first code; performing code parsing on the first code, and performing code parsing deletion on the first code according to the code parsing result to obtain a target code.

[0049] In summary, the code generation method, in the process of code generation, inputs code requirement information and configuration generation prompt words into a large language model, generates code configuration with the help 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 a code generation program for code generation to obtain initial code, and further inputs code requirement information, sample code and configuration generation prompt words into the large language model, so that the large language model can make more targeted modifications to the input initial code based on the analysis and understanding of the sample code, with reference to the sample code, thereby improving the code quality of the target code finally obtained through the code configuration generation, code generation and code modification performed by the cooperation of the large language model and the code generation program; In order to further improve the targeted code modification of the input initial code by the large language model, the code modification method of what kind of modification to make to the input initial code can also be added to the code modification prompt word. Based on this, after the code modification prompt word containing the code modification method and the initial code are input into the large language model, the large language model can make more targeted code modifications to the initial code according to the code modification method contained in the code modification prompt word.

[0050] The following takes the application of a code generation method provided in this embodiment in a code generation scenario as an example, combined with Figure 3 , the code generation method provided in this embodiment is further described, see Figure 3 , a code generation method applied to a code generation scenario specifically includes the following steps.

[0051] Step S302, obtaining code requirement information, and generating configuration generation prompt words for the code language model.

[0052] Optionally, the code requirement information includes code requirement description information, code storage path information and code structure location information; the configuration generates prompt words, which are used to prompt the code language model to generate code configuration adapted to the code generation tool according to the input code requirement information.

[0053] Step S304: input the code requirement information and configuration generation prompt words into the code language model to generate code configuration and obtain code configuration.

[0054] Step S306: input the code configuration into a code generation tool to generate source code to obtain initial source code.

[0055] Step S308, obtaining sample source code, and generating code modification prompt words of the code language model.

[0056] Optionally, a code modification prompt word is used to prompt the code language model to refer to the input sample source code and perform code modification on the input initial source code according to the code modification method included in the code modification prompt word.

[0057] Step S310: input the initial source code, the sample source code and the code modification prompt words into the code language model to perform code modification to obtain the target source code.

[0058] Optionally, the code modification includes at least one of the following implementation methods: determining a code specification for the example source code, and modifying the code specification of the initial source code according to the code specification; performing a code association analysis on the initial source code and the example source code, and rewriting the initial source code according to the analysis results; determining a code comment specification for the example source code, and modifying the code comment specification of the initial source code according to the code comment specification; performing code parsing on the initial source code, and deleting code from the initial source code according to the code parsing results.

[0059] It should be noted that any one of steps S302 to S310 or any combination of multiple steps can be combined with any one of steps S202 to S206 to form a new implementation method according to the needs of implementation deployment; in addition, according to the needs of actual deployment, any one or multiple technical features can be selected from steps S302 to S310 and combined with any one or multiple technical features provided by steps S202 to S206 to form a new implementation method; or, any one or multiple technical features in steps S302 to S310 can be replaced with any one or multiple technical features provided by steps S202 to S206 to form a new implementation method according to the needs of actual deployment, which will not be elaborated here.

[0060] An embodiment of a code generation device provided in this specification is as follows: In the above-mentioned embodiment, a code generation method is provided, and correspondingly, a code generation device is also provided, which will be described below in conjunction with the accompanying drawings.

[0061] Reference Figure 4 , which shows a schematic diagram of an embodiment of a code generation device provided in this embodiment.

[0062] Since the device embodiment corresponds to the method embodiment, the description is relatively simple, and the relevant parts can refer to the corresponding description of the method embodiment provided above. The device embodiment described below is only illustrative.

[0063] This embodiment provides a code generation device, the device comprising: The configuration generation module 402 is configured to input the code requirement information and the configuration generation prompt words into the large language model to generate the code configuration and obtain the code configuration; The code generation module 404 is configured to input the code configuration into a code generation program to generate code and obtain an initial code; The code modification module 406 is configured to input the initial code, sample code and code modification prompt words into the large language model to perform code modification and obtain target code.

[0064] An embodiment of a code generation device provided in this specification is as follows: Corresponding to the code generation method described above, based on the same technical concept, one or more embodiments of this specification also provide a code generation device, which is used to execute the code generation method provided above. Figure 5 A schematic diagram of the structure of a code generation device provided in one or more embodiments of this specification.

[0065] This embodiment provides a code generation device, including: like Figure 5 As shown, the code generation device may have relatively large differences due to different configurations or performances, and may include one or more processors 501 and memory 502, and the memory 502 may store one or more storage applications or data. Among them, the memory 502 may be a short-term storage or a persistent storage. The application stored in the memory 502 may include one or more modules (not shown in the figure), and each module may include a series of computer executable instructions in the code generation device. Furthermore, the processor 501 may 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 may 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.

[0066] In a specific embodiment, the code generation device includes a memory and one or more programs, wherein the one or more programs are stored in the memory, and the one or more programs may include one or more modules, and each module may include a series of computer executable instructions in the code generation device, and the one or more programs configured to be executed by one or more processors include the following computer executable instructions: Inputting the code requirement information and configuration generation prompt words into the large language model to generate code configuration and obtain code configuration; Inputting the code configuration into a code generation program to generate code and obtain an initial code; The initial code, sample code and code modification prompt words are input into the large language model to perform code modification to obtain the target code.

[0067] An embodiment of a computer-readable storage medium provided in this specification is as follows: Corresponding to the code generation method described above, based on the same technical concept, one or more embodiments of this specification also provide a computer-readable storage medium.

[0068] The computer-readable storage medium provided in this embodiment is used to store computer-executable instructions, and the computer-executable instructions implement the following process when executed: Inputting the code requirement information and configuration generation prompt words into the large language model to generate code configuration and obtain code configuration; Inputting the code configuration into a code generation program to generate code and obtain an initial code; The initial code, sample code and code modification prompt words are input into the large language model to perform code modification to obtain the target code.

[0069] It should be noted that an embodiment of a computer-readable storage medium in this specification and an embodiment of a code generation method in this specification are based on the same inventive concept, so the specific implementation of this embodiment can refer to the implementation of the aforementioned corresponding method, and the repeated parts will not be repeated.

[0070] An embodiment of a computer program product provided in this specification is as follows: Corresponding to the code generation method described above, based on the same technical concept, one or more embodiments of this specification also provide a computer program product.

[0071] A computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the following steps: Inputting the code requirement information and configuration generation prompt words into the large language model to generate code configuration and obtain code configuration; Inputting the code configuration into a code generation program to generate code and obtain an initial code; The initial code, sample code and code modification prompt words are input into the large language model to perform code modification to obtain the target code.

[0072] It should be noted that an embodiment of a computer program product in this specification and an embodiment of a code generation method in this specification are based on the same inventive concept, so the specific implementation of this embodiment can refer to the implementation of the aforementioned corresponding method, and the repeated parts will not be repeated.

[0073] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments. For example, the device embodiment, equipment embodiment, computer-readable storage medium embodiment, and computer program product embodiment are similar to the method embodiment, so the description is relatively simple. To read the relevant contents of the device embodiment, equipment embodiment, computer-readable storage medium embodiment, and computer program product embodiment, please refer to the partial description of the method embodiment.

[0074] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0075] In the 1930s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to circuit structures such as diodes, transistors, switches, etc.) or software improvements (improvements to method flows). However, with the development of technology, many of today's method flow improvements can be regarded as direct improvements to hardware circuit structures. 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) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask chip manufacturers to design and produce dedicated integrated circuit chips. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one kind of HDL, but many kinds, 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. The most commonly used ones are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages ​​and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.

[0076] The controller may be implemented in any suitable manner, for example, the controller may take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (e.g., software or firmware) executable by the (micro)processor, a logic gate, a switch, 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, and the memory controller may also be implemented as part of the control logic of the memory. It is also known to those skilled in the art that, in addition to implementing the controller in a purely computer-readable program code manner, the controller may be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, such a controller may be considered as a hardware component, and the devices for implementing various functions included therein may also be considered as structures within the hardware component. Or even, the devices for implementing various functions may be considered as both software modules for implementing the method and structures within the hardware component.

[0077] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, 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.

[0078] For the convenience of description, the above devices are described in terms of functions and are divided into various units. Of course, when implementing the embodiments of this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0079] It should be understood by those skilled in the art that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present specification may 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-ROM, optical storage, etc.) containing computer-usable program code.

[0080] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable code generating device to generate a machine, so that the instructions executed by the processor of the computer or other programmable code generating device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0081] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable code generating device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0082] These computer program instructions may also be loaded onto a computer or other programmable code generating device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0083] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0084] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0085] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. 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 technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.

[0086] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of further restrictions, the elements defined by the sentence "includes at least one ..." do not exclude the presence of other identical elements in the process, method, commodity or device including the elements.

[0087] One or more embodiments of the present specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of the present specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0088] The above description is only an embodiment of this document and is not intended to limit this document. For those skilled in the art, this document may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this document should be included in the scope of the claims of this document.

Claims

1. A code generation method, comprising: Inputting the code requirement information and configuration generation prompt words into the large language model to generate code configuration and obtain code configuration; Inputting the code configuration into a code generation program to generate code and obtain an initial code; The initial code, sample code and code modification prompt words are input into the large language model to perform code modification to obtain the target code.

2. The code generation method according to claim 1, wherein the code requirement information comprises: 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 generates a prompt word for prompting the large language model to generate a code configuration adapted to the code generation program according to the input code requirement information.

4. The code generation method according to claim 1, wherein the code modification prompt word is used to prompt the large language model to modify the input initial code according to the input sample code and the code modification method contained in the code modification prompt word.

5. According to the code generation method of claim 4, the code modification method includes at least one of the following: code standard modification, code rewriting, code comment modification, and code deletion.

6. The code generation method according to claim 1, wherein the code modification comprises at least one of the following implementations: Determine a code standard of the sample code, and modify the initial code according to the code standard; Performing code correlation analysis on the initial code and the sample code, and rewriting the initial code according to the analysis result; Determining a code comment specification of the sample code, and modifying the code comment specification of the initial code according to the code comment specification; The initial code is parsed, and the initial code is pruned according to the parsing result.

7. The code generation method according to claim 1, wherein the code modification comprises: Determine a code specification of the sample code, and modify the initial code according to the code specification to obtain a first code; Determine a code comment specification of the sample code, and modify the code comment specification of the first code according to the code comment specification to obtain a second code; The second code is parsed, and according to the code parsing result, the second code is pruned to obtain the target code.

8. A code generating device, comprising: A configuration generation module is configured to input code requirement information and configuration generation prompt words into a large language model to generate code configuration and obtain code configuration; A code generation module is configured to input the code configuration into a code generation program to generate code and obtain an initial code; The code modification module is configured to input the initial code, sample code and code modification prompt words into the large language model to perform code modification and obtain the target code.

9. A code generating device comprising: processor; and a memory configured to store computer executable instructions that, when executed, cause the processor to: Inputting the code requirement information and configuration generation prompt words into the large language model to generate code configuration and obtain code configuration; Inputting the code configuration into a code generation program to generate code and obtain an initial code; The initial code, sample code and code modification prompt words are input into the large language model to perform code modification to obtain the target code.

10. A computer-readable storage medium for storing computer-executable instructions, wherein the computer-executable instructions implement the steps of the method of claim 1 when executed.

Citation Information

Patent Citations

  • Training method and device for security code generation model

    CN117369783A

  • Code change label generation method, device and equipment

    CN117725920A

  • Programming language conversion method and device, equipment and storage medium

    CN118940721A

  • API code generation method and device, equipment, medium and program product

    CN119127152A

  • Method for generating a code for an electronic control unit

    US9417853B1

Cited By

  • Code generation method and device based on large model

    CN120929061A