Code generation method and device, storage medium and program product

By training the initial AI agent, a target AI agent with code specification information recognition and generation functions is generated, which solves the problem that the new code does not match the existing code programming style and specifications of the project, and improves project stability and code generation efficiency , reduce maintenance costs.

CN119201123APending Publication Date: 2024-12-2758 CHANG LIFE (BEIJING) INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411240258.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-04
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

During the project development process, the new code does not match the programming style and specifications of the project's existing code, resulting in poor project stability and high post-maintenance costs.

Method used

By training the initial AI agent, a target AI agent with code specification information recognition and generation functions is generated, the code specification information in the target project is identified, and code that complies with the specification is generated based on business functions and specification information.

Benefits of technology

It improves the programming style and specifications of the new code and the existing code of the project, improves the project stability, reduces the cost of later maintenance, and frees the hands of developers, and improves code generation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201123A_ABST
    Figure CN119201123A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code generation method and device, a storage medium and a program product, and according to the technical scheme provided by the embodiment of the invention, a target AI agent with a code specification information recognition function and a code generation function is obtained through training according to a sample code and sample code specification information corresponding to the sample code; first code specification information corresponding to existing codes in the target project can be identified by using the target AI agent; furthermore, a target AI agent can be utilized to generate a target code which conforms to the first code specification information and meets the first description information according to the business function for describing the code, the second code specification information and the first code specification information which are contained in the code generation request; therefore, the adaptation degree between the written new code and the programming style and specification of the existing code of the project can be improved, so that the stability of the project is improved, and the later maintenance cost is reduced. In addition, the code generation efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a code generation method, device, storage medium and program product. Background Art

[0002] Code is the basis for instructing computers to perform specific tasks or operations. Whether it is a simple script or a complex system, it relies on code to realize its functions. By writing code, developers can create new applications and services and promote technological progress.

[0003] At present, in the process of project development, developers often write code according to their own coding style and specifications. Although the code can realize the functions required by the business, the written code does not conform to the programming style and specifications of the existing code of the project. In the long run, it may undermine the stability of the project and increase the maintenance cost in the later stage. Summary of the invention

[0004] In view of this, the embodiments of the present invention provide a code generation method, device, storage medium and program product to improve the compatibility of the newly written code with the programming style and specifications of the existing code of the project, thereby improving the stability of the project and reducing the subsequent maintenance costs.

[0005] An embodiment of the present application provides a code generation method, including: pre-training an initial AI agent based on sample codes and sample code specification information corresponding to the sample codes to obtain a target AI agent, the target AI agent is used to identify code specification information and generate code, the code specification information includes writing style and code rules; inputting existing code in a target project into the target AI agent to identify code specification information to obtain first code specification information corresponding to the target project; in response to a code generation request for the target project, obtaining first description information contained in the code generation request, the first description information is used to describe the business function of the code and second code specification information; inputting the first description information and the first code specification information into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information.

[0006] An embodiment of the present application provides an electronic device, including: a memory and a processor; the memory is used to store a computer program; the processor is coupled to the memory and is used to execute the computer program to implement the steps in the above method.

[0007] An embodiment of the present application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor implements the steps in the above method.

[0008] An embodiment of the present application provides a computer program product, which includes a computer program / instructions. When the computer program / instructions are executed by a processor, the processor is enabled to implement the steps in the above method.

[0009] In the technical solution provided by the embodiment of the present application, the initial AI agent is trained according to the sample code and the sample code specification information corresponding to the sample code, and a target AI agent with code specification information recognition function and code generation function is obtained, and the target AI agent can be used to identify the first code specification information corresponding to the existing code in the target project; further, the target AI agent can be used to generate a target code that conforms to the first code specification information and satisfies the first description information according to the business function and the second code specification information and the first code specification information contained in the code generation request for describing the code; thereby, the technical problem that the newly written code is inconsistent with the programming style and specifications of the existing code of the project can be solved, and the compatibility of the newly written code with the programming style and specifications of the existing code of the project can be improved, thereby improving the stability of the project and reducing the subsequent maintenance costs. In addition, based on the recognition of code specification information and code generation by the target AI agent, the hands of developers can be freed and the efficiency of code generation can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0011] Figure 1 A flowchart of a code generation method provided for an exemplary embodiment of the present application;

[0012] Figure 2 A schematic diagram of the working process of an application development method provided by an exemplary embodiment of the present application;

[0013] Figure 3 A schematic diagram of the structure of a code generating device provided by an exemplary embodiment of the present application;

[0014] Figure 4 A schematic structural diagram of an electronic device provided as an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0015] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0016] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "a", "an" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings, and "multiple" generally includes at least two, but does not exclude the situation of including at least one.

[0017] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0018] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to identifying", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is identified" may be interpreted as "when determining" or "in response to determining" or "when identifying (stated condition or event)" or "in response to identifying (stated condition or event)", depending on the context.

[0019] It should be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a product or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such product or system. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the product or system including the elements.

[0020] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0021] In order to solve the problem that the newly written code is inconsistent with the programming style and specifications of the existing code of this project, and the technical problems that the project may be poorly stable and have high maintenance costs in the later period, the technical solution provided by this application can train the initial AI agent according to the sample code and the sample code specification information corresponding to the sample code, and obtain the target AI agent with code specification information recognition function and code generation function, and the target AI agent can be used to identify the first code specification information corresponding to the existing code in the target project; further, the target AI agent can be used to generate the target code that conforms to the first code specification information and satisfies the first description information according to the business function and the second code specification information and the first code specification information contained in the code generation request for describing the code; thus, the technical problem that the newly written code is inconsistent with the programming style and specifications of the existing code of this project can be solved, and the compatibility of the newly written code with the programming style and specifications of the existing code of this project can be improved, thereby improving the stability of the project and reducing the maintenance costs in the later period. In addition, based on the recognition of code specification information and code generation by the target AI agent, the hands of developers can be freed and the efficiency of code generation can be improved.

