Code generation method, device and electronic equipment based on large model

By analyzing and breaking down target code requirements using a large model, and combining it with code sample libraries and test case libraries, efficient and accurate code generation is achieved in complex software development projects, improving software development efficiency and quality.

CN119759356BActive Publication Date: 2025-10-28BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411824176.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-11
Publication Date
2025-10-28
Estimated Expiration
2044-12-11

AI Technical Summary

Technical Problem

Existing technologies are unable to efficiently and accurately generate code in complex software development projects, making it difficult to improve software development efficiency and quality.

Method used

A large model is used to analyze the target code requirements, split them into multiple subtasks, and generate target code through the large model. Code generation and repair are performed in combination with the code sample library and test case library to achieve efficient and accurate code generation.

Benefits of technology

By breaking down complex tasks into easily implementable subtasks using a large model, and combining code examples and test cases, the efficiency and quality of code generation are improved, dependence on code libraries is reduced, and storage space is saved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119759356B_ABST
    Figure CN119759356B_ABST
Patent Text Reader

Abstract

This disclosure provides a code generation method, apparatus, and electronic device based on a large model, relating to artificial intelligence technologies such as large models, model training, and deep learning. It can be applied to scenarios such as code generation and software development, including generative search, intelligent assistants, and code recommendation. The specific implementation scheme is as follows: Obtaining target code requirements; performing requirement analysis on the target code requirements using a large model to obtain the data objects involved in the target code requirements, and breaking down the processing tasks of the data objects into at least one sub-task; generating executable code corresponding to the target code requirements based on the at least one sub-task using the large model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the fields of artificial intelligence technology such as large models, model training, and deep learning, and can be applied to scenarios such as code generation and software development, including applications such as generative search, intelligent assistants, and code recommendation. In particular, it relates to code generation methods, devices, and electronic devices based on large models. Background Technology

[0002] With the rapid development of software development, the demand for automated code generation is increasing. How to generate code accurately and efficiently to meet the code generation needs of complex software development projects is of great significance for improving software development efficiency and quality. Summary of the Invention

[0003] This disclosure provides a code generation method, apparatus, and electronic device based on a large model.

[0004] According to a first aspect of this disclosure, a code generation method based on a large model is provided, comprising: obtaining target code requirements; performing requirement analysis on the target code requirements through the large model to obtain data objects involved in the target code requirements, and splitting the processing tasks of the data objects into at least one sub-task; and generating target code corresponding to the target code requirements through the large model based on the at least one sub-task.

[0005] According to a second aspect of this disclosure, a target model training method is provided, comprising: acquiring a training sample set, wherein the training sample set includes a first training sample and a second training sample; training an initial large model using the first training sample to obtain a first large model, wherein the first large model is used to perform requirement analysis on target code requirements, obtain data objects involved in the target code requirements, and decompose the processing tasks of the data objects into at least one sub-task; training the first large model using the second training sample to obtain a target large model, wherein the target large model is used to generate target code corresponding to the target code requirements based on the at least one sub-task.

[0006] According to a third aspect of this disclosure, a code generation apparatus based on a large model is provided, comprising: a first acquisition module for acquiring target code requirements; a processing module for performing requirement analysis on the target code requirements through the large model to obtain data objects involved in the target code requirements, and splitting the processing task of the data objects into at least one sub-task; and a generation module for generating target code corresponding to the target code requirements based on the at least one sub-task through the large model.

[0007] According to a fourth aspect of this disclosure, a target model training apparatus is provided, comprising: a second acquisition module for acquiring a training sample set, wherein the training sample set includes a first training sample and a second training sample; a training module for training an initial large model using the first training sample to obtain a first large model, wherein the first large model is used to perform requirement analysis on target code requirements, obtain data objects involved in the target code requirements, and decompose the processing tasks of the data objects into at least one sub-task; the training module is further 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 target code corresponding to the target code requirements based on the at least one sub-task.

[0008] According to a fifth aspect of this disclosure, an electronic device is provided, comprising:

[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 to enable the at least one processor to perform the code generation method based on a large model as described in the first aspect, or to perform the target model training method as described in the second aspect.

[0012] According to a sixth aspect of this disclosure, a non-transitory computer-readable storage medium is provided that stores computer instructions for causing the computer to perform a code generation method based on a large model as described in the first aspect, or to perform a target model training method as described in the second aspect.

[0013] According to a seventh aspect of this disclosure, a computer program product is provided, including computer instructions that, when executed by a processor, implement the code generation method based on a large model as described in the first aspect, or the target model training method as described in the second aspect.

[0014] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0015] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:

[0016] Figure 1 This is a flowchart illustrating a code generation method based on a large model according to an embodiment of the present disclosure;

[0017] Figure 2 This is a flowchart illustrating a code generation method based on a large model according to another embodiment of the present disclosure;

[0018] Figure 3 This is a flowchart illustrating a code generation method based on a large model according to another embodiment of the present disclosure;

[0019] Figure 4 This is a flowchart illustrating a target model training method according to an embodiment of the present disclosure;

[0020] Figure 5 This is a schematic diagram of the structure of a code generation apparatus based on a large model according to an embodiment of the present disclosure;

[0021] Figure 6 This is a schematic diagram of the structure of a target model training device according to an embodiment of the present disclosure;

[0022] Figure 7 This is a block diagram of an electronic device used to implement the code generation method or target model training method based on a large model according to the embodiments of this disclosure. Detailed Implementation

[0023] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0024] In the technical solutions disclosed herein, the collection, storage, use, processing, transmission, provision, and disclosure of users' personal information are all carried out with the consent of the users, and all comply with the provisions of relevant laws and regulations, and do not violate public order and good morals.

[0025] With the rapid development of software development, the demand for automated code generation is increasing. How to generate code accurately and efficiently to meet the code generation needs of complex software development projects is of great significance for improving software development efficiency and quality.

[0026] In order to generate code accurately and efficiently and meet the code generation needs of complex software development projects, this disclosure proposes a code generation method, target model training method, device and electronic device based on a large model.

[0027] To facilitate understanding of the embodiments of this disclosure, some technical terms in the embodiments of this disclosure will be briefly explained first.

[0028] A prompt is a word that encapsulates the user's input, i.e., the query, into instructions for interacting with the large model. After the prompt is input into the large model, the model outputs a response. The response is then further processed and presented to the user as the final result.

[0029] The prompt template is a template used to generate prompts. The content can be preset as needed. For example, it can include instructions for large models, as well as the positions to be filled or the information to be replaced. By using the specified information to fill the positions to be filled or replace the information to be replaced, the corresponding prompts can be obtained.

[0030] The following description, with reference to the accompanying drawings, outlines a code generation method, target model training method, apparatus, and electronic device based on a large model, representing embodiments of the present disclosure.

[0031] It should be noted that the execution entity of the code generation method based on a large model in this embodiment is a code generation device based on a large model. In the following embodiments, the code generation device based on a large model will be simply referred to as a code generation device. The code generation device can be implemented in software and / or hardware, and can be configured in an electronic device, which may include, but is not limited to, a terminal or a server.

[0032] Figure 1 This is a flowchart illustrating a code generation method based on a large model according to an embodiment of the present disclosure.

[0033] like Figure 1 As shown, this code generation method based on a large model includes:

[0034] Step 101: Obtain the target code requirements.

[0035] The target code requirements include a description of the code to be generated, indicating the functionality that the generated code should implement. These target code requirements can be described using natural language.

[0036] In some embodiments, the target code requirement may be input by the user using voice or text.

[0037] For example, when a user needs to develop a new shopping cart feature for an e-commerce website, they can describe the requirements in natural language: "The shopping cart should be able to add and remove items, and calculate the total price of the items." The code generation device can then obtain the target code requirements based on the user's input.

[0038] Alternatively, when a user needs to update the user authentication module of a software system to support a new security protocol, they can describe the update requirements in natural language: "The user authentication module needs to support multi-factor authentication and ensure that all information is encrypted." The code generation device can then obtain the target code requirements based on the user's input.

[0039] Step 102: Analyze the target code requirements using the large model to obtain the data objects involved in the target code requirements, and break down the data object processing tasks into at least one sub-task.

[0040] In some embodiments, a large model can be used to perform requirement analysis on the target code requirements, obtain the data objects involved in the target code requirements and the processing tasks for the data objects, and break down the processing tasks for the data objects into at least one sub-task.

