Code generation method, device and system

By obtaining and splitting user problem information in the code generation system, determining the target code blocks and dependencies, and using large language models to generate code, the problem of inefficient code generation and inability to implement specific business logic in the existing technology is solved, and efficient and available code generation is achieved.

CN120162076APending Publication Date: 2025-06-17ALIBABA (CHINA) CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510168686.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-14
Publication Date
2025-06-17

AI Technical Summary

Technical Problem

The existing technology can only generate a framework when generating code, and cannot implement specific business logic. It requires artificial code writing in the framework, resulting in low code generation efficiency.

Method used

By obtaining user problem information, split into necessary and non-essential sub-information, the target code block and dependency are determined in the target code repository based on these sub-information, assembled into prompt information and input into a large language model, and generated the target code.

Benefits of technology

It realizes the rapid generation of code containing specific business logic, improves the usability and generation efficiency of code, and reduces the need for human-made code writing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120162076A_ABST
    Figure CN120162076A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a code generation method, device and system. In the embodiment of the invention, user question information is obtained; the user question information is split to generate at least two pieces of sub-information, the sub-information comprises necessary sub-information and unnecessary sub-information, the necessary sub-information comprises demand information and signature information, and the unnecessary sub-information comprises background codes and / or extension point names; determining a target code block in a target code warehouse according to the at least two pieces of sub-information; determining a target dependency relationship according to the target code block; assembling the target dependency relationship, the target code block, the demand information and the signature information into prompt information according to a set rule; and inputting the prompt information into a first large language model to generate a target code. Through the method, the code can be quickly generated, and the availability of the code is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and more particularly, to a method, apparatus, and system for code generation. Background Art

[0002] In the process of software development, it is necessary to generate corresponding code according to user requirements. For example, users need to customize different business logics for different services and generate corresponding code for different business logics.

[0003] In the prior art, when using development platforms such as JHipster and Yeoman to generate code, only some frameworks can be generated, and specific business logics cannot be implemented. If business logics need to be implemented, code needs to be manually written in the above frameworks.

[0004] In summary, how to quickly generate available code is a problem that needs to be solved currently. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method, apparatus, and system for code generation, which can quickly generate code and improve the usability of the code.

[0006] In a first aspect, an embodiment of the present invention provides a method for code generation, the method including:

[0007] Obtain user problem information;

[0008] Split the user problem information to generate at least two sub-informations, where the sub-informations include necessary sub-informations and non-necessary sub-informations, and the necessary sub-informations include requirement information and signature information, and the non-necessary sub-informations include background code and / or extension point names;

[0009] Determine target code blocks in a target code repository according to the at least two sub-informations;

[0010] Determine a target dependency relationship according to the target code blocks;

[0011] Assemble the target dependency relationship, the target code blocks, the requirement information, and the signature information into a prompt message according to a set rule;

[0012] Input the prompt message into a first large language model to generate target code.

[0013] Optionally, the splitting the user problem information to generate at least two sub-informations specifically includes:

[0014] Input the user problem information into a second large language model for splitting to generate at least two sub-informations.

[0015] Optionally, determining the target code block in the target code repository according to the at least two sub-information specifically includes:

[0016] Recall code snippets with the same function name as in the signature information in the target code repository, and determine the code snippets as the target code block.

[0017] Optionally, determining the target code block in the target code repository according to the at least two sub-information specifically further includes:

[0018] Recall code snippets with the same function name as in the signature information in the target code repository;

[0019] Filter the code snippets according to the extension point name to determine the target code block.

[0020] Optionally, determining the target dependency relationship according to the target code block specifically includes:

[0021] Identify and screen in the target code repository through a third large language model for the signature information and the function name in the target code block to determine candidate dependency relationships;

[0022] Perform abstract syntax tree (AST) search in the target code repository according to the candidate dependency relationships to determine the searched target dependency relationships.