[0022] Figure 1 The following is a flow chart of a code generation method provided by an exemplary embodiment of the present application. Figure 1 As shown, the method includes:

[0023] 101. Pre-training an initial AI agent based on sample codes and sample code specification information corresponding to the sample codes to obtain a target AI agent, wherein the target AI agent is used to identify code specification information and generate code, wherein the code specification information includes writing style and code rules;

[0024] 102. Input the existing code in the target project into the target AI agent to identify the code specification information, so as to obtain the first code specification information corresponding to the target project;

[0025] 103. In response to a code generation request for a target project, obtain first description information included in the code generation request, where the first description information is used to describe a business function of the code and second code specification information;

[0026] 104. Input the first description information and the first code specification information into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information.

[0027] In this embodiment, in order to obtain an artificial intelligence agent (AI agent) with certain functions, an initial AI agent may be obtained first. For the convenience of description and distinction, the initial AI agent is referred to as the initial AI agent. The initial AI agent may be an intelligent framework or platform without any specific functions, or the initial AI agent may be an intelligent framework or platform with initial specific functions, providing a basis for subsequent development and integration of various functions.

[0028] This embodiment does not limit the implementation method of obtaining the initial AI agent. For example, obtaining the initial AI agent includes: obtaining a pre-generated initial AI agent from an AI agent library; or generating the initial AI agent in real time, etc.

[0029] Optionally, generating an initial AI agent in real time includes: conducting a demand analysis on subsequent applications of the initial AI agent to determine demand information, including but not limited to: subsequent uses, target users and development direction of the initial AI agent; selecting a technology stack and tools that are compatible with the demand information based on the demand information, including but not limited to programming languages, frameworks and databases; building a development environment based on the technology stack and tools, including but not limited to: code repositories, continuous integration / continuous deployment (CI / CD) systems; developing basic functions based on the built development environment, including but not limited to: user interaction, data storage and error handling; further, testing the initial AI agent to ensure the stability and reliability of its basic functions, and writing development documents and user manuals to provide guidance for subsequent development and use.

[0030] This embodiment does not limit the subsequent use of the initial AI agent. For example, the subsequent use may be for image feature recognition, image generation, sound feature recognition, audio and video generation based on text information, and so on. Further, the initial AI agent may be subjected to corresponding functional training based on the subsequent use to obtain an AI agent with corresponding functions. For example, the initial AI agent may be subjected to functional training for image feature recognition to obtain an AI agent with image feature recognition function; or, the initial AI agent may be subjected to functional training for image generation to obtain an AI agent with image generation function; or, the initial AI agent may be subjected to functional training for sound feature recognition to obtain an AI agent with sound feature recognition function; or, the initial AI agent may be subjected to functional training for audio generation based on text information to obtain an AI agent with audio and video generation function based on text information.

[0031] In this embodiment, the subsequent use of the initial AI agent focuses on the identification of code specification information and the generation of code. Among them, the code can be front-end code or back-end code. Front-end code refers to the code that runs on the user's browser or mobile device, which is mainly responsible for the design and implementation of the user interface (UI) and user experience (UX). Back-end code refers to the code that runs on the server, which is mainly responsible for processing business logic, database management, server management, network security, etc.

[0032] Among them, the code standard information includes code writing style and code rules. The code writing style refers to a series of formats and conventions followed when writing code. These styles include but are not limited to: visual style information of UI components: such as font size and color, line thickness and background color of text boxes or lists, etc.; calling methods of tool classes: such as the calling method and time comparison method of time comparison tools, the calling method and string processing method of string processing tools, the calling method and reading and writing method of file reading and writing tools, and the calling method and recording method of logging tools, etc.; working methods of network libraries: such as HTTP requests, WebSocket connections, etc.; indentation: the indentation method of code blocks, such as using spaces or tabs (Tab) and the size of indentation, such as the indentation size can be 2 or 4 spaces; naming conventions: naming rules for variables, functions, classes, etc., such as CamelCase naming method (Came lCase), underscore nomenclature (snake_case), etc.; Space usage: the use of spaces in the code, such as around operators, parameter lists, control statements, etc.; Line length: the maximum number of characters per line of code, which helps to keep the code readable; Comments: how to add comments, including the style and location of comments; Code layout: how the code is organized, such as the layout of functions and classes, and the grouping of related code; Error handling: how errors and exceptions are handled; Code formatting: the formatting rules of the code, such as the use of brackets, line ending symbols, etc.; File organization: the organizational structure of files, such as file naming, directory structure, etc. Coding rules refer to the guiding principles for writing code, including but not limited to: Programming standards: standards for specific programming languages, such as Python's PEP 8, Java's Oracle coding standards, etc.; Code quality: rules to ensure code quality, such as avoiding duplication of code (DRY principle), using appropriate data structures, etc.; Security: writing secure code to avoid security vulnerabilities, such as SQL injection, cross-site scripting (XSS), etc.; Performance: rules to optimize code performance, such as avoiding unnecessary calculations, using efficient algorithms, etc.; Maintainability: rules to improve code maintainability, such as modular design, clear logic, etc.; Testability: writing easy-to-test code, such as using dependency injection, avoiding global state, etc.; Code review: rules and processes for code review to ensure that the code meets the team's standards; Version control: rules for using version control systems (such as Git), such as the format of submission information, branching strategy, etc.; Document writing: rules for writing code documents, such as the format, content and update frequency of documents; Dependency management: rules for managing project dependencies, such as using package managers, updating dependencies regularly, etc. In the following embodiments, the technical solution provided by the present application is described in detail by taking the subsequent use of the initial AI agent for identification of code specification information and generation of code as an example, but this example does not constitute a limitation on the technical solution of the present application.

