Code generation method and related equipment

Through the user input requirements description and sample code, combined with task decomposition and dependency management, as well as the use of preset prompt words, input large language models to generate target code, solving the problem of insufficient flexibility in the code generation method and long-term training process in the existing technology, and achieving efficient and flexible code generation.

CN119576304APending Publication Date: 2025-03-07CHINA TELECOM CORP LTD TECHNOLOGY INNOVATION CENTER +1
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411749398.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

In the prior art, the code generation method based on fixed templates is insufficient in flexibility, while the training process of the method based on specific code training models takes a long time and requires high computing resources.

Method used

By obtaining the requirements description and sample code input by the user, the dependencies between multiple tasks and tasks are obtained based on these inputs, and the prompt words matching each task are determined in the preset prompt words, and finally these tasks, dependencies and prompt words are input into the large language model to generate the target code.

Benefits of technology

This method greatly reduces the user's usage threshold and cost, improves the flexibility and ease of use of code generation, and can generate code that meets the needs of specific tasks without requiring users to conduct additional model training.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576304A_ABST
    Figure CN119576304A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method and related equipment, and relates to the technical field of artificial intelligence. The method comprises the following steps: acquiring a demand description and an example code input by a user; based on the demand description and the example code, obtaining a plurality of tasks and a dependency relationship among the plurality of tasks, the plurality of tasks being used for generating a target code corresponding to the demand description; determining a prompt word matched with each task in preset prompt words; and inputting the plurality of tasks, the dependency relationship and the cue word corresponding to each task into a large language model to obtain a target code corresponding to the demand description. According to the embodiment of the invention, the user does not need to carry out additional model training, the use threshold of the user is greatly reduced, the large model can be guided to generate the code meeting the specific task requirement, and the user satisfaction is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] The technology of automatic code generation has a long history. With the development of software engineering and the increase in automation needs, this field has gone through several stages of development. In general, there are mainly the following types:

[0003] The first is the method based on fixed templates: This method is widely used in the automatic code generation of low-code platforms and database access layers. Its core principle is to set "slots" in the preset code framework, such as When the user provides specific information (such as the database table name "Person"), the system will

[0004]

[0005]

[0006]

[0007]

[0008]

[0009]

[0010]

[0011]

[0012]

[0013]

[0014]

[0015]

[0016]

[0017]

[0018]

[0019]

[0020]

[0021]

[0022]

[0023]

[0024]

[0025]

[0026]

[0027]

[0028]

[0029] Figure 1

[0030] Figure 2

[0031] Figure 3

[0032] Figure 4

[0033] Figure 5

[0034] Figure 6

[0035] Figure 7

[0036] Figure 8

[0037] Fig. 9

[0038] Fig.10

[0039] Fig.11

[0040] Fig.12

[0041]

[0042]

[0043]

[0044]

[0045]

[0046]

[0047]

[0048]

[0049]

[0050]

[0051]

[0052]

[0053]

[0054] Figure 1 Figure 1

[0055]

[0056]

[0057]

[0058]

[0059]

[0060]

[0061]

[0062]

[0063]

[0064]

[0065]

[0066]

[0067]

[0068]

[0069]

[0070]

[0071]

[0072]

[0073]

[0074]

[0075]

[0076]

[0077]

[0078]

[0079]

[0080]

[0081]

[0082]

[0083]

[0084]

[0085] Figure 2

[0086]

[0087]

[0088]

[0089] Figure 3 Figure 3

[0090]

[0091]

[0092] Figure 4

[0093]

[0094]

[0095]

[0096]

[0097] Figure 3

[0098]

[0099]

[0100] Figure 5

[0101]

[0102]

[0103]

[0104]

[0105]

[0106]

[0107]

[0108]

[0109]

[0110]

[0111]

[0112]

[0113]

[0114]

[0115]

[0116]

[0117]

[0118] Figure 6 Figure 2

[0119] Figure 7 Figure 1 Figure 3 Figure 4

[0120] Figure 8 Fig. 9

[0121] Fig. 9

[0122] Fig.10

[0123]

[0124]

[0125]

[0126]

[0127]

[0128]

[0129]

[0130]

[0131]

[0132]

[0133]

[0134]

[0135]

[0136]

[0137]

[0138]

[0139]

[0140]

[0141]

[0142]

[0143]

[0144]

[0145]

[0146]

[0147]

[0148]

[0149]

[0150]

[0151]

[0152]

[0153]

[0154]

[0155]

[0156]

[0157] Fig.11 Fig.11

[0158]

[0159]

[0160]

