Code generation method and device, equipment, medium and product
Through multi-level requirements analysis and code recall mechanisms, the target code is generated, which solves the shortcomings of existing code generation methods in terms of code quality and accuracy, and achieves efficient and accurate code generation.
Patent Information
- Application Number
- CN202510414054.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-05-02
AI Technical Summary
The existing automated code generation methods have shortcomings in the quality and accuracy of generated codes, making it difficult to ensure that the generated code can accurately meet actual needs and improve the aesthetics, efficiency and practicality of code generation.
By responding to user input, multiple levels of demand description information are determined, and corresponding reference code snippets are recalled from the code center, and target code input is generated based on this information.
It realizes efficient and accurate code generation, improves code quality and accuracy, can better meet user needs, and improves the efficiency and aesthetics of code generation.
Smart Images

Figure CN119917108A_ABST
Abstract
Description
Technical Field
[0001] Example embodiments of the present disclosure generally relate to the field of computers, and more particularly, to methods, devices, apparatuses, and computer-readable storage media for code generation. Background Art
[0002] With the rapid development of Internet technology and the continuous evolution of software development technology, automated code generation has become an important means to improve development efficiency. However, as development requirements become increasingly complex, existing automated code generation methods still have certain deficiencies in terms of the quality and accuracy of generated code. How to ensure that the generated code can accurately meet actual needs and further improve the aesthetics, efficiency and practicality of code generation has become an urgent problem to be solved. Summary of the invention
[0003] In a first aspect of the present disclosure, a method for code generation is provided. The method includes: in response to receiving a user input indicating a code generation requirement, based on the user input, determining multiple pieces of requirement description information corresponding to multiple levels, wherein the requirement description information in the multiple pieces of requirement description information indicates the code requirements of the code generation requirement at the corresponding level; based on at least a part of the multiple pieces of requirement description information, determining at least one reference code fragment from a code set, wherein the code set includes at least multiple code fragments corresponding to the multiple levels and corresponding description information of the multiple code fragments; and generating a target code for the user input based on information related to the at least one reference code fragment.
[0004] In a second aspect of the present disclosure, a device for code generation is provided. The device includes: a requirement determination module, configured to, in response to receiving a user input indicating a code generation requirement, determine, based on the user input, multiple requirement description information corresponding to multiple levels respectively, wherein the requirement description information in the multiple requirement description information indicates the code requirements of the code generation requirement at the corresponding level; a reference code determination module, configured to, based on at least a part of the multiple requirement description information, determine at least one reference code fragment from a code set, wherein the code set includes at least multiple code fragments corresponding to the multiple levels and corresponding description information of the multiple code fragments; and a generation module, configured to generate a target code for the user input based on information related to the at least one reference code fragment.
[0005] In a third aspect of the present disclosure, an electronic device is provided. The device includes at least one processing unit; and at least one memory, the at least one memory is coupled to the at least one processing unit and stores instructions for execution by the at least one processing unit. When the instructions are executed by the at least one processing unit, the device executes the method of the first aspect.
[0006] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and the computer program can be executed by a processor to implement the method of the first aspect.
[0007] In a fifth aspect of the present disclosure, a computer program product is provided, which includes a computer program, wherein when the computer program is executed by a processor, the method according to the first aspect of the present disclosure is implemented.
[0008] It should be understood that the contents described in this content section are not intended to limit the key features or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein: Figure 1 A schematic diagram showing an example environment in which embodiments of the present disclosure can be implemented; Figure 2 A flowchart showing a process of code generation according to some embodiments of the present disclosure is shown; Figure 3 A schematic diagram showing an example process of code generation according to some embodiments of the present disclosure is shown; Figure 4 A schematic structural block diagram of an apparatus for code generation according to some embodiments of the present disclosure is shown; and Figure 5 A block diagram of an electronic device is shown in which one or more embodiments of the present disclosure may be implemented. DETAILED DESCRIPTION
[0010] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0011] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The term "some embodiments" should be understood as "at least some embodiments". Other explicit and implicit definitions may also be included below.
[0012] As used herein, the term "model" can learn the association between the corresponding input and output from the training data, so that after the training is completed, the corresponding output can be generated for a given input. The generation of the model can be based on machine learning technology. Deep learning is a machine learning algorithm that processes inputs and provides corresponding outputs by using multiple layers of processing units. In this article, "model" may also be referred to as "machine learning model", "machine learning network", "neural network" or "network", and these terms are used interchangeably in this article.
[0013] Herein, unless explicitly stated, executing a step “in response to A” does not mean executing the step immediately after “A” but may include one or more intermediate steps.
[0014] It is understandable 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 relevant laws, regulations and relevant provisions.
[0015] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. 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.
[0016] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information, so that the user can independently choose whether to provide personal information to software or hardware such as electronic devices, applications, servers or storage media that execute operations of the technical solution of the present disclosure based on the prompt message.
[0017] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information is sent to the user in a manner such as a pop-up window, in which the prompt information can be presented in text form. 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.
[0018] 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 relevant laws and regulations may also be applied to the implementation of the present disclosure.
[0019] Figure 1 A schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented is shown. Environment 100 involves a platform 110, which can support the creation of applications and / or the running of applications. In some embodiments, the portion of platform 110 used to support application creation can also be referred to as an application creation portion. In some embodiments, the portion of platform 110 used to support application running can also be referred to as an application running portion.
[0020] like Figure 1 As shown, the application creation part can provide a user 105 with an environment for creating and publishing applications. User 105 can be referred to as an application creation user or creator. In some embodiments, the application creation part can be a low-code platform that provides a collection of tools for application creation. The application creation part can support visual development of various types of applications, so that developers can skip the manual coding process and speed up the application development cycle and cost. The application creation part can support any appropriate platform for users to develop one or more types of applications, for example, it can include a platform based on application platform as a service (aPaaS). Such a platform can support users to efficiently develop applications and realize operations such as application creation and application function adjustment.
[0021] The application creation part can be deployed locally on the terminal device of user 105, and / or can be supported by a server-side device. For example, the terminal device of user 105 can run a client of the application creation part, which can support the interaction between the user and the application creation part provided by the server. In the case where the application creation part runs locally on the user's terminal device, the user 105 can directly interact with the local application creation part using the terminal device. In the case where the application creation part runs on the server-side device, the server-side device can, based on the communication connection with the terminal device, implement service provision for the client running in the terminal device. The application creation part can present a corresponding page 130 to the user 105 based on the operation of the user 105, so as to output to the user 105 and / or receive from the user 105 information related to application creation.
[0022] In some embodiments, the application creation part can be associated with a corresponding database, which stores data or information required for the application creation process supported by the application creation part. For example, the database can store the code and description information corresponding to each functional module that constitutes the application. The application creation part can also perform operations such as calling, adding, deleting, and updating the functional modules in the database. The database can also store operations that can be performed on different functional blocks. Exemplarily, in a scenario where an application is to be created, the application creation part can call the corresponding functional blocks from the database to build the application.
[0023] In an embodiment of the present disclosure, the user 105 can create a target application 120 as needed on the application creation part and publish the target application 120. The target application 120 can be published to any appropriate application running part, as long as the application running part can support the operation of the target application 120. After publishing, the target application 120 can be used to be operated by one or more terminal users 145. The terminal user 145 can operate the target application 120 through an associated terminal device, and then interact with the platform 110. The terminal user 145 can be referred to as the terminal user of the target application 120. In some embodiments, the target application 120 may include or be implemented as a digital assistant 122.
[0024] The digital assistant 122 may be configured to have intelligent conversation capabilities. Figure 1 In the example shown, the digital assistant 122 can be integrated into the target application 120 to assist in performing task processing within the target application 120 as part of the target application 120. In other examples, the digital assistant 122 can be configured as an independently running application, such as a web application or other types of applications. In such an example, the digital assistant 122 and the target application 120 can be regarded as the same application. The digital assistant 122 is provided to assist users with various task processing requirements in different applications and scenarios. During the interaction with the digital assistant 122, the user inputs an interactive message, and the digital assistant 122 provides a reply message in response to the user input. Typically, the digital assistant 122 can support users to input questions in natural language, and perform tasks and provide replies based on the understanding of natural language input and logical reasoning ability.
[0025] In some embodiments, the digital assistant 122 can interact with the terminal user 145 as a contact. For example, the digital assistant 122 can be implemented in an instant messaging (IM) application. The digital assistant 122 can interact with the terminal user 145 in a single chat session with the terminal user 145. In some embodiments, the digital assistant 122 can interact with multiple users in a group chat session including multiple users.
[0026] For each terminal user 145, the client of the application running part can present an interactive window 142 of the target application 120 or the digital assistant 122 in the client interface, such as a conversation window with the digital assistant 122. The terminal user 145 can enter a conversation message in the conversation window, and the target application 120 can determine the reply message of the digital assistant 122 based on the created configuration information and present it to the user in the interactive window 142. In some embodiments, depending on the configuration of the target application 120, the interactive message with the target application 120 may include a message in a multimodal form, such as a text message (e.g., a natural language text), a voice message, an image message, a video message, and the like.
[0027] Similar to the application creation part, the application running part can be deployed locally on the terminal device of each terminal user 145, and / or can be supported by the server device. For example, the terminal device of the terminal user 145 can run a client with the application running part, and the client can support the interaction between the user and the application running part provided by the server. In the case where the application running part runs locally on the user's terminal device, the terminal user 145 can directly use the terminal device to interact with the local application running part. In the case where the application running part runs on the server device, the server device can realize the service supply to the client running in the terminal device based on the communication connection with the terminal device. The application running part can present the corresponding application page to the terminal user 145 based on the operation of the terminal user 145, so as to output and / or receive information related to the use of the application to the terminal user 145.
[0028] In some embodiments, the implementation of at least part of the functions of the target application 120 and / or the implementation of at least part of the functions of the digital assistant 122 in the target application 120 can be implemented based on the model. During the creation or operation of the target application 120, one or more models 155, such as the capabilities of the model 155, can be called. In the target application 120, the digital assistant 122 can use the model 155 to understand the user input and provide a reply to the user based on the output of the model 155.
[0029] During the creation process, the platform 110 needs to use the model 155 to test the target application 120 to determine whether the operation result of the target application 120 meets expectations. During the operation process, in response to different operation requests of the user of the target application 120, the application operation part may need to use the model 155 to determine the response result to the user.
[0030] Although shown as being independent of platform 110, one or more models 155 may run on platform 110, or other remote servers. In some embodiments, model 155 may be a machine learning model, a deep learning model, a learning model, a neural network, etc. In some embodiments, the model may be based on a language model (LM), such as a large language model (LLM). The language model can have question-answering capabilities by learning from a large amount of corpus. Model 155 may also be based on other appropriate models.
[0031] The platform 110 can run on appropriate electronic devices. The electronic devices here can be any type of device with computing capabilities, including terminal devices or server devices. The terminal device can be any type of mobile terminal, fixed terminal or portable terminal, including mobile phones, desktop computers, laptop computers, notebook computers, netbook computers, tablet computers, media computers, multimedia tablets, personal communication systems (PCS) devices, personal navigation devices, personal digital assistants (PDAs), audio / video players, digital cameras / camcorders, positioning devices, television receivers, radio broadcast receivers, e-book devices, gaming devices, or any combination of the foregoing, including accessories and peripherals of these devices or any combination thereof. The server device can include, for example, a computing system / server, such as a mainframe, an edge computing node, a computing device in a cloud environment, and the like. In some embodiments, the platform 110 can be implemented based on cloud services.
[0032] It should be understood that the structure and functionality of environment 100 are described for exemplary purposes only and do not imply any limitation on the scope of the present disclosure. For example, although a single user interacting with the application creation portion and a single user interacting with the application execution portion are shown, in reality multiple users can access platform 110 to each create a digital assistant, and each digital assistant can be used to interact with multiple users.
[0033] As briefly mentioned above, with the continuous advancement of machine learning, natural language processing, and code generation technologies, the feasibility and application scenarios of automatic code generation have received widespread attention. With the continuous changes in software development requirements and the rapid development of technology, automatic code generation has gradually become a key technology to improve development efficiency and quality. Especially in scenarios such as front-end interface construction, back-end business logic implementation, and application programming interface (API) generation. However, traditional code generation methods still face many challenges. The following describes several typical scenarios.
[0034] A typical scenario involves the problem of code generation efficiency. Specifically, traditional code generation methods often have difficulty accurately understanding user needs and efficiently reusing existing code implementations. This may lead to reduced efficiency of the generated code, and it may not match the existing structure and variable naming of the project, and may not fully meet user needs.
[0035] Another typical scenario involves code generation quality issues. For example, when developing front-end pages, different developers may use different implementation styles and state management methods. Conventional code generation methods usually only focus on basic functional implementations and lack style uniformity control. This may lead to low quality of generated code, especially in terms of page aesthetics and code accuracy.
[0036] In view of this, according to an embodiment of the present disclosure, an improved scheme for code generation is proposed to at least partially solve one or more of the above-mentioned problems. In this scheme, if a user input indicating a code generation requirement is received, based on the user input, multiple pieces of requirement description information corresponding to multiple levels can be determined. The requirement description information in the multiple pieces of requirement description information indicates the code requirements of the code generation requirement at the corresponding level. Further, based on at least a part of the multiple pieces of requirement description information, at least one reference code fragment can be determined from a code set, and the code set at least includes multiple code fragments corresponding to multiple levels and corresponding description information of the multiple code fragments. And based on information related to at least one reference code fragment, a target code for the user input can be generated.
[0037] In the embodiments of the present disclosure, efficient and accurate code generation is achieved through multi-level requirements analysis and code recall mechanism. Automatically decomposing user requirements into multiple different levels and matching and reusing existing code snippets in the code set can improve the accuracy and quality of code generation. In this way, code generation tasks for various development scenarios such as front-end pages, back-end logic, and API interfaces can be completed, effectively improving code quality.
[0038] Some example embodiments of the present disclosure will be described in detail below with reference to examples of the accompanying drawings.
[0039] In an embodiment of the present disclosure, the code may include various suitable types of computer languages, including but not limited to front-end page code, back-end business logic code, database operation code, API interface code, script code, automated configuration code, data processing code, etc., and is applicable to different development scenarios and technology stacks. For example, the generated code can be used for any suitable scenario such as machine learning model deployment, system configuration, infrastructure management, etc. The code generation process described in the embodiment of the present disclosure can be implemented on a code generation platform, a terminal device equipped with a code generation platform, and / or a server corresponding to the code generation platform. For example, if the code is used for application creation or maintenance, the code generation process can be implemented on an application management platform.
[0040] In the following examples, for the sake of discussion, the platform is used as the starting point for description, for example Figure 1 The platform 110 shown. The user interface presented by the platform 110 can be presented via the terminal device of the user 105, and the platform 110 can receive user input via the terminal device of the user 105. For example, the code generation to be described below can be implemented in the process of the user 105 creating the target application 120. In some embodiments of the present disclosure, the user 105 is the creator, manager or maintainer of the target application 120. The embodiments of the present disclosure will be described below mainly with reference to the user 105, but it should be understood that the code generation to be described below can also be implemented in the use process of the target application 120, for example, the target application 120 is an application for application creation or maintenance.
[0041] Figure 2 1 shows a flow chart of a code generation process 200 according to some embodiments of the present disclosure. The code generation process may be implemented by the running part of the platform 110, for example, by the target application 120. Figure 1 To describe Figure 2 The code generation process shown. It should be understood that Figure 2 The various steps in the above are merely exemplary and do not limit the solutions of the present disclosure.
[0042] In some embodiments, the platform 110 may receive user input indicating a code generation requirement. The user input may be input information provided by the user 105 to the platform 110 to describe its code generation requirement. The input may be a brief text description, or may be a more specific request for code modification or generation.
[0043] In some examples, the user input may include a natural language description (e.g., "generate a login page"), a structured input (e.g., an input including structured parameters). Alternatively or additionally, the user 105 may provide an existing code file or a configuration file of an existing project and describe the part that is desired to be modified or extended as the user input.
[0044] In box 210, after receiving user input, platform 110 can determine multiple requirements description information corresponding to multiple levels based on the user input. The requirements description information can indicate the code requirements of the user's code generation requirements at the corresponding level. The code generation requirements of user 105 are often not single, but are jointly determined by multiple levels of information. For example, user 105 may want to develop a complete application, and the requirement can be broken down into multiple levels of information. Therefore, after receiving user input, platform 110 can parse the input and extract multiple levels of requirements description information. These requirements description information can involve different development tasks or code structure levels, thereby forming a hierarchical requirements description system.
[0045] In some embodiments, the multiple levels corresponding to the multiple requirement description information can be determined based on the specific user requirements and the organization method of the code corresponding to the requirements. For example, the multiple levels can include application level, page level and component level, where each level corresponds to a different granularity of code organization method and requirement decomposition method.
[0046] In some embodiments, the multiple levels may correspond to different types of code generation requirements, including more, fewer, or other different hierarchical structures. For example, in a backend development scenario, the multiple levels may include application layer, module layer, interface layer, logic layer, etc. In a database development scenario, the multiple levels may include database architecture layer, data table layer, field layer, etc.
[0047] In some embodiments, the platform 110 can generate extended description information corresponding to the code generation requirements by supplementing the user input. For example, the user input may be incomplete and lack key details for code generation. For example, the user input is "create a login page", but the input does not specify what functions the page needs to include, nor does it specify information such as user interface (UI) design requirements. Therefore, the code generated directly based on the user input may not fully meet the user's needs.
[0048] In this case, the platform 110 can supplement the vague or brief user input into more complete and executable extended description information. For example, the platform 110 can use the model 155 (such as a large language model) to infer and supplement the details of the requirements, thereby determining the extended description information.
[0049] In some embodiments, the platform 110 can decompose the extended description information according to multiple levels to determine multiple demand description information corresponding to the multiple levels. The supplemented extended description information is usually still a complete description, so the platform 110 can further decompose the extended description information according to multiple levels so that the determined multiple demand description information can match the user needs at different levels.
[0050] As an example, the platform 110 can use the large language model to supplement the received user input: "Develop an e-commerce application homepage, including product display, search, shopping cart and personal account management functions", thereby obtaining extended demand information. The extended demand information is, for example: "Please develop a user-friendly e-commerce application homepage, including high-quality product display, real-time search function, intuitive shopping cart preview, and convenient personal account management entrance. The page design should be beautiful and have a responsive layout to enhance the user's shopping experience and interactive feeling."
[0051] Furthermore, the platform 110 may decompose the extended requirement information into multiple levels, thereby determining multiple requirement description information corresponding to multiple levels. For example, the platform 110 decomposes the extended requirement information in the above example into description information corresponding to an independent page, and specifies the specific function of the page. As an example, Table 1 shows an example of requirement description information at the page level.
[0052] Table 1 Example of page-level requirement description information
[0053] As shown in Table 1, the page-level requirement description information may include the page name, description of specific functional modules within the page, such as product display, search function, etc. Alternatively or additionally, the page-level requirement description information may include information such as page experience requirements and data interaction requirements, so as to ensure that the functional design of the page is clear and facilitate implementation according to a reasonable structure during code generation.
[0054] The platform 110 can further decompose each function of the page into independent, reusable component description information, each component having a clear functional description. As an example, Table 2 shows multiple examples of component-level requirement description information corresponding to the page.
[0055] Table 2 Multiple examples of component-level requirement description information
[0056] As shown in Table 2, the component-level requirement description information may include categories of various components included in the page, such as a navigation bar, a search box, a button, a product list, etc. Alternatively or additionally, the component-level requirement description information may include detailed description information of components of various categories to indicate specific functions of the components.
[0057] In some examples, the requirement description information may adopt a predetermined format to ensure a clear structure and easy parsing, for example, using the Extensible Markup Language (XML) format to organize and represent the requirement description information.
[0058] In some embodiments, if the input of the user 105 is sufficiently clear (for example, the user input "add a page" or "add a component" for the code file provided by the user 105 or the historical code file generated by the platform 110), the platform 110 may not perform the aforementioned process of decomposing the requirement description information into multiple levels. In this case, the platform 110 may use the model 155 to generate code that meets the user's requirements based on the context information of the user's input requirements, or update the existing code.
[0059] Continue to refer Figure 2 In block 220, the platform 110 may determine at least one reference code snippet from a code set based on at least a portion of the multiple requirement description information. A code set may be understood as a structured and organized code database that stores a large number of reusable and referenceable code snippets.
[0060] In the code generation task, relying on the machine learning model to directly generate code may cause the code structure generated by the model to be chaotic and not meet user needs. In addition, if the model generates code from scratch every time, instead of reusing existing high-quality code snippets as much as possible, it is easy to cause redundant code and reduce the efficiency of code generation. To this end, in some embodiments of the present disclosure, a retrieval-augmented generation (RAG) method is introduced. By combining code sets for code retrieval and generation, the generated code can not only reuse existing high-quality code snippets, but also better meet the specific needs of users.
[0061] The traditional RAG method may have problems such as confusing code organization levels and unreasonable code snippet combinations when facing complex code requirements. To this end, in some embodiments of the present disclosure, the code snippets in the code set can be divided and managed according to multiple levels corresponding to the requirement description information, so as to facilitate matching with multiple levels of user requirements.
[0062] In some embodiments, the code set includes at least a plurality of code snippets corresponding to a plurality of levels and corresponding description information of the plurality of code snippets. The description information of the code snippets may include an offline code representation, i.e., structured description information of the code snippets. The code snippets may be analyzed and characterized in advance, and the corresponding description information of the code snippets may be stored. In this way, the platform 110 may match the corresponding description information of the code snippets in the code set with the requirement description information corresponding to a plurality of levels, without directly analyzing the specific content of the code. In this way, the efficiency and accuracy of the recall of the reference code snippets may be improved.
[0063] In some embodiments, the description information of the code snippet includes at least one of the following: the name of the code snippet, the level corresponding to the code snippet, the storage location of the code snippet, the component category corresponding to the code snippet, or the summary information of the code snippet. As an example, Table 3 shows an example of the description information of the code snippet.
[0064] Table 3 Example of description information of code snippet
[0065] In some embodiments, the summary information of the code snippet can be generated using a machine learning model based on a predetermined prompt word. For example, the platform 110 can use a large language model to analyze the function, input and output parameters, applicable scenarios, and other information of the code snippet, and convert it into text described in natural language.
[0066] In some embodiments, the platform 110 can determine at least a portion of at least one reference code snippet from multiple code snippets corresponding to the level in the code set based on the requirement description information corresponding to the level in the multiple levels. The requirements of the user 105 are broken down into requirement description information corresponding to multiple levels, and the code set also stores code snippets that can be used for reference corresponding to multiple levels. When generating code, the platform 110 can determine the most matching code snippet from the code set for a specific level as at least a portion of the reference code snippet.
[0067] Figure 3 FIG. 3 is a schematic diagram of an example code generation process 300 according to some embodiments of the present disclosure. The example process 300 may be implemented by the operating part of the platform 110. Figure 3As shown, the platform 110 determines multiple demand description information corresponding to multiple levels based on the received user input 305. The platform 110 can gradually disassemble the corresponding demand description information according to the predetermined multiple hierarchical structures. For example, the first demand description information 311 corresponding to the application level. The application level corresponds to the overall architecture and organization of the entire application or large functional module, and its main focus is, for example, on the overall functions and business processes of the application, the interaction between the front and back ends, data storage and management, etc.
[0068] In some examples, an application is usually composed of multiple pages. The page level can correspond to a specific page or functional interface in the application. In this case, the first requirement description information 311 at the application level can be further decomposed into several items of second requirement description information 321 at the page level. For example, Figure 3 Second requirement description information 321 - 1 to second requirement description information 321 -N are shown, where N is a positive integer greater than or equal to 1.
[0069] In some examples, each page may include multiple components. The page hierarchy may correspond to reusable small code units in the page, such as UI components or other functional components. In this case, each item of the second requirement description information 321 at the page level may be further decomposed into several items of the third requirement description information 331 at the component level. For example, the second requirement description information 321-1 may be decomposed into M items of the third requirement description information 331-1, and the second requirement description information 321-N may be decomposed into M items of the third requirement description information 331-N, where M is a positive integer greater than or equal to 1.
[0070] Continue to refer Figure 3 In some embodiments, the platform 110 may determine a corresponding first similarity between corresponding description information of a plurality of first code snippets corresponding to the application level in the code set 301 and the first requirement description information 311 corresponding to the application level.
[0071] As an example, the platform 110 may determine the corresponding first similarity based on the text similarity between the corresponding description information of the first code snippet and the first requirement description information 311. For example, the platform 110 may convert the corresponding description information of each code snippet corresponding to the application level in the code set 301 and the first requirement description information 311 into vectors through a natural language processing model, and calculate their cosine similarity. After initially recalling several first code snippets, the platform 110 may use a large language model to reorder the candidate code snippets to ensure that the most relevant code snippets are ranked higher.
[0072] Continue to refer Figure 3, in box 310, the platform 110 determines whether the first similarity is greater than or equal to the first threshold similarity. If it is determined that the first similarity between the description information of at least one first code snippet among the multiple first code snippets and the first requirement description information 311 is greater than or equal to the first threshold similarity, the platform 110 can determine the at least one first code snippet as at least one reference code snippet. For example, if the platform 110 determines that the first similarity between a certain first code snippet and the first requirement description information 311 is greater than the set threshold T1, the platform 110 can determine the code snippet as a reference code snippet (for example, at least a portion of the context information 342). In the subsequent generation process, the platform 110 can directly reuse the code snippet at the application level or update the code snippet based on the corresponding user requirements to generate the target code.
[0073] Continue to refer Figure 3 If it is determined that the corresponding first similarities are all less than the first threshold similarity, the platform 110 can enter the next level of matching process. The platform 110 determines the corresponding second similarity between the description information of the plurality of second code snippets corresponding to the page level in the code set 302 and the at least one second requirement description information 321 corresponding to the page level.
[0074] In box 320, the platform 110 determines whether the second similarity is greater than or equal to the second threshold similarity. If it is determined that the second similarity between the description information of at least one second code snippet among the multiple second code snippets and at least one second requirement description information 321 is greater than or equal to the second threshold similarity, the platform 110 determines at least one second code snippet as at least one reference code snippet. For example, if the platform 110 determines that the second similarity between a second code snippet and the second requirement description information 321 is greater than the set threshold T2, the platform 110 can determine the code snippet as a reference code snippet (for example, at least a portion of the context information 342). In the subsequent generation process, the platform 110 can directly reuse the code snippet at the page level or update the corresponding user requirements based on the code snippet to generate the target code. The above process can be repeated N times to determine the code snippet that best matches each second requirement description information 321, where N is the number of second requirement description information 321.
[0075] In some embodiments, for a second code snippet among multiple second code snippets, the platform 110 may determine a corresponding second similarity based on a textual similarity between the description information of the second code snippet and at least one item of second requirement description information 321, or at least one of the number of components indicated by the description information of the second code snippet that match the components indicated by at least one item of second requirement description information 321.
[0076] As an example, the platform 110 may determine the second similarity by combining text similarity calculation with component tag matching. For example, the platform 110 may use a natural language processing model (such as similarity calculation based on vector embedding) to compare the text similarity between the description information of the second code snippet and at least one second requirement description information 321. In addition, the platform 110 may analyze the tag information of the code snippet, such as the component type contained in the page, and calculate the matching degree with the component type specified in the second requirement description information 321 based on the number of matched components. The platform 110 may determine the final second similarity based on the weighted calculation of the text similarity score and the component matching score, and screen the most suitable page-level code snippet accordingly.
[0077] Continue to refer Figure 3 If the platform 110 determines that each second similarity is less than the second threshold similarity, the platform 110 may determine a corresponding third similarity between the description information of the plurality of third code snippets corresponding to the component level in the code set 303 and the at least one third requirement description information 331 corresponding to the component level.
[0078] At block 330 , the platform 110 determines whether the third similarity is greater than or equal to a third threshold similarity. If it is determined that the third similarity between the description information of at least one third code snippet among the plurality of third code snippets and the at least one item of third requirement description information 331 is greater than or equal to the third threshold similarity, the at least one third code snippet is determined as at least one reference code snippet (e.g., at least a portion of the context information 342 ).
[0079] As an example, the platform 110 can determine whether the code snippet at the component level matches the user requirements based on text similarity calculation. Alternatively or additionally, the platform 110 can further utilize the functional characteristics matching of the components to improve the screening accuracy. For example, the platform 110 can first calculate the text similarity between the description information of the third code snippet and the third requirement description information 331. If the similarity is higher than the set third threshold T3, the code snippet is selected as the reference code snippet. In addition, the platform 110 can further analyze the component type, functional description and interaction mode of the code snippet to ensure that the selected component meets the requirements. The above process can be repeated M times to determine the code snippet that best matches each third requirement description information 331, where M is the number of third requirement description information 331.
[0080] In some embodiments, the first threshold similarity is greater than the second threshold similarity, and the second threshold similarity is greater than the third threshold similarity. By setting a higher matching requirement for the determination of a higher level of reference code, the reference code snippet can be highly matched with the user's needs, thereby further improving the quality of code generation. In addition, the level-by-level matching method in this way can also avoid excessive disassembly of the code snippet at the minimum granularity level, thereby improving the efficiency of code generation.
[0081] Return to reference Figure 2 In block 230, the platform 110 generates a target code for the user input based on information related to at least one reference code snippet. In some embodiments, the platform 110 generates prompt information based on multiple requirement description information and at least one reference code snippet. The platform 110 may provide the prompt information to the machine learning model 155 to obtain an output of the machine learning model 155. The platform 110 may determine the target code based on the output of the machine learning model. The target code includes multiple code snippets corresponding to multiple levels of requirement description information.
[0082] refer to Figure 3 , the prompt information may include context information 342. The context information 342 may be composed of requirement description information indicating the code generation requirement of the user 105 and a plurality of recalled reference code snippets. Alternatively or additionally, the context information 342 may also include historical conversation data 341 and reference information indicating information such as code structure, style, and variable naming conventions, and the like.
[0083] In some embodiments, the target code 350 may include multiple code files corresponding to multiple levels of requirement description information. For example, independent code files may be generated for different pages and components, and stored in a reasonable file organization to ensure the maintainability and clarity of the code.
[0084] In some embodiments, the platform 110 may present an interface corresponding to the target code as at least part of the response to the user input. The platform 110 may not only output the target code, but also render a visual interface generated by the code, allowing the user 105 to intuitively preview the execution effect of the code. In this way, the user 105 can see the interface effect corresponding to the target code without manually running the code, and judge whether it meets expectations.
[0085] In summary, in the embodiments of the present disclosure, efficient and high-quality code generation is achieved by combining multi-level demand decomposition, retrieval enhancement generation mechanism and machine learning model. Hierarchical analysis of user needs can ensure that the code structure is clear, logically reasonable, and highly matched with user needs. In addition, by determining reference code snippets from the code set through the retrieval enhancement generation mechanism, code generation can efficiently reuse existing high-quality code snippets, improve code consistency and development efficiency. Ultimately, the generated target code can cover multiple levels of code snippets, can be seamlessly integrated into existing projects, and is convenient for subsequent expansion and optimization.
[0086] Figure 4 A schematic structural block diagram of an apparatus 400 for code generation according to some embodiments of the present disclosure is shown. The apparatus 400 may be implemented as or included in the platform 110. Each module / component in the apparatus 400 may be implemented by hardware, software, firmware, or any combination thereof.
[0087] As shown in the figure, the device 400 includes a requirement determination module 410, which is configured to determine, in response to receiving user input indicating a code generation requirement, multiple requirement description information corresponding to multiple levels respectively based on the user input, and the requirement description information in the multiple requirement description information indicates the code requirements of the code generation requirement at the corresponding level; a reference code determination module 420, which is configured to determine at least one reference code fragment from a code set based on at least a part of the multiple requirement description information, and the code set includes at least multiple code fragments corresponding to multiple levels and corresponding description information of the multiple code fragments; and a generation module 430, which is configured to generate a target code for the user input based on information related to at least one reference code fragment.
[0088] In some embodiments, the requirement determination module 410 is further configured to generate extended description information corresponding to the code generation requirement by supplementing user input; and to determine multiple pieces of requirement description information corresponding to the multiple levels by decomposing the extended description information according to multiple levels.
[0089] In some embodiments, the reference code determination module 420 is further configured to determine, for a level among multiple levels, at least a portion of at least one reference code snippet from multiple code snippets corresponding to the level in the code set based on requirement description information corresponding to the level.
[0090] In some embodiments, the multiple levels include an application level, a page level, and a component level. The reference code determination module 420 is further configured to determine a corresponding first similarity between corresponding description information of multiple first code snippets corresponding to the application level and first requirement description information corresponding to the application level in the code set; and in response to determining that the first similarity between the description information of at least one first code snippet in the multiple first code snippets and the first requirement description information is greater than or equal to a first threshold similarity, determine at least one first code snippet as at least one reference code snippet.
[0091] In some embodiments, the reference code determination module 420 is further configured to, in response to determining that the corresponding first similarities are all less than a first threshold similarity, determine the corresponding second similarities between the description information of multiple second code fragments corresponding to the page level in the code set and at least one second requirement description information corresponding to the page level; and in response to determining that the second similarity between the description information of at least one second code fragment among the multiple second code fragments and at least one second requirement description information is greater than or equal to the second threshold similarity, determine at least one second code fragment as at least one reference code fragment.
[0092] In some embodiments, for a second code snippet among multiple second code snippets, determining the second similarity is based on at least one of the following: the textual similarity between the description information of the second code snippet and at least one second requirement description information, or the number of components indicated by the description information of the second code snippet that match the components indicated by at least one second requirement description information.
[0093] In some embodiments, the reference code determination module 420 is further configured to, in response to determining that the corresponding second similarities are all less than a second threshold similarity, determine the corresponding third similarities between the description information of multiple third code fragments corresponding to the component level in the code set and at least one third requirement description information corresponding to the component level; and in response to determining that the third similarity between the description information of at least one third code fragment among the multiple third code fragments and at least one third requirement description information is greater than or equal to a third threshold similarity, determine at least one third code fragment as at least one reference code fragment.
[0094] In some embodiments, the description information of a given code snippet in the plurality of code snippets includes at least one of the following: The name of the given code snippet, the level to which the given snippet corresponds, the storage location of the given snippet, the component category to which the given snippet corresponds, or summary information of the given snippet.
[0095] In some embodiments, summary information is generated based on predetermined cue words using a machine learning model.
[0096] In some embodiments, the generation module 430 is further configured to generate prompt information based on multiple requirement description information and at least one reference code snippet; provide the prompt information to the machine learning model to obtain the output of the machine learning model; and determine the target code based on the output of the machine learning model, the target code including multiple code snippets corresponding to multiple levels of requirement description information.
[0097] In some embodiments, the apparatus 400 further includes a presentation module configured to present an interface corresponding to the target code as at least a part of a reply to the user input.
[0098] The units and / or modules included in the device 400 can be implemented in various ways, including software, hardware, firmware, or any combination thereof. In some embodiments, one or more units and / or modules can be implemented using software and / or firmware, such as machine executable instructions stored on a storage medium. In addition to or as an alternative to machine executable instructions, some or all of the units and / or modules in the device 400 can be implemented at least in part by one or more hardware logic components. As an example and not limitation, exemplary types of hardware logic components that can be used include field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0099] It should be understood that one or more steps in the above method can be performed by a suitable electronic device or a combination of electronic devices. Such an electronic device or a combination of electronic devices may include, for example, Figure 1 Platform 110 in.
[0100] Figure 5 1 shows a block diagram of an electronic device 500 in which one or more embodiments of the present disclosure may be implemented. It should be understood that Figure 5 The electronic device 500 shown is merely exemplary and should not constitute any limitation on the functionality and scope of the embodiments described herein. Figure 5 The electronic device 500 shown may include or be implemented as Figure 1 Platform 110, or Figure 4 Device 400.
[0101] like Figure 5As shown, the electronic device 500 is in the form of a general electronic device. The components of the electronic device 500 may include, but are not limited to, one or more processors or processing units 510, a memory 520, a storage device 530, one or more communication units 540, one or more input devices 550, and one or more output devices 560. The processing unit 510 may be an actual or virtual processor and is capable of performing various processes according to a program stored in the memory 520. In a multi-processor system, multiple processing units execute computer executable instructions in parallel to improve the parallel processing capability of the electronic device 500.
[0102] The electronic device 500 typically includes a plurality of computer storage media. Such media may be any accessible media accessible to the electronic device 500, including but not limited to volatile and non-volatile media, removable and non-removable media. The memory 520 may be a volatile memory (e.g., registers, caches, random access memory (RAM)), a non-volatile memory (e.g., a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), flash memory), or some combination thereof. The storage device 530 may be a removable or non-removable medium, and may include a machine-readable medium, such as a flash drive, a disk, or any other medium, which may be capable of being used to store information and / or data and may be accessed within the electronic device 500.
[0103] The electronic device 500 may further include additional removable / non-removable, volatile / non-volatile storage media. Figure 5 As shown in , a disk drive for reading or writing from a removable, non-volatile disk (e.g., a "floppy disk") and an optical drive for reading or writing from a removable, non-volatile optical disk may be provided. In these cases, each drive may be connected to the bus (not shown) by one or more data media interfaces. The memory 520 may include a computer program product 525 having one or more program modules that are configured to perform various methods or actions of various embodiments of the present disclosure.
[0104] The communication unit 540 enables communication with other electronic devices through a communication medium. Additionally, the functions of the components of the electronic device 500 can be implemented in a single computing cluster or multiple computing machines that can communicate through a communication connection. Therefore, the electronic device 500 can operate in a networked environment using a logical connection with one or more other servers, a network personal computer (PC), or another network node.
[0105] The input device 550 may be one or more input devices, such as a mouse, a keyboard, a tracking ball, etc. The output device 560 may be one or more output devices, such as a display, a speaker, a printer, etc. The electronic device 500 may also communicate with one or more external devices (not shown) through the communication unit 540 as needed, such as a storage device, a display device, etc., communicate with one or more devices that allow a user to interact with the electronic device 500, or communicate with any device (e.g., a network card, a modem, etc.) that allows the electronic device 500 to communicate with one or more other electronic devices. Such communication may be performed via an input / output (I / O) interface (not shown).
[0106] According to an exemplary implementation of the present disclosure, a computer-readable storage medium is provided, on which computer-executable instructions are stored, wherein the computer-executable instructions are executed by a processor to implement the method described above. According to an exemplary implementation of the present disclosure, a computer program product is also provided, which is tangibly stored on a non-transitory computer-readable medium and includes computer-executable instructions, and the computer-executable instructions are executed by a processor to implement the method described above.
[0107] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices, equipment, and computer program products implemented according to the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0108] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0109] Computer-readable program instructions can be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, so that the instructions executed on the computer, other programmable data processing apparatus, or other device implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0110] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple implementations of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of a module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some implementations as an update, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the function involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a special hardware-based system that performs the function or action of the specification, or can be realized by a combination of special hardware and computer instructions.
[0111] The above descriptions of various implementations of the present disclosure are exemplary, non-exhaustive, and not limited to the disclosed implementations. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described implementations. The selection of terms used herein is intended to best explain the principles of the implementations, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the various implementations disclosed herein.
Claims
1. A method for code generation, comprising: In response to receiving a user input indicating a code generation requirement, based on the user input, determining multiple pieces of requirement description information corresponding to multiple levels respectively, wherein the requirement description information in the multiple pieces of requirement description information indicates a code requirement of the code generation requirement at the corresponding level; Based on at least a portion of the plurality of requirement description information, determining at least one reference code snippet from a code set, the code set comprising at least a plurality of code snippets corresponding to the plurality of levels and corresponding description information of the plurality of code snippets; and A target code for the user input is generated based on information related to the at least one reference code segment.
2. The method according to claim 1, wherein determining the multiple demand description information corresponding to the multiple levels comprises: By supplementing the user input, generating extended description information corresponding to the code generation requirement; as well as By decomposing the extended description information according to the multiple levels, multiple pieces of requirement description information corresponding to the multiple levels are determined.
3. The method of claim 1 , wherein determining the at least one reference code segment comprises: For a level in the multiple levels, based on the requirement description information corresponding to the level, at least a portion of the at least one reference code segment is determined from multiple code segments corresponding to the level in the code set.
4. The method of claim 1, wherein the plurality of levels include an application level, a page level, and a component level, and determining the at least one reference code snippet comprises: Determining corresponding first similarities between corresponding description information of a plurality of first code snippets in the code set corresponding to the application level and first requirement description information corresponding to the application level; and In response to determining that a first similarity between description information of at least one first code snippet among the plurality of first code snippets and the first requirement description information is greater than or equal to a first threshold similarity, the at least one first code snippet is determined as the at least one reference code snippet.
5. The method according to claim 4, further comprising: In response to determining that the corresponding first similarities are all less than the first threshold similarity, determining corresponding second similarities between the description information of the plurality of second code snippets in the code set corresponding to the page hierarchy and the at least one second requirement description information corresponding to the page hierarchy; and In response to determining that a second similarity between description information of at least one second code snippet among the multiple second code snippets and the at least one second requirement description information is greater than or equal to a second threshold similarity, the at least one second code snippet is determined as the at least one reference code snippet.
6. The method according to claim 5, wherein for a second code segment in the plurality of second code segments, determining the second similarity is based on at least one of the following: The text similarity between the description information of the second code snippet and the at least one second requirement description information, or The number of components indicated by the description information of the second code snippet that match the components indicated by the at least one item of second requirement description information.
7. The method according to claim 5, further comprising: In response to determining that the corresponding second similarities are all less than the second threshold similarity, determining corresponding third similarities between description information of a plurality of third code snippets corresponding to the component level in the code set and at least one item of third requirement description information corresponding to the component level; and In response to determining that a third similarity between description information of at least one third code snippet among the multiple third code snippets and the at least one item of third requirement description information is greater than or equal to a third threshold similarity, the at least one third code snippet is determined as the at least one reference code snippet.
8. The method according to claim 1, wherein the description information of a given code snippet among the plurality of code snippets comprises at least one of the following: The name of the given code snippet, The level corresponding to the given code snippet, the storage location of the given code snippet, the component category to which the given code snippet corresponds, or Summary information for the given code snippet.
9. The method according to claim 8, wherein the summary information is generated based on predetermined prompt words using a machine learning model.
10. The method of claim 1, wherein generating a target code for the user input comprises: Generate prompt information based on the multiple pieces of requirement description information and the at least one reference code fragment; Providing the prompt information to a machine learning model to obtain an output of the machine learning model; as well as The target code is determined based on the output of the machine learning model, and the target code includes multiple code snippets corresponding to the multiple levels of requirement description information.
11. The method according to claim 1, further comprising: An interface corresponding to the target code is presented as at least a part of a response to the user input.
12. A device for code generation, comprising: A requirement determination module is configured to, in response to receiving a user input indicating a code generation requirement, determine, based on the user input, a plurality of pieces of requirement description information corresponding to a plurality of levels, wherein the requirement description information in the plurality of pieces of requirement description information indicates a code requirement of the code generation requirement at the corresponding level; A reference code determination module is configured to determine at least one reference code segment from a code set based on at least a portion of the plurality of requirement description information, the code set comprising at least a plurality of code segments corresponding to the plurality of levels and corresponding description information of the plurality of code segments; as well as The generating module is configured to generate a target code for the user input based on information related to the at least one reference code segment.
13. An electronic device, comprising: at least one processing unit; as well as At least one memory, the at least one memory being coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions causing the electronic device to perform the method according to any one of claims 1 to 11 when executed by the at least one processing unit.
14. A computer-readable storage medium having a computer program stored thereon, wherein the computer program can be executed by a processor to implement the method according to any one of claims 1 to 11.
15. A computer program product comprising computer executable instructions, wherein the computer executable instructions, when executed by a processor, implement the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Method and device for determining interface code, electronic equipment and storage medium
CN112835579A
Intelligent low-code page development system and method
CN117331561A
Code generation method and device, electronic equipment and storage medium
CN117762389A
Code generation method, device and equipment based on AI, RPA and AI Agent
CN119045825A
Code generation method and device, equipment and storage medium
CN119536720A
Cited By
Model-based application building method and device, equipment, medium and program product
CN120848870A