Code generation method and device, electronic equipment and readable storage medium

By obtaining target component pattern entries from the component pattern information library and generating program pattern definitions, the problem of insufficient code generation accuracy in the prior art is solved, and higher code generation accuracy and practicality are achieved.

CN119536695AActive Publication Date: 2025-02-28CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411448391.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-16
Publication Date
2025-02-28
Estimated Expiration
2044-10-16

AI Technical Summary

Technical Problem

The accuracy of automatic code generation in the prior art is low, especially when processing longer text, resulting in insufficient accuracy of generated code.

Method used

The program mode definition is generated by obtaining the target component mode entry from the component mode information library based on the program description information and inputting it into the target large language model. Then, based on this definition, an abstract syntax tree is generated, and finally a program code is generated based on the abstract syntax tree.

Benefits of technology

It improves the accuracy and practicality of code generation, can still have high accuracy when facing the needs of complete program code generation, and makes full use of the semantic understanding ability of large language models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536695A_ABST
    Figure CN119536695A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code generation method and device, electronic equipment and a readable storage medium, and relates to the technical field of data processing.The code generation method comprises the steps that a target component mode entry is obtained from a component mode information library based on program description information; inputting the program description information and the target component mode entry into the target large language model to obtain a program mode definition output by the target large language model; generating an abstract syntax tree corresponding to the program description information based on the program mode definition; and generating a program code corresponding to the program description information according to the abstract syntax tree. The semantic understanding capability of the large language model can be fully utilized in the automatic code generation process, and the randomness and uncertainty of the large language model are inhibited through a defined regularization component mode under the condition that the large language model can fully understand program development requirements; and the accuracy and practicability of the automatically generated program code are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of data processing technology, and in particular relates to a code generation method, device, electronic equipment and readable storage medium. Background Art

[0002] Automatic code generation technology has received more and more attention. This technology aims to reduce the workload of developers and improve development efficiency by automatically generating code. In this process, automatic code generation technology simplifies the software development process and reduces the requirements for developers' professional skills. Therefore, it has gradually been applied and promoted in various software projects.

[0003] In the related art, a pre-trained large language model is usually used to directly generate corresponding code based on the functional requirement text provided by the user. The user inputs a natural language description into the large language model, and the large model automatically parses the requirement and generates corresponding code snippets.

[0004] However, the processing accuracy of large language models decreases as the length of the text increases, resulting in the above method being only applicable to the generation of shorter code snippets, and there is a problem of low accuracy in the generated code. Summary of the invention

[0005] The present invention provides a code generation method, device, electronic device and readable storage medium to solve the technical problem that the accuracy of automatically generated codes in the prior art is low.

[0006] In a first aspect, the present invention provides a code generation method, the method comprising:

[0007] Obtaining a target component pattern entry from a component pattern information library based on the program description information;

[0008] Inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model;

[0009] Generate an abstract syntax tree corresponding to the program description information based on the program pattern definition;

[0010] Generate program code corresponding to the program description information according to the abstract syntax tree.

[0011] Optionally, generating a program code corresponding to the program description information according to the abstract syntax tree includes:

[0012] Parsing the abstract syntax tree to obtain a first code;

[0013] The first code and the program description information are input into a target large language model, and the first code is modified by the target large language model to obtain the program code output by the target large language model.

[0014] Optionally, the step of inputting the first code and the program description information into a target large language model, and correcting the first code by using the target large language model to obtain the program code output by the target large language model includes:

[0015] Inputting the first code into a target large language model to obtain code description information output by the target large language model;

[0016] generating a code correction instruction according to the functional difference between the code description information and the program description information;

[0017] The first code, the program description information and the code correction instruction are input into a target large language model to obtain the program code output by the target large language model.

[0018] Optionally, the method further comprises:

[0019] Obtaining program description media information and entry function description information corresponding to the component pattern information library;

[0020] The program description media information and the item function description information are input into a target large language model to obtain program description information output by the target large language model; wherein the keywords included in the program description information match the keywords included in the item function description information.

[0021] Optionally, acquiring a target component pattern entry from a component pattern information library based on the program description information includes:

[0022] Performing semantic segmentation processing on the program description information, and extracting segmentation semantic features corresponding to the segmentation results;

[0023] The segment semantic features are matched with entry semantic features respectively corresponding to each component pattern entry in the component pattern information library to obtain the target component pattern entry.

[0024] Optionally, acquiring a target component pattern entry from a component pattern information library based on the program description information includes:

[0025] Obtaining entry name information corresponding to each component pattern entry in the component pattern information library;

[0026] Inputting the item name information and the program description information into a target large language model, obtaining a target item name corresponding to a component pattern item output by the target large language model and required to implement a target program corresponding to the program description information;

[0027] A target component schema entry is obtained from a component schema information base based on the target entry name.

[0028] Optionally, inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model includes:

[0029] Determine a target program type corresponding to the target program described in the program description information;

[0030] matching a target prompt text from a prompt text database based on the target program type;

[0031] The program description information, the target component pattern entry and the target prompt text are input into a target large language model to obtain a program pattern definition output by the target large language model.

[0032] In a second aspect, the present invention provides a code generation device, the device comprising:

[0033] An entry module, used for obtaining a target component pattern entry from a component pattern information base based on program description information;

