Code generation method and device

By leveraging the intelligent capabilities of large language models in code generation, and constantly updating context information and decision-making instructions, the problems of low code generation efficiency and low degree of intelligence in the existing technology are solved, and more efficient and intelligent code generation is achieved.

CN119829063APending Publication Date: 2025-04-15WEBANK (CHINA)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411896991.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

The current large language model has problems of inefficiency and low intelligence in code generation, especially when generating the complete code of the project, it is impossible to fully utilize the intelligent capabilities of the large language model.

Method used

By a code generation method and device, the method includes inputting task instructions to a large language model, obtaining decision instructions, and updating context information based on the execution result until a code that conforms to the task description is generated. The device includes an input module, a receiving module, an execution module and an update module for implementing the above-mentioned method.

Benefits of technology

It improves the intelligence and accuracy of code generation, reduces dependence on traditional IDEs, and improves the efficiency and intelligence of code generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829063A_ABST
    Figure CN119829063A_ABST
Patent Text Reader

Abstract

The invention discloses a code generation method and device.The method comprises the steps that a first task instruction is input into a large language model, a decision instruction of the Tth round output by the large language model is obtained, and the first task instruction comprises context information of the (T-1) th round and a decision instruction of the (T-1) th round, the context information of the (T-1) th round comprises task description defined by a code generation role and decision instructions related to code generation, and executing the decision instruction of the Tth round to obtain an execution result of the Tth round; and adding the execution result of the Tth round into the context information of the (T-1) th round to obtain the context information of the Tth round, and updating the first task instruction input into the large language model based on the context information of the Tth round until the large language model outputs a code which conforms to the task description defined by the code generation role. By adopting the method, the code corresponding to the task description can be generated according to the first task instruction, and the intelligence and accuracy of code generation are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a code generation method and device. Background Art

[0002] With the rapid development of large language models, large language models have achieved remarkable results in natural language processing and problem solving, and are increasingly used in code generation and software development.

[0003] However, current large language models are mostly limited to generating local codes such as functions and components. The complete code generation of the project still relies on the traditional Integrated Development Environment (IDE). IDE is a software application that integrates code editors, compilers, debuggers and other development tools into a unified interface to provide various functions required for program development.

[0004] Therefore, generating complete codes of a project based on a large language model and IDE tools has problems of low efficiency and low intelligence. Summary of the invention

[0005] The present application provides a code generation method and device for generating code corresponding to a task description according to a first task instruction, thereby improving the intelligence and accuracy of code generation.

[0006] In a first aspect, an embodiment of the present application provides a code generation method, which can be executed by a code generation device, the method comprising: inputting a first task instruction into a large language model to obtain a decision instruction of the Tth round output by the large language model; the first task instruction comprises context information of the T-1th round and a decision instruction of the T-1th round, the context information of the T-1th round comprising a task description defined by a code generation role and various decision instructions related to code generation; executing the decision instruction of the Tth round to obtain an execution result of the Tth round; adding the execution result of the Tth round to the context information of the T-1th round to obtain the context information of the Tth round, and updating the first task instruction input into the large language model based on the context information of the Tth round until the large language model outputs code that conforms to the task description defined by the code generation role.

[0007] In a possible implementation, updating the first task instruction input into the large language model based on the context information of the Tth round includes: inputting a second task instruction into the large language model; the second task instruction is used to instruct the large language model to compress the context information of the Tth round when determining that the length of the context information of the Tth round exceeds a length threshold; and obtaining an updated first task instruction based on the compressed context information of the Tth round and the decision instruction of the Tth round.

[0008] In one possible implementation, the method further includes: inputting a third task instruction into the large language model; the third task instruction includes a task description defined in a global code review role; and the third task instruction is used to instruct the large language model to determine whether the large language model outputs code that complies with the task description defined in the code generation role.

[0009] In a possible implementation, the first task instruction is input into a large language model to obtain a decision instruction for the Tth round output by the large language model, including: inputting the first task instruction into the large language model to obtain an initial decision instruction for the Tth round; based on the third task instruction, determining through the large language model whether it is necessary to adjust the initial decision instruction for the Tth round, thereby obtaining a decision instruction for the Tth round.

[0010] In a possible implementation, the task description defined by the code generation role is a task description for modifying existing code; the context information also includes dependencies between code files; before inputting the first task instruction into the large language model, it also includes: according to the code path of the existing code, reading basic information of each code file under the code path; determining the dependencies between code files according to the basic information of each code file.

