Code generation method, electronic equipment and storage medium
By constructing code modeling graphs and generating target code templates, the problem of general-purpose large language models being difficult to adapt to enterprise coding standards is solved, improving the quality and efficiency of code generation and reducing the review costs for enterprises.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANJING GLORY SOFTWARE TECH CO LTD
- Filing Date
- 2025-12-18
- Publication Date
- 2026-05-12
AI Technical Summary
The code generated by general-purpose large language models is difficult to adapt to the internal coding standards of enterprises, resulting in low code generation efficiency and difficulty in guaranteeing quality. Existing technologies such as retrieval augmentation generation and model fine-tuning have problems with poor accuracy and high cost.
By constructing a code modeling graph, the target code template is generated using preset code specifications and placeholder replacements. Based on the request information, the matching target code template is determined and prompt text is generated, ensuring that the language model understands the preset code specifications.
It improves the quality and efficiency of code generation, reduces reliance on developer experience, avoids redundant calculations and template omissions, and reduces the time and cost for enterprises in code review and correction.
Smart Images

Figure CN122018911A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a code generation method, electronic device, and storage medium. Background Technology
[0002] With the development of artificial intelligence, large language models can be used to assist developers in writing code to improve development efficiency. However, in practical applications, the code generated by general-purpose large language models is difficult to adapt to the internal coding standards of enterprises, requiring them to invest a significant amount of time and manpower in reviewing and correcting the generated code. This approach not only reduces the overall efficiency of code generation but is also susceptible to the influence of developers' experience, leading to a failure to guarantee the quality of the generated code. Summary of the Invention
[0003] This application discloses a code generation method, an electronic device, and a storage medium, which can solve the technical problems of low code generation efficiency and inability to guarantee the quality of generated code.
[0004] The first aspect of this application discloses a code generation method, the method comprising: responding to a code generation request; determining a matching target code template based on request information in the code generation request, the target code template being created based on a preset code specification; generating a prompt text based on the target code template; and generating target code corresponding to the code generation request based on the prompt text.
[0005] Through the above technical solution, based on the request information in the code generation request, a target code template that follows the preset code specifications can be adapted, and then the target code template can be used to generate prompt text, so that the language model can accurately understand the preset code specifications, thereby improving the generation quality and efficiency of the target code.
[0006] In one possible implementation, the method further includes: obtaining code examples corresponding to the preset code specification; extracting multiple entities in the code examples and the entity relationships between the multiple entities; and constructing a code modeling graph based on the multiple entities and the entity relationships.
[0007] By using the above technical solution and code examples corresponding to the preset code specifications, a code modeling graph can be constructed, which can ensure that multiple preset code templates corresponding to the code modeling graph follow the preset code specifications.
[0008] In one possible implementation, constructing a code modeling graph based on the plurality of entities and the entity relationships includes: constructing the code modeling graph using the plurality of entities as graph nodes and the entity relationships as graph edges, wherein the nodes in the code modeling graph correspond to a plurality of preset code templates.
[0009] By using the above technical solution, the entity relationships can be displayed as graph nodes and the entity relationships as graph edges, thus visually representing the entity relationships in the code example.
[0010] In one possible implementation, the step of constructing a code modeling graph based on the plurality of entities and the entity relationships further includes: mapping each entity to a Unified Modeling Language (UML) class, and mapping the entity attributes of each entity to the object attributes of the corresponding UML class; mapping the entity relationships to the relationships between the plurality of UML classes; and constructing the code modeling graph based on the plurality of UML classes, the object attributes, and the relationships between the plurality of UML classes, wherein the UML classes in the code modeling graph correspond to a plurality of preset code templates.
[0011] Through the above technical solutions, based on multiple UML classes obtained by mapping multiple entities, object attributes of UML classes obtained by mapping the entity attributes of each entity, and relationships between multiple UML classes obtained by mapping entity relationships, abstract code examples can be transformed into structured and standardized code modeling graphs.
[0012] In one possible implementation, the method further includes: replacing the dynamic code in multiple code examples with preset placeholders to obtain multiple preset code templates; and establishing a mapping relationship between the template identifiers in the multiple code examples and the corresponding preset code templates.
[0013] By using the above technical solution, multiple preset code templates can be obtained by replacing the dynamic code in multiple code examples with preset placeholders. By establishing a mapping relationship between template identifiers and corresponding preset code templates, the target code template can be determined.
[0014] In one possible implementation, determining the matching target code template based on the request information in the code generation request includes: generating a file identifier corresponding to the code generation request based on the request information; and selecting the target code template from the plurality of preset code templates based on the matching degree between the file identifier and the template identifiers of the plurality of preset code templates.
[0015] Using the above technical solution, a file identifier corresponding to the code generation request can be generated based on the request information. Then, by comparing the file identifier with the template identifiers of multiple preset code templates, the target code template that matches the request information can be selected.
[0016] In one possible implementation, the file identifier includes at least one of the following: framework name, architecture name, module name, element name, and programming language name.
[0017] In one possible implementation, the matching degree is determined by a combination of one or more of the following methods: determining the matching degree based on the similarity between the first vector corresponding to the file identifier and the second vector corresponding to the template identifier; counting the first number of target characters in the file identifier, where the target characters represent the same characters in the file identifier and the template identifier at corresponding positions; determining the larger value of the number of characters in the file identifier and the number of characters in the template identifier as the second number; and determining the matching degree based on the first number and the second number.
[0018] Through the above technical solution, the similarity between the first vector corresponding to the file identifier and the second vector corresponding to the template identifier can be used to quantify the matching degree between the file identifier and the template identifier. The matching degree between the file identifier and the template identifier can be reasonably quantified by the larger of the first number of target characters in the file identifier and the number of characters in the file identifier and the number of characters in the template identifier.
[0019] In one possible implementation, selecting the target code template from the plurality of preset code templates based on the matching degree between the file identifier and the template identifiers of the plurality of preset code templates includes: if the highest matching degree is greater than or equal to a first preset threshold, determining the preset code template corresponding to the highest matching degree as the target code template; if the highest matching degree is less than the first preset threshold, determining the preset code template corresponding to the matching degree greater than a second preset threshold as the target code template, wherein the first preset threshold is greater than the second preset threshold.
[0020] Through the above technical solution, when the highest matching degree is greater than or equal to the first preset threshold, the preset code template corresponding to the highest matching degree can be used as the target code template to quickly determine the preset code template that best matches the request information, avoiding redundant calculations caused by multiple template filtering. When the highest matching degree is less than the first preset threshold, it indicates that the multiple preset code templates do not include a single optimal template. Therefore, using the preset code template corresponding to a matching degree greater than the second preset threshold as the target code template can prevent valid templates that match the request information from being missed.
[0021] In one possible implementation, generating the prompt text based on the target code template includes: obtaining a prompt word template; and filling the prompt word template with the target code template to obtain the prompt text.
[0022] By using the above technical solution to fill the target code template into the prompt word template, it can be ensured that the prompt text includes the target code template, so that the language model can understand the preset code specification.
[0023] In one possible implementation, determining the matching target code template based on the request information in the code generation request further includes: selecting a target code specification from multiple preset code specifications based on the request information; and determining the target code template based on the code example corresponding to the target code specification.
[0024] Using the above technical solution, the target code specification corresponding to the code generation request can be filtered out based on the request information, and then the target code template can be quickly determined by the code example corresponding to the target code specification.
[0025] The second aspect of this application discloses an electronic device including a processor and a memory, the memory being used to store instructions, and the processor being used to invoke the instructions in the memory to cause the electronic device to execute the code generation method as described in the first aspect.
[0026] A third aspect of this application discloses a computer-readable storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform the code generation method as described in the first aspect.
[0027] The fourth aspect of this application discloses a computer program product comprising a computer program that, when executed by a processor, implements the code generation method as described in the first aspect.
[0028] It should be understood that the electronic device described in the second aspect, the computer-readable storage medium described in the third aspect, and the computer program product described in the fourth aspect all correspond to the method described in the first aspect. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here. Attached Figure Description
[0029] Figure 1 This is a schematic diagram of a code generation method.
[0030] Figure 2 This is a schematic diagram illustrating the degree of compliance of different language models provided in an embodiment of this application.
[0031] Figure 3 This is a schematic diagram illustrating an application scenario of the code generation method provided in an embodiment of this application.
[0032] Figure 4 This is a software architecture diagram of an electronic device provided in an embodiment of this application.
[0033] Figure 5 This is a flowchart of the code generation method provided in one embodiment of this application.
[0034] Figure 6 This is a schematic diagram illustrating the code generation requirements displayed in a dialog interface, as provided in one embodiment of this application.
[0035] Figure 7 This is a schematic diagram of the framework of a code generation method provided in an embodiment of this application.
[0036] Figure 8 This is a flowchart illustrating the steps of a code modeling graph construction method provided in one embodiment of this application.
[0037] Figure 9 This is a schematic diagram of a UML class diagram provided in an embodiment of this application.
[0038] Figure 10 This is a schematic diagram of the framework of a code modeling graph construction method provided in an embodiment of this application.
[0039] Figure 11 This application provides a hardware architecture diagram of an electronic device according to an embodiment. Detailed Implementation
[0040] In the following description, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of the embodiments of this application, words such as "exemplary," "or," and "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of words such as "exemplary," "or," and "for example" is intended to present the relevant concepts in a concrete manner.
[0041] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. The terminology used in this application's specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. It should be understood that, unless otherwise stated, " / " in this application means "or". For example, A / B can mean A or B. "And / or" in this application is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. "At least one" means one or more. "More than one" means two or more. For example, at least one of a, b, or c can represent: a, b, c, a and b, a and c, b and c, and a, b, and c. It should be understood that the order of steps shown in the flowcharts herein can be changed, and some can be omitted.
[0042] With the development of artificial intelligence, large language models can be used to assist developers in writing code to improve development efficiency. The code generated by these large language models needs to strictly adhere to the company's internal coding standards, not just ensure the correct implementation of output functions.
[0043] Enterprise coding standards can be broken down into several core dimensions, including but not limited to: coding standards based on syntax structure, coding standards based on semantic meaning, and coding standards based on usage scenarios. Each dimension of standards constrains code writing logic and standards from different levels.
[0044] For specific examples of coding standards across multiple dimensions, please refer to Table 1 below. Table 1 shows the coding standards within an enterprise under different dimensions, but practical applications are not limited to this.
[0045] The following shows a portion of the code that follows the coding standards in Table 1 above, for example: / ** * [Semantic-Conceptual] Bank Account Class * [Semantic-Property] It has the property that the balance cannot be negative. * [Semantic Pattern Application] Using Encapsulation Patterns to Protect Data Integrity * [Structured File - Package] Class Definition Begins / package com.example.banking; / / [Structured File - Package] Declares the package it belongs to. / / [Structured File - Comments and Explanations] Import Dependencies import java.time.LocalDateTime; / / [Semantic-Time] Used to record operation time / ** * [Semantic-Conceptual] An entity representing a bank account * [Semantic-Relationship] Associated with the Transaction class (not shown) * [Structured File - Class] Class Body / public class BankAccount { / / [Semantic-attribute] Unique Account Identifier / / [Semantic-variable / constant] Instance variable / / [symbol-character] underscore named constant private final String ACCOUNT_NUMBER; / / [Semantic-State] Current account balance / / [Pragmatic Error Prevention] Private encapsulation prevents unauthorized modification private double balance; / / [Semantic-Location] Branch where the account was opened private String branchLocation; / ** * [Semantic-Behavioral] Constructor * [Pragmatic-Maintenance Optimization] Parameter validation ensures object validity * [Structured File - Functions] Constructor Block / public BankAccount(String accountNumber, double initialBalance,String branch) { / / Syntax-branch parameter validation if (accountNumber == null || accountNumber.isEmpty()) { throw new IllegalArgumentException("Account cannot be empty"); } if (initialBalance<0) { / / [Semantic-property] The balance cannot be negative throw new IllegalArgumentException("Initial balance cannot be negative"); } this.ACCOUNT_NUMBER = accountNumber; / / [Syntax - Assignment / Operation] Final variable assignment this.balance = initialBalance; this.creationDate = LocalDateTime.now(); / / [Semantic-Time] Records the creation time this.branchLocation = branch; / / [Semantic-Location] Sets the account opening location. } / ** * [Semantic-Behavioral] Deposit Operations * [Semantic Error Prevention] Validate the validity of deposit amounts * [Structured File - Functions] Method Block / public void deposit(double amount) { / / [Syntax-Branch] Business Rule Check if (amount <= 0) { / / [Semantic-property] The deposit amount must be positive throw new IllegalArgumentException("The deposit amount must be greater than zero"); } this.balance += amount; / / [Syntax - Assignment / Operation] Arithmetic operation } / / [Semantic-Behavior] Get Current Balance public double getBalance() { Return balance; } }
[0046] However, in practical applications, whether through the dialog window of the general language model or by using the auxiliary plugin of the embedded coding tool, the general language model can generate general code that is adapted to public domain scenarios (such as general algorithms and general frameworks), but the code generated by the general language model is difficult to adapt to the coding standards of the enterprise.
[0047] Specifically, the code generated by the general-purpose large language model cannot strictly follow the technical specifications and conventions of the enterprise's private domain (such as API technical specifications, database technical specifications, etc.), nor can it be effectively integrated with the local existing base class code or framework (also known as "cannot be inherited"); at the same time, due to the randomness of generation, there are also conflict issues between the code generated multiple times.
[0048] Please refer to Table 2 below. Table 2 shows the coding conventions that are difficult to adapt to in code generated by the general large language model: Therefore, companies need to invest a lot of time and manpower in reviewing and correcting the generated code. This approach not only reduces the overall efficiency of code generation but is also easily affected by the experience level of developers, making it difficult to guarantee the quality of generated code.
[0049] In related technologies, to ensure that the code generated by the large language model conforms to the enterprise's private domain specifications, it is usually optimized by combining techniques such as Retrieval-Augmented Generation (RAG) or model fine-tuning.
[0050] like Figure 1 As shown, Figure 1 This is a diagram illustrating a code generation method. Figure 1 In the illustrated scheme, enterprise private domain specifications can be pre-vectorized, and the corresponding vectors can be stored in a vector library. In response to a user's code completion task, intent recognition can be performed on the code completion task, and based on the recognized intent, matching enterprise private domain specifications can be retrieved from the vector library. Based on the matching degree between the retrieved enterprise private domain specifications and the intent, the retrieved enterprise private domain specifications are rearranged, and the k enterprise private domain specifications with the highest matching degree are selected from the retrieved specifications. Then, prompt words can be assembled based on the k enterprise private domain specifications. Finally, the prompt words are input into a Large Language Model (LLM) to obtain the generated code output by the Large Language Model.
[0051] However, the above methods face two major challenges in application. First, it is difficult to accurately identify the intent of code completion tasks and recall all relevant enterprise private domain specifications. For example, all code completion content must adhere to comment writing and code formatting specifications; however, the above methods cannot guarantee that every code completion task can reliably recall these basic specifications. Secondly, when generating data entities, concurrency control specifications and database version field selection specifications need to be referenced, but in practice, issues such as missing or inaccurate specification recall often occur. Thirdly, when generating interface code, the specific implementation mechanism specifications of the current development framework need to be considered; however, the above methods cannot dynamically recall the corresponding specifications based on the framework type, resulting in generated interface code that does not meet enterprise specification requirements.
[0052] Secondly, enterprise private domain guidelines are usually described in natural language. If the enterprise private domain guidelines are simply broken down into independent text fragments as prompt words, the large language model does not have enough depth of understanding of the enterprise private domain guidelines, resulting in poor compliance.
[0053] like Figure 2 As shown, Figure 2 This is a schematic diagram illustrating the compliance of different language models provided in one embodiment of this application. In some embodiments, the IFEval evaluation set and the IFBench evaluation set can be used to evaluate multiple large language models (e.g., Qwen3-8B). TM Qwen3-32B TM Gemini 2.5 Pro TM The system assesses compliance with various constraints, including those related to the IFEval test set (which includes 25 verifiable instructions and can generate approximately 500 prompts) and the IFBench test set (which includes 58 different verifiable constraints).
[0054] The evaluation revealed that most models could not achieve 100% compliance on the IFEval evaluation set, while models that performed well on the IFEval evaluation set showed a significant decrease in compliance on the IFBench evaluation set, sometimes even falling below 50%.
[0055] Therefore, the relevant technologies cannot translate enterprise private domain specifications into prompt word instructions that can be effectively followed by large language models. In addition, the method of model fine-tuning is not only costly, but also causes problems such as poor compatibility and repeated optimization results due to the iterative updates of large language models.
[0056] To address the aforementioned issues, this application provides a code generation method. Based on the request information in the code generation request, a target code template that conforms to a preset code specification can be adapted. Then, prompt text is generated using the target code template, enabling the language model to accurately understand the preset code specification. Furthermore, code is generated based on the prompt text. This method can improve the quality and efficiency of code generation without adjusting model parameters.
[0057] Please see Figure 3 , Figure 3 This is a schematic diagram illustrating an application scenario of the code generation method provided in an embodiment of this application. This scenario may include various terminal devices 100 and servers 200.
[0058] Terminal device 100 may be a mobile phone, tablet computer, desktop computer, laptop computer, handheld computer, notebook computer, ultra-mobile personal computer (UMPC), netbook, as well as cellular phone, personal digital assistant (PDA), augmented reality (AR) device, virtual reality (VR) device, artificial intelligence (AI) device, wearable device, in-vehicle device, smart home device and / or smart city device. This application embodiment does not impose any special restrictions on the specific type of terminal device 100.
[0059] Server 200 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms, but it is not limited to these. Server 200 can deploy a database that stores code modeling graphs. Nodes or UML classes in the code modeling graphs can correspond to preset code templates, which can be created based on preset code specifications.
[0060] In some embodiments of this application, the code generation method can be executed by either the terminal device 100 or the server 200 alone, or by both the server 200 and the terminal device 100. When executed by either the terminal device 100 or the server 200 alone, the code generation process can be implemented by either the terminal device 100 or the server 200 alone. For example, on the terminal device 100, a locally deployed language model can be used to generate the target code corresponding to the code generation request based on the constructed prompt text. This process can also be executed by the server 200 alone. When executed by both the server 200 and the terminal device 100, the server 200 can train the language model and then deploy the trained language model to the terminal device 100, allowing the terminal device 100 to implement the code generation process. If the trained language model is not deployed to the terminal device 100, the server 200 can send the target code corresponding to the code generation request back to the terminal device 100 based on the code generation request sent by the terminal device 100. Alternatively, some steps in the code generation process can be implemented by the terminal device 100, while others can be implemented by the server 200, with both working together to achieve the code generation process. In practical applications, specific configurations can be made according to the circumstances, and no specific limitations are made here.
[0061] In some embodiments of this application, when the code generation method provided in the embodiments of this application is executed by either server 200 or terminal device 100 alone, the above application scenario may also include only a single device, either server 200 or terminal device 100. Alternatively, server 200 and terminal device 100 may be considered as the same device. In practical applications, when the code generation method provided in the embodiments of this application is executed jointly by server 200 and terminal device 100, server 200 and terminal device 100 may also be the same device. That is, server 200 and terminal device 100 may be different functional modules of the same device, or virtual devices virtualized from the same physical device.
[0062] In one possible implementation, a user can provide a code generation request through a terminal device 100, and the server 200 can use the code generation method of this application embodiment to determine the target code corresponding to the code generation request and return it to the terminal device 100 for output, such as presenting the target code through a display interface.
[0063] In this embodiment, the terminal device 100 and the server 200 can communicate directly or indirectly through one or more networks. This network can be a wired network or a wireless network; for example, the wireless network can be a mobile cellular network or a Wireless-Fidelity (Wi-Fi) network, and of course, it can be other possible networks. This embodiment does not limit this. It should be noted that... Figure 3 The examples shown are merely illustrative; in reality, the number of terminal devices and servers is unlimited and is not specifically limited in the embodiments of this application.
[0064] The embodiments of this application will now be described in detail with reference to the accompanying drawings. Please refer to... Figure 4 , Figure 4 This is a software architecture diagram of an electronic device provided in an embodiment of this application. A layered architecture divides the software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. For example, the Android system, from top to bottom, consists of the application layer 401, the framework layer (FWK) 402, native libraries or system libraries 403, the Android runtime 404, the hardware abstraction layer (HAL) 405, and the kernel layer (Linux Kernel) 406.
[0065] Application layer, such as Figure 4 The application layer 401 shown can include multiple applications, such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and SMS. Additionally, application layer 401 can also include core Android applications such as the launcher, system UI, and wallpapers. Application layer 401 can also include applications that support user-generated code.
[0066] Application framework layer, such as Figure 4 The framework layer 402 shown can provide application programming interfaces (APIs) and programming frameworks for applications in the application layer. For example, the framework layer 402 may include an activity manager, a window manager, a view system, an input method manager, and a power manager.
[0067] The Activity Manager provides the Activity Manager Service (AMS), which can be used to start, switch, and schedule system components (such as activities, services, content providers, and broadcast receivers), as well as manage and schedule application processes.
[0068] The window manager provides a window management service (WMS), which can be used for window management, window animation management, surface management, and as an input system intermediary. WMS can create and manage windows. WMS is a service provided by the window manager. The window manager can also obtain the screen size, determine if a status bar is present, lock the screen, and capture the screen.
[0069] View systems can be used to build applications, where the display interface can consist of one or more views. For example, a display interface including a text message notification icon can include views that display text and views that display images. A view system can include a view frame.
[0070] The Input Method Manager provides an Input Method Management Service (IMS), which manages system inputs such as touchscreen input, keypad input, and sensor input. IMS retrieves events from input device nodes and, through interaction with the Power Management System (WMS), distributes these events to appropriate windows. The Power Manager provides a Power Management Service (PMS).
[0071] Optionally, the framework layer may also include a content provider, a phone manager, a resource manager, a notification manager, etc.
[0072] Content providers store and retrieve data, making it accessible to applications. This data can include videos, images, audio, made and received calls, browsing history and bookmarks, phone books, etc. Phone managers provide communication functionality for electronic devices, such as managing call status (connection, termination, etc.). Resource managers provide applications with various resources, such as localized strings, icons, images, layout files, video files, etc. Notification managers allow applications to display notifications in the status bar, conveying informational messages that disappear automatically after a short pause without user interaction. For example, notification managers can be used to notify of download completion or message alerts. Notification managers can also display notifications as icons or scrolling text in the system's top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting alert sounds, vibrating electronic devices, and flashing indicator lights.
[0073] The application layer (401) and framework layer (402) run in a virtual machine. The virtual machine executes the Java files of the application layer and framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0074] System library 403 may include multiple functional modules. For example, a surface manager, media libraries, 3D graphics processing libraries (e.g., Open GLES), 2D graphics engines (e.g., SGL), etc.
[0075] The Surface Manager manages the display subsystem and provides fusion of 2D and 3D layers for multiple applications. The Media Library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG. The 3D Graphics Processing Library implements 3D graphics drawing, image rendering, compositing, and layer processing. The 2D Graphics Engine is the drawing engine for 2D graphics.
[0076] The Android runtime 404 error consists of the core libraries and the virtual machine. The Android runtime is responsible for the scheduling and management of the Android system. The core libraries consist of two parts: one part contains the functionalities that Java needs to call, and the other part contains the core Android libraries.
[0077] Hardware Abstraction Layer 405 runs in user space, encapsulates the kernel layer 406 driver, and provides calling interfaces to the upper layers.
[0078] Kernel layer 406 is the layer between hardware and software. Kernel layer 406 includes at least the display driver, touch driver, audio driver, and sensor driver.
[0079] Kernel layer 406 is the core of the operating system for electronic devices. It is the first layer of software extension based on the hardware, providing the most basic functions of the operating system. It is the foundation for the operation of the operating system, responsible for managing system processes, memory, device drivers, files, and network systems, and determining the system's performance and stability. For example, the kernel layer can determine the timing of an application's operation on a certain part of the hardware.
[0080] Kernel layer 406 includes hardware-dependent programs such as interrupt handlers and device drivers, as well as basic, common, and frequently running modules such as clock management and process scheduling modules, and critical data structures. The kernel layer can be located within the processor or embedded in internal memory.
[0081] To better understand the embodiments of this application, the code generation method provided by the embodiments of this application will be described below with reference to the accompanying drawings. The following embodiments can be implemented independently or in combination with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0082] Please see Figure 5 , Figure 5 This is a flowchart of the code generation method provided in one embodiment of this application. Figure 5 The steps shown are one possible illustration of an embodiment of this application. In other embodiments of this application, they can be changed according to actual needs. Figure 5 The diagram illustrates the sequence of steps. This code generation method can be applied to electronic devices, such as... Figure 3 The code generation method for the terminal device 100 or server 200 shown may include the following steps: S501 responds to the code generation request and determines the matching target code template based on the request information in the code generation request.
[0083] In some embodiments of this application, the electronic device may provide a graphical user interface as a dialog interface, where the user can input a code generation requirement. For ease of understanding, please refer to [link to relevant documentation]. Figure 6 , Figure 6 This is a schematic diagram illustrating the display of code generation requirements in a dialog interface, as provided in one embodiment of this application. For example... Figure 6 As shown, users can enter their code generation request in the dialog interface, such as "Please help me write a piece of code with the file name logic-imexport-ep.truss.cola.adapter.excelcontroller.java.mtl". Figure 6 This is just an example; in actual applications, there are no restrictions on the form and description of the code generation requirements input by the user.
[0084] In some embodiments of this application, a code generation request can be triggered in response to a user's code generation request input in a dialog interface. The electronic device can extract request information from the code generation request, which can be used to indicate the coding standards that the code generated by the language model must follow. The request information may include, but is not limited to: model type, framework name, architecture name, module name, element name, and programming language name. The model type can represent the type of implementation model used by the generated code; for example, the model type can be entity-ep, logic-ep, entity-storage-ep, webui-main, webui-detail, etc. The framework name can be truss, spring boot, dubbo, wp, etc. The architecture name can be ddd, mvc, cola, card, etc. The module name can be adapter, client, component, etc. The element name can be controller, etc. The programming language name can be java, cpp, xml, vue, js, etc.
[0085] In some embodiments of this application, the electronic device determines a matching target code template based on the request information in the code generation request, including: generating a file identifier corresponding to the code generation request based on the request information; and selecting a target code template from multiple preset code templates based on the matching degree between the file identifier and the template identifiers of multiple preset code templates.
[0086] In one embodiment of this application, the electronic device can concatenate request information to obtain a file identifier. For example, by extracting the model type, framework name, architecture name, module name, element name, and programming language name from the request information, the generated file identifier can be represented as: {model type}.{framework name}.{architecture name}.{module name}.{element name}.{programming language name}.mtl. For example, the file identifier could be logic-ep.truss.cola.adapter.controller.java.mtl. Alternatively, the file identifier could be webui.wp.card.component.edit-form.vue.mtl. Different file identifiers can correspond to different code styles.
[0087] In one embodiment of this application, the electronic device can obtain a code example corresponding to a preset code specification. The code example can be code that follows the preset code specification. For example, if the target code specification is: {Operation permission point annotation: TrussResource is an access-controlled resource, the annotation is on the class, and the code attribute value must use all English characters}, then the corresponding code example is as follows, where "xxx" below is used to represent the enterprise identifier, for example, the enterprise identifier of Honor can be "hihonor": import com.xxx.truss.security.service.ISecurityTestService; import org.springframework.stereotype.Service; import com.xxx.truss.core.core.annotation.SecurityPolicy; import com.xxx.truss.core.core.annotation.TrussResource; @Service @TrussResource( code = "testResource", / / Permission resource encoding - please use uppercase underscores in English. desc = "Test Resource" / / Permissioned resource name in Chinese ) public class SecurityTestService implements ISecurityTestService { @Override @TrussOperation( code = "testOperation_read", / / Permission operation encoding - please use uppercase underscores in English. desc = "Test Operation", / / Chinese name of permission operation policy = SecurityPolicy.Required / / Permission policy ) public String test() { return "test"; } }
[0088] Electronic devices can set preset placeholders, which can be used to replace dynamic code in multiple code examples to obtain multiple preset code templates. For example, the preset placeholder can be `package.name`, and the preset code template obtained after replacing the dynamic code with the preset placeholder can be `package [package.name].controller`, where "[package.name]" can represent the project's package name, and ".controller" can represent the package path suffix. These multiple preset code templates correspond to a code modeling graph. The method for constructing the code modeling graph can be found in [reference needed]. Figure 8 The relevant description is as follows. In this application's embodiments, preset placeholders are used to replace dynamic code in multiple code examples to obtain multiple general preset code templates.
[0089] In one embodiment of this application, the electronic device can also generate a corresponding template identifier for each preset code template. The method for generating the template identifier can be found in the detailed description of file identifiers above.
[0090] In one embodiment of this application, an electronic device determines the matching degree between a file identifier and each template identifier based on the similarity between a first vector corresponding to a file identifier and second vectors corresponding to multiple template identifiers. In one example, the similarity between the first vector corresponding to the file identifier and the second vector corresponding to each template identifier can be used as the matching degree between the file identifier and each template identifier. In another example, a preset ratio can be set according to actual needs, and the product of the preset ratio and the similarity can be used as the matching degree between the file identifier and each template identifier. This embodiment of the application quantifies the matching degree between a file identifier and a template identifier through the similarity between the first vector corresponding to the file identifier and the second vector corresponding to the template identifier.
[0091] In another embodiment of this application, the electronic device can identify target characters as identical characters in the file identifier and template identifier at corresponding positions. The electronic device counts a first number of target characters in the file identifier. The electronic device determines a second number as the larger of the number of characters in the file identifier and the number of characters in the template identifier. The electronic device determines a matching degree based on the first and second numbers. For example, the electronic device can use the ratio of the first number to the second number as the matching degree.
[0092] For example, if the file identifier is logic-ep.truss.cola.adapter.controller.java.mtl and the template identifier is logic-imexport-ep.truss.cola.adapter.excelcontroller.java.mtl, comparing the model type "logic-ep" in the file identifier with the model type "logic-imexport-ep" in the template identifier yields the target character "logic-ep" at the model type position in the file identifier. Similarly, comparing the framework name "truss" in the file identifier with the framework name "truss" in the template identifier yields the target character "truss" at the framework name position in the file identifier. Following this method, we can obtain the target character "cola" at the architecture name position, "adapter" at the module name position, "controller" at the element name position, and "java" at the programming language name position in the file identifier. The file identifier also includes the target character "mtl". Statistical analysis revealed the following numbers of target characters at different positions: 8, 5, 4, 7, 10, 4, and 3. Therefore, the first number of target characters is 41. The number of characters in the file identifier is 41, and the number of characters in the template identifier is 55, resulting in a second number of 55. The calculated matching degree is "41 / 55".
[0093] The matching degree between the file identifier and the template identifier can be reasonably quantified by using the larger of the first number of target characters in the file identifier and the number of characters in the file identifier and the number of characters in the template identifier.
[0094] In one embodiment of this application, during the process of selecting a target code template from multiple preset code templates, a first preset threshold and a second preset threshold can be set. The first preset threshold is greater than the second preset threshold. This application does not impose specific restrictions on the values of the first preset threshold and the second preset threshold.
[0095] In one embodiment of this application, if the highest matching degree is greater than or equal to a first preset threshold, the preset code template corresponding to the highest matching degree is determined as the target code template. If the highest matching degree is less than the first preset threshold, the preset code template corresponding to a matching degree greater than a second preset threshold is determined as the target code template.
[0096] In another embodiment of this application, if all matching degrees are less than or equal to the second preset threshold, it can be determined that there is a large deviation between the file identifier and the template identifier, and a prompt message is output to prompt the user to re-enter the code generation requirement.
[0097] In this embodiment, when the highest matching degree is greater than or equal to a first preset threshold, the preset code template corresponding to the highest matching degree can be used as the target code template to quickly determine the preset code template that best matches the request information, avoiding redundant calculations caused by multiple template filtering. When the highest matching degree is less than the first preset threshold, it indicates that the multiple preset code templates do not include a single optimal template. Therefore, using the preset code template corresponding to a matching degree greater than a second preset threshold as the target code template can prevent valid templates that match the request information from being missed.
[0098] In other embodiments of this application, the electronic device determines the matching target code template based on the request information in the code generation request, and further includes: selecting a target code specification from multiple preset code specifications based on the request information; and determining the target code template based on the code example corresponding to the target code specification.
[0099] In one embodiment of this application, the electronic device identifies the user's intent in the request information and selects a target code specification from the multiple preset code specifications based on the similarity between the user's intent and multiple preset code specifications.
[0100] In one embodiment of this application, a dictionary can be set up, which includes multiple preset word units, each of which can correspond to at least one preset code specification. During the process of recognizing user intent, the electronic device can segment the request information to obtain multiple initial word units, select a target word unit from the multiple initial word units based on the preset vocabulary, and generate a user intent based on the target word unit.
[0101] For example, if the request message is "Please help me write a piece of code named logic-imexport-ep.truss.cola.adapter.excelcontroller.java.mtl", after processing, the target keywords are obtained, including: imexport, truss, cola, adapter, excelcontroller, and java. Here, imexport corresponds to import / export functionality, truss corresponds to the Truss framework, cola corresponds to the COLA architecture, adapter corresponds to the adaptation layer, excelcontroller corresponds to the Excel controller, and java corresponds to Java code. Therefore, the identified user intent is: generate Java code that conforms to the COLA architecture, Truss framework, adapter layer responsibilities, and Excel controller import / export specifications.
[0102] In one embodiment of this application, the method by which an electronic device can calculate the similarity between a user intent and multiple preset code specifications can be referred to the method by which an electronic device calculates the similarity between a first vector corresponding to a file identifier and a second vector corresponding to multiple template identifiers, which will not be described again in this application.
[0103] In one embodiment of this application, the electronic device may set a similarity threshold and determine the preset code specification corresponding to similarity greater than the similarity threshold as the target code specification.
[0104] In one embodiment of this application, the target code template is created based on the target code specification among multiple preset code specifications, and the electronic device obtains the code example corresponding to the target code specification as the target code template.
[0105] This application embodiment can filter out the target code specification corresponding to the code generation request based on the request information, and then quickly determine the target code template through the code example corresponding to the target code specification.
[0106] S502 generates prompt text based on the target code template.
[0107] In some embodiments of this application, the electronic device generates prompt text based on a target code template, including: obtaining a prompt word template; and filling the prompt word template with the target code template to obtain the prompt text.
[0108] In one embodiment of this application, the prompt word template includes one or more of the following information: identity information indicating that the language model is a code generation expert; task information indicating that the language model generates code based on the target code template; and preset quality requirements, which are used to limit the code generated by the language model. This application does not impose specific limitations on the prompt word template.
[0109] For example, the task information for the instruction language model to generate code based on the target code template can be set as: "Identify the Acceleo syntax description in the target code template; Code generation: Generate code based on the syntax description in the target code template, and output static code and configuration that are not part of the syntax description in the target code template as is; Intelligent fill: Infers the optimal implementation scheme based on the model context; The content to be filled in must meet the following requirements: syntactic correctness (primary condition), implementation completeness (covering all branch logic), and style consistency (matching the existing code style of the template).
[0110] The default quality requirements can be set as follows: "Complete code that can be directly compiled / executed must be generated. Natural language other than comments is prohibited. Ensure that variables described by template syntax marked in the form of [xxx / ] are correctly replaced."
[0111] In one embodiment of this application, the electronic device can fill the target code template into the corresponding position in the prompt word template to obtain prompt text. The electronic device can also concatenate the target code template and the prompt word template to obtain prompt text.
[0112] In this embodiment, the target code template is filled into the prompt word template, which ensures that the prompt text includes the target code template, so that the language model can understand the preset code specification.
[0113] In other embodiments of this application, a set quantity can be set according to actual needs. When the number of target code templates exceeds the set quantity, a preset template can be obtained. The preset template may include one or more of the following information: information indicating the language model's identity as a code generation expert; task information indicating the language model's task of generating code based on the target code template. The electronic device fills the preset template with the target code template to obtain the prompt text. In embodiments of this application, when the number of target code templates exceeds the set quantity, prompt text is generated based on the preset template, which avoids the language model spending a lot of time interpreting the prompt text due to excessive information in the prompt text.
[0114] S503, based on the prompt text, generates the target code corresponding to the request.
[0115] In some embodiments of this application, the electronic device utilizes a language model to generate target code based on prompt text.
[0116] In one embodiment of this application, the electronic device encodes the prompt text to obtain encoded features, and extracts key features of the encoded features through the self-attention mechanism of a language model. Based on the key features, the electronic device iteratively predicts the corresponding output words until a preset condition is met. The electronic device sequentially concatenates multiple output words to obtain an initial code. The electronic device uses the grammatical structure of the target code template in the prompt text to perform syntax validation on the initial code. If the initial code fails the syntax validation, it is adjusted based on the grammatical structure of the target code template to obtain the target code. If the initial code passes the syntax validation, it is determined as the target code.
[0117] In one embodiment of this application, during the prediction of the first output word, the electronic device decodes key features through the decoding network of a language model to obtain the first output word. Specifically, based on the key features, the electronic device predicts the probability corresponding to each configuration word and selects the configuration word with the highest probability as the first word.
[0118] In one embodiment of this application, during the prediction of the i-th output word, the electronic device concatenates the vectors of the first i-1 output words to obtain a first concatenated vector, where i is a positive integer greater than or equal to 2. The electronic device then concatenates the first concatenated vector with the key feature to obtain a second concatenated vector corresponding to the i-th output word. The electronic device decodes the second concatenated vector corresponding to the i-th output word through the decoding network of the language model to obtain the i-th output word. The method by which the electronic device decodes the second concatenated vector corresponding to the i-th output word can refer to the method by which the electronic device decodes the key feature, and will not be described again in this application.
[0119] In one embodiment of this application, the preset condition can be set and adjusted according to actual needs. For example, the preset condition can be set to the total number of output tokens being greater than a preset number threshold. The preset number threshold can be set and adjusted according to actual needs, and can also be set according to the number of characters in a single target code template. The preset condition can also be set to: the i-th output token is a preset character. The preset character can be set and adjusted according to actual needs; for example, the preset character can be set to "return".
[0120] The different ways that language models generate target code based on prompt text can be referenced from the code generation functions of various models in related technologies, and this application does not impose any restrictions on this.
[0121] In several embodiments of this application, based on the request information in the code generation request, a target code template that follows a preset code specification can be adapted, and then the target code template can be used to generate prompt text, so that the language model can accurately understand the preset code specification, thereby improving the generation quality and efficiency of the target code.
[0122] Please see Figure 7 This is a schematic diagram illustrating the framework of a code generation method provided in an embodiment of this application. Figure 7 In the illustrated framework diagram, the electronic device triggers a code generation task (also known as a "code generation request"). Based on the code task, the electronic device matches a target code template in a code knowledge graph (also known as a "code modeling graph"). The method for constructing the relevant graph can be found in the following section. Figure 8 A detailed description.
[0123] In some embodiments of this application, the electronic device matches a target code template from a vector library based on at least one file identifier, such as the filename, file extension, or path carried by the code task. The method for determining the target code template can be referred to... Figure 5 The relevant description of step S501 will not be repeated in this application.
[0124] In some embodiments of this application, the target code template may include, but is not limited to: a business code generation template, a test code generation template, and an assembly code generation template. An electronic device assembly prompt text template and a target code template are used to generate prompt text. The prompt text may include task information indicating that the language model generates code based on the target code template; for example, the task information may include a task description and generated content. The prompt text may also include the target code template. The method for generating the prompt text can be referred to... Figure 5 The relevant description of step S502 will not be repeated in this application.
[0125] In some embodiments of this application, the electronic device inputs prompt text into a language model and outputs generated code through the language model. The generated code can be understood as the target code corresponding to the code generation request.
[0126] In several embodiments of this application, a code knowledge graph can be used to accurately adapt a target code template that follows a preset code specification. Then, the target code template is used to generate prompt text, enabling the language model to accurately understand the preset code specification, improving the language model's compliance with the generation instructions when generating code, and thus improving the generation quality and efficiency of the target code.
[0127] Please see Figure 8 , Figure 8 This is a flowchart illustrating the steps of a code modeling graph construction method provided in one embodiment of this application. Figure 8 The steps shown are one possible illustration of an embodiment of this application. In other embodiments of this application, they can be changed according to actual needs. Figure 8 The diagram illustrates the sequence of steps. The code modeling graph construction method can be applied to electronic devices, such as... Figure 3 The method for constructing the code modeling graph for the terminal device 100 or server 200 shown may include the following steps: S801, retrieve the code example corresponding to the preset code specification.
[0128] In some embodiments of this application, the preset code specifications may include coding specifications in multiple dimensions. The preset code specifications can be set and adjusted according to actual needs. For example, the preset code specifications can refer to the coding specifications shown in Table 1. This application does not limit this.
[0129] In some embodiments of this application, the electronic device can obtain code examples that conform to preset code specifications. For example, the preset code specifications include: Enterprise Private Domain Development Engineering Specification 1, Enterprise Private Domain Technical Design Specification 2, Enterprise Private Domain Technical Specification 3, and Enterprise Private Domain Technical Specification 4. In one example, the electronic device can obtain code example 1 that conforms to Enterprise Private Domain Development Engineering Specification 1, code example 2 that conforms to Enterprise Private Domain Technical Design Specification 2, code example 3 that conforms to Enterprise Private Domain Technical Specification 3, and code example 4 that conforms to Enterprise Private Domain Technical Specification 4. In another example, the electronic device can also obtain code examples that conform to both Enterprise Private Domain Technical Specification 3 and Enterprise Private Domain Technical Specification 4.
[0130] S802, extract multiple entities and the entity relationships between them from the code example.
[0131] In some embodiments of this application, the electronic device can utilize a language model to extract multiple entities from code examples. The entity types of these entities may include, but are not limited to: project template entities, directory template entities, code file template entities, and code content template entities. For example, project template entities may include, but are not limited to: _context_-adapter, _context_-app, and _context_-infrastructure. Directory template entities may include, but are not limited to: / src / main / java / _package_ / controller, / src / main / java / _package_ / executor / command, and / src / main / java / _package_ / gateway / impl / database / mapper. Please refer to Table 3, which shows the structure of project template entities and directory template entities. In some embodiments of this application, the electronic device can construct configuration prompts for extracting entities from code examples. The content of the configuration prompts may include, but is not limited to: information indicating the language model's identity as a code expert, task information indicating the language model's task of extracting entities from the code examples, entity examples corresponding to multiple entity types, and naming convention requirements for multiple entities. The electronic device inputs the configuration prompts into the language model, which then extracts entities that meet the naming convention requirements from the code examples. This embodiment of the application, through the language model, can quickly extract entities that meet the naming convention requirements from code examples.
[0132] In some embodiments of this application, the electronic device can also utilize a language model to extract entity relationships between multiple entities from code examples. The method for extracting entity relationships is similar to the method for extracting multiple entities, and will not be described in detail here.
[0133] S803 constructs a code modeling graph based on multiple entities and their relationships.
[0134] In some embodiments of this application, the electronic device can set preset placeholders, such as package.name. The electronic device can identify code in code examples that changes with business requirements as dynamic code, and replace the dynamic code in multiple code examples with preset placeholders to obtain multiple preset code templates. For example, the preset code template obtained after replacing the dynamic code with preset placeholders can be package [package.name].controller, where "[package.name]" can represent the preset placeholder corresponding to the project package name, and ".controller" can represent the package path suffix. The electronic device can also establish a mapping relationship between template identifiers in multiple code examples and corresponding preset code templates. Template identifiers can be referenced... Figure 5 Step S501 describes the file identifier. In this embodiment, preset placeholders are used to replace dynamic code in multiple code examples to obtain multiple generic preset code templates. By establishing a mapping relationship between template identifiers and corresponding preset code templates, the target code template can be determined.
[0135] In some embodiments of this application, an electronic device constructs a code modeling graph based on multiple entities and entity relationships, including: constructing a code modeling graph using multiple entities as graph nodes and entity relationships as graph edges. The code modeling graph can be a knowledge graph, and the nodes in the code modeling graph correspond to multiple preset code templates. By using multiple entities as graph nodes and entity relationships as graph edges, the embodiments of this application can visually display the entity relationships in the code examples.
[0136] In some embodiments of this application, the electronic device constructs a code modeling graph based on multiple entities and entity relationships, further including: mapping each entity to a Unified Modeling Language (UML) class, and mapping the entity attributes of each entity to the object attributes of the corresponding UML class; mapping entity relationships to relationships between multiple UML classes; and constructing a code modeling graph based on multiple UML classes, object attributes, and relationships between multiple UML classes. The code modeling graph can be... Figure 9 The UML class diagram shown is as follows. Figure 9As shown, the electronic device maps each entity, and the resulting UML class can include basic reusable classes such as NamedElement (from MOF), Function (from QVT), Variable (from OCL), OclExpression (from OCL), Package (from MOF), Parameter (from MOF), and TypedModel (from QVT). The mapped UML class can also include Module, ModuleElement, Template, Block, TemplateExpression, Query, QueryInvocation, etc. UML classes are usually represented by solid rectangles. The electronic device can also map the entity attributes of each entity to the object attributes of the corresponding UML class. For example, the object attribute of the UML class "ModuleElement" is: +isPublic :Boolean, where "+" indicates visibility, "isPublic" indicates the attribute identifier of the object attribute of the UML class "ModuleElement", and "Boolean" indicates the attribute type of the object attribute of the UML class "ModuleElement". For example, if +isPublic :Boolean [0] = true, then all classes in the code modeling graph can access the UML class "ModuleElement" instance.
[0137] The relationships between multiple UML classes can include, but are not limited to: aggregation, composition, association, dependency, and inheritance. For example... Figure 9 As shown, the relationship between the UML class "ForBlock" and the UML class "Block" is one of inheritance.
[0138] In some embodiments of this application, the UML classes in the code modeling graph correspond to preset code templates. For example, the UML class "Template" can correspond to the preset code template "[template public generateValueObject(entity:entity.entity)]", and the UML class "IfBlock" can correspond to the preset code template "[ifservice.needapprovalprocess]". import [package.name].listener.ProcessTrigger; import [package.name].listener.SaveInstancesTrigger; import [package.name].listener.UpdateInstancesTrigger; [endif]”.
[0139] In some embodiments of this application, multiple UML classes in the code modeling graph correspond to a preset code template. For example, the combination of the UML class "Template" and the UML class "OclExpression" can correspond to the preset code template "@TrussResource( code = "[entity.name]ControllerResource", / / Permission resource code desc = "[entity.name]Controller Resource" / / Description of the permission resource )".
[0140] For example, the combination of the UML classes "IfBlock", "Template", and "OclExpression" can correspond to the preset code template "[if service.needquery]". / ** * ById query * @param id Entity ID * @return Unified Response Body / @GetMapping(" / {id}") @ApiOperation(value = "[entity.name] Information Query") @TrussOperation( code = "[entity.name]Controller_get[entity.name]ById", desc = "[entity.name]Controller_get[entity.name]ById", ) [endif]”.
[0141] In some embodiments of this application, multiple UML classes in the code modeling graph may also correspond to a preset code template. For example, the preset code template may also be "[if service.needcreate]". / ** * New Interface * * @param [entity.name.toLowercaseFirst()]VO New entity information * @return Unified response body * @throws BusinessException BusinessException * / @PostMapping @ApiOperation(value = "[entity.name] Information Saving") @TrusOperation( code = "[entity.name]Controller.create.[entity.name]", desc = "[entity.name]Controller.create.[entity.name]", policy = SecurityPolicy.Required) [if service.needapprovalprocess] @SaveInstanceTrigger [endif] @Audit(module = "[entity.name]Controller", operation = "create[entity.name]", message = "[entity.name]Controller functional create[entity.name]Successfully") public ResponseEntity<BaseResult <boolean>>create[entity.name](@Valid@RequestBody [entity.name]VO [entity.name.toLowercaseFirst()]VO) throwsBusinessException { [entity.name]VO register = [entity.name.toLowercaseFirst()]Service.register([entity.name.toLowercaseFirst()]VO); BaseResult <boolean>result = new BaseResult<>(); if (null == register) { result.setCode(ResponseCodeEnum.VUL_AUDIT_DATA_ALREADY_ERROR.getCode()); result.setMessage(ResponseCodeEnum.VUL_AUDIT_DATA_ALREADY_ERROR.getMessage()); return new ResponseEntity<>(result, HttpStatus.OK); } result.setCode(ResponseCodeEnum.SUCCESS.getCode()); result.setMessage(ResponseCodeEnum.SUCCESS.getMessage()); return new ResponseEntity<>(result, HttpStatus.OK); } [endif]”.
[0142] Based on multiple UML classes obtained by mapping multiple entities, object attributes of UML classes obtained by mapping entity attributes of each entity, and relationships between multiple UML classes obtained by mapping entity relationships, the abstract code examples can be transformed into a structured and standardized code modeling graph.
[0143] In several embodiments of this application, code modeling graphs are constructed using code examples corresponding to preset code specifications, which can ensure that multiple preset code templates corresponding to the code modeling graphs follow preset code specifications.
[0144] Please see Figure 10 This is a schematic diagram illustrating the framework of a code modeling graph construction method provided in an embodiment of this application. Figure 10 In the schematic diagram shown, the electronic device is based on code example 1 that follows the Enterprise Private Domain Development Engineering Specification 1, code example 2 that follows the Enterprise Private Domain Technical Design Specification 2, code example 3 that follows the Enterprise Private Domain Technical Specification 3, and code example 4 that follows the Enterprise Private Domain Technical Specification 4.
[0145] The electronic device can access a preset code template structure, which can be a pre-built code template structure within the industry. Based on the preset code template structure, the electronic device integrates code example 1, code example 2, code example 3, and code example 4 into a project template, directory template, file template, and content template. The project template, directory template, file template, and content template are templates at different levels.
[0146] Electronic devices construct a code knowledge graph based on project templates, directory templates, file templates, content templates, and code from the code repository. This code knowledge graph describes the relationships between multiple entities. The construction method for the code knowledge graph can be found in [reference needed]. Figure 8 The method for constructing the code template graph will not be described again in this application.
[0147] Electronic devices can convert code knowledge graphs into code template graphs, and each code template graph can correspond to multiple preset code templates. For example, a code template graph can be as follows: Figure 9 The UML class diagram shown. The UML classes in the code template diagram correspond to the preset code templates.
[0148] The template identifier for generating preset code templates on electronic devices can be found in the following documentation: Figure 5 The method for generating file identifiers. Electronic devices store the mapping relationship between the vector corresponding to the template identifier and the preset code template in a database (also known as a "vector library").
[0149] In several embodiments of this application, based on a preset code template structure, code examples corresponding to preset code specifications can be integrated into code templates of different levels. Then, by converting code templates of different levels into code template graphs, abstract code examples are transformed into structured and standardized code template graphs, so that corresponding target code templates can be matched from the code template graphs in the future.
[0150] Figure 11 This is a schematic diagram of the structure of an electronic device 10 provided in one embodiment of this application. (Reference) Figure 11 The electronic device 10 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0151] It is understood that the structures illustrated in the embodiments of the present invention do not constitute a specific limitation on the electronic device 10. In other embodiments of this application, the electronic device 10 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0152] The processor 110 may include one or more processing units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU).
[0153] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0154] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I1C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0155] The I1C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). The I2S interface can be used for audio communication. The PCM interface can also be used for audio communication, sampling, quantizing, and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via the PCM bus interface. The UART interface is a universal serial data bus used for asynchronous communication. This bus can be a bidirectional communication bus. It converts the data to be transmitted between serial and parallel communication. In some embodiments, the UART interface is typically used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 via the UART interface to implement Bluetooth functionality.
[0156] The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI) and a display serial interface (DSI). In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to enable the electronic device 10 to capture images. The processor 110 and the display screen 194 communicate via the DSI interface to enable the electronic device 10 to display images.
[0157] The GPIO interface is configurable via software. It can be configured as a control signal or a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 to a camera 193, a display screen 194, a wireless communication module 160, an audio module 170, a sensor module 180, etc. The GPIO interface can also be configured as an I1C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0158] USB port 130 is a USB standard compliant interface, specifically a Mini USB port, Micro USB port, USB Type-C port, etc. USB port 130 can be used to connect a charger to charge electronic device 10, and can also be used for data transfer between electronic device 10 and peripheral devices. It can also be used to connect headphones for audio playback. This interface can also be used to connect other electronic devices 10, such as AR devices.
[0159] It is understood that the interface connection relationships between the modules illustrated in the embodiments of the present invention are merely illustrative and do not constitute a structural limitation on the electronic device 10. In other embodiments of this application, the electronic device 10 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0160] The charging management module 140 receives charging input from a charger, which can be either a wireless or wired charger. The power management module 141 connects the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, providing power to the processor 110, internal memory 121, display screen 194, camera 193, and wireless communication module 160, among other components. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage current, impedance).
[0161] The wireless communication function of electronic device 10 can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor, and baseband processor.
[0162] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals.
[0163] The mobile communication module 150 can provide solutions for wireless communication applications including 2G / 3G / 4G / 5G on the electronic device 10. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1.
[0164] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 10, including wireless local area networks (WLAN), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR).
[0165] Electronic device 10 implements display functions through a GPU, display screen 194, and application processor. The GPU is a microprocessor that provides error alerts and connects to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0166] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Mini LED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc.
[0167] In some embodiments, the electronic device 10 may include one or N displays 194, where N is a positive integer greater than 1. The electronic device 10 may implement the shooting function through an ISP, a camera 193, a video codec, a GPU, displays 194, and an application processor.
[0168] Camera 193 is used to capture still images or videos. An object passes through the lens to generate an optical image that is projected onto a photosensitive element.
[0169] Internal memory 121 may include one or more random access memory (RAM) and one or more non-volatile memory (NVM).
[0170] The external memory interface 120 can be used to connect to external non-volatile memory, thereby expanding the storage capacity of the electronic device 10. The external non-volatile memory communicates with the processor 110 through the external memory interface 120 to perform data storage functions. For example, music, video, and other files can be stored in the external non-volatile memory.
[0171] Electronic device 10 can implement audio functions such as music playback and recording through audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.
[0172] Audio module 170 is used to convert digital audio information into analog audio signal output, and also to convert analog audio input into digital audio signal. Audio module 170 can also be used for encoding and decoding audio signals.
[0173] Speaker 170A, also known as a "loudspeaker," is used to convert audio electrical signals into sound signals. Electronic device 10 can listen to music or hands-free calls through speaker 170A. Receiver 170B, also known as a "handpiece," is used to convert audio electrical signals into sound signals. When electronic device 10 answers a phone call or voice message, the receiver 170B can be brought close to the user's ear to hear the voice. Microphone 170C, also known as a "microphone" or "voice transducer," is used to convert sound signals into electrical signals. When making a phone call or sending a voice message, the user can speak by bringing their mouth close to microphone 170C, inputting the sound signal into microphone 170C. Electronic device 10 can have at least one microphone 170C. In some embodiments, electronic device 10 can have two microphones 170C, which, in addition to collecting sound signals, can also achieve noise reduction. In other embodiments, electronic device 10 can have three, four, or more microphones 170C, which can collect sound signals, reduce noise, identify the sound source, and achieve directional recording functions, etc.
[0174] The 170D headphone jack is used to connect wired headphones. The 170D headphone jack can be a USB 130 interface or a 3.5mm Open Mobile Terminal Platform (OMTP) standard interface, a CTIA (Cellular Telecommunications Industry Association of the USA) standard interface.
[0175] Pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. Gyroscope sensor 180B can be used to determine the motion posture of electronic device 10. Barometric pressure sensor 180C is used to measure air pressure. Magnetic sensor 180D includes a Hall sensor. Electronic device 10 can use magnetic sensor 180D to detect the opening and closing of the flip cover. Accelerometer 180E can detect the magnitude of acceleration of electronic device 10 in various directions (generally three axes). Distance sensor 180F is used to measure distance. Proximity sensor 180G may include, for example, a light-emitting diode (LED) and a photodetector, such as a photodiode. Ambient light sensor 180L is used to sense ambient light intensity. Fingerprint sensor 180H is used to collect fingerprints. Temperature sensor 180J is used to detect temperature. Touch sensor 180K, also called a "touch device". Touch sensor 180K can be set on display screen 194, and touch sensor 180K and display screen 194 form a touch screen, also called a "touchscreen". Bone conduction sensor 180M can acquire vibration signals.
[0176] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. Motor 191 can generate vibration feedback. Indicator 192 can be an indicator light, used to indicate charging status, battery level changes, and also to indicate messages, missed calls, notifications, etc.
[0177] The SIM card interface 195 is used to connect a SIM card. The SIM card can be inserted into or removed from the SIM card interface 195 to make contact with and separate from the electronic device 10. The electronic device 10 can support one or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc. Multiple SIM cards can be inserted into the same SIM card interface 195 simultaneously. The types of multiple SIM cards can be the same or different. The SIM card interface 195 is also compatible with different types of SIM cards. The SIM card interface 195 is also compatible with external memory cards. The electronic device 10 interacts with the network through the SIM card to realize functions such as calls and data communication. In some embodiments, the electronic device 10 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 10 and cannot be separated from the electronic device 10.
[0178] This embodiment also provides a computer storage medium storing computer instructions. When the computer instructions are executed on the electronic device 10, the electronic device 10 performs the above-described related method steps to implement the code generation method in the above embodiment.
[0179] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned steps to implement the code generation method described in the above embodiment.
[0180] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component, or module. The apparatus may include a connected processor and a memory; wherein the memory is used to store computer execution instructions, and when the apparatus is running, the processor may execute the computer execution instructions stored in the memory to cause the chip to execute the code generation methods in the above-described method embodiments.
[0181] In this embodiment, the electronic device, computer storage medium, computer program product, or chip are all used to execute the corresponding methods described above. Therefore, the beneficial effects they achieve can be referred to the beneficial effects in the corresponding methods described above, and will not be repeated here. Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0182] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the shown or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms. The units described as separate components may or may not be physically separate. The components shown as units may be one physical unit or multiple physical units, i.e., they may be located in one place or distributed in multiple different places. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0183] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0184] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this application without departing from the spirit and scope of the technical solutions of this application.< / boolean> < / boolean>
Claims
1. A code generation method, characterized in that, The method includes: In response to a code generation request, a matching target code template is determined based on the request information in the code generation request, and the target code template is created based on a preset code specification. Based on the target code template, generate prompt text; Based on the prompt text, the target code corresponding to the code generation request is generated.
2. The method according to claim 1, characterized in that, The method further includes: Obtain the code example corresponding to the preset code specification; Extract multiple entities from the code example and the entity relationships between them; Based on the multiple entities and their relationships, a code modeling graph is constructed.
3. The method according to claim 2, characterized in that, The step of constructing a code modeling graph based on the multiple entities and their relationships includes: The code modeling graph is constructed by using the multiple entities as graph nodes and the entity relationships as graph edges. The nodes in the code modeling graph correspond to multiple preset code templates.
4. The method according to claim 2, characterized in that, The step of constructing a code modeling graph based on the multiple entities and their relationships further includes: Each entity is mapped to a Unified Modeling Language (UML) class, and the entity attributes of each entity are mapped to the object attributes of the corresponding UML class. Map the entity relationships to relationships between multiple UML classes; Based on the multiple UML classes, the object attributes, and the relationships between the multiple UML classes, the code modeling graph is constructed, and the UML classes in the code modeling graph correspond to multiple preset code templates.
5. The method according to any one of claims 2 to 4, characterized in that, The method further includes: By replacing dynamic code in multiple code examples with preset placeholders, multiple preset code templates can be obtained. Establish a mapping relationship between the template identifiers in the multiple code examples and the corresponding preset code templates.
6. The method according to claim 1, characterized in that, The step of determining the matching target code template based on the request information in the code generation request includes: Generate a file identifier corresponding to the code generation request based on the request information; Based on the matching degree between the file identifier and the template identifiers of multiple preset code templates, the target code template is selected from the multiple preset code templates.
7. The method according to claim 6, characterized in that, The matching degree is determined by one or more of the following methods in combination: The matching degree is determined based on the similarity between the first vector corresponding to the file identifier and the second vector corresponding to the template identifier; Count the first number of target characters in the file identifier, where the target characters represent the same characters in the file identifier and the template identifier at corresponding positions; The larger of the number of characters in the file identifier and the number of characters in the template identifier is determined as the second quantity, and the matching degree is determined based on the first quantity and the second quantity.
8. The method according to claim 6 or 7, characterized in that, The step of selecting the target code template from the multiple preset code templates based on the matching degree between the file identifier and the template identifier of the multiple preset code templates includes: If the highest matching degree is greater than or equal to the first preset threshold, the preset code template corresponding to the highest matching degree is determined as the target code template; If the highest matching degree is less than the first preset threshold, the preset code template corresponding to the matching degree greater than the second preset threshold is determined as the target code template, where the first preset threshold is greater than the second preset threshold.
9. The method according to claim 1, characterized in that, The step of generating prompt text based on the target code template includes: Get the prompt word template; The target code template is filled into the prompt word template to obtain the prompt text.
10. The method according to claim 9, characterized in that, The prompt word template includes one or more of the following information: Indicates the identity information of the language model as a code generation expert; Task information instructing the language model to generate code based on the target code template; A preset quality requirement is set to limit the code generated by the language model.
11. The method according to claim 1, characterized in that, The step of determining the matching target code template based on the request information in the code generation request further includes: Based on the request information, a target code specification is selected from multiple preset code specifications; The target code template is determined based on the code examples corresponding to the target code specification.
12. The method according to claim 11, characterized in that, The step of selecting a target code specification from multiple preset code specifications based on the request information includes: Identify the user's intent in the request information; The target code specification is selected from the multiple preset code specifications based on the similarity between the user intent and the preset code specifications.
13. An electronic device, characterized in that, include: Memory, which stores computer-readable instructions; A processor that, when executing the computer-readable instructions, implements the code generation method as described in any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor in an electronic device, implement the code generation method as described in any one of claims 1 to 12.