[0023] Optionally, assembling the target dependency relationship, the target code block, the requirement information, and the signature information into a prompt message according to a set rule specifically includes:

[0024] Assemble the target dependency relationship, the target code block, the requirement information, the signature information, and the pre-set constraint information into a prompt message according to a set rule.

[0025] Optionally, the set rule includes: when the total string length of the target dependency relationship, the target code block, the requirement information, the signature information, and the pre-set constraint information exceeds the set length, trim the target dependency relationship, the target code block, the requirement information, the signature information, or the pre-set constraint information in a set order.

[0026] In a second aspect, an embodiment of the present invention provides a code generation device, and the device includes:

[0027] An acquisition unit, configured to acquire user question information;

[0028] A generation unit for splitting the user question information to generate at least two sub-informations, where the sub-informations include necessary sub-informations and non-necessary sub-informations, and the necessary sub-informations include requirement information and signature information, and the non-necessary sub-informations include background code and / or extension point names;

[0029] A determination unit for determining a target code block in a target code repository according to the at least two sub-informations;

[0030] The determination unit is further configured to: determine a target dependency relationship according to the target code block;

[0031] A processing unit for assembling the target dependency relationship, the target code block, the requirement information, and the signature information into a prompt message according to a set rule;

[0032] The generation unit is further configured to: input the prompt message into a first large language model to generate target code.

[0033] Optionally, the generation unit is specifically configured to:

[0034] Input the user question information into a second large language model for splitting to generate at least two sub-informations.

[0035] Optionally, the determination unit is specifically configured to:

[0036] Recall a code snippet with the same function name as that in the signature information in the target code repository, and determine the code snippet as the target code block.

[0037] Optionally, the determination unit is further specifically configured to:

[0038] Recall a code snippet with the same function name as that in the signature information in the target code repository;

[0039] Filter the code snippet according to the extension point name to determine the target code block.

[0040] Optionally, the determination unit is specifically configured to:

[0041] Identify and screen in the target code repository through a third large language model for the function names in the signature information and the target code block to determine candidate dependency relationships;

[0042] Perform abstract syntax tree AST search in the target code repository according to the candidate dependency relationships to determine the searched target dependency relationships.

[0043] Optionally, the processing unit is further specifically configured to:

[0044] The target dependency relationship, the target code block, the requirement information, the signature information, and the pre-set constraint information are assembled into a prompt message according to a set rule.

[0045] Optionally, the set rule includes: when the total string length of the target dependency relationship, the target code block, the requirement information, the signature information, and the pre-set constraint information exceeds a set length, the target dependency relationship, the target code block, the requirement information, the signature information, or the pre-set constraint information is trimmed in a set order.

[0046] In a third aspect, an embodiment of the present invention provides a code generation system, where the system includes:

[0047] A terminal and a cloud server; wherein, the terminal is configured to receive user question information and send the user question information to the cloud server; the cloud server is configured to execute the method described in any one of the first aspect or any possible one of the first aspect, and send the generated target code to the terminal.

[0048] In a fourth aspect, an embodiment of the present invention provides an electronic device, including a memory and a processor, where the memory is configured to store one or more computer program instructions, and wherein the one or more computer program instructions are executed by the processor to implement the method described in any one of the first aspect or any possible one of the first aspect.

[0049] In a fifth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which computer program instructions are stored, and the computer program instructions, when executed by a processor, implement the method described in any one of the first aspect or any possible one of the first aspect.

[0050] In the embodiments of the present invention, by obtaining user question information; splitting the user question information to generate at least two sub-information, where the sub-information includes necessary sub-information and non-necessary sub-information, and where the necessary sub-information includes requirement information and signature information, and the non-necessary sub-information includes background code and / or extension point name; determining a target code block in a target code repository according to the at least two sub-information; determining a target dependency relationship according to the target code block; assembling the target dependency relationship, the target code block, the requirement information, and the signature information into a prompt message according to a set rule; and inputting the prompt message into a first large language model to generate a target code. Through the above method, code can be generated quickly and the usability of the code can be improved. Description of the Drawings