[0033] Based on this, in order to obtain an AI agent with the function of identifying code specification information and generating code, sample code and sample code specification information corresponding to the sample code can be obtained, and the initial AI agent can be trained in advance according to the sample code and the sample code specification information corresponding to the sample code to obtain an AI agent that can identify code specification information and generate code. For the convenience of description and distinction, the trained AI agent can be referred to as a target AI agent. Alternatively, sample code and sample code specification information corresponding to the sample code can be obtained, and the initial AI agent can be trained in real time according to the sample code and the sample code specification information corresponding to the sample code to obtain a target AI agent. Among them, the sample code and the sample code specification information corresponding to the sample code can be obtained from a sample code library, or can be obtained from existing code in the same project, and this embodiment does not limit this.

[0034] It can be seen from the above embodiments that the initial AI agent may not have any specific functions, or the initial AI agent may also have specific functions, such as the function of identifying code specification information and / or the function of generating codes.

[0035] Based on this, in some embodiments, when the initial AI agent has the function of identifying code specification information, the initial AI agent is pre-trained according to the sample code and the sample code specification information corresponding to the sample code to obtain the target AI agent. The code specification information of the sample code can be identified by the initial AI agent, that is, the code specification information as the training result of the initial AI agent, and the first loss function between the sample code specification information and the code specification information as the training result and the first termination condition are introduced to constrain the parameters of the initial AI agent during the training process, that is, by minimizing the first loss function, the parameters of the initial AI agent can be optimized, so that the code specification information identified by the initial AI agent is closer to the real code specification information, thereby obtaining a high-precision AI agent. Among them, the function value of the first loss function represents the error between the two, that is, the larger the function value, the larger the error between the two, and the smaller the function value, the smaller the error between the two. This embodiment does not limit the type of the first loss function. For example, the first loss function may be a cross entropy loss function, which is mainly used for classification-related problems to measure the difference between the probability distribution predicted by the model and the true probability distribution. In multi-classification tasks, it is usually used together with a softmax activation function to calculate classification errors. In addition, the first loss function may also be a mean square error (MSE) function, a mean absolute error (MAE) function, and a Huber loss function, etc. The first termination condition may be regarded as an error threshold, which is used to constrain the function value of the first loss function. The smaller the value of the first termination condition is, the smaller the error between the sample code specification information and the code specification information as the training result is when the first loss function satisfies the first termination condition, which means that the accuracy of the trained AI agent is higher.

[0036] Specifically, in the case where the initial AI agent has the function of identifying code specification information, the initial AI agent is trained in advance according to the sample code and the sample code specification information corresponding to the sample code to obtain the target AI agent, including: inputting the sample code into the initial AI agent to identify the code specification information to obtain the code specification information as the training result; calculating the first loss function between the sample code specification information and the code specification information as the training result, and obtaining an intermediate AI agent when the first loss function satisfies the first termination condition; inputting the sample code specification information and the sample description information corresponding to the sample code into the intermediate AI agent for code generation to obtain the code as the training result; calculating the second loss function between the sample code and the code as the training result, and obtaining the target AI agent when the second loss function satisfies the second termination condition.

[0037] Optionally, the above-mentioned input of the sample code into the initial AI agent for identification of code specification information to obtain code specification information as a training result includes: performing semantic analysis on the sample code to obtain a code semantic feature vector set; performing inverse operation processing on the code semantic feature vector set to obtain text information corresponding to the code semantic feature vector; and using the text information as the code specification information of the training result. Among them, the inverse operation refers to reconstructing the original text based on the code semantic feature vector. This embodiment does not limit the implementation method of performing inverse operation processing on the code semantic feature vector set. For example, if the code semantic feature vector is generated based on a vocabulary, the original sentence can be reconstructed by looking up the words corresponding to each feature vector in the vocabulary. Alternatively, the feature vectors can be grouped into specific topics or categories by clustering or classification, and then a representative text description or example is provided for each category. Alternatively, the feature vector can be converted back to text by a decoder, and so on.

[0038] It should be noted that for tools with the same function, there may be different display styles or implementation methods. In other words, the code for the same function may have different corresponding code specification information. Taking the text box in the UI component as an example, the visual style information of the same type of text box in the same project may be different. For example, if the line color of the same type of text box in the same project includes yellow, red and black, then you need to choose one color as the standard information of the text box. Based on this, the above-mentioned input of the sample code into the initial AI agent for identification of code specification information to obtain code specification information as a training result also includes: performing semantic analysis on the sample code to obtain a code semantic feature vector set, the code semantic feature vector set may contain the same code semantic feature vectors, the same code semantic feature vectors represent the same type of tools and correspond to the same specification information; classifying each code semantic feature vector in the code semantic feature vector set, and classifying the code semantic feature vectors of the sample code corresponding to the tools of the same type and with the same specification information into the same group; from at least one group of code semantic feature vectors corresponding to the same type of tools, selecting a group containing code semantic feature vectors that meets a threshold value as a target code semantic feature vector set for each sample code; performing inverse operation processing on the target code semantic feature vector set of each sample code to obtain text information corresponding to the target code semantic feature vector set of each sample code; and using each text information as the code specification information of the training result.

[0039] In this embodiment, both the front-end code and the back-end code contain different categories of code, and different categories of code correspond to different tools, and different categories of code correspond to different requirements of code specification description information. Taking the front-end code as an example, the different tools corresponding to different categories of code include but are not limited to: UI components (such as buttons, text boxes, lists), other tool classes (such as time comparison tools, string processing tools, logging tools) and network libraries (such as HTTP requests, WebSocket connections). Based on this, in order to improve the accuracy of the AI ​​agent, when calculating the first loss function, the loss functions between the same type of code specification description information can be calculated separately, and then the loss functions between the various types of code specification description information are summed, and the sum of the functions is used as the first loss function. Specifically, a first loss function is calculated between sample code specification information and code specification information as a training result, and when the first loss function satisfies a first termination condition, an intermediate AI agent is obtained, including: determining sample code specification information corresponding to various types of tool codes, and determining code specification description information as a training result corresponding to various types of tool codes; performing semantic analysis on sample code specification description information corresponding to various types of tool codes to obtain a first code specification description information semantic feature vector, and performing semantic analysis on code specification information as a training result corresponding to various types of tool codes to obtain a second specification information speech feature vector; calculating the vector distance between the first specification description information semantic feature vector corresponding to each type of tool code and the second specification description information semantic feature vector corresponding to the type of tool code; using the vector distance as the loss function between the type of code specification description information; calculating the sum of the vector distances corresponding to various types of tool codes, and using the sum of the vector distances as the first loss function; and obtaining an intermediate AI agent when the first loss function is less than the first termination condition.

