Code content generation method, device, equipment, medium and program product
Patent Information
- Application Number
- CN202610686273.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-18
- Publication Date
- 2026-08-28
AI Technical Summary
例如,侵入性强,通常需要在项目代码中插入特定注解、注释或继承特定基类,污染了业务代码
[0023]The above embodiments of this disclosure have the following beneficial effects: The code content generation method of some embodiments of this disclosure can automatically generate code content of the corresponding type in a non-intrusive, flexible, and accurate manner. Specifically, the significant limitations of the code content generation process of the corresponding type are: strong intrusiveness, usually requiring the insertion of specific annotations, comments, or inheritance of specific base classes into the project code, polluting the business code; strong binding to specific technical frameworks, poor flexibility, fixed generated code structure, and difficulty in customization. Based on this, the code content generation method of some embodiments of this disclosure firstly parses the target code generation request to obtain parsing information for the target business entity, wherein the parsing information includes entity metadata and template selection information. Here, by obtaining entity metadata, the separation of metadata (i.e., business description) and code can be achieved, so as to obtain the business description content for the target business entity based on the entity metadata. Using the corresponding developed and maintained template text, the corresponding code content can be generated efficiently and non-intrusively. Here, by setting different template texts, flexible generation of code content under the corresponding file type can be achieved. Then, the above entity metadata is converted into a data model under the target format to generate a standardized business entity data model. Here, by generating standardized business entity data models, it is ensured that all files originate from the same metadata, guaranteeing consistency between APIs (Application Programming Interfaces), data models, and database schemas. This significantly reduces vulnerabilities caused by manual, out-of-sync modifications, improving system performance and user experience. Finally, using a template engine, the code content corresponding to the loaded template text is generated. The code file type corresponding to the template selection information is the same as the code file type corresponding to the code content. In summary, by generating standardized data models based on entity metadata and flexibly calling template texts of corresponding code file types, the corresponding type of code content can be automatically generated non-intrusively, flexibly, and accurately.
Smart Images

