Training code generation method, device, terminal and computer-readable storage medium
By performing code screening and task prediction on the target code database, the training code generation prompt words are constructed and high-quality target training code is generated, which solves the problem of insufficient code data quality in the training of the code generation large model and improves the code generation effect.
Patent Information
- Application Number
- CN202411774767.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-04
AI Technical Summary
During the training process, a large number of high-quality code data is required for a large number of code data, and the quality of conventional code data is uneven, which limits the code generation effect.
By performing code screening on the target code database, the target complete code and its key code snippets are determined, task prediction processing is performed for the key code snippets, training code generation prompt words are constructed, and reference training code is generated through the target code completion model to finally determine the high-quality target training code.
It ensures the high quality of the target training code, expands the application scenarios of key code snippets, solves the problem of insufficient code data quality in code generation large model training, and improves the code generation effect.
Smart Images

Figure CN119249156B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a training code generation method, device, terminal and computer-readable storage medium. Background Art
[0002] With the rapid development of artificial intelligence, code generation big models have gradually become an important tool for code generation. Code generation big models can automatically generate corresponding code based on input prompts, thereby helping developers improve development efficiency and code quality. However, the training of code generation big models requires a large amount of high-quality code data. Conventional code data often has uneven quality, which limits the code generation effect of code generation big models. Summary of the invention
[0003] The embodiments of the present application provide a training code generation method, device, terminal and computer-readable storage medium, which can solve the technical problem that the training of a large code generation model requires a large amount of high-quality code data, and the quality of conventional code data is often uneven, which limits the code generation effect of the large code generation model.
[0004] In a first aspect, an embodiment of the present application provides a training code generation method, the method comprising:
[0005] Perform code screening on the target code database to obtain a target complete code, and determine a key code fragment corresponding to the target complete code;
[0006] Performing task prediction processing on the key code snippet to obtain at least one target task, and constructing a training code generation prompt word based on the key code snippet and the target task;
[0007] At least two reference training codes for generating prompt words for the training code are generated by a target code completion model, and the reference training codes are run for the target task to determine a target training code from the reference training codes.
[0008] Optionally, the code screening process on the target code database to obtain the target complete code includes:
[0009] Determine source code from a target code database, perform type checking on the source code to obtain a type checking result, and use the type checking result to perform code screening on the source code to obtain an initial code;
[0010] A code integrity check is performed on the initial code to obtain an integrity check result, the initial code whose integrity check result is a code integrity type is used as a complete code, and a code deduplication process is performed on the complete code to obtain a target complete code.
[0011] Optionally, the key code snippet is reusable; and determining the key code snippet corresponding to the target complete code includes:
[0012] Performing business logic code snippet extraction processing on the target complete code to obtain a business logic code snippet, and using the business logic code snippet as a key code snippet; and / or,
[0013] A decision code fragment extraction process is performed on the target complete code to obtain a decision code fragment, and the decision code fragment is used as a key code fragment.
[0014] Optionally, performing task prediction processing on the key code snippet to obtain at least one target task includes:
[0015] Acquire a pre-established task database, the task database comprising a reference task and at least one task execution logic feature associated with the reference task, the task execution logic feature comprising a plurality of reference logic features;
[0016] Determine the code logic feature corresponding to the key code snippet, and use the code logic feature to perform feature matching processing on the reference logic feature in the task database to obtain the target logic feature matched by the code logic feature;
[0017] At least one target task execution logic feature corresponding to the target logic feature is determined from the task execution logic features, and a reference task corresponding to the at least one target task execution logic feature is used as a target task.
[0018] Optionally, constructing the training code based on the key code snippet and the target task to generate prompt words includes:
[0019] Determine the task content of the target task, and generate a task description corresponding to the target task based on the task content;
[0020] Performing description association processing on the task description and the key code snippet to obtain a target task description;
[0021] A training code generation prompt word template is obtained, and description editing processing is performed on the training code generation prompt word template based on the target task description to obtain a training code generation prompt word.
[0022] Optionally, the running the reference training code for the target task to determine the target training code from the reference training code includes:
[0023] Running the reference training code for the target task to determine code running information, and determining a task completion degree of the reference training code for the target task based on the code running information;
[0024] The target training code is determined from the reference training code using the task completion degree.
[0025] Optionally, the method further comprises:
[0026] Obtain target training codes corresponding to multiple target tasks, and determine task completion sample labels corresponding to the target training codes through the target tasks;
[0027] Controlling the initial code generation model to generate a reference code corresponding to the target task, and determining a task completion reference tag of the reference code through the target task;
[0028] The model loss value is determined using the task completion sample labels and task completion reference labels corresponding to the same target task, and the model loss value is used to adjust the model parameters of the initial code generation model until the initial code generation model completes model training to obtain the target code generation model.
[0029] In a second aspect, an embodiment of the present application provides a training code generation device, the device comprising:
[0030] A generation module, adapted to perform code screening processing on a target code database to obtain a target complete code, and determine a key code fragment corresponding to the target complete code;
[0031] A construction module, adapted to perform task prediction processing on the key code snippet to obtain at least one target task, and construct a training code generation prompt word based on the key code snippet and the target task;
[0032] The training code generation module is adapted to generate at least two reference training codes for generating prompt words for the training code through a target code completion model, and to run the reference training codes for the target task to determine a target training code from the reference training codes.
[0033] In a third aspect, an embodiment of the present application provides a terminal, the terminal comprising:
[0034] Processor; and
[0035] A memory arranged to store computer executable instructions which, when executed, cause the processor to perform a method according to any one of the above.
[0036] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores one or more programs, and when the one or more programs are executed by a processor, implement any of the methods described above.
[0037] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least: obtaining the target complete code by performing code screening processing on the target code database, thereby ensuring the code quality of the target complete code. At the same time, since the target complete code can run independently without the need for additional code, the target complete code can independently implement at least one function, and then the key code fragment corresponding to the target complete code can play a role in the functional code corresponding to at least one function, that is, the key code fragment has a real application scenario. Since the code quality of the target complete code is effectively guaranteed, the code quality of the key code fragment in the target complete code is also guaranteed.
[0038] Afterwards, task prediction processing is performed on the key code snippet to obtain at least one target task, thereby determining one or more target tasks to which the key code snippet can be applied, so that the application scenarios of the key code snippet can be divergently expanded. Then, the key code snippet and the target task are used to construct a training code generation prompt word, thereby controlling the target code completion model to generate at least two reference training codes. In order to ensure the code quality of the target training code finally obtained, the reference training code is run for the target task, and the target training code is screened out by the running performance of the reference training code, so that each key code snippet can be used to expand at least one high-quality target training code corresponding to the target task, thereby solving the technical problem that the training of the large code generation model requires a large amount of high-quality code data, and the conventional code data is often of uneven quality, which limits the code generation effect of the large code generation model. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0040] Figure 1 An exemplary system architecture diagram of a training code generation method provided in an embodiment of the present application;
[0041] Figure 2 A flowchart of a training code generation method provided in an embodiment of the present application;
[0042] Figure 3 A schematic diagram of a process for determining a target training code provided in an embodiment of the present application;
[0043] Figure 4 A schematic diagram of a process for model training using target training code provided in an embodiment of the present application;
[0044] Figure 5 A schematic diagram of another process for determining a target training code provided in an embodiment of the present application;
[0045] Figure 6 A schematic diagram of another process of performing model training using target training code provided in an embodiment of the present application;
[0046] Figure 7 A schematic diagram of a process for determining a target complete code provided in an embodiment of the present application;
[0047] Figure 8 A schematic diagram of a process flow for performing task prediction processing provided in an embodiment of the present application;
[0048] Fig. 9 A schematic diagram of a flow chart of constructing a training code to generate prompt words provided in an embodiment of the present application;
[0049] Fig.10 A schematic diagram of the structure of a training code generation device provided in an embodiment of the present application;
[0050] Fig.11 A schematic diagram of the structure of a terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] In order to make the features and advantages of the embodiments of the present application more obvious and easy to understand, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of them. Based on the embodiments in the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the embodiments of the present application.
[0052] In related technologies, with the continuous development of artificial intelligence and machine learning technologies, LLM (Large Language Model) has become an important tool for code generation and understanding. These large code generation models can automatically generate high-quality code based on user input prompts, thereby helping developers improve development efficiency and code quality.
[0053] However, the training of these models often requires a large amount of high-quality code data. At the same time, due to the complexity and diversity of the code, obtaining high-quality code data becomes a difficult and time-consuming task. In addition, conventional code data is often small in scale and of varying quality, which limits the model's learning ability and code generation effect, making it difficult for traditional code data collection methods to meet the needs of model training.
[0054] In order to solve the related technical problems, an embodiment of the present application provides a training code generation method, which includes: performing code screening processing on a target code database to obtain a target complete code, and determining a key code snippet corresponding to the target complete code; performing task prediction processing on the key code snippet to obtain at least one target task, and constructing a training code generation prompt word based on the key code snippet and the target task; generating at least two reference training codes for the training code generation prompt word through a target code completion model, and running the reference training code for the target task to determine the target training code from the reference training code, thereby solving the technical problem that the training of a large code generation model requires a large amount of high-quality code data, and conventional code data often has uneven quality, which limits the code generation effect of the large code generation model.
[0055] See also Figure 1 , Figure 1 An exemplary system architecture diagram of a training code generation method provided in an embodiment of the present application.
[0056] like Figure 1 As shown, the system architecture may include a terminal 101, a network 102, and a server 103. The network 102 is used to provide a medium for a communication link between the terminal 101 and the server 103. The network 102 may include various types of wired communication links or wireless communication links, for example, the wired communication link includes an optical fiber, a twisted pair, or a coaxial cable, and the wireless communication link includes a Bluetooth communication link, a Wireless-Fidelity (Wi-Fi) communication link, or a microwave communication link.
[0057] The terminal 101 can interact with the server 103 through the network 102 to receive messages from the server 103 or send messages to the server 103, or the terminal 101 can interact with the server 103 through the network 102 to receive messages or data sent by other users to the server 103. The terminal 101 can be hardware or software. When the terminal 101 is hardware, it can be various terminals, including but not limited to smart watches, smart phones, tablet computers, laptop portable computers and desktop computers. When the terminal 101 is software, it can be installed in the terminals listed above, which can be implemented as multiple software or software modules (for example: used to provide distributed services), or it can be implemented as a single software or software module, which is not specifically limited here.
[0058] The server 103 may be a business server that provides various services. It should be noted that the server 103 may be hardware or software. When the server 103 is hardware, it may be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the server 103 is software, it may be implemented as multiple software or software modules (for example, for providing distributed services), or as a single software or software module, which is not specifically limited here.
[0059] In an embodiment of the present application, terminal 101 can perform code screening processing on the target code database to obtain the target complete code, and determine the key code fragment corresponding to the target complete code; then, perform task prediction processing on the key code fragment to obtain at least one target task, and construct a training code generation prompt word based on the key code fragment and the target task; finally, generate at least two reference training codes for the training code generation prompt word through the target code completion model, and run the reference training code for the target task to determine the target training code from the reference training code.
[0060] It should be understood that Figure 1 The number of terminals, networks and servers in the example is only illustrative, and any number of terminals, networks and servers may be used according to implementation requirements. Of course, the server may not be included in the embodiment provided in the present application.
[0061] See also Figure 2 , Figure 2 A flowchart of a training code generation method provided in an embodiment of the present application. The execution subject of the embodiment of the present application can be a terminal that executes the training code generation method, or a processor in the terminal that executes the training code generation method, or a training code generation service in the terminal that executes the training code generation method. For the convenience of description, the specific execution process of the training code generation method is introduced below by taking the execution subject as the processor in the terminal as an example.
[0062] like Figure 2 As shown, the training code generation method includes:
[0063] S202: Perform code screening processing on the target code database to obtain a target complete code, and determine a key code fragment corresponding to the target complete code.
[0064] Among them, the target code database includes a large amount of source code, and the source code can be crawled from various target open source databases on the Internet based on a crawler, and the source code is crawled and stored in the target code database. These target open source databases can be databases whose data is verified to be safe. In the target code database, not all source codes are valid codes that meet the preset requirements of the code. Therefore, it is necessary to perform code screening on the source code in the target code database to obtain a valid target complete code. Here, the target complete code can run independently without additional code.
[0065] On the one hand, code screening is used to screen out source code in the target code database where the types of variables, expressions, and operators match during code execution. For example, check whether the types of variables, expressions (code fragments consisting of variables and operators), and operators (such as plus sign "+", equal to "==") are compatible with each other. If an operator requires that the operands corresponding to the two variables are both integer types, type checking will ensure that integers are passed to the variables, rather than strings or other types of data, thereby avoiding type errors at runtime and improving the stability and reliability of the program.
[0066] On the other hand, the code screening process can also be used to screen out source codes in the target code database whose security meets the preset security requirements. Specifically, during the code screening process, the source codes in the target code database can be subjected to at least one of security audit, legal compliance review, security license review, source code feasibility verification, signature verification and checksum verification, and filtering of malicious code sources to ensure the data security of the source codes.
[0067] Among them, security audit of source code includes but is not limited to code vulnerability review of source code in the target code database. For example, static code analysis of source code can be used in static code analysis to identify potential code defects and security vulnerabilities. For another example, manual code review of source code can be performed, with reviewers checking the code line by line to find problems that may be missed by automated tools, such as logical errors, unsafe API (Application Programming Interface) usage, etc., so as to eliminate source code that fails the security audit and ensure that the screened source code meets the requirements of the security audit.
[0068] The legal compliance review of the source code is used to ensure the compliance and security of the selected source code. The security license review of the source code is used to ensure that the components, libraries, etc. used in the selected source code have obtained the necessary security licenses. Verifying the feasibility of the source code includes but is not limited to functional testing and non-functional testing of the source code. Functional testing is used to verify whether the source code can run as expected, and non-functional testing is used to verify whether the source code can meet non-functional requirements such as scalability and maintainability. Feasibility verification of the source code is used to ensure that the selected source code meets the requirements of functional testing and non-functional testing, that is, the selected source code can run as expected and has scalability and maintainability. Signature verification and verification verification of the source code are used to ensure the integrity and security source of the selected source code. The signature corresponding to the source code is closely associated with the source code and is used to verify whether the source code has been tampered with during transmission or storage. When the integrity and source of the source code need to be verified, the signature can be verified. Filtering malicious code sources is used to identify and filter out malicious source code, such as worms and Trojans.
[0069] On the other hand, the code screening process is also used to perform data preprocessing on the source code in the target code database. Specifically, the data preprocessing includes at least one of syntax filtering, compilation filtering, language filtering, format filtering, heat filtering, length filtering, duplicate data removal, and sensitive data processing.
[0070] The syntax filtering of the source code in the target code database is used to check and filter out the source code that does not conform to the preset syntax rules, thereby improving the code quality of the source code that has not been filtered out. The compilation filtering of the source code in the target code database is used to filter out the source code that does not conform to the syntax rules, has logical errors, and has security issues during the code compilation process. The compilation filtering of the source code in the target code database is also used to improve the code quality of the source code that has not been filtered out. The language filtering of the source code in the target code database is used to filter the source code using the preset language rules, thereby improving the code quality and readability of the source code that has not been filtered out. The format filtering of the source code in the target code database is used to filter the source code using the preset formatting rules, thereby improving the readability, format consistency, and maintainability of the source code that has not been filtered out.
[0071] The heat filtering of the source code in the target code database is used to filter out the source code with a low heat index value based on the heat index of each source code. The heat index includes but is not limited to the number of times the source code is called, the modification frequency of the source code, the number of source code contributors, etc. It is easy to understand that the higher the number of times the source code is called, the more the modification frequency of the source code, and the more the number of source code contributors, the higher the heat index value of the source code. The length filtering of the source code in the target code database is used to filter out source code with a length greater than a first preset length or a length less than a second preset length. The first preset length is greater than the second preset length. The source code with a length greater than the first preset length means that the readability and maintainability of the code are low, and the source code with a length less than the second preset length indicates that the code is just a simple auxiliary function. Deduplication of the source code in the target code database is used to deduplicate the source code to improve the maintainability and readability of the code and reduce potential errors. Sensitive data processing of the source code in the target code database is used to desensitize the source code in the target code database.
[0072] In other aspects, the code screening process is also used to perform content control on the source code in the target code database, which includes user feedback, manual intervention, risk assessment, input constraints, LLM supervision alignment and scenario design.
[0073] Among them, user feedback, manual intervention and risk assessment can be operated by content control personnel to control the code content. Input constraints on the source code in the target code database are used to ensure that the data input of the source code can be correctly processed by the source code, thereby avoiding operation failure during the source code operation. LLM supervision alignment of the source code in the target code database is used to make the source code in the target code database conform to programming specifications and be easy to understand and maintain. Scenario design of the source code in the target code database is used to evaluate the scenarios in which the source code may be applied.
[0074] In another aspect, the code screening process is also used to perform accuracy assessment on the source code in the target code database, and the accuracy assessment includes at least one of open source testing, functional verification, automated testing, comparison with actual requirements, code review and expert evaluation, thereby filtering out source code that does not meet the accuracy standard.
[0075] After the target code database is subjected to code screening, the corresponding target complete code can be obtained. The number of target complete codes can be one or more. The target complete code has been subjected to code screening, so that the code quality of the target complete code has been greatly optimized. At the same time, since the target complete code can independently implement at least one function, that is, the key code fragment corresponding to the target complete code can play a role in the functional code corresponding to at least one function. Therefore, there are real application scenarios for the key code fragments, and since the code quality of the target complete code has been greatly optimized, the code quality of the key code fragments in the target complete code is also high.
[0076] Each target complete code can correspond to one or more key code snippets. The key code snippet can be understood as the core snippet in the target complete code, that is, the code snippet that has a significant positive impact on the corresponding function, performance or security of the target complete code.
[0077] Exemplarily, the key code snippet corresponding to the target complete code can be determined by extracting the target complete code using a key code snippet extraction model. The key code snippet extraction model can be an initial key code snippet extraction model obtained by training the sample complete code and the sample key code snippet corresponding to the sample complete code.
[0078] S204: performing task prediction processing on the key code snippet to obtain at least one target task, and constructing a training code generation prompt word based on the key code snippet and the target task.
[0079] After the key code snippet is determined, task prediction processing is performed on the key code snippet to predict codes corresponding to tasks to which the key code can be applied, and then one or more target tasks corresponding to the key code snippet are predicted.
[0080] Exemplarily, the code running logic corresponding to the key code snippet can be used to predict the code corresponding to the task to which it can be applied. The implementation of each task usually needs to rely on one or more code running logics. Therefore, the code running logic corresponding to the key code snippet and the code running logic that the task implementation depends on can be matched to determine at least one target task corresponding to the key code snippet. Here, the code running logic includes the sequential execution, conditional judgment, loop control, function call, etc. of the corresponding code when the code is executed. The target task is a task that can be executed based on the code, and the code corresponding to the target task includes the key code snippet.
[0081] After determining at least one target task corresponding to the key code snippet, a training code generation prompt is constructed using the key code snippet and the target task. The training code generation prompt is used to instruct the target code completion model to complete the key code snippet to obtain at least two reference training codes, and the reference training codes are used to complete the target task.
[0082] S206: Generate at least two reference training codes for training code generation prompt words through the target code completion model, and run the reference training codes for the target task to determine the target training code from the reference training codes.
[0083] The target code completion model is used to perform corresponding code completion using the input training code generation prompt words. First, the training code generation prompt words are input into the target code completion model. After receiving the training code generation prompt words, the target code completion model completes the key code fragments based on the instructions of the training code generation prompt words, thereby obtaining at least two reference training codes for completing the target task. After that, the target code completion model outputs at least two reference training codes.
[0084] Different reference training codes may be codes generated by the target code completion model based on different task implementation paths. Therefore, different reference training codes may have different running performances for target tasks.
[0085] The running performance includes but is not limited to task completion, task completion accuracy, etc. Different reference training codes may have different task completions for the target task. The reference training code can be run for the target task to determine the task completion of each reference training code. The task completion can be understood as the workload completion ratio of the reference training code for the target task. Similarly, different reference training codes may have different task completion accuracy for the target task. The reference training code can be run for the target task to determine the task completion accuracy of each reference training code. The target training code determined from the reference training code can be used to train the initial code generation model.
[0086] Exemplarily, when the operation is performed as task completion, the target task can be split into multiple subtasks, and the subtasks completed by the reference training code can be determined after running the reference training code. Afterwards, the workload completion ratio of the reference training code for the target task is determined by using the ratio of the subtasks completed by the reference training code to the total subtasks corresponding to the target task. Then, the preset task completion can be used to screen the completion of each task, and the reference training code with a task completion greater than or equal to the preset task completion can be used as the target training code. For example, the preset task completion can be 99.9%. Of course, the preset task completion can also be flexibly set based on user needs. In addition, the reference training code with the highest task completion can be selected from the task completion corresponding to each reference training code as the target training code.
[0087] Exemplarily, when the operation is performed as task completion accuracy, the standard code operation result of the target task can be determined. Then, the reference task result is determined using the operation result of the reference training code, and the task completion accuracy of the reference training code is calculated based on the code operation result and the standard code operation result. Then, the preset task completion accuracy is used to screen the task completion accuracy of each task, and the reference training code with a task completion accuracy greater than or equal to the preset task completion accuracy is used as the target training code. For example, the preset task completion accuracy can be 99.9%. Of course, the preset task completion accuracy can also be flexibly set based on user needs. It is also possible to select the reference training code with the highest task completion accuracy from the task completion accuracy corresponding to each reference training code as the target training code.
[0088] In addition, multiple code quality assessment models can be used to vote on each reference training code, and the reference training code with the highest number of votes is retained as the target training code.
[0089] In the embodiments provided by the present application, the target complete code is obtained by performing code screening on the target code database, thereby ensuring the code quality of the target complete code. At the same time, since the target complete code can run independently without additional code, the target complete code can independently implement at least one function, and then the key code fragment corresponding to the target complete code can play a role in the functional code corresponding to at least one function, that is, the key code fragment has a real application scenario. Since the code quality of the target complete code is effectively guaranteed, the code quality of the key code fragment in the target complete code is also guaranteed.
[0090] Afterwards, task prediction processing is performed on the key code snippet to obtain at least one target task, thereby determining one or more target tasks to which the key code snippet can be applied, so that the application scenarios of the key code snippet can be divergently expanded. Then, the key code snippet and the target task are used to construct a training code generation prompt word, thereby controlling the target code completion model to generate at least two reference training codes. In order to ensure the code quality of the target training code finally obtained, the reference training code is run for the target task, and the target training code is screened out by the running performance of the reference training code, so that each key code snippet can be used to expand at least one high-quality target training code corresponding to the target task, thereby solving the technical problem that the training of the large code generation model requires a large amount of high-quality code data, and the conventional code data is often of uneven quality, which limits the code generation effect of the large code generation model.
[0091] See also Figure 3 , Figure 3 A flow chart of determining a target training code provided in an embodiment of the present application. Figure 3 As shown, in S206, running the reference training code for the target task to determine the target training code from the reference training code includes:
[0092] S302: Run the reference training code for the target task to determine code running information, and determine the task completion degree of the reference training code for the target task based on the code running information.
[0093] The reference training code is run for the target task to obtain code running information of the reference training code, the code running information including completion information of subtasks completed by the reference training code for the target task. After determining the code running information, the number of subtasks in the target task completed by the reference training code and the total number of subtasks in the target task are used to determine the task completion degree of the reference training code for the target task.
[0094] Exemplarily, the number of subtasks in the target task completed by the reference training code is 99, and the total number of subtasks in the target task is 100, then the task completion degree of the reference training code for the target task is 99%.
[0095] S304: Determine a target training code from reference training codes using the task completion degree.
[0096] Among them, after determining the task completion degree of each reference training code, the preset task completion degree can be used to screen the task completion degrees of each reference training code, and the reference training code with a task completion degree greater than or equal to the preset task completion degree can be used as the target training code. In addition, the reference training code with the highest task completion degree can be selected from the task completion degrees corresponding to each reference training code as the target training code.
[0097] In the embodiment provided in the present application, target training codes are screened out from the reference training codes according to the task completion degree of each reference training code, and then target training codes whose code quality meets the requirements are selected from the reference training codes.
[0098] See also Figure 4 , Figure 4 A flow chart of a method for model training using target training code is provided in an embodiment of the present application. Figure 4 As shown, the method includes:
[0099] S402: Obtain target training codes corresponding to multiple target tasks, and determine task completion sample labels corresponding to the target training codes through the target tasks.
[0100] Among them, each target task can correspond to one or more target training codes, and the target training codes corresponding to multiple target tasks are collected. Then, the task completion degree of the target training code corresponding to the target task is determined through the target task, and the task completion degree sample label of the target training code is determined based on the task completion degree of each target training code.
[0101] Exemplarily, after determining the task completion degree of each target training code, the task completion degree value of each target training code can be used as the task completion degree sample label corresponding to the target training code. For example, if the task completion degree of the target training code is 99.95%, then the task completion degree sample label corresponding to the target training code is also 99.95%.
[0102] S404: Control the initial code generation model to generate a reference code corresponding to the target task, and determine a task completion reference label of the reference code through the target task.
[0103] Among them, first determine the task content corresponding to the target task, then generate the target task code generation prompt word corresponding to the target task based on the task content, then input the target task code generation prompt word into the initial code generation large model, and then control the initial code generation large model to generate the reference code corresponding to the target task. After determining the reference code, similarly, determine the task completion degree of the reference code through the target task, and determine the task completion degree reference label of the reference code based on the task completion degree of the reference code.
[0104] Exemplarily, after determining the task completion of the reference code, the task completion value of the reference code can be used as the task completion reference label corresponding to the reference code. For example, if the task completion of the reference code is 69%, then the task completion reference label corresponding to the reference code is also 69%.
[0105] S406: Determine the model loss value using the task completion sample labels and task completion reference labels corresponding to the same target task, and use the model loss value to adjust the model parameters of the initial code generation model until the initial code generation model completes model training to obtain the target code generation model.
[0106] Among them, the task completion sample labels and task completion reference labels corresponding to the same target task are determined, and the model loss function is constructed using the task completion sample labels and the task completion reference labels. Then, the numerical values corresponding to the task completion sample labels and the task completion reference labels are substituted into the model loss function to calculate the model loss value. After determining the model loss value, the model loss value is used to adjust the model parameters of the initial code generation large model, and the initial code generation large model is trained through a large number of target training codes until the initial code generation large model completes the model training to obtain the target code generation large model.
[0107] In the embodiments provided in the present application, the target training code generated by the key code snippets is used to perform model training on the initial code generation model, thereby providing a large amount of high-quality code data for the initial code generation model, thereby improving the code generation effect of the target code generation model trained by the target training code.
[0108] See also Figure 5 , Figure 5 Another flow chart of determining a target training code is provided in an embodiment of the present application. Figure 5 As shown, in S206, running the reference training code for the target task to determine the target training code from the reference training code includes:
[0109] S502: Run the reference training code for the target task to determine the code running result, and determine the task completion accuracy of the reference training code for the target task based on the code running result.
[0110] The reference training code is run for the target task to obtain the code running result of the reference training code, which includes the output result of the reference training code for the target task. After determining the code running result, the standard code running result of the target task is determined. The code running result of the reference training code is then used to determine the reference task result, and the task completion accuracy of the reference training code is calculated based on the code running result and the standard code running result.
[0111] Exemplarily, the result similarity between the code running result of the reference training code and the standard code running result of the target task may be calculated, and the task completion accuracy of the reference training code may be determined based on the result similarity.
[0112] S504: Determine a target training code from reference training codes using the task completion accuracy.
[0113] Among them, after determining the task completion accuracy of each reference training code, the preset task completion accuracy can be used to screen the task completion accuracy of each reference training code, and the reference training code with a task completion accuracy greater than or equal to the preset task completion accuracy can be used as the target training code. In addition, the reference training code with the highest task completion accuracy can be selected from the task completion accuracy corresponding to each reference training code as the target training code.
[0114] In the embodiment provided in the present application, target training codes are screened out from the reference training codes according to the task completion accuracy of each reference training code, and then target training codes whose code quality meets the requirements are selected from the reference training codes.
[0115] See also Figure 6 , Figure 6 Another flow chart of using target training code to perform model training is provided in the embodiment of the present application. Figure 6 As shown, the method includes:
[0116] S602: Obtain target training codes corresponding to multiple target tasks, and determine task completion accuracy sample labels corresponding to the target training codes through the target tasks.
[0117] Among them, each target task can correspond to one or more target training codes, and the target training codes corresponding to multiple target tasks are collected. Then, the task completion accuracy of the target training code corresponding to the target task is determined through the target task, and the task completion accuracy sample label of the target training code is determined based on the task completion accuracy of each target training code.
[0118] Exemplarily, after determining the task completion accuracy of each target training code, the task completion accuracy value of each target training code can be used as the task completion accuracy sample label corresponding to the target training code. For example, if the task completion accuracy of the target training code is 99.95%, then the task completion accuracy sample label corresponding to the target training code is also 99.95%.
[0119] S604: Control the initial code generation model to generate a reference code corresponding to the target task, and determine a reference label of the task completion accuracy of the reference code through the target task.
[0120] Among them, first determine the task content corresponding to the target task, then generate the target task code generation prompt word corresponding to the target task based on the task content, then input the target task code generation prompt word into the initial code generation large model, and then control the initial code generation large model to generate the reference code corresponding to the target task, after determining the reference code. Similarly, the task completion accuracy of the reference code can be determined by the target task, and the task completion accuracy reference label of the reference code can be determined based on the task completion accuracy of the reference code.
[0121] Exemplarily, after determining the task completion accuracy of the reference code, the task completion accuracy value of the reference code can be used as the task completion accuracy reference label corresponding to the reference code. For example, if the task completion accuracy of the reference code is 59%, then the task completion accuracy reference label corresponding to the reference code is also 59%.
[0122] S606: Determine the model loss value using the task completion accuracy sample labels and task completion accuracy reference labels corresponding to the same target task, and use the model loss value to adjust the model parameters of the initial code generation large model until the initial code generation large model completes model training to obtain the target code generation large model.
[0123] Among them, the task completion accuracy sample labels and task completion accuracy reference labels corresponding to the same target task are determined, and the model loss function is constructed using the task completion accuracy sample labels and the task completion accuracy reference labels. After that, the numerical values corresponding to the task completion accuracy sample labels and the task completion accuracy reference labels are substituted into the model loss function to calculate the model loss value. After determining the model loss value, the model loss value is used to adjust the model parameters of the initial code generation large model, and the initial code generation large model is trained through a large batch of target training codes until the initial code generation large model completes the model training to obtain the target code generation large model.
[0124] In the embodiment provided in the present application, the target training code generated by the key code snippets is used to perform model training on the initial code generation model, thereby providing a large amount of high-quality code data for the initial code generation model, thereby improving the code generation effect of the trained target code generation model.
[0125] See also Figure 7 , Figure 7 A schematic diagram of a process for determining a target complete code provided in an embodiment of the present application. Figure 7 As shown, in S202, the target code database is screened to obtain the target complete code, including:
[0126] S702: Determine source code from the target code database, perform type checking on the source code to obtain a type checking result, and use the type checking result to perform code screening on the source code to obtain an initial code.
[0127] Among them, the target code database includes multiple source codes, and the source codes in the target code database are subjected to type checking processing to obtain the type checking results of each source data. The type checking processing is used to check whether the types of variables, expressions and operators in the source code match during code execution, so as to capture potential type errors and runtime errors in the code.
[0128] When the type check result corresponding to the source code is a normal type check, that is, the types of variables, expressions and operators in the source code match during code execution, the source code corresponding to the normal type check is used as the initial code; when the type check result corresponding to the source code is a type check exception, that is, the types of variables, expressions and operators in the source code do not match during code execution, the source code corresponding to the type check exception is eliminated.
[0129] S704: Perform code integrity check on the initial code to obtain an integrity check result, take the initial code whose integrity check result is a code integrity type as the complete code, and perform code deduplication processing on the complete code to obtain a target complete code.
[0130] Among them, the integrity detection model can be used to perform code integrity detection on the initial code, so as to determine the integrity detection result corresponding to the initial code. When the initial code can run independently and does not rely on external code, and can realize at least one function, the integrity detection result corresponding to the initial code is determined to be a code complete type; otherwise, the integrity detection result corresponding to the initial code is an incomplete code type. Afterwards, the initial code with an integrity detection result of a code complete type is regarded as a complete code.
[0131] After the complete code is determined, the complete code is deduplicated, thereby filtering out unnecessary repeated code fragments in the complete code, thereby improving the code quality of the complete code, and thus obtaining the target complete code.
[0132] In the embodiments provided in the present application, the source code is screened using the type checking result to obtain the initial code, thereby eliminating the source code with potential type errors and runtime errors. The initial code is then subjected to code integrity checking to obtain the integrity checking result. The integrity checking result is used to determine the complete code that can run independently and does not rely on external code and can implement at least one function. Finally, the complete code is deduplicated to obtain the target complete code. Since the target complete code can independently implement at least one function, the key code snippet corresponding to the target complete code can play a role in the functional code corresponding to at least one function, that is, the key code snippet has a real application scenario.
[0133] In one embodiment provided in the present application, the key code snippet is reusable. Reusability can be understood as the key code snippet can be reused in different task codes without a lot of modification or rewriting. The key code snippet can include at least one of a business logic code snippet and a decision code snippet. The key code snippet corresponding to the target complete code is determined in S202, including:
[0134] Extracting business logic code snippets from the target complete code to obtain business logic code snippets, and using the business logic code snippets as key code snippets; and / or,
[0135] The target complete code is subjected to decision code fragment extraction processing to obtain the decision code fragment, and the decision code fragment is used as the key code fragment.
[0136] The business logic code snippet extraction process is used to extract the code snippet corresponding to the service layer or business logic layer in the target complete code. Specifically, the business logic code snippet can be a code snippet that executes business rules, processes business data, and interacts with business data to complete business tasks.
[0137] The business logic code snippet may be a code snippet for making decisions in the target complete code, and the decision code snippet extraction process is used to extract code snippets for making decisions such as condition judgment, loop control, and function call in the target complete code.
[0138] In the embodiments provided in the present application, the business logic code snippet and the decision code snippet can be understood as the core code in the target complete code. Therefore, taking the core code in the target complete code as the key code snippet can effectively ensure the code quality of the key code snippet and ensure that the key code snippet can play a more active role in the target training code generated subsequently, rather than existing as invalid code in the target training code.
[0139] See also Figure 8 , Figure 8A flowchart of a task prediction process provided by an embodiment of the present application. Figure 8 As shown, in S204, task prediction processing is performed on the key code fragment to obtain at least one target task, including:
[0140] S802: Acquire a pre-established task database, where the task database includes a reference task and at least one task execution logic feature associated with the reference task, where the task execution logic feature includes a plurality of reference logic features.
[0141] In order to establish a task database, multiple reference tasks can be obtained, and the reference tasks are tasks that can be implemented based on the code. After determining the reference task, at least one task execution logic for completing the reference task is determined based on the task content corresponding to the reference task. Afterwards, a task execution logic feature for characterizing the task execution logic is generated based on the task execution logic, so that the reference task is associated with the task execution logic feature.
[0142] The task execution logic feature may include multiple reference logic features, and the task execution logic feature may be represented by a reference logic feature flow chart. Exemplarily, the task execution logic feature A may include reference logic feature a, reference logic feature b, and reference logic feature c, and the task execution logic feature A may be represented by a reference logic feature flow chart as reference logic feature a→reference logic feature b→reference logic feature c. That is, after executing the logic corresponding to reference logic feature a, the logic corresponding to reference logic feature b is executed, and then the logic corresponding to reference logic feature c is executed.
[0143] S804: Determine the code logic features corresponding to the key code snippets, and use the code logic features to perform feature matching processing on the reference logic features in the task database to obtain target logic features for matching the code logic features.
[0144] The code logic information of the key code snippet is extracted, and then the code logic features corresponding to the code logic information are generated, and the code logic features are used to characterize the code logic information. After the code logic features corresponding to the key code snippet are determined, the code logic features are matched in the task database, so as to determine the target logic features matched by the code logic features from the reference logic features.
[0145] S806: Determine at least one target task execution logic feature corresponding to the target logic feature from the task execution logic features, and use a reference task corresponding to the at least one target task execution logic feature as the target task.
[0146] Among them, after determining the target logical characteristics, the target task execution logical characteristics that contain the target logical characteristics are searched among the task execution logical characteristics in the task database, and the number of target task execution logical characteristics is one or more. After determining the target task execution logical characteristics, the reference tasks corresponding to one or more target task execution logical characteristics are used as the target tasks.
[0147] In the embodiment provided in the present application, the code logic features corresponding to the key code snippets are used to match the reference logic features in the task database, so as to query the target task execution logic features to which the key code snippets can be applied, and then predict the target task to which the key code snippets can be applied.
[0148] See also Fig. 9 , Fig. 9 A flowchart of constructing a training code to generate prompt words is provided in an embodiment of the present application. Fig. 9 As shown, in S204, training code generation prompt words are constructed based on key code snippets and target tasks, including:
[0149] S902: Determine the task content of the target task, and generate a task description corresponding to the target task based on the task content.
[0150] Among them, after determining the target task, the task content of the target task is obtained, and then the task content of the target task is used to generate a corresponding task description. Specifically, the task content can be rewritten to generate a task description that meets the task description specification. Exemplarily, the target task includes but is not limited to a code review task, a code repair task, etc. For example, the task description corresponding to the code review task can be used to review the code to be reviewed and generate review results and modification suggestions.
[0151] S904: Perform description association processing on the task description and the key code snippet to obtain a target task description.
[0152] After the task description and the key code snippet are determined, description association is performed on the task description and the key code snippet so that the task description and the key code snippet correspond to each other.
[0153] S906: Obtain a training code generation prompt word template, and perform description editing processing on the training code generation prompt word template based on the target task description to obtain a training code generation prompt word.
[0154] Among them, the description editing process includes but is not limited to description modification, description addition, description deletion, etc. The training code generation prompt word template can be a prompt word template pre-established by the user based on actual needs. The training code generation prompt word template can be "Please generate code that can implement the following task description based on the provided key code snippet {XXX}. The task description is: YYY". Then, the "XXX" and "YYY" parts in the training code generation prompt word template are described and added using the interrelated task descriptions and key code snippets, thereby obtaining the training code generation prompt words.
[0155] In the embodiment provided in the present application, the task content is used to generate a task description corresponding to the target task, and then the task description and key code snippets are described and associated to obtain the target task description. Finally, the target task description is used to describe and edit the training code generation prompt word template to obtain the training code generation prompt word.
[0156] See also Fig.10 , Fig.10 This is a schematic diagram of the structure of a training code generation device provided in an embodiment of the present application. Fig.10 As shown, the training code generating device 1000 includes:
[0157] A generating module 1010 is adapted to perform code screening processing on a target code database to obtain a target complete code and determine a key code fragment corresponding to the target complete code;
[0158] A construction module 1020 is adapted to perform task prediction processing on the key code snippet to obtain at least one target task, and construct a training code generation prompt word based on the key code snippet and the target task;
[0159] The training code generation module 1030 is adapted to generate at least two reference training codes for training code generation prompt words through a target code completion model, and run the reference training codes for a target task to determine a target training code from the reference training codes.
[0160] Optionally, the generating module 1010 includes:
[0161] A type checking unit, adapted to determine source code from a target code database, perform type checking on the source code to obtain a type checking result, and perform code screening on the source code using the type checking result to obtain an initial code;
[0162] The target complete code determination unit is adapted to perform code integrity detection processing on the initial code to obtain an integrity detection result, take the initial code whose integrity detection result is a code integrity type as the complete code, and perform code deduplication processing on the complete code to obtain the target complete code.
[0163] Optionally, the key code snippet is reusable; the generation module 1010 includes:
[0164] A first extraction unit is adapted to extract business logic code fragments from the target complete code to obtain business logic code fragments, and use the business logic code fragments as key code fragments; and / or,
[0165] The second extraction unit is adapted to perform decision code fragment extraction processing on the target complete code to obtain the decision code fragment, and use the decision code fragment as the key code fragment.
[0166] Optionally, the construction module 1020 includes:
[0167] an acquisition unit, adapted to acquire a pre-established task database, the task database comprising a reference task and at least one task execution logic feature associated with the reference task, the task execution logic feature comprising a plurality of reference logic features;
[0168] A matching unit, adapted to determine the code logic features corresponding to the key code fragments, and use the code logic features to perform feature matching processing on the reference logic features in the task database to obtain target logic features for matching the code logic features;
[0169] The target task determination unit is adapted to determine at least one target task execution logic feature corresponding to the target logic feature from the task execution logic feature, and to use the reference task corresponding to the at least one target task execution logic feature as the target task.
[0170] Optionally, the construction module 1020 includes:
[0171] A task description generating unit, adapted to determine the task content of the target task, and to generate a task description corresponding to the target task based on the task content;
[0172] An association unit, adapted to perform description association processing on the task description and the key code snippet to obtain a target task description;
[0173] The editing unit is adapted to obtain a training code generation prompt word template, and perform description editing processing on the training code generation prompt word template based on the target task description to obtain the training code generation prompt word.
[0174] Optionally, the training code generation module 1030 includes:
[0175] A task completion degree determination unit, adapted to determine code operation information for executing a reference training code for a target task, and determine a task completion degree of the reference training code for the target task based on the code operation information;
[0176] The target training code determination unit is adapted to determine the target training code from the reference training code using the task completion degree.
[0177] Optionally, the training code generating apparatus 1000 further includes:
[0178] A task completion sample label determination module is adapted to obtain target training codes corresponding to multiple target tasks, and determine task completion sample labels corresponding to the target training codes through the target tasks;
[0179] A task completion reference label determination module is adapted to control the initial code generation large model to generate a reference code corresponding to a target task, and determine a task completion reference label of the reference code through the target task;
[0180] The training module is suitable for determining the model loss value using the task completion sample labels and task completion reference labels corresponding to the same target task, and using the model loss value to adjust the model parameters of the initial code generation model until the initial code generation model completes the model training to obtain the target code generation model.
[0181] See also Fig.11 , Fig.11 A schematic diagram of the structure of a terminal provided in an embodiment of the present application. Fig.11 As shown, the terminal 1100 may include: at least one processor 1101 , at least one network interface 1104 , a user interface 1103 , a memory 1105 , and at least one communication bus 1102 .
[0182] The communication bus 1102 is used to realize the connection and communication between these components.
[0183] The user interface 1103 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 1103 may also include a standard wired interface and a wireless interface.
[0184] The network interface 1104 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0185] Among them, the processor 1101 may include one or more processing cores. The processor 1101 uses various interfaces and lines to connect various parts in the entire terminal 1100, and executes various functions and processes data of the terminal 1100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 1105, and calling data stored in the memory 1105. Optionally, the processor 1101 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 1101 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 1101, and it can be implemented separately through a chip.
[0186] Among them, the memory 1105 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory, ROM). Optionally, the memory 1105 includes a non-transitory computer-readable storage medium. The memory 1105 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1105 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1105 may also be optionally at least one storage device located away from the aforementioned processor 1101. As Fig.11 As shown, the memory 1105 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a training code generation program.
[0187] exist Fig.11In the terminal 1100 shown, the user interface 1103 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 1101 can be used to call the training code generation program stored in the memory 1105, and specifically perform the following operations:
[0188] Perform code screening on the target code database to obtain the target complete code, and determine the key code fragments corresponding to the target complete code;
[0189] Performing task prediction processing on the key code snippet to obtain at least one target task, and constructing a training code generation prompt word based on the key code snippet and the target task;
[0190] At least two reference training codes for training code generation prompt words are generated by a target code completion model, and the reference training codes are run for a target task to determine a target training code from the reference training codes.
[0191] Optionally, when the processor 1101 performs code screening processing on the target code database to obtain the target complete code, specifically:
[0192] Determine source code from a target code database, perform type checking on the source code to obtain a type checking result, and use the type checking result to perform code screening on the source code to obtain an initial code;
[0193] A code integrity check is performed on the initial code to obtain an integrity check result, the initial code whose integrity check result is a code integrity type is taken as the complete code, and a code deduplication process is performed on the complete code to obtain a target complete code.
[0194] Optionally, the key code snippet is reusable; when the processor 1101 executes to determine the key code snippet corresponding to the target complete code, it specifically executes:
[0195] Extracting business logic code snippets from the target complete code to obtain business logic code snippets, and using the business logic code snippets as key code snippets; and / or,
[0196] The target complete code is subjected to decision code fragment extraction processing to obtain the decision code fragment, and the decision code fragment is used as the key code fragment.
[0197] Optionally, when the processor 1101 performs task prediction processing on the key code snippet to obtain at least one target task, the processor 1101 specifically performs:
[0198] Acquire a pre-established task database, the task database including a reference task and at least one task execution logic feature associated with the reference task, the task execution logic feature including a plurality of reference logic features;
[0199] Determine the code logic features corresponding to the key code snippets, use the code logic features to perform feature matching processing on the reference logic features in the task database, and obtain the target logic features for matching the code logic features;
[0200] At least one target task execution logic feature corresponding to the target logic feature is determined from the task execution logic features, and a reference task corresponding to the at least one target task execution logic feature is used as the target task.
[0201] Optionally, when the processor 1101 constructs a training code based on the key code snippet and the target task to generate prompt words, the processor 1101 specifically executes:
[0202] Determine the task content of the target task, and generate a task description corresponding to the target task based on the task content;
[0203] Perform description association processing on the task description and key code snippets to obtain the target task description;
[0204] A training code generation prompt word template is obtained, and description editing processing is performed on the training code generation prompt word template based on the target task description to obtain the training code generation prompt word.
[0205] Optionally, when the processor 1101 executes running the reference training code for the target task to determine the target training code from the reference training code, specifically:
[0206] Running the reference training code for the target task to determine code running information, and determining the task completion degree of the reference training code for the target task based on the code running information;
[0207] The target training code is determined from the reference training code using task completion.
[0208] Optionally, the processor 1101 is also adapted to execute
[0209] Obtain target training codes corresponding to multiple target tasks, and determine task completion sample labels corresponding to the target training codes through the target tasks;
[0210] Control the initial code generation model to generate reference code corresponding to the target task, and determine the task completion reference label of the reference code through the target task;
[0211] The model loss value is determined by using the task completion sample labels and task completion reference labels corresponding to the same target task, and the model loss value is used to adjust the model parameters of the initial code generation large model until the initial code generation large model completes model training to obtain the target code generation large model.
[0212] An embodiment of the present application further provides a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded by a processor and executing the steps of any method in the above embodiments.
[0213] In the several embodiments provided in the embodiments of the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0214] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0215] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or in the form of software functional modules.
[0216] If the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0217] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of the present application.
[0218] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0219] The above is a description of a training code generation method, device, terminal and computer-readable storage medium provided in an embodiment of the present application. For technicians in this field, according to the ideas of the embodiments of the present application, there may be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the embodiments of the present application.
Claims
1. A training code generation method, wherein: The method comprises: Perform code screening on the target code database to obtain a target complete code, and determine a key code fragment corresponding to the target complete code; Performing task prediction processing on the key code snippet to obtain at least one target task, and constructing a training code generation prompt word based on the key code snippet and the target task; Generate at least two reference training codes for generating prompt words for the training code through a target code completion model, and run the reference training codes for the target task to determine a target training code from the reference training codes; The code screening process of the target code database to obtain the target complete code includes: Determine source code from a target code database, perform type checking on the source code to obtain a type checking result, and use the type checking result to perform code screening on the source code to obtain an initial code; Performing code integrity detection processing on the initial code to obtain an integrity detection result, taking the initial code with the integrity detection result of code integrity type as the complete code, and performing code deduplication processing on the complete code to obtain a target complete code; The key code snippet is reusable; and the step of determining the key code snippet corresponding to the target complete code includes: Performing business logic code snippet extraction processing on the target complete code to obtain a business logic code snippet, and using the business logic code snippet as a key code snippet; and / or, Performing decision code fragment extraction processing on the target complete code to obtain a decision code fragment, and using the decision code fragment as a key code fragment; The step of performing task prediction processing on the key code snippet to obtain at least one target task includes: Acquire a pre-established task database, the task database comprising a reference task and at least one task execution logic feature associated with the reference task, the task execution logic feature comprising a plurality of reference logic features; Determine the code logic feature corresponding to the key code snippet, and use the code logic feature to perform feature matching processing on the reference logic feature in the task database to obtain the target logic feature matched by the code logic feature; At least one target task execution logic feature corresponding to the target logic feature is determined from the task execution logic features, and a reference task corresponding to the at least one target task execution logic feature is used as a target task.
2. The method according to claim 1, wherein: The generating prompt words based on the key code snippet and the target task training code construction includes: Determine the task content of the target task, and generate a task description corresponding to the target task based on the task content; Performing description association processing on the task description and the key code snippet to obtain a target task description; A training code generation prompt word template is obtained, and description editing processing is performed on the training code generation prompt word template based on the target task description to obtain a training code generation prompt word.
3. The method according to claim 1, wherein: The step of running the reference training code for the target task to determine the target training code from the reference training code comprises: Running the reference training code for the target task to determine code running information, and determining a task completion degree of the reference training code for the target task based on the code running information; The target training code is determined from the reference training code using the task completion degree.
4. The method according to claim 3, wherein: The method further comprises: Obtain target training codes corresponding to multiple target tasks, and determine task completion sample labels corresponding to the target training codes through the target tasks; Controlling the initial code generation model to generate a reference code corresponding to the target task, and determining a task completion reference tag of the reference code through the target task; The model loss value is determined using the task completion sample labels and task completion reference labels corresponding to the same target task, and the model loss value is used to adjust the model parameters of the initial code generation model until the initial code generation model completes model training to obtain the target code generation model.
5. A training code generating device, wherein: The device comprises: A generation module, adapted to perform code screening processing on a target code database to obtain a target complete code, and determine a key code fragment corresponding to the target complete code; A construction module, adapted to perform task prediction processing on the key code snippet to obtain at least one target task, and construct a training code generation prompt word based on the key code snippet and the target task; A training code generation module, adapted to generate at least two reference training codes for generating prompt words for the training code through a target code completion model, and to run the reference training codes for the target task to determine a target training code from the reference training codes; Wherein, the generation module includes: A type checking unit, adapted to determine source code from a target code database, perform type checking on the source code to obtain a type checking result, and perform code screening on the source code using the type checking result to obtain an initial code; a target complete code determination unit, adapted to perform code integrity detection processing on the initial code to obtain an integrity detection result, take the initial code with the integrity detection result of the code integrity type as the complete code, and perform code deduplication processing on the complete code to obtain a target complete code; The key code fragment is reusable; the generation module also includes: A first extraction unit is adapted to extract a business logic code fragment from the target complete code to obtain a business logic code fragment, and use the business logic code fragment as a key code fragment; and / or, A second extraction unit is adapted to perform a decision code fragment extraction process on the target complete code to obtain a decision code fragment, and use the decision code fragment as a key code fragment; The construction module comprises: an acquisition unit, adapted to acquire a pre-established task database, the task database comprising a reference task and at least one task execution logic feature associated with the reference task, the task execution logic feature comprising a plurality of reference logic features; A matching unit, adapted to determine a code logic feature corresponding to the key code snippet, and use the code logic feature to perform feature matching processing on a reference logic feature in the task database to obtain a target logic feature matched by the code logic feature; The target task determination unit is adapted to determine at least one target task execution logic feature corresponding to the target logic feature from the task execution logic feature, and take the reference task corresponding to the at least one target task execution logic feature as the target task.
6. A terminal, wherein: The terminal includes: Processor; and A memory arranged to store computer executable instructions which, when executed, cause the processor to perform a method according to any one of claims 1 to 4.
7. A computer-readable storage medium, wherein: The computer-readable storage medium stores one or more programs, and when the one or more programs are executed by a processor, the method of any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Code processing method and code processing model training method
CN117806967A
Task testing method, code annotation method, task testing platform and equipment
CN118312212A