[0051] Through the following description of the embodiments of the present invention with reference to the drawings, the above and other objects, features, and advantages of the present invention will become clearer. In the drawings:

[0052] Figure 1 is a flowchart of a method for code generation in an embodiment of the present invention;

[0053] Figure 2 is a flowchart of another method for code generation in an embodiment of the present invention;

[0054] Figure 3 is a schematic diagram of a system for code generation in an embodiment of the present invention;

[0055] Figure 4 is a schematic diagram of a device for code generation in an embodiment of the present invention;

[0056] Figure 5 is a schematic diagram of an electronic device in an embodiment of the present invention. Detailed implementation manners

[0057] The following describes the present application based on embodiments, but the present application is not limited to these embodiments. In the following detailed description of the present application, some specific details are described in detail. Those skilled in the art can fully understand the present application without the description of these details. In order to avoid obscuring the essence of the present application, well-known methods, processes, procedures, components, and circuits are not described in detail.

[0058] In addition, those of ordinary skill in the art should understand that the drawings provided herein are for illustrative purposes only, and the drawings are not necessarily drawn to scale.

[0059] Unless the context clearly requires otherwise, the words "including", "comprising", and the like throughout the application document should be construed in an inclusive sense rather than an exclusive or exhaustive sense; that is, the meaning of "including but not limited to".

[0060] In the description of the present application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be construed as indicating or implying relative importance. In addition, in the description of the present application, unless otherwise specified, the meaning of "a plurality" is two or more.

[0061] In the prior art, development platforms such as JHipster, Yeoman, Apache Velocity, Mustache, Cookiecutter, Plop, Swagger Codegen / OpenAPI Generator can be used to generate code. Specifically, JHipster is used to generate, develop, and deploy Spring Boot + Angular / React / Vue applications, providing rich templates and generators, and can quickly create a complete web application. JHipster can be quickly started, that is, it can quickly generate a complete Spring Boot + Angular / React / Vue application, support multiple technology stacks such as front-end frameworks, databases, and authentication mechanisms, have a large number of plugins and modules to meet different development needs, and have an active community and rich documentation resources. However, the initial configuration and understanding of the generated code may be relatively complex, and the generated code may require a large amount of modification and maintenance, especially in large projects; Yeoman is a scaffolding tool that can help developers quickly generate project structures and configuration files. Through various generators, Yeoman can generate templates for front-end, back-end, and even full-stack projects. It supports multiple generators, can cover front-end, back-end, and even full-stack projects, and can quickly generate the project's basic structure through command-line operations. There are a large number of community generators, suitable for multiple frameworks and languages. However, the quality and maintenance mainly depend on the developers of the generators, and some generators may not be perfect, suitable for generating the basic structure of the project, and have limited support for continuous integration and maintenance of large projects; Apache Velocity is a Java-based template engine used to generate various text contents, including HTML, XML, and Java code. Developers can define templates and generate the final code or document through the Velocity engine. Apache Velocity can generate various text contents, including HTML, XML, and Java code, allowing developers to fully customize templates, with guaranteed performance and stability. However, the template syntax and configuration are relatively complex; Mustache is a logic-independent template language that can be used in multiple programming languages and is used to generate HTML, configuration files, and code snippets. The Mustache template syntax is simple, easy to understand and use, supports multiple programming languages, and does not contain business logic in the template, clearly separating code and views. However, the logic-independent design may limit flexibility in complex scenarios;The Cookiecutter is a tool for creating project templates, mainly targeting the Python community. Developers can use existing templates or create their own templates to generate project structures and code files. The Cookiecutter command-line tool is simple and intuitive. Developers can create their own templates to adapt to different project requirements. There are a large number of ready-made templates available, but the main user group is still Python developers, and the quality and maintenance of community templates vary. The Plop is a small code generation tool written in JavaScript, mainly used for generating front-end components, routes, services, etc. Through simple configuration, developers can define templates and generation rules. The Plop is simply designed and easy to integrate into existing projects. It can customize generation rules and templates to adapt to different needs and is very suitable for generating common code snippets such as front-end components and routes. However, it is mainly used for generating small code snippets and is not suitable for the overall generation of large projects. It requires a Node.js environment and may not be friendly to non-JavaScript developers. The Swagger Codegen / OpenAPI Generator can generate client SDKs, server-side code, and API documentation according to the OpenAPI specification. Developers can define the description of API interfaces and then use these tools to generate corresponding code. The Swagger Codegen / OpenAPI Generator is based on the OpenAPI specification, and the generated code and documentation are standardized. It can generate client SDKs and server-side code in multiple programming languages, reducing the workload of manually writing API interface code. However, the generated code may be very complex and difficult to read and maintain. In summary, although the above development platforms can generate code, they can only generate some frameworks when generating code and cannot implement specific business logic. If you want to implement business logic, you need to manually write code in the above frameworks. Therefore, how to quickly generate usable code is a problem that needs to be solved currently.;