[0034] A pattern definition module, used for inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model;

[0035] An abstract syntax tree module, used for generating an abstract syntax tree corresponding to the program description information based on the program pattern definition;

[0036] A code module is used to generate program code corresponding to the program description information according to the abstract syntax tree.

[0037] Optionally, the code module includes:

[0038] A parsing submodule, used for parsing the abstract syntax tree to obtain a first code;

[0039] The first input submodule is used to input the first code and the program description information into a target large language model, and to modify the first code through the target large language model to obtain the program code output by the target large language model.

[0040] Optionally, the first input submodule includes:

[0041] A code description information unit, used for inputting the first code into a target large language model to obtain code description information output by the target large language model;

[0042] A code correction instruction unit, used for generating a code correction instruction according to the functional difference between the code description information and the program description information;

[0043] The first input unit is used to input the first code, the program description information and the code correction instruction into a target large language model to obtain the program code output by the target large language model.

[0044] Optionally, the device further comprises:

[0045] A first acquisition module, used to acquire program description media information and entry function description information corresponding to the component pattern information library;

[0046] The program description information module is used to input the program description media information and the item function description information into a target large language model to obtain the program description information output by the target large language model; wherein the keywords included in the program description information match the keywords included in the item function description information.

[0047] Optionally, the entry module includes:

[0048] A semantic feature submodule, used for performing semantic segmentation processing on the program description information and extracting segmentation semantic features corresponding to the segmentation results;

[0049] The first entry acquisition submodule is used to match the segment semantic features with the entry semantic features respectively corresponding to each component pattern entry in the component pattern information library to obtain the target component pattern entry.

[0050] Optionally, the entry module includes:

[0051] The second acquisition submodule is used to acquire the entry name information corresponding to each component mode entry in the component mode information library;

[0052] A second input submodule is used to input the item name information and the program description information into a target large language model to obtain a target item name corresponding to a component pattern item output by the target large language model and required to implement a target program corresponding to the program description information;

[0053] The second entry acquisition submodule is used to acquire a target component pattern entry from a component pattern information base based on the target entry name.

[0054] Optionally, the mode definition module includes:

[0055] A program type submodule, used to determine a target program type corresponding to the target program described in the program description information;

[0056] A prompt text submodule, used for matching a target prompt text from a prompt text database based on the target program type;

[0057] The mode definition determination submodule is used to input the program description information, the target component mode entry and the target prompt text into the target large language model to obtain the program mode definition output by the target large language model.

[0058] In a third aspect, the present invention provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned code generation method when executing the program.

[0059] In a fourth aspect, the present invention provides a readable storage medium, which, when instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to execute the above-mentioned code generation method.

[0060] In an embodiment of the present invention, it includes: obtaining a target component pattern entry from a component pattern information library based on program description information; inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model; generating an abstract syntax tree corresponding to the program description information based on the program pattern definition; and generating program code corresponding to the program description information according to the abstract syntax tree. The defined component model can be screened to obtain a small number of target component pattern entries that meet the program description information, and then a program pattern definition with high accuracy is generated according to the target component pattern entry using a large language model, and then the program pattern definition is converted into an abstract syntax tree, and accurate program code is directly generated through the abstract syntax tree. In the process of automatic code generation, the semantic understanding ability of the large language model is fully utilized. When the large language model can fully understand the program development requirements, the randomness and uncertainty of the large language model are suppressed through the defined regularized component pattern, and the accuracy and practicality of the automatically generated program code are improved, and it still has a high accuracy when facing the complete program code generation requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0062] Figure 1 is a flowchart of a code generation method provided by an embodiment of the present invention;

[0063] Figure 2 is a flowchart of another code generation method provided by an embodiment of the present invention;

[0064] Figure 3 is a code generation example flow chart provided by an embodiment of the present invention;

[0065] Figure 4 is a structural diagram of a code generating device provided by an embodiment of the present invention;

[0066] Figure 5 It is a structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0067] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0068] Reference Figure 1 , Figure 1 1 is a flow chart of the steps of a code generation method provided by an embodiment of the present invention. Figure 1 As shown, the method may include:

[0069] Step 101: Obtain a target component pattern entry from a component pattern information library based on program description information.

[0070] In an embodiment of the present application, the program description information may represent a document used to describe the program form and development requirements. The above-mentioned program may include a front-end program, such as a client, a web page, a UI interface, etc., and may also include a back-end program, such as a database, a server, etc., or other programs, which are not specifically limited in the embodiment of the present application. The program description information may be written by a developer or provided by the demander. Exemplarily, the program description information of a client may include the location, form, function, jump relationship, and other contents of each UI control.

[0071] The component pattern information library represents a database for storing component pattern (Schema) information, where Schema is a specification for defining and describing data structures or models, which can specify the organization, data types, relationships, etc. of program component data through hierarchies and rules. Schema can be used to define program components, such as UI definition, API definition, data exchange definition, functional module definition, service definition, etc. The component pattern information library can store component pattern entries corresponding to each program component. The component pattern entries can describe the program components through specific information (such as text, code, low code). For example, when the component pattern is a user interface pattern (UI Schema), the above-mentioned program components may include but are not limited to UI composition, layout, interaction, appearance, etc.

