Code generation method and device, computer device, and storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-10
- Publication Date
- 2026-08-11
AI Technical Summary
当前在进行程序开发时,主要涉及对程序代码的编写和调试过程,而当前在进行程序代码的编写和调试时,主要是由负责程序开发的技术人员来进行编写和调试的,而随着程序的不断更新和技术革新,由开发人员来进行程序代码的编写和调试的方法,使得程序开发的人力成本较大,且存在效率低下的问题
[0021]在本申请实施例中,计算机设备可基于应用层获取到的针对待生成的程序代码的描述信息进行特征提取处理,从而得到待生成的程序代码的描述特征,并进一步通过模型层的代码生成模型,对数据层的代码知识库进行调用,以从数据层的代码知识库包含的编码特征中,通过特征匹配确定出与该描述特征相匹配的参考编码特征,进而则可基于描述特征和参考编码特征进行融合后得到的融合特征,调用模型层的代码生成模型来进行程序代码的生成。使得计算机设备实现了基于知识库技术得到融合特征并进行程序代码的生成,基于特征的匹配和融合进行程序代码的生成,可有效提升计算机设备进行代码生成的效率,且由于在代码生成过程中,是通过代码生成模型来实现的,而该代码生成模型又是已完成了模型训练的能提供各种生成目标的模型,那么,也就使得计算机设备实现了基于自然语言来进行程序代码的生成,可有效降低程序代码生成的门槛,有效提升代码的生成效率。
Smart Images