[0062] In an embodiment of the present invention, to solve the above problems, a method for code generation is proposed, specifically as Figure 1 shown, the method includes:

[0063] Step S101, obtain user problem information.

[0064] Specifically, the server obtains the user problem information sent by the terminal. For example, the user enters the user problem information in the display interface of the terminal, and the terminal sends the received user problem information to the server. Among them, the server can be a cloud server or a local server, which is specifically determined according to the actual situation.

[0065] In a possible implementation, the user problem information can also be referred to as user requirement information or original problem information. For example, the user problem information is "@workspace Currently, I need to implement a function for customizing the right - hand button in the UtryTaoDetailCustomizationExt class. You can retrieve other code snippets for implementing this function from the repository for reference. The function signature is as follows: public PlaceHolder<List<Detail3BottomBarView.SimpleButtonViewContent>> addDetail3BottomRight BottomCustom(TaoViewDisplayInput input)". This is only for illustrative purposes, and the specific user problem information is determined according to the actual situation.

[0066] Step S102: Split the user problem information to generate at least two sub - information.

[0067] Specifically, the sub - information includes necessary sub - information and non - necessary sub - information. Among them, the necessary sub - information includes requirement information and signature information, and the non - necessary sub - information includes background code and / or extension point name.

[0068] In a possible implementation, input the user problem information into a second large - language model for splitting to generate at least two sub - information.

[0069] Suppose the following statement: "@workspace Currently, I need to implement a function for customizing the right - hand button in the UtryTaoDetailCustomizationExt class. You can retrieve other code snippets that implement this function from the repository for reference. The function signature is as follows: public PlaceHolder<List<Detail3BottomBarView.SimpleButtonViewContent>> addDetail3BottomRightBottomCustom(TaoViewDisplayInput input)". After splitting it through the second large - language model, it generates requirement information "Implement a function for customizing the right - hand button. You can retrieve other code snippets that implement this function from the repository for reference", background code "UtryTaoDetailCustomizationExt.java", signature "public PlaceHolder<List<Detail3BottomBarView.SimpleButtonViewContent>> addDetail3BottomRightBottomCustom(TaoViewDisplayInput input)", and extension point name "TAODETAIL#ADD_DETAIL3_BOTTOM_RIGHT_BUTTON_CUSTOM", where the signature includes the function name and input and output parameters.

[0070] In a possible implementation, the server receives the requirement information, signature information, background code, and / or extension point name sent by the terminal respectively.

[0071] In a possible implementation, the second large - language model can also be called the second - largest model. The second - largest model belongs to the large - model category. The large - model can also be called an Artificial Intelligence (AI) model or a Large Language Model (LLM). Among them, the large - model is a deep - learning model based on the transformer architecture, capable of processing and generating natural - language text. It is usually trained on a large amount of text data and has the ability to understand and generate language, and is widely used in dialogue systems, text generation, and other natural - language processing tasks.