[0072] In an embodiment of the present application, the program description information can be analyzed, and the target component pattern entries required for the corresponding program can be recalled (retrieval) from the component pattern information library. Specifically, the index information corresponding to each component pattern entry in the component pattern information library can be text-searched and matched based on the program description information to determine the target component pattern entry. The above-mentioned text retrieval method may include but is not limited to term frequency-inverse document frequency (Term Frequency-Inverse Document Frequency, TF-IDF), Best Matching 25 (Best Matching 25, BM25), dense passage retrieval (DPR), etc., which are not specifically limited in the embodiment of the present application. Among them, the index information corresponding to the component pattern entry may include but is not limited to name information, description information, feature information, instruction information, etc.

[0073] It should be noted that the Schema definition in the component schema information library can use a ready-made template or be written according to actual business needs. For example, a component schema entry about the appearance of a QR code in the component schema information library can be in the following form:

[0074] {"component":"page","body":[{"component":"barcode","backgroundColor":"#eee","foregroundColor":"#fff","value":"https: / / www.xxx.com","style":{"width":100,"height":50,"margin":5}}],"title":"Page containing QR code"}

[0075] The above component mode entry describes a page containing a QR code component and related layout, style and other configurations. Among them, component: "page" indicates that the root component of the entire JSON structure is a page. The layout, content and components of the entire page will be included in this page; body: [{...}] defines the main content of the page. In this example, the page content is a QR code (barcode) component; component: "barcode" defines a "barcode" or "QR code" display area; backgroundColor: "#eee" defines the background color of the QR code component; foregroundColor: "#fff" defines the foreground color of the QR code; value: "https: / / www.xxx.com" defines the content encoded in the QR code; style: {...} defines the style of the QR code component, including size and layout; title: "Page containing QR code" defines the title of the page where the QR code is located.

[0076] Step 102: input the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model.

[0077] In the embodiment of the present application, since the target component pattern entry includes all functions of the program that needs to be generated to implement the program description information, by assembling the target component pattern entry, a program pattern definition (Schema definition) corresponding to the program that needs to be generated by the program description information can be generated.

[0078] Since component pattern entries are blueprints that describe the data structures or components of various parts of a system or application, such as database schema, UI schema, API schema, etc. These component pattern entries define the low code of data models, UI layouts, interaction rules, API interfaces, etc. Therefore, using the above-mentioned target component pattern entries that match the program description information, a program pattern definition corresponding to the complete program required by the program description information can be generated, and the program pattern definition can be expressed as the complete low code of the program described by the program description information.

[0079] Specifically, the program description information and the target component pattern entries can be input into the target large language model, and the target large language model (LLMs) directly combines, arranges, adjusts, modifies, etc. each target component pattern entry based on the program description information to generate a corresponding program pattern definition. The target large language model may include but is not limited to GPT, LLaMA, MOSS, Pangu, etc., and the embodiments of the present application are not specifically limited.

[0080] In an embodiment of the present application, the target large language model may be a general large language model. When the general large language model is used to perform the above-mentioned tasks, corresponding prompt word information may be input, such as "The following is the program description information and the required schema data. Please output the complete mode definition of the program according to the program description information and the schema data". The target large language model may also be a task-specific model obtained by fine-tuning the general large language model so as to be dedicated to the above-mentioned tasks, so that the target large language model can perform the above-mentioned tasks without inputting prompt word information, thereby improving the operating efficiency and the accuracy of the program mode definition output.

[0081] Step 103: Generate an abstract syntax tree corresponding to the program description information based on the program pattern definition.