[0011] In a possible implementation, any task description is a task described in natural language, and any task requirement includes at least one of the following: background of the task, verification steps of the task, expected results of the task, and relevant knowledge of the task.

[0012] In a second aspect, an embodiment of the present application provides a code generation device, comprising: an input module for inputting a first task instruction into a large language model, and a receiving module for obtaining a decision instruction of the Tth round output by the large language model; the first task instruction comprises context information of the T-1th round and a decision instruction of the T-1th round, and the context information of the T-1th round comprises a task description defined by a code generation role and various decision instructions related to code generation; an execution module for executing the decision instruction of the Tth round to obtain an execution result of the Tth round; an update module for adding the execution result of the Tth round to the context information of the T-1th round to obtain the context information of the Tth round, and updating the first task instruction input into the large language model based on the context information of the Tth round until the large language model outputs code that conforms to the task description defined by the code generation role.

[0013] In a possible implementation, the update module is specifically used to input a second task instruction into the large language model; the second task instruction is used to instruct the large language model to compress the context information of the Tth round when determining that the length of the context information of the Tth round exceeds a length threshold; and obtain an updated first task instruction based on the compressed context information of the Tth round and the decision instruction of the Tth round.

[0014] In a possible implementation, the input module is also used to input a third task instruction into the large language model; the third task instruction includes a task description defined in a global code review role; the third task instruction is used to instruct the large language model to determine whether the large language model outputs code that complies with the task description defined in the code generation role.

[0015] In a possible implementation, the receiving module is also used to obtain an initial decision instruction for the Tth round; based on the third task instruction, determine whether it is necessary to adjust the initial decision instruction for the Tth round through the large language model, thereby obtaining a decision instruction for the Tth round.

[0016] In a possible implementation, the task description defined by the code generation role is a task description for modifying existing code; the context information also includes dependencies between code files; a processing module is used to read basic information of each code file under the code path according to the code path of the existing code; and determine the dependencies between code files according to the basic information of each code file.

[0017] In a possible implementation, any task description is a task described in natural language, and any task requirement includes at least one of the following: background of the task, verification steps of the task, expected results of the task, and relevant knowledge of the task.

[0018] In a third aspect, an embodiment of the present application further provides a code generation device, comprising a memory and a processor, wherein the memory is used to store computer programs or instructions; the processor is used to call the computer programs or instructions stored in the memory to execute a method as in any possible implementation of the first aspect.

[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which instructions are stored. When a computer reads and executes the instructions, the computer executes a method in any possible implementation of the first aspect.

[0020] In a fifth aspect, an embodiment of the present application provides a computer program product, wherein instructions are stored in the computer program product. When a computer reads and executes the instructions, the computer executes a method in any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0022] Figure 1 A flowchart corresponding to a code generation method provided in an embodiment of the present application;

[0023] Figure 2 A flowchart corresponding to another code generation method provided in an embodiment of the present application;

[0024] Figure 3 A schematic diagram of the internal modules of a code generating device 3000 provided in an embodiment of the present application;

[0025] Figure 4 A schematic diagram of the structure of a code generation device 4000 provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0027] In order to more clearly introduce the solutions proposed in the embodiments of the present application, the self-defined terms in the present application are first explained. Adaptive Decision Network (ADN): Establish a continuously circulating decision network that can dynamically generate new decision instructions based on current decision instructions and context information to achieve continuous self-reflection and strategy adjustment.

[0028] Context Compression Engine (CCE): Design a context information compression mechanism to compress and summarize the acquired context information to generate condensed context information, thus solving the problem of context information length limitation in large language models.

[0029] Global Observer (GO): A global observer is introduced to evaluate the current progress status from a macro perspective, provide optimization suggestions, and ensure the accuracy and effectiveness of decision instructions.

[0030] In combination with the above-mentioned ADN, CCE and GO, a code generation method provided in an embodiment of the present application can be implemented, which is used to generate code corresponding to the task description according to the first task instruction, thereby improving the intelligence and accuracy of code generation.

[0031] Figure 1 A flowchart corresponding to a code generation method provided in an embodiment of the present application is shown, and the flowchart can be executed by a code generation device, such as Figure 1 As shown, the process includes the following steps:

[0032] In step 101, a code generation device inputs a first task instruction into a large language model to obtain a T-th round decision instruction output by the large language model.