[0040] Optionally, the intermediate AI agent also has the functions of code query and alarm. After obtaining the intermediate AI agent, the sample code specification information and the sample description information corresponding to the sample code are input into the intermediate AI agent for code generation to obtain the code as the training result, including: traversing the existing code of the target project; judging whether there is a code corresponding to the first description information in the existing code; if not, generating the code as the training result according to the sample code information and the sample description information corresponding to the sample code; if so, outputting an alarm message, and using the code corresponding to the first description information in the existing code as the code of the training result, the alarm message is used to prompt that the code corresponding to the first description information already exists in the existing code of the target project, and there is no need to regenerate the code. In the case where there is a code corresponding to the first description information in the existing code, there is no need to regenerate the code, and in the case where there is no code corresponding to the first description information in the existing code, the code needs to be generated, which can not only improve the efficiency of code generation, but also reduce development costs.

[0041] Optionally, in order to further improve the accuracy of the AI ​​agent, after obtaining the code as a training result, the second loss function between the sample code and the code as a training result can also be calculated, and the target AI agent is obtained when the second loss function satisfies the second termination condition. Specifically, the second loss function between the sample code and the code as a training result is calculated, and the target AI agent is obtained when the second loss function satisfies the second termination condition, including: determining the sample codes corresponding to various types of tools and the codes as training results corresponding to various types of tools; performing semantic analysis on the sample generations corresponding to various types of tool codes to obtain a first code semantic feature vector, and performing semantic analysis on the codes as training results corresponding to various types of tool codes to obtain a second code semantic feature vector; calculating the vector distance between the first code semantic feature vector corresponding to each type of tool code and the second code semantic feature vector corresponding to the type of tool code; using the vector distance as the loss function between various types of codes; calculating the sum of the vector distances corresponding to various types of tool codes, and using the sum of the vector distances as the second loss function; and obtaining the target AI agent when the second loss function is less than the second termination condition.

[0042] In other embodiments, when the initial AI agent does not have any specific functions, the initial AI agent is pre-trained based on the sample code and the sample code specification information corresponding to the sample code to obtain a target AI agent, including: training the initial AI agent to perform the functions of identifying code specification information and generating code based on the correspondence between the sample code and the sample code specification information of the sample code, that is, training the initial AI agent to identify the corresponding code specification information based on the code, and training the initial AI agent to generate the corresponding code based on the sample code specification information, so as to obtain the target AI agent, which is used to identify the code specification information and generate the code.

[0043] Furthermore, in response to a code generation request for the target project, first description information contained in the code generation request is obtained, the first description information being used to describe a business function of the code and second code specification information, wherein the business function represents a code implementation logic.

[0044] Furthermore, the first description information and the first code specification information may be input into the target AI agent for code generation to obtain a target code that complies with the first code specification information and satisfies the first description information.

[0045] Optionally, the first description information and the first code specification information are input into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information, including: inputting the first description information and the first code specification information into the target AI agent; writing an initial code according to the business function in the first description information and the second code specification information; and correcting the initial code according to the first code specification information to obtain a target code.

[0046] Optionally, inputting the first description information and the first code specification information into the target AI agent includes: inputting the first description information, the existing code and the first code specification information into the target AI agent. Correspondingly, before writing the initial code according to the business function in the first description information and the second code specification information, it also includes: matching the first description information in the second description information corresponding to the existing code in sequence; if the second description information contains target description information that is compatible with the first description information, using the existing code corresponding to the target description information as the target code; if the second description information does not contain target description information that is compatible with the first description information, executing the initial code writing and subsequent operations according to the business function in the first description information and the second code specification information.

[0047] Optionally, the first description information is matched in turn with the second description information corresponding to the existing code, including: parsing the existing code to obtain the second description information corresponding to the existing code; calculating the similarity between the first description information and the second description information corresponding to the existing code in turn; judging whether there is description information in the second description information whose similarity with the first description information is greater than a set similarity threshold, and if so, taking the description information whose similarity with the first description information is greater than the set similarity threshold as the target description information.

[0048] Optionally, the initial code is corrected according to the first code specification information to obtain the target code, including: determining the open source code library to which the existing code belongs, the open source code library having third code specification information; judging the similarity between the first code specification information and the third code specification information; when the similarity is greater than a second similarity threshold, correcting the initial code according to the first code specification information to obtain the target code; when the similarity is less than the second similarity threshold, correcting the initial code according to the third code specification information to obtain the target code.

[0049] The technical solutions provided by the above-mentioned embodiments of the present application train the initial AI agent according to the sample code and the sample code specification information corresponding to the sample code, and obtain the target AI agent with the code specification information recognition function and the code generation function, and the target AI agent can be used to identify the first code specification information corresponding to the existing code in the target project; further, the target AI agent can be used to generate the target code that conforms to the first code specification information and satisfies the first description information according to the business function and the second code specification information and the first code specification information contained in the code generation request for describing the code; thereby, the technical problem that the newly written code does not conform to the programming style and specifications of the existing code of the project can be solved, and the compatibility of the newly written code with the programming style and specifications of the existing code of the project can be improved, thereby improving the stability of the project and reducing the maintenance cost in the later stage. In addition, based on the recognition of code specification information and the generation of code by the target AI agent, the hands of developers can be freed and the efficiency of code generation can be improved.