[0082] In an embodiment of the present application, the program schema definition can be parsed and an Abstract Syntax Tree (AST) corresponding to the program description information can be generated. Specifically, since the schema definition is usually defined using different syntax types, such as JSON (JavaScript Object Notation) syntax, YAML (YAML A in 't Markup Language) syntax, etc., the AST conversion tool corresponding to the corresponding syntax type can be used to parse and convert it to obtain an abstract syntax tree. For JSON type program description information, JSON Schema to AST tools can be used for conversion, such as Esprima, Acorn, JSON to AST, etc. For YAML type program description information, JSON toAST tools can be used for conversion, such as yaml-ast-parser, etc., which are not specifically limited in the embodiments of the present application.

[0083] In addition, the program pattern definition can be directly parsed and converted without using existing tools, thereby improving the conversion efficiency. Specifically, the program pattern definition can be parsed first to extract the structure of the definition, such as function name, parameter list, function body, etc. The parser can be a JSON parser, a YAML parser, etc., depending on the syntax type of the specific program pattern definition. During the parsing process, the root node (such as the starting point of the function definition) can be extracted according to the structure of the schema, and each attribute in the schema can be traversed. After parsing the schema, each attribute is corresponded to a node in the AST, and the entire abstract syntax tree is established recursively.

[0084] Step 104: Generate program code corresponding to the program description information according to the abstract syntax tree.

[0085] In an embodiment of the present application, the program code of the program required for the program description information can be generated according to the abstract syntax tree. Specifically, each node of the AST can be recursively traversed, and corresponding code fragments can be generated according to the type of the node, and then the code fragments generated by each child node can be combined into a complete code.

[0086] In addition, the conversion from the abstract syntax tree to program code can also be realized using ready-made tools and libraries, which may specifically include but are not limited to JavaScript's Babel tool, Python's ast module, ANTLR, etc., which are not specifically limited in the embodiments of the present application.

[0087] It should be noted that the format type used by the program code can be flexibly selected by the technician according to actual needs, and may include but is not limited to JavaScript, Vue.js, React.js, etc., and is not specifically limited in the embodiments of this application.

[0088] In the embodiments of the present application, since the program description information can describe a complete program, such as the entire client program, and can also describe partial modules in the program, such as the UI interface in the client program, the generated program code can be directly compiled to obtain the corresponding program, or it can be integrated with other codes to form a complete software code, which is not specifically limited in the embodiments of the present application.

[0089] In summary, a code generation method provided by an embodiment of the present invention includes: obtaining a target component pattern entry from a component pattern information library based on program description information; inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model; generating an abstract syntax tree corresponding to the program description information based on the program pattern definition; and generating a program code corresponding to the program description information according to the abstract syntax tree. The defined component model can be screened to obtain a small number of target component pattern entries that meet the program description information, and then a program pattern definition with high accuracy is generated according to the target component pattern entry using a large language model, and then the program pattern definition is converted into an abstract syntax tree, and accurate program code is directly generated through the abstract syntax tree. In the process of automatic code generation, the semantic understanding ability of the large language model is fully utilized. When the large language model can fully understand the program development requirements, the randomness and uncertainty of the large language model are suppressed through the defined regularized component pattern, and the accuracy and practicality of the automatically generated program code are improved, and it still has a high accuracy when facing the complete program code generation requirements.

[0090] Reference Figure 2 , Figure 2 1 is a flow chart of the steps of a code generation method provided by an embodiment of the present invention. Figure 2 As shown, the method may include:

[0091] Step 201, obtaining program description media information and entry function description information corresponding to the component pattern information library.

[0092] In the embodiments of the present application, the program demander usually conceives the required program functions through meetings, conversations, mind maps, etc. These conception processes will form program description media information such as images, audio, and video. By analyzing and summarizing these program description media information, program description information can be obtained. Among them, the program description media information may include but is not limited to meeting recordings, meeting videos, conversation recordings, mind maps, program design sketches, UI design drawings, development requirements description texts, meeting record texts, etc., and the embodiments of the present application do not make specific limitations.

[0093] Specifically, since a program function may be implemented by multiple technical means, in the embodiment of the present application, the component model information library may record the entry function description information corresponding to the technical means that the code generation automation process of the present solution can provide, and the entry function description information may be used to refine and summarize the program description media information, and the functions in the entry function description information may be used to generate the program description information corresponding to the program description media information. Among them, the entry function description information may be the additional information corresponding to each component pattern entry in the component pattern information library for recording its function, role, and usage, or it may be the name information of the component pattern entry, which is not specifically limited in the embodiment of the present application.

[0094] Step 202: input the program description media information and the item function description information into a target large language model to obtain the program description information output by the target large language model; wherein the keywords included in the program description information match the keywords included in the item function description information.

[0095] In an embodiment of the present application, the target large language model may be a multimodal large language model (MLLM), which is an artificial intelligence model that can process and generate a variety of different modal data (such as text, images, videos, audio, etc.). The program description media information and the item function description information may be input into the target large language model to obtain the program description information output by the target large language model, so that the keywords contained in the program description information match the keywords contained in the item function description information. Among them, the keywords contained in the program description information match the keywords contained in the item function description information, indicating that the program description information is described using the terms in the item function description information. For example, if the program description media information contains "this page sets two buttons, a confirmation button and a cancel button", and the item function description information contains "Button control", then "Button control" can be used in the program description information to express "button".

[0096] In an embodiment of the present application, the target large language model may be a general large language model. When the general large language model is used to perform the above-mentioned task, corresponding prompt word information may be input, such as "The following is the program description media information and the description of the development functions that can be used. Please summarize the program description media information based on these contents to obtain textual program description information. The program description information should be based on the functions existing in the development function description." The target large language model may also be a task-specific model obtained by fine-tuning the general large language model, so as to be specifically used for the above-mentioned task of generating program description information based on the program description media information and the item function description information, so that the target large language model can perform the above-mentioned task without inputting prompt word information.

[0097] By obtaining the program description media information and the entry function description information corresponding to the component pattern information library; inputting the program description media information and the entry function description information into the target large language model, the program description information output by the target large language model is obtained. The program description information can be automatically generated according to the media-based development requirement information, which helps to further improve the development efficiency.

[0098] Step 203: Obtain a target component pattern entry from a component pattern information library based on the program description information.

[0099] This step can refer to step 101, and will not be described in detail in this embodiment of the present invention.

[0100] Optionally, step 203 may be implemented by the following sub-steps:

[0101] Sub-step A1, performing semantic segmentation processing on the program description information, and extracting segmentation semantic features corresponding to the segmentation results.

[0102] In an embodiment of the present application, the program description information can be semantically segmented to obtain multiple segmentation results. Semantic segmentation (Semantic Segmentation of Text), the goal of semantic segmentation is to divide the text into different parts or paragraphs according to the semantic content in the text, each part represents a semantic unit or theme. Specifically, semantic segmentation can include rule-based segmentation, such as dividing paragraphs according to formatting marks in the text (such as line breaks, paragraph marks, punctuation marks); it can also include machine learning-based segmentation, that is, using natural language processing models (such as BERT, GPT, etc.) to identify natural pause points in semantics and divide the content into different semantic units. The embodiment of the present application does not specifically limit the above-mentioned semantic segmentation method.

[0103] After obtaining the semantic segmentation results, the segmentation semantic features of the semantic segmentation results can be extracted through word embedding models, topic models, Transformer-based semantic feature extraction models, etc.

[0104] Sub-step A2, matching the segment semantic features with the entry semantic features corresponding to each component pattern entry in the component pattern information library, to obtain the target component pattern entry.

[0105] In an embodiment of the present application, corresponding entry semantic features can be generated for each component pattern entry in the component pattern information library. The entry semantic features can be generated when matching is required, or can be generated and stored in advance, thereby improving the matching speed. The entry semantic features can be obtained by extracting semantic features based on relevant information of the component pattern entry (such as name, description, instructions, etc.). Each segmented semantic feature can be matched with the entry semantic feature corresponding to each component pattern entry to obtain the semantic similarity between each segmented semantic feature and each entry semantic feature.

[0106] In one embodiment, the component pattern entries of the entry semantic features corresponding to one or more maximum similarities among all the semantic similarities corresponding to a segmented semantic feature may be determined as the target component pattern entries. In another embodiment, the component pattern entries of the entry semantic features corresponding to the semantic similarities greater than or equal to the preset similarity among all the semantic similarities corresponding to a segmented semantic feature may be determined as the target component pattern entries.

[0107] By performing semantic segmentation processing on the program description information, the segmentation semantic features corresponding to the segmentation results are extracted; the segmentation semantic features are matched with the entry semantic features corresponding to each component pattern entry in the component pattern information library to obtain the target component pattern entry. The target component pattern entry can be determined based on the semantic features, and a relatively accurate target component pattern entry can still be determined when there is a certain deviation between the program description information and the description of the component pattern entry.

[0108] Optionally, step 203 may also be implemented by the following sub-steps:

[0109] Sub-step B1, obtaining the entry name information corresponding to each component pattern entry in the component pattern information library.

[0110] In the embodiment of the present application, since there may be a large number of component pattern entries in the component pattern information base, in order to improve the efficiency of determining the target entry name, it is also possible to obtain only the entry name information corresponding to each component pattern entry in the component pattern information base, and the entry name information generally carries part of the information of the function implemented by the entry. Among them, the entry name information may include the entry names corresponding to all component pattern entries in the component pattern information base.

[0111] Sub-step B2, inputting the item name information and the program description information into a target large language model, and obtaining a target item name corresponding to a component pattern item output by the target large language model and required to implement a target program corresponding to the program description information.

[0112] Since the amount of information contained in the entry name information is limited and may be vague, in order to accurately determine the target component pattern entry based on the entry name information, a target large language model can be used. The entry name information and program description information are input into the target large language model, so that the target large language model selects the target entry name corresponding to the target component pattern entry required by the program according to the entry name information.

[0113] In one implementation, a general large language model may be used to perform the above-mentioned task of obtaining the target entry name. At this time, corresponding prompt word information may be inputted into the large language model while the entry name information and program description information are inputted. For example, "The following is the program description information and all Schema component entry names. Please select the required component entry names according to the program requirements and output them." The target large language model may also be a task-specific model obtained by fine-tuning the general large language model, so as to be dedicated to the above-mentioned task of obtaining the target entry name, so that the target large language model can perform the above-mentioned task without inputting prompt word information.

[0114] Sub-step B3: acquiring a target component pattern entry from a component pattern information base based on the target entry name.

[0115] By obtaining the entry name information corresponding to each component pattern entry in the component pattern information library; inputting the entry name information and program description information into the target large language model, obtaining the target entry name corresponding to the component pattern entry required to implement the target program corresponding to the program description information output by the target large language model; obtaining the target component pattern entry from the component pattern information library based on the target entry name. The target component pattern entry that matches the program description information can be determined based on the entry name information with a small amount of data, and the entire process is based on a large language model that can be based on semantic recognition with high accuracy, which can improve the efficiency of obtaining the target component pattern entry while maintaining high accuracy.

[0116] Step 204: determine the target program type corresponding to the target program described by the program description information.

[0117] In the embodiment of the present application, the target program described by the program description information may be a variety of different program types, including but not limited to user interface programs, front-end programs, back-end programs, data processing programs, web page programs, etc. Different prompt texts may be used for different program types to improve the output accuracy of the program mode definition. Therefore, the target program type corresponding to the target program described by the program description information can be determined according to the program description information.

[0118] Specifically, semantic features can be extracted from the program description information to obtain program description semantic features, and similarity matching can be performed between the program description semantic features and type semantic features corresponding to each preset program type to obtain feature similarities between the program description semantic features and each type semantic feature, and the program type corresponding to the type semantic feature corresponding to the highest similarity among the feature similarities of the program description semantic features can be determined as the target program type corresponding to the program description information.

[0119] It is also possible to directly input all preset program types and program description information into the large language model, and instruct the large language model through corresponding prompt words to select a target program type that best matches the program description information from the preset program types.

[0120] Step 205: Match target prompt text from a prompt text database based on the target program type.

[0121] In an embodiment of the present application, in an embodiment of the present application, different prompt questions for generating program pattern definitions can be set for different target program types. For example, for a front-end program type, the corresponding prompt text can include qualifiers of the interface style, such as concise, beautiful, high contrast, etc. For an algorithm program type, the corresponding prompt text can include qualifiers such as high efficiency and low resource utilization. This allows the large language model to perform targeted optimization when generating program pattern definitions for program description information of different program types, which is more in line with the usage scenarios of specific program types.

[0122] Specifically, the correspondence between various program types and prompt texts may be set in advance through expert experience or the like, and the target program type may be used to retrieve the correspondence to obtain the corresponding target prompt text.

[0123] Step 206: input the program description information, the target component pattern entry and the target prompt text into a target large language model to obtain a program pattern definition output by the target large language model.

[0124] By determining the target program type corresponding to the target program described by the program description information; matching the target prompt text from the prompt text database based on the target program type; inputting the program description information, the target component pattern entry and the target prompt text into the target large language model, the program pattern definition output by the target large language model is obtained. This allows the large language model to perform targeted optimization when generating program pattern definitions for program description information of different program types, making it more suitable for the usage scenarios of specific program types, and improving the matching degree between the program pattern definition and program development requirements.

[0125] Step 207: Generate an abstract syntax tree corresponding to the program description information based on the program pattern definition.

[0126] This step can refer to the above-mentioned step 103, and will not be described in detail in this embodiment of the present application.

[0127] Step 208: parse the abstract syntax tree to obtain a first code.

[0128] In the embodiment of the present application, the abstract syntax tree can be parsed first to obtain the first code, wherein the first code is obtained by directly parsing the abstract syntax tree, and the two contain the same programming content. The process of obtaining the first code based on the abstract syntax tree parsing can refer to the process of generating the program code in step 104, and the embodiment of the present application will not be repeated.

[0129] Step 209: input the first code and the program description information into a target large language model, and modify the first code through the target large language model to obtain the program code output by the target large language model.

[0130] Since the first code is generated based on the Schema definition, the Schema definition may have missing functions, be unsuitable for the program, etc., which may cause imperfections in the first code. Therefore, the generated first code and program description information may be input into the target large language model again, so that the target large language model can correct the first code, wherein the correction may include but is not limited to at least one of error correction, completion, optimization, adding comment information, code adaptation, etc. Code adaptation means making necessary adjustments to the code so that it can meet the naming specifications, interface specifications, annotation specifications, format specifications, etc. of the current project or development team.

[0131] In one implementation, a general large language model may be used to perform the above correction task. At this time, corresponding correction prompt word information may be input into the large language model while inputting the first code and program description information. The correction prompt word information may be flexibly set according to the correction requirements, for example, "The following is the program description information and the corresponding code. Please correct and optimize these codes according to the program requirements and add annotation information." The target large language model may also be a task-specific model obtained by fine-tuning the general large language model, so as to be dedicated to the above code correction task, so that the target large language model can perform the above task without inputting prompt word information.

[0132] The first code is obtained by parsing the abstract syntax tree; the first code and the program description information are input into a target large language model, and the first code is corrected by the target large language model to obtain the program code output by the target large language model. The accuracy and practicality of the program code generated based on the program description information can be improved.

[0133] Optionally, step 209 may include:

[0134] Sub-step 2091: input the first code into a target large language model to obtain code description information output by the target large language model.

[0135] In an embodiment of the present application, the first code can be input into the target large language model to obtain code description information output by the target large language model, and the code description information is used to describe the actual function and characteristics of the first code. In one embodiment, a general large language model can be used to perform the above-mentioned code description information generation task. At this time, the corresponding prompt word information can be input while inputting the first code into the large language model, such as "Please describe the functions and characteristics of the following code in detail." The target large language model can also be a task-specific model obtained by fine-tuning the general large language model, which is dedicated to the above-mentioned code description information generation task, so that the target large language model can perform the above-mentioned task without inputting the prompt word information.

[0136] Sub-step 2092, generating a code correction instruction according to the functional difference between the code description information and the program description information.

[0137] In an embodiment of the present application, the code description information and the program description information can be compared to determine the functional difference between the two, and then a code correction instruction can be generated based on the functional difference. Among them, the functional difference can be used to represent the difference between the software functions indicated by the code description information and the program description information. For example, the functional difference may include code missing functions and code redundant functions of the first code. Specifically, the code description information and the program description information can be analyzed by a natural language processing tool (NLP), and the semantic features of the two can be extracted. By comparing the semantic features, the functional difference between the two can be determined. In addition, the functional difference between the two can also be determined based on a large language model, which is not specifically limited in the embodiment of the present application.

[0138] For example, if the code description information is "a user interface A, which includes a black QR code" and the program description information is "a user interface A, which includes a red QR code and a cancel button", then accordingly, the functional differences between the two may include "difference in color of the QR code in user interface A, and missing cancel button in user interface A".

[0139] After obtaining the functional difference, a code correction instruction can be generated according to the functional difference. Specifically, the functional difference information can be spliced ​​with preset fixed information to obtain the code correction instruction. For example, the preset fixed information can be "The following are the problems with the code. Please correct and improve the code based on this." The code correction instruction can also be generated directly according to the code description information and the program description information. For example, the code description information and the program description information can be directly input into the large language model, and prompt word information indicating how to modify the code description information output by the large language model to make it consistent with the program function indicated by the program description information is input, and the code correction instruction output by the large language model is directly obtained.

[0140] Sub-step 2093: input the first code, the program description information and the code correction instruction into a target large language model to obtain the program code output by the target large language model.

[0141] In an embodiment of the present application, the first code, program description information and code correction instructions can be input into the target large language model, so that the large language model can modify the first code in a targeted manner based on the program description information and the code correction instructions to obtain the program code output by the target large language model. Since the amount of information that can be referenced by the large language model when modifying the code is increased, it helps to improve the effect of suppressing the model hallucination of the large language model during the correction process, thereby improving the code correction effect and obtaining more accurate program code.

[0142] It should be noted that in the embodiments of the present application, since different large language models may have different accuracy and efficiency when performing different tasks, the target large language models for performing different tasks in different steps may be the same or different. The same general large language model may be used to perform all tasks, or different general large language models may be used to perform different tasks. Different fine-tuning methods may also be used for different tasks to obtain different task-specific models, which is not specifically limited in the embodiments of the present application.

[0143] Reference Figure 3 , Figure 3 A code generation example flow chart provided in an embodiment of the present application is shown, referring to Figure 3 Taking the generation of client programs as an example, the user can first describe the client requirements to obtain program description information, and then retrieve the component pattern information library based on the program description information, recall the target component pattern entry, input the target component pattern entry and the program description information into the big model, obtain the program pattern definition (Schema), and then generate the first code according to the program pattern definition, and finally input the first code and the program description information into the big model, so that the big model can modify the first code and obtain the complete program code of the client.

[0144] In summary, another code generation method provided by an embodiment of the present invention obtains a target component pattern entry from a component pattern information library based on program description information; inputs the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model; generates an abstract syntax tree corresponding to the program description information based on the program pattern definition; and generates a program code corresponding to the program description information according to the abstract syntax tree. The defined component model can be screened to obtain a small number of target component pattern entries that meet the program description information, and then a large language model is used to generate a program pattern definition with high accuracy according to the target component pattern entry, and then the program pattern definition is converted into an abstract syntax tree, and accurate program code is directly generated through the abstract syntax tree. In the process of automatic code generation, the semantic understanding ability of the large language model is fully utilized. When the large language model can fully understand the program development requirements, the randomness and uncertainty of the large language model are suppressed through the defined regularized component pattern, and the accuracy and practicality of the automatically generated program code are improved, and it still has a high accuracy when facing the complete program code generation requirements.

[0145] Reference Figure 4 , Figure 4 4 is a structural diagram of a code generating device provided by an embodiment of the present invention. The code generating device 40 may include:

[0146] An entry module 41, used for acquiring a target component pattern entry from a component pattern information base based on the program description information;

[0147] A pattern definition module 42, used for inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model;

[0148] An abstract syntax tree module 43, used to generate an abstract syntax tree corresponding to the program description information based on the program pattern definition;

[0149] The code module 44 is used to generate program code corresponding to the program description information according to the abstract syntax tree.

[0150] Optionally, the code module includes:

[0151] A parsing submodule, used for parsing the abstract syntax tree to obtain a first code;

[0152] The first input submodule is used to input the first code and the program description information into a target large language model, and to modify the first code through the target large language model to obtain the program code output by the target large language model.

[0153] Optionally, the first input submodule includes:

[0154] A code description information unit, used for inputting the first code into a target large language model to obtain code description information output by the target large language model;

[0155] A code correction instruction unit, used for generating a code correction instruction according to the functional difference between the code description information and the program description information;

[0156] The first input unit is used to input the first code, the program description information and the code correction instruction into a target large language model to obtain the program code output by the target large language model.

[0157] Optionally, the device further comprises:

[0158] A first acquisition module, used to acquire program description media information and entry function description information corresponding to the component pattern information library;

[0159] The program description information module is used to input the program description media information and the item function description information into a target large language model to obtain the program description information output by the target large language model; wherein the keywords included in the program description information match the keywords included in the item function description information.

[0160] Optionally, the entry module includes:

[0161] A semantic feature submodule, used for performing semantic segmentation processing on the program description information and extracting segmentation semantic features corresponding to the segmentation results;

[0162] The first entry acquisition submodule is used to match the segment semantic features with the entry semantic features respectively corresponding to each component pattern entry in the component pattern information library to obtain the target component pattern entry.

[0163] Optionally, the entry module includes:

[0164] The second acquisition submodule is used to acquire the entry name information corresponding to each component mode entry in the component mode information library;

[0165] A second input submodule is used to input the item name information and the program description information into a target large language model to obtain a target item name corresponding to a component pattern item output by the target large language model and required to implement a target program corresponding to the program description information;

[0166] The second entry acquisition submodule is used to acquire a target component pattern entry from a component pattern information base based on the target entry name.

[0167] Optionally, the mode definition module includes:

[0168] A program type submodule, used to determine a target program type corresponding to the target program described in the program description information;

[0169] A prompt text submodule, used for matching a target prompt text from a prompt text database based on the target program type;

[0170] The mode definition determination submodule is used to input the program description information, the target component mode entry and the target prompt text into the target large language model to obtain the program mode definition output by the target large language model.

[0171] In summary, the code generation device provided by the embodiment of the present invention includes: an entry module, which is used to obtain a target component pattern entry from a component pattern information library based on program description information; a pattern definition module, which is used to input the program description information and the target component pattern entry into the target large language model to obtain a program pattern definition output by the target large language model; an abstract syntax tree module, which is used to generate an abstract syntax tree corresponding to the program description information based on the program pattern definition; and a code module, which is used to generate a program code corresponding to the program description information according to the abstract syntax tree. The defined component model can be screened to obtain a small number of target component pattern entries that meet the program description information, and then a large language model is used to generate a program pattern definition with high accuracy according to the target component pattern entry, and then the program pattern definition is converted into an abstract syntax tree, and accurate program code is directly generated through the abstract syntax tree. In the process of automatic code generation, the semantic understanding ability of the large language model is fully utilized. When the large language model can fully understand the program development requirements, the randomness and uncertainty of the large language model are suppressed through the defined regularized component pattern, and the accuracy and practicality of the automatically generated program code are improved, and it still has a high accuracy when facing the complete program code generation requirements.

[0172] Reference Figure 5 , the present invention also provides a structural diagram of an electronic device, such as Figure 5 As shown, it includes: a processor 1101, a memory 1102, and a computer program 11021 stored in the memory and executable on the processor, and the code generation method of the aforementioned embodiment is implemented when the processor executes the program.

[0173] The present invention also provides a readable storage medium, when the instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the code generation method of the aforementioned embodiment.

[0174] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0175] It should be noted that the various information and data obtained in the embodiments of the present invention are all obtained with the authorization of the information / data holder.

