Code generation method and device based on large model and electronic equipment
Through the code generation method based on large models, complex code generation tasks are split into sub-tasks, solving the problem of insufficient code generation efficiency and quality in the existing technology, achieving efficient and accurate code generation, and improving software development efficiency and quality.
Patent Information
- Application Number
- CN202411824176.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2044-12-11
AI Technical Summary
The prior art is difficult to accurately and efficiently generate the code required for complex software development projects, and cannot meet the needs of improving the efficiency and quality of software development.
The code generation method based on the big model is adopted, and the object code needs are obtained, the requirement analysis is performed, the processing tasks of the data object are split into subtasks, and the object code is generated based on these subtasks.
It realizes the splitting of complex code generation tasks into smaller granular subtasks through large models, which improves the accuracy and efficiency of code generation, meets the code generation needs of complex software development projects, and improves the efficiency and quality of software development.
Smart Images

Figure CN119759356A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the fields of artificial intelligence technologies such as big models, model training, and deep learning, and can be applied to scenarios such as code generation and software development, such as generative search, intelligent assistants, code recommendations, and more, in particular to code generation methods, devices, and electronic devices based on big models. Background Art
[0002] With the rapid development of software development, the demand for automatic code generation is increasing. How to generate code accurately and efficiently to meet the code generation needs in complex software development projects is of great significance to improving software development efficiency and quality. Summary of the invention
[0003] The present disclosure provides a code generation method, device and electronic device based on a large model.
[0004] According to a first aspect of the present disclosure, a code generation method based on a big model is provided, comprising: obtaining target code requirements; performing a demand analysis on the target code requirements through a big model to obtain data objects involved in the target code requirements, and splitting the processing tasks of the data objects into at least one subtask; based on the at least one subtask, generating a target code corresponding to the target code requirements through the big model.
[0005] According to a second aspect of the present disclosure, a target model training method is provided, comprising: obtaining a training sample set, wherein the training sample set includes a first training sample and a second training sample; using the first training sample to train an initial large model to obtain a first large model, wherein the first large model is used to perform a demand analysis on a target code requirement, obtain a data object involved in the target code requirement, and split a processing task for the data object into at least one subtask; using the second training sample to train the first large model to obtain a target large model, wherein the target large model is used to generate a target code corresponding to the target code requirement based on the at least one subtask.
[0006] According to a third aspect of the present disclosure, a code generation device based on a big model is provided, including: a first acquisition module, used to obtain target code requirements; a processing module, used to perform demand analysis on the target code requirements through the big model, obtain data objects involved in the target code requirements, and split the processing tasks of the data objects into at least one subtask; a generation module, used to generate target code corresponding to the target code requirements through the big model based on the at least one subtask.
[0007] According to a fourth aspect of the present disclosure, a target model training device is provided, comprising: a second acquisition module, used to acquire a training sample set, wherein the training sample set includes a first training sample and a second training sample; a training module, used to train an initial large model using the first training sample to obtain a first large model, wherein the first large model is used to perform a demand analysis on a target code requirement, obtain a data object involved in the target code requirement, and split a processing task for the data object into at least one subtask; the training module is also used to train the first large model using the second training sample to obtain a target large model, wherein the target large model is used to generate a target code corresponding to the target code requirement based on the at least one subtask.
[0008] According to a fifth aspect of the present disclosure, there is provided an electronic device, including:
[0009] at least one processor; and
[0010] a memory communicatively connected to the at least one processor; wherein,
[0011] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the large model-based code generation method as described in the first aspect, or execute the target model training method as described in the second aspect.
[0012] According to the sixth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the large model-based code generation method as described in the first aspect, or to execute the target model training method as described in the second aspect.
[0013] According to a seventh aspect of the present disclosure, a computer program product is provided, comprising computer instructions, which, when executed by a processor, implement the large model-based code generation method as described in the first aspect, or implement the target model training method as described in the second aspect.
[0014] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0016] Figure 1 It is a flowchart of a code generation method based on a large model provided according to an embodiment of the present disclosure;
[0017] Figure 2 is a flowchart of a code generation method based on a large model provided according to another embodiment of the present disclosure;
[0018] Figure 3 is a flowchart of a code generation method based on a large model provided according to another embodiment of the present disclosure;
[0019] Figure 4 is a flowchart of a target model training method provided according to an embodiment of the present disclosure;
[0020] Figure 5 is a structural diagram of a code generation device based on a large model provided according to an embodiment of the present disclosure;
[0021] Figure 6 is a schematic diagram of the structure of a target model training device provided according to an embodiment of the present disclosure;
[0022] Figure 7 It is a block diagram of an electronic device used to implement the large model-based code generation method or target model training method of the embodiment of the present disclosure. DETAILED DESCRIPTION
[0023] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0024] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, comply with the relevant laws and regulations, and do not violate public order and good morals.
[0025] With the rapid development of software development, the demand for automatic code generation is increasing. How to accurately and efficiently generate code to meet the code generation requirements in complex software development projects is of great significance to improving software development efficiency and quality.
[0026] In order to generate code accurately and efficiently and meet the code generation requirements in complex software development projects, the embodiments of the present disclosure propose a code generation method based on a large model, a target model training method, a device and an electronic device.
[0027] In order to facilitate understanding of the embodiments of the present disclosure, some technical terms in the embodiments of the present disclosure are first briefly explained.
[0028] The prompt word, i.e., the query, is encapsulated as an instruction for interacting with the big model. After the prompt word is input into the big model, the response output by the big model can be obtained. After further processing, the response can be presented to the user as the final result.
[0029] The prompt word template is a template used to generate prompt words. The content can be preset as needed. For example, it can be set to include indication information for the large model, as well as positions to be filled or information to be replaced. By using the specified information to fill in the positions to be filled or replace the information to be replaced, the corresponding prompt words can be obtained.
[0030] The following describes the large model-based code generation method, target model training method, device and electronic device of the embodiments of the present disclosure with reference to the accompanying drawings.
[0031] It should be noted that the execution subject of the code generation method based on the large model of this embodiment is a code generation device based on the large model. The following embodiments refer to the code generation device based on the large model as a code generation device. The code generation device can be implemented by software and / or hardware, and can be configured in an electronic device, which can include but is not limited to a terminal, a server, etc.
[0032] Figure 1 It is a flowchart of a code generation method based on a large model provided according to an embodiment of the present disclosure.
[0033] like Figure 1 As shown, the code generation method based on the large model includes:
[0034] Step 101, obtaining target code requirements.
[0035] The target code requirement includes a description of the code to be generated, which is used to indicate the functions to be implemented by the code to be generated. The target code requirement can be described in natural language.
[0036] In some embodiments, the target code requirement may be input by the user in the form of voice or text.
[0037] For example, when a user needs to develop a new shopping cart function for an e-commerce website, he can use natural language in text form to describe the requirements for the shopping cart function: "The shopping cart should be able to add and delete items and calculate the total price of items." The code generation device can obtain the target code requirements based on the user's input.
[0038] Alternatively, when a user needs to update a user authentication module for a software system to support a new security protocol, the user can use a natural language in text form to describe the update requirements for the user authentication module: "The user authentication module needs to support multi-factor authentication and ensure that all information is encrypted." The code generation device can obtain the target code requirements based on the user's input.
[0039] Step 102, performing a demand analysis on the target code requirement through the large model, obtaining the data objects involved in the target code requirement, and splitting the processing task of the data object into at least one subtask.
[0040] In some embodiments, the target code requirements can be analyzed through a large model to obtain data objects and processing tasks for the data objects involved in the target code requirements, and the processing tasks for the data objects can be split into at least one subtask.
[0041] Among them, the big model is a large neural network model trained using deep learning algorithms, designed to understand and generate natural language text. The big model is trained with a large amount of text data, and is able to capture the complexity and nuances of language, so as to perform various natural language processing tasks, such as text generation, code generation, question-answering systems, semantic understanding and reasoning, etc. This model is designed to improve the model's expressiveness and predictive performance, and can handle more complex tasks and data, showing human-like intelligence.
[0042] The large model in the disclosed embodiment may be the following large models, such as the large language model LLM, GPT3 (Generative Pre-trained Transformer), GPT4, T5 (Text-to-Text Transfer Transformer), LLaMA (Large Language Model Meta AI, lightweight large model), etc.
[0043] The data object may include a class or other data object involved in the target code requirement. The class may be an instance of the class, which may encapsulate related properties and methods. The number of data objects may be one or more, which is not limited by the present disclosure.
[0044] The processing tasks for data objects may include operations on data objects, which can be obtained by analyzing the requirements of the target code requirements. For example, taking the target code requirement as a requirement for the shopping cart function described in a natural language in text form, "the shopping cart should be able to add and delete items, and be able to calculate the total price of items", the data objects involved in the target code requirements may include the shopping cart class, and the processing tasks for the data objects may include adding and deleting items in the shopping cart and calculating the total price of all items in the shopping cart.
[0045] At least one subtask can be obtained by splitting the data object processing task. For example, when the data object processing task includes adding and deleting items in a shopping cart and calculating the total price of all items in the shopping cart, the data object processing task can be split into the following three subtasks: adding items to a shopping cart, removing items from a shopping cart, and calculating the total price of all items in the shopping cart.
[0046] In some embodiments, a prompt word corresponding to the target code requirement can be generated, wherein the prompt word is used to instruct the large model to perform a demand analysis on the target code requirement, obtain the data object involved in the target code requirement, and split the processing task of the data object into at least one subtask, and input the prompt word into the large model, so that the data object involved in the target code requirement and the at least one subtask into which the processing task of the data object is split can be obtained through the large model.
[0047] Among them, the target code requirement can be filled into the preset prompt word template to obtain the corresponding prompt word; or, the target code requirement can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the corresponding prompt word; or, other methods can be used to obtain the prompt word corresponding to the target code requirement, which is not limited in the present disclosure.
[0048] For example, the preset prompt word template may include the following:
[0049] You are a requirement analyzer who can analyze the following target code requirements, determine the data objects and processing tasks involved in the target code requirements, and split the processing tasks into subtasks. The number of subtasks should be as large as possible, and the generated data should be returned in a list format that can be processed by Python:
[0050] Target code requirements: ["query"]
[0051] Please perform a demand analysis on the target code requirements, generate the data objects involved in the target code requirements and the subtasks they are split into at one time, and return the generated data in a list format.
[0052] Among them, in the above-mentioned preset prompt word template, the information to be replaced corresponding to the target code requirement is: query. The code generation device replaces the query in the above-mentioned prompt word template with the obtained target code requirement to obtain the prompt word corresponding to the target code requirement.
[0053] Step 103: Based on at least one subtask, generate a target code corresponding to the target code requirement through the large model.
[0054] Among them, the target code corresponding to the target code requirement is the code that can realize the function described by the target code requirement.
[0055] In some embodiments, a prompt word corresponding to at least one subtask can be generated, and the prompt word is used to instruct the large model to generate code that can implement each subtask. The prompt word is then input into the large model, and the target code corresponding to the target code requirement can be obtained through the large model.
[0056] Among them, the task information of at least one subtask can be directly used as a prompt word; or, the task information of at least one subtask can be filled into a preset prompt word template to obtain a prompt word; or, the task information of at least one subtask can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain a prompt word; or, the prompt word can be obtained in other ways, which is not limited in the present disclosure.
[0057] In some embodiments, for any subtask, a prompt word corresponding to the subtask can be generated first, and the prompt word is used to instruct the large model to generate code that can implement the subtask. Then, each prompt word is input into the large model to obtain the code corresponding to each subtask output by the large model. Then, the code corresponding to each subtask is merged to obtain the target code corresponding to the target code requirement.
[0058] Among them, the task information of any subtask can be directly used as the prompt word corresponding to the subtask; or, the task information of any subtask can be filled into a preset prompt word template to obtain the prompt word corresponding to the subtask; or, the task information of any subtask can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the prompt word corresponding to the subtask; or, other methods can be used to obtain the prompt word corresponding to the subtask, and the present disclosure does not limit this.
[0059] The code generation method based on the big model provided in the embodiment of the present disclosure uses the big model to perform demand analysis on the target code requirements, obtains the data objects involved in the target code requirements, and splits the processing tasks of the data objects into at least one subtask. It can be realized that through the big model, the complex processing tasks of the data objects involved in the target code requirements can be split into subtasks with smaller granularity and easier to implement. Then, the code generation is performed based on the split subtasks through the big model, and the target code corresponding to the target code requirements can be generated more efficiently and accurately, meeting the code generation requirements in complex software development projects and improving software development efficiency and quality. In addition, by using the big model to generate the target code, the dependence of the code generation process on the code library can be reduced, saving storage space.
[0060] In order to clearly illustrate the process of generating target code corresponding to target code requirements through a large model, the embodiment of the present disclosure also provides a code generation method based on a large model.
[0061] Figure 2 It is a flowchart of a code generation method based on a large model provided according to another embodiment of the present disclosure.
[0062] like Figure 2 As shown, the code generation method based on the large model includes:
[0063] Step 201, obtaining target code requirements.
[0064] Step 202: Perform a demand analysis on the target code requirement through the large model to obtain the data object involved in the target code requirement, and split the processing task of the data object into at least one subtask.
[0065] The specific implementation process and principle of steps 201-202 may refer to the description of other embodiments and will not be repeated here.
[0066] Step 203: Obtain a target code sample that matches the target code requirement from a code sample library.
[0067] The code sample library includes a plurality of first candidate code requirements and corresponding candidate code samples. The candidate code samples are code samples pre-saved in the code sample library. The first candidate code requirement includes a description of the function implemented by the corresponding candidate code sample. The first candidate code requirement can be described in natural language.
[0068] In some embodiments, step 203 may be implemented by:
[0069] Determine the similarity between the target code requirement and each first candidate code requirement in the code sample library;
[0070] Based on the similarity, determining a second candidate code requirement from the first candidate code requirements in the code sample library;
[0071] The candidate code sample corresponding to the second candidate code requirement is determined as the target code sample.
[0072] As an example, for any first candidate code requirement, the similarity between the vector of the target code requirement and the vector of the first candidate code requirement may be used as the similarity between the target code requirement and the first candidate code requirement.
[0073] As an example, a first candidate code requirement in the code sample library whose similarity with the target code requirement is higher than a set threshold may be determined as the second candidate code requirement.
[0074] In some embodiments, the first candidate code requirements and the corresponding candidate code samples in the code sample library can be divided according to classes, that is, the code sample library includes first candidate code requirements and corresponding candidate code samples under multiple classes. In the case where the data object involved in the target code requirement includes the target class, step 203 can be implemented in the following manner:
[0075] Determine the similarity between the target code requirement and the first candidate code requirement under the target class in the code sample library;
[0076] Based on the similarity, determining a third candidate code requirement from the first candidate code requirements under the target class;
[0077] The candidate code sample corresponding to the third candidate code requirement is determined as the target code sample.
[0078] As an example, for any first candidate code requirement under the target class, the similarity between the vector of the target code requirement and the vector of the first candidate code requirement may be used as the similarity between the target code requirement and the first candidate code requirement.
[0079] As an example, a first candidate code requirement under the target class whose similarity with the target code requirement is higher than a set threshold may be determined as the third candidate code requirement.
[0080] For example, assuming that the data objects involved in the target code requirement include commodity categories, the similarity between the target code requirement and the first candidate code requirement under the commodity category in the code sample library can be determined first, and then the first candidate code requirement under the commodity category whose similarity with the target code requirement is higher than a set threshold is determined as the third candidate code requirement, and then the candidate code sample corresponding to the third candidate code requirement is determined as the target code sample.
[0081] Therefore, based on the target class included in the data object, a target code sample that better matches the target code requirement can be quickly obtained from the code sample library.
[0082] Step 204 , taking the target code sample as an example, based on at least one subtask, generating target code corresponding to the target code requirement through the large model.
[0083] In some embodiments, a prompt word can be generated based on the target code sample and at least one subtask. In order to facilitate the distinction from other prompt words, the prompt word is called the fifth prompt word in this embodiment. Among them, the fifth prompt word is used to instruct the large model to use the target code sample as an example to generate the target code corresponding to the target code requirement based on at least one subtask. Then, the fifth prompt word is input into the large model, and the target code corresponding to the target code requirement can be obtained through the large model. Thus, it is possible to guide the large model to understand the task requirements more accurately through the fifth prompt word, so as to use the target code sample as an example and accurately generate the target code corresponding to the target code requirement based on at least one subtask.
[0084] Among them, the target code sample and at least one subtask can be filled into the preset prompt word template to obtain the fifth prompt word; or, the target code sample and at least one subtask can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the fifth prompt word; or, the fifth prompt word can be obtained in other ways, which is not limited in the present disclosure.
[0085] In some embodiments, step 204 may be implemented by:
[0086] Taking the target code sample as an example, based on at least one subtask, the code of the main function and the code of the sub-function corresponding to at least one subtask are generated through the large model; wherein the sub-function is used to implement the corresponding subtask, and the main function is used to coordinate the call of the sub-function to implement the processing task of the data object involved in the target code requirement;
[0087] Based on the main function code and the sub-function code, generate the target code corresponding to the target code requirement.
[0088] Among them, any subtask corresponds to a subfunction, and the subfunction is used to implement the corresponding subtask, which is a subtask obtained by splitting the processing task of the data object involved in the target code requirement.
[0089] Among them, the main function is used to coordinate the sub-functions corresponding to each sub-task to realize the processing task of the data objects involved in the target code requirements.
[0090] In some embodiments, a prompt word can be generated based on the target code sample and at least one subtask. In order to facilitate the distinction from other prompt words, the prompt word is called the sixth prompt word in this embodiment. Among them, the sixth prompt word is used to instruct the large model to use the target code sample as an example, and to generate the code of the main function and the code of the sub-function corresponding to at least one subtask respectively based on at least one subtask. Among them, the subtask is a subtask obtained by splitting the processing task of the data object involved in the target code requirement. Then, the sixth prompt word is input into the large model, and the code of each sub-function for implementing each subtask and the code of the main function for coordinating the call of each subfunction can be obtained through the large model. Thus, it can be achieved through the sixth prompt word to guide the large model to understand the task requirements more accurately, so as to use the target code sample as an example, based on at least one subtask, accurately generate the code of each sub-function for implementing each subtask and the code of the main function for coordinating the call of each subfunction.
[0091] Among them, the target code sample and at least one subtask can be filled into the preset prompt word template to obtain the sixth prompt word; or, the target code sample and at least one subtask can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the sixth prompt word; or, the sixth prompt word can be obtained in other ways, which is not limited in the present disclosure.
[0092] By taking the target code sample as an example, based on at least one subtask, the code of the main function and the code of the sub-function corresponding to the at least one subtask are generated through the big model, and then based on the code of the main function and the code of the sub-function, the target code corresponding to the target code requirement is generated. It is possible to use the big model, refer to the target code sample, and based on at least one subtask with smaller granularity and easier to implement, generate the code of the sub-function for implementing a single subtask, and the code of the main function for coordinating the call of the sub-function, and then based on the code of the main function and the code of the sub-function, more accurately generate the target code corresponding to the target code requirement.
[0093] In some embodiments, the target code sample includes a main function sample and a sub-function sample, wherein the main function sample is a sample of the main function in the target code sample, and the sub-function sample is a sample of the sub-function in the target code sample.
[0094] Accordingly, taking the target code sample as an example, based on at least one subtask, generating the code of the main function and the code of the sub-function corresponding to at least one subtask through the large model may include:
[0095] Based on the main function example and at least one subtask, a first prompt word is generated, wherein the first prompt word is used to indicate an example to be referred to for generating the code of the main function and a task to be implemented by the subfunction called by the main function;
[0096] Input the first prompt word into the large model to obtain the code of the main function;
[0097] Based on the sub-function sample and the main function, a second prompt word is generated, wherein the second prompt word is used to indicate an example required to be referenced by the code for generating the sub-function and a main function for calling the sub-function;
[0098] Input the second prompt word into the large model to get the code of the sub-function.
[0099] Among them, the main function sample and at least one subtask can be filled into a preset prompt word template to obtain a first prompt word; or, the main function sample and at least one subtask can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the first prompt word; or, other methods can be used to obtain the first prompt word, which is not limited in the present disclosure.
[0100] The sub-function sample and the main function can be filled into the preset prompt word template to obtain the second prompt word; or, the sub-function sample and the main function can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the second prompt word; or, the second prompt word can be obtained in other ways, which is not limited in the present disclosure.
[0101] Thus, it is possible to guide the large model to understand the task requirements more accurately through the first prompt word, so as to accurately generate the code of the main function for coordinating the calls of each sub-function based on the main function sample and at least one sub-task, and it is possible to guide the large model to understand the task requirements more accurately through the second prompt word, so as to accurately generate the codes of each sub-function coordinated by the main function based on the sub-function sample and the main function. In addition, it is understandable that when the code is generated through the large model, the length of the output characters of the large model may be limited. Then, when the processing task of the data object involved in the target code requirement is relatively complex, the large model may not be able to generate the complete target code corresponding to the target code requirement at one time. In the embodiment of the present disclosure, by inputting the first prompt word and the second prompt word into the large model respectively, the code of the main function and the code of the sub-function are obtained, and then the target code is generated based on the code of the main function and the code of the sub-function, the complete target code corresponding to the target code requirement can be generated.
[0102] In some embodiments, the main function and the sub-function may reference a library, and the class composed of the main function and the sub-function may have some declaration information. Then, in order to generate a complete target code corresponding to the target code requirement, the target code may be generated based on the code of the main function and the code of the sub-function in the following manner:
[0103] Taking the target code sample as an example, the code of the header file and the code of the include file are generated through the large model; wherein the header file includes the declaration of the class composed of the main function and the sub-functions, and the include file includes the library referenced by the main function and the sub-functions;
[0104] Concatenate the main function code, sub-function code, header file code, and included file code to obtain the target code corresponding to the target code requirement.
[0105] Among them, the included file is the include file.
[0106] The library referenced by the main function and the sub-function is a set of predefined code collections that can provide a series of functions, classes, and methods for solving specific problems or implementing specific functions.
[0107] In some embodiments, the splicing rules for the main function code, sub-function code, header file code, and include file code can be set in advance, so that the main function code, sub-function code, header file code, and include file code can be spliced according to the splicing rules to obtain the target code corresponding to the target code requirements.
[0108] In some embodiments, prompt words can be generated based on the target code sample, the main function and the sub-function. In order to facilitate the distinction from other prompt words, the prompt word is called the seventh prompt word in this embodiment. Among them, the seventh prompt word is used to instruct the large model to use the target code sample as an example to generate the code of the header file and the code of the include file, wherein the header file includes the declaration of the class composed of the main function and the sub-function, and the include file includes the library referenced by the main function and the sub-function. Then the seventh prompt word is input into the large model, and the code of the header file and the code of the include file can be obtained through the large model. Thus, it can be achieved through the seventh prompt word to guide the large model to understand the task requirements more accurately, so as to use the target code sample as an example to accurately generate the code of the header file and the code of the include file.
[0109] Among them, the target code sample, main function and sub-function can be filled into the preset prompt word template to obtain the seventh prompt word; or, the target code sample, main function and sub-function can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the seventh prompt word; or, the seventh prompt word can be obtained in other ways, which is not limited in the present disclosure.
[0110] In some embodiments, the target code sample includes a header file sample and an included file sample, wherein the header file sample is a sample of a header file in the target code sample, and the included file sample is a sample of an included file in the target code sample.
[0111] Accordingly, taking the target code sample as an example, the code of the header file and the code of the include file are generated through the large model, including:
[0112] Based on the header file sample, the main function and the sub-function, a third prompt word is generated, wherein the third prompt word is used to indicate the example required for reference of the code for generating the header file and the main function and the sub-function constituting the class declared in the header file;
[0113] Input the third prompt word into the large model to obtain the code of the header file;
[0114] Generate a fourth prompt word based on the included file sample, the main function and the sub-function, wherein the fourth prompt word is used to indicate an example of reference required for generating the code of the included file and to reference the main function and the sub-function of the library in the included file;
[0115] Input the fourth prompt word into the large model to get the code of the included file.
[0116] Among them, the header file sample, main function and sub-function can be filled into the preset prompt word template to obtain the third prompt word; or, the header file sample, main function and sub-function can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the third prompt word; or, the third prompt word can be obtained in other ways, which is not limited in the present disclosure.
[0117] The included file sample, main function and sub-function may be filled into a preset prompt word template to obtain a fourth prompt word; or, the included file sample, main function and sub-function may be used to replace the corresponding information to be replaced in the preset prompt word template to obtain a fourth prompt word; or, the fourth prompt word may be obtained in other ways, which is not limited in the present disclosure.
[0118] Therefore, the third prompt word can be used to guide the large model to more accurately understand the task requirements, thereby accurately generating the code of the header file based on the header file sample, the main function and the sub-function, and the header file includes the declaration of the class of the main function and the sub-function. And the fourth prompt word can be used to guide the large model to more accurately understand the task requirements, thereby accurately generating the code of the include file based on the include file sample, the main function and the sub-function, and the include file includes the library referenced by the main function and the sub-function.
[0119] The code generation method based on a big model provided by the embodiment of the present disclosure performs a demand analysis on the target code requirements by using the big model to obtain the data objects involved in the target code requirements, and splits the processing tasks of the data objects into at least one subtask. It can be achieved by splitting the complex processing tasks of the data objects involved in the target code requirements into subtasks with smaller granularity and easier to implement through the big model. By obtaining target code samples matching the target code requirements from a code sample library, taking the target code samples as examples, and generating target code corresponding to the target code requirements through the big model based on at least one subtask, it can be achieved by referring to the target code samples through the big model, based on subtasks with smaller granularity and easier to implement, and generating the target code corresponding to the target code requirements more efficiently and accurately, thereby meeting the code generation requirements in complex software development projects and improving software development efficiency and quality.
[0120] Through the above analysis, it can be known that the embodiment of the present disclosure can generate target code corresponding to the target code requirement. In a possible implementation form, the target code can also be detected and repaired through a large model to obtain executable code, so as to improve the quality of the code generated by the code generation device and make the generated code directly executable. Figure 3 , the process of detecting the target code through the big model and repairing the problems to obtain the executable code in the code generation method based on the big model provided in the embodiment of the present disclosure is explained.
[0121] Figure 3 It is a flowchart of a code generation method based on a large model provided according to another embodiment of the present disclosure.
[0122] It should be noted that the execution subject of the code generation method based on the large model is a code generation device based on the large model, referred to as a code generation device. The code generation device can be implemented by software and / or hardware, and can be configured in an electronic device, which can include but is not limited to a terminal, a server, etc.
[0123] For example, the code generation device may be a software development tool configured in an electronic device. The software development tool adopts an end-to-end learning framework and can directly generate executable code corresponding to the target code requirements based on the target code requirements. This architecture enables the software development tool to more intuitively understand and handle the code generation requirements in complex software development projects.
[0124] like Figure 3 As shown, the code generation method based on the large model includes:
[0125] Step 301, obtaining target code requirements.
[0126] Step 302: Perform a demand analysis on the target code requirement through the large model to obtain the data object involved in the target code requirement, and split the processing task of the data object into at least one subtask.
[0127] Step 303: Based on at least one subtask, generate target code corresponding to the target code requirement through the large model.
[0128] The specific implementation process and principle of steps 301-303 may refer to the description of other embodiments and will not be repeated here.
[0129] Step 304, compile the target code to obtain a compilation result.
[0130] In some embodiments, the target code may be compiled in a compilation environment to obtain a compilation result.
[0131] Step 305: When the compilation result indicates that the target code has a compilation problem, the target code is repaired based on the compilation problem by using the large model to obtain a repaired code.
[0132] Among them, compilation problems are problems that occur during the compilation process of the target code.
[0133] In some embodiments, an eighth prompt word can be generated based on the compilation problem and the target code, wherein the eighth prompt word is used to instruct the large model to repair the target code based on the compilation problem. The repaired code can be obtained by inputting the eighth prompt word into the large model.
[0134] The compilation problem and the target code may be filled into a preset prompt word template to obtain an eighth prompt word; or, the compilation problem and the target code may be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the eighth prompt word; or, the eighth prompt word may be obtained in other ways, which is not limited in the present disclosure.
[0135] Step 306, testing the repaired code in a test environment to obtain a test result.
[0136] In some embodiments, in order to realize automated testing of the repaired code, step 306 may be implemented in the following manner:
[0137] Get the test cases that match the target code requirements from the test case library;
[0138] Take the test cases as examples and generate target test cases corresponding to the target code requirements through the big model;
[0139] Generate test code corresponding to the target test case through the large model;
[0140] In the test environment, the repaired code is tested using the test code to obtain the test results.
[0141] Test cases are used to verify whether a specific function or module of the code works as expected. Test cases can include input data, expected results, actual results, test steps, and environment settings.
[0142] The test code is the code generated according to the specified test case to verify the code function.
[0143] The test case library includes a plurality of fourth candidate code requirements and corresponding candidate test cases. The candidate test cases are test cases pre-saved in the test case library. The fourth candidate code requirement includes a description of the function implemented by the code, wherein the code is the code verified by the candidate test case corresponding to the fourth candidate code requirement. The fourth candidate code requirement and the candidate test case can be described in natural language.
[0144] In some embodiments, obtaining a test case matching the target code requirement from a test case library includes:
[0145] Determine the similarity between the target code requirement and each fourth candidate code requirement in the test case library;
[0146] Based on the similarity, determine a fifth candidate code requirement from the fourth candidate code requirements in the test case library;
[0147] The candidate test sample corresponding to the fifth candidate code requirement is determined as a test case that matches the target code requirement.
[0148] In some embodiments, the fourth candidate code requirement and the corresponding candidate test case in the test case library can be divided according to the class, that is, the test case library includes the fourth candidate code requirement and the corresponding candidate test case under multiple classes. In the case where the data object involved in the target code requirement includes the target class, obtaining the test case matching the target code requirement from the test case library includes:
[0149] Determine the similarity between the target code requirement and a fourth candidate code requirement under the target class in the test case library;
[0150] Based on the similarity, determining a sixth candidate code requirement from the fourth candidate code requirements under the target class;
[0151] The candidate test sample corresponding to the sixth candidate code requirement is determined as a test case that matches the target code requirement.
[0152] Therefore, based on the target class included in the data object, the test case that better matches the target code requirement can be quickly obtained from the test case library.
[0153] In some embodiments, a prompt word may be generated based on the test case and the target code requirement. In order to facilitate the distinction from other prompt words, the prompt word is referred to as the ninth prompt word in this embodiment. The ninth prompt word is used to instruct the large model to use the specified test case as an example to generate a target test case corresponding to the target code requirement. Then, the ninth prompt word is input into the large model, and the target test case corresponding to the target code requirement can be obtained through the large model.
[0154] Among them, the test case and the target code requirement can be filled into the preset prompt word template to obtain the ninth prompt word; or, the test case and the target code requirement can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the ninth prompt word; or, the ninth prompt word can be obtained in other ways, which is not limited in the present disclosure.
[0155] In some embodiments, a prompt word may be generated based on the target test case. In order to facilitate the distinction from other prompt words, the prompt word is referred to as the tenth prompt word in this embodiment. The tenth prompt word is used to instruct the large model to generate the test code corresponding to the specified target test case. Then, the tenth prompt word is input into the large model, and the test code corresponding to the target test case can be obtained through the large model.
[0156] Among them, the target test case can be filled into the preset prompt word template to obtain the tenth prompt word; or, the target test case can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the tenth prompt word; or, other methods can be used to obtain the tenth prompt word, which is not limited in the present disclosure.
[0157] Step 307: When the test result indicates that the repaired code has a test problem, the repaired code is repaired based on the test problem by using the large model to obtain executable code.
[0158] Among them, test problems are problems that occur during the testing process of the repaired code.
[0159] In some embodiments, an eleventh prompt word can be generated based on the test problem and the repaired code, wherein the eleventh prompt word is used to instruct the large model to repair the repaired code based on the test problem. The eleventh prompt word is input into the large model to obtain executable code.
[0160] Among them, the test problem and the repaired code can be filled into the preset prompt word template to obtain the eleventh prompt word; or, the test problem and the repaired code can be used to replace the corresponding information to be replaced in the preset prompt word template to obtain the eleventh prompt word; or, the eleventh prompt word can be obtained by other methods, which is not limited in the present disclosure.
[0161] The code generation method based on the big model provided by the embodiment of the present disclosure can integrate the various stages of demand analysis, code generation, code compilation, code testing, and problem repair to generate executable code corresponding to the target code demand, and obtain a compilation result by compiling the target code. When the compilation result indicates that the target code has a compilation problem, the target code is repaired based on the compilation problem through the big model to obtain a repaired code. When the target code has a compilation problem, the big model can be used to automatically and accurately repair the target code. When the repaired code is tested in a test environment to obtain a test result, when the test result indicates that the repaired code has a test problem, the big model can be used to repair the repaired code based on the test problem. When the repaired code has a test problem, the big model can be used to automatically and further repair the repaired code to obtain high-quality executable code.
[0162] With respect to the large model adopted in the above-mentioned embodiments, the present disclosure also provides a target model training method.
[0163] It should be noted that the executor of the target model training method of this embodiment is the target model training device. The target model training device can be implemented by software and / or hardware and can be configured in an electronic device. The electronic device may include but is not limited to a terminal, a server, etc.
[0164] Figure 4 It is a flowchart of a target model training method provided according to an embodiment of the present disclosure.
[0165] like Figure 4 As shown, the target model training method includes:
[0166] Step 401: Acquire a training sample set, wherein the training sample set includes a first training sample and a second training sample.
[0167] Step 402, use the first training sample to train the initial large model to obtain the first large model, wherein the first large model is used to perform demand analysis on the target code requirements, obtain the data objects involved in the target code requirements, and split the processing task of the data object into at least one subtask.
[0168] In some embodiments, the first training sample includes:
[0169] A first sample prompt word is used to instruct the initial large model to perform a demand analysis on the first sample code demand, obtain a sample data object involved in the first sample code demand, and split a processing task on the sample data object into at least one first sample subtask;
[0170] The first sample code requires an expected data object, and subtasks expected to be obtained by splitting a processing task of the expected data object.
[0171] The sample code requirement includes a description of the code to be generated, which is used to indicate the function to be implemented by the code to be generated. The sample code requirement can be described in natural language. In order to distinguish it from other sample code requirements, the sample code requirement corresponding to the first training sample is referred to as the first sample code requirement.
[0172] The sample data object is a processing object involved in the first sample code requirement, and may include a class or other data objects involved in the first sample code requirement, wherein the class may be an instance of a class, in which related properties and methods may be encapsulated.
[0173] The processing task for the sample data object may include operations performed on the sample data object.
[0174] The first sample subtask is a subtask obtained by splitting the processing task of the sample data object.
[0175] The expected data object is the data object expected to be generated by the initial large model.
[0176] The expected subtask is the subtask for generating the expected initial large model.
[0177] Therefore, by using the first training sample to train the initial large model to obtain the first large model, the first large model can be used to perform demand analysis on the target code requirements, obtain the data objects involved in the target code requirements, and split the processing tasks of the data objects into at least one subtask.
[0178] Step 403: Use the second training sample to train the first large model to obtain a target large model, wherein the target large model is used to generate a target code corresponding to a target code requirement based on at least one subtask.
[0179] The at least one subtask in step 403 is at least one subtask split from the task of processing a data object, and the data object is a data object involved in the target code requirement.
[0180] In some embodiments, the second training sample may include:
[0181] The second sample prompt word is used to instruct the first large model to generate a target code corresponding to the second sample code requirement based on at least one second sample subtask;
[0182] The second sample code requirement corresponds to the desired target code.
[0183] The second sample code requirement may be the same as or different from the first sample code requirement, and the present disclosure does not limit this.
[0184] The second sample subtask is a subtask obtained by splitting the processing task of the data object involved in the second sample code requirement.
[0185] The target code corresponding to the second sample code requirement is a code that can implement the function described by the second sample code requirement.
[0186] The expected target code corresponding to the second sample code requirement is the target code corresponding to the second sample code requirement expected to be generated by the first large model.
[0187] Therefore, since the first large model can be used to perform demand analysis on the target code requirements, obtain the data objects involved in the target code requirements, and split the processing tasks of the data objects into at least one sub-task, the target large model obtained by continuing to train the first large model with the second training sample can not only be used to process the above tasks, but also can be used to generate executable code corresponding to the target code requirements based on the at least one sub-task.
[0188] Correspondingly, the target large model obtained by training the first large model can be applied to the embodiment of the above-mentioned large model-based code generation method to perform demand analysis on the target code requirements and generate the target code based on the results of the demand analysis.
[0189] In some embodiments, a third training sample may be used to train a target large model to obtain a second large model, wherein the second large model is used to detect and repair problems in the target code corresponding to the target code requirement to obtain executable code corresponding to the target code requirement.
[0190] Among them, the third training sample includes:
[0191] The third sample prompt word is used to instruct the target large model to detect and fix problems in the sample code to obtain the corresponding executable code;
[0192] The expected executable code corresponding to the sample code.
[0193] The sample code may be a code that can realize any function.
[0194] The expected executable code is the executable code corresponding to the sample code generated for the expected target large model.
[0195] Therefore, since the target large model can be used to perform demand analysis on the target code requirements, obtain the data objects involved in the target code requirements, and split the processing tasks of the data objects into at least one sub-task, and can also be used to generate executable code corresponding to the target code requirements based on the at least one sub-task, the second large model obtained by continuing to train the target large model with the third training sample can not only be used to process the above tasks, but also can be used to detect and fix problems in the generated target code to obtain executable code corresponding to the target code requirements.
[0196] In some embodiments, the fourth training sample may be used to train the second largest model to obtain the third largest model, wherein the fourth training sample includes:
[0197] The fourth sample prompt word is used to instruct the second large model to use the first sample code sample as an example and generate a target code corresponding to the third sample code requirement based on at least one third sample subtask;
[0198] The third sample code requirement corresponds to the expected target code.
[0199] The third sample code requirement may be the same as or different from the other sample code requirements, and the present disclosure does not limit this.
[0200] The third sample subtask is a subtask obtained by splitting the task of processing the data object involved in the third sample code requirement.
[0201] The target code corresponding to the third sample code requirement is a code that can implement the function described by the third sample code requirement.
[0202] The first sample code example is a code example that matches the third sample code requirement.
[0203] The expected target code corresponding to the third sample code requirement is the target code corresponding to the third sample code requirement expected to be generated by the second largest model.
[0204] Therefore, by using the fourth training sample to train the second largest model to obtain the third largest model, the third largest model can be used to process the tasks that the second largest model can process, and can also be used to use the target code sample as an example to generate target code corresponding to the target code requirement based on at least one subtask, and detect and repair problems in the target code to obtain the corresponding executable code, wherein the at least one subtask is obtained by splitting the processing tasks of the data objects involved in the target code requirement.
[0205] In some embodiments, the fifth training sample may be used to train the third largest model to obtain a fourth largest model, wherein the fifth training sample includes:
[0206] The fifth sample prompt word is used to instruct the third model to use the second sample code sample as an example, and based on at least one fourth sample subtask, generate the code of the first main function and the code of the first sub-function corresponding to at least one fourth sample sub-task respectively; wherein the first sub-function is used to implement the corresponding fourth sample subtask, and the first main function is used to coordinate the call of the first sub-function to implement the processing task of the data object involved in the fourth sample code requirement;
[0207] The code of the expected first sub-function, the code of the expected first main function.
[0208] The fourth sample code requirement may be the same as or different from the other sample code requirements, and the present disclosure does not limit this.
[0209] The fourth sample subtask is a subtask obtained by splitting the task of processing the data object involved in the fourth sample code requirement.
[0210] The second sample code example is a code example that matches the fourth sample code requirement.
[0211] The code of the expected first sub-function is the code of the first sub-function generated by the expected third largest model.
[0212] The code of the expected first main function is the code of the first main function generated by the expected third largest model.
[0213] Therefore, by using the fifth training sample to train the third model to obtain the fourth model, the fourth model can be used to process the tasks that the third model can process, and can also be used to use the target code sample as an example to generate, based on at least one subtask, the code of the sub-function for implementing each subtask and the code of the main function for coordinating the calls of each subfunction, wherein the at least one subtask is obtained by splitting the processing tasks of the data objects involved in the target code requirements.
[0214] In some embodiments, the sixth training sample may be used to train the fourth largest model to obtain the fifth largest model, wherein the sixth training sample includes:
[0215] A sixth sample prompt word is used to indicate an example of reference required for the fourth model to generate the code of the second main function and a task to be achieved by the second sub-function called by the second main function;
[0216] The code of the second main function is expected to be generated.
[0217] The number of the second sub-functions is one or more, and any second sub-function corresponds to any sub-task into which the processing task of any data object is split, and the second sub-function is used to implement the corresponding sub-task. The second main function is used to coordinate the calling of each second sub-function to implement the processing task.
[0218] The code of the second main function expected to be generated is the code of the second main function expected to be generated by the fourth largest model.
[0219] Therefore, by using the sixth training sample to train the fourth model to obtain the fifth model, the fifth model can be used to process the tasks that the fourth model can process, and can also be used to generate the code of the main function based on the first prompt word, where the first prompt word indicates the example required to refer to and the task to be implemented by the sub-function called by the main function to generate the code of the main function.
[0220] In some embodiments, the seventh training sample may be used to train the fifth largest model to obtain the sixth largest model, wherein the seventh training sample includes:
[0221] A seventh sample prompt word, used to indicate an example of reference required by the fifth large model to generate the code of the third sub-function and a third main function that calls the third sub-function;
[0222] The code of the third sub-function is expected to be generated.
[0223] The number of the third sub-functions is one or more, and any third sub-function corresponds to any sub-task into which the processing task of any data object is split, and the third sub-function is used to implement the corresponding sub-task. The third main function is used to coordinate the calling of each third sub-function to implement the processing task.
[0224] The code of the third sub-function expected to be generated is the code of the third sub-function expected to be generated by the fifth largest model.
[0225] Therefore, by using the seventh training sample to train the fifth model to obtain the sixth model, the sixth model can be used to process the tasks that the fifth model can process, and can also be used to generate the code of the sub-function based on the second prompt word, where the second prompt word indicates the example required to refer to the code of the sub-function and the main function that calls the sub-function.
[0226] In some embodiments, the eighth training sample may be used to train the sixth largest model to obtain the seventh largest model, wherein the eighth training sample includes:
[0227] The eighth sample prompt word is used to instruct the sixth model to use the third sample code sample as an example to generate the code of the first sample header file and the code of the first sample include file; wherein the first sample header file includes the declaration of the class composed of the fourth main function and the fourth sub-function, and the first sample include file includes the library referenced by the fourth main function and the fourth sub-function;
[0228] The code of the first sample header file expected to be generated and the code of the first sample include file expected to be generated.
[0229] The third sample code example is a code example that matches the fifth sample code requirement. The fifth sample code requirement may be the same as or different from the other sample code requirements, and the present disclosure does not limit this.
[0230] The fourth sub-function is used to implement the corresponding fifth sample sub-task, and the fourth main function is used to coordinate the call of the fourth sub-function to implement the processing task of the data object involved in the fifth sample code requirement. Among them, the fifth sample sub-task is a sub-task obtained by splitting the processing task of the data object involved in the fifth sample code requirement.
[0231] The code of the expected first sample header file is the code of the first sample header file generated by the expected sixth model.
[0232] The first sample included file code is expected to be generated, and the first sample included file code is expected to be generated for the sixth largest model.
[0233] Therefore, by using the eighth training sample to train the sixth model, the seventh model is obtained. The seventh model can be used to process the tasks that the sixth model can process, and can also use the target code sample as an example to generate the code of the header file and the code of the include file, wherein the header file includes the declaration of the class consisting of the main function and the sub-function, and the include file includes the library referenced by the main function and the sub-function, wherein the sub-function corresponds to a sub-task, and the main function is used to coordinate the call of the sub-function corresponding to at least one sub-task, so as to realize the processing task of the data object involved in the target code requirement, and the at least one sub-task is obtained by splitting the processing task of the data object involved in the target code requirement.
[0234] In some embodiments, the ninth training sample may be used to train the seventh model to obtain the eighth model, wherein the ninth training sample includes:
[0235] The ninth sample prompt word is used to indicate the example of reference required by the seventh model to generate the code of the second sample header file and the fifth main function and the fifth sub-function constituting the class declared in the second sample header file;
[0236] Expected to generate the code of the second sample header file.
[0237] The number of the fifth sub-functions is one or more, and any fifth sub-function corresponds to any sub-task into which the processing task of any data object is split, and the fifth sub-function is used to implement the corresponding sub-task. The fifth main function is used to coordinate the calling of each fifth sub-function to implement the processing task.
[0238] The second sample header file includes a declaration of a class consisting of a fifth main function and a fifth sub-function.
[0239] The code of the second sample header file expected to be generated is the code of the second sample header file expected to be generated by the seventh model.
[0240] Therefore, by using the ninth training sample to train the seventh model to obtain the eighth model, the eighth model can be used to process the tasks that the seventh model can process, and can also be used to generate the code for the header file based on the third prompt word, wherein the third prompt word indicates the examples required to refer to the code for generating the header file and the main functions and sub-functions that constitute the class declared in the header file.
[0241] In some embodiments, the eighth model may be trained with the tenth training sample to obtain a ninth model, wherein the tenth training sample includes:
[0242] A tenth sample prompt word, used to indicate an example of references required for the eighth model to generate the code of the second sample include file and to reference a sixth main function and a sixth sub-function of the library in the second sample include file;
[0243] The second sample contains the code of the file that is expected to be generated.
[0244] The number of the sixth sub-functions is one or more, and any sixth sub-function corresponds to any sub-task split into which the processing task of any data object is processed, and the sixth sub-function is used to implement the corresponding sub-task. The sixth main function is used to coordinate the calling of each sixth sub-function to implement the processing task.
[0245] The second sample include file includes the library referenced by the sixth main function and the sixth sub-function.
[0246] The second sample included file code is expected to be generated, and the second sample included file code is expected to be generated for the eighth largest model.
[0247] Therefore, by using the tenth training sample to train the eighth model to obtain the ninth model, the ninth model can be used to process the tasks that the eighth model can process, and can also be used to generate code for the include file based on the fourth prompt word, wherein the fourth prompt word is used to indicate the examples required to refer to the code for the include file and the main functions and sub-functions of the library in the include file that are referenced.
[0248] In some embodiments, the eleventh training sample may be used to train the ninth model to obtain the tenth model, wherein the eleventh training sample includes:
[0249] The eleventh sample prompt word is used to instruct the ninth model to repair the first problem code based on the sample compilation problem to obtain the corresponding repaired code;
[0250] The expected repair code corresponding to the first problem code.
[0251] The sample compilation problem is a problem that occurs during the compilation of the first problem code.
[0252] The expected repaired code corresponding to the first problem code is the repaired code of the first problem code expected to be obtained by the ninth model.
[0253] Therefore, by using the eleventh training sample to train the ninth model and obtain the tenth model, the tenth model can be used to process the tasks that the ninth model can process, and can also be used to repair the target code based on compilation problems corresponding to the target code requirements.
[0254] In some embodiments, the twelfth training sample may be used to train the tenth model to obtain the eleventh model, wherein the twelfth training sample includes:
[0255] The twelfth sample prompt word is used to instruct the tenth model to repair the second problem code based on the sample test problem and obtain the corresponding repaired code;
[0256] The expected repair code corresponding to the second problem code.
[0257] Among them, the sample test problem is the problem that occurs during the testing process of the second problem code.
[0258] The expected repaired code corresponding to the second problem code is the repaired code of the second problem code obtained by the expected tenth largest model.
[0259] Therefore, by using the twelfth training sample to train the tenth model, the eleventh model is obtained. The eleventh model can be used to process the tasks that the tenth model can process, and can also be used to test problems existing in the repaired code corresponding to the target code requirements, and further repair the repaired code to obtain the corresponding executable code.
[0260] In some embodiments, the thirteenth training sample may be used to train the eleventh large model to obtain the twelfth large model, wherein the thirteenth training sample includes:
[0261] The thirteenth sample prompt word is used to instruct the eleventh model to use the first test case as an example to generate a test case corresponding to the sixth sample code requirement;
[0262] The sixth sample code requirement corresponds to the expected test case.
[0263] The sixth sample code requirement may be the same as or different from other sample code requirements, and the present disclosure does not limit this. The first test case is a test case that matches the sixth sample code requirement.
[0264] The expected test cases corresponding to the sixth sample code requirement are test cases corresponding to the sixth sample code requirement expected to be generated by the eleventh large model.
[0265] Therefore, by using the thirteenth training sample to train the eleventh model, the twelfth model is obtained. The twelfth model can be used to process the tasks that the eleventh model can process, and can also be used to take the test cases matching the target code requirements as examples to generate target test cases corresponding to the target code requirements.
[0266] In some embodiments, the twelfth model may be trained using the fourteenth training sample to obtain the thirteenth model, wherein the fourteenth training sample includes:
[0267] The fourteenth sample prompt word is used to instruct the twelfth model to generate the test code corresponding to the second test case;
[0268] The second test case corresponds to the expected test code.
[0269] The second test case may be any test case, and may be the same as or different from the first test case, and the present disclosure does not impose any limitation on this.
[0270] The test code corresponding to the second test case is the code generated according to the specified second test case and used to verify the code function.
[0271] The expected test code corresponding to the second test case is the test code corresponding to the second test case expected to be generated by the twelfth model.
[0272] Therefore, by using the fourteenth training sample to train the twelfth model, the thirteenth model is obtained, so that the thirteenth model can be used to process the tasks that the twelfth model can process, and can also be used to generate test codes corresponding to the target test cases.
[0273] Among them, the thirteenth model can be applied to the large model-based code generation method in the above embodiment.
[0274] In some embodiments, the number of any one of the above training samples may be multiple.
[0275] It should be noted that the above-mentioned method of training the initial large model and finally obtaining the thirteenth largest model adopts a method of iterative training of the initial large model based on multiple training samples, that is, each iteration uses a training sample to optimize the large model to be trained, so that the optimized large model can perform the task corresponding to the training sample of this type, and another training sample is used in the next iteration to continue to improve the model performance. After multiple iterations, the model is gradually optimized so that the final large model can perform multiple tasks.
[0276] In some embodiments, other methods can also be used to train the initial large model based on the above-mentioned various training samples. For example, the above-mentioned various training samples can be mixed and the initial large model can be trained together. By fine-tuning the model parameters, an optimized fourteenth largest model can be obtained, wherein the fourteenth largest model can be used to process a variety of tasks that the fourteenth largest model can handle. After the training is completed, the performance of the fourteenth largest model can be evaluated. If it does not meet expectations, the fourteenth largest model can continue to be trained, and after multiple rounds of training, the model capabilities can be continuously improved. The large model finally obtained can be applied to the code generation method based on the large model in the above-mentioned embodiment.
[0277] It should be noted that similar steps or implementation processes in the embodiment of the present disclosure to those in other embodiments will not be repeated here.
[0278] The target model training method provided by the embodiment of the present disclosure uses the first training sample in the training sample set to train the initial large model to obtain the first large model, and uses the second training sample in the training sample set to train the first large model to obtain the target large model. The target large model can be used to perform demand analysis on the target code requirements, obtain the data objects involved in the target code requirements, and split the processing tasks of the data objects into at least one subtask, and based on the at least one subtask, more efficiently and accurately generate the target code corresponding to the target code requirement, so as to meet the code generation requirements in complex software development projects and improve the efficiency and quality of software development.
[0279] In order to implement the above embodiments, the present disclosure also provides a code generation device based on a large model.
[0280] Figure 5 It is a structural diagram of a code generation device based on a large model provided according to an embodiment of the present disclosure.
[0281] like Figure 5 As shown, the code generation device 500 based on the large model includes:
[0282] A first acquisition module 501 is used to acquire target code requirements;
[0283] The processing module 502 is used to perform demand analysis on the target code demand through the large model, obtain the data object involved in the target code demand, and split the processing task of the data object into at least one subtask;
[0284] The generating module 503 is used to generate the target code corresponding to the target code requirement through the large model based on at least one subtask.
[0285] As a possible implementation of the embodiment of the present disclosure, the generating module 503 includes:
[0286] The acquisition submodule is used to obtain target code samples matching the target code requirements from the code sample library;
[0287] The generation submodule is used to generate the target code through the large model based on at least one subtask by taking the target code sample as an example.
[0288] As a possible implementation of the embodiment of the present disclosure, a submodule is generated, including:
[0289] A first generating unit is used to use the target code sample as an example, based on at least one subtask, to generate the code of the main function and the code of the sub-function corresponding to the at least one subtask through the large model; wherein the sub-function is used to implement the corresponding subtask, and the main function is used to coordinate the calling of the sub-function to implement the processing task;
[0290] The second generating unit is used to generate target code based on the code of the main function and the code of the sub-function.
[0291] As a possible implementation of the embodiment of the present disclosure, the target code sample includes a main function sample and a sub-function sample; the first generation unit includes:
[0292] A first generating subunit is used to generate a first prompt word based on the main function sample and at least one subtask, wherein the first prompt word is used to indicate an example to be referred to when generating the code of the main function and a task to be implemented by the subfunction called by the main function;
[0293] A first processing subunit is used to input the first prompt word into the large model to obtain the code of the main function;
[0294] A second generating subunit is used to generate a second prompt word based on the sub-function sample and the main function, wherein the second prompt word is used to indicate an example required to be referenced by the code for generating the sub-function and a main function for calling the sub-function;
[0295] The second processing sub-unit is used to input the second prompt word into the large model to obtain the code of the sub-function.
[0296] As a possible implementation of the embodiment of the present disclosure, the second generating unit includes:
[0297] The third generation subunit is used to use the target code sample as an example to generate the code of the header file and the code of the include file through the large model; wherein the header file includes the declaration of the class composed of the main function and the sub-functions, and the include file includes the library referenced by the main function and the sub-functions;
[0298] The third processing sub-unit is used to splice the code of the main function, the code of the sub-function, the code of the header file, and the code of the included file to obtain the target code.
[0299] As a possible implementation of the embodiment of the present disclosure, the target code sample includes a header file sample and an include file sample; the third generation subunit is used to:
[0300] Based on the header file sample, the main function and the sub-function, a third prompt word is generated, wherein the third prompt word is used to indicate the example required for reference of the code for generating the header file and the main function and the sub-function constituting the class declared in the header file;
[0301] Input the third prompt word into the large model to obtain the code of the header file;
[0302] Generate a fourth prompt word based on the included file sample, the main function and the sub-function, wherein the fourth prompt word is used to indicate an example of reference required for generating the code of the included file and to reference the main function and the sub-function of the library in the included file;
[0303] Input the fourth prompt word into the large model to get the code of the included file.
[0304] As a possible implementation of the embodiment of the present disclosure, the device further includes:
[0305] The detection and repair submodule is used to detect and repair problems in the target code through the large model to obtain executable code corresponding to the target code requirements.
[0306] As a possible implementation of the embodiment of the present disclosure, the detection and repair submodule includes:
[0307] A compilation unit is used to compile the target code and obtain a compilation result;
[0308] A first repair unit is used to repair the target code based on the compilation problem by using a large model to obtain a repaired code when the compilation result indicates that the target code has a compilation problem;
[0309] The test unit is used to test the repaired code in the test environment and obtain the test results;
[0310] The second repairing unit is used to repair the repaired code based on the test problem by using the large model to obtain executable code when the test result indicates that the repaired code has a test problem.
[0311] As a possible implementation of the embodiment of the present disclosure, the test unit includes:
[0312] The acquisition subunit is used to obtain the test cases matching the target code requirements from the test case library;
[0313] A fourth generating subunit is used to use the test case as an example to generate a target test case corresponding to the target code requirement through the large model;
[0314] A fifth generation subunit, used to generate test codes corresponding to target test cases through the large model;
[0315] The test subunit is used to test the repaired code using the test code in the test environment to obtain the test result.
[0316] It should be noted that the aforementioned explanation of the code generation method based on the large model is also applicable to the code generation device based on the large model of this embodiment, and will not be repeated here.
[0317] In order to implement the above embodiments, the present disclosure also provides a target model training device.
[0318] Figure 6 It is a structural diagram of a target model training device provided according to an embodiment of the present disclosure.
[0319] like Figure 6 As shown, the target model training device 600 includes:
[0320] A second acquisition module 601 is used to acquire a training sample set, wherein the training sample set includes a first training sample and a second training sample;
[0321] A training module 602 is used to train an initial large model using a first training sample to obtain a first large model, wherein the first large model is used to perform a demand analysis on a target code requirement, obtain a data object involved in the target code requirement, and split a processing task on the data object into at least one subtask;
[0322] The training module 602 is also used to train the first large model with the second training sample to obtain a target large model, wherein the target large model is used to generate a target code corresponding to a target code requirement based on at least one subtask.
[0323] As a possible implementation of the embodiment of the present disclosure, the first training sample includes:
[0324] A first sample prompt word is used to instruct the initial large model to perform a demand analysis on the first sample code demand, obtain a sample data object involved in the first sample code demand, and split a processing task on the sample data object into at least one first sample subtask;
[0325] The first sample code requires an expected data object, and expected subtasks obtained by splitting a processing task of the expected data object.
[0326] As a possible implementation of the embodiment of the present disclosure, the second training sample includes:
[0327] The second sample prompt word is used to instruct the first large model to generate a target code corresponding to the second sample code requirement based on at least one second sample subtask;
[0328] The second sample code requirement corresponds to the desired target code.
[0329] As a possible implementation method of the embodiment of the present disclosure, the training module 602 is also used to train the target large model with a third training sample to obtain a second large model, wherein the second large model is used to detect and repair problems in the target code to obtain executable code corresponding to the target code requirements; wherein the third training sample includes: a third sample prompt word, used to instruct the target large model to detect and repair problems in the sample code to obtain the corresponding executable code; and the expected executable code corresponding to the sample code.
[0330] It should be noted that the above explanation of the target model training method is also applicable to the target model training device of this embodiment and will not be repeated here.
[0331] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0332] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0333] like Figure 7As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a ROM (Read-Only Memory) 702 or a computer program loaded from a storage unit 705 to a RAM (Random Access Memory) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An I / O (Input / Output) interface 705 is also connected to the bus 704.
[0334] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 705, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0335] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, CPU (Central Processing Unit), GPU (Graphic Processing Units), various dedicated AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSP (Digital Signal Processor), and any appropriate processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as a code generation method or a target model training method based on a large model. For example, in some embodiments, a code generation method or a target model training method based on a large model may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 705. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the code generation method based on the large model or the target model training method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to execute the code generation method based on the large model or the target model training method by any other appropriate means (e.g., by means of firmware).
[0336] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application Specific Standard Products), SOCs (System On Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that may be executed and / or interpreted on a programmable system including at least one programmable processor that may be a dedicated or general-purpose programmable processor that may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0337] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0338] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only-Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0339] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0340] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: LAN (Local Area Network), WAN (Wide Area Network), the Internet, and blockchain networks.
[0341] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0342] It should be noted that artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.), and includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0343] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0344] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A code generation method based on a large model, comprising: Obtain object code requirements; Performing a demand analysis on the target code requirement through a large model to obtain a data object involved in the target code requirement, and splitting a processing task on the data object into at least one subtask; Based on the at least one subtask, a target code corresponding to the target code requirement is generated through the large model.
2. The method according to claim 1, wherein: The generating the target code corresponding to the target code requirement by using the large model based on the at least one subtask includes: Obtaining a target code sample matching the target code requirement from a code sample library; Taking the target code sample as an example, the target code is generated by the large model based on the at least one subtask.
3. The method according to claim 2, wherein: The step of taking the target code sample as an example and generating the target code through the large model based on the at least one subtask includes: Taking the target code sample as an example, based on the at least one subtask, the code of the main function and the code of the sub-functions respectively corresponding to the at least one subtask are generated through the large model; wherein the sub-functions are used to implement the corresponding subtasks, and the main function is used to coordinate the calls of the sub-functions to implement the processing tasks; The target code is generated based on the code of the main function and the code of the sub-function.
4. The method according to claim 3, wherein: The target code sample includes a main function sample and a sub-function sample; the step of taking the target code sample as an example and generating the code of the main function and the code of the sub-functions corresponding to the at least one sub-task respectively through the large model based on the at least one sub-task includes: Based on the main function example and the at least one subtask, a first prompt word is generated, wherein the first prompt word is used to indicate an example to be referred to for generating the code of the main function and a task to be implemented by the subfunction called by the main function; Input the first prompt word into the large model to obtain the code of the main function; Based on the sub-function sample and the main function, a second prompt word is generated, wherein the second prompt word is used to indicate an example required to be referenced for generating the code of the sub-function and a main function that calls the sub-function; The second prompt word is input into the large model to obtain the code of the sub-function.
5. The method according to claim 3, wherein: The generating the target code based on the code of the main function and the code of the sub-function comprises: Taking the target code sample as an example, the code of the header file and the code of the include file are generated through the large model; wherein the header file includes the declaration of the class composed of the main function and the sub-function, and the include file includes the library referenced by the main function and the sub-function; The code of the main function, the code of the sub-function, the code of the header file, and the code of the included file are spliced to obtain the target code.
6. The method according to claim 5, wherein: The target code sample includes a header file sample and an included file sample; the code of the header file and the code of the included file are generated by the large model using the target code sample as an example, including: Generate a third prompt word based on the header file sample, the main function and the sub-function, wherein the third prompt word is used to indicate an example required to be referenced by the code for generating the header file and a main function and a sub-function constituting a class to which the declaration in the header file belongs; Input the third prompt word into the large model to obtain the code of the header file; Generate a fourth prompt word based on the include file sample, the main function and the sub-function, wherein the fourth prompt word is used to indicate an example of reference required to generate the code of the include file and a main function and a sub-function that reference the library in the include file; The fourth prompt word is input into the large model to obtain the code of the included file.
7. The method according to any one of claims 1 to 6, wherein: The method further comprises: The target code is detected and problems are repaired through the large model to obtain executable code corresponding to the target code requirements.
8. The method according to claim 7, wherein: The detecting and fixing of the target code by the large model to obtain the executable code corresponding to the target code requirement includes: Compiling the target code to obtain a compilation result; When the compilation result indicates that there is a compilation problem in the target code, repairing the target code based on the compilation problem by using the large model to obtain a repaired code; Testing the repaired code in a test environment to obtain a test result; When the test result indicates that there are test problems in the repaired code, the repaired code is repaired based on the test problems using the large model to obtain the executable code.
9. The method according to claim 8, wherein: The step of testing the repaired code in a test environment to obtain a test result includes: Obtaining test cases matching the target code requirements from a test case library; Taking the test case as an example, generating a target test case corresponding to the target code requirement through the large model; Generate test code corresponding to the target test case through the large model; In the test environment, the repaired code is tested using the test code to obtain the test result.
10. A target model training method, comprising: Acquire a training sample set, wherein the training sample set includes a first training sample and a second training sample; Using the first training sample to train the initial large model to obtain a first large model, wherein the first large model is used to perform demand analysis on the target code demand, obtain the data object involved in the target code demand, and split the processing task of the data object into at least one subtask; The first large model is trained using a second training sample to obtain a target large model, wherein the target large model is used to generate a target code corresponding to the target code requirement based on the at least one subtask.
11. The method according to claim 10, wherein: The first training sample includes: A first sample prompt word is used to instruct the initial large model to perform a demand analysis on the first sample code demand, obtain a sample data object involved in the first sample code demand, and split a processing task on the sample data object into at least one first sample subtask; The expected data object involved in the first sample code requirement, and the subtasks expected to be obtained by splitting the processing task of the expected data object.
12. The method according to claim 10, wherein: The second training sample includes: A second sample prompt word is used to instruct the first large model to generate a target code corresponding to a second sample code requirement based on at least one second sample subtask; The second sample code requirement corresponds to the expected target code.
13. The method according to any one of claims 10 to 12, wherein: The method further comprises: The target large model is trained using the third training sample to obtain a second large model, wherein the second large model is used to detect and repair problems of the target code to obtain executable code corresponding to the target code requirement; Wherein, the third training sample includes: The third sample prompt word is used to instruct the target large model to detect and repair the sample code to obtain the corresponding executable code; The sample code corresponds to the expected executable code.
14. A code generation device based on a large model, comprising: A first acquisition module is used to acquire target code requirements; A processing module, used for performing demand analysis on the target code demand through a large model, obtaining data objects involved in the target code demand, and splitting a processing task on the data object into at least one subtask; A generation module is used to generate target code corresponding to the target code requirement through the large model based on the at least one subtask.
15. The device according to claim 14, wherein: The generating module comprises: An acquisition submodule is used to acquire a target code sample matching the target code requirement from a code sample library; A generating submodule is used to take the target code sample as an example and generate the target code through the large model based on the at least one subtask.
16. The device according to claim 15, wherein: The generating submodule comprises: A first generating unit is used to use the target code sample as an example, based on the at least one subtask, to generate the code of the main function and the code of the sub-functions respectively corresponding to the at least one subtask through the large model; wherein the sub-functions are used to implement the corresponding subtasks, and the main function is used to coordinate the calling of the sub-functions to implement the processing task; The second generating unit is used to generate the target code based on the code of the main function and the code of the sub-function.
17. The device according to claim 16, wherein: The target code sample includes a main function sample and a sub-function sample; The first generating unit comprises: A first generating subunit is used to generate a first prompt word based on the main function example and the at least one subtask, wherein the first prompt word is used to indicate an example to be referred to for generating the code of the main function and a task to be implemented by the subfunction called by the main function; A first processing subunit is used to input the first prompt word into the large model to obtain the code of the main function; A second generating subunit is used to generate a second prompt word based on the sub-function sample and the main function, wherein the second prompt word is used to indicate an example required to be referenced for generating the code of the sub-function and a main function that calls the sub-function; The second processing sub-unit is used to input the second prompt word into the large model to obtain the code of the sub-function.
18. The device according to claim 16, wherein: The second generating unit comprises: A third generating subunit is used to use the target code sample as an example to generate header file code and include file code through the large model; wherein the header file includes a declaration of a class composed of the main function and the sub-functions, and the include file includes a library referenced by the main function and the sub-functions; The third processing sub-unit is used to splice the code of the main function, the code of the sub-function, the code of the header file, and the code of the included file to obtain the target code.
19. The device according to claim 18, wherein: The target code sample includes a header file sample and an include file sample; the third generation subunit is used to: Generate a third prompt word based on the header file sample, the main function and the sub-function, wherein the third prompt word is used to indicate an example required to be referenced by the code for generating the header file and a main function and a sub-function constituting a class to which the declaration in the header file belongs; Input the third prompt word into the large model to obtain the code of the header file; Generate a fourth prompt word based on the include file sample, the main function and the sub-function, wherein the fourth prompt word is used to indicate an example of reference required to generate the code of the include file and a main function and a sub-function that reference the library in the include file; The fourth prompt word is input into the large model to obtain the code of the included file.
20. The device according to any one of claims 14 to 19, wherein: The device also includes: The detection and repair submodule is used to detect and repair problems of the target code through the large model to obtain executable code corresponding to the target code requirements.
21. The device according to claim 20, wherein: The detection and repair submodule includes: A compiling unit, used for compiling the target code to obtain a compilation result; A first repairing unit is configured to repair the target code based on the compilation problem by using the large model to obtain a repaired code when the compilation result indicates that the target code has a compilation problem; A testing unit, used to test the repaired code in a testing environment to obtain a test result; The second repairing unit is used to repair the repaired code based on the test problem by using the large model to obtain the executable code when the test result indicates that the repaired code has a test problem.
22. The device according to claim 21, wherein The testing unit comprises: An acquisition subunit, used to acquire a test case matching the target code requirement from a test case library; A fourth generating subunit, configured to use the test case as an example and generate a target test case corresponding to the target code requirement through the large model; A fifth generating subunit, configured to generate test code corresponding to the target test case through the large model; The testing subunit is used to test the repaired code in the testing environment using the testing code to obtain the testing result.
23. A target model training device, comprising: A second acquisition module, used to acquire a training sample set, wherein the training sample set includes a first training sample and a second training sample; A training module, used for training an initial large model with a first training sample to obtain a first large model, wherein the first large model is used to perform a demand analysis on a target code requirement, obtain a data object involved in the target code requirement, and split a processing task on the data object into at least one subtask; The training module is further used to train the first large model with a second training sample to obtain a target large model, wherein the target large model is used to generate a target code corresponding to the target code requirement based on the at least one subtask.
24. The device according to claim 23, wherein: The first training sample includes: A first sample prompt word is used to instruct the initial large model to perform a demand analysis on the first sample code demand, obtain a sample data object involved in the first sample code demand, and split a processing task on the sample data object into at least one first sample subtask; The expected data object involved in the first sample code requirement, and the expected subtasks obtained by splitting the processing task of the expected data object.
25. The device according to claim 23, wherein: The second training sample includes: A second sample prompt word is used to instruct the first large model to generate a target code corresponding to a second sample code requirement based on at least one second sample subtask; The second sample code requirement corresponds to the expected target code.
26. The device according to any one of claims 23 to 25, wherein: The training module is also used to train the target large model with a third training sample to obtain a second large model, wherein the second large model is used to detect and repair problems in the target code to obtain executable code corresponding to the target code requirements; wherein the third training sample includes: a third sample prompt word, used to instruct the target large model to detect and repair problems in the sample code to obtain the corresponding executable code; and the expected executable code corresponding to the sample code.
27. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method of any one of claims 1-9, or execute the method of any one of claims 10-13.
28. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable the computer to execute the method according to any one of claims 1 to 9, or to execute the method according to any one of claims 10 to 13.
29. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to any one of claims 1 to 9, or implements the method according to any one of claims 10 to 13.
Citation Information
Patent Citations
Knowledge distillation method and device based on large model
CN117785158A
Model training method, related method, device, equipment and storage medium
CN118012781A
Code generation method and system based on large model, terminal and medium
CN118113271A
Task execution method and device based on large model
CN118519680A
Intelligent model distributed deployment system and method based on block chain
CN118611848A
Cited By
Code quality evaluation method and device, computer equipment and storage medium
CN120407427A
Code generation task adaptive reasoning method, device and equipment
CN120560664A
Code repairing method and device based on large language model, equipment and medium
CN120909640A
A code repair method, device and equipment based on a large language model and a medium
CN120909640B
Code generation method and computing device
CN121166525A