[0041] Large models, in particular, are large neural network models trained using deep learning algorithms, designed to understand and generate natural language text. Trained on massive amounts of text data, large models capture the complexity and nuances of language, enabling them to perform various natural language processing tasks such as text generation, code generation, question-answering systems, semantic understanding, and reasoning. These models are designed to improve expressive power and predictive performance, handling more complex tasks and data, and exhibiting human-like intelligence.

[0042] The large model in this embodiment can be one of the following: large language model LLM, GPT3 (Generative Pre-trained Transformer), GPT4, T5 (Text-to-Text Transformer), LLaMA (Large Language Model Meta AI), etc.

[0043] The data objects may include classes or other data objects required by the target code. A class may be an instance of a class, which may encapsulate relevant attributes and methods. The number of data objects may be one or more, and this disclosure does not limit this.

[0044] The tasks for processing data objects can include operations performed on the data objects, which can be obtained through requirements analysis of the target code requirements. For example, taking the requirement of a shopping cart function described in natural language (textual form) as "the shopping cart should be able to add and delete items, and calculate the total price of all items" as an example, the data objects involved in the target code requirements can include a shopping cart class, and the tasks for processing the data objects can 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 derived by breaking down the data object processing task. For example, if the data object processing task includes adding and deleting items from the shopping cart and calculating the total price of all items in the shopping cart, the data object processing task can be broken down into the following three subtasks: adding items to the shopping cart, removing items from the 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 requirement analysis on the target code requirement, obtain the data objects involved in the target code requirement, and break down the processing task of the data objects into at least one sub-task. The prompt word is then input into the large model, so that the data objects involved in the target code requirement and at least one sub-task of the processing task of the data objects can be obtained through the large model.

[0047] The target code requirement can be filled into a 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, and this disclosure does not limit this.

[0048] For example, preset prompt templates may include the following:

[0049] You are a requirements analyzer capable of performing requirements analysis on the following target code requirements, identifying the data objects involved in the target code requirements and the processing tasks for those data objects, breaking down the processing tasks into subtasks (the more subtasks the better), and returning the generated data in a list format that Python can process:

[0050] Target code requirement: ["query"]

[0051] Please perform a requirements analysis on the target code requirements, generate all the data objects involved in the target code requirements and their sub-tasks in one go, and return the generated data in list format.

[0052] In the aforementioned preset prompt word template, the information to be replaced corresponding to the target code requirement is: query. The code generation device can obtain the prompt word corresponding to the target code requirement by replacing the query in the prompt word template with the obtained target code requirement.

[0053] Step 103: Based on at least one subtask, generate the target code corresponding to the target code requirements through the large model.

[0054] The target code, which corresponds to the target code requirement, is the code that can implement the function described in the target code requirement.

[0055] In some embodiments, at least one prompt word corresponding to a subtask can be generated. This prompt word is used to instruct the large model to generate code that can implement each subtask. Then, by inputting the prompt word into the large model, the target code corresponding to the target code requirement can be obtained through the large model.

[0056] In this process, the task information of at least one subtask can be directly used as the prompt word; or, the task information of at least one subtask can be filled into a preset prompt word template to obtain the 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 the prompt word; or, the prompt word can be obtained in other ways, and this disclosure does not limit this.

[0057] In some embodiments, for any subtask, a prompt word corresponding to that subtask can be generated first. This prompt word instructs the large model to generate code that can implement the subtask. Each prompt word is then input into the large model to obtain the code corresponding to each subtask output by the large model. Finally, the codes corresponding to each subtask are merged to obtain the target code corresponding to the target code requirement.

[0058] Specifically, the task information of any subtask can be directly used as the prompt word corresponding to that subtask; or, the task information of any subtask can be filled into a preset prompt word template to obtain the prompt word corresponding to that 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 that subtask; or, other methods can be used to obtain the prompt word corresponding to that subtask, and this disclosure does not impose any restrictions on this.

[0059] The code generation method based on a large model provided in this disclosure analyzes the target code requirements using a large model to obtain the data objects involved in the target code requirements. It then breaks down the processing tasks for these data objects into at least one sub-task. This allows the complex processing tasks of the data objects involved in the target code requirements to be broken down into smaller, more easily implemented sub-tasks using the large model. Furthermore, code generation based on these sub-tasks using the large model can generate target code corresponding to the target code requirements more efficiently and accurately, meeting the code generation needs of complex software development projects and improving software development efficiency and quality. In addition, using a large model to generate target code reduces the code generation process's dependence on code libraries, saving storage space.

[0060] To clearly illustrate the process of generating target code corresponding to the target code requirements through a large model, this disclosure also provides a code generation method based on a large model.

[0061] Figure 2 This is a flowchart illustrating a code generation method based on a large model according to another embodiment of the present disclosure.

[0062] like Figure 2 As shown, this code generation method based on a large model includes:

[0063] Step 201: Obtain the target code requirements.

[0064] Step 202: Analyze the target code requirements using the large model to obtain the data objects involved in the target code requirements, and break down the data object processing tasks into at least one sub-task.

[0065] The specific implementation process and principle of steps 201-202 can be found in the descriptions of other embodiments, and will not be repeated here.

[0066] Step 203: Obtain target code samples that match the target code requirements from the code sample library.

[0067] The code sample library includes multiple first-choice code requirements and corresponding candidate code examples. The candidate code examples are pre-saved code examples in the library. Each first-choice code requirement includes a description of the functionality implemented by the corresponding candidate code example. These first-choice code requirements can be described using natural language.

[0068] In some embodiments, step 203 can be implemented in the following ways:

[0069] Determine the similarity between the target code requirements and the requirements of each first candidate code in the code sample library;

[0070] Based on similarity, a second candidate code requirement is determined from the first candidate code requirement in the code sample library;

[0071] The candidate code example corresponding to the second candidate code requirement is determined as the target code example.