[0033] Specifically, the code generation device can be a computer, a server or other intelligent device, and the large language model can be chatGPT, Kimi, and the embodiment of the present application does not specifically limit the type of large language model. The first task instruction includes the context information of the T-1th round and the decision instruction of the T-1th round, wherein the context information of the T-1th round includes the task description defined by the code generation role and each decision instruction related to code generation, and the first task instruction is input into the large language model to obtain the decision instruction of the Tth round output by the large language model.

[0034] Exemplarily, the process of obtaining the second round of decision instructions based on the context information and decision instructions of the first round is first introduced. The context information of the first round can be input by the user. For example, an input box for user input can be provided on the interface of the code generation device. The user can enter the task description in the input box according to the requirements of the project. The task description can be a description defined by the code generation role. The code generation role can be a senior software engineer or a front-end engineer. Taking the senior software engineer as an example, the task description includes that from now on, you act as a senior software engineer and are responsible for completing the task requirements. The task requirements are as follows, and you have the following decision instructions to call. Task requirements: Modify the user login code in the user authentication module to reduce the response time of user login. Decision instructions: Preview the main function summary of a.py; View the code details of the authenticate_user() function in a.py. Optionally, the decision instruction can be an address, and the file under the address includes multiple available decision instructions. The above-mentioned task description defined by the code generation role is an example, and the embodiment of the present application does not limit the specific content of the task description. Since the first round of large models has not yet output a decision instruction, the decision instruction of the first round is not one of the above multiple decision instructions. In the embodiment of the present application, the first round of decision instructions can be a code path input by the user, and the code path is the path of the code corresponding to the task requirement, which can be a root path. If the task requirement is based on an existing code, the code path can be the path of the existing code; if the task requirement is a new project, the code path is a pre-saved path of a new project.

[0035] The first task instruction includes the context information of the first round and the decision instruction of the first round. The first task instruction is input into the large language model to obtain the second round of decision instructions output by the large language model. The second round of decision instructions are executed, and the execution result of the second round of decision instructions is added to the context information of the first round to obtain the context information of the second round, and the first task instruction is updated based on the context information of the second round and the decision instruction of the second round. The first task instruction is input into the large language model to obtain the third round of decision instructions output by the large language model, and the execution result of the third round of decision instructions is added to the context information of the second round to obtain the context information of the third round, and the first task instruction is updated based on the context information of the third round and the decision instruction of the third round. The first task instruction is input into the large language model to obtain the fourth round of decision instructions output by the large language model, and the cycle is repeated until the large language model outputs code that conforms to the task description defined by the code generation role. It can be understood that the above loop process includes inputting the first task instruction into the large language model to obtain the decision instruction of the Tth round output by the large language model. Except that the decision instruction of the first round is the code path, the decision instructions of the remaining rounds are determined according to the multiple decision instructions input in the context information of the first round. The above loop process is executed by ADN, which calls the large language model to continuously reflect and output the next decision instruction.

[0036] In the above example, the task description defined by the code generation role is a task description for modifying existing code. Optionally, in the task of modifying existing code, the context information also includes dependencies between code files. Before inputting the first task instruction into the large language model, it also includes: according to the code path of the existing code, reading the basic information of each code file under the code path, and determining the dependencies between the code files according to the basic information of each code file.

[0037] Specifically, according to the code path in the first round of decision instructions, each code file in the code path is traversed to extract the basic information of each code file, including the file name, number of lines, and main function summary of each code file. Optionally, in order to better obtain the relationship between each code file, an abstract syntax tree (AST) parsing tool is used to analyze the dependencies between code files and generate a code file dependency graph. AST is a tree representation of the abstract syntax structure of the code. It represents the building blocks of the programming language in the form of a tree, and each node in the tree represents a structure in the source code. In this way, by parsing each code file in the code path, the relationship between the code files can be more accurately known so that the large language model can output more accurate decision instructions.

[0038] Optionally, any task requirement is a task described in natural language, and any task description includes at least one of the following: background of the task, verification steps of the task, expected results of the task, and relevant knowledge of the task.

[0039] Specifically, in order to better express the task requirements, the embodiment of the present application provides an Agent Specific Story Description (ASSD), which is a standardized task requirement description format that aims to provide a complete task background and clear operation steps. Exemplarily, the above task requirements are converted into ASSD format input, which can be converted into, Background: This module is a user authentication module. Currently, users report that the login speed is slow and there is no clear prompt when the login fails. Detailed tasks: Modify the performance of the user authentication module, especially the response speed when processing large-scale concurrent login requests, and at the same time, improve the error prompt function when the user login fails. Reproduction / verification steps: Start the user authentication module locally; use 1000 concurrent login requests to simulate the login operation of large-scale users; record the login success rate and response time; try to enter the wrong password and observe the error prompt; expected results: when there are 1000 concurrent login requests, the response time is controlled within 2 seconds, and when the user login fails, the interface can display a clear error prompt. Optionally, the input in ASSD format can also include knowledge related to the task requirements, such as the user authentication module relies on the index query of the database, and the relevant query code is located at