[0161]

[0162]

[0163]

[0164]

[0165]

[0166]

[0167]

[0168]

[0169]

[0170]

[0171]

[0172]

[0173] Fig.12 Fig.12

[0174] Fig.12 Fig.12

[0175]

[0176]

[0177]

[0178]

[0179]

[0180]

[0181]

[0182]

[0183]

[0184]

[0185]

[0186]

[0187] Fig.12

[0188]

[0189]

[0190]

[0191] Fig.12

[0192]

[0193] Fig.12 Fig.12

[0194]

[0195]

[0196]

[0197]

[0198]

[0199]

[0200]

[0201]

[0202]

[0203]

[0204]

[0205]

[0206]

[0207]

[0208]

[0209]

[0210]

[0211]

[0212] Replace with "Person". This method is simple to implement, but the input conditions are strictly limited, the scalability and flexibility are insufficient, and the development and maintenance costs are high. The second is a method based on specific code training models: In order to generate code that better meets specific needs, some researchers use a code base unique to the organization to train a dedicated model. This method can generate high-quality code that meets internal specifications, but the model training process is time-consuming, has high requirements for computing resources, and the generation process is closely coupled with a specific model, which is not conducive to the long-term maintenance and development of the system. It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. SUMMARY The present disclosure provides a code generation method and related equipment, which at least to some extent overcomes the lack of flexibility of the fixed template method, and the problem that the training process of the training model method is time-consuming and has high requirements for computing resources. Other features and advantages of the present disclosure will become apparent from the detailed description below, or partially learned through the practice of the present disclosure. According to one aspect of the present disclosure, a code generation method is provided, including: obtaining a requirement description and a sample code input by a user; based on the requirement description and the sample code, obtaining multiple tasks and dependencies between the multiple tasks, the multiple tasks are used to generate a target code corresponding to the requirement description; determining a prompt word matching each task in a preset prompt word; inputting multiple tasks, dependencies, and prompt words corresponding to each task into a large language model to obtain a target code corresponding to the requirement description. In one embodiment of the present disclosure, one or more of the programming language, programming structure, technology stack or library used in the example target code is the same as the example code. In one embodiment of the present disclosure, when the value of the sample code is empty, the method further includes: analyzing the requirement description to determine a prompt word matching the requirement description in a preset prompt word; inputting the prompt word matching the requirement description into the large language model to obtain a target code corresponding to the requirement description. In one embodiment of the present disclosure, before inputting multiple tasks, dependencies, and prompt words corresponding to each task into the large language model, the method further includes: receiving a content adjustment request, the content adjustment request is used to adjust one or more of the multiple tasks, dependencies, and prompt words corresponding to each task. In one embodiment of the present disclosure, multiple tasks, dependency relationships, and prompt words corresponding to each task are input into a large language model to obtain a target code corresponding to the requirement description, including: inputting multiple tasks, dependency relationships, and prompt words corresponding to each task into the large language model to obtain a first code; verifying the first code based on the requirement description and the example code; and using the first code as the target code if the verification passes.In one embodiment of the present disclosure, the method further includes: if the verification fails, re-execute based on the requirement description and the sample code, obtain multiple tasks and the dependency relationship between the multiple tasks, determine the prompt word matching each task in the preset prompt words, input the multiple tasks, the dependency relationship and the prompt word corresponding to each task into the large language model, and obtain the target code corresponding to the requirement description. According to another aspect of the present disclosure, a code generation device is provided, including an information acquisition module, an analysis and processing module, a prompt word determination module and a code generation module. The information acquisition module is used to obtain the requirement description and the sample code input by the user; the analysis and processing module is used to obtain multiple tasks and the dependency relationship between the multiple tasks based on the requirement description and the sample code, and the multiple tasks are used to generate the target code corresponding to the requirement description; the prompt word determination module is used to determine the prompt word matching each task in the preset prompt words; the code generation module is used to input the multiple tasks, the dependency relationship and the prompt word corresponding to each task into the large language model, and obtain the target code corresponding to the requirement description. According to another aspect of the present disclosure, an electronic device is provided, including: a memory for storing instructions; a processor for calling the instructions stored in the memory to implement the above-mentioned code generation method. According to another aspect of the present disclosure, a computer-readable storage medium is provided, on which computer instructions are stored, and the computer instructions implement the above-mentioned code generation method when executed by a processor. According to another aspect of the present disclosure, a computer program product is provided, and the computer program product stores instructions, and when the instructions are executed by a computer, the computer implements the above-mentioned code generation method. According to another aspect of the present disclosure, a chip is provided, including at least one processor and an interface; the interface is used to provide program instructions or data to at least one processor; at least one processor is used to execute program instructions to implement the above-mentioned code generation method. The code generation method and related devices provided in the embodiment of the present disclosure are based on the existing large language model, and do not require users to perform additional model training, which greatly reduces the user's use threshold and cost, and improves ease of use and scalability. In addition, through the demand description and sample code input by the user, combined with task decomposition and dependency management, and the use of preset prompt words, it is possible to guide the large model to generate code that meets the specific task requirements and improve user satisfaction. It should be understood that the above general description and the detailed description below are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.A flowchart of a code generation method in an embodiment of the present disclosure is shown; another flowchart of a code generation method in an embodiment of the present disclosure is shown; another flowchart of a code generation method in an embodiment of the present disclosure is shown; a flowchart of applying a large model to generate code in an embodiment of the present disclosure is shown; a schematic diagram of the architecture of a code generation system in an embodiment of the present disclosure is shown; a flowchart of applying a general code generator to generate code in an embodiment of the present disclosure is shown; a flowchart of applying a dedicated code generator to generate code in an embodiment of the present disclosure is shown; a schematic diagram of the composition architecture of a dedicated code generator in an embodiment of the present disclosure is shown; a schematic diagram of the creation process of a dedicated code generator in an embodiment of the present disclosure is shown; another schematic diagram of a code generation process in an embodiment of the present disclosure is shown; a schematic diagram of a code generation device in an embodiment of the present disclosure is shown; a structural block diagram of an electronic device in an embodiment of the present disclosure is shown. Specific implementation methods In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the claimed disclosure, but only represents selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure. It is understood that before using the technical solutions disclosed in the embodiments of the present disclosure, the type, scope of use, and usage scenarios of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations. In some embodiments, before obtaining the user's input demand description and sample code, a prompt message can be sent to the user to clearly prompt the user that the operation requested to be performed will require the acquisition and use of the user's personal information. Thus, the user can autonomously choose whether to provide personal information to the electronic device, application, server, storage medium, or other software or hardware that performs the operation of the technical solution of the present disclosure according to the prompt message. As an optional but non-limiting implementation method, in response to receiving the user's active request, the method of sending the prompt message to the user can be, for example, a pop-up window, and the prompt message can be presented in text in the pop-up window. In addition, the pop-up window can also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device. It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.At the same time, it is understood that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of the relevant laws, regulations and relevant provisions. For ease of understanding, the following first explains the relevant concepts involved in this disclosure as follows: Large Language Model (LLM): A large language model is an artificial intelligence model designed to understand and generate human language, usually referring to a language model containing tens of billions (or more) parameters. These models are trained on massive amounts of text data to obtain a deep understanding of the language. Compared with traditional language models, LLM has more powerful capabilities and can handle various complex text tasks, including but not limited to translation, question and answer, text summarization, dialogue, text classification, sentiment analysis, code generation, creative assistance, etc. Reasoning and Acting (ReAct): It is a general concept that describes the ability of artificial intelligence systems to reason and act in uncertain and dynamic environments. Its core idea is to combine reasoning (Reasoning) and action (Acting) so that the system can make decisions and perform tasks in uncertain and dynamically changing environments. Chain-of-Thought (COT): is an improved prompt strategy used in large language models, which aims to improve the performance of the model in complex reasoning tasks. Prompt: is a text or input used to guide or stimulate the model to generate a specific response. Prompts can be very diverse, ranging from a few simple words to complex sentences or paragraphs, depending on the required application scenarios and the complexity of the model. The following is a detailed description of this example implementation method in conjunction with the accompanying drawings and embodiments. First, a code generation method is provided in an embodiment of the present disclosure, and the code generation method can be executed by any electronic device with computing and processing capabilities. The execution subject of the code generation method of the embodiment of the present disclosure can be at least one of the user terminals such as mobile phones, tablet computers, wearable devices, etc. that can be configured to execute the code generation method provided by the embodiment of the present disclosure, or the execution subject of the method can also be the client itself that can execute the code generation method. A flow chart of a code generation method in an embodiment of the present disclosure is shown. As shown, the code generation method provided in the embodiment of the present disclosure includes S101-S104. In S101, a user input requirement description and sample code are obtained. The requirement description can be a few sentences input by the user, such as a few sentences of requirement description language input by the user through a dialog box. The requirement description can also be a requirement description document input by the user. The sample code can be a code input by the user for comparison. It should be noted that the sample code is not a code for implementing the requirements recorded in the above requirement description. In S102, based on the requirement description and the sample code, multiple tasks and dependencies between the multiple tasks are obtained, and the multiple tasks are used to generate target codes corresponding to the requirement description.In some embodiments, multiple tasks are used to generate target codes that correspond to the requirement description and are similar to the sample code, wherein the similarity may be that the programming language, programming structure, technology stack or library used in the sample target code is the same as the sample code. Convert the user's requirement description and the sample code into specific tasks. Each task usually corresponds to a step or a functional module of code generation. There are dependencies between the above multiple tasks, that is, the completion of some tasks needs to depend on the results of other tasks. As an example, generating a complete Web API interface may involve the following tasks: Task A: Create a database connection; Task B: Define a data model; Task C: Write an API route; Task D: Implement permission verification; Task E: Generate response processing logic. Next, determine the dependencies between these tasks. Dependencies can be divided into the following categories: Sequential dependency: One task must be started after another task is completed. For example, Task B (define the data model) must be performed after Task A (create a database connection) is completed, because the definition of the data model needs to rely on the established database connection. Data dependency: The output of one task is the input of another task. For example, Task C (write API routes) requires the output result of Task B (define the data model) because the definition of the API route requires knowing the structure of the data model. Conditional dependency: The execution of a task depends on whether the result of another task meets certain conditions. For example, task D (implementing permission verification) may need to check whether certain fields in task B (defining data model) exist to decide whether to perform permission verification. In S103, the prompt words that match each task are determined in the preset prompt words. The role of the preset prompt words is to provide context information and specific instructions to help the model better understand and generate the required code snippets. In some embodiments, the preset prompt words can be a set of predefined text templates, each template containing specific instructions and context information. These prompt words can help the large language model better understand the requirements of the task and generate code that meets expectations. As an example, the prompt words can include the following elements: Task description: clear task goals and requirements; Context information: relevant background information, such as database type, programming language, framework, etc.; Example code: short example code or code snippets to help the model understand the specific form of the task.In the previous example of generating a complete Web API interface, the prompt words that may be used for Task A to create a database connection are as follows: "Task:Create a database connection.Context:Use PostgreSQL as the database and Python with SQLAlchemy asthe ORM.Example:from sqlalchemy import create_engineengine=create_engine('postgresql: / / user:password@localhost / dbname')". In S104, multiple tasks, dependencies and the prompt words corresponding to each task are input into the large language model to obtain the target code corresponding to the requirement description. The disclosed embodiments break through the strict input restrictions of traditional low-code platforms, improve adaptability and intelligence levels; automatic demand analysis and processing can accurately understand user needs, and automatically handle various segmentation differences encountered during the generation process. Design a flexible architecture to reduce dependence on specific models and facilitate future upgrades and expansions. The generated code meets both industry standards and the specific needs of users. In the related art, the large model can generate code directly based on the user's description. Although it is very convenient, it also has an obvious disadvantage: it cannot directly generate user-defined code. For example, in the actual production system, when making an interface call, there will be a set of strict internal permissions verification, parameter splicing, data encryption and other restrictions. When the user generates the code, he certainly hopes to generate code that fully complies with his internal development specifications. The large model is trained based on the code in the open source code library, and it is difficult to directly generate code for user-specific needs. However, in the embodiment of the present disclosure, through the demand description and sample code entered by the user, combined with task decomposition and dependency management, and the use of preset prompt words, the large model can be guided to generate code that meets the specific task requirements. In some embodiments, the user may not be able to provide sample code, that is, the value of the above sample code may be empty. In the case where the value of the sample code is empty, that is, the above S101 only obtains the demand description entered by the user, the code generation method of the embodiment of the present disclosure can be as shown, including S201-S202. In S201, the requirement description is analyzed to determine the prompt words matching the requirement description in the preset prompt words; in S202, the prompt words matching the requirement description are input into the large language model to obtain the target code corresponding to the requirement description. In the embodiment of the present disclosure, the target code can be generated for the user even without the sample code, which can at least solve the problem of the first prior art in the background technology and improve the flexibility of code generation.A flow chart of a code generation method in an embodiment of the present disclosure is shown. As shown, the code generation method provided in the embodiment of the present disclosure includes steps S301-S305, wherein S301-S303 are the same as S101-S103 above. In S304, a content adjustment request is received, and the content adjustment request is used to adjust one or more of the prompt words corresponding to multiple tasks, dependencies, and each task. In S305, adjustments are made based on the content adjustment request, and the adjusted multiple tasks, dependencies, and prompt words corresponding to each task are input into the large language model to obtain the target code corresponding to the requirement description. As shown, multiple tasks, dependencies, and prompt words corresponding to each task are input into the large language model to obtain the target code corresponding to the requirement description, which may include S401-S403. In S401, multiple tasks, dependencies, and prompt words corresponding to each task are input into the large language model to obtain a first code; in S402, the first code is verified based on the requirement description and the sample code; in S403, if the verification passes, the first code is used as the target code. In some embodiments, when the verification fails, the requirement description and the sample code are re-executed to obtain multiple tasks and the dependencies between the multiple tasks, the prompt words matching each task are determined in the preset prompt words, and the multiple tasks, the dependencies and the prompt words corresponding to each task are input into the large language model to obtain the target code corresponding to the requirement description. It should be noted that, when the verification fails, one or more of the prompt words corresponding to the multiple tasks, the dependencies and each task can be adjusted based on the content adjustment request in the above embodiment. The disclosed embodiment aims to automatically understand the user's input and requirements and automatically generate executable program code based on the pre-trained large language model through deep learning and natural language processing technology. In addition to supporting the commonly used code automatic generation function, the disclosed embodiment is more suitable for professional system development scenarios, especially for scenarios with specific requirements for code generation, for example: in the front-end development process, the user needs to use the custom controls, custom styles or layouts that have been created before in the automatic code generation; or when accessing the interface service at the back end, the user needs to automatically generate code for the interface with certain logical requirements (such as: specific parameter splicing method and encryption method). A code generation system framework diagram provided by an embodiment of the present disclosure is shown. The functions of the various components of the code generation system from bottom to top are as follows: Large Language Model (LLM) is an artificial intelligence model designed to understand and generate human language, usually referring to a language model containing tens of billions (or more) of parameters. These models are trained on massive amounts of text data to gain a deep understanding of the language.Compared with traditional language models, LLM has more powerful capabilities and can handle various complex text tasks. The large model used in this patent has no specific restrictions. Common open source models can be used. Models with large parameters are preferred, such as qwen-72b. Cache, used to temporarily store temporary data generated during code generation. Database, used to store various information in the system, such as user information, examples uploaded by users, structure of code generator, detailed steps (i.e., tasks in the previous text) and prompt words required for each step, as well as dependencies between various steps, etc. Reasoning service, is a common module that calls the large model to unify input and output. Prompt word management, preset prompt words, used for user demand description and sample code analysis. Autonomous operation management: a list of operations provided to the large model, such as reading files (reading the contents of a code file), writing files (writing generated code into files), etc., the large model can autonomously select the operations that can be executed. Parsing engine: using inherent prompt words, parses the input requirements and examples based on the large model. Task engine: performs task management of the code generator and task execution during the generation process. Generation verification: re-enter the example and use the large model to determine whether the generated code is correct. Code generator: a set of code generation logic generated based on user requirements and examples. Automatic code generation: application layer, calling the code generator to perform actual automatic code generation. The core of the above code generation system is a dedicated code generator. When the user describes the requirements, a simple code example is provided. Based on the requirements and examples, the system automatically decomposes the generation process into multiple steps, analyzes the dependencies between the steps, generates prompt words, and finally solidifies the entire generation process into a dedicated code generator. Different scenarios correspond to different dedicated code generators. The above code generation system does not rely on a specific large language model, does not require special training for the code, is convenient and fast, can greatly shorten the development time, can flexibly handle changes in requirements under various specific scenarios, reduce repetitive time, and unify and standardize system development. The code generator is described in detail below. In the code generation system of the embodiment of the present disclosure, the code generator is divided into two types: a general code generator and a dedicated code generator. General code generator: that is, the commonly used large model code generation function. After the user describes the requirements, the large model directly generates code. The general code generator can be understood as a special case of a dedicated code generator. Special code generator: used to handle complex code generation process. Users describe their requirements and provide code examples. Based on the requirements and examples, the system automatically breaks down the generation process into multiple tasks, analyzes the dependencies between the tasks, generates prompt words, and finally solidifies the entire generation process into a special code generator. Different scenarios correspond to different special code generators. A process of using a general code generator to generate code is shown. This process is similar to the steps of the code generation method in the previous embodiment and will not be repeated here.A process of generating code using a dedicated code generator is shown, which is similar to the steps of the code generation method in the previous text and the embodiment, and will not be repeated here. In some embodiments, the composition of the dedicated code generator can be as shown, and the creation process of the dedicated code generator can be as shown. As shown, in the creation process of the dedicated code generator, the requirements and examples can be automatically parsed based on the large model and split into multiple tasks; the code generation process is composed of multiple tasks that are interrelated, and each task is executed separately or dependently; each task has its corresponding prompt word, input and output; the final generator is a task set, and can be generated and verified based on the example; the configuration of each generated task can be adjusted manually. As shown, the dedicated code generator is mainly based on the large model for example analysis and task disassembly. The prompt word template can be preset in advance, and the analysis and disassembly steps can be solidified in a framework through the prompt word. In addition, the operation list can be preset in advance, allowing the large model to autonomously select the operations to be performed, such as executing the "read file" operation to read the content of the sample code provided by the user, and then call the large model again for analysis through the prompt word. Based on multiple cycles of COT (Chain-of-Thought) and ReAct (Reasoning and Acting), the task set and dependency relationship are finally generated. The following is a detailed description of the embodiment of the present disclosure through a specific example. Source: Automatic generation of UI code of a certain team; Requirement: Generate front-end code for the interface based on the description document in markdown format of the interface; Requirement: The generated code needs to use the table controls, button controls and styles created by the team itself, and needs to include the search area and list display area, and the operation items need to be automatically added to the list; Result: Subsequent input of the description documents of other interfaces can automatically generate the corresponding front-end code. Implementation: Create a dedicated code generator suitable for this scenario. The tasks in the code generator are as follows: Task 1, find the interface for generating the list page from the interface document, and the judgment basis is: the object returned by the interface is an array, and other interfaces are used as operation items in the list page. Task 2, based on the input example, it is judged that the number of files that need to be generated in the end is four: the definition of enumeration (dictionary), the definition of model l class, api call and front-end UI. Task 3, based on the definition of the interface, generate file names for the four files respectively. Task 4, give the definitions of 4 files respectively. (1) Definition of enumeration: Source: Parameters with limited value ranges in the request data and return data of the interface; Purpose: When the front-end UI is presented, the numeric value is converted into a readable Chinese description, and the style is controlled; Dependencies: None. (2) Definition of model l class: Source: Parameters in the request data and return data of the interface; Purpose: Data objects used in the search box and the table control in the front-end UI page; Dependencies: None.(3) api call: source: main interface in the interface; purpose: in the front-end UI page, initialize and obtain the data in the table, or after resetting the search conditions, query again to obtain data; dependency: previously generated model l class. (4) front-end UI: source: definition of the main interface; purpose: display the front-end UI page; dependency: previously generated enumeration, model l class, api call; others: operation items in the table, other interfaces in the interface document input by the source. Task 5, based on the file definition and dependency, generate the final code file in the specified order. The embodiment of the present disclosure supports the generation of custom code that meets the specific needs of users. It only requires the user to provide a code example without any additional model training work. It supports the currently commonly used large models, and is loosely coupled to the large models without strong dependence. In the embodiment of the present disclosure, the terms "first", "second" and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. The term "and / or" in the present disclosure is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the objects associated with each other are in an "or" relationship. In addition, although the various steps of the method in the present disclosure are described in a specific order in the accompanying drawings, this does not require or imply that these steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. In some embodiments, certain steps can be omitted, multiple steps can be combined into one step for execution, and / or one step can be decomposed into multiple steps for execution, etc. Based on the same inventive concept, a code generation device is also provided in the embodiment of the present disclosure, as described in the following embodiments. Since the principle of solving the problem in the embodiment of the device is similar to that in the above-mentioned method embodiment, the implementation of the embodiment of the device can refer to the implementation of the above-mentioned method embodiment, and the repetitions will not be repeated. A schematic diagram of a code generation device in the embodiment of the present disclosure is shown, as shown, the code generation device includes an information acquisition module 1101, an analysis and processing module 1102, a prompt word determination module 1103 and a code generation module 1104. The information acquisition module 1101 is used to obtain the requirement description and sample code input by the user; the analysis and processing module 1102 is used to obtain multiple tasks and the dependencies between the multiple tasks based on the requirement description and the sample code, and the multiple tasks are used to generate the target code corresponding to the requirement description; the prompt word determination module 1103 is used to determine the prompt word matching each task in the preset prompt words; the code generation module 1104 is used to input the multiple tasks, the dependencies and the prompt words corresponding to each task into the large language model to obtain the target code corresponding to the requirement description. In some embodiments, one or more of the programming language, programming structure, and the technology stack or library used in the example target code are the same as the example code.In some embodiments, when the value of the sample code is empty, the code generation device further includes a data processing module. The data processing module is used to analyze the requirement description to determine the prompt words that match the requirement description in the preset prompt words; input the prompt words that match the requirement description into the large language model to obtain the target code corresponding to the requirement description. In some embodiments, the code generation device further includes a content adjustment module. The content adjustment module is used to receive a content adjustment request before inputting multiple tasks, dependencies, and prompt words corresponding to each task into the large language model, and the content adjustment request is used to adjust one or more of the prompt words corresponding to multiple tasks, dependencies, and each task. In some embodiments, the code generation module 1104 is used to input multiple tasks, dependencies, and prompt words corresponding to each task into the large language model to obtain a first code; based on the requirement description and the sample code, the first code is verified; if the verification passes, the first code is used as the target code. In some embodiments, the code generation module 1104 is also used to re-execute the requirements description and the sample code in the case of failure of verification, obtain multiple tasks and the dependencies between the multiple tasks, determine the prompt words matching each task in the preset prompt words, input the multiple tasks, the dependencies and the prompt words corresponding to each task into the large language model, and obtain the target code corresponding to the requirements description. The concepts of "first", "second" and the like mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units. Regarding the code generation device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment of the code generation method, and will not be elaborated in detail here. It should be noted that although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiment of the present disclosure, the features and functions of the two or more modules or units described above can be concretized in one module or unit. On the contrary, the features and functions of a module or unit described above can be further divided into multiple modules or units to be concretized. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices. The electronic device provided by the embodiment of the present disclosure is described with reference below. The electronic device 1200 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiment of the present disclosure. An architectural schematic diagram of an electronic device 1200 provided by the present embodiment is shown. As shown, the electronic device 1200 includes, but is not limited to: at least one processor 1210, at least one memory 1220.Memory 1220, for storing instructions. In some embodiments, memory 1220 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 12201 and / or a cache memory unit 12202, and may further include a read-only memory unit (ROM) 12203. In some embodiments, memory 1220 may also include a program / utility 12204 having a set (at least one) of program modules 12205, such program modules 12205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or a combination thereof may include the implementation of a network environment. In some embodiments, memory 1220 may store an operating system. The operating system may be an operating system such as a real-time operating system (RTX), LINUX, UNIX, WINDOWS, or OS X. In some embodiments, data may also be stored in memory 1220. As an example, processor 1210 may read data stored in memory 1220, which may be stored at the same storage address as the instruction, or may be stored at a different storage address than the instruction. The processor 1210 is used to call the instructions stored in the memory 1220 to implement the steps of various exemplary embodiments of the present disclosure described in the "Exemplary Method" section of the specification. For example, the processor 1210 can execute the steps of the above-mentioned code generation method embodiment. It should be noted that the above-mentioned processor 1210 can be a general-purpose processor or a special-purpose processor. The processor 1210 may include one or more processing cores, and the processor 1210 executes various functional applications and data processing by running instructions. In some embodiments, the processor 1210 may include a central processing unit (CPU) and / or a baseband processor. In some embodiments, the processor 1210 may determine an instruction based on the priority identification and / or function category information carried in each control instruction. In the present disclosure, the processor 1210 and the memory 1220 may be set separately or integrated together. As an example, the processor 1210 and the memory 1220 may be integrated on a single board or a system-on-chip (SOC). As shown, the electronic device 1200 is presented in the form of a general-purpose computing device. The electronic device 1200 may also include a bus 1230. The bus 1230 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures.The electronic device 1200 may also communicate with one or more external devices 1240 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1200, and / or communicate with any device that enables the electronic device 1200 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed through an input / output (I / O) interface 1250. In addition, the electronic device 1200 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 1260. As shown, the network adapter 1260 communicates with other modules of the electronic device 1200 through a bus 1230. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1200, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc. It is understood that the structure illustrated in the embodiment of the present disclosure does not constitute a specific limitation on the electronic device 1200. In other embodiments of the present disclosure, the electronic device 1200 may include more or fewer components than shown, or combine certain components, or split certain components, or arrange different components. The components shown may be implemented in hardware, software, or a combination of software and hardware. The present disclosure also provides a computer-readable storage medium on which computer instructions are stored, and when the computer instructions are executed by a processor, the code generation method described in the above method embodiment is implemented. In the embodiment of the present disclosure, the computer-readable storage medium is a computer instruction that can be sent, propagated, or transmitted for use by an instruction execution system, device, or device or used in combination with it. As an example, the computer-readable storage medium is a non-volatile storage medium. In some embodiments, more specific examples of computer-readable storage media in the present disclosure may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, a U disk, a mobile hard disk, or any suitable combination of the above. In the disclosed embodiments, the computer-readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer instruction (readable program code). Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. In some examples, the computing instructions contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above.The embodiment of the present disclosure also provides a computer program product, which stores instructions, and when the instructions are executed by a computer, the computer implements the code generation method described in the above method embodiment. The above instructions can be program codes. In specific implementation, the program code can be written by any combination of one or more programming languages. The programming language includes object-oriented programming languages, such as Java, C++, etc., and also includes conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed completely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device, partially on the remote computing device, or completely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet). The embodiment of the present disclosure also provides a chip, including at least one processor and an interface; the interface is used to provide program instructions or data to at least one processor; at least one processor is used to execute program instructions to implement the code generation method described in the above method embodiment. In some embodiments, the chip may also include a memory, which is used to store program instructions and data, and the memory is located within or outside the processor. It can be understood by those of ordinary skill in the art that all or part of the steps for implementing the above-mentioned embodiments can be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation combining hardware and software, which can be collectively referred to as "circuit", "module" or "system" here. After considering the specification and practicing the invention disclosed herein, it will be easy for those skilled in the art to think of other embodiments of the present disclosure. The present disclosure is intended to cover any variants, uses or adaptive changes of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and embodiments are regarded as exemplary only, and the true scope and spirit of the present disclosure are indicated by the attached claims.