[0050] The above embodiments mainly describe how to accurately generate other codes in the same project based on the code specification information of the existing code in the target project. The existing code or other codes in the same project generated according to the above embodiments of the present application are used to implement a certain function. For the convenience of description, the function is referred to as the target function. Among them, the target function may include any one of an order processing function, a map positioning function, an information query function, and the like. The following embodiments mainly describe how to encapsulate the code corresponding to the target function into a reusable function module in the development process of different projects. The reusable function module can be called a general function module. Then, this general function module can be configured into different applications so that multiple applications have the target function.

[0051] In practice, since the general function module itself needs to be updated, and multiple applications and the general function module may have different interface layouts, title texts, and theme styles, the process of configuring the general function module to different applications is often complicated, which affects the configuration efficiency of the general function module. In order to improve the above problems, the application development method provided by the following embodiments of the present invention can be used.

[0052] First, a description file is obtained, which describes the difference information between multiple preset implementation methods and a common implementation method of the target function; further, for any one of the multiple preset implementation methods, a difference function code corresponding to the difference object is generated according to the description file; further, the difference function code is stored in a folder corresponding to any one of the preset implementation methods in the common function module; further, the difference function code corresponding to each of the different preset implementation methods is added to the common function module to obtain a target function module; further, in response to a test of an application of the target type, the difference function code in the folder corresponding to the target preset implementation method in the target function module is called according to the correspondence between the implementation method and the folder to determine whether the application has been developed.

[0053] In practice, when multiple applications want to achieve the same target function, one application can correspond to a preset implementation method of the target function. Among them, any preset implementation method includes at least one difference object. The difference object specifically includes at least the implementation logic and / or display style of the target function. Among them, the implementation logic of the target function includes the record data of the user's operation behavior when using the target function, such as the user clicking any button at any time point, etc. The display style includes at least one of the above-mentioned objects such as interface layout, title text, theme style, etc.

[0054] Based on this difference object, developers can write difference information corresponding to the difference objects in multiple preset implementations and the general implementation. For any of the multiple preset implementations, the development platform can obtain a description file describing the difference information, and generate a difference function code corresponding to the difference object according to the description file. The difference function code can describe the difference implementation process of the difference object.

[0055] For example, assuming that the preset implementation includes setting the theme style to blue, and the general implementation includes setting the theme style to pink, then the difference object between the preset implementation and the general implementation is the theme style, and correspondingly, the difference function code describes the difference implementation process of the theme style, that is, the implementation process of setting the theme style to blue.

[0056] Then, the development platform can obtain the difference function codes corresponding to each of the multiple preset implementations, and store the difference function codes in the general function module. The general function module includes multiple folders corresponding to the multiple preset implementations. That is, the difference function code corresponding to any preset implementation is stored in the folder corresponding to any preset implementation in the general function module.

[0057] Afterwards, the development platform can add the difference function codes corresponding to the different preset implementation methods to the general function module to obtain the target function module. Among them, the target function module can be understood as the encapsulation result of the code corresponding to the target function, which can be used to support different applications to achieve the same target function.

[0058] After obtaining the target functional module, the development platform can encapsulate the code corresponding to the target functional module and the code corresponding to other functional modules corresponding to the target type to obtain the target type application. Among them, other functional modules can be understood as the encapsulation result of the code corresponding to other functions implemented by this application. Optionally, other functional modules may include user identity management functional modules, interactive functional modules, etc.

[0059] After obtaining the target type of application, the development platform can further test the target type of application to determine whether the application is developed. Specifically, in response to the test of the target type of application, the development platform can call the difference function code in the folder corresponding to the target preset implementation method in the target function module according to the correspondence between the implementation method and the folder, and execute the difference function code to determine the running status of the application.

[0060] If the running state of the application is determined to be not running normally, it can be determined that the application has not been developed, that is, the application cannot provide the target function. If the running state of the application is determined to be running normally, it can be determined that the application has been developed, that is, the application can also provide the target function.

[0061] In this embodiment, for any one of the multiple preset implementations, a difference function code corresponding to the difference object is generated according to the obtained description file. Then, the difference function code is stored in a folder corresponding to any preset implementation in the general function module, and the difference function codes corresponding to different preset implementations are added to the general function module to obtain the target function module. Finally, in response to the test of the target type of application, according to the correspondence between the implementation and the folder, the difference function code in the folder corresponding to the target preset implementation in the target function module is called to determine whether the application is developed.

[0062] It can be seen that the difference function codes corresponding to different preset implementation methods generated according to the description file are all added to the general function module to obtain the target function module. Since different preset implementation methods correspond to different folders, and the folder corresponding to any preset implementation method often includes difference function codes corresponding to multiple difference objects, therefore, in the test phase of application development, the scheme can directly call the difference function code in the folder corresponding to the target preset implementation method in the target function module according to the correspondence between the implementation method and the folder, that is, the difference function code corresponding to multiple difference objects in a folder can be obtained through one call, eliminating the process of searching for the difference function codes corresponding to multiple difference objects in turn according to the number of difference objects, thereby improving the configuration efficiency of the function module and further improving the development efficiency of the application.

[0063] In practice, in order to improve the readability of the code, the development platform can encapsulate the difference information between the multiple preset implementations of the target function and the general implementation into the definition information of the interface or abstract class. Then the development platform can generate the difference function code corresponding to the interface or abstract class according to the definition information of the interface or abstract class. Among them, the difference function code can make the target function have any one of the preset implementation methods.

[0064] For example, assuming that the difference information includes the title text colors of the preset implementation and the general implementation, a set of methods related to the title text colors can be defined using an interface, such as red for the first-level title and yellow for the second-level title. That is, the title text colors of different levels can be obtained through this interface, but the specific implementation methods of the title text colors of different levels are unknown.