[0072] Step S103: Determine the target code block in the target code repository according to the at least two sub - information.

[0073] Specifically, recall the code snippet with the same function name as that in the signature information in the target code repository, and determine the code snippet as the target code block; or, recall the code snippet with the same function name as that in the signature information in the target code repository; filter the code snippet according to the extension point name to determine the target code block.

[0074] In a possible implementation, the target code repository is provided by a development platform. For example, business-apps / china-detail-product, taodetail / taodetail, itemdetail / alidetail. This is only for illustrative purposes. For example, obtain the code snippet with the same function name as that in the signature information in the target code repository business-apps / china-detail-product according to the function name in the signature information; or, after obtaining the code snippet with the same function name as that in the signature information in the target code repository business-apps / china-detail-product according to the function name in the signature information, filter the code snippet according to the extension point name to determine the target code block. Specifically, filtering the code snippet according to the extension point name can be based on the set filtering rule, and the filtering rule can be @AppBootExtPoint(code = xxxx). This is only for illustrative purposes.

[0075] In the embodiments of the present invention, accurately retrieving and filtering relevant code in multiple code repositories ensures the high quality and high relevance of the generated code, and avoids the interference of irrelevant code.

[0076] Step S104: Determine the target dependency relationship according to the target code block.

[0077] Specifically, use the third large language model to identify and screen in the target code repository for the function names in the signature information and the target code block to determine the candidate dependency relationship; perform an Abstract Syntax Tree (AST) search in the target code repository according to the candidate dependency relationship to determine the search target dependency relationship.

[0078] In a possible implementation, the candidate dependency relationship includes class and method. Perform an AST search in business-apps / china-detail-product according to the class and method to determine the search target dependency relationship.

[0079] Step S105: Assemble the target dependency relationship, the target code block, the requirement information, and the signature information into a prompt message according to a set rule.

[0080] Specifically, the target dependency relationship, the target code block, the requirement information, the signature information, and the pre-set constraint information are assembled into a prompt message according to a set rule.

[0081] In a possible implementation manner, the set rule includes: when the total string length of the target dependency relationship, the target code block, the requirement information, the signature information, and the pre-set constraint information exceeds a set length maxtoken, the target dependency relationship, the target code block, the requirement information, the signature information, or the pre-set constraint information is trimmed in a set order, and the trimming can ensure the efficiency and conciseness of the generated code.

[0082] In a possible implementation manner, when trimming, the deeper target dependency relationship is trimmed, the constraint information can be text color, etc., and the constraint information can better manage and optimize the code, so as to better meet the needs of users.

[0083] Step S106: Input the prompt message into a first large language model to generate target code.

[0084] Through the above embodiments, the user can describe the requirements in simple natural language. After the terminal receives the user's requirements, it is sent to the server. The large model in the server understands the requirements and converts them into a specific and operable code generation task, and finally generates target code; moreover, the large model can perform fine-grained splitting of the user's requirements, and can accurately identify different parts of the requirements, such as requirement information, signature information, background code, and / or extension point names; the large model can also deeply understand the logical structure and dependency relationship of the code through static analysis technology, and then generate complete and runnable business logic code. Since the generated target code retains the complete dependency relationship and logical structure, subsequent code extension and maintenance are relatively easy, and developers can continue to develop based on the generated target code without a large amount of refactoring of the generated target code.

[0085] The following uses a specific schematic diagram to explain the code generation process in detail, specifically as Figure 2As shown, the user problem information is split in the second large language model to generate requirements, background code, signatures, and extension point names. According to the background code, signatures, and extension point names, target code blocks are recalled from the target code repository. In the target code repository, classes and methods are identified through the third large language model based on the target code blocks. An Abstract Syntax Tree (AST) search is performed in the target code repository according to the classes and methods to determine the target dependency relationship. The target dependency relationship, the target code blocks, the requirement information, and the signature information are assembled into a prompt, and the prompt is input into the first large language model to generate target code.