[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 can be used as the similarity between the target code requirement and the first candidate code requirement.

[0073] As an example, the first candidate code requirement in the code sample library whose similarity to the target code requirement is higher than a set threshold can be identified as the second candidate code requirement.

[0074] In some embodiments, the first candidate code requirements and corresponding candidate code examples in the code example library can be divided according to classes, that is, the code example library includes first candidate code requirements and corresponding candidate code examples under multiple classes. When the data object involved in the target code requirement includes the target class, step 203 can be implemented in the following way:

[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 similarity, the third candidate code requirement is determined from the first candidate code requirement under the target class;

[0077] The candidate code example corresponding to the third candidate code requirement is determined as the target code example.

[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 can be used as the similarity between the target code requirement and the first candidate code requirement.

[0079] As an example, the first candidate code requirement in the first candidate code requirement under the target class whose similarity to the target code requirement is higher than a set threshold can be identified as the third candidate code requirement.

[0080] For example, assuming the data objects involved in the target code requirement include product categories, we can first determine the similarity between the target code requirement and the first candidate code requirement under the product category in the code sample library. Then, among the first candidate code requirements under the product category, the first candidate code requirement whose similarity to the target code requirement is higher than a set threshold is determined as the third candidate code requirement. Subsequently, 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, target code examples that better match the target code requirements can be quickly obtained from the code example library.

[0082] Step 204: Using the target code sample as an example, generate the target code corresponding to the target code requirements based on at least one subtask through the large model.

[0083] In some embodiments, a prompt word can be generated based on a target code example and at least one subtask. To distinguish it from other prompt words, this prompt word is referred to as the fifth prompt word in this embodiment. The fifth prompt word instructs the large model to use the target code example as an example to generate the target code corresponding to the target code requirement based on at least one subtask. Then, by inputting the fifth prompt word into the large model, the large model can obtain the target code corresponding to the target code requirement. Thus, the fifth prompt word can guide the large model to more accurately understand the task requirements, thereby accurately generating the target code corresponding to the target code requirement based on at least one subtask using the target code example as an example.

[0084] The fifth prompt can be obtained by filling the target code sample and at least one subtask into a preset prompt template; or, the corresponding information to be replaced in the preset prompt template can be replaced using the target code sample and at least one subtask to obtain the fifth prompt; or, the fifth prompt can be obtained in other ways, and this disclosure does not limit this.

[0085] In some embodiments, step 204 can be implemented in the following manner:

[0086] Using 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-functions corresponding to at least one subtask are generated through the large model; wherein, the sub-functions are used to implement the corresponding sub-tasks, and the main function is used to coordinate the calls of the sub-functions to realize the processing tasks of the data objects involved in the target code requirements;

[0087] Based on the code of the main function and the code of the sub-functions, generate the target code corresponding to the target code requirements.

[0088] Each subtask corresponds to a subfunction, which is used to implement the corresponding subtask. The subtask is obtained by breaking down the data object processing task involved in the target code requirements.

[0089] The main function coordinates the sub-functions corresponding to each subtask to handle the data objects required by the target code.

[0090] In some embodiments, a prompt word can be generated based on a target code example and at least one subtask. To distinguish it from other prompt words, this prompt word is referred to as the sixth prompt word in this embodiment. The sixth prompt word instructs the large model to use the target code example as an example to generate the code for the main function and the code for the corresponding sub-functions of each sub-task, based on at least one sub-task. The sub-task is obtained by breaking down the processing task of the data objects involved in the target code requirements. Then, by inputting the sixth prompt word into the large model, the large model can obtain the code for each sub-function used to implement each sub-task, as well as the code for the main function used to coordinate the calls of each sub-function. Thus, the sixth prompt word can guide the large model to more accurately understand the task requirements, thereby using the target code example as an example to accurately generate the code for each sub-function used to implement each sub-task, as well as the code for the main function used to coordinate the calls of each sub-function, based on at least one sub-task.

[0091] The sixth prompt word can be obtained by filling the target code sample and at least one subtask into a preset prompt word template; 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, and this disclosure does not limit this.

[0092] By using a sample target code as an example, and based on at least one subtask, a large model generates the code for the main function and the code for the corresponding sub-functions of each of the at least one subtask. Then, based on the code for the main function and the code for the sub-functions, the target code corresponding to the target code requirements is generated. This allows the large model to generate the code for the sub-functions that implement a single subtask, as well as the code for the main function that coordinates the calls of the sub-functions, based on at least one subtask with smaller granularity and easier implementation. Finally, based on the code for the main function and the code for the sub-functions, the target code corresponding to the target code requirements is generated more accurately.

[0093] In some embodiments, the target code sample includes a main function sample and sub-function samples. The main function sample is the sample relating to the main function in the target code sample. The sub-function sample is the sample relating to the sub-function in the target code sample.

[0094] Accordingly, taking the target code example as an example, based on at least one subtask, the code for the main function and the code for the sub-functions corresponding to at least one subtask are generated through the large model, which 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 the example that needs to be referenced when generating the code for the main function and the task to be performed by the sub-function called by the main function;

[0096] Input the first prompt word into the large model to obtain the code for the main function;

[0097] Based on the example of the sub-function and the main function, a second prompt word is generated, which is used to indicate the example that needs to be referenced when generating the code for the sub-function and the main function that calls the sub-function;

[0098] Input the second prompt word into the large model to obtain the code for the sub-function.

[0099] The first prompt word can be obtained by filling the main function example and at least one subtask into a preset prompt word template; or, the corresponding information to be replaced in the preset prompt word template can be replaced using the main function example and at least one subtask to obtain the first prompt word; or, the first prompt word can be obtained in other ways, and this disclosure does not limit this.

[0100] The sub-function example and the main function can be filled into a preset prompt word template to obtain the second prompt word; or, the sub-function example 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, other methods can be used to obtain the second prompt word, and this disclosure does not limit this.

[0101] Therefore, by using a first prompt, the large model can be guided to more accurately understand the task requirements, thereby accurately generating the main function code for coordinating the calls of each sub-function based on the main function example and at least one sub-task. Furthermore, by using a second prompt, the large model can be guided to more accurately understand the task requirements, thereby accurately generating the code for each sub-function coordinated by the main function based on the sub-function examples and the main function. Additionally, it is understood that when generating code using a large model, the length of the output characters may be limited. Therefore, when the processing tasks involving the data objects in the target code requirements are complex, the large model may not be able to generate the complete target code corresponding to the target code requirements in one go. However, in this embodiment, by inputting the first and second prompts into the large model respectively to obtain the main function code and the sub-function code, and then generating the target code based on the main function code and the sub-function code, the complete target code corresponding to the target code requirements can be generated.

[0102] In some embodiments, the main function and sub-functions may reference libraries, and the class comprised of the main function and sub-functions may contain some declarative information. Therefore, to generate the complete target code corresponding to the target code requirements, the target code can be generated based on the code of the main function and the code of the sub-functions in the following way:

[0103] Using the target code example as an example, the code for generating header files and include files is generated from the large model; the header file includes the declaration of the class consisting of the main function and sub-functions, and the include file includes the libraries referenced by the main function and sub-functions;

[0104] By concatenating the code of the main function, the code of the sub-functions, the code of the header file, and the code of the include file, the target code corresponding to the target code requirement is obtained.

[0105] The included file is the file that is included in the list.

[0106] The libraries referenced by the main function and sub-functions are a set of predefined code that can provide a series of functions, classes and methods to solve specific problems or implement specific functions.

[0107] In some embodiments, the concatenation rules for the main function code, sub-function code, header file code, and include file code can be preset, so that the main function code, sub-function code, header file code, and include file code can be concatenated according to the concatenation rules to obtain the target code corresponding to the target code requirement.

[0108] In some embodiments, a prompt word can be generated based on the target code example, the main function, and the sub-functions. To distinguish it from other prompt words, this prompt word is referred to as the seventh prompt word in this embodiment. The seventh prompt word instructs the large model to use the target code example as an example to generate header file code and include file code. The header file includes the declaration of the class formed by the main function and the sub-functions, and the include file includes the libraries referenced by the main function and the sub-functions. By inputting the seventh prompt word into the large model, the large model can obtain the header file code and include file code. Thus, the seventh prompt word guides the large model to more accurately understand the task requirements, thereby accurately generating header file code and include file code using the target code example.

[0109] The seventh prompt word can be obtained by filling the target code sample, main function and sub-function into a preset prompt word template; 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, other methods can be used to obtain the seventh prompt word, and this disclosure does not limit this.

[0110] In some embodiments, the object code sample includes header file samples and include file samples. The header file samples are examples of header files in the object code sample. The include file samples are examples of include files in the object code sample.

[0111] Accordingly, using the target code sample as an example, the code for generating header files and include files from the large model includes:

[0112] Based on the header file example, main function, and sub-functions, a third prompt word is generated. The third prompt word is used to indicate the example that the code for generating the header file needs to refer to, as well as the main function and sub-functions that constitute the class declared in the header file.

[0113] Input the third prompt word into the large model to obtain the header file code;

[0114] Based on the included file example, main function, and sub-functions, a fourth prompt word is generated. The fourth prompt word is used to indicate the examples that the code needed to generate the included file should refer to, as well as the main functions and sub-functions that reference the libraries in the included file.

[0115] Input the fourth prompt word into the large model to obtain the code for the included file.

[0116] The third prompt can be obtained by filling the header file example, main function, and sub-function into a preset prompt template; or, the corresponding information to be replaced in the preset prompt template can be replaced using the header file example, main function, and sub-function to obtain the third prompt; or, other methods can be used to obtain the third prompt, and this disclosure does not limit this.

[0117] The fourth prompt word can be obtained by filling the included file sample, main function, and sub-function into a preset prompt word template; or, the corresponding information to be replaced in the preset prompt word template can be replaced using the included file sample, main function, and sub-function to obtain the fourth prompt word; or, the fourth prompt word can be obtained in other ways, and this disclosure does not limit this.

[0118] Therefore, a third prompt can be used to guide the large model to more accurately understand the task requirements, thereby accurately generating the header file code based on the header file example, main function, and sub-functions. This header file includes the class declarations of the main function and the sub-functions. Furthermore, a fourth prompt can be used to guide the large model to more accurately understand the task requirements, thereby accurately generating the include file code based on the include file example, main function, and sub-functions. This include file includes the libraries referenced by the main function and the sub-functions.

[0119] The code generation method based on a large model provided in this disclosure analyzes the target code requirements using a large model to obtain the data objects involved in the target code requirements. It then breaks down the processing tasks for these data objects into at least one sub-task. This allows the complex processing tasks of the data objects involved in the target code requirements to be broken down into smaller, more easily implemented sub-tasks using the large model. By obtaining target code examples that match the target code requirements from a code example library and using these examples as examples, the target code corresponding to the target code requirements is generated based on at least one sub-task using the large model. This method enables more efficient and accurate generation of target code corresponding to the target code requirements by using a large model, referring to target code examples, and based on smaller, more easily implemented sub-tasks. This meets the code generation needs of complex software development projects and improves software development efficiency and quality.

[0120] As can be seen from the above analysis, the embodiments of this disclosure can generate target code corresponding to the target code requirements. In one possible implementation, the target code can also be detected and bugs fixed using a large model to obtain executable code, thereby improving the quality of the code generated by the code generation device and ensuring that the generated code is directly executable. The following is in conjunction with... Figure 3 This document describes the process of obtaining executable code by detecting target code and fixing problems through a large model in the code generation method based on a large model provided in this embodiment.

[0121] Figure 3 This is a flowchart illustrating a code generation method based on a large model according to another embodiment of the present disclosure.

[0122] It should be noted that the execution entity of this large-model-based code generation method is a large-model-based code generation device, or simply a code generation device. This code generation device can be implemented in software and / or hardware, and can be configured in an electronic device, which may include, but is not limited to, terminals and servers.

[0123] For example, a code generation device can be a software development tool configured in an electronic device. This software development tool adopts an end-to-end learning framework and can directly generate executable code corresponding to the target code requirements. This architecture enables the software development tool to more intuitively understand and handle the code generation requirements of complex software development projects.

[0124] like Figure 3 As shown, this code generation method based on a large model includes:

[0125] Step 301: Obtain the target code requirements.

[0126] Step 302: Analyze the target code requirements using the large model to obtain the data objects involved in the target code requirements, and break down the data object processing tasks into at least one sub-task.

[0127] Step 303: Based on at least one subtask, generate the target code corresponding to the target code requirements through the large model.

[0128] The specific implementation process and principle of steps 301-303 can be found in the descriptions of other embodiments, and will not be repeated here.

[0129] Step 304: Compile the target code to obtain the compilation result.

[0130] In some embodiments, the target code can be compiled in a compilation environment to obtain the compilation result.

[0131] Step 305: If the compilation result indicates that there is a compilation problem in the target code, the target code is repaired based on the compilation problem using the large model to obtain the repaired code.

[0132] Among them, compilation problems refer to issues that occur during the compilation of the target code.

[0133] In some embodiments, an eighth prompt word can be generated based on the compilation problem and the target code. The eighth prompt word is used to instruct the large model to repair the target code based on the compilation problem. By inputting the eighth prompt word into the large model, the repaired code can be obtained.

[0134] The eighth prompt word can be obtained by filling the compilation problem and target code into a preset prompt word template; or, the corresponding information to be replaced in the preset prompt word template can be replaced using the compilation problem and target code; or, the eighth prompt word can be obtained by other methods, which are not limited in this disclosure.

[0135] Step 306: Test the repaired code in the test environment and obtain the test results.

[0136] In some embodiments, to automate the testing of the repaired code, step 306 can be implemented in the following ways:

[0137] Retrieve test cases from the test case library that match the requirements of the target code;

[0138] Using test cases as examples, target test cases corresponding to the target code requirements are generated through a large model;

[0139] Generate test code corresponding to the target test cases using a large model;

[0140] In the test environment, the fixed code is tested using test code to obtain 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 based on the specified test cases to verify the code functionality.

[0143] The test case library includes multiple fourth candidate code requirements and corresponding candidate test cases. The candidate test cases are pre-saved in the test case library. The fourth candidate code requirement includes a description of the functionality implemented by the code, which is the code verified by the corresponding candidate test cases. Both the fourth candidate code requirement and the candidate test cases can be described using natural language.

[0144] In some embodiments, retrieving test cases that match the target code requirements from a test case library includes:

[0145] Determine the similarity between the target code requirements and the requirements of each of the fourth candidate code in the test case library;

[0146] Based on similarity, a fifth candidate code requirement is determined from the fourth candidate code requirement in the test case library;

[0147] The candidate test cases corresponding to the fifth candidate code requirement are determined as test cases that match the target code requirement.

[0148] In some embodiments, the fourth candidate code requirement and its corresponding candidate test cases in the test case library can be divided by class, meaning the test case library includes fourth candidate code requirements and their corresponding candidate test cases under multiple classes. When the data object involved in the target code requirement includes the target class, test cases matching the target code requirement are retrieved from the test case library, including:

[0149] Determine the similarity between the target code requirement and the fourth candidate code requirement under the target class in the test case library;

[0150] Based on similarity, the sixth candidate code requirement is determined from the fourth candidate code requirement under the target class;

[0151] The candidate test cases corresponding to the sixth candidate code requirement are determined as test cases that match the target code requirement.

[0152] Therefore, based on the target classes included in the data object, test cases that better match the requirements of the target code can be quickly obtained from the test case library.

[0153] In some embodiments, prompt words can be generated based on test cases and target code requirements. To distinguish it from other prompt words, this prompt word is referred to as the ninth prompt word in this embodiment. The ninth prompt word instructs the large model to use the specified test cases as examples to generate target test cases corresponding to the target code requirements. Then, by inputting the ninth prompt word into the large model, the target test cases corresponding to the target code requirements can be obtained through the large model.

[0154] The ninth prompt word can be obtained by filling test cases and target code requirements into a preset prompt word template; or, the corresponding information to be replaced in the preset prompt word template can be replaced using test cases and target code requirements; or, the ninth prompt word can be obtained by other methods, which are not limited in this disclosure.

[0155] In some embodiments, a prompt word can be generated based on the target test case. To distinguish it from other prompt words, this 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, by inputting the tenth prompt word into the large model, the test code corresponding to the target test case can be obtained from the large model.

[0156] The tenth prompt word can be obtained by filling the target test case into the preset prompt word template; 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, and this disclosure does not limit this.

[0157] Step 307: If the test results indicate that there are test problems in the repaired code, the repaired code is fixed based on the test problems using a large model to obtain executable code.

[0158] Among them, "testing issues" refers to problems that occur during testing of the fixed code.

[0159] In some embodiments, an eleventh prompt word can be generated based on the test issue and the fixed code. The eleventh prompt word is used to instruct the large model to fix the fixed code based on the test issue. By inputting the eleventh prompt word into the large model, executable code can be obtained.

[0160] The eleventh prompt can be obtained by filling the test problem and the fixed code into the preset prompt template; or, the corresponding information to be replaced in the preset prompt template can be replaced using the test problem and the fixed code; or, other methods can be used to obtain the eleventh prompt, and this disclosure does not limit this.

[0161] The code generation method based on a large model provided in this disclosure can integrate various stages such as requirements analysis, code generation, code compilation, code testing, and problem fixing to generate executable code corresponding to the target code requirements. By compiling the target code, a compilation result is obtained. If the compilation result indicates that the target code has compilation problems, the large model is used to fix the target code based on these compilation problems, resulting in fixed code. This method can automatically and accurately fix the target code when compilation problems exist. Furthermore, by testing the fixed code in a test environment, test results are obtained. If the test results indicate that the fixed code has testing problems, the large model is used to further fix the fixed code based on these testing problems, resulting in high-quality executable code.

[0162] In view of the large model used in the above embodiments, this disclosure also provides a target model training method.

[0163] It should be noted that the execution subject of the target model training method in 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, which may include, but is not limited to, a terminal, a server, etc.

[0164] Figure 4 This is a flowchart illustrating a target model training method according to an embodiment of the present disclosure.

[0165] like Figure 4 As shown, the training method for this target model includes:

[0166] Step 401: Obtain a training sample set, wherein the training sample set includes a first training sample and a second training sample.

[0167] Step 402: Train the initial large model using the first training sample to obtain the first large model. The first large model is used to perform requirement analysis on the target code requirements, obtain the data objects involved in the target code requirements, and break down the data object processing task into at least one sub-task.

[0168] In some embodiments, the first training sample includes:

[0169] The first sample prompt is used to instruct the initial large model to perform requirement analysis on the first sample code requirements, obtain the sample data objects involved in the first sample code requirements, and break down the processing task of the sample data objects into at least one first sample sub-task.

[0170] The first sample code requirement involves the expected data object, and the expected sub-tasks obtained by breaking down the processing task of the expected data object.

[0171] The sample code requirements include a description of the code to be generated, indicating the functionality the generated code should implement. These requirements can be described using natural language. To distinguish them from other sample code requirements, the sample code requirements corresponding to the first training sample are referred to here as the first sample code requirements.

[0172] The sample data object refers to the processing object involved in the requirements of the first sample code, and may include classes or other data objects involved in the requirements of the first sample code. The class can be an instance of a class, which can encapsulate related attributes and methods.

[0173] Processing tasks for sample data objects can include operations performed on the sample data objects.

[0174] The first sample subtask is a subtask obtained by splitting the task of processing sample data objects.

[0175] The expected data object is the data object generated from the expected initial large model.

[0176] The desired subtasks are the subtasks generated by the expected initial large model.

[0177] Therefore, by using the first training sample to train the initial large model, the first large model is obtained. This first large model can be used to perform requirement analysis on the target code requirements, obtain the data objects involved in the target code requirements, and break down the data object processing task into at least one sub-task.

[0178] Step 403: Train the first large model using the second training sample to obtain the target large model, wherein the target large model is used to generate target code corresponding to the target code requirement based on at least one subtask.

[0179] In step 403, at least one subtask is a subtask that is broken down from the data object processing task, and the data object is the data object involved in the target code requirements.

[0180] In some embodiments, the second training sample may include:

[0181] The second sample prompt is used to instruct the first main model to generate the target code corresponding to the second sample code requirement based on at least one second sample sub-task.

[0182] The second sample code requires the corresponding expected target code.

[0183] The requirements for the second sample code may be the same as or different from those for the first sample code, and this disclosure does not impose any restrictions on this.

[0184] The second sample subtask is a subtask obtained by breaking down the data object processing task involved in the second sample code requirements.

[0185] The target code corresponding to the second sample code requirement is the code that can achieve the function described in 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 generated by the first large model.

[0187] Therefore, since the first large model can be used to perform requirement analysis on the target code requirements, obtain the data objects involved in the target code requirements, and break down the processing task 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 to generate executable code corresponding to the target code requirements based on the at least one sub-task that has been broken down.

[0188] Correspondingly, the target large model obtained by training the first large model can be applied to the above-mentioned code generation method based on the large model in the embodiment of the code generation method, to perform requirement analysis on the target code requirements and generate target code based on the results of the requirement analysis.

[0189] In some embodiments, a third training sample can be used to train the target large model to obtain a second large model. The second large model is used to detect and fix problems in the target code corresponding to the target code requirements to obtain the executable code corresponding to the target code requirements.

[0190] The third training sample includes:

[0191] The third sample prompt is used to instruct the target large model to detect and fix problems in the sample code, and obtain the corresponding executable code.

[0192] The expected executable code corresponding to the sample code.

[0193] The sample code can be any code capable of performing 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 requirement analysis on the target code requirements, obtain the data objects involved in the target code requirements, and break down 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 to detect and fix problems in the generated target code, and obtain executable code corresponding to the target code requirements.

[0196] In some embodiments, a fourth training sample may also 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 is used to instruct the second model to use the first sample code example as an example to generate the 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 requirements for the third sample code may be the same as or different from those for other sample codes, and this disclosure does not impose any restrictions on this.

[0200] The third sample subtask is a subtask obtained by splitting the data object processing task involved in the third sample code requirements.

[0201] The target code corresponding to the third sample code requirement is the code that can achieve the function described in the third sample code requirement.

[0202] The first sample code example is a code example that matches the requirements of the third sample code example.

[0203] The target code corresponding to the requirement of the third sample code is the target code corresponding to the requirement of the third sample code generated by the second largest model.

[0204] Therefore, by using the fourth training sample to train the second major model, the third major model is obtained. This third major model can be used to handle the tasks that the second major model can handle, and can also be used to generate target code corresponding to the target code requirements based on at least one sub-task, and to detect and fix problems in the target code to obtain the corresponding executable code. The at least one sub-task is obtained by splitting the data object processing tasks involved in the target code requirements.

[0205] In some embodiments, a third major model can also be trained using a fifth training sample to obtain a fourth major model, wherein the fifth training sample includes:

[0206] The fifth sample prompt is used to instruct the third model to take the second sample code example as an example, and generate the code of the first main function and the code of the first sub-function corresponding to the fourth sample sub-task based on at least one fourth sample sub-task; wherein, the first sub-function is used to implement the corresponding fourth sample sub-task, and the first main function is used to coordinate the call of the first sub-function to realize the processing task of the data object involved in the fourth sample code requirement;

[0207] The expected code for the first sub-function, and the expected code for the first main function.

[0208] The requirements for the fourth sample code may be the same as or different from those for the other sample codes, and this disclosure does not impose any restrictions on this.

[0209] The fourth sample subtask is a subtask obtained by splitting the data object processing task involved in the fourth sample code requirements.

[0210] The second sample code example is a code example that matches the requirements of the fourth sample code example.

[0211] The code for the expected first sub-function is the code for the expected third-largest model's first sub-function.

[0212] The code for the expected first main function is the code for the expected first main function generated by the third largest model.

[0213] Therefore, by using the fifth training sample to train the third major model, the fourth major model is obtained. This fourth major model can be used to handle the tasks that the third major model can handle, and can also be used to generate code for sub-functions that implement each sub-task and code for the main function that coordinates the calls of each sub-function, based on at least one sub-task, using the target code example as an example. The at least one sub-task is obtained by splitting the data object processing tasks involved in the target code requirements.

[0214] In some embodiments, a sixth training sample may also be used to train a fourth major model to obtain a fifth major model, wherein the sixth training sample includes:

[0215] The sixth sample prompt is used to indicate the examples that the fourth model needs to refer to when generating the code for the second main function, as well as the tasks that the second sub-function called by the second main function needs to perform.

[0216] The code for the expected second main function.

[0217] The second sub-function can be one or more, and each second sub-function corresponds to any sub-task in which the processing task of any data object is broken down. This second sub-function is used to implement the corresponding sub-task. The second main function is used to coordinate the calls of each second sub-function to achieve the processing task.

[0218] The code for the second main function expected to be generated is the code for the second main function expected to be generated by the fourth main model.

[0219] Therefore, by training the fourth major model using the sixth training sample, the fifth major model is obtained. This fifth major model can be used to handle the tasks that the fourth major model can handle, and it can also be used to generate the code of the main function based on the first prompt word, which indicates the example to be referenced for generating the code of the main function and the task to be implemented by the sub-functions called by the main function.

[0220] In some embodiments, the fifth major model can also be trained using the seventh training samples to obtain the sixth major model, wherein the seventh training samples include:

[0221] The seventh sample prompt is used to indicate the example that the code for generating the third sub-function of the fifth major model needs to refer to, as well as the third main function that calls the third sub-function;

[0222] The code for the expected third sub-function.

[0223] The system includes one or more third sub-functions, each corresponding to any subtask in the processing of any data object, and is used to implement that subtask. The main function coordinates the calls to these third sub-functions to achieve the processing task.

[0224] The code for the third sub-function expected to be generated is the code for the third sub-function expected to be generated by the fifth major model.

[0225] Therefore, by training the fifth model using the seventh training sample, the sixth model is obtained. The sixth model can be used to handle the tasks that the fifth model can handle, and it can also be used to generate the code of the sub-function based on the second prompt word, which indicates the example to be referenced for the code of the sub-function and the main function that calls the sub-function.

[0226] In some embodiments, the sixth model can also be trained using the eighth training samples to obtain the seventh model, wherein the eighth training samples include:

[0227] The eighth sample prompt is used to instruct the sixth model to use the third sample code example as an example to generate the code for the first sample header file and the code for the first sample include file; wherein, the first sample header file includes the declaration of the class consisting of the fourth main function and the fourth sub-function, and the first sample include file includes the libraries referenced by the fourth main function and the fourth sub-function;

[0228] The code for the first sample header file and the code for the first sample include file to be generated.

[0229] The third sample code example is a code example that matches the requirements of the fifth sample code. The requirements of the fifth sample code may be the same as or different from the requirements of the other sample codes, and this disclosure does not impose any restrictions on this.

[0230] The fourth sub-function implements the corresponding fifth sample sub-task, and the fourth main function coordinates the calls to the fourth sub-function to handle the data objects involved in the fifth sample code requirements. The fifth sample sub-task is a sub-task derived by breaking down the data object handling tasks involved in the fifth sample code requirements.

[0231] The code for the expected first sample header file is the code for the expected first sample header file generated by the sixth major model.

[0232] The code for the first sample to be generated is expected to be from the file containing the code for the sixth largest model.

[0233] Therefore, by training the sixth model using the eighth training sample, the seventh model is obtained. This seventh model can not only handle the tasks that the sixth model can handle, but also generate header file code and include file code using the target code example. The header file includes the declaration of the class consisting of the main function and sub-functions, and the include file includes the libraries referenced by the main function and sub-functions. Each sub-function corresponds to a subtask, and the main function is used to coordinate the calls of the sub-functions corresponding to at least one subtask to realize the processing task of the data objects involved in the target code requirements. The at least one subtask is obtained by decomposing the processing task of the data objects involved in the target code requirements.

[0234] In some embodiments, the seventh model can also be trained using the ninth training samples to obtain the eighth model, wherein the ninth training samples include:

[0235] The ninth sample prompt is used to indicate the examples that the code for generating the second sample header file of the seventh model needs to refer to, as well as the fifth main function and the fifth sub-function that constitute the class declared in the second sample header file;

[0236] The code for the expected second sample header file.

[0237] The system includes one or more fifth sub-functions, each corresponding to any subtask in the processing of any data object, and is used to implement that subtask. The main fifth function coordinates the calls to these sub-functions to achieve the processing task.

[0238] The second sample header file includes the declaration of the class consisting of the fifth main function and the fifth sub-function.

[0239] The code for the expected second sample header file is the code for the expected second sample header file generated by the seventh model.

[0240] Therefore, by training the seventh model using the ninth training sample, the eighth model is obtained. The eighth model can be used to handle the tasks that the seventh model can handle, and it can also be used to generate the code of the header file based on the third prompt word, which indicates the examples that the code needs to refer to when generating the header file, as well as the main function and sub-functions of the class declared in the header file.

[0241] In some embodiments, the eighth model can also be trained using the tenth training sample to obtain the ninth model, wherein the tenth training sample includes:

[0242] The tenth sample prompt is used to indicate the examples that the code for generating the second sample include file from the eighth model needs to refer to, as well as the sixth main function and sixth sub-function of the library in the second sample include file;

[0243] The second sample to be generated is expected to contain the code of the file.

[0244] There can be one or more sixth sub-functions, each corresponding to any subtask in the processing task of any data object, and this sixth sub-function is used to implement the corresponding subtask. The sixth main function coordinates the calls to all the sixth sub-functions to achieve the processing task.

[0245] The second sample includes files containing libraries referenced by the sixth main function and the sixth sub-function.

[0246] The code for the second sample to be generated is expected to be the code for the file containing the second sample to be generated by the eighth model.

[0247] Therefore, by training the eighth model using the tenth training sample, the ninth model is obtained. This ninth model can be used to handle the tasks that the eighth model can handle, and it can also be used to generate the code of the include file based on the fourth prompt word, which indicates the examples that need to be referenced to generate the code of the include file and the main function and sub-functions of the library in the include file.

[0248] In some embodiments, the eleventh training sample can also be used to train the ninth model to obtain the tenth model, wherein the eleventh training sample includes:

[0249] The eleventh sample prompt is used to instruct the ninth model to fix the code of the first problem based on the sample compilation issue, and obtain the corresponding fixed code.

[0250] The expected corrected code corresponding to the first problematic code.

[0251] Among them, the sample compilation problem refers to the problem that occurred during the compilation of the first problematic code.

[0252] The expected corrected code corresponding to the first problem code is the corrected code obtained from the ninth model.

[0253] Therefore, by using the eleventh training sample to train the ninth model, the tenth model is obtained. This tenth model can not only handle the tasks that the ninth model can handle, but also fix the compilation problems of the target code based on the target code requirements.

[0254] In some embodiments, the twelfth training sample can also be used to train the tenth model to obtain the eleventh model, wherein the twelfth training sample includes:

[0255] The twelfth sample prompt is used to instruct the tenth model to fix the code of the second problem based on the sample test problem, and obtain the corresponding fixed code.

[0256] The expected corrected code corresponding to the second problematic code.

[0257] The sample test problem refers to the issue that occurred during the testing of the second problem code.

[0258] The expected corrected code corresponding to the second problem code is the corrected code obtained from the tenth 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 handle the tasks that the tenth model can handle, and it can also be used to further repair the repaired code based on the test problems of the repaired code corresponding to the target code requirements, so as to obtain the corresponding executable code.

[0260] In some embodiments, the eleventh model can be trained using the thirteenth training samples to obtain the twelfth model, wherein the thirteenth training samples include:

[0261] The thirteenth sample prompt is used to instruct the eleventh model to use the first test case as an example to generate test cases corresponding to the sixth sample code requirements.

[0262] The sixth sample code requirement corresponds to the expected test cases.

[0263] The requirements for the sixth sample code may be the same as or different from those for the other sample codes; this disclosure does not impose any restrictions on this. The first test case is a test case that matches the requirements of the sixth sample code.

[0264] The expected test cases corresponding to the sixth sample code requirement are the test cases corresponding to the sixth sample code requirement generated by the expected eleventh 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 handle the tasks that the eleventh model can handle, and can also be used to generate target test cases corresponding to the target code requirements by using test cases that match the target code requirements as examples.

[0266] In some embodiments, the twelfth model can also be trained using the fourteenth training samples to obtain the thirteenth model, wherein the fourteenth training samples include:

[0267] The fourteenth sample prompt is used to instruct the twelfth model to generate the test code corresponding to the second test case.

[0268] The expected test code corresponding to the second test case.

[0269] The second test case can be any test case, and can be the same as or different from the first test case. This disclosure does not impose any restrictions on this.

[0270] The test code corresponding to the second test case is the code generated based on the specified second test case to verify the code functionality.

[0271] The expected test code corresponding to the second test case is the test code corresponding to the second test case generated by the expected twelfth model.

[0272] Therefore, by using the fourteenth training sample to train the twelfth model, the thirteenth model is obtained. This allows the thirteenth model to not only handle the tasks that the twelfth model can handle, but also to generate test code corresponding to the target test cases.

[0273] The thirteenth model can be applied to the code generation method based on large models in the above embodiments.

[0274] In some embodiments, the number of any of the above training samples can be multiple.

[0275] It should be noted that the above method of training the initial large model to obtain the thirteenth model adopts an iterative training method based on multiple training samples. That is, each iteration uses a different training sample to optimize the large model to be trained, so that the optimized large model can perform the task corresponding to that type of training sample. In the next iteration, a different training sample is used to further improve the model performance. Through 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 various training samples described above. For example, the various training samples can be mixed and used together to train the initial large model. By fine-tuning the model parameters, an optimized fourteenth model can be obtained, which can handle the multiple tasks that the thirteenth model can handle. After training, the performance of the fourteenth model can be evaluated. If it does not meet expectations, the fourteenth model can be trained again. Through multiple rounds of training, the model's capabilities can be continuously improved. The final large model can be applied to the code generation method based on the large model in the above embodiments.

[0277] It should be noted that steps or implementation processes similar to those in other embodiments of this disclosure will not be described again here.

[0278] The target model training method provided in this disclosure trains an initial large model using a first training sample from the training sample set to obtain a first large model. Then, it trains the first large model using a second training sample from the training sample set to obtain a target large model. This allows the target large model to be used for requirement analysis of target code requirements, obtain the data objects involved in the target code requirements, and break down the data object processing tasks into at least one sub-task. Based on at least one sub-task, it generates the target code corresponding to the target code requirements more efficiently and accurately, meeting the code generation needs of complex software development projects and improving software development efficiency and quality.

[0279] To implement the above embodiments, this disclosure also provides a code generation apparatus based on a large model.

[0280] Figure 5 This is a schematic diagram of the structure of a code generation apparatus 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 a large model includes:

[0282] The first acquisition module 501 is used to acquire target code requirements;

[0283] Processing module 502 is used to perform requirement analysis on the target code requirements through a large model, obtain the data objects involved in the target code requirements, and break down the processing task of the data objects into at least one sub-task.

[0284] The generation module 503 is used to generate target code corresponding to the target code requirements based on at least one subtask and a large model.

[0285] As one possible implementation of this disclosure, the generation module 503 includes:

[0286] The `get` submodule is used to retrieve target code examples that match the target code requirements from the code example library.

[0287] The generation submodule is used to generate target code from a large model based on at least one subtask, using the target code sample as an example.

[0288] As one possible implementation of this disclosure, the generation submodule includes:

[0289] The first generation unit is used to take the target code example as an example and, based on at least one subtask, generate the code of the main function and the code of the sub-functions corresponding to at least one subtask through the large model; wherein, the sub-functions are used to implement the corresponding sub-tasks, and the main function is used to coordinate the calls of the sub-functions to realize the task processing;

[0290] The second generation unit is used to generate target code based on the code of the main function and the code of the sub-functions.

[0291] As one possible implementation of this disclosure, the target code example includes a main function example and a sub-function example; the first generation unit includes:

[0292] The first generation subunit is used to generate a first prompt word based on a main function example and at least one subtask, wherein the first prompt word is used to indicate the example that needs to be referenced when generating the code of the main function and the task to be performed by the subfunction called by the main function;

[0293] The first processing subunit is used to input the first prompt word into the large model and obtain the code of the main function;

[0294] The second generation subunit is used to generate a second prompt word based on the subfunction example and the main function, wherein the second prompt word is used to indicate the example that the code for generating the subfunction needs to refer to and the main function that calls the subfunction;

[0295] The second processing subunit is used to input the second prompt word into the large model and obtain the code for the sub-function.

[0296] As one possible implementation of this disclosure, the second generation unit includes:

[0297] The third generation subunit is used to take the target code sample as an example and generate the header file code and include file code through the large model; the header file includes the declaration of the class consisting of the main function and sub-functions, and the include file includes the libraries referenced by the main function and sub-functions;

[0298] The third processing subunit is used to concatenate the code of the main function, the code of the sub-functions, the code of the header file, and the code of the include file to obtain the target code.

[0299] As one possible implementation of this disclosure, the object code example includes a header file example and an include file example; the third generation subunit is used for:

[0300] Based on the header file example, main function, and sub-functions, a third prompt word is generated. The third prompt word is used to indicate the example that the code for generating the header file needs to refer to, as well as the main function and sub-functions that constitute the class declared in the header file.

[0301] Input the third prompt word into the large model to obtain the header file code;

[0302] Based on the included file example, main function, and sub-functions, a fourth prompt word is generated. The fourth prompt word is used to indicate the examples that the code needed to generate the included file should refer to, as well as the main functions and sub-functions that reference the libraries in the included file.

[0303] Input the fourth prompt word into the large model to obtain the code for the included file.

[0304] As one possible implementation of this disclosure, the apparatus further includes:

[0305] The detection and repair submodule is used to detect and repair problems in the target code using a large model, and obtain the executable code corresponding to the target code requirements.

[0306] As one possible implementation of this disclosure, the detection and repair submodule includes:

[0307] A compilation unit is used to compile the target code and obtain the compilation result;

[0308] The first repair unit is used to repair the target code based on the compilation problem using a large model when the compilation result indicates that there is a compilation problem in the target code, and obtain the repaired code.

[0309] Test units are used to test the fixed code in a test environment and obtain test results;

[0310] The second repair unit is used to repair the code based on the test problems when the test results indicate that there are test problems in the repaired code, and obtain executable code by using a large model.

[0311] As one possible implementation of this disclosure, the test unit includes:

[0312] Get sub-units, used to retrieve test cases from the test case library that match the requirements of the target code;

[0313] The fourth generation subunit is used to generate target test cases corresponding to the target code requirements through the large model, using test cases as examples.

[0314] The fifth generation subunit is used to generate test code corresponding to the target test cases from the large model;

[0315] The test subunit is used to test the fixed code in a test environment and obtain test results.

[0316] It should be noted that the foregoing explanation of the code generation method based on large models also applies to the code generation device based on large models in this embodiment, and will not be repeated here.

[0317] To implement the above embodiments, this disclosure also provides a target model training apparatus.

[0318] Figure 6 This is a schematic diagram of the structure 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] The 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] Training module 602 is used to train an initial large model using the first training sample to obtain a first large model. The first large model is used to perform requirement analysis on the target code requirements, obtain the data objects involved in the target code requirements, and break down the data object processing task into at least one sub-task.

[0322] The training module 602 is also used to train the first large model using the second training samples to obtain the target large model, wherein the target large model is used to generate target code corresponding to the target code requirement based on at least one subtask.

[0323] As one possible implementation of this disclosure, the first training sample includes:

[0324] The first sample prompt is used to instruct the initial large model to perform requirement analysis on the first sample code requirements, obtain the sample data objects involved in the first sample code requirements, and break down the processing task of the sample data objects into at least one first sample sub-task.

[0325] The first sample code requirement involves the expected data object and the expected sub-tasks obtained by breaking down the processing task of the expected data object.

[0326] As one possible implementation of this disclosure, the second training sample includes:

[0327] The second sample prompt is used to instruct the first main model to generate the target code corresponding to the second sample code requirement based on at least one second sample sub-task.

[0328] The second sample code requires the corresponding expected target code.

[0329] As one possible implementation of this disclosure, the training module 602 is further configured to train a target large model using a third training sample to obtain a second large model, wherein the second large model is used to detect and fix 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 fix 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 foregoing explanation of the target model training method also applies to the target model training device of this embodiment, and will not be repeated here.

[0331] According to embodiments of this disclosure, this 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 embodiments 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 may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0333] like Figure 7As shown, device 700 includes a computing unit 701, which can perform various appropriate actions and processes based on a computer program stored in ROM (Read-Only Memory) 702 or loaded from storage unit 705 into RAM (Random Access Memory) 703. RAM 703 can also store various programs and data required for the operation of device 700. The computing unit 701, ROM 702, and RAM 703 are interconnected via bus 704. I / O (Input / Output) interface 705 is also connected to bus 704.