[0040] The `authenticate_user()` function in the `auth_service.py` file.

[0041] Step 102: The code generation device executes the decision instruction of the Tth round and obtains the execution result of the Tth round.

[0042] Receive the T-th round decision instruction output by the large language model, execute the decision instruction, and obtain the execution result of the decision instruction. Optionally, the decision instruction of each round may not be reflected in the interface of the code generation device, and may be saved in a preset storage space. When there is an updated decision instruction in the preset storage space, the code generation device automatically executes the updated decision instruction to obtain the execution result of the decision instruction.

[0043] Step 103, add the execution result of the Tth round to the context information of the T-1th round to obtain the context information of the Tth round, and update the first task instruction input into the large language model based on the context information of the Tth round, until the large language model outputs code that conforms to the task description defined by the code generation role.

[0044] Specifically, the execution result of the Tth round is added to the context information of the T-1th round to obtain the context information of the Tth round. Exemplarily, the decision instruction can be any one of the multiple decision instructions input in the first round context, or multiple. For example, if the decision instruction is to open a file, search for keywords, etc., the path and file name of the file can be added to the context information of the T-1th round; if the decision instruction is to search for keywords, the paths and file names of all files that search for the keyword can be added to the context information of the T-1th round to obtain the context information of the Tth round.

[0045] The first task instruction input into the large language model is updated based on the context information of the Tth round, including: inputting a second task instruction into the large language model, the second task instruction is used to instruct the large language model to compress the context information of the Tth round when determining that the length of the context information of the Tth round exceeds a length threshold, and obtaining an updated first task instruction according to the compressed context information of the Tth round and the decision instruction of the Tth round.

[0046] It should be noted that the length of the context information that can be understood by the large language model is limited. When the length of the context information exceeds the understandable length, the large language model cannot understand it. Therefore, after obtaining the context information of the Tth round, CCE calls the large language model and inputs the second task instruction into the large language model to instruct the large language model to determine whether the context information of the Tth round exceeds the length threshold. If it exceeds, the large language model summarizes the context information, retains the key information, and generates compressed context information. Based on the compressed context information of the Tth round and the decision instruction of the Tth round, the updated first task instruction is obtained. It can be understood that the length threshold is less than the length of the information that can be understood by the large language model, that is, before the length of the context information exceeds the length of the information that can be understood by the large language model, the context information is compressed. Optionally, CCE can also determine whether the context information of the Tth round exceeds the length threshold. If it exceeds, an instruction to compress the context information of the Tth round is input to the large language model. In this way, each time new context information is obtained, it is determined whether the length of the context information exceeds the threshold. When the length of the context information exceeds the threshold, the context information can be compressed by the large language model to form compressed context information. In this way, the length of the context information will not exceed the length that the large language model can understand, and the context information is summarized during the compression process, retaining key information and not losing key information in the context information.

[0047] Optionally, a third task instruction is input into the large language model, the third task instruction includes a task description defined in a global code review role, and the third task instruction is used to instruct the large language model to determine whether the large language model outputs code that complies with the task description defined in a code generation role.

[0048] Exemplarily, after ADN generates a decision instruction, GO can call the large language model and input the third task instruction into the large language model to instruct the large language model to determine whether to output code that complies with the task description defined by the code generation role. The third task instruction includes a task description defined by the global code review role. The task description defined by the global code review role can be: from now on, you act as a manager. The requirements are as follows. Please determine from a global perspective whether the senior engineer has deviated from the direction. The requirement is: modify the user login code in the user authentication module to reduce the response time of the user login. The above task description defined by the global code review role is only an example. The embodiment of the present application does not limit the task description defined by the global code review role. In other words, GO calls the large language model to check whether accurate code is currently generated and whether the current decision instructions deviate from the correct direction from the perspective of a leader based on the task requirements and the latest contextual information.

[0049] Furthermore, the first task instruction is input into the large language model to obtain the decision instruction of the Tth round output by the large language model, including: inputting the first task instruction into the large language model to obtain the initial decision instruction of the Tth round; based on the third task instruction, determining through the large language model whether the initial decision instruction of the Tth round needs to be adjusted, thereby obtaining the decision instruction of the Tth round.