[0086] In the embodiments of the present invention, the above method can generate code containing specific business logic, which better meets the actual requirements. Through the static analysis and dependency recognition functions of AI, the generated target code can accurately retain the dependency relationship. Users do not need to master complex configurations. They only need to describe the requirements in natural language, and the code generation system can understand and generate the corresponding code, improving the usability. Moreover, through retrieval and analysis in multiple code repositories, the code generation system can provide more comprehensive code generation and extension services, avoiding the limitations of single code repository generation.

[0087] In the embodiments of the present invention, a code generation system is provided, as Figure 3 shown. The system includes a terminal 301 and a cloud server 302. Among them, the terminal 301 is used to receive user problem information and send the user problem information to the cloud server 302. The cloud server 302 is used to execute the above code generation method to generate target code and send the generated target code to the terminal 301.

[0088] In the embodiments of the present invention, a code generation device is provided, as Figure 4 shown, specifically including: an acquisition unit 401, a generation unit 402, a determination unit 403, and a processing unit 404.

[0089] Among them, the obtaining unit 401 is used to obtain user question information; the generating unit 402 is used to split the user question information to generate at least two sub-information, where the sub-information includes necessary sub-information and non-necessary sub-information, and the necessary sub-information includes requirement information and signature information, and the non-necessary sub-information includes background code and / or extension point name; the determining unit 403 is used to determine a target code block in the target code repository according to the at least two sub-information; the determining unit 403 is further used to: determine a target dependency relationship according to the target code block; the processing unit 404 is used to assemble the target dependency relationship, the target code block, the requirement information, and the signature information into a prompt message according to a set rule; the generating unit 402 is further used to: input the prompt message into a first large language model to generate target code.

[0090] Further, the generating unit is specifically used for:

[0091] Input the user question information into a second large language model for splitting to generate at least two sub-information.

[0092] Further, the determining unit is specifically used for:

[0093] Recall a code snippet in the target code repository with the same function name as that in the signature information, and determine the code snippet as the target code block.

[0094] Further, the determining unit is specifically further used for:

[0095] Recall a code snippet in the target code repository with the same function name as that in the signature information;

[0096] Filter the code snippet according to the extension point name to determine the target code block.

[0097] Further, the determining unit is specifically used for:

[0098] Identify and screen in the target code repository with the signature information and the function names in the target code block through a third large language model to determine candidate dependency relationships;

[0099] Perform an Abstract Syntax Tree (AST) search in the target code repository according to the candidate dependency relationships to determine the searched target dependency relationships.

[0100] Further, the processing unit is specifically further used for:

[0101] Assemble the target dependency relationship, the target code block, the requirement information, the signature information, and the pre-set constraint information into a prompt message according to a set rule.

[0102] Further, the setting rule includes: when the total string length of the target dependency relationship, the target code block, the requirement information, the signature information, and the pre-set constraint information exceeds the set length, the target dependency relationship, the target code block, the requirement information, the signature information, or the pre-set constraint information is trimmed in a set order.

[0103] Figure 5 It is a schematic structural diagram of the electronic device in the embodiment of the present invention. As Figure 5 shown, it includes a general computer hardware structure, which at least includes a processor 501 and a memory 502. The processor 501 and the memory 502 are connected through a bus 503. The memory 502 is suitable for storing instructions or programs executable by the processor 501. The processor 501 can be an independent microprocessor or a set of one or more microprocessors. Thus, the processor 501 executes the instructions stored in the memory 502 to execute the method flow of the embodiment of the present invention as described above to implement the processing of data and the control of other devices. The bus 503 connects the above-mentioned multiple components together and at the same time connects the above-mentioned components to a display controller 504, a display device, and an input / output (I / O) device 505. The input / output (I / O) device 505 can be a mouse, a keyboard, a modem, a network interface, a touch input device, a somatosensory input device, a printer, and other devices well known in the art. Typically, the input / output (I / O) device 505 is connected to the system through an input / output (I / O) controller 506.