Figure CN122653579A_ABST
Abstract
Description
Technical Field
[0001] The embodiments disclosed herein relate to the field of computer technology, and specifically to code content generation methods, apparatus, devices, media, and program products. Background Technology
[0002] Currently, with the rapid development of the internet, microservice-based internet applications are becoming increasingly mature, system functions are becoming more complex, and business requirements are constantly changing. Faced with these complex and ever-changing business demands, it is often necessary to add new business tables, parse business data, and develop different types of code files (such as Entity, Interface, Mapper, etc.). The typical approach to generating code files for corresponding code file types and business entities is to use code generators and automated project initialization tools (such as Spring Boot Initializer) to generate the code content for those specific code file types and business entities.
[0003] However, the inventors discovered that the following technical problems often arise when using the above method: Generating code using code generators has significant limitations. For example, it is highly intrusive, often requiring the insertion of specific annotations, comments, or inheritance of specific base classes into the project code, thus polluting the business logic. It is also strongly tied to specific technical frameworks, lacking flexibility, and the generated code has a fixed structure that is difficult to customize. Summary of the Invention
[0004] The summary portion of this disclosure is intended to provide a brief overview of the concepts, which will be described in detail in the detailed description portion. This summary portion is not intended to identify key or essential features of the claimed technical solutions, nor is it intended to limit the scope of the claimed technical solutions.
[0005] Some embodiments of this disclosure provide code content generation methods, apparatuses, electronic devices, computer-readable media, and program products to address the technical problems mentioned in the background section above.
[0006] In a first aspect, some embodiments of this disclosure provide a code content generation method, including: parsing a target code generation request to obtain parsing information for a target business entity, wherein the parsing information includes: entity metadata and template selection information; converting the entity metadata into a data model in a target format; loading the data model into template text corresponding to the template selection information to obtain loaded template text; and using a template engine to generate code content corresponding to the loaded template text, wherein the code file type corresponding to the template selection information is the same as the code file type corresponding to the code content.
[0007] Optionally, the above-mentioned conversion of the entity metadata into a data model in the target format includes: determining the metadata adapter corresponding to the entity metadata; and using the metadata adapter to convert the entity metadata into a data model in the target format.
[0008] Optionally, loading the data model into the template text corresponding to the template selection information to obtain the loaded template text includes: obtaining the template text corresponding to the template selection information from the template text repository as the target template text, wherein the template text repository stores template texts corresponding to various code file types; and loading the data model into the target template text to obtain the loaded template text.
[0009] Optionally, the template selection information includes: at least one selection information for at least one code file type; and obtaining the template text corresponding to the template selection information from the template text repository as the target template text includes: for each selection information, obtaining the template text corresponding to the selection information from the template text repository as a template sub-file, wherein the code file type corresponding to the template sub-file is the code file type corresponding to the selection information; determining the obtained at least one template sub-file as the target template text; and loading the data model into the target template text to obtain the loaded template text includes: loading the data model into the at least one model sub-file to obtain at least one loaded template sub-text as the loaded template text; and generating the code content corresponding to the loaded template text using the template engine includes: using the template engine to generate the code sub-content corresponding to each loaded template sub-text in the at least one loaded template sub-text to obtain at least one code sub-content as the code content.
[0010] Optionally, the parsed information may also include: code output path; and the method may also include: generating a code file of the corresponding code file type for the target business entity based on the code content and the code output path.
[0011] Optionally, after obtaining the template text corresponding to the template selection information from the template text repository as the target template text, the method further includes: in response to determining that the template text repository does not contain the template text corresponding to the template selection information, generating a first initial template text using a pre-trained large language model that supports template customization based on the template selection information and the code file type; displaying the first initial template text on the template text display page; and in response to selecting confirmation information for the first initial template text on the template text display page, determining the first initial template text as the target template text and storing the target template text in the template text repository.
[0012] Optionally, the above method further includes: in response to selecting file modification information for the initial template text on the template text display page, generating a second initial template text using the large language model based on the file modification information, the template selection information, and the code file type; displaying the second initial template text and the corresponding file modification content on the template text display page; and in response to selecting confirmation information for the second initial template text on the template text display page, determining the second initial template text as the target template text and storing the target template text in the template text repository.
[0013] Secondly, some embodiments of this disclosure provide a code content generation apparatus, including: a parsing unit configured to parse a target code generation request to obtain parsing information for a target business entity, wherein the parsing information includes entity metadata and template selection information; a conversion unit configured to convert the entity metadata into a data model in a target format; a loading unit configured to load the data model into template text corresponding to the template selection information to obtain loaded template text; and a generation unit configured to use a template engine to generate code content corresponding to the loaded template text, wherein the code file type corresponding to the template selection information is the same as the code file type corresponding to the code content.
[0014] Optionally, the transformation unit can be configured to: determine the metadata adapter corresponding to the aforementioned entity metadata; and use the aforementioned metadata adapter to convert the aforementioned entity metadata into a data model in the target format.
[0015] Optionally, the loading unit can be configured to: retrieve the template text corresponding to the template selection information from the template text repository as the target template text, wherein the template text repository stores template texts corresponding to various code file types; load the data model into the target template text to obtain the loaded template text.
[0016] Optionally, the template selection information includes at least one selection information for at least one code file type; and the loading unit can be configured to: for each selection information, obtain the template text corresponding to the selection information from the template text repository as a template sub-file, wherein the code file type corresponding to the template sub-file is the code file type corresponding to the selection information; and determine the obtained at least one template sub-file as the target template text. The loading unit can also be configured to: load the data model into the at least one model sub-file to obtain at least one loaded template sub-text as the loaded template text. The first generation unit can be configured to: use the template engine to generate code sub-content corresponding to each loaded template sub-text in the at least one loaded template sub-text, obtaining at least one code sub-content as the code content.
[0017] Optionally, the parsed information may further include: code output path; and the device may further include: generating a code file of the corresponding code file type for the target business entity based on the code content and the code output path.
[0018] Optionally, the loading unit can be configured to: in response to determining that the template text repository does not contain the template text corresponding to the template selection information, generate a first initial template text using a pre-trained large language model that supports template customization based on the template selection information and the code file type; display the first initial template text on the template text display page; and in response to selecting confirmation information for the first initial template text on the template text display page, determine the first initial template text as the target template text and store the target template text in the template text repository.
[0019] Optionally, the loading unit can be configured to: in response to selecting file modification information for the initial template text on the template text display page, generate a second initial template text based on the file modification information, the template selection information, and the code file type, using the large language model; display the second initial template text and the corresponding file modification content on the template text display page; and in response to selecting confirmation information for the second initial template text on the template text display page, determine the second initial template text as the target template text and store the target template text in the template text repository.
[0020] Thirdly, some embodiments of this disclosure provide an electronic device, including: one or more processors; and a storage device having one or more programs stored thereon, such that when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any implementation of the first aspect.
[0021] Fourthly, some embodiments of this disclosure provide a computer-readable medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the method as described in any implementation of the first aspect.
[0022] Fifthly, some embodiments of this disclosure provide a computer program product, including a computer program that, when executed by a processor, implements the method described in any of the implementations of the first aspect above.
[0023] The above embodiments of this disclosure have the following beneficial effects: The code content generation method of some embodiments of this disclosure can automatically generate code content of the corresponding type in a non-intrusive, flexible, and accurate manner. Specifically, the significant limitations of the code content generation process of the corresponding type are: strong intrusiveness, usually requiring the insertion of specific annotations, comments, or inheritance of specific base classes into the project code, polluting the business code; strong binding to specific technical frameworks, poor flexibility, fixed generated code structure, and difficulty in customization. Based on this, the code content generation method of some embodiments of this disclosure firstly parses the target code generation request to obtain parsing information for the target business entity, wherein the parsing information includes entity metadata and template selection information. Here, by obtaining entity metadata, the separation of metadata (i.e., business description) and code can be achieved, so as to obtain the business description content for the target business entity based on the entity metadata. Using the corresponding developed and maintained template text, the corresponding code content can be generated efficiently and non-intrusively. Here, by setting different template texts, flexible generation of code content under the corresponding file type can be achieved. Then, the above entity metadata is converted into a data model under the target format to generate a standardized business entity data model. Here, by generating standardized business entity data models, it is ensured that all files originate from the same metadata, guaranteeing consistency between APIs (Application Programming Interfaces), data models, and database schemas. This significantly reduces vulnerabilities caused by manual, out-of-sync modifications, improving system performance and user experience. Finally, using a template engine, the code content corresponding to the loaded template text is generated. The code file type corresponding to the template selection information is the same as the code file type corresponding to the code content. In summary, by generating standardized data models based on entity metadata and flexibly calling template texts of corresponding code file types, the corresponding type of code content can be automatically generated non-intrusively, flexibly, and accurately. Attached Figure Description
[0024] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and elements are not necessarily drawn to scale.
[0025] Figure 1 This is a schematic diagram illustrating an application scenario of a code content generation method according to some embodiments of this disclosure; Figure 2 This is a flowchart of some embodiments of the method for generating code based on the code content of this disclosure; Figure 3 This is a flowchart of some other embodiments of the method for generating code based on the code content of this disclosure; Figure 4 These are schematic diagrams illustrating the structure of some embodiments of the code content generation apparatus according to this disclosure; Figure 5 This is a schematic diagram of the structure of an electronic device suitable for implementing some embodiments of the present disclosure. Detailed Implementation
[0026] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0027] It should also be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings. Unless otherwise specified, the embodiments and features described in this disclosure can be combined with each other.
[0028] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.
[0029] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0030] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0031] Before performing any of the operations involving the collection, storage, or use of user personal information (such as target code generation requests) disclosed in this disclosure, the relevant organizations or individuals shall fulfill their obligations, including conducting personal information security impact assessments, informing personal information subjects, and obtaining prior authorization and consent from personal information subjects.
[0032] This disclosure will now be described in detail with reference to the accompanying drawings and embodiments.
[0033] Figure 1 This is a schematic diagram illustrating an application scenario of a code content generation method according to some embodiments of this disclosure.
[0034] exist Figure 1 In this application scenario, firstly, the electronic device 101 can parse the target code generation request 102 to obtain parsing information 103 for the target business entity. This parsing information 103 includes entity metadata 1031 and template selection information 1032. In this application scenario, entity metadata 1031 can be entity metadata A. Template selection information 1032 can be "select template text corresponding to code file type 1". Then, the electronic device 101 can convert the entity metadata 1031 into a data model 104 in the target format. Next, the electronic device 101 can load the data model 104 into the template text 105 corresponding to the template selection information 1032, obtaining the loaded template text 106. In this application scenario, the loaded template text 1 can be obtained by loading the data model 103 into template text 1. Finally, the electronic device 101 can use a template engine to generate code content 107 corresponding to the loaded template text 106, wherein the code file type corresponding to the template selection information 1032 is the same as the code file type corresponding to the code content 107.
[0035] It should be noted that the aforementioned electronic device 101 can be either hardware or software. When the electronic device is hardware, it can be implemented as a distributed cluster consisting of multiple servers or terminal devices, or as a single server or a single terminal device. When the electronic device is software, it can be installed in the hardware devices listed above. It can be implemented as, for example, multiple software programs or software modules used to provide distributed services, or as a single software program or software module. No specific limitations are made here.
[0036] It should be understood that Figure 1 The number of electronic devices shown is merely illustrative. Any number of electronic devices can be used depending on the implementation requirements.
[0037] Continue to refer to Figure 2 The diagram illustrates a flow 200 of some embodiments of a code content generation method according to the present disclosure. The code content generation method includes the following steps: Step 201: Parse the target code generation request to obtain parsing information for the target business entity.
[0038] In some embodiments, the execution body of the above code content generation method (e.g.) Figure 1The electronic device 101 shown can parse the target code generation request to obtain parsing information for the target business entity. The target code generation request can be a request to generate code content corresponding to the target code file type, representing the entity to be processed. The target code file type can be the display format of the code content corresponding to the currently requested target business entity. In practice, the target code file type can be one of the following: Entity type, Interface type, or Mapper type. The target business entity can be the object from which the code content is generated. That is, code content under the corresponding target code file type is generated based on the entity content of the target business entity information. The target business entity can be entity information under the target business. Here, entity information can be an entity identifier. The target business can be a target activity business. For example, the target activity business can be a promotional business targeting a target group. In practice, the target business entity here can be a target user or a target item. The parsing information can be the parsing result after parsing the target code generation request. The above parsing information includes entity metadata and template selection information. The entity metadata can be entity information describing the above target business entity. For example, entity metadata can be the identity and address description information of the target user. Template selection information can be the selection information for template text. For example, template selection information could be the template text corresponding to the target code file type. In practice, template text can be a pre-designed code framework / specification used to guide the automated generation of target code, with the core function of "providing a fixed structure + reserving space for dynamic replacement". The essence of template text is a set of "semi-finished code logic" or "format specifications", which includes both the fixed structure of the code (e.g., package declaration, class structure, and method framework of Java classes; syntax templates for SQL statements; tag structure of front-end components, etc.) and dynamically replaceable placeholders (e.g., using {{className}} to place class names and {{methodName}} to place method names). Here, using template text, the code generator can automatically generate code content under the corresponding code file type. Template text can be customized and extended according to actual business needs. For example, template text can be one of the following: template text corresponding to JavaEntity.vm, template text corresponding to TypeScriptInterface.vm, template text corresponding to MyBatisMapper.vm, and template text corresponding to SwaggerSchema.vm. Each template text has a corresponding code output type.
[0039] In practice, the metadata parsing unit within the execution entity can be used to obtain and parse the target code generation request, thereby acquiring parsed information for the target business entity. The metadata parsing unit can be a module that parses metadata.
[0040] As an example, the aforementioned execution entity can use the target parsing script to parse the target code generation request and obtain parsing information for the target business entity.
[0041] Step 202: Convert the above entity metadata into a data model in the target format.
[0042] In some embodiments, the aforementioned executing entity can convert the entity metadata into a data model in a target format. The target format can be a pre-defined data format. In practice, the target format can represent a standardized data format. The data model can be a data representation in the target format. For example, the data model can be an object including Entity, className, and fields. The data model can be an intermediate description describing the target business entity.
[0043] In practice, the metadata of the aforementioned entities can be converted into a data model in the target format using a metadata parsing module.
[0044] As an example, the aforementioned execution entity can utilize a large language model pre-trained based on entity knowledge and code knowledge to convert the aforementioned entity metadata into a data model in the target format.
[0045] In some optional implementations of certain embodiments, the aforementioned execution entity may convert the aforementioned entity metadata into a data model in a target format, including the following steps: The first step is to determine the metadata adapter corresponding to the aforementioned entity metadata. The metadata adapter is used to read entity metadata from a specific source and normalize it into a standard data model within the system. In practice, the metadata adapter can be one of the following: a YAML / JSON adapter, a database adapter, or an AST parsing adapter. The YAML / JSON adapter directly parses the user-provided configuration file (i.e., the corresponding entity metadata) and maps it to a standard data model. The database adapter can connect to the database via JDBC, query the database's metadata table (INFORMATION_SCHEMA.COLUMNS), and convert the table structure (table name, column name, data type, constraints) into a standard data model. The AST parsing adapter can use an open-source library (JavaParser for Java) to parse existing source code into an abstract syntax tree, traverse the AST, identify class definitions, field definitions, method definitions, etc., extract information such as names, types, and comments from the AST nodes, and construct a standard data model without modifying the original code.
[0046] The second step is to use the metadata adapter described above to convert the entity metadata into a data model in the target format. This target format data model can be a standard data model.
[0047] In some optional implementations of certain embodiments, the aforementioned entity metadata includes at least one metadata source. Each metadata source has corresponding metadata. The metadata source can be a source channel for the metadata. In practice, the various metadata sources within the at least one metadata source are different. The metadata source can be, but is not limited to, one of the following: external configuration files (such as YAML, JSON), database schema (e.g., reading table structures via JDBC). The metadata is also entity information describing the target business entity.
[0048] Optionally, the aforementioned executing entity may utilize the aforementioned metadata adapter to convert the aforementioned entity metadata into a data model in the target format, including the following steps: The first step is to transform the metadata from at least one of the aforementioned metadata sources into a corresponding data sub-model using the metadata adapter corresponding to that source. In practice, depending on the metadata source, different metadata adapters can be sampled for metadata transformation. The data sub-model here is also the standard data model after metadata transformation.
[0049] It should be noted that, regarding the metadata source, if a corresponding metadata adapter does not exist, you can set up and develop your own metadata adapter. The metadata adapter can then be stored for future use.
[0050] The second step is to fuse at least one of the obtained data sub-models to obtain the data model.
[0051] Step 203: Load the above data model into the template text corresponding to the above template selection information to obtain the loaded template text.
[0052] In some embodiments, the execution entity can load the data model into the template text corresponding to the template selection information to obtain the loaded template text. The loaded template text can be text with the model content corresponding to the data model added to the corresponding text position in the template text.
[0053] In practice, the above data model can be loaded into the template text corresponding to the template selection information by the template library and management unit (a module for storing and managing templates for different output file types) included in the execution entity, so as to obtain the loaded template text.
[0054] Step 204: Use the template engine to generate the code content corresponding to the loaded template text.
[0055] In some embodiments, the aforementioned execution entity can utilize a template engine to generate the code content corresponding to the loaded template text. The template engine can be Velocity. Apache Velocity is an open-source Java template engine used to automatically generate corresponding text content (i.e., the code content here) based on the template text. The code file type corresponding to the template selection information is the same as the code file type corresponding to the code content (i.e., both are target code file types). The code content can be in the form of a code string.
[0056] In practice, the code generation engine unit corresponding to the execution subject can be used to call the template engine to output the code content.
[0057] In some optional implementations of certain embodiments, the parsed information may further include: a code output path. The code output path can be a path where the code content is output. In practice, the code output path may include: directory structure, naming conventions, and project path.
[0058] Optionally, after step 204, the steps further include: The aforementioned execution entity can generate code files of the corresponding code file type for the aforementioned target business entity based on the aforementioned code content and the aforementioned code output path.
[0059] As an example, the aforementioned execution entity can write the generated code content into the specified project path according to the preset directory structure and naming rules, forming a code file.
[0060] In some optional implementations of certain embodiments, the aforementioned execution entity may utilize a template engine to generate the code content corresponding to the loaded template text, including the following steps: The aforementioned execution entity can utilize the template engine to generate code sub-content corresponding to each of the at least one loaded template sub-text, obtaining at least one code sub-content as the code content. In practice, the template engine can be used to render each loaded template sub-text to obtain the final code string, which serves as the code sub-content.
[0061] The above embodiments of this disclosure have the following beneficial effects: The code content generation method of some embodiments of this disclosure can automatically generate code content of the corresponding type in a non-intrusive, flexible, and accurate manner. Specifically, the significant limitations of the code content generation process of the corresponding type are: strong intrusiveness, usually requiring the insertion of specific annotations, comments, or inheritance of specific base classes into the project code, polluting the business code; strong binding to specific technical frameworks, poor flexibility, fixed generated code structure, and difficulty in customization. Based on this, the code content generation method of some embodiments of this disclosure firstly parses the target code generation request to obtain parsing information for the target business entity, wherein the parsing information includes entity metadata and template selection information. Here, by obtaining entity metadata, the separation of metadata (i.e., business description) and code can be achieved, so as to obtain the business description content for the target business entity based on the entity metadata. Using the corresponding developed and maintained template text, the corresponding code content can be generated efficiently and non-intrusively. Here, by setting different template texts, flexible generation of code content under the corresponding file type can be achieved. Then, the above entity metadata is converted into a data model under the target format to generate a standardized business entity data model. Here, by generating standardized business entity data models, it is ensured that all files originate from the same metadata, guaranteeing consistency between APIs (Application Programming Interfaces), data models, and database schemas. This significantly reduces vulnerabilities caused by manual, out-of-sync modifications, improving system performance and user experience. Finally, using a template engine, the code content corresponding to the loaded template text is generated. The code file type corresponding to the template selection information is the same as the code file type corresponding to the code content. In summary, by generating standardized data models based on entity metadata and flexibly calling template texts of corresponding code file types, the corresponding type of code content can be automatically generated non-intrusively, flexibly, and accurately.
[0062] Further reference Figure 3 The diagram illustrates flow 300 of another embodiment of the code content generation method according to this disclosure. This code content generation method includes the following steps: Step 301: Parse the target code generation request to obtain parsing information for the target business entity.
[0063] Step 302: Convert the above entity metadata into a data model in the target format.
[0064] Step 303: Obtain the template text corresponding to the above template selection information from the template text repository, and use it as the target template text.
[0065] In some embodiments, the executing entity (e.g. Figure 1 The electronic device 101 shown can retrieve the template text corresponding to the template selection information from the template text repository as the target template text. The template text repository stores template texts corresponding to various code file types. In practice, these various code file types may include, but are not limited to, at least one of the following: Entity type, Interface type, and Mapper type. In practice, the template text repository may be a database storing template texts of various types.
[0066] In some optional implementations of certain embodiments, the template selection information includes at least one selection information for at least one code file type. There is a one-to-one correspondence between the code file type and the selection information, where the selection information may be the selection content of the template text corresponding to the selected code file type.
[0067] Optionally, the aforementioned execution entity may obtain the template text corresponding to the template selection information from the template text repository as the target template text, including the following steps: The first step is to retrieve the template text corresponding to each selection from the template text repository, and use it as a template sub-file. The code file type corresponding to the template sub-file is the same as the code file type corresponding to the selection information.
[0068] The second step is to identify at least one template sub-file as the target template text.
[0069] In some optional implementations of certain embodiments, after obtaining the template text corresponding to the template selection information from the template text repository as the target template text, the method further includes: The first step, in response to the determination that the template text repository does not contain the template text corresponding to the template selection information, is to generate the first initial template text using a pre-trained large language model that supports custom template generation, based on the template selection information and the code file type. The large language model can be a large language model trained based on template knowledge and code text type correspondence knowledge. In practice, the large language model can be a large language model based on the Transformer architecture. The large language model can also be a large language model trained on a template text training dataset, which may include: code file type and corresponding matching template text. In practice, the large language model can be trained using conventional model training methods. The first initial template text can be a pre-generated template text that requires further confirmation.
[0070] As an example, firstly, text generation prompts are generated to produce template text corresponding to the code file type based on the template selection information. Then, the text generation prompts are input into the large language model to obtain the first initial template text.
[0071] The second step involves displaying the initial template text on the template text display page. This page can be a page showing the text content corresponding to the template text. In practice, the template text display page includes a confirmation control and a question input control for the candidate initial template text. Clicking the confirmation control converts the candidate initial template text into a usable template text. Clicking the question input control allows users to input any issues with the initial template text, enabling subsequent corrections using a large language model to generate a more accurate second initial template text.
[0072] The third step involves responding to the confirmation message selected on the template text display page regarding the first initial template text, thus identifying the first initial template text as the target template text, and storing the target template text in the template text repository. In practice, the target template text and its corresponding code file type can be synchronously stored in the template text repository for later retrieval and use.
[0073] Step 304: Load the above data model into the above target template text to obtain the loaded template text.
[0074] In some embodiments, the execution entity may load the data model into the target template text to obtain the loaded template text.
[0075] In some optional implementations of certain embodiments, the execution entity may load the data model into at least one model sub-file to obtain at least one loaded template sub-text, which serves as the loaded template text. There is a one-to-one correspondence between the template sub-text in the at least one model sub-file and the loaded template sub-text in the at least one loaded template sub-text.
[0076] Step 305: Use the template engine to generate the code content corresponding to the loaded template text.
[0077] In some embodiments, the specific implementation of steps 301-302 and 305 and their resulting technical effects can be found in [reference needed]. Figure 2 Steps 201-202 and 204 in the corresponding embodiments will not be repeated here.
[0078] from Figure 3 It can be seen from this that, with Figure 2Compared to the description of some corresponding embodiments, Figure 3 In some corresponding embodiments, the code content generation method process 300 obtains the corresponding flexible template text from the template text repository, and then accurately generates the code content of the corresponding type based on the template text.
[0079] Further reference Figure 4 As an implementation of the methods shown in the above figures, this disclosure provides some embodiments of a code content generation apparatus, which are similar to... Figure 2 Corresponding to the method embodiments shown, this code content generation apparatus can be specifically applied to various electronic devices.
[0080] like Figure 4 As shown, a code content generation device 400 includes: a parsing unit 401, a conversion unit 402, a loading unit 403, and a generation unit 404. The parsing unit 401 is configured to parse a target code generation request to obtain parsing information for the target business entity, wherein the parsing information includes entity metadata and template selection information. The conversion unit 402 is configured to convert the entity metadata into a data model in the target format. The loading unit 403 is configured to load the data model into the template text corresponding to the template selection information to obtain the loaded template text. The generation unit 404 is configured to use a template engine to generate code content corresponding to the loaded template text, wherein the code file type corresponding to the template selection information is the same as the code file type corresponding to the code content.
[0081] In some optional implementations of certain embodiments, the conversion unit 402 may be further configured to: determine the metadata adapter corresponding to the entity metadata; and use the metadata adapter to convert the entity metadata into a data model in the target format.
[0082] In some optional implementations of some embodiments, the entity metadata includes at least one metadata corresponding to at least one metadata source; and the conversion unit 402 can be further configured to: for each of the at least one metadata source, convert the metadata corresponding to the metadata source into a corresponding data sub-model according to the metadata adapter corresponding to the metadata source; and fuse the obtained at least one data sub-model to obtain a data model.
[0083] In some optional implementations of some embodiments, the loading unit 403 may be further configured to: obtain the template text corresponding to the template selection information from the template text repository as the target template text, wherein the template text repository stores template texts corresponding to various code file types; load the data model into the target template text to obtain the loaded template text.
[0084] In some optional implementations of some embodiments, the template selection information includes at least one selection information for at least one code file type. The loading unit 403 can be further configured to: for each selection information, obtain the template text corresponding to the selection information from the template text repository as a template sub-file, wherein the code file type corresponding to the template sub-file is the code file type corresponding to the selection information; and determine the obtained at least one template sub-file as the target template text. The loading unit 403 can be further configured to: load the data model into the at least one model sub-file to obtain at least one loaded template sub-text as the loaded template text. The generation unit can be further configured to: utilize the template engine to generate code sub-content corresponding to each loaded template sub-text in the at least one loaded template sub-text, obtaining at least one code sub-content as code content.
[0085] In some optional implementations of certain embodiments, the apparatus 400 further includes a file generation unit (not shown in the figure). The parsed information further includes a code output path; and the file generation unit can be configured to generate a code file of the corresponding code file type for the target business entity based on the code content and the code output path.
[0086] In some optional implementations of certain embodiments, the loading unit 403 may be further configured to: in response to determining that the template text repository does not contain template text corresponding to the template selection information, generate a first initial template text using a pre-trained large language model that supports template customization based on the template selection information and the code file type; display the first initial template text on the template text display page; in response to selecting confirmation information for the first initial template text on the template text display page, determine the first initial template text as the target template text, and store the target template text in the template text repository.
[0087] It is understandable that the units described in the code content generation device 400 and the reference Figure 2The steps in the described method correspond to each other. Therefore, the operations, features, and beneficial effects described above for the method also apply to the code content generation device 400 and the units contained therein, and will not be repeated here.
[0088] The following is for reference. Figure 5 It illustrates electronic devices suitable for implementing some embodiments of this disclosure (e.g., Figure 1 A schematic diagram of the structure of electronic device 101)500. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of this disclosure.
[0089] like Figure 5 As shown, the electronic device 500 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory 502 or a program loaded from a storage device 508 into a random access memory 503. The random access memory 503 also stores various programs and data required for the operation of the electronic device 500. The processing unit 501, the read-only memory 502, and the random access memory 503 are interconnected via a bus 504. An input / output interface 505 is also connected to the bus 504.
[0090] Typically, the following devices can be connected to the input / output interface 505: input devices 506 including, for example, a touchscreen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 507 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 508 including, for example, magnetic tape, hard disk, etc.; and communication devices 509. Communication device 509 allows electronic device 500 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 An electronic device 500 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively. Figure 5 Each box shown can represent a device or multiple devices as needed.
[0091] In particular, according to some embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, some embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a storage device 508, or installed from a read-only memory 502. When the computer program is executed by the processing device 501, it performs the functions defined above in the methods of some embodiments of this disclosure.
[0092] It should be noted that, in some embodiments of this disclosure, the computer-readable medium described above may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In some embodiments of this disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In some embodiments of this disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0093] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.
[0094] The aforementioned computer-readable medium may be included within the aforementioned electronic device; or it may exist independently without being assembled into the electronic device. The aforementioned computer-readable medium carries one or more programs that, when executed by the electronic device, cause the electronic device to: parse a target code generation request to obtain parsing information for the target business entity, wherein the parsing information includes: entity metadata and template selection information; convert the entity metadata into a data model in the target format; load the data model into the template text corresponding to the template selection information to obtain the loaded template text; and use a template engine to generate code content corresponding to the loaded template text, wherein the code file type corresponding to the template selection information is the same as the code file type corresponding to the code content.
[0095] Computer program code for performing operations of some embodiments of this disclosure can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0096] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0097] The units described in some embodiments of this disclosure can be implemented in software or hardware. The described units can also be housed in a processor; for example, a processor may be described as including a parsing unit, a conversion unit, a loading unit, and a generation unit. The names of these units do not necessarily limit the specific unit; for example, a parsing unit may also be described as "a unit that parses a target code generation request to obtain parsed information for the target business entity."
[0098] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), and so on.
[0099] Some embodiments of this disclosure also provide a computer program product, including a computer program that, when executed by a processor, implements any of the code content generation methods described above.
[0100] The above description is merely a selection of preferred embodiments of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in the embodiments of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in the embodiments of this disclosure.
Claims
1. A method for generating code content, comprising: The target code generation request is parsed to obtain parsing information for the target business entity, wherein the parsing information includes: entity metadata and template selection information; Convert the entity metadata into a data model in the target format; The data model is loaded into the template text corresponding to the template selection information to obtain the loaded template text. Using a template engine, code content corresponding to the loaded template text is generated, wherein the code file type corresponding to the template selection information is the same as the code file type corresponding to the code content.
2. The method according to claim 1, wherein, The step of converting the entity metadata into a data model in the target format includes: Determine the metadata adapter corresponding to the entity metadata; The metadata adapter is used to convert the entity metadata into a data model in the target format.
3. The method according to claim 2, wherein, The entity metadata includes: at least one metadata source corresponding to at least one metadata source; and The step of using the metadata adapter to convert the entity metadata into a data model in the target format includes: For each of the at least one metadata source, the metadata corresponding to the metadata source is converted into a corresponding data sub-model according to the metadata adapter corresponding to the metadata source; The obtained data sub-models are fused together to obtain the data model.
4. The method according to claim 1, wherein, The step of loading the data model into the template text corresponding to the template selection information to obtain the loaded template text includes: The template text corresponding to the template selection information is obtained from the template text repository and used as the target template text. The template text repository stores template texts corresponding to various code file types. The data model is loaded into the target template text to obtain the loaded template text.
5. The method according to claim 4, wherein, The template selection information includes: at least one selection information for at least one code file type; and The step of retrieving the template text corresponding to the template selection information from the template text repository as the target template text includes: For each selection information, the template text corresponding to the selection information is obtained from the template text repository as a template sub-file, wherein the code file type corresponding to the template sub-file is the code file type corresponding to the selection information; Identify at least one obtained template sub-file as the target template text; and The step of loading the data model into the target template text to obtain the loaded template text includes: Load the data model into the at least one model sub-file to obtain at least one loaded template sub-text, which serves as the loaded template text; and The process of generating the code content corresponding to the loaded template text using a template engine includes: Using the template engine, generate code sub-content corresponding to each loaded template sub-text in the at least one loaded template sub-text, and obtain at least one code sub-content as code content.
6. The method according to claim 1, wherein, The parsed information also includes: the code output path; and The method further includes: Based on the code content and the code output path, generate a code file of the corresponding code file type for the target business entity.
7. The method according to claim 4, wherein, After obtaining the template text corresponding to the template selection information from the template text repository as the target template text, the method further includes: In response to determining that the template text repository does not contain template text corresponding to the template selection information, a first initial template text is generated based on the template selection information and the code file type using a pre-trained large language model that supports template customization. The first initial template text is displayed on the template text display page; In response to the confirmation information selected for the first initial template text on the template text display page, the first initial template text is identified as the target template text, and the target template text is stored in the template text repository.
8. A code content generation apparatus, comprising: The parsing unit is configured to parse the target code generation request to obtain parsing information for the target business entity, wherein the parsing information includes: entity metadata and template selection information; The conversion unit is configured to convert the entity metadata into a data model in a target format; The loading unit is configured to load the data model into the template text corresponding to the template selection information, thereby obtaining the loaded template text. The generation unit is configured to use a template engine to generate the code content corresponding to the loaded template text, wherein the code file type corresponding to the template selection information is the same as the code file type corresponding to the code content.
9. An electronic device, comprising: One or more processors; Storage device, on which one or more programs are stored, When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-7.
10. A computer-readable medium having a computer program stored thereon, wherein, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-7.
11. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-7.