[0065] Optionally, an abstract class including at least one abstract method may be used to define the title text color. Different abstract methods may represent different levels of title text colors. In addition, at least one subclass may be defined in the abstract class, and the at least one subclass may be used to implement at least one abstract method in the abstract class to provide specific colors corresponding to title texts at each level.

[0066] In this embodiment, since the definition information of the interface or abstract class is more readable, by encapsulating the difference information between the multiple preset implementations of the target function and the general implementation into the definition information of the interface or abstract class, the readability of the code corresponding to the difference information can be improved, that is, the readability of the description file can be improved. Furthermore, the readability of the generated difference function code can also be improved.

[0067] In order to better manage the difference function codes in the folders corresponding to different preset implementations in the general function module, the development platform can optionally first obtain the folders corresponding to the multiple preset implementations in the general function module. Among them, one preset implementation corresponds to one folder, one folder includes at least one difference object, one difference object can correspond to a segment of difference function code, that is, one folder can include multiple segments of difference function code.

[0068] Since the difference function codes corresponding to the same difference object are essentially the same, that is, they are all used to describe the difference implementation process of the same difference object, the development platform can unify the identification of the difference function codes corresponding to the same difference object in different folders to obtain updated folders.

[0069] After obtaining the updated folder with a unified identifier, the development platform can respond to the test of the target type of application and call the difference function code in the folder corresponding to the target preset implementation method in the target function module according to the correspondence between the implementation method and the updated folder to determine whether the application is developed. The calling process of the difference function code can refer to the relevant description of responding to the test of the target type of application and calling the difference function code in the folder corresponding to the target preset implementation method in the target function module according to the correspondence between the implementation method and the folder in the above embodiment, which will not be repeated here.

[0070] The difference function code can be understood as the code for realizing the target function in the implementation class corresponding to any preset implementation method. For the identification of the unified difference function code, specifically, the development platform can add the same suffix to the name of the implementation class corresponding to the difference function code corresponding to the same difference object in different folders to obtain a unified identification.

[0071] In the present embodiment, by unifying the identifiers of the difference function codes corresponding to the same difference objects in the folders corresponding to different preset implementation methods, it can be ensured that different difference function codes corresponding to the same difference objects have the same identifier, thereby avoiding the situation where essentially the same difference objects correspond to multiple identifiers, that is, reducing the number of identifiers managed by the development platform, thereby being able to better manage the difference function codes in the folders corresponding to different preset implementation methods in the common function module, thereby improving the development efficiency of the application.

[0072] In addition, compared to the solution in which the difference function codes are generated by multiple applications respectively, the present embodiment innovatively proposes that the development platform independently generates the difference function codes corresponding to multiple preset implementation methods, that is, there is no need for the development platform and the developers of each of the multiple applications to communicate on the implementation process of the target function. Therefore, it can avoid that the developers of each of the multiple applications generate erroneous codes due to their lack of understanding of the workflow or data processing logic of the common function module, thereby improving the stability of the target type of application.

[0073] And when the difference function code is generated by multiple applications, since different applications have different code writing specifications, the identifiers corresponding to different difference function codes corresponding to the same difference object are also different. In this case, it is necessary to distinguish the identifiers when calling the difference function code, such as using different configuration classes for different applications, so that the configuration class manages the difference function codes corresponding to each difference function code. It can be seen that even if it corresponds to the same difference object, multiple difference function codes need to be distinguished by identifiers, which will obviously increase the workload of application development and reduce the efficiency of application development.

[0074] For ease of understanding, the following Figure 2 The specific application scenario of configuring the order processing function module into application A and application B is used to exemplify the specific implementation process of the application development method provided in the above embodiments. Among them, the order processing function module is the common function module mentioned in the above embodiments. Application A and application B may include a user identity management function module, that is, other function modules mentioned in the above embodiments.

[0075] Specifically, when application A and application B want to implement an order processing function, application A can correspond to a first preset implementation method of the order processing function, and application B can correspond to a second preset implementation method of the order processing function. The difference object included in the first preset implementation method and the second preset implementation method can be the title text color.

[0076] Based on the title text color, the developer can write the definition information of the interface or abstract class corresponding to the title text color. The development platform can generate the first difference function code and the second difference function code corresponding to the interface or abstract class according to the definition information. The first difference function code can make the order processing function have the first preset implementation mode, and the second difference function code can make the order processing function have the second preset implementation mode.

[0077] Then, the development platform may store the first difference function code in a first folder in the order processing function module corresponding to the first preset implementation method, and store the second difference function code in a second folder in the order processing function module corresponding to the second preset implementation method.

[0078] In order to better manage the difference function codes, the development platform can also unify the identification of the first difference function code corresponding to the title text color in the first folder and the identification of the second difference function code corresponding to the title text color in the second folder to obtain the updated first folder and the updated second folder.

[0079] The development platform can also add the first difference function code and the second difference function code to the order processing function module to obtain a new order processing function module, wherein the new order processing function module is the target function module mentioned in the above embodiments.

[0080] Afterwards, in response to the test of the target type of application, the development platform may call the first difference function code in the updated first folder corresponding to the first preset implementation in the new order processing function module according to the correspondence between the implementation and the folder, and execute the first difference function code to determine the running state of the application A. The target type of application includes a new order processing module and a user identity management module.

[0081] If it is determined that the running state of application A is not running normally, it can be determined that application A has not been developed, that is, application A cannot provide the order processing function. If it is determined that the running state of application A is running normally, it can be determined that application A has been developed, that is, application A can also provide the order processing function.

[0082] Similar to the process of determining whether application A has been developed, the development platform can also determine whether application B has been developed, which will not be described in detail here.

[0083] Figure 3 The following is a schematic diagram of a code generation device provided by an exemplary embodiment of the present application. Figure 3 As shown, the device comprises:

[0084] A training module 31 is used to train the initial AI agent in advance according to the sample code and the sample code specification information corresponding to the sample code to obtain a target AI agent, wherein the target AI agent is used to identify the code specification information and generate the code, wherein the code specification information includes the writing style and the code rules;

[0085] The recognition module 32 is used to input the existing code in the target project into the target AI agent to recognize the code standard information, so as to obtain the first code standard information corresponding to the target project;

[0086] An acquisition module 33 is used to respond to a code generation request for a target project and acquire first description information included in the code generation request, where the first description information is used to describe a business function of the code and second code specification information;

[0087] The generation module 34 is used to input the first description information and the first code specification information into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information.

[0088] In some embodiments, when the training module trains the initial AI agent in advance according to the sample code and the sample code specification information corresponding to the sample code to obtain the target AI agent, the training module is specifically used to: input the sample code into the initial AI agent to identify the code specification information to obtain the code specification information as the training result; calculate the first loss function between the sample code specification information and the code specification information as the training result, and obtain the intermediate AI agent when the first loss function satisfies the first termination condition; input the sample code specification information and the sample description information corresponding to the sample code into the intermediate AI agent for code generation to obtain the code as the training result; calculate the second loss function between the sample code and the code as the training result, and obtain the target AI agent when the second loss function satisfies the second termination condition.

[0089] In some embodiments, when the generation module inputs the first description information and the first code specification information into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information, it is specifically used to: input the first description information and the first code specification information into the target AI agent; write the initial code according to the business function in the first description information and the second code specification information; and correct the initial code according to the first code specification information to obtain the target code.

[0090] Optionally, when the generation module inputs the first description information and the first code specification information into the target AI agent, it is specifically used to: input the first description information, the existing code and the first code specification information into the target AI agent.

[0091] Correspondingly, before the generation module writes the initial code according to the business function in the first description information and the second code specification information, it is also used to: match the first description information in the second description information corresponding to the existing code in sequence; if there is target description information adapted to the first description information in the second description information, use the existing code corresponding to the target description information as the target code; if there is no target description information adapted to the first description information in the second description information, execute the initial code and subsequent operations based on the business function in the first description information and the second code specification information.

[0092] Optionally, when the generation module matches the first description information in the second description information corresponding to the existing code in sequence, it is specifically used to: parse the existing code to obtain the second description information corresponding to the existing code; calculate the similarity between the first description information and the second description information corresponding to the existing code in sequence; determine whether there is description information in the second description information whose similarity with the first description information is greater than a set similarity threshold, and if so, use the description information whose similarity with the first description information is greater than the set similarity threshold as the target description information.

[0093] Optionally, when the generation module corrects the initial code according to the first code specification information to obtain the target code, it is specifically used to: determine the open source code library to which the existing code belongs, and the open source code library has third code specification information; judge the similarity between the first code specification information and the third code specification information; when the similarity is greater than the second similarity threshold, correct the initial code according to the first code specification information to obtain the target code.

[0094] Further optionally, the generating module is further configured to, when the similarity is less than a second similarity threshold, modify the initial code according to the third code specification information to obtain the target code.

[0095] The detailed implementation and beneficial effects of each module provided in the embodiments of the present application have been described in detail in the aforementioned embodiments and will not be elaborated here.

[0096] Figure 4 The schematic diagram of the structure of the electronic device provided by the exemplary embodiment of the present application. Figure 4 As shown, the electronic device includes: a memory 40a and a processor 40b; the memory 40a is used to store a computer program; the processor 40b is coupled to the memory 40a and is used to execute the computer program to implement the following steps:

[0097] An initial AI agent is trained in advance according to sample codes and sample code specification information corresponding to the sample codes to obtain a target AI agent, wherein the target AI agent is used to identify code specification information and generate code, wherein the code specification information includes writing style and code rules; the existing code in the target project is input into the target AI agent to identify the code specification information to obtain first code specification information corresponding to the target project; in response to a code generation request for the target project, first description information included in the code generation request is obtained, wherein the first description information is used to describe the business function of the code and second code specification information; the first description information and the first code specification information are input into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information.

[0098] In some embodiments, when the processor 40b trains the initial AI agent in advance according to the sample code and the sample code specification information corresponding to the sample code to obtain the target AI agent, it is specifically used to: input the sample code into the initial AI agent to identify the code specification information to obtain the code specification information as the training result; calculate the first loss function between the sample code specification information and the code specification information as the training result, and obtain the intermediate AI agent when the first loss function satisfies the first termination condition; input the sample code specification information and the sample description information corresponding to the sample code into the intermediate AI agent for code generation to obtain the code as the training result; calculate the second loss function between the sample code and the code as the training result, and obtain the target AI agent when the second loss function satisfies the second termination condition.

[0099] In some embodiments, when the processor 40b inputs the first description information and the first code specification information into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information, it is specifically used to: input the first description information and the first code specification information into the target AI agent; write the initial code according to the business function in the first description information and the second code specification information; and correct the initial code according to the first code specification information to obtain the target code.

[0100] Optionally, when the processor 40b inputs the first description information and the first code specification information into the target AI agent, it is specifically used to: input the first description information, the existing code and the first code specification information into the target AI agent.

[0101] Correspondingly, before writing the initial code according to the business function in the first description information and the second code specification information, the processor 40b is also used to: match the first description information in the second description information corresponding to the existing code in sequence; if there is target description information adapted to the first description information in the second description information, use the existing code corresponding to the target description information as the target code; if there is no target description information adapted to the first description information in the second description information, execute the initial code writing and subsequent operations according to the business function in the first description information and the second code specification information.