[0104] Among them, the instructions stored in the memory 502 are executed by at least one processor 501 to achieve: obtaining user question information; splitting the user question information to generate at least two sub-information, where the sub-information includes necessary sub-information and non-necessary sub-information, where the necessary sub-information includes requirement information and signature information, and the non-necessary sub-information includes background code and / or extension point name; determining a target code block in a target code repository according to the at least two sub-information; determining a target dependency relationship according to the target code block; assembling the target dependency relationship, the target code block, the requirement information, and the signature information into a prompt information according to a set rule; and inputting the prompt information into a first large language model to generate target code.

[0105] Specifically, the electronic device includes: one or more processors 501 and a memory 502, Figure 5 Taking one processor 501 as an example. The processor 501 and the memory 502 can be connected through a bus or other means, Figure 5Take the bus connection as an example. As a non-volatile computer-readable storage medium, the memory 502 can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. By running the non-volatile software programs, instructions, and modules stored in the memory 502, the processor 501 executes various functional applications and data processing of the device, that is, implements the method for determining code generation described above.

[0106] The memory 502 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store an option list, etc. In addition, the memory 502 may include high-speed random access memory and may also include non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 502 may optionally include a memory remotely set relative to the processor 501, and these remote memories can be connected to external devices through a network. Examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.

[0107] One or more modules are stored in the memory 502 and, when executed by one or more processors 501, execute the method for code generation in any of the above method embodiments.

[0108] As those skilled in the art will realize, various aspects of the embodiments of the present invention can be implemented as a system, a method, or a computer program product. Therefore, various aspects of the embodiments of the present invention can take the following forms: a complete hardware implementation, a complete software implementation (including firmware, resident software, microcode, etc.), or an implementation that combines software aspects with hardware aspects, which is generally referred to herein as a "circuit", "module", or "system". In addition, various aspects of the embodiments of the present invention can take the following form: a computer program product implemented in one or more computer-readable media, the computer-readable media having computer-readable program code implemented thereon.

[0109] Any combination of one or more computer-readable media may be utilized. A computer-readable medium may be either a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of embodiments of the present invention, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.

[0110] A computer-readable signal medium may include a propagated data signal with computer-readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated signal may take any of a variety of forms, including but not limited to: electromagnetic, optical, or any suitable combination thereof. A computer-readable signal medium may be any computer-readable medium that is not a computer-readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.

[0111] Any suitable medium may be used to transmit the program code embodied on a computer-readable medium, including but not limited to wireless, wireline, fiber optic cable, RF, etc., or any suitable combination of the foregoing.

[0112] The computer program code for performing operations in connection with the aspects of the embodiments of the present invention may be written in any combination of one or more programming languages, including: object-oriented programming languages such as Java, Smalltalk, C++; and conventional procedural programming languages such as the “C” programming language or similar programming languages. The program code may execute entirely on the user's computer as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server. In the latter case, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).

[0113] The flowchart illustrations and / or block diagrams of the methods, apparatuses (systems), and computer program products according to the embodiments of the present invention described above depict various aspects of the embodiments of the present invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and the combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine, such that the instructions (executed via the processor of the computer or other programmable data processing device) create a means for implementing the functions / actions specified in the flowchart and / or block diagram block or blocks.

[0114] These computer program instructions can also be stored in a computer-readable medium that can direct a computer, other programmable data processing device, or other apparatus to operate in a specific manner, such that the instructions stored in the computer-readable medium produce an article of manufacture including instructions for implementing the functions / actions specified in the flowchart and / or block diagram block or blocks.