[0176] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages ​​can be utilized to realize the content of the present invention described herein, and the description of the above specific languages ​​is for disclosing the best mode of the present invention.

[0177] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0178] Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.

[0179] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

[0180] The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components in the sorting device according to the present invention. The present invention may also be implemented as a device or apparatus program for executing part or all of the methods described herein. Such a program for implementing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0181] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.

[0182] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0183] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

[0184] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A code generation method, characterized in that: The method comprises: Obtaining a target component pattern entry from a component pattern information library based on the program description information; Inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model; Generate an abstract syntax tree corresponding to the program description information based on the program pattern definition; Generate program code corresponding to the program description information according to the abstract syntax tree.

2. The method according to claim 1, characterized in that The generating the program code corresponding to the program description information according to the abstract syntax tree includes: Parsing the abstract syntax tree to obtain a first code; The first code and the program description information are input into a target large language model, and the first code is modified by the target large language model to obtain the program code output by the target large language model.

3. The method according to claim 2, characterized in that The step of inputting the first code and the program description information into a target large language model, and correcting the first code by using the target large language model to obtain the program code output by the target large language model includes: Inputting the first code into a target large language model to obtain code description information output by the target large language model; generating a code correction instruction according to the functional difference between the code description information and the program description information; The first code, the program description information and the code correction instruction are input into a target large language model to obtain the program code output by the target large language model.