Claims

1. A code generation method, characterized in that: include: Get the requirement description and sample code input by the user; Based on the requirement description and the sample code, a plurality of tasks and dependencies between the plurality of tasks are obtained, wherein the plurality of tasks are used to generate target codes corresponding to the requirement description; Determine the prompt word matching each task from the preset prompt words; The multiple tasks, the dependency relationships, and the prompt words corresponding to each task are input into a large language model to obtain a target code corresponding to the requirement description.

2. The method according to claim 1, characterized in that One or more of the programming language, programming structure, and used technology stack or library of the example object code is the same as that of the example code.

3. The method according to claim 1, characterized in that In the case where the value of the example code is empty, the method further includes: Analyze the requirement description to determine a prompt word matching the requirement description from preset prompt words; The prompt words matching the requirement description are input into the large language model to obtain the target code corresponding to the requirement description.

4. The method according to claim 1, characterized in that: Before inputting the plurality of tasks, the dependency relationships and the prompt words corresponding to each task into the large language model, the method further includes: A content adjustment request is received, where the content adjustment request is used to adjust one or more of the plurality of tasks, the dependency relationships, and a prompt word corresponding to each task.

5. The method according to claim 1, characterized in that The step of inputting the plurality of tasks, the dependency relationships, and the prompt words corresponding to each task into a large language model to obtain a target code corresponding to the requirement description includes: Input the plurality of tasks, the dependency relationships, and the prompt words corresponding to each task into a large language model to obtain a first code; Based on the requirement description and the sample code, verify the first code; If the verification is passed, the first code is used as the target code.