[0050] Exemplarily, the first task instruction includes the decision instruction of the T-1th round and the context information of the T-1th round, and the first task instruction is input into the large language model to obtain the initial decision instruction of the Tth round. GO calls the large language model, inputs the third task instruction into the large language model, and determines whether the initial decision instruction of the Tth round needs to be adjusted.

[0051] If it is determined that the initial decision instruction of the Tth round has correctly completed the code corresponding to the task requirement, GO determines that the task is over; if it is determined that the initial decision instruction of the Tth round has not correctly completed the code corresponding to the task requirement, then combined with the context information and task requirements of the T-1th round, it is determined whether the initial decision instruction of the Tth round deviates from the correct idea, and corresponding suggestions are given. For example, if it is found that there is a performance problem of database query in the authenticate_user() function, it is recommended to optimize the query. Then ADN generates a new decision instruction based on the feedback of GO, that is, the decision instruction of the Tth round. It should be noted that in order to improve the processing efficiency of task requirements, it is possible to start judging whether the task requirement is completed from a global perspective after receiving the decision instruction multiple times, instead of judging whether the task requirement is completed from a global perspective after receiving a new decision instruction and generating new context information each time.

[0052] In this way, during the entire code generation process, the steps of global observation and evaluation can be combined to evaluate the quality and performance of the generated code from an expert's perspective to ensure the accuracy of code generation.

[0053] Further, the decision instruction of the Tth round is executed, and the execution result of the decision instruction of the Tth round is added to the context information of the T-1th round to obtain the context information of the Tth round. The above process is repeated until GO determines that the task requirement is completed and generates the final optimization plan. The final optimization plan is the modified user authentication module code.

[0054] It is understandable that the optimization plan is determined according to the task requirements. If the task requirement is to find the files and code modification suggestions that need to be optimized for the user authentication module, then the final plan is the specific files and code modification suggestions that need to be modified. If the task requirement is to create a new module for counting user fund flows, then the final plan is the specific code of a module for counting user fund flows. It should be noted that the decision instructions in the context information are different for different task requirements, and the staff sets the corresponding decision instruction set according to different task requirements.

[0055] To more clearly reflect the code generation method, Figure 2 A flowchart corresponding to another code generation method provided in an embodiment of the present application is shown in FIG. Figure 2 The sequence of the operation steps is not unique and can be flexibly adjusted according to actual conditions.

[0056] Figure 3 A schematic diagram of the internal modules of a code generating device 3000 provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, the device may include: an input module 301 , a receiving module 302 , an execution module 303 , an update module 304 and a processing module 305 .

[0057] Among them, the input module 301 is used to input the first task instruction into the large language model, and the receiving module 302 is used to obtain the decision instruction of the Tth round output by the large language model; the first task instruction includes the context information of the T-1th round and the decision instruction of the T-1th round, and the context information of the T-1th round includes the task description defined by the code generation role and each decision instruction related to code generation; the execution module 303 is used to execute the decision instruction of the Tth round to obtain the execution result of the Tth round; the update module 304 is used to add the execution result of the Tth round to the context information of the T-1th round to obtain the context information of the Tth round, and update the first task instruction input into the large language model based on the context information of the Tth round until the large language model outputs code that conforms to the task description defined by the code generation role.

[0058] In a possible implementation, the update module 304 is specifically used to input a second task instruction into the large language model; the second task instruction is used to instruct the large language model to compress the context information of the Tth round when determining that the length of the context information of the Tth round exceeds a length threshold; and obtain an updated first task instruction based on the compressed context information of the Tth round and the decision instruction of the Tth round.

[0059] In a possible implementation, the input module 301 is also used to input a third task instruction into the large language model; the third task instruction includes a task description defined by a global code review role; the third task instruction is used to instruct the large language model to determine whether the large language model outputs code that complies with the task description defined by the code generation role.

[0060] In a possible implementation, the receiving module 302 is also used to obtain an initial decision instruction for the Tth round; based on the third task instruction, determine whether the initial decision instruction for the Tth round needs to be adjusted through the large language model, thereby obtaining a decision instruction for the Tth round.

[0061] In one possible implementation, the task description defined by the code generation role is a task description for modifying existing code; the context information also includes dependencies between code files; the processing module 305 is used to read the basic information of each code file under the code path according to the code path of the existing code; and determine the dependencies between the code files according to the basic information of each code file.