4. The method according to claim 1, characterized in that: The method further comprises: Obtaining program description media information and entry function description information corresponding to the component pattern information library; The program description media information and the item function description information are input into a target large language model to obtain program description information output by the target large language model; wherein the keywords included in the program description information match the keywords included in the item function description information.

5. The method according to claim 1, characterized in that The step of acquiring a target component pattern entry from a component pattern information library based on the program description information includes: Performing semantic segmentation processing on the program description information, and extracting segmentation semantic features corresponding to the segmentation results; The segment semantic features are matched with entry semantic features respectively corresponding to each component pattern entry in the component pattern information library to obtain the target component pattern entry.

6. The method according to claim 1, characterized in that The step of acquiring a target component pattern entry from a component pattern information library based on the program description information includes: Obtaining entry name information corresponding to each component pattern entry in the component pattern information library; Inputting the item name information and the program description information into a target large language model, obtaining a target item name corresponding to a component pattern item output by the target large language model and required to implement a target program corresponding to the program description information; A target component schema entry is obtained from a component schema information base based on the target entry name.

7. The method according to claim 1, characterized in that The step of inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model includes: Determine a target program type corresponding to the target program described in the program description information; matching a target prompt text from a prompt text database based on the target program type; The program description information, the target component pattern entry and the target prompt text are input into a target large language model to obtain a program pattern definition output by the target large language model.

8. A code generating device, characterized in that: The device comprises: An entry module, used for obtaining a target component pattern entry from a component pattern information base based on program description information; A pattern definition module, used for inputting the program description information and the target component pattern entry into a target large language model to obtain a program pattern definition output by the target large language model; An abstract syntax tree module, used for generating an abstract syntax tree corresponding to the program description information based on the program pattern definition; A code module is used to generate program code corresponding to the program description information according to the abstract syntax tree.

9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.

10. A readable storage medium, characterized in that: When the instructions in the readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any one of the methods described in claims 1-7.

Citation Information

Patent Citations

  • Code generation method and device, electronic equipment and storage medium

    CN117762389A

  • Software code generation method and device, electronic equipment and storage medium

    CN118034670A

  • Structured query language generation method and device, electronic equipment and storage medium

    CN118093621A

  • Code generation method based on large language model, medium and equipment

    CN118363580A