6. The method according to claim 5, characterized in that The method further comprises: If the verification fails, the method based on the requirement description and the sample code is re-executed to obtain multiple tasks and dependencies between the multiple tasks, a prompt word matching each task is determined from preset prompt words, the multiple tasks, the dependencies and the prompt word corresponding to each task are input into a large language model to obtain a target code corresponding to the requirement description.

7. A code generating device, characterized in that: include: Information acquisition module, used to obtain the requirement description and sample code input by the user; An analysis and processing module, used to obtain a plurality of tasks and dependencies between the plurality of tasks based on the requirement description and the sample code, wherein the plurality of tasks are used to generate target codes corresponding to the requirement description; A prompt word determination module, used to determine a prompt word matching each task from preset prompt words; The code generation module is used to input the multiple tasks, the dependency relationships and the prompt words corresponding to each task into a large language model to obtain a target code corresponding to the requirement description.

8. An electronic device, characterized in that: include: A memory for storing instructions; A processor, configured to call instructions stored in the memory to implement the code generation method according to any one of claims 1 to 6.

9. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by a processor, the code generation method described in any one of claims 1 to 6 is implemented.

10. A computer program product, characterized in that The computer program product stores instructions, and when the instructions are executed by a computer, the computer implements the code generation method according to any one of claims 1 to 6.

Citation Information

Cited By

  • Multi-source heterogeneous hybrid code unified standardization method oriented to intelligent model service

    CN120085845A

  • Method and device for processing data by using intelligent agent, equipment, medium and product

    CN120181126A

  • Target embedded code generation method and device, electronic equipment and storage medium

    CN120704694A