[0062] In a possible implementation, any task description is a task described in natural language, and any task requirement includes at least one of the following: background of the task, verification steps of the task, expected results of the task, and relevant knowledge of the task.

[0063] Figure 4 Schematic diagram of the structure of a code generating device 4000 provided in an embodiment of the present application. Figure 4 As shown, it includes at least one processor 401 and a memory 402 connected to the at least one processor 401. The specific connection medium between the processor 401 and the memory 402 is not limited in the embodiment of the present application. Figure 4 For example, the processor 401 and the memory 402 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.

[0064] In the embodiment of the present application, the memory 402 stores instructions that can be executed by at least one processor 401, and the at least one processor 401 can implement the steps of the above-mentioned code generation method by executing the instructions stored in the memory 402.

[0065] The processor 401 is the control center of the computer device, and can use various interfaces and lines to connect various parts of the computer device, and perform resource settings by running or executing instructions stored in the memory 402 and calling data stored in the memory 402. Optionally, the processor 401 may include one or more processing units, and the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401. In some embodiments, the processor 401 and the memory 402 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on independent chips.

[0066] Processor 401 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware processor for execution, or can be executed by a combination of hardware and software modules in the processor.

[0067] The memory 402 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 402 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 402 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 402 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0068] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

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

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

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

[0072] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A code generation method, characterized in that: The method comprises: Inputting a first task instruction into a large language model, obtaining a decision instruction of the Tth round output by the large language model; the first task instruction includes context information of the T-1th round and a decision instruction of the T-1th round, and the context information of the T-1th round includes a task description defined by a code generation role and various decision instructions related to code generation; Execute the decision instruction of the Tth round to obtain the execution result of the Tth round; The execution result of the Tth round is added to the context information of the T-1th round to obtain the context information of the Tth round, and the first task instruction input into the large language model is updated based on the context information of the Tth round until the large language model outputs code that conforms to the task description defined by the code generation role.

2. The method according to claim 1, characterized in that Updating the first task instruction input into the large language model based on the context information of the Tth round includes: Inputting a second task instruction into the large language model; the second task instruction is used to instruct the large language model to compress the context information of the Tth round when determining that the length of the context information of the Tth round exceeds a length threshold; According to the compressed context information of the Tth round and the decision instruction of the Tth round, an updated first task instruction is obtained.

3. The method according to claim 1, characterized in that The method further comprises: A third task instruction is input into the large language model; the third task instruction includes a task description defined in a global code review role; the third task instruction is used to instruct the large language model to determine whether the large language model outputs code that complies with the task description defined in the code generation role.

4. The method according to claim 3, characterized in that Inputting the first task instruction into the large language model to obtain the decision instruction of the Tth round output by the large language model includes: Input the first task instruction into the large language model to obtain the initial decision instruction of the Tth round; Based on the third task instruction, it is determined through the large language model whether the initial decision instruction of the Tth round needs to be adjusted, thereby obtaining the decision instruction of the Tth round.

5. The method according to any one of claims 1 to 4, characterized in that The task description defined by the code generation role is a task description for modifying the existing code; the context information also includes the dependency relationship between the code files; Before inputting the first task instruction into the large language model, the method further includes: According to the code path of the existing code, read the basic information of each code file under the code path; Dependencies between code files are determined according to the basic information of each code file.

6. The method according to any one of claims 1 to 4, characterized in that Any task requirement is a task described in natural language, and any task description includes at least one of the following: task background, task verification steps, task expected results, and task related knowledge.

7. A code generating device, characterized in that: include: An input module, used for inputting a first task instruction into a large language model; a receiving module, used for obtaining a decision instruction of the Tth round output by the large language model; the first task instruction includes context information of the T-1th round and a decision instruction of the T-1th round, and the context information of the T-1th round includes a task description defined by a code generation role and various decision instructions related to code generation; An execution module, used for executing the decision instruction of the Tth round and obtaining the execution result of the Tth round; An updating module is used to add the execution result of the Tth round to the context information of the T-1th round to obtain the context information of the Tth round, and update the first task instruction input into the large language model based on the context information of the Tth round until the large language model outputs code that conforms to the task description defined by the code generation role.

8. A code generating device, characterized in that: include: Memory, used to store computer programs or instructions; A processor, configured to call a computer program or instruction stored in the memory to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program or instructions. When a computer reads and executes the computer program or instructions, the computer executes the method according to any one of claims 1 to 6.

10. A computer program product, characterized in that The computer program product stores instructions, and when a computer reads and executes the instructions, the computer executes the method according to any one of claims 1 to 6.