[0334] Multiple components in device 700 are connected to I / O interface 705, including: input unit 706, such as keyboard, mouse, etc.; output unit 707, such as various types of monitors, speakers, etc.; storage unit 705, such as disk, optical disk, etc.; and communication unit 709, such as network card, modem, wireless transceiver, etc. Communication unit 709 allows device 700 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0335] The computing unit 701 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, CPUs (Central Processing Units), GPUs (Graphics Processing Units), various special-purpose AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSPs (Digital Signal Processors), and any suitable processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as code generation methods based on large models or target model training methods. For example, in some embodiments, the code generation methods based on large models or target model training methods can be implemented as computer software programs tangibly contained in a machine-readable medium, such as storage unit 705. In some embodiments, part or all of the computer program can be loaded and / or installed on device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by computing unit 701, one or more steps of the large model-based code generation method or target model training method described above can be performed. Alternatively, in other embodiments, computing unit 701 can be configured by any other suitable means (e.g., by means of firmware) to execute the large model-based code generation method or target model training method.

[0336] Various implementations of the systems and techniques described above herein can 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 implementations may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0337] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0338] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, 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 for displaying information to the user (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, 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 sound input, voice input, or tactile input).

[0340] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include LANs (Local Area Networks), WANs (Wide Area Networks), the Internet, and blockchain networks.