[0102] Optionally, the first description information is matched in turn with the second description information corresponding to the existing code, including: parsing the existing code to obtain the second description information corresponding to the existing code; calculating the similarity between the first description information and the second description information corresponding to the existing code in turn; judging whether there is description information in the second description information whose similarity with the first description information is greater than a set similarity threshold, and if so, taking the description information whose similarity with the first description information is greater than the set similarity threshold as the target description information.

[0103] Optionally, the initial code is modified according to the first code specification information to obtain the target code, including: determining an open source code library to which the existing code belongs, the open source code library having third code specification information; judging the similarity between the first code specification information and the third code specification information; when the similarity is greater than a second similarity threshold, modifying the initial code according to the first code specification information to obtain the target code.

[0104] Further optionally, the processor 40b is further configured to, when the similarity is less than a second similarity threshold, modify the initial code according to the third code specification information to obtain the target code.

[0105] Furthermore, if Figure 4 As shown, the electronic device also includes: a communication component 40c, a display 40d, a power component 40e, an audio component 40f and other components. Figure 4 Only some components are shown schematically, which does not mean that the electronic device only includes Figure 4 Components shown.

[0106] The detailed implementation and beneficial effects of each module provided in the embodiments of the present application have been described in detail in the aforementioned embodiments and will not be elaborated here.

[0107] The exemplary embodiments of the present application also provide a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor is caused to implement the steps in the above method.

[0108] The exemplary embodiments of the present application also provide a computer program product, which includes a computer program / instruction. When the computer program / instruction is executed by a processor, the processor is enabled to implement the steps in the above method.

[0109] The above-mentioned memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.

[0110] The above-mentioned communication component is configured to facilitate wired or wireless communication between the device where the communication component is located and other devices. The device where the communication component is located can access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G / LTE, 5G and other mobile communication networks, or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (Ultra Wide Band, UWB) technology, Bluetooth (BlueTooth, BT) technology and other technologies to achieve.

[0111] The above-mentioned display includes a screen, and the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.

[0112] The power supply assembly provides power to various components of the device where the power supply assembly is located. The power supply assembly may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device where the power supply assembly is located.

[0113] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, compact disk read-only memory (Compact Disk Read-Only Memory, CD-ROM), optical storage, etc.) that contain computer-usable program code.

[0114] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0115] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0116] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0117] In a typical configuration, a computing device includes one or more processors (Central Processing Unit, CPU), input / output interface, network interface and memory.

[0118] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash memory (flashRAM). The memory is an example of a computer-readable medium.

[0119] Computer-readable media include permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.

[0120] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0121] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A code generation method, characterized in that: include: Pre-training an initial AI agent based on sample codes and sample code specification information corresponding to the sample codes to obtain a target AI agent, wherein the target AI agent is used to identify code specification information and generate code, wherein the code specification information includes writing style and code rules; Inputting the existing code in the target project into the target AI agent to identify the code standard information, so as to obtain the first code standard information corresponding to the target project; In response to a code generation request for the target project, obtaining first description information included in the code generation request, where the first description information is used to describe a business function of the code and second code specification information; The first description information and the first code specification information are input into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information.

2. The method according to claim 1, characterized in that Inputting the first description information and the first code specification information into the target AI agent for code generation to obtain a target code that conforms to the first code specification information and satisfies the first description information, including: Inputting the first description information and the first code specification information into the target AI agent; Write an initial code according to the business function in the first description information and the second code specification information; The initial code is modified according to the first code specification information to obtain the target code.

3. The method according to claim 2, characterized in that Before writing the initial code according to the business function in the first description information and the second code specification information, the method further includes: Matching the first description information in sequence with the second description information corresponding to the existing codes; If the second description information contains target description information that is adapted to the first description information, using an existing code corresponding to the target description information as the target code; If the second description information does not contain target description information that is adapted to the first description information, the initial code and subsequent operations are written according to the business function in the first description information and the second code specification information.

4. The method according to claim 3, characterized in that Matching the first description information in sequence with the second description information corresponding to the existing code includes: Parsing the existing code to obtain second description information corresponding to the existing code; sequentially calculating the similarity between the first description information and the second description information corresponding to the existing code; Determine whether there is description information in the second description information whose similarity with the first description information is greater than a set similarity threshold. If so, use the description information whose similarity with the first description information is greater than the set similarity threshold as the target description information.

5. The method according to claim 2, characterized in that: Correcting the initial code according to the first code specification information to obtain the target code includes: Determining an open source code library to which the existing code belongs, the open source code library having third code specification information; Determining the similarity between the first code standard information and the third code standard information; When the similarity is greater than a second similarity threshold, the initial code is modified according to the first code standard information to obtain the target code.

6. The method according to claim 5, characterized in that Also includes: When the similarity is less than the second similarity threshold, the initial code is modified according to the third code standard information to obtain the target code.

7. The method according to any one of claims 1 to 6, characterized in that: The initial AI agent is trained in advance according to the sample code and the sample code specification information corresponding to the sample code to obtain the target AI agent, including: Inputting the sample code into the initial AI agent to identify the code standard information to obtain the code standard information as a training result; Calculate a first loss function between the sample code specification information and the code specification information as the training result, and obtain an intermediate AI agent when the first loss function satisfies a first termination condition; Inputting the sample code specification information and the sample description information corresponding to the sample code into the intermediate AI agent for code generation to obtain a code as a training result; A second loss function is calculated between the sample code and the code as a training result, and when the second loss function satisfies a second termination condition, the target AI agent is obtained.

8. An electronic device, characterized in that: include: Memory and processor; The memory is used to store a computer program; the processor is coupled to the memory and is used to execute the computer program to implement the steps in the method according to any one of claims 1 to 7.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the processor is caused to implement the steps in the method according to any one of claims 1 to 7.

10. A computer program product, characterized in that The computer program product comprises a computer program / instruction, which, when executed by a processor, enables the processor to implement the steps of any one of the methods of claims 1 to 7.

Citation Information

Cited By

  • Code generation method and device and computing equipment cluster

    CN119396464A