Figure CN122547321A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code generation method, apparatus, computer device, and storage medium. Background Technology
[0002] In the internet age, software development is a core force in building and driving the interconnectedness of the digital world. It not only promotes technological innovation and information exchange but also greatly enriches people's lives and work. Currently, software development mainly involves writing and debugging code, which is primarily done by technical personnel responsible for the development process. However, with continuous program updates and technological innovation, this method of relying on developers for code writing and debugging results in high labor costs and low efficiency. Therefore, improving code generation efficiency during software development has become a current research hotspot. Summary of the Invention
[0003] This invention provides a code generation method, apparatus, computer device, and storage medium, which can improve the efficiency of program code generation.
[0004] On one hand, embodiments of the present invention provide a code generation method, including:
[0005] Obtain descriptive information for the program code to be generated; the descriptive information is used to indicate the code functions possessed by the program code;
[0006] The descriptive information is subjected to feature extraction processing to obtain the descriptive features of the program code;
[0007] Reference coding features are matched from the code knowledge base based on the descriptive features, wherein the code knowledge base contains at least one coding feature, and one coding feature corresponds to one code function. The reference coding features include at least one coding feature in the code knowledge base that corresponds to the code function possessed by the program code.
[0008] The descriptive features and the reference coding features are fused to obtain fused features, and the program code is generated based on the fused features.
[0009] In another aspect, embodiments of the present invention provide a code generation apparatus, comprising:
[0010] An acquisition unit is used to acquire descriptive information about the program code to be generated; the descriptive information is used to indicate the code functions possessed by the program code.
[0011] The processing unit is used to perform feature extraction processing on the description information to obtain the description features of the program code;
[0012] The processing unit is further configured to match reference coding features from the code knowledge base based on the descriptive features, wherein the code knowledge base contains at least one coding feature, and one coding feature corresponds to one code function; the reference coding feature includes at least one coding feature in the code knowledge base that corresponds to the code function possessed by the program code.
[0013] The processing unit is further configured to perform feature fusion processing on the descriptive features and the reference coding features to obtain fused features, and generate the program code based on the fused features.
[0014] In another aspect, embodiments of the present invention provide a computer device, including a processor, an input device, an output device, and a memory, wherein the processor, input device, output device, and memory are interconnected, wherein the memory is used to store a computer program supporting the computer device in executing the above-described method, the computer program including program instructions, and the processor is configured to invoke the program instructions to execute the following steps:
[0015] Obtain descriptive information for the program code to be generated; the descriptive information is used to indicate the code functions possessed by the program code;
[0016] The descriptive information is subjected to feature extraction processing to obtain the descriptive features of the program code;
[0017] Reference coding features are matched from the code knowledge base based on the descriptive features, wherein the code knowledge base contains at least one coding feature, and one coding feature corresponds to one code function. The reference coding features include at least one coding feature in the code knowledge base that corresponds to the code function possessed by the program code.
[0018] The descriptive features and the reference coding features are fused to obtain fused features, and the program code is generated based on the fused features.
[0019] In another aspect, embodiments of the present invention provide a computer-readable storage medium storing a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method described in the first aspect.
[0020] In another aspect, embodiments of the present invention provide a computer program product, the computer program product including a computer program, the computer program including program instructions, and when the program instructions are invoked by a processor, causing the processor to execute the method described in the first aspect.
[0021] In this embodiment, the computer device can perform feature extraction processing based on the descriptive information of the program code to be generated obtained from the application layer, thereby obtaining the descriptive features of the program code to be generated. Further, through the code generation model of the model layer, it calls the code knowledge base of the data layer to determine a reference coding feature matching the descriptive feature from the coding features contained in the code knowledge base. Then, based on the fused feature obtained by fusing the descriptive feature and the reference coding feature, it calls the code generation model of the model layer to generate the program code. This enables the computer device to obtain fused features based on knowledge base technology and generate program code. The generation of program code based on feature matching and fusion can effectively improve the efficiency of code generation. Furthermore, since the code generation process is implemented through a code generation model, and this code generation model is a pre-trained model capable of providing various generation targets, the computer device can generate program code based on natural language, effectively lowering the threshold for program code generation and significantly improving code generation efficiency. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 This is a schematic diagram of a code generation system provided in an embodiment of the present invention;
[0024] Figure 2 This is a schematic flowchart of a code generation method provided in an embodiment of the present invention;
[0025] Figure 3a This is a schematic diagram of the overall architecture of a code generation model provided in an embodiment of the present invention;
[0026] Figure 3b This is a schematic diagram illustrating the determination of descriptive information provided in an embodiment of the present invention;
[0027] Figure 3c This is a schematic diagram illustrating the training of a code generation model for the model layer, provided by an embodiment of the present invention.
[0028] Figure 4a This is a schematic diagram of the architecture of an intelligent agent device provided in an embodiment of the present invention;
[0029] Figure 4b This is a schematic diagram illustrating program code generation and feedback model adjustment provided in an embodiment of the present invention;
[0030] Figure 5 This is a schematic block diagram of a code generation device provided in an embodiment of the present invention;
[0031] Figure 6 This is a schematic block diagram of a computer device provided in an embodiment of the present invention. Detailed Implementation
[0032] The technical solutions of this application will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0033] This application proposes a code generation method that allows a computer device to match reference coding features from a code knowledge base based on the descriptive features corresponding to the descriptive information of the program code to be output. The reference coding features obtained from the code knowledge base based on feature matching satisfy the coding features required for the generated program code. After determining the reference coding features, the computer device can generate program code based on the descriptive features corresponding to the descriptive information and the fused features corresponding to the reference coding features, thus achieving automatic program code generation and effectively improving the efficiency of program code generation. The descriptive information describing the program code to be output is described using natural language. Using natural language descriptions to generate program code effectively reduces the technical requirements for program code generation, lowering the technical threshold and improving programming efficiency.
[0034] The code generation involved in this application includes debugging existing program code and writing new program code. When generating program code, the computer device can invoke a code generation model. Specifically, the code generation model involved in this application includes a basic code generation model and a domain code generation model. Both the basic code generation model and the domain code generation model are large language models. The basic code generation model is the foundational large model used for basic program code generation, while the domain code generation model is a domain code model used for program code generation in a corresponding business domain.
[0035] In one embodiment, the basic model for generating basic program code is used to generate program code that does not contain business attributes. The description information used when generating program code without business attributes also does not contain keywords related to business attributes. For example, the description information could be: "Please optimize the input code," etc. However, the domain-specific model for generating program code in a related domain is used to generate program code that contains business attributes. Therefore, when generating program code with business attributes, the input description information is also description information containing keywords related to business attributes. For example, the description information containing keywords related to business attributes could be: "Please generate code for a data table corresponding to yesterday's daily active users (DAU) of the video account." The keywords used to describe business attributes in this description information are related to the video account business. Therefore, when the computer device generates code, the generated business must also be related to the video account business.
[0036] In other words, when a computer device generates program code based on object-based code generation requirements, in one implementation, the device calls either a basic code generation model or a domain code generation model based on the code generation requirement. Therefore, when the code generation requirement is for program code unrelated to (or weakly related to) domain business, the device can call the basic code generation model. In another implementation, when the code generation requirement is for program code related to (or strongly related to) domain business, the device can call the domain code generation model. This allows the device to flexibly control the calls to the basic and domain code generation models based on the differences in code generation requirements, thereby improving the matching between the generated program code and the code generation requirement, and enhancing the usability of the generated program code.
[0037] In another implementation, when generating program code based on object-based code generation requirements, the computer device can directly call a basic code generation model to generate the program code. However, while the basic code generation model possesses code generation capabilities, these capabilities are not integrated with relevant domain business logic. This means that if the program code generated using this basic model is applied to a specific domain business (such as the aforementioned video account business), it may not be reusable with other code within that domain business. In other words, although the program code generated using the basic model can implement the corresponding functions within the domain business, other functions within that domain business may be unable to invoke the program code when needed. Therefore, if the program code generated based on the basic code generation model is subsequently determined to be applied to a related domain business, the computer device can call the domain code generation model again to generate program code based on this code generation requirement. The domain code generation model is a type of model capable of generating code for a specific domain business. In other words, program code generated using the domain code generation model, when applied to the corresponding domain business, can not only implement functions within that domain business but also interoperate with the code for other functions within that domain business, thus better realizing the domain business. Furthermore, when the computer device determines that the program code generated by the basic code generation model needs to be applied to a related domain business, it can also call the domain code generation model to adjust the program code generated by the basic code generation model based on the business domain, thereby ensuring that the adjusted program code can interoperate with the code for other functions within that domain business.
[0038] The system possesses the ability to generate basic program code (i.e., code that cannot be reused and called by other business code within the corresponding domain business) based on the basic code generation model, and the ability to generate program code (i.e., code that can be reused and called by other business code within the corresponding domain business) based on the domain code generation model. In this embodiment, when deploying the models, two code generation models may be deployed separately: a basic code generation model and a domain code generation model, to adapt to different code generation intentions of the computer device. Based on the two deployed code generation models, the computer device can call different code generation models to perform program code generation processing based on different code generation intentions. In one embodiment, the code generation intention includes: the intention to generate basic program code and the intention to generate business program code. It can be understood that when the code generation intention is to generate basic program code, the basic program code is called to generate code; and when the code generation intention is to generate business program code, the business program code is called to generate code.
[0039] Because the basic code generation model and the domain code generation model differ, the training data used for training them also differs. The training processes for the basic code generation model and the domain code generation model are explained below:
[0040] (I) Training of the basic code generation model.
[0041] The sample data used to train the basic code generation model is the basic training sample, which includes the description sample and the code sample corresponding to the description sample. It can be understood that the code sample is the standard code that the basic model needs to generate based on the description sample.
[0042] Based on this foundational training sample, the computer device trains the basic code generation model by first calling the foundational large model to identify the description sample and obtain the sample features corresponding to it. Then, the computer device can retrieve the coding features with the highest feature similarity to the sample features from the code knowledge base. Furthermore, the sample features and the coding features retrieved based on them are concatenated and fused to obtain a fused feature sample. This fused feature sample can then be input into the foundational large model, enabling it to generate initial program code. Finally, the foundational large model is trained based on the differences between the initial program code and the code sample to obtain the basic code generation model.
[0043] (ii) Training of the domain code generation model.
[0044] The sample data used to train the domain code generation model can be called business samples. Similar to the basic training samples used to train the basic code generation model, business samples include business description samples and corresponding business code samples. In one embodiment, the business code sample not only contains the standard code that the trained domain code generation model needs to generate based on the business description sample, but also the business information of the standard code when implementing the target business.
[0045] In one embodiment, the domain code generation model trained by the computer device is obtained by training a basic code generation model. Since the basic code generation model already has the ability to generate program code, further training of the basic code generation model is to integrate the business information for implementing the target business contained in the business code sample into the model. This allows the program code generated by the model with integrated business information to be able to call each other with other program codes in the corresponding domain business when there is a calling requirement.
[0046] The method by which the computer device trains the basic code generation model and obtains the domain code generation model based on the business code sample is as follows: First, the computer device performs feature extraction and feature matching on the business description. Then, it fuses the features of the extracted business description sample and the corresponding matching features to obtain the fused business feature sample. Next, the computer device can obtain the business information for implementing the target business from the business code sample. Furthermore, the computer device can call the basic code generation model to generate initial business program code based on the business feature sample and business information. Based on the difference between the initial business program code and the business code sample, the basic code generation model is fine-tuned to obtain the domain code generation model, thereby integrating the fused information into the trained domain code generation model.
[0047] In one embodiment, the business information for implementing the target business includes: the location description of the code context (function, class, file path) of standard code under the domain business when applied to the corresponding domain; the symbol definitions and dependencies of the corresponding code file imports; similar code blocks and functions; the data interface (API) sequence call knowledge of the basic code components; and information such as domain functions and functional specifications. With this information, the application method of the description code under the corresponding domain business can be clearly defined. Therefore, by training the model with this business information, the trained domain code generation model can also learn the relevant file information knowledge, such as functions and classes, that need to be included in the program code generated under the corresponding domain business, thus obtaining a domain code generation model specific to that domain business.
[0048] After training the basic code generation model and the domain code generation model, the computer device can generate program code by calling these models. In one embodiment, if the description information obtained by the computer device requesting program code generation does not contain business-related information, the basic program code can be called to generate the code; if the description information obtained by the computer device requesting program code generation contains business-related content, the domain code generation model can be called to generate the program code.
[0049] Please see below. Figure 1 , Figure 1 This is a schematic diagram of the network architecture for implementing a code generation method according to an embodiment of this application. Figure 1 As shown, this network architecture may include a server 200 and a terminal device cluster. The terminal device cluster may include one or more terminal devices; the number of terminal devices is not limited here. Figure 1 As shown, multiple terminal devices can specifically include terminal device 1, terminal device 2, terminal device 3, ..., terminal device n, where n is a positive integer. For example... Figure 1 As shown, terminal device 1, terminal device 2, terminal device 3, ..., terminal device n can all connect to server 200 via the network, so that each terminal device can interact with server 200 through the network connection.
[0050] like Figure 1The server 200 shown 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, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal device can be a smartphone, tablet, laptop, desktop computer, smart TV, in-vehicle terminal, smart home device, or other smart terminal. The following description uses the communication between terminal device 1 and server 200 as an example to illustrate the specific implementation of this application.
[0051] In this context, terminal device 1 can be a user terminal, and terminal device 1 can contain a business client. This business client is a client capable of requesting program code generation, and the client can be software, a mini-program (a program that does not require installation), a webpage, etc. Server 200 can be the backend server to which this business client belongs.
[0052] The following describes the overall process of the code generation method involved in the embodiments of this application, taking terminal device 1 and server 200 as examples.
[0053] (1) Terminal device 1 sends description information of the program code to be generated to server 200, such as description text;
[0054] (2) Server 200 determines the code function of the program code to be generated based on the description information sent by terminal device 1, and performs feature extraction processing on the description information to obtain the corresponding description features.
[0055] (3) If the server 200 determines that the program code to be generated is not related to the domain business based on the description information, it calls the basic code generation model to determine the reference coding feature that matches the description feature from the code knowledge base according to the description feature of the description information, so that the basic code generation model generates basic program code according to the fusion feature of the description feature and the reference coding feature.
[0056] (4) If the server 200 determines that the program code to be generated is related to the corresponding domain business based on the description information, then the computer device can call the corresponding domain code generation model and make the domain code generation model determine the reference coding feature that matches the description feature under the domain knowledge from the code knowledge base according to the description feature of the description information, and then generate the program code under the domain business according to the fusion feature of the reference coding feature matched under the domain knowledge and the description feature.
[0057] (5) The program code generated by server 200 is returned to terminal device 1 and displayed on terminal device 1.
[0058] Based on this method of generating program code, computer devices can automatically generate program code based on descriptions in natural language. This, combined with the knowledge learned by the corresponding model for generating relevant program code and the code statements provided by the code knowledge base, can effectively improve the efficiency of computer devices in generating program code and reduce the technical requirements for program code generation, thereby improving the development efficiency of applications.
[0059] It should be specifically noted that the data involved in the code generation process of this application (such as sample data, descriptive information, code knowledge base, etc.) requires the permission or consent of the target user when the above embodiments of this application are applied to specific products or technologies. Furthermore, the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the region, adhering to the principles of legality, legitimacy, and necessity, and must not involve obtaining data types prohibited or restricted by laws and regulations. In some optional embodiments, the related data involved in the embodiments of this application is obtained after separate authorization from the target user. Additionally, when obtaining separate authorization from the target user, the purpose of the related data is explained to the target user.
[0060] Please see Figure 2 This is a schematic flowchart illustrating a code generation method proposed in an embodiment of this application. This code generation method can be executed by a computer device, which can be... Figure 1 The terminal device in the middle can be Figure 1 The server in the middle can also be provided by Figure 1 The system equipment consisting of terminal devices and servers is not limited in the embodiments of this application. Figure 2 As shown, the method may include:
[0061] S201, Obtain description information for the program code to be generated; the description information is used to indicate the code functions that the program code has.
[0062] The computer device that acquires description information for program code generation is essentially an intelligent agent device; that is, the program code in this embodiment is generated by this intelligent agent device. In one embodiment, the intelligent agent device, such as... Figure 3aAs shown, it consists of an application layer, a model layer, and a data layer. The model layer deploys code generation models (including the aforementioned basic code generation model and domain code generation model). The data layer stores the code knowledge base. The application layer obtains the description information of the program code to be generated. After obtaining the description information, the application layer sends it to the model layer. The model layer receives the description information sent by the application layer, performs feature extraction processing on the description information to obtain description features, and matches the reference coding features from the code knowledge base stored in the data layer based on the description features. In addition, the model layer also calls the code generation model to generate program code based on the fused features of the reference coding features and description features.
[0063] In one embodiment, the application layer of the intelligent agent device is further used to provide an application page, which displays the generation functions (or generation goals) supported by the intelligent agent device for generating program code. The generation functions (or generation goals) supported by the intelligent agent device include one or more of the following: generating debugged code after debugging existing program code contained in the description information; generating annotation information of existing program code after annotating it; and writing code for program code functions indicated by the description information. Code debugging includes one or more of the following: code optimization, code completion, and code correction; code annotation includes one or two of the following: code explanation and code comments. Therefore, based on the program code generation functions (or goals) supported by the intelligent agent device, the corresponding functional components can be displayed on the application page corresponding to the application layer of the intelligent agent device (i.e., the computer device).
[0064] Specifically, the functional components displayed on the application page corresponding to the application layer of the intelligent agent device may include one or more of the following: functional components for code optimization, functional components for code generation, functional components for code completion, functional components for code commenting, functional components for code correction, and functional components for code translation, etc. By displaying these functional components on the application page corresponding to the application layer, the user of the intelligent agent device can select the appropriate functional component based on the current program development needs, triggering the corresponding code generation function of the intelligent agent device, thereby enabling the intelligent agent device to generate program code based on the corresponding code generation function.
[0065] In another implementation, the application layer may not directly display these functional components on the application page, but instead embed them as built-in components. In this case, after obtaining the description information input by the user, the application page corresponding to the application layer can determine the generation target of the program code to be output based on the description information, and then trigger the corresponding built-in component so that the intelligent agent device can generate program code based on the code generation function corresponding to the triggered built-in component. In one embodiment, the description information obtained by the application page may be, for example, "Please optimize the following code, XXX (representing the input code to be optimized)". By analyzing the description information, it can be determined that the current generation target for the program code to be generated by the intelligent agent device is the target of code optimization. Then, the functional component of the application layer for code optimization will be triggered, and the intelligent agent device will generate optimized program code under the code generation function of code optimization (i.e., the code generation target).
[0066] In one embodiment, the application layer integrates all the code generation functions provided by the intelligent agent device into a single application page, enabling the intelligent agent device to interact with the corresponding user based on this application page. The user can select a code block through the application page, triggering the intelligent agent device to analyze and optimize the code within that block. Furthermore, the user can quickly access the various code generation functions supported by the intelligent agent device through the application interface, or they can access the application page through a programming interface to activate these functions. In other words, the application layer of the intelligent agent device provides program development assistance. The process of obtaining the description information of the code to be generated in step S201 is performed by the application layer of the intelligent agent device.
[0067] In one embodiment, the descriptive information obtained by the computer device (or intelligent agent device) is mainly text information, wherein the text information is text described using natural language. When the computer device obtains descriptive information for the program code to be generated, it can first obtain the input text and perform text rewriting processing on the input text to obtain the rewritten text. The text rewriting processing includes one or more of the following: merging the input text with historical text, associating the input text with relevant business data, and associating the input text with existing code information used to implement the code function.
[0068] In one embodiment, the input text acquired by the computer device is the currently input text, which is the text entered by the user in the current interaction round with the computer device. Before the current interaction round, there may have been previous interaction rounds, and these previous interaction rounds also contain historical input text. After acquiring the currently input text, the computer device can combine it with the user's historical input text from previous rounds to jointly determine the intent of the current input text to request code generation. In a specific implementation, after acquiring the currently input text, the computer device can acquire at least one historical input text and combine the intent of the current input text indicating code generation with the intent of each historical input text. If the intent indicated by the current input text is the same as the intent indicated by the historical input text, the current input text can be rewritten based on the historical input text with the same intent. This means merging the historical input text with the current input text, and using the merged text as the new rewritten text. If the intent of the historical input text is different from the intent of the current input text, the historical input text will not be merged and rewritten with the current input text.
[0069] Furthermore, when the input text is a descriptive text requesting the generation of program code under a corresponding business domain, since implementing the program code under that business domain may require related business data, the computer device can, in this case, obtain the business data associated with the input text based on the input text and use the input text associated with the business data as the new rewritten text. In one embodiment, when the business data required for generating program code under a corresponding business domain from the input text is data table type business data, the corresponding data table type business data can be obtained based on the data table schema (a data table identifier) or Data Definition Language (DDL), and the input text can be rewritten based on the obtained data table business data to obtain a new rewritten text.
[0070] Based on the acquisition of relevant business data and the rewriting of input text based on the acquired business data, the description information for program code generation by the intelligent agent device already contains business data. Therefore, when the intelligent agent device generates program code based on this description information, it does not need to acquire business data again, but can generate program code based on the business data contained in the description information, thereby effectively improving the efficiency of program code generation by the computer device.
[0071] Furthermore, since the implementation of the program code to be generated, as indicated by the input text, may be generated using other existing program code, the computer device, after acquiring the input text, can also associate the input text with existing code information used to implement the functionality of the program code to be generated, and rewrite the input text based on the acquired existing code information to obtain new rewritten text. In one embodiment, the existing code information is recorded in a code project file directory, so the computer device can determine the existing code information used to implement the functionality of the program code to be generated based on the code project file directory.
[0072] Specifically, if the program code to be generated is for implementing function A, and the implementation of function A is related to function B (e.g., calling program code b for function B), then after obtaining the input text of the program code a to be generated, the computer device can retrieve program code b based on the code project file directory, associate program code b with the input text, and use the input text associated with program code b as the rewritten text. By rewriting the input text based on existing program code, the intelligent agent device can effectively reuse existing program code during the program code generation process, thereby avoiding the repeated generation of existing program code, improving the conciseness of the generated program code, and thus enhancing the applicability of the code.
[0073] After the computer device identifies the rewritten text from the input text, it can further perform intent recognition on the rewritten text to extract keywords. These extracted keywords are then used as descriptive information for the program code to be generated. Specifically, this can be done as follows: Figure 3b As shown. The keywords extracted by the computer equipment include keywords describing the functionalities required for the generated program code, keywords describing the generation intent of the generated program code, keywords describing the business scenario of the domain corresponding to the generated program code, and so on.
[0074] In one embodiment, when the rewritten text is: "Please optimize the following code, XXX (representing the input code to be optimized)," the keyword for the required code function is the code function corresponding to the code to be optimized XXX, and the keyword describing the generation intent is: "optimize." Since this program code does not correspond to the domain business, there are no keywords describing the business scenario. In another implementation, if the rewritten text is: "Please generate code corresponding to yesterday's daily active users (DAU) of the video account," then the extracted keyword for the required code function is: "statistics DAU," the keyword for the generation intent is: "generate," and the keywords for the business domain are: "video account" and "DAU."
[0075] After obtaining the description information from the application page in the application layer, the intelligent agent device can call the code generation model deployed in the model layer to extract the description features corresponding to the description information, and then match the reference encoded features from the code knowledge base stored in the data layer based on the description features. That is, the intelligent agent device can then proceed to step S202. Alternatively, the computer device can also, after extracting the description features corresponding to the description information and...
[0076] S202, perform feature extraction processing on the description information to obtain the description features of the program code.
[0077] S203, Match reference coding features from the code knowledge base based on descriptive features, wherein the code knowledge base contains at least one coding feature, and one coding feature corresponds to one code function. The reference coding features include at least one coding feature in the code knowledge base that corresponds to the code function possessed by the program code.
[0078] In steps S202 and S203, the process of feature extraction of descriptive information and matching coding features from the code knowledge base based on the extracted descriptive features can be implemented by calling the code generation model deployed at the model layer. In one embodiment, the code generation model deployed at the model layer includes a basic code generation model and a domain code generation model. The training process for the basic code generation model can adopt the aforementioned training process. When training the basic code generation model, the basic training samples used to train the basic code generation model can be pre-processed according to the pre-training or augmentation method, and then the new basic training samples obtained after processing can be used to train the basic code generation model.
[0079] In one embodiment, when preprocessing the basic training samples, a security scan of the basic training samples can be performed to detect sensitive information, defects, and vulnerabilities involved in the code samples within the basic training samples. Specifically, the detection includes one or more of the following: specification detection of the code samples involved in the basic training samples, cyclomatic complexity analysis, license analysis (a method for analyzing data usage), deduplication analysis of code samples, formatting of code samples, and quality assessment of code samples.
[0080] By detecting sensitive information, defects, and vulnerabilities in the code samples of the basic training samples, sensitive information can be removed, and defects can be supplemented and vulnerabilities removed to obtain new code samples, thus obtaining new basic training samples and improving code quality. Since the process of training this basic code generation model involves using a code knowledge base to write (generate) new program code based on fused information or to improve existing program code, in the data preparation stage of the basic training samples, various code task data pairs can be constructed based on static code analysis. Then, after quality assessment and manual annotation, a small portion is selected as high-quality seed data for basic training. Then, in the training stage, various fine-tuning techniques are used to adjust all parameters of the basic large model, thereby training the basic code generation model.
[0081] By improving the quality of the corresponding code samples, the quality of the code generated by the base code generation model, after being trained using those samples, is also improved. Furthermore, training the base code generation model with higher-quality code samples can effectively improve the efficiency of training that model.
[0082] After training a basic code generation model, further domain-specific fine-tuning can be performed based on its model parameters to obtain a domain-specific code generation model. During this domain-specific fine-tuning, the computer device can utilize retrieval enhancement techniques and related techniques defined by prompt word engineering. Retrieval enhancement involves abstracting and storing the code information to be retrieved from the code knowledge base as features. The process of retrieving relevant code from the code knowledge base based on descriptive information is then abstracted as a feature matching process between the descriptive features corresponding to the descriptive information and the encoding features in the code knowledge base. It can be understood that since feature matching involves multiple dimensions and levels of matching, this retrieval enhancement improves the accuracy of the code information retrieved from the code knowledge base during the training of the domain-specific code generation model, thereby enhancing the code generation capability of the trained domain-specific code generation model.
[0083] Furthermore, the prompt word engineering technique refers to using prompt word engineering to assign the domain code generation model (or the intelligent agent device) the role of a professional programmer during training. This involves using tool invocation technology to ensure stable and accurate API calls between the intelligent agent device and different tools. Simultaneously, it leverages the agent's contextual memory to achieve multi-turn dialogue and multi-intent recognition and triage of users. The domain code generation model trained using prompt word engineering, once deployed to the model layer of the intelligent agent device, makes the device more human-like when interacting with users, thus increasing user engagement and enhancing the device's applicability.
[0084] The trained base code generation model and domain code generation model are as follows: Figure 3c As shown, the basic code generation model and the domain code generation model are deployed to the model layer of the intelligent agent device. During the model deployment phase, the vLLM (Virtual Large Language Model, an efficient system for optimizing large language model inference) large model inference acceleration framework can be used to deploy the trained basic code generation model and domain code generation model to a constant-running environment (i.e., the model layer), facilitating the provision of a secure and stable usage environment for the application layer.
[0085] In one embodiment, since training the base code generation model and the domain code generation model is an iterative optimization process, existing sample data or feedback data from actual users can be used for training and optimization during the iterative optimization phase. Therefore, during model deployment, a data flywheel can be built at the model layer to form a positive loop for model training and optimization. Based on collected bad cases (negative feedback information) combined with manual annotation, automated technology is used to achieve self-detection and self-optimization of model iteration. The core of the data flywheel is a data processing mechanism that continuously improves model performance by accumulating, analyzing, feeding back, and optimizing data to form a self-reinforcing positive feedback loop.
[0086] By deploying a basic code generation model and a domain code generation model at the model layer, the intelligent agent device can extract descriptive features from the descriptive information of the program code to be generated after obtaining it. Based on these descriptive features, it can then match reference coding features from the code knowledge base at the data layer. Specifically, when matching reference coding features from the code knowledge base based on descriptive features, the computer device first calculates the similarity between the descriptive features and each coding feature included in the code knowledge base, determining the coding feature with the highest similarity. This highest-similarity coding feature is then used as the reference coding feature for the reference code statements used to implement the code functionality, matched from the code knowledge base.
[0087] Based on the reference coding features matched by the computer device, the computer device can generate corresponding program code based on the fused features after performing feature fusion between the descriptive features and the reference coding features, and then proceed to execute step S204.
[0088] S204, perform feature fusion processing on the descriptive features and reference coding features to obtain fused features, and generate program code based on the fused features.
[0089] In one embodiment, when a computer device performs feature fusion on descriptive features and reference coding features, since the descriptive information obtained by the computer device includes keywords extracted from the rewritten text, and the extracted keywords not only include functional keywords indicating code functions, but also keywords indicating the generation intent of the program code to be generated, the computer device can further perform business keyword recognition processing on the extracted keywords after extracting the corresponding keywords from the rewritten text. When a business keyword is identified from the extracted keywords, the generation intent of the program code to be generated is determined to be the intent to generate business program code; when no business keyword is identified, the generation intent of the program code to be generated is determined to be the intent to generate basic program code.
[0090] In one embodiment, since the program code is generated by calling a code generation model deployed in the model layer, the code generation model includes a basic code generation model and a domain code generation model. The basic code generation model is associated with the encoding features corresponding to the basic code statements in the code knowledge base, and the domain code generation model is associated with the encoding features corresponding to the business code statements in the code knowledge base. Therefore, when the current generation intent is determined to be to generate business program code based on the descriptive information (i.e., the extracted keywords), the computer device can match a first reference encoding feature from the code knowledge base based on the descriptive features, and then call the domain code generation model to generate business program code based on the fused features obtained from the first reference encoding feature and the descriptive features. The first reference encoding feature is the encoding feature corresponding to the business code statements used to implement the code's functionality.
[0091] Alternatively, when the computer device determines that the current generation intent is to generate basic program code, it can match the second reference coding feature from the code knowledge base based on the descriptive features, and call the basic code generation model to generate basic program code based on the fused features obtained from the second reference coding feature and the descriptive features; wherein, the second reference coding feature is the coding feature corresponding to the basic code statement used to implement the code function.
[0092] In other words, by extracting keywords, the current generation intent of the intelligent agent device can be determined. Based on this generation intent, the basic code generation model can be called to generate basic program code, or the domain code generation model can be called to generate business program code.
[0093] After generating the business program code (including basic program code and business program code), the output business program code can be used to implement the target business and obtain business feedback information for the target business. This feedback information is then used to collect bad cases. In specific implementations, by configuring the target business with product features, such as allowing users to like or dislike it, business feedback can be obtained. Likes indicate that the implementation of the target business meets the needs of the relevant users, while dislikes indicate that the implementation does not meet the needs of the relevant users. These dislikes are the bad cases that the intelligent agent device needs to acquire.
[0094] In other words, when the computer device obtains business feedback information from the target business implemented by the generated business program code, indicating that the business user is not satisfied with the target business implemented by the business program code, the currently generated business program code can be used as a negative sample, and the reason for obtaining the business feedback information can be obtained. Based on the reason obtained, the standard business program code can be determined. The domain code generation model is then fine-tuned and trained based on the negative sample and the standard business program code to obtain the trained domain code generation model.
[0095] Specifically, the reasons why users are not satisfied with using business programs to implement business operations include: first, the code generation model at the model layer makes a mistake in feature inverse mapping when generating program code based on fusion features; second, the tool call is incorrect, such as interpreting program code instead of optimizing it.
[0096] Based on the obtained information, the currently generated business program code, along with the descriptive information used to generate it, can be sent to a code expert object. This allows the code expert object to retrieve the standard business program code to be generated based on the descriptive information. The domain code generation model can then be fine-tuned and optimized using this standard code, enabling real-time adjustments to the domain code generation model based on bad cases, taking into account the actual implementation of the business requirements. Furthermore, when business feedback indicates that the user is satisfied with the target business implemented using the business program code, this feedback can establish a corresponding positive case (Good case). Based on this positive case, the domain program code can then be iteratively optimized according to requirements.
[0097] Below, in conjunction with Figure 4a This application describes an intelligent agent device according to its embodiments. The intelligent agent device includes an application layer, a model layer, and a data layer. The descriptions of the application layer and model layer can be found in the foregoing embodiments. The data layer of the intelligent agent device can be described as follows: Figure 4a As shown, this data layer provides high-quality training samples for the basic code generation model and tool calls and contextual memory for the domain code generation model. It also uses prompt word engineering to define the role of the domain code generation model as a professional programmer, thereby improving the code generation capabilities of the trained model. Furthermore, this data layer further fine-tunes the model based on feedback mechanisms and feedback classification attribution.
[0098] Based on this intelligent agent device, the process of outputting program code based on input text and fine-tuning the model based on feedback information can be described as follows: Figure 4b As shown, the process includes the following steps:
[0099] (1) Obtain the input text and rewrite it to obtain the rewritten text. After obtaining the rewritten text, the intention of generating the program code to be generated can be determined by recognizing the intention of the rewritten text. Based on the rewritten text, the intelligent agent device can also determine the code function required by the program code to be generated and the generation goal (the goal is to optimize, complete, generate, or interpret the code).
[0100] (2) When the input text does not contain business keywords, the basic code generation model in the model layer is called to generate basic program code. When the input text contains business keywords, the domain program code in the model layer can be called to generate business program code.
[0101] (3) Output the generated program code, and after deploying the generated business program code to the corresponding business domain, collect feedback information on the business implemented based on the business program code.
[0102] (4) Classify and attribute the feedback information to obtain Bad case and Good case, and further optimize the domain code generation model based on the Bad case and Good case to further improve the ability of the code generation model in the model layer to generate program code.
[0103] In this embodiment, the computer device can perform feature extraction processing based on the descriptive information of the program code to be generated obtained from the application layer, thereby obtaining the descriptive features of the program code to be generated. Further, through the code generation model of the model layer, it calls the code knowledge base of the data layer to determine a reference coding feature matching the descriptive feature from the coding features contained in the code knowledge base. Then, based on the fused feature obtained by fusing the descriptive feature and the reference coding feature, it calls the code generation model of the model layer to generate the program code. This enables the computer device to obtain fused features based on knowledge base technology and generate program code. The generation of program code based on feature matching and fusion can effectively improve the efficiency of code generation. Furthermore, since the code generation process is implemented through a code generation model, and this code generation model is a pre-trained model capable of providing various generation targets, the computer device can generate program code based on natural language, effectively lowering the threshold for program code generation and significantly improving code generation efficiency.
[0104] Please see Figure 5 , Figure 5 This is a schematic diagram of the structure of a code generation device provided in an embodiment of this application. Figure 5As shown, the code generation device may include an acquisition unit 501 and a processing unit 502.
[0105] The acquisition unit 501 is used to acquire description information for the program code to be generated; the description information is used to indicate the code functions possessed by the program code;
[0106] The processing unit 502 is used to perform feature extraction processing on the description information to obtain the description features of the program code;
[0107] The processing unit 502 is further configured to match reference coding features from the code knowledge base based on the description features, wherein the code knowledge base contains at least one coding feature, and one coding feature corresponds to one code function; the reference coding feature includes at least one coding feature in the code knowledge base that corresponds to the code function possessed by the program code.
[0108] The processing unit 502 is further configured to perform feature fusion processing on the description feature and the reference coding feature to obtain fused features, and generate the program code based on the fused features.
[0109] In one embodiment, the program code is generated by an intelligent agent device, which includes an application layer, a model layer, and a data layer; the model layer deploys a code generation model, and the data layer stores the code knowledge base.
[0110] The application layer obtains the description information of the program code to be generated and sends the description information to the model layer.
[0111] The model layer receives the description information sent by the application layer, performs feature extraction processing on the description information to obtain the description features, and matches the reference coding features from the code knowledge base stored in the data layer based on the description features.
[0112] The model layer calls the code generation model to generate the program code based on the fusion features of the reference coding features and the description features.
[0113] In one embodiment, the processing unit 502 is specifically used for:
[0114] Obtain input text and perform text rewriting processing on the input text to obtain rewritten text; wherein, the text rewriting processing includes one or more of the following: merging the input text with historical text, associating the input text with corresponding business data, and associating the input text with existing code information used to implement the code function;
[0115] Keywords are extracted from the rewritten text and used as descriptive information for the program code to be generated.
[0116] In one embodiment, the description information includes extracted keywords, which include functional keywords indicating the function of the code, wherein the extracted keywords are also used to indicate the generation intent of the program code to be generated;
[0117] The processing unit 502 is further configured to perform business keyword identification processing on the extracted keywords, and when a business keyword is identified from the extracted keywords, determine that the intention to generate the program code to be generated is the intention to generate business program code.
[0118] The processing unit 502 is further configured to determine, when the business keyword is not identified, that the intention to generate the program code to be generated is the intention to generate basic program code.
[0119] In one embodiment, the program code is generated by calling a code generation model deployed in the model layer. The code generation model includes a basic code generation model and a domain code generation model. The basic code generation model is associated with the encoding features corresponding to the basic code statements in the code knowledge base, and the domain code generation model is associated with the encoding features corresponding to the business code statements in the code knowledge base.
[0120] The processing unit 502 is further configured to, when the generation intent is to generate business program code, match a first reference encoding feature from the code knowledge base based on the description feature, and call the domain code generation model to generate business program code based on the fusion feature obtained by the first reference encoding feature and the description feature; wherein, the first reference encoding feature is the encoding feature corresponding to the business code statement used to implement the function of the code.
[0121] The processing unit 502 is further configured to, when the generation intent is to generate basic program code, match a second reference encoding feature from the code knowledge base based on the description feature, and call the basic code generation model to generate basic program code based on the fusion feature obtained by the second reference encoding feature and the description feature; wherein, the second reference encoding feature is the encoding feature corresponding to the basic code statement used to implement the code function.
[0122] In one embodiment, the processing unit 502 is specifically used for:
[0123] The similarity between the descriptive features and the coding features contained in the code knowledge base is calculated, and the coding feature with the highest similarity is determined.
[0124] The encoding feature with the highest similarity is used as the reference encoding feature for the reference code statement matched from the code knowledge base to implement the code function.
[0125] In one embodiment, the description information is further used to indicate the generation target of the program code to be output, the generation target including one or more of the following: the target of generating debugged code after debugging the existing program code contained in the description information, the target of generating annotation information of the existing program code after annotating the existing program code, and the target of writing code for the program code function indicated by the description information.
[0126] The code debugging includes one or more of the following: code optimization, code completion, and code error correction; the code annotation includes one or two of the following: code explanation and code comments.
[0127] In one embodiment, the code generation model deployed in the model layer includes a basic code generation model, which is obtained after basic training of a basic large model. The basic training samples used for basic training include: description samples and corresponding code samples, wherein the code samples are standard code to be generated by the basic large model based on the description samples; the processing unit 502 is specifically used for:
[0128] The basic large model is invoked to generate fused feature samples based on the description samples, and initial program code is generated based on the fused feature samples;
[0129] Based on the differences between the initial program code and the code sample, the basic large model is trained to obtain the basic code generation model.
[0130] In one embodiment, the code generation model deployed in the model layer further includes a domain code generation model, which is obtained by fine-tuning the basic code generation model using business samples. The business samples include business description samples and corresponding business code samples. The processing unit 502 is specifically used for:
[0131] Obtain the fused business feature sample based on the business description sample, and obtain the business information for implementing the target business from the business code sample;
[0132] The basic code generation model is invoked to generate initial business program code based on the business feature sample and the business information. Based on the difference between the initial business program code and the business code sample, the basic code generation model is fine-tuned to obtain the domain code generation model.
[0133] In one embodiment, when the program code is business program code, the business program code is generated by calling a domain code generation model; the processing unit 502 is further configured to obtain business feedback information for the target business after implementing the target business using the generated business program code, the business feedback information being used to indicate whether the target business user is satisfied with the target business implemented using the business program code;
[0134] The processing unit 502 is further configured to treat the business program code as a negative sample when the business feedback information indicates that the user of the business is not satisfied with the target business implemented by the business program code;
[0135] The processing unit 502 is further configured to obtain the reason for obtaining the business feedback information, determine the standard business program code based on the obtained reason, and fine-tune the domain code generation model based on the negative sample and the standard business program code to obtain the trained domain code generation model.
[0136] In this embodiment, after the acquisition unit 501 acquires the descriptive information of the program code to be generated, the processing unit 502 performs feature extraction processing on the acquired descriptive information of the program code to be generated, thereby obtaining the descriptive features of the program code to be generated. Furthermore, through the code generation model of the model layer, it calls the code knowledge base of the data layer to determine the reference coding features that match the descriptive features from the coding features contained in the code knowledge base of the data layer through feature matching. Then, based on the fused features obtained by fusing the descriptive features and the reference coding features, it calls the code generation model of the model layer to generate the program code. This achieves the generation of program code based on fused features obtained from knowledge base technology, and the generation of program code based on feature matching and fusion, which can effectively improve the efficiency of code generation by the processing unit 502. Since the code generation process is implemented through a code generation model, and this code generation model is a model that has completed model training and can provide various generation targets, it also realizes the generation of program code based on natural language, which can effectively lower the threshold for program code generation and effectively improve the efficiency of code generation.
[0137] According to one embodiment of this application, Figure 5The modules in the code generation apparatus shown can be individually or entirely combined into one or more units, or some of these units can be further divided into multiple functionally smaller sub-units to achieve the same operation without affecting the technical effects of the embodiments of this application. The above modules are based on logical functional division. In practical applications, the function of one module can be implemented by multiple units, or the function of multiple modules can be implemented by one unit. In other embodiments of this application, the code generation apparatus may also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented collaboratively by multiple units.
[0138] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0139] According to one embodiment of this application, a computer program capable of executing the steps involved in the corresponding methods shown in the various embodiments of this application can be run on a general-purpose computer device (which may include processing elements and storage elements such as a central processing unit (CPU), random access memory (RAM), and read-only memory (ROM)) to construct a system as described in the embodiments of this application. Figure 5 The code generation apparatus shown above. The computer program described above can be recorded on a computer-readable recording medium, and can be loaded into the computer device described above through the computer-readable recording medium and run therein.
[0140] Please see Figure 6 , Figure 6 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application, which is the aforementioned intelligent agent device. Figure 6As shown, the computer device 1000 may include a processor 1001, a network interface 1004, and a memory 1005. In some embodiments, the computer device 1000 may also include a user interface 1003 and at least one communication bus 1002. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen and a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be high-speed RAM or non-volatile memory, such as at least one disk storage device. Optionally, the memory 1005 may also be at least one storage device located remotely from the aforementioned processor 1001. Figure 6 As shown, the memory 1005, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and a device control application program.
[0141] exist Figure 6 In the computer device 1000 shown, the network interface 1004 provides network communication functionality; the user interface 1003 is mainly used to provide an input interface for the user; and the processor 1001 can be used to call the device control application stored in the memory 1005 to achieve:
[0142] Obtain descriptive information for the program code to be generated; the descriptive information is used to indicate the code functions possessed by the program code;
[0143] The descriptive information is subjected to feature extraction processing to obtain the descriptive features of the program code;
[0144] Reference coding features are matched from the code knowledge base based on the descriptive features, wherein the code knowledge base contains at least one coding feature, and one coding feature corresponds to one code function. The reference coding features include at least one coding feature in the code knowledge base that corresponds to the code function possessed by the program code.
[0145] The descriptive features and the reference coding features are fused to obtain fused features, and the program code is generated based on the fused features.
[0146] In one embodiment, the program code is generated by an intelligent agent device, which includes an application layer, a model layer, and a data layer; the model layer deploys a code generation model, and the data layer stores the code knowledge base.
[0147] The application layer obtains the description information of the program code to be generated and sends the description information to the model layer.
[0148] The model layer receives the description information sent by the application layer, performs feature extraction processing on the description information to obtain the description features, and matches the reference coding features from the code knowledge base stored in the data layer based on the description features.
[0149] The model layer calls the code generation model to generate the program code based on the fusion features of the reference coding features and the description features.
[0150] In one embodiment, the processor 1001 can be used to invoke a device control application stored in the memory 1005, and can also achieve:
[0151] Obtain input text and perform text rewriting processing on the input text to obtain rewritten text; wherein, the text rewriting processing includes one or more of the following: merging the input text with historical text, associating the input text with corresponding business data, and associating the input text with existing code information used to implement the code function;
[0152] Keywords are extracted from the rewritten text and used as descriptive information for the program code to be generated.
[0153] In one embodiment, the description information includes extracted keywords, which include functional keywords indicating the function of the code. The extracted keywords are also used to indicate the generation intent of the program code to be generated. The processor 1001 can be used to call the device control application stored in the memory 1005, and can also implement:
[0154] The extracted keywords are processed for business keyword identification, and when a business keyword is identified from the extracted keywords, the intention to generate the program code to be generated is determined to be the intention to generate business program code.
[0155] If the business keyword is not identified, the intention to generate the program code to be generated is determined to be the intention to generate basic program code.
[0156] In one embodiment, the program code is generated by calling a code generation model deployed in the model layer. The code generation model includes a basic code generation model and a domain code generation model. The basic code generation model is associated with the encoding features corresponding to the basic code statements in the code knowledge base, and the domain code generation model is associated with the encoding features corresponding to the business code statements in the code knowledge base. The processor 1001 can be used to call the device control application stored in the memory 1005, and can also implement:
[0157] When the intention to generate business program code is to generate business program code, a first reference encoding feature is matched from the code knowledge base based on the description feature, and the domain code generation model is invoked to generate business program code based on the fusion feature obtained by the first reference encoding feature and the description feature; wherein, the first reference encoding feature is the encoding feature corresponding to the business code statement used to implement the function of the code;
[0158] When the intention to generate basic program code is to generate basic program code, a second reference encoding feature is matched from the code knowledge base based on the description feature, and the basic code generation model is called to generate basic program code based on the fusion feature obtained by the second reference encoding feature and the description feature; wherein, the second reference encoding feature is the encoding feature corresponding to the basic code statement used to implement the code function.
[0159] In one embodiment, the processor 1001 can be used to invoke a device control application stored in the memory 1005, and can also achieve:
[0160] The similarity between the descriptive features and the coding features contained in the code knowledge base is calculated, and the coding feature with the highest similarity is determined.
[0161] The encoding feature with the highest similarity is used as the reference encoding feature for the reference code statement matched from the code knowledge base to implement the code function.
[0162] In one embodiment, the description information is further used to indicate the generation target of the program code to be output, the generation target including one or more of the following: the target of generating debugged code after debugging the existing program code contained in the description information, the target of generating annotation information of the existing program code after annotating the existing program code, and the target of writing code for the program code function indicated by the description information.
[0163] The code debugging includes one or more of the following: code optimization, code completion, and code error correction; the code annotation includes one or two of the following: code explanation and code comments.
[0164] In one embodiment, the code generation model deployed at the model layer includes a base code generation model, which is obtained after basic training of a base model. The basic training samples used for basic training include: description samples and corresponding code samples, wherein the code samples are standard code to be generated by the base model based on the description samples. The processor 1001 can be used to call the device control application stored in the memory 1005, and can also implement:
[0165] The basic large model is invoked to generate fused feature samples based on the description samples, and initial program code is generated based on the fused feature samples;
[0166] Based on the differences between the initial program code and the code sample, the basic large model is trained to obtain the basic code generation model.
[0167] In one embodiment, the code generation model deployed in the model layer further includes a domain code generation model, which is obtained by fine-tuning the basic code generation model using business samples. The business samples include business description samples and corresponding business code samples. The processor 1001 can be used to call the device control application stored in the memory 1005, and can also implement:
[0168] Obtain the fused business feature sample based on the business description sample, and obtain the business information for implementing the target business from the business code sample;
[0169] The basic code generation model is invoked to generate initial business program code based on the business feature sample and the business information. Based on the difference between the initial business program code and the business code sample, the basic code generation model is fine-tuned to obtain the domain code generation model.
[0170] In one embodiment, when the program code is business program code, the business program code is generated by calling a domain code generation model; the processor 1001 can be used to call the device control application stored in the memory 1005, and can also achieve:
[0171] After implementing the target business using the generated business program code, business feedback information for the target business is obtained. The business feedback information is used to indicate whether the users of the target business are satisfied with the target business implemented using the business program code.
[0172] When the business feedback information indicates that the user of the business is not satisfied with the target business implemented by the business program code, the business program code is used as a negative sample.
[0173] The reasons for obtaining the business feedback information are obtained, and the standard business program code is determined based on the reasons. The domain code generation model is then fine-tuned and trained based on the negative samples and the standard business program code to obtain the trained domain code generation model.
[0174] It should be understood that the computer device 1000 described in the embodiments of this application can execute the code generation method described in the embodiments of this application, and can also execute the code generation method described above. Figure 5 The description of the code generation apparatus in the corresponding embodiments will not be repeated here. Furthermore, the beneficial effects of using the same method will also not be repeated.
[0175] Furthermore, it should be noted that this application also provides a computer-readable storage medium storing a computer program. When a processor executes the computer program, it can perform the code generation methods described in the various embodiments of this application; therefore, they will not be repeated here. Additionally, the beneficial effects of using the same method will also not be repeated. For technical details not disclosed in the embodiments of the computer storage medium involved in this application, please refer to the description of the method embodiments of this application.
[0176] As an example, the aforementioned computer program can be deployed and executed on a single computer device, or deployed and executed on multiple computer devices located in one location, or executed on multiple computer devices distributed across multiple locations and interconnected via a communication network. These multiple computer devices distributed across multiple locations and interconnected via a communication network can form a blockchain network.
[0177] The aforementioned computer-readable storage medium can be an internal storage unit of the computer device, such as a hard drive or memory. It can also be an external storage device, such as a plug-in hard drive, smart media card (SMC), secure digital card (SD) card, or flash card. Furthermore, the computer-readable storage medium can include both internal and external storage units of the computer device. This computer-readable storage medium is used to store the computer program and other programs and data required by the computer device. It can also be used to temporarily store data that has been output or will be output.
[0178] This application provides a computer program product comprising a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to perform the code generation methods described in the embodiments of this application; therefore, these descriptions will not be repeated here. Furthermore, the beneficial effects of using the same method will also not be repeated. For technical details not disclosed in the embodiments of the computer-readable storage medium involved in this application, please refer to the description of the method embodiments of this application.
[0179] The terms "first," "second," etc., in the specification, claims, and drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the term "comprising," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or device that includes a series of steps or units is not limited to the listed steps or modules, but may optionally include steps or modules not listed, or may optionally include other step units inherent to these processes, methods, apparatuses, products, or devices.
[0180] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.
[0181] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A code generation method characterized by, include: Obtain descriptive information for the program code to be generated; The descriptive information is used to indicate the code functions possessed by the program code; The descriptive information is subjected to feature extraction processing to obtain the descriptive features of the program code; Reference coding features are matched from the code knowledge base based on the descriptive features, wherein the code knowledge base contains at least one coding feature, and one coding feature corresponds to one code function. The reference coding features include at least one coding feature in the code knowledge base that corresponds to the code function possessed by the program code. The descriptive features and the reference coding features are fused to obtain fused features, and the program code is generated based on the fused features.
2. The method of claim 1, wherein, The program code is generated by an intelligent agent device, which includes an application layer, a model layer, and a data layer; the model layer deploys a code generation model, and the data layer is used to store the code knowledge base. The application layer obtains the description information of the program code to be generated and sends the description information to the model layer. The model layer receives the description information sent by the application layer, performs feature extraction processing on the description information to obtain the description features, and matches the reference coding features from the code knowledge base stored in the data layer based on the description features. The model layer calls the code generation model to generate the program code based on the fusion features of the reference coding features and the description features.
3. The method of claim 1, wherein, The step of obtaining descriptive information for the program code to be generated includes: Obtain input text and perform text rewriting processing on the input text to obtain rewritten text; wherein, the text rewriting processing includes one or more of the following: merging the input text with historical text, associating the input text with corresponding business data, and associating the input text with existing code information used to implement the code function; Keywords are extracted from the rewritten text and used as descriptive information for the program code to be generated.
4. The method of claim 1, wherein, The descriptive information includes extracted keywords, which include functional keywords indicating the function of the code, wherein the extracted keywords are also used to indicate the generation intent of the program code to be generated; the method further includes: The extracted keywords are processed for business keyword identification, and when a business keyword is identified from the extracted keywords, the intention to generate the program code to be generated is determined to be the intention to generate business program code. If the business keyword is not identified, the intention to generate the program code to be generated is determined to be the intention to generate basic program code.
5. The method of claim 4, wherein, The program code is generated by calling a code generation model deployed in the model layer. The code generation model includes a basic code generation model and a domain code generation model. The basic code generation model is associated with the encoding characteristics corresponding to the basic code statements in the code knowledge base, and the domain code generation model is associated with the encoding characteristics corresponding to the business code statements in the code knowledge base. The method further includes: When the intention to generate business program code is to generate business program code, a first reference encoding feature is matched from the code knowledge base based on the description feature, and the domain code generation model is invoked to generate business program code based on the fusion feature obtained by the first reference encoding feature and the description feature; wherein, the first reference encoding feature is the encoding feature corresponding to the business code statement used to implement the function of the code; When the intention to generate basic program code is to generate basic program code, a second reference encoding feature is matched from the code knowledge base based on the description feature, and the basic code generation model is called to generate basic program code based on the fusion feature obtained by the second reference encoding feature and the description feature; wherein, the second reference encoding feature is the encoding feature corresponding to the basic code statement used to implement the code function.
6. The method as described in claim 1, characterized in that, The process of matching reference coding features from the code knowledge base based on the descriptive features includes: The similarity between the descriptive features and the coding features contained in the code knowledge base is calculated, and the coding feature with the highest similarity is determined. The encoding feature with the highest similarity is used as the reference encoding feature for the reference code statement matched from the code knowledge base to implement the code function.
7. The method as described in claim 1, characterized in that, The description information is also used to indicate the generation target of the program code to be output. The generation target includes one or more of the following: the target of generating debugged code after debugging the existing program code contained in the description information; the target of generating annotation information of the existing program code after annotating the existing program code; and the target of writing code for the program code function indicated by the description information. The code debugging includes one or more of the following: code optimization, code completion, and code error correction; the code annotation includes one or two of the following: code explanation and code comments.
8. The method of claim 2, wherein, The code generation model deployed in the model layer includes a basic code generation model, which is obtained after basic training of a basic large model. The basic training samples used for basic training include: description samples and corresponding code samples, wherein the code samples are standard code that needs to be generated by the basic large model based on the description samples. The basic code generation model is trained in the following ways: The basic large model is invoked to generate fused feature samples based on the description samples, and initial program code is generated based on the fused feature samples; Based on the differences between the initial program code and the code sample, the basic large model is trained to obtain the basic code generation model.
9. The method of claim 2, wherein, The code generation model deployed in the model layer also includes a domain code generation model. The domain code generation model is obtained by fine-tuning the basic code generation model using business samples. The business samples include business description samples and corresponding business code samples. The methods for training the domain code generation model include: Obtain the fused business feature sample based on the business description sample, and obtain the business information for implementing the target business from the business code sample; The basic code generation model is invoked to generate initial business program code based on the business feature sample and the business information. Based on the difference between the initial business program code and the business code sample, the basic code generation model is fine-tuned to obtain the domain code generation model.
10. The method of claim 1 or 9, wherein, When the program code is business program code, the business program code is generated by calling a domain code generation model; the method further includes: After implementing the target business using the generated business program code, business feedback information for the target business is obtained. The business feedback information is used to indicate whether the users of the target business are satisfied with the target business implemented using the business program code. When the business feedback information indicates that the user of the business is not satisfied with the target business implemented by the business program code, the business program code is used as a negative sample. The reasons for obtaining the business feedback information are obtained, and the standard business program code is determined based on the reasons. The domain code generation model is then fine-tuned and trained based on the negative samples and the standard business program code to obtain the trained domain code generation model.
11. A code generation device, characterized in that, include: The acquisition unit is used to acquire descriptive information about the program code to be generated; The descriptive information is used to indicate the code functions possessed by the program code; The processing unit is used to perform feature extraction processing on the description information to obtain the description features of the program code; The processing unit is further configured to match reference coding features from the code knowledge base based on the descriptive features, wherein the code knowledge base contains at least one coding feature, and one coding feature corresponds to one code function; the reference coding feature includes at least one coding feature in the code knowledge base that corresponds to the code function possessed by the program code. The processing unit is further configured to perform feature fusion processing on the descriptive features and the reference coding features to obtain fused features, and generate the program code based on the fused features.
12. A computer device, comprising: The system includes a processor, an input device, an output device, and a memory, which are interconnected. The memory is used to store a computer program, which includes program instructions. The processor is configured to invoke the program instructions to execute the method as described in any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1 to 10.
14. A computer program product, characterised in that, The computer program product includes a computer program, which includes program instructions that, when invoked by a processor, cause the processor to perform the method as described in any one of claims 1 to 10.