[0341] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service ecosystem, addressing the shortcomings of traditional physical hosts and VPS (Virtual Private Server, or simply "VPS") services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.

[0342] It's important to note that artificial intelligence (AI) is the study of enabling computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). It encompasses both hardware and software technologies. AI hardware technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, and big data processing. AI software technologies primarily include computer vision, speech recognition, natural language processing, machine learning / deep learning, big data processing, and knowledge graph technologies.

[0343] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0344] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A code generation method based on a large model, comprising: Requirements for obtaining target code; The target code requirements are analyzed using a large model to obtain the data objects involved in the target code requirements, and the processing tasks of the data objects are broken down into at least one sub-task. Obtain target code examples that match the target code requirements from the code example library, wherein the target code examples include main function examples and sub-function examples; Using the target code example as an example, based on the at least one subtask, the main function code and the sub-function code corresponding to each of the 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 calling of the sub-functions to realize the processing task; 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.

2. The method according to claim 1, wherein, The step of using the target code example 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 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 the example that needs to be referenced to generate the code of the main function and the task to be performed by the sub-function 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 example and the main function, a second prompt word is generated, wherein the second prompt word is used to indicate the example that needs to be referenced for the code that generates the sub-function and the main function that calls the sub-function; Input the second prompt word into the large model to obtain the code of the sub-function.