[0115] The computer program instructions can also be loaded onto a computer, other programmable data processing device, or other apparatus, so as to perform a series of operational steps on the computer, other programmable device, or other apparatus to produce a computer-implemented process, such that the instructions executed on the computer or other programmable device provide a process for implementing the functions / actions specified in the flowchart and / or block diagram block or blocks.

[0116] The above are only the preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, various modifications and changes can be made to the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present application shall be included within the protection scope of the present application.

[0117] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or fully authorized by all parties. Moreover, the collection, use, and processing of the relevant data need to comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding operation entrances are provided for the user to select authorization or rejection. When the user refuses to process personal information other than the necessary information required for the basic functions, it will not affect the user's use of the basic functions.

Claims

1. A method for code generation, characterized in that: The method comprises: Get user question information; Splitting the user question information to generate at least two sub-information, wherein the sub-information includes necessary sub-information and non-essential sub-information, wherein the necessary sub-information includes requirement information and signature information, and the non-essential sub-information includes background code and / or extension point name; Determine a target code block in a target code repository according to the at least two sub-information; Determining target dependencies according to the target code block; Assembling the target dependency, the target code block, the requirement information and the signature information into prompt information according to set rules; The prompt information is input into a first large language model to generate a target code.

2. The method according to claim 1, characterized in that The user question information is split to generate at least two sub-information, specifically including: The user question information is input into a second large language model for splitting to generate at least two sub-information.

3. The method according to claim 1, characterized in that The determining the target code block in the target code repository according to the at least two sub-information specifically includes: A code fragment identical to the function name in the signature information is recalled in the target code repository, and the code fragment is determined as the target code block.

4. The method according to claim 1, characterized in that: The determining the target code block in the target code repository according to the at least two sub-information specifically further includes: Recalling a code snippet with the same function name as that in the signature information in the target code repository; The code fragments are filtered according to the extension point names to determine the target code blocks.

5. The method according to claim 1, characterized in that Determining the target dependency relationship according to the target code block specifically includes: Identify and filter the signature information and the function name in the target code block in the target code repository by using a third large language model to determine candidate dependency relationships; An abstract syntax tree AST search is performed in the target code repository according to the candidate dependency relationship to determine the search target dependency relationship.

6. The method according to claim 1, characterized in that The target dependency, the target code block, the requirement information and the signature information are assembled into prompt information according to a set rule, specifically including: The target dependency, the target code block, the requirement information, the signature information and the preset constraint information are assembled into prompt information according to the set rules.

7. The method according to claim 1, characterized in that The setting rules include: when the total length of the character string of the target dependency, the target code block, the requirement information, the signature information and the pre-set constraint information exceeds the set length, the target dependency, the target code block, the requirement information, the signature information or the pre-set constraint information are trimmed in a set order.

8. A code generation device, characterized in that: The device comprises: An acquisition unit, used to acquire user question information; A generating unit, configured to split the user question information to generate at least two sub-information, wherein the sub-information includes necessary sub-information and non-essential sub-information, wherein the necessary sub-information includes requirement information and signature information, and the non-essential sub-information includes a background code and / or an extension point name; A determination unit, configured to determine a target code block in a target code repository according to the at least two sub-information; The determining unit is further used to: determine a target dependency relationship according to the target code block; A processing unit, used to assemble the target dependency, the target code block, the requirement information and the signature information into prompt information according to a set rule; The generating unit is further used for: inputting the prompt information into the first large language model to generate target code.

9. A code generation system, characterized in that: The system comprises: Terminal and cloud server; Wherein, the terminal is used to receive user question information and send the user question information to the cloud server; The cloud server is used to execute the method described in any one of claims 1 to 7 above, and send the generated target code to the terminal.

10. An electronic device comprising a memory and a processor, characterized in that: The memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1 to 7.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Code processing method and device, equipment, storage medium and program product

    CN120723248A