3. The method according to claim 1, wherein, The process of generating the target code corresponding to the target code requirement based on the code of the main function and the code of the sub-functions includes: Using the target code example as an example, the code for generating header files and include files is generated through the large model; wherein, the header file includes the declaration of the class consisting of the main function and the sub-functions, and the include file includes the libraries referenced by the main function and the sub-functions; The target code is obtained by concatenating the code of the main function, the code of the sub-function, the code of the header file, and the code of the include file.

4. The method according to claim 3, wherein, The target code example includes header file examples and include file examples; the step of using the target code example to generate the header file code and include file code through the large model includes: Based on the header file example, the main function, and the sub-functions, a third prompt word is generated, wherein the third prompt word is used to indicate the example that the code required to generate the header file needs to refer to, as well as the main function and sub-functions that constitute the 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; Based on the included file example, the main function, and the sub-function, a fourth prompt word is generated, wherein the fourth prompt word is used to indicate the example that the code required to generate the included file needs to refer to, as well as the main function and sub-function that reference the library in the included file; Input the fourth prompt word into the large model to obtain the code of the included file.

5. The method according to any one of claims 1-4, wherein, The method further includes: The target code is detected and problems are fixed using the large model to obtain the executable code corresponding to the target code requirements.

6. The method according to claim 5, wherein, The process of detecting and fixing problems in the target code using the large model to obtain the executable code corresponding to the target code requirements includes: The target code is compiled to obtain the compilation result; If the compilation result indicates that the target code has a compilation problem, the target code is repaired based on the compilation problem using the large model to obtain the repaired code; The repaired code was tested in a test environment, and the test results were obtained. If the test results indicate that the repaired code has a testing problem, the large model is used to repair the repaired code based on the testing problem to obtain the executable code.

7. The method according to claim 6, wherein, The process of testing the repaired code in a test environment and obtaining test results includes: Obtain test cases from the test case library that match the requirements of the target code; Using the test cases as examples, target test cases corresponding to the target code requirements are generated through the large model; The large model is used to generate test code corresponding to the target test cases. In the test environment, the repaired code is tested using the test code to obtain the test results.

8. A method for training a target model, comprising: Obtain a training sample set, wherein the training sample set includes a first training sample and a second training sample; The first training sample is used to train the initial large model to obtain the first large model. The first large model is used to perform requirement analysis on the target code requirements, obtain the data objects involved in the target code requirements, and split the processing task of the data objects into at least one sub-task. The first large model is trained using a second training sample to obtain a target large model. The target large model is used to obtain target code examples matching the target code requirements from a code example library. These target code examples include main function examples and sub-function examples. Using these target code examples as examples, based on the at least one sub-task, the large model generates the code for the main function and the code for the sub-functions corresponding to each of the at least one sub-task. The sub-functions are used to implement the corresponding sub-tasks, and the main function coordinates the calls to the sub-functions to achieve the processing task. Based on the code for the main function and the code for the sub-functions, target code corresponding to the target code requirements is generated.

9. The method according to claim 8, wherein, The first training samples include: The first sample prompt word is used to instruct the initial large model to perform requirement analysis on the first sample code requirement, obtain the sample data object involved in the first sample code requirement, and break down the processing task of the sample data object into at least one first sample sub-task. The first sample code requirement involves the expected data object, and the expected sub-tasks obtained by breaking down the processing task of the expected data object.

10. The method according to claim 8, wherein, The second training samples include: The second sample prompt word is used to instruct the first large model to generate the target code corresponding to the second sample code requirement based on at least one second sample sub-task. The expected target code corresponding to the second sample code requirement.

11. The method according to any one of claims 8-10, wherein, The method further includes: The target large model is trained using a third training sample to obtain a second large model. The second large model is used to detect and fix problems in the target code to obtain the executable code corresponding to the target code requirements. The third training sample includes: The third sample prompt word is used to instruct the target large model to detect and fix problems in the sample code, and obtain the corresponding executable code. The expected executable code corresponding to the sample code.

12. A code generation device based on a large model, comprising: The first acquisition module is used to acquire the target code requirements; The processing module is used to perform requirement analysis on the target code requirements through a large model, obtain the data objects involved in the target code requirements, and break down the processing task of the data objects into at least one sub-task. A generation module is used to generate target code corresponding to the target code requirement based on the at least one sub-task and the large model. The generation module includes: The acquisition submodule is used to acquire target code samples that match the target code requirements from the code sample library, wherein the target code samples include main function samples and subfunction samples; A generation submodule is used to generate the target code based on the at least one subtask and the large model, using the target code sample as an example. The generation submodule includes: The first generation unit is used to take the target code example as an example and, based on the at least one subtask, generate the code of the main function and the code of the sub-functions corresponding to the at least one subtask through the large model; wherein, the sub-functions are used to implement the corresponding sub-tasks, and the main function is used to coordinate the calls of the sub-functions to realize the processing task; The second generation unit is used to generate the target code based on the code of the main function and the code of the sub-function.

13. The apparatus according to claim 12, wherein, The first generation unit includes: The first generation subunit is configured to generate a first prompt word based on the main function example and the at least one subtask, wherein the first prompt word is configured to indicate the example that needs to be referenced to generate the code of the main function and the task to be performed by the subfunction called by the main function; The first processing subunit is used to input the first prompt word into the large model to obtain the code of the main function; The second generation subunit is used to generate a second prompt word based on the sub-function example and the main function, wherein the second prompt word is used to indicate the example that needs to be referenced for the code that generates the sub-function and the main function that calls the sub-function; The second processing subunit is used to input the second prompt word into the large model to obtain the code of the sub-function.

14. The apparatus according to claim 12, wherein, The second generation unit includes: The third generation subunit is used to generate header file code and include file code using the target code example as an example 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 libraries referenced by the main function and the sub-functions; The third processing subunit is used to concatenate the code of the main function, the code of the sub-function, the code of the header file, and the code of the include file to obtain the target code.

15. The apparatus according to claim 14, wherein, The target code sample includes header file samples and include file samples; the third generation subunit is used for: Based on the header file example, the main function, and the sub-functions, a third prompt word is generated, wherein the third prompt word is used to indicate the example that the code required to generate the header file needs to refer to, as well as the main function and sub-functions that constitute the 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; Based on the included file example, the main function, and the sub-function, a fourth prompt word is generated, wherein the fourth prompt word is used to indicate the example that the code required to generate the included file needs to refer to, as well as the main function and sub-function that reference the library in the included file; Input the fourth prompt word into the large model to obtain the code of the included file.

16. The apparatus according to any one of claims 12-15, wherein, The device further includes: The detection and repair submodule is used to detect and repair problems in the target code using the large model, and obtain the executable code corresponding to the target code requirements.

17. The apparatus according to claim 16, wherein, The detection and repair submodule includes: A compilation unit is used to compile the target code to obtain the compilation result; The first repair unit is used to repair the target code based on the compilation problem using the large model when the compilation result indicates that the target code has a compilation problem, thereby obtaining the repaired code; The testing unit is used to test the repaired code in a testing environment and obtain test results; The second repair unit is used to repair the repaired code based on the test problem using the large model when the test result indicates that the repaired code has a test problem, thereby obtaining the executable code.

18. The apparatus according to claim 17, wherein, The test unit includes: The sub-unit is used to retrieve test cases that match the target code requirements from the test case library. The fourth generation subunit is used to generate target test cases corresponding to the target code requirements through the large model, using the test cases as examples. The fifth generation subunit is used to generate the test code corresponding to the target test case through the large model; The test subunit is used to test the repaired code in the test environment using the test code, and obtain the test results.

19. A target model training device, comprising: The second acquisition module is used to acquire a training sample set, wherein the training sample set includes a first training sample and a second training sample. The training module is used to train an initial large model using the first training sample to obtain a first large model. The first large model is used to perform requirement analysis on the target code requirements, obtain the data objects involved in the target code requirements, and break down the processing task of the data objects into at least one sub-task. The training module is further configured to train the first large model using the second training samples to obtain a target large model. The target large model is used to obtain target code examples matching the target code requirements from a code example library. These target code examples include main function examples and sub-function examples. Using the target code examples as examples, based on the at least one sub-task, the large model generates the code for the main function and the code for the sub-functions corresponding to each of the at least one sub-task. The sub-functions are used to implement the corresponding sub-tasks, and the main function is used to coordinate the calls to the sub-functions to achieve the processing task. Based on the code for the main function and the code for the sub-functions, target code corresponding to the target code requirements is generated.

20. The apparatus according to claim 19, wherein, The first training samples include: The first sample prompt word is used to instruct the initial large model to perform requirement analysis on the first sample code requirement, obtain the sample data object involved in the first sample code requirement, and break down the processing task of the sample data object into at least one first sample sub-task. The first sample code requirement involves the expected data object, and the expected sub-tasks obtained by breaking down the processing task of the expected data object.

21. The apparatus according to claim 19, wherein, The second training samples include: The second sample prompt word is used to instruct the first large model to generate the target code corresponding to the second sample code requirement based on at least one second sample sub-task. The expected target code corresponding to the second sample code requirement.

22. The apparatus according to any one of claims 19-21, wherein, The training module is further configured to train the target large model using a third training sample to obtain a second large model, wherein the second large model is used to detect and fix 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 fix problems in the sample code to obtain the corresponding executable code; and the expected executable code corresponding to the sample code.

23. 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, which, when executed by the at least one processor, enables the at least one processor to perform the method of any one of claims 1-7, or the method of any one of claims 8-11.

24. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method of any one of claims 1-7, or to perform the method of any one of claims 8-11.

25. A computer program product comprising a computer program that, when executed by a processor, implements the method of any one of claims 1-7, or the method of any one of claims 8-11.

Citation Information

Patent Citations

  • Code generation method and system based on large model, terminal and medium

    CN118113271A

  • Task execution method and device based on large model

    CN118519680A