Code generation method, apparatus, and computer-readable storage medium

By decomposing the problems of user input on the cloud computing platform, searching the code knowledge base and using artificial intelligence technology to generate code, the problem of inefficient code writing in the existing technology is solved, and high accuracy and code generation meets user needs is achieved.

WO2025086764A1PCT designated stage expired Publication Date: 2025-05-01HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD

Patent Information

Application Number
PCT/CN2024/108284
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-11-15
Filing Date
2024-07-29
Publication Date
2025-05-01

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively improve the efficiency of code writing and program development, resulting in inefficiency among developers when writing code manually.

Method used

Provide a code generation method and device, which receives code generation requests sent by the terminal device through a cloud computing platform, decomposes problems entered by users, retrieves code knowledge base, generates target code, and sends them back to the terminal device. This method uses code generation models trained by artificial intelligence technology to generate code that is highly accurate and meets user needs.

Benefits of technology

It has achieved the ability to help developers improve code writing efficiency and help enterprises improve program development efficiency. The generated code has high accuracy and meets user needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024108284_01052025_PF_FP_ABST
    Figure CN2024108284_01052025_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application are a code generation method, an apparatus, and a computer-readable storage medium, which can be applied to a code generation system comprising a cloud computing platform and a terminal device. The method comprises: after receiving, sent by the terminal device, a code generation request carrying a first question, the cloud computing platform decomposing the first question to obtain solution steps of the first question; then on the basis of each step among the solution steps of the first question, searching a code knowledge base for code knowledge matched with each step; and finally, inputting into a code generation model each step among the solution steps of the first question and the code knowledge matched with each step, so as to obtain code generated by the code generation model, and then sending the code to the terminal device for the terminal device to present the code. By means of the method, users only need to input code-related questions into terminal devices to view code automatically generated by systems according to the questions input by the users, thereby helping to improve code writing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Code generation method, device and computer-readable storage medium

[0001] This application claims priority to the Chinese patent application with application number 202311377535.6 filed with the State Intellectual Property Office of China on October 23, 2023, and priority to the Chinese patent application with invention name “Code generation method, device and computer-readable storage medium”, as well as priority to the Chinese patent application with application number 202311535400.8 filed with the State Intellectual Property Office of China on November 15, 2023, and priority to the Chinese patent application with invention name “Code generation method, device and computer-readable storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of computer technology, and in particular to a code generation method, device, and computer-readable storage medium. Background Art

[0003] With the development of computer technology and the increasingly fast pace of people's work and life, enterprise developers' manual coding on personal computers (PCs), desktops, laptops and other terminal devices using software with code writing functions (such as integrated development environments (IDEs)) can no longer meet the pursuit of high efficiency by enterprises and developers.

[0004] Therefore, there is an urgent need to provide a method to help developers improve code writing efficiency and help enterprises improve program development efficiency.

[0005] Summary of the Invention

[0006] The present application provides a code generation method, device and computer-readable storage medium, which can automatically generate code based on natural language questions input by developers, help developers improve code writing efficiency, and help enterprises improve program development efficiency.

[0007] In a first aspect, a code generation method is provided, which is applied to a code generation system, the code generation system including a cloud computing platform and a terminal device, the method including the following steps: the cloud computing platform receives a code generation request carrying a first problem sent by the terminal device, decomposes the first problem, obtains the solution steps of the first problem, and then searches a code knowledge base based on each step in the solution steps of the first problem to obtain target code knowledge, the target code knowledge including the code knowledge in the code knowledge base that matches each step in the solution steps of the first problem, and then the cloud computing platform inputs the solution steps of the first problem and the target code knowledge into a code generation model, uses the code output by the code generation model as the target code, and sends the target code to the terminal device, which presents the target code. The above-mentioned code generation model is obtained by using artificial intelligence (AI) technology to train the solution steps of multiple known problems, the code knowledge matching the solution steps of multiple known problems, and the code for solving the multiple known problems, and the code for solving each known problem includes the code in the code knowledge matching the solution steps of each known problem.

[0008] It can be seen that in the above solution, users only need to enter code-related questions on the terminal device, and they can view the code automatically generated by the cloud computing platform based on the questions entered by the user and fed back to the terminal device. Therefore, it can help users improve code writing efficiency, and then help enterprises improve program development efficiency.

[0009] In addition, since the cloud computing platform decomposes user problems to obtain the solution steps of user problems, searches the code knowledge base based on each step in the solution steps of the user problems, obtains the code knowledge matching each step, and then inputs each step and the code knowledge matching the step into the code generation model to generate code, it does not simply input the user problem into the model to output the code. Therefore, the code generated by the above solution has higher accuracy.

[0010] In some possible implementations, the code knowledge base includes the language type to which each piece of code knowledge in the code knowledge base belongs;

[0011] The above method further includes the following steps: the cloud computing platform obtains the desired code language type of a first user, where the first user is a user of a terminal device;

[0012] The above-mentioned cloud computing platform retrieves the code knowledge base based on each step in the solution steps of the first problem to obtain target code knowledge, and the target code knowledge includes code knowledge that matches each step in the solution steps of the first problem, including: the cloud computing platform retrieves the code knowledge base based on each step in the solution steps of the first problem and the expected code language type to obtain target code knowledge, and the target code knowledge includes code knowledge in the code knowledge base that has the same language type as the expected code language type, and code knowledge that matches each step in the solution steps of the first problem.

[0013] In the above implementation, since the code knowledge base includes the language type to which each code knowledge in the code knowledge base belongs, the cloud computing platform obtains the user's expected code language type, and searches the code knowledge base for knowledge recommendation based on the problem-solving steps and the expected code language type. The code knowledge matched to each step is more detailed. Therefore, the granularity of the code generated by the code generation model will also be refined to the user's expected code language field, and the generated code will better meet user needs and optimize the user experience.

[0014] In some possible implementations, the method further includes the following steps: the cloud computing platform obtains information of the first user, and based on the information of the first user, queries a first correspondence relationship, and uses a prompt template corresponding to the information of the first user from a plurality of prompt templates as a target prompt template, wherein the first correspondence relationship indicates a correspondence between the plurality of user information and the plurality of prompt templates, the first user is a user of the terminal device, and the first user belongs to the plurality of users;

[0015] The cloud computing platform inputs the solution steps of the first problem and the target code knowledge into the code generation model, including: the cloud computing platform fills the solution steps of the first problem and the target code knowledge into the target prompt template, and then inputs the target prompt template into the code generation model.

[0016] Since the prompt template can help the model better understand the user's intention, generate responses that are more in line with user needs, and improve the quality of the model's responses, the above implementation method is implemented. The cloud computing platform fills the solution steps of the first problem and the target code knowledge into the prompt template corresponding to the user information, and then inputs the prompt template into the code generation model to generate code. The code will be more in line with user needs and the code quality will be higher.

[0017] In some possible implementations, the above method further includes the following steps: the cloud computing platform receives an update request for the code knowledge base sent by the terminal device, and then updates the code knowledge base based on the update request.

[0018] It is understandable that with the rapid development of computer technology and the passage of time, new code knowledge and outdated code knowledge will appear in various language fields. If the code generation model is not updated, the code generation model may face the problem of insufficient training data / outdated training data, resulting in low reasoning accuracy. If the code generation model is updated and trained, it will face the problem of long training cycle and high cost. By implementing the above implementation method, since the code knowledge in the code knowledge base is updated, when the cloud computing platform receives a new user question and generates code based on the new user question, it can search in the updated code knowledge base based on the new user question. The retrieved matching code knowledge is updated, so that the code generation model can generate code based on the updated code knowledge, which helps to maintain the timeliness, adaptability and accuracy of the model.

[0019] In some possible implementations, the update request carries new code knowledge;

[0020] The cloud computing platform updates the code knowledge base based on the update request, including: the cloud computing platform adds the new code knowledge carried in the update request to the code knowledge base.

[0021] In some possible implementations, the language type to which the code knowledge in the above-mentioned code knowledge base belongs includes any one or more of the following: C language, C++ language, C# language, Java language, Python language, JavaScript language, Visual Basic language and Golang language.

[0022] In some possible implementations, the terminal device is installed with an IDE, and the code generation request is generated based on the first question by the IDE on the terminal device after receiving the first question and is sent to the cloud computing platform.

[0023] In a second aspect, a code generation device is provided, which is applied to a cloud computing platform. The cloud computing platform belongs to a code generation system. The code generation system also includes a terminal device. The device includes:

[0024] An acquisition module, configured to receive a code generation request carrying a first question sent by the terminal device;

[0025] A problem decomposition module, configured to decompose the first problem to obtain solution steps for the first problem;

[0026] a knowledge retrieval module, configured to search a code knowledge base based on each step in the steps of solving the first problem to obtain target code knowledge, wherein the target code knowledge includes code knowledge in the code knowledge base that matches each step in the steps of solving the first problem;

[0027] a code generation module, configured to input the solution steps of the first problem and the target code knowledge into a code generation model, and use the code output by the code generation model as the target code, wherein the code generation model is obtained by training the solution steps of multiple known problems, the code knowledge matching the solution steps of the multiple known problems, and the code for solving the multiple known problems using artificial intelligence (AI) technology, wherein the code for solving each known problem includes the code in the code knowledge matching the solution steps of each known problem;

[0028] A sending module is used to send the target code to the terminal device.

[0029] In some possible implementations, the code knowledge base includes a language type to which each code knowledge in the code knowledge base belongs;

[0030] The acquisition module is further configured to acquire a desired code language type of a first user, where the first user is a user of the terminal device;

[0031] The knowledge retrieval module is used to search the code knowledge base based on each step in the solution steps of the first problem and the expected code language type to obtain target code knowledge, where the target code knowledge includes code knowledge in the code knowledge base that has the same language type as the expected code language type and matches each step in the solution steps of the first problem.

[0032] In some possible implementations, the acquisition module is further configured to acquire information of a first user, query a first correspondence based on the information of the first user, and use a prompt template corresponding to the information of the first user among multiple prompt templates as a target prompt template, wherein the first correspondence indicates a correspondence between information of multiple users and the multiple prompt templates, the first user is a user of the terminal device, and the first user belongs to the multiple users;

[0033] The code generation module is specifically used for:

[0034] Fill the solution steps of the first problem and the target code knowledge into the target prompt template;

[0035] The target prompt template is input into the code generation model.

[0036] In some possible implementations, the apparatus further includes: a knowledge updating module;

[0037] The acquisition module is further configured to receive an update request for the code knowledge base sent by the terminal device;

[0038] The knowledge updating module is used to update the code knowledge base based on the update request.

[0039] In some possible implementations, the update request carries new code knowledge;

[0040] The knowledge updating module is configured to add the new code knowledge carried in the update request to the code knowledge base.

[0041] In some possible implementations, the language type to which the code knowledge in the code knowledge base belongs includes any one or more of the following: C language, C++ language, C# language, Java language, Python language, JavaScript language, Visual Basic language, and Golang language.

[0042] In some possible implementations, the terminal device is installed with an IDE, and the code generation request is generated by the IDE on the terminal device based on the first question after receiving the first question and sent to the acquisition module.

[0043] In a third aspect, a computing device cluster is provided, comprising a processor and a memory; the processor is configured to execute instructions stored in the memory, so that the computing device cluster implements the method provided in the first aspect or any possible implementation of the first aspect.

[0044] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores instructions, and the instructions are used to implement the method provided in the first aspect or any possible implementation of the first aspect.

[0045] In a fifth aspect, a computer program product is provided, comprising a computer program. When the computer program is read and executed by a computing device cluster, the computing device cluster executes the method provided in the first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] FIG1 is a schematic diagram of the structure of a code generation system provided in an embodiment of the present application;

[0047] FIG2 is a schematic diagram of a code generation system according to an embodiment of the present application providing a code generation cloud service to a user;

[0048] FIG3 is a flow chart of a code generation method provided in an embodiment of the present application;

[0049] FIG4A is a schematic diagram of the training and reasoning process of a problem step decomposition model provided in an embodiment of the present application;

[0050] FIG4B is a schematic diagram of the training and reasoning process of a code generation model provided in an embodiment of the present application;

[0051] FIG5 is a flow chart of another code generation method provided in an embodiment of the present application;

[0052] FIG6 is a flow chart of another code generation method provided in an embodiment of the present application;

[0053] FIG7 is a schematic diagram of a prompt template exemplarily shown in an embodiment of the present application;

[0054] FIG8 is a flow chart of another code generation method provided in an embodiment of the present application;

[0055] FIG9 is a schematic diagram of a prompt template filled with problem-solving steps and target code knowledge according to an embodiment of the present application;

[0056] FIG10 is a schematic diagram of the structure of a code generation device provided in an embodiment of the present application;

[0057] FIG11 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application;

[0058] FIG12 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application;

[0059] FIG13 is a schematic diagram of the structure of another computing device cluster provided in an embodiment of the present application. DETAILED DESCRIPTION

[0060] The technical solution provided in this application will be described below in conjunction with the accompanying drawings.

[0061] With the development of computer technology and the increasingly fast pace of people's work and life, enterprise developers' manual coding on personal computers (PCs), desktops, laptops and other terminal devices using software with code writing functions (such as IDE) on terminal devices for program development can no longer meet the pursuit of high efficiency by enterprises and developers.

[0062] Therefore, the present application provides a code generation system and a code generation method, etc. In the code generation system and code generation method provided by the present application, users (such as developers) only need to enter code-related questions on the terminal device to view the code automatically generated by the code generation system based on the questions entered by the user, thereby helping users improve code writing efficiency and helping enterprises improve program development efficiency. Moreover, the accuracy of the generated code is also relatively high.

[0063] The code generation system, method, etc. provided in this application are described in detail below in conjunction with the corresponding drawings.

[0064] Please refer to Figure 1, which is a schematic diagram of the structure of a code generation system provided in an embodiment of the present application. As shown in Figure 1, the system includes a terminal device 100 and a cloud computing platform 200. The terminal device 100 can communicate with the cloud computing platform 200 via a communication network using any communication mechanism / communication standard. The communication network can be a wide area network, a local area network, a point-to-point connection, or any combination thereof.

[0065] The user can operate the terminal device 100 to submit code-related questions to the cloud computing platform 200. The cloud computing platform 200 generates code based on the code-related questions submitted by the user, and returns the generated code to the terminal device 100, which is presented to the user by the terminal device 100.

[0066] In a specific implementation, the terminal device 100 can be any computing device, such as a personal computer, a tablet computer, a mobile notebook, a smart phone, a handheld processing device, a virtual reality device, a wearable device, an integrated handheld game console, a personal computer, a computer workstation, etc., and this application does not make any specific limitations.

[0067] Cloud computing platform 200 may be composed of one or more computing devices, which may be personal computers, general-purpose physical servers such as X86 servers or ARM servers, virtual machines (VMs), or containers, though this application does not impose specific limitations. A virtual machine refers to a complete computer system implemented using network function virtualization (NFV) technology, simulated through software, with complete hardware system functions, and running in a completely isolated environment. A container refers to a group of processes that are resource-constrained and isolated from each other.

[0068] The cloud computing platform 200 may be a central cloud data center of a cloud service provider, or an edge data center provided by the cloud service provider to users.

[0069] In some possible implementations, a cloud service provider may provide the code generation service provided by the cloud computing platform 200 as a cloud service. As shown in FIG2 , a user may interact with the cloud computing platform 200 through a terminal device 100 and purchase the code generation cloud service. After the user purchases the cloud service, users who have registered an account with the cloud computing platform 200 may use the cloud service to generate code. For example, the cloud computing platform 200 may provide a graphical user interface (GUI) to the user who purchases the cloud service, display the GUI on the user's terminal device 100, and the user may perform code generation within the GUI. Purchasing the code generation cloud service may include pre-charging and then settling based on the actual usage of the resources, or settling based on the time the cloud service is used or the functions or resources of the purchased cloud service.

[0070] In other possible implementations, all functions of the above code generation system may also be implemented by the terminal device 100. For example, the terminal device 100 implements the above code generation service to generate a code for its own user, or the terminal device 100 implements the above code generation service to generate a code for a user operating another terminal device.

[0071] It should be understood that the code generation system shown in Figure 1 is only an example. For example, in actual applications, the code generation system may include any number of terminal devices 100 and cloud computing platforms 200. The code generation system may also include other or more components, such as a network device for forwarding communication data between the cloud computing platform 200 and the terminal device 100. Figure 1 should not be regarded as a specific limitation.

[0072] In order to facilitate a clearer understanding of the specific process of the code generation system shown in Figure 1 generating code according to user questions, the following is a detailed introduction with reference to the flow charts of several code generation methods shown in Figures 3, 5, 6, and 8. It should be noted that in Figures 3, 5, 6, and 8, the description is based on the example of the terminal device 100 and the cloud computing platform 200 collaboratively implementing the code generation service. When the code generation service is implemented by the terminal device 100 alone, it is only necessary to delete the interaction steps between the terminal device 100 and the cloud computing platform 200 in the code generation method shown in Figures 3, 5, 6, and 8, and hand over the steps originally performed by the cloud computing platform 200 to the terminal device 100 for execution. For the sake of brevity of the specification, no further details will be given.

[0073] As shown in FIG3 , the method includes the following steps:

[0074] S301: The terminal device 100 receives a first question input by a first user.

[0075] S302: The terminal device 100 generates a code generation request carrying a first question.

[0076] S303: The terminal device 100 sends a code generation request to the cloud computing platform 200. Correspondingly, the cloud computing platform 200 receives the code generation request carrying the first question sent by the terminal device 100.

[0077] S304: The cloud computing platform 200 decomposes the first problem carried in the code generation request to obtain steps for solving the first problem.

[0078] S305: The cloud computing platform 200 searches the code knowledge base based on each step in the solution to the first problem to obtain target code knowledge, where the target code knowledge includes code knowledge in the code knowledge base that matches each step in the solution to the first problem.

[0079] S306: The cloud computing platform 200 inputs the solution steps of the first problem and the target code knowledge into the code generation model, and uses the code output by the code generation model as the target code.

[0080] S307: The cloud computing platform 200 sends the target code to the terminal device 100.

[0081] S308: The terminal device 100 displays the target code.

[0082] The following is a detailed introduction to each step shown in Figure 3.

[0083] In S301, the first user refers to the user of the terminal device 100; the first question refers to related questions for generating code, such as "write a crawler software to regularly access professional papers on the large model direction of paper platform A every morning and automatically generate paper summaries", such as "help me complete the code and recommend some codes with similar functions and structures to the example code B", and "convert the example code B from C language to Java language and C++ language", etc. It should be understood that the above examples are for illustration, and this application does not specifically limit the first question.

[0084] Specifically, the first question may be a question described in natural language, and the first user may input the first question through the code generation application client on the terminal device 100. Optionally, the first user may also input voice data including the first question through the code generation application client, and the code generation client may extract the first question from the voice data.

[0085] The code generation application client can be a separate software on the terminal device 100, or it can be integrated into existing software on the terminal device 100, such as software with code writing function (such as IDE) integrated into the terminal device 100 in the form of a plug-in, or run in a browser on the terminal device 100, such as a web page in the browser that can interact with the first user. This application does not make specific limitations on this.

[0086] In a possible embodiment, the code generation application client may display multiple code-related questions to the first user, and the first user may select one or more questions from the displayed multiple code-related questions as the first question input to the terminal device 100.

[0087] In S302, after receiving the first question input by the first user, the terminal device 100 may also receive an operation for generating a code performed by the first user on the terminal device 100, and then process the operation as a code generation request carrying the first question. For example, a "Generate Code" button or a "Confirm" button may be displayed on the interface displayed by the terminal device 100 for the first user to input the first question. After the first user inputs the first question on the interface, the first user may click or touch the "Generate Code" button or the "Confirm" button on the interface, thereby inputting the operation for generating a code to the terminal device 100.

[0088] Specifically, the first user may input an operation for generating a code through the code generation application client on the terminal device 100 . After receiving the operation of the first user, the code generation application client processes the operation into a code generation request.

[0089] In S303, the terminal device 100 may send a code generation request carrying the first question to the code generation server of the cloud computing platform 200 via the code generation application client. The code generation application server may be a separate software on the cloud computing platform 200, or may be integrated into existing software on the cloud computing platform 200, or may run in a browser on the cloud computing platform 200, and this application does not specifically limit this.

[0090] In S304, taking the first problem described in S301, "write a crawler software, regularly visit the professional papers in the large model direction of paper platform A every morning, and automatically generate paper abstracts" as an example, the solution steps obtained after decomposing the first problem can be: S1, crawler software depends on program library installation, S2, configure the search keyword interface, S3, configure the crawler interface, S4, obtain the interface for paper data of paper platform A, S5, configure the summary generation function, S6, configure the timing service interface, and crawl the paper list at a fixed time every day; taking the first problem described in S301, "help me complete the code and recommend some codes with similar functions and structures to the example code B" as an example, the solution steps obtained after decomposing the first problem can be: S1, configure the completion code interface, S2, configure the code recommendation interface. It should be understood that the solution steps of the above-mentioned first problem are only used as examples and should not be regarded as specific limitations.

[0091] In a possible embodiment, the cloud computing platform 200 may input the first problem into a problem step decomposition model, and use the solution steps output by the problem step decomposition model as the solution steps for the first problem, wherein the problem step decomposition model may be expressed as: y1=f1(x1)

[0092] Among them, y1 is the solution step of the first problem, x1 is the first problem, and f1() is the mapping relationship between the solution step of the first problem and the first problem.

[0093] As shown in Figure 4A, the problem step decomposition model can be obtained by training the first AI model using a first training sample set including a large number of known problems and a large number of solutions to known problems. After the problem step decomposition model is trained, the cloud computing platform 200 can use the problem step decomposition model to decompose the first problem to obtain the solution steps for the first problem. The first AI model may include but is not limited to decision trees, support vector machines (SVMs), deep learning models such as generative pre-trained transformer (GPT) models, etc., and this application does not make specific limitations. A large number of known problems can be historical problems accumulated in one or more language fields (such as C language, C++ language, C# language, Java language, Python language, JavaScript language, Visual Basic language and Golang language), and this application does not make specific limitations on this.

[0094] Furthermore, the first AI model may be trained using the first training sample set to obtain a problem step decomposition model in the following manner:

[0095] The i-th known question in the first training sample set is used as the input data sample S i , take the solution steps of the i-th known problem as the output data sample W i Through the above combination, a large number of input data samples and a large number of output data samples can be obtained, and there is a one-to-one correspondence between the large number of input data samples and the large number of output data samples.

[0096] After obtaining a large number of input data samples and a large number of output data samples, the large number of input data samples can be sequentially used as inputs to the first AI model, and the output data samples corresponding to each input data sample can be used as a reference for the output value of the first AI model. A loss function is used to calculate the loss value between the output value of the first AI model and the aforementioned data output samples, and the parameters of the first AI model are then adjusted based on the loss value. In a specific implementation, the large number of input data samples and the large number of output data samples can be used to iteratively train the first AI model, and the parameters of the first AI model can be continuously adjusted until the first AI model can accurately output the same output value as the output data sample corresponding to the input data sample based on the input data sample, thereby obtaining a trained problem step decomposition model.

[0097] It should be understood that the above-mentioned training process to obtain the problem step decomposition model is only an example and should not be regarded as a specific limitation. For example, in a specific implementation, the training samples in the first training sample set can be first classified, such as being classified into C language domain problems, C++ language domain problems, Java language domain problems, etc. according to the language domains to which a large number of known problems belong. Then, the first AI model is trained using a multi-task learning (MTL) method to obtain a problem step decomposition model that can achieve both separate decomposition of multi-language domain problems and decomposition of mixed language domain problems. Mixed language domain problems refer to problems that are a combination of problems in multiple different language domains. For example, Problem 1 "Converting sample code B into C language" belongs to the C language domain problem, Problem 2 "Converting sample code B into Java language" belongs to the Java language domain problem, and Problem 3, a mixture of Problems 1 and 2, is "Converting sample code B into C language and Java language."

[0098] Optionally, the cloud computing platform 200 can store a large number of steps described in text. After receiving the first question, the cloud computing platform 200 can extract keywords from the first question, and then query the large number of steps described in text based on the extracted keywords, and use the steps containing the keywords as the solution steps for the first question. Taking the first question described in S301 as "Help me complete the code and recommend some codes with similar functions and structures to sample code B" as an example, the cloud computing platform 200 can extract the following keywords "code completion" and "recommended code" from the first question, and then match the steps based on the extracted keywords "code completion" and "recommended code". Optionally, the cloud computing platform 200 can also store a large number of questions, the solution steps for each of the large number of questions, and the corresponding relationship between each question and its solution steps. After receiving the first question, the cloud computing platform 200 can query based on the first question to obtain the solution steps corresponding to the first question. This application does not limit the implementation method of the cloud computing platform 200 obtaining the solution steps for the first question.

[0099] In S305, the code knowledge base can be stored in the cloud computing platform 200 in the form of a data table or array. The code knowledge base includes a large amount of code knowledge. Each code knowledge includes code (such as a program library, interface, function, etc.) and its usage description, such as the usage description of the interface "paper_key_word" as an interface for retrieving keywords, the usage description of the interface "def crawl_papers(search_query)" as an interface for implementing the crawler function, and the usage description of the function "add" as a function for implementing the addition function. A large amount of code knowledge may include code knowledge in multiple language fields, and the code knowledge in the code knowledge base may be knowledge classified according to the language field. This application does not make specific limitations on this.

[0100] The code knowledge in the code knowledge base that matches each step in the solution steps of the first problem can be the code knowledge in the code knowledge base that has the highest matching degree with each step in the solution steps of the first problem. Specifically, the similarity (also called matching degree) between each step and the usage description in each code knowledge in the code knowledge base can be calculated by a similarity algorithm, so as to obtain the code knowledge with the highest matching degree for each step. After obtaining the code knowledge with the highest matching degree for each step, the target code knowledge can be obtained by combining the code knowledge with the highest matching degree for multiple steps. Among them, the similarity algorithm may include but is not limited to the Euclidean distance algorithm, the Pearson correlation coefficient algorithm, the cosine similarity algorithm, the term frequency-inverse document frequency index (TF-IDF), etc., and this application does not make specific limitations.

[0101] Taking the first problem in S304 as "write a crawler software to regularly visit professional papers in the large model direction of paper platform A every morning and automatically generate paper summaries", the solution steps for the first problem are "S1. The crawler software depends on the program library installation, S2. Configure the retrieval keyword interface, S3. Configure the crawler interface, S4. Configure the interface for obtaining paper data from paper platform A, S5. Configure the summary generation function, S6. Configure the timing service interface to crawl the paper list at a fixed time every day" as an example. The cloud computing platform 200 searches the code knowledge base based on the above 6 steps respectively, and can obtain the code knowledge that matches each step.

[0102] Taking S1 "Installation of Crawler Software Dependent Program Libraries" as an example, the matching code knowledge examples are: import requests, from bs4, import BeautifulSoup, import openai, where import requests, from bs4, import BeautifulSoup, and import openai are all crawler software dependent program libraries. Taking S2 "Configure Search Keyword Interface" as an example, the matching code knowledge examples are: paper_title, paper_abstract, paper_text, paper_key_word, where paper_title is an interface for searching for keywords in paper titles, paper_abstract is an interface for searching for keywords in paper abstracts, paper_text is an interface for searching for keywords in paper texts, and paper_key_word is an interface for searching for keywords. It should be understood that the solution steps for the first problem mentioned above and the code knowledge examples matching the solution steps for the first problem are merely examples and should not be regarded as specific limitations.

[0103] In S306, the code generation model can be expressed as: y2 = f2(x2)

[0104] Among them, y2 is the code generated based on the solution steps of the first problem and the target code knowledge, x2 is the solution steps of the first problem and the target code knowledge, and f2() is the mapping relationship between the solution steps of the first problem and the target code knowledge and the code.

[0105] As shown in Figure 4B, the code generation model can be trained on the second AI model using a second training sample set including a large number of solution steps to known problems, a large number of code knowledge matching the solution steps to known problems, and codes for solving a large number of known problems. After the code generation model is trained, the cloud computing platform 200 can use the code generation model to infer the solution steps to the first problem and the target code knowledge to obtain the code for solving the first problem. Among them, the solution steps to a large number of known problems in the second training sample set can be the solution steps to a large number of known problems in the first training sample set; the code for solving each known problem includes the code knowledge matching the solution steps to each known problem. In other words, the code for solving each known problem is written on the basis of the code knowledge matching the solution steps to each known problem; the second AI model may include but is not limited to decision trees, support vector machines, deep learning models such as GPT models, etc., and this application does not make specific limitations.

[0106] In a possible embodiment, the second AI model and the first AI model may be the same model, such as both being GPT models.

[0107] Furthermore, a method of using the second training sample set to train the second AI model to obtain a code generation model may be:

[0108] The solution steps of the i-th known problem in the second training sample set and its matching code knowledge are used as input data sample S i , the code used to solve the i-th known problem is used as the output data sample W i Through the above combination, a large number of input data samples and a large number of output data samples can be obtained, and there is a one-to-one correspondence between the large number of input data samples and the large number of output data samples.

[0109] After obtaining a large number of input data samples and a large number of output data samples, the large number of input data samples can be sequentially used as inputs to the second AI model, and the output data samples corresponding to each input data sample can be used as a reference for the output value of the second AI model. A loss function is used to calculate the loss value between the output value of the second AI model and the aforementioned data output samples, and the parameters of the second AI model are then adjusted based on the loss value. In a specific implementation, the large number of input data samples and a large number of output data samples can be used to iteratively train the second AI model, and the parameters of the second AI model can be continuously adjusted until the second AI model can accurately output the same output value as the output data sample corresponding to the input data sample based on the input data sample, thereby obtaining a trained problem step decomposition model.

[0110] It should be understood that the above training process of obtaining the code generation model is merely an example and should not be regarded as a specific limitation.

[0111] In S307 , the cloud computing platform 200 may send the target code to the code generation application client on the terminal device 100 through the code generation application server.

[0112] In S308 , the code generation application client on the terminal device 100 may display the target code to the first user for viewing.

[0113] It can be seen that in the embodiment shown in FIG3 above, the user only needs to input code-related questions on the terminal device 100 to view the code automatically generated by the code generation system based on the questions input by the user. This can help users improve code writing efficiency and further help enterprises improve program development efficiency.

[0114] In addition, since the cloud computing platform 200 decomposes the user problem to obtain the solution steps of the user problem, searches the code knowledge base based on each step in the solution steps of the user problem, obtains the code knowledge matching each step, and then inputs each step and the code knowledge matching the step into the code generation model to generate code, it does not simply input the user problem into the model to output the code. Therefore, the code generated by the above solution has higher accuracy.

[0115] In one possible embodiment, in addition to including a large amount of code knowledge, the code knowledge base may also include the type of each code knowledge in the large amount of code knowledge, such as the language type, product line, and department to which each code knowledge belongs. See Tables 1 and 2 for two exemplary code knowledge bases shown in this application. In Table 1, the code knowledge base includes the language type to which each code knowledge belongs, and in Table 2, the code knowledge base includes the product line to which each code knowledge belongs. It should be understood that the language types shown in Table 1 and the product line types shown in Table 2 are for illustration only and are not specifically limited in this application.

[0116] Table 1 Code knowledge base

[0117] Table 2 Code knowledge base

[0118] Taking the example of a code knowledge base including a large amount of code knowledge and the language type to which each piece of code knowledge belongs, the specific process of the code generation system shown in FIG1 generating code according to the user question is shown in the steps shown in FIG5 .

[0119] S501: The terminal device 100 receives a first question input by a first user.

[0120] S502: The terminal device 100 obtains the desired coding language type of the first user.

[0121] S503: The terminal device 100 generates a code generation request carrying the first question and the desired code language type.

[0122] S504 : The terminal device 100 sends a code generation request to the cloud computing platform 200 . Correspondingly, the cloud computing platform 200 receives the code generation request sent by the terminal device 100 .

[0123] S505: The cloud computing platform 200 decomposes the first problem carried in the code generation request to obtain steps for solving the first problem.

[0124] S506: The cloud computing platform 200 searches the code knowledge base based on each step in the solution to the first problem and the expected code language type to obtain target code knowledge. The target code knowledge includes code knowledge in the code knowledge base that has the same language type as the expected code language type and that matches each step in the solution to the first problem.

[0125] S507: The cloud computing platform 200 inputs the solution steps of the first problem and the target code knowledge into the code generation model, and uses the code output by the code generation model as the target code.

[0126] S508 : The cloud computing platform 200 sends the target code to the terminal device 100 .

[0127] S509: The terminal device 100 displays the target code.

[0128] S501 is the same as S301, the specific implementation process of S503 is similar to the specific implementation process of S302, S504 is the same as S303, S505 is the same as S304, the specific implementation process of S506 is similar to the specific implementation process of S305, S507 is the same as S306, S508 is the same as S307, and S509 is the same as S308. Please refer to the relevant descriptions of the corresponding steps shown in Figure 3. For the sake of brevity of the specification, no further details will be given.

[0129] The remaining step S502 shown in FIG. 5 is described in detail below.

[0130] In S502 , the expected code language type refers to the language type of the code that the first user expects to generate.

[0131] The terminal device 100 may obtain the desired code language type of the first user in the following manner 1 or manner 2:

[0132] Mode 1: The first user inputs the desired code language type into the terminal device 100. Specifically, the first user may input the desired code language type through the code generation application client on the terminal device 100.

[0133] For example, on the interface displayed on the terminal device 100 for the first user to input the first question, an "expected language type" input box is also displayed. When the first user inputs the first question on the interface, the first user can enter the expected code language type in the "expected language type" input box. For another example, on the interface displayed on the terminal device 100 for the first user to input the first question, an "expected language type" selection box is also displayed. The selectable language types include but are not limited to C language, C++ language, C# language, Java language, Python language, JavaScript language, Visual Basic language and Golang language. When the first user enters the first question on the interface, the first user can select one or more language types as the expected code language type in the "expected language type" selection box.

[0134] In method 2, the terminal device 100 automatically obtains the desired code language type, and the automatic obtaining method may be the following method 2.1 or method 2.2.

[0135] Method 2.1: If the first user creates a code file on software with code writing capabilities (such as an IDE) on the terminal device 100 and then enters the first question in the opened code file, the terminal device 100 can identify the language type of the code file based on the suffix of the code file to which the first question belongs before generating a code generation request, and use the language type of the code file as the first user's expected code language type. For example, if the code file has a suffix of .c, the terminal device 100 identifies the language type as C. For another example, if the code file has a suffix of .java, the terminal device 100 identifies the language type as Java.

[0136] Method 2.2: If the first user creates a code file on software with code writing function (such as IDE) on the terminal device 100, writes code in the opened code file and enters the first question, then the terminal device 100 can identify the language type of the code that the first user has written in the code file before generating a code request, and use the language type as the first user's expected code language type.

[0137] It should be understood that the above-described method by which the terminal device 100 automatically obtains the first user's desired coding language type is merely an example and is not specifically limited in this application. For example, since some IDEs allow users to configure their programming environment, including specifying the programming language to be used, the terminal device 100 can obtain the user's programming language preference by analyzing the IDE's user configuration information and use the user's preferred programming language type as the desired coding language type.

[0138] Taking the example of a code knowledge base including a large amount of code knowledge and the product line to which each piece of code knowledge belongs, the specific process of the code generation system shown in Figure 1 generating code according to user questions is shown in the steps shown in Figure 6.

[0139] S601: The terminal device 100 receives a first question input by a first user.

[0140] S602: The terminal device 100 obtains the product line to which the first user belongs.

[0141] S603: The terminal device 100 generates a code generation request carrying the first question and the product line to which the first user belongs.

[0142] S604: The terminal device 100 sends a code generation request to the cloud computing platform 200. Correspondingly, the cloud computing platform 200 receives the code generation request sent by the terminal device 100.

[0143] S605: The cloud computing platform 200 decomposes the first problem carried in the code generation request to obtain steps for solving the first problem.

[0144] S606: The cloud computing platform 200 retrieves the code knowledge base based on each step in the solution to the first problem and the product line to which the first user belongs to obtain target code knowledge. The target code knowledge includes code knowledge in the code knowledge base that belongs to the same product line as the first user, and code knowledge that matches each step in the solution to the first problem.

[0145] S607: The cloud computing platform 200 inputs the solution steps of the first problem and the target code knowledge into the code generation model, and uses the code output by the code generation model as the target code.

[0146] S608: The cloud computing platform 200 sends the target code to the terminal device 100.

[0147] S609: The terminal device 100 displays the target code.

[0148] S601 is the same as S301, the specific implementation process of S603 is similar to the specific implementation process of S302, the specific implementation process of S604 is similar to the specific implementation process of S303, S605 is the same as S304, the specific implementation process of S606 is similar to the specific implementation process of S305, S607 is the same as S306, S608 is the same as S307, and the specific implementation process of S609 is the same as S308. Please refer to the relevant description of the corresponding steps shown in Figure 3. For the sake of brevity of the specification, no further details will be given.

[0149] The remaining step S602 shown in FIG. 6 is described in detail below.

[0150] In S602, the terminal device 100 may obtain the product line to which the first user belongs in the following manner (1) or manner (2).

[0151] In mode (1), the product line to which the first user belongs is input by the first user into the terminal device 100. Specifically, the first user may input the product line to which the first user belongs through the code generation application client on the terminal device 100.

[0152] For example, on the interface displayed on the terminal device 100 for the first user to input the first question, a "product line type" input box is also displayed. When the first user inputs the first question on the interface, the first user can enter the product line to which the first user belongs in the "product line type" input box. For another example, on the interface displayed on the terminal device 100 for the first user to input the first question, a "product line type" selection box is also displayed. The selectable product line types may include but are not limited to wireless, data communication, cloud core, and computing. When the first user inputs the first question on the interface, the first user can select a product line type in the "product line type" selection box as the product line to which the first user belongs.

[0153] Method (2): The registration information filled in by the first user when registering on the cloud computing platform 200 may include the first user's information, such as the first user's identifier (such as name, ID number, mobile phone number, email address, etc.), the product line to which the first user belongs, the department to which the first user belongs, etc. The cloud computing platform 200 will store the registration information. Before generating a code request, the terminal device 100 may send a product line acquisition request carrying the first user's identifier to the cloud computing platform 200, requesting to obtain the product line corresponding to the first user's identifier, and the product line is the product line to which the first user belongs.

[0154] It should be understood that the above-mentioned manner in which the terminal device 100 obtains the product line to which the first user belongs is merely an example, and this application does not impose any specific limitation thereto.

[0155] Optionally, S602 may obtain the first user's identifier for the terminal device 100, and S603 may generate a code generation request for the terminal device 100 that carries the first question and the first user's identifier. After S604 and before S606, the cloud computing platform 200 may query the registration information described in the above method (2) based on the first user's identifier carried in the code generation request to obtain the product line to which the first user belongs. In other words, the product line to which the first user belongs is not obtained by the terminal device 100 and sent to the cloud computing platform 200, but is obtained by the cloud computing platform 200 by querying the first user's registration information based on the first user's identifier sent by the terminal device 100. This application does not limit the implementation method by which the cloud computing platform 200 obtains the product line to which the first user belongs.

[0156] It can be seen that, compared with the embodiment shown in Figure 3, the embodiments shown in Figures 5 and 6 are more detailed in matching the code knowledge of the problem-solving steps. The embodiment in Figure 5 is refined to a specific language field, and the embodiment in Figure 6 is refined to a specific product line. Therefore, in the embodiments shown in Figures 5 and 6, the code generation model generates code based on the finer-grained code knowledge matched to the problem-solving steps. Therefore, the granularity of the generated code will also be finer. For example, in the embodiment in Figure 5, the code generated by the code generation model will be refined to the user's expected code language field, and in the embodiment in Figure 6, the code generated by the code generation model will be refined to the product line to which the user belongs, which is more in line with user needs and further optimizes the user experience.

[0157] In another possible embodiment, the cloud computing platform 200 may store multiple user information, multiple prompt templates, and a first correspondence, wherein the first correspondence indicates the correspondence between the multiple user information and the multiple prompt templates. The first user mentioned above belongs to multiple users, and the user information may include the user's name, ID number, mobile phone number, email address, department, product line, professional field, etc. The first correspondence may be stored in the cloud computing platform 200 in the form of a data table or array. The prompt template is used to help the code generation model better understand the user's intent when generating code, generate responses that better meet the user's needs, and improve the quality of the model's responses.

[0158] Refer to Table 3 for an exemplary first correspondence of this application. In Table 3, the user information is taken as the user name as an example.

[0159] Referring to FIG. 7 , FIG. 7 is a schematic diagram of a prompt template exemplified in this application. The prompt template includes a task filling area 710 for filling in problem-solving steps and the code knowledge that matches the problem-solving steps. The {} in the prompt template is used to fill in the user's professional field. For example, if the first question entered by the first user includes the keyword "Java," then {} is filled in with "Java development." If the first question entered by the first user includes the keyword "C++," then {} is filled in with "C++ development." It should be understood that the prompt template shown in FIG. 7 is for illustration only and is not specifically limited in this application.

[0160] Table 3 First correspondence

[0161] In this embodiment, the specific process of the code generation system shown in FIG1 generating a code according to a user question is shown in FIG8 .

[0162] S801: The terminal device 100 receives a first question input by a first user.

[0163] S802: The terminal device 100 obtains the information of the first user.

[0164] S803: The terminal device 100 generates a code generation request carrying the first question and the information of the first user.

[0165] S804: The terminal device 100 sends a code generation request to the cloud computing platform 200. Correspondingly, the cloud computing platform 200 receives the code generation request sent by the terminal device 100.

[0166] S805: The cloud computing platform 200 decomposes the first problem carried in the code generation request to obtain solution steps for the first problem.

[0167] S806: The cloud computing platform 200 searches the code knowledge base based on each step in the solution to the first problem to obtain target code knowledge, where the target code knowledge includes code knowledge in the code knowledge base that matches each step in the solution to the first problem.

[0168] S807: The cloud computing platform 200 searches for a first corresponding relationship based on the information of the first user carried in the code generation request, and uses the prompt template corresponding to the first user information among the multiple prompt templates as a target prompt template.

[0169] S808: The cloud computing platform 200 fills the solution steps of the first problem and the target code knowledge into the target prompt template.

[0170] S809: The cloud computing platform 200 inputs the target prompt template filled with the solution steps of the first problem and the target code knowledge into the code generation model, and uses the code output by the code generation model as the target code.

[0171] S810: The cloud computing platform 200 sends the target code to the terminal device 100.

[0172] S811: The terminal device 100 displays the target code.

[0173] S801 is the same as S301, the specific implementation process of S803 is similar to the specific implementation process of S302, the specific implementation process of S804 is similar to the specific implementation process of S303, S805 is the same as S304, the specific implementation process of S806 is similar to the specific implementation process of S305, S810 is the same as S307, and the specific implementation process of S811 is the same as S308. Please refer to the relevant description of the corresponding steps shown in Figure 3. For the sake of brevity of the specification, no further details will be given.

[0174] The remaining steps S802 , S807 , S808 , and S809 shown in FIG8 are described in detail below.

[0175] In S802, the first user's information may be input into the terminal device 100 by the first user. Specifically, the first user may input the first user's information through a code generation application client on the terminal device 100.

[0176] Taking the product line to which the user information belongs as an example, for example, on the interface displayed by the terminal device 100 for the first user to input the first question, a "product line type" input box is also displayed. When the first user inputs the first question on the interface, the first user can enter the product line to which the first user belongs in the "product line type" input box. For another example, on the interface displayed by the terminal device 100 for the first user to input the first question, a "product line type" selection box is also displayed. The selectable product line types may include but are not limited to wireless, data communication, cloud core, and computing. When the first user inputs the first question on the interface, the first user can select a product line type in the "product line type" selection box as the product line to which the first user belongs.

[0177] Optionally, S802 may obtain the first user's identifier for the terminal device 100, and S803 may generate a code generation request for the terminal device 100 that carries the first question and the first user's identifier. After S804 and before S807, the cloud computing platform 200 may query the registration information described in method (2) in S602 based on the first user's identifier carried in the code generation request to obtain the product line to which the first user belongs. In other words, the product line to which the first user belongs is not obtained by the terminal device 100 and sent to the cloud computing platform 200, but is obtained by the cloud computing platform 200 by querying the first user's registration information based on the first user's identifier sent by the terminal device 100. This application does not limit the implementation method by which the cloud computing platform 200 obtains the product line to which the first user belongs.

[0178] In S807 and S808, see FIG9 for an exemplary prompt template. The left side of FIG9 is a schematic diagram of the prompt template before the solution steps for the first problem and the target code knowledge are entered into the prompt template. For details of the prompt template, please refer to the relevant description of FIG7. The right side of FIG9 is a schematic diagram of the prompt template after the solution steps for the first problem and the target code knowledge are entered into the prompt template. It should be understood that FIG9 is for illustration only and is not intended to be a specific limitation in this application.

[0179] In S809, if the code generation model is to be implemented to infer and output code based on the target prompt template filled with the solution steps of the first problem and the target code knowledge, the second AI model can be trained to obtain the code generation model using the aforementioned second training sample set in the following manner: the solution steps of the i-th known problem in the second training sample set and its matching code knowledge are filled into the corresponding prompt template, the prompt template filled with the solution steps of the i-th known problem and its matching code knowledge is used as the input data sample Si, and the prompt template filled with the solution steps of the i-th known problem and its matching code knowledge and the code for solving the i-th known problem is used as the output data sample Wi. Through the above combination, a large number of input data samples and a large number of output data samples can be obtained, and there is a one-to-one correspondence between the large number of input data samples and the large number of output data samples. Then, the second AI model can be trained using the large number of input data samples and the large number of output data samples.

[0180] The solution steps for the above-mentioned known problem i and the corresponding prompt template of the corresponding code knowledge can be determined as follows:

[0181] Method ①: Taking the first correspondence shown in Table 3 as an example, the prompt template corresponding to the same product line as the product line to which the i-th known problem belongs among the multiple prompt templates shown in Table 3 is the prompt template corresponding to the solution steps of the i-th known problem and its matching code knowledge.

[0182] Method ②: Continuing with the first correspondence shown in Table 3 as an example, among the multiple prompt templates shown in Table 3, the prompt template corresponding to the product line that has the same product line as the code knowledge matching the solution steps of the i-th known problem is the prompt template corresponding to the solution steps of the i-th known problem and its matching code knowledge.

[0183] It should be noted that the above-mentioned methods ① and ② are merely examples and should not be considered as specific limitations. For example, if the first correspondence indicates the correspondence between multiple user departments and multiple prompt templates, then the prompt template corresponding to the department of the code knowledge matching the solution to the i-th known problem in the multiple prompt templates can be used as the prompt template corresponding to the solution to the i-th known problem and its matching code knowledge.

[0184] It can be seen that the embodiment of FIG8 is an expansion of the embodiment shown in FIG3. On the basis of the embodiment of FIG3, a step of obtaining the first user information (i.e., S802) and a step of obtaining the target prompt template by querying the first corresponding relationship based on the information of the first user (i.e., S807) are added, as well as a step of filling the target prompt template with the solution steps of the first problem and the target code knowledge (i.e., S808) is added. The step of inputting the solution steps of the first problem and the target code knowledge into the code generation model in S306 shown in FIG3 is replaced by the step of inputting the target prompt template filled with the solution steps of the first problem and the target code knowledge into the code generation model in S809. Since the prompt template can help the code generation model better understand the user's intention, generate a response that better meets the user's needs, and improve the quality of the model's response, therefore, compared with the embodiment of FIG3, the cloud computing platform 200 in the embodiment of FIG8 can use the code generation model to generate code that better meets the user's needs and improve the code quality.

[0185] According to the above ideas, it can be understood that, on the basis of the embodiment of Figure 5 / Figure 6, a step of obtaining the first user information, a step of obtaining the target prompt template by querying the first corresponding relationship according to the information of the first user, and a step of filling the solution steps of the first problem and the target code knowledge into the target prompt template are added. The step of inputting the solution steps of the first problem and the target code knowledge into the code generation model in S507 / S607 shown in Figure 5 / Figure 6 is replaced by inputting the target prompt template filled with the solution steps of the first problem and the target code knowledge into the code generation model. Since the prompt template can help the code generation model better understand the user's intention, generate a reply that is more in line with the user's needs, and improve the quality of the model's reply, therefore, the above operations are performed on the basis of the embodiment of Figure 5 / Figure 6. Compared with the embodiment of Figure 5 / Figure 6, the cloud computing platform 200 can use the code generation model to generate code that is more in line with user needs and improve the code quality.

[0186] It should be noted that the above-mentioned code knowledge base, multiple user information, multiple prompt templates, multiple language types, first correspondence, etc. are stored in the cloud computing platform 200 only as an example. In a specific implementation, the above-mentioned information can also be stored in one or more other storage devices independent of the cloud computing platform 200. When the cloud computing platform 200 needs to query the corresponding information, it can access the storage device that stores the corresponding information for query.

[0187] It is understandable that with the rapid development of computer technology and the passage of time, new code knowledge and outdated code knowledge will appear in various language fields. If the code generation model is not updated, the code generation model may face the problem of insufficient training data / outdated training data, resulting in low reasoning accuracy. If the code generation model is updated and trained, it will face the problem of long training cycle and high cost. In order to solve the above problems, the code generation method shown in Figures 3, 5, 6, and 8 provided in the embodiments of the present application may also include the following steps:

[0188] In the first step, the terminal device 100 receives an update operation on the code knowledge base input by the first user, such as deleting expired code knowledge in the code knowledge base, correcting erroneous code knowledge in the code knowledge base, adding new code knowledge to the code knowledge base, etc.

[0189] In the second step, the terminal device 100 processes the above-mentioned update operation on the code knowledge base into an update request for the code knowledge base.

[0190] Step 3: The terminal device 100 sends an update request to the cloud computing platform 200.

[0191] In the fourth step, the cloud computing platform 200 updates the code knowledge base based on the update request, such as deleting expired code knowledge in the code knowledge base, correcting erroneous code knowledge in the code knowledge base, or adding new code knowledge to the code knowledge base.

[0192] In the case where the update request is used to request adding new code knowledge to the code knowledge base, the update request may carry the new code knowledge to be added.

[0193] It can be understood that since the code knowledge in the code knowledge base has been updated, when the cloud computing platform 200 subsequently receives a new user question and generates code based on the new user question, it can search in the updated code knowledge base based on the new user question. The retrieved matching code knowledge is updated, so that the code generation model can generate code based on the updated code knowledge, which helps to maintain the timeliness, adaptability and accuracy of the model.

[0194] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0195] The above describes in detail the code generation method provided in the embodiment of the present application. Based on the same inventive concept, the following further introduces the code generation device and computing device cluster provided in the embodiment of the present application.

[0196] See Figure 10, which is a structural diagram of a code generation device 1000 provided in an embodiment of the present application. The code generation device 1000 can be applied to the code generation system shown in Figure 1, and specifically can be applied to the computing device in the cloud computing platform 200 shown in Figure 2.

[0197] As shown in Figure 10, the code generation device 1000 includes an acquisition module 1010, a problem decomposition module 1020, a knowledge retrieval module 1030, a code generation module 1040, and a sending module 1050. The functions of the various modules of the code generation device 1000 are described below by way of example. It should be understood that the functions of the various modules described below are merely functions that the code generation device 1000 may have in some embodiments of this application, and this application does not limit the functions of the various modules.

[0198] The acquisition module 1010 is configured to receive a code generation request carrying a first question sent by the terminal device 100 .

[0199] The problem decomposition module 1020 is used to decompose the first problem to obtain solution steps for the first problem.

[0200] The knowledge retrieval module 1030 is used to retrieve the code knowledge base based on each step in the solution to the first problem to obtain target code knowledge, where the target code knowledge includes code knowledge in the code knowledge base that matches each step in the solution to the first problem.

[0201] The code generation module 1040 is used to input the solution steps of the first problem and the target code knowledge into the code generation model, and use the code output by the code generation model as the target code. The code generation model is obtained by using AI technology to train the solution steps of multiple known problems, the code knowledge matching the solution steps of multiple known problems, and the code for solving multiple known problems, wherein the code for solving each known problem includes the code in the code knowledge matching the solution steps of each known problem.

[0202] The sending module 1050 is used to send the target code to the terminal device 100.

[0203] In some possible embodiments, the above-mentioned code knowledge base includes the language type to which each code knowledge in the code knowledge base belongs; the acquisition module 1010 is also used to obtain the expected code language type of the first user, where the first user is the user of the terminal device; the knowledge retrieval module 1030 is specifically used to: search the code knowledge base based on each step in the solution steps of the first problem and the expected code language type to obtain target code knowledge, and the target code knowledge includes the code knowledge in the code knowledge base whose language type is the same as the expected code language type, and the code knowledge that matches each step in the solution steps of the first problem.

[0204] In some possible embodiments, the acquisition module 1010 is also used to obtain the information of the first user, and query the first corresponding relationship based on the information of the first user, and use the prompt template corresponding to the information of the first user in multiple prompt templates as the target prompt template, wherein the first corresponding relationship indicates the correspondence between multiple user information and multiple prompt templates, the first user is the user of the terminal device, and the first user belongs to multiple users; the code generation module 1040 is specifically used to: fill in the solution steps of the first problem and the target code knowledge into the target prompt template; and input the target prompt template into the code generation model.

[0205] In some possible embodiments, the apparatus 1000 further includes: a knowledge updating module 1060 (not shown in FIG10 ); an acquisition module 1010 , further configured to receive an update request for a code knowledge base sent by the terminal device 100 ; and a knowledge updating module 1060 , configured to update the code knowledge base based on the update request.

[0206] In some possible embodiments, the update request carries new code knowledge; the knowledge update module 1060 is configured to add the new code knowledge carried in the update request to the code knowledge base.

[0207] In some possible embodiments, the language type to which the code knowledge in the above-mentioned code knowledge base belongs includes any one or more of the following: C language, C++ language, C# language, Java language, Python language, JavaScript language, Visual Basic language and Golang language.

[0208] In some possible embodiments, the terminal device 100 is installed with an IDE, and the code generation request is generated by the IDE on the terminal device 100 based on the first question after receiving the first question and sent to the acquisition module 1010 .

[0209] In some possible embodiments, the device 1000 may also include a first model training module 1070 and a second model training module 1080 (not shown in Figure 10), the first model training module 1070 is used to train to obtain the above-mentioned problem step decomposition model, and the second model training module 1080 is used to train to obtain the above-mentioned code generation model.

[0210] In a specific implementation, the acquisition module 1010, the problem decomposition module 1020, the knowledge retrieval module 1030, the code generation module 1040, the sending module 1050, the knowledge update module 1060, the first model training module 1070, and the second model training module 1080 can all be implemented by software, or can be implemented by hardware. Exemplarily, the implementation of the code generation module 1040 is described below using the code generation module 1040 as an example. Similarly, the implementation of the acquisition module 1010, the problem decomposition module 1020, the knowledge retrieval module 1030, the sending module 1050, the knowledge update module 1060, the first model training module 1070, and the second model training module 1080 can refer to the implementation of the code generation module 1040.

[0211] As an example of a software functional unit, the code generation module 1040 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Furthermore, the computing instance may be one or more. For example, the code generation module 1040 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including one data center or multiple geographically close data centers. Typically, a region may include multiple AZs.

[0212] Similarly, multiple hosts / virtual machines / containers running the code can be distributed within the same virtual private cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Cross-region communication between two VPCs within the same region, or between VPCs in different regions, requires a communication gateway within each VPC to interconnect the VPCs.

[0213] As an example of a hardware functional unit, the code generation module 1040 may include at least one computing device, such as a server. Alternatively, the code generation module 1040 may be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0214] When the code generation module 1040 includes multiple computing devices, the multiple computing devices can be distributed in the same region or in different regions. The multiple computing devices included in the code generation module 1040 can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the code generation module 1040 can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0215] It should be noted that, in other embodiments, the code generation module 1040 can be used to execute any step in the code generation method shown in Figures 3, 5, 6, and 8, the acquisition module 1010 can be used to execute any step in the code generation method shown in Figures 3, 5, 6, and 8, the knowledge retrieval module 1030 can be used to execute any step in the code generation method shown in Figures 3, 5, 6, and 8, the problem decomposition module 1020 can be used to execute any step in the code generation method shown in Figures 3, 5, 6, and 8, the sending module 1050 can be used to execute any step in the code generation method shown in Figures 3, 5, 6, and 8, the knowledge update module 1060 can be used to execute any step in the code generation method shown in Figures 3, 5, 6, and 8, and the first model training module 1070 can be used to execute the code generation method shown in Figures 3, 5, 6, and 8. 3 , 5 , 6 , and 8 , and the steps that the acquisition module 1010, the problem decomposition module 1020, the knowledge retrieval module 1030, the code generation module 1040, the sending module 1050, the knowledge update module 1060, the first model training module 1070, and the second model training module 1080 are responsible for implementing can be specified as needed. By using the acquisition module 1010, the problem decomposition module 1020, the knowledge retrieval module 1030, the code generation module 1040, the sending module 1050, the knowledge update module 1060, the first model training module 1070, and the second model training module 1080, different steps in the code generation method shown in FIG. 3 , 5 , 6, and 8 are respectively implemented to realize all the functions of the code generation device 1000.

[0216] An embodiment of the present application also provides a computing device 1100, which can deploy the code generation apparatus 1000 shown in FIG10 . The operations and / or functions of each module in the computing device 1100 are respectively to implement the corresponding steps in the code generation method shown in FIG3 , FIG5 , FIG6 , and FIG8 .

[0217] As shown in FIG. 11 , a computing device 1100 includes a processor 1110 , a memory 1120 , and a communication interface 1130 , wherein the processor 1110 , the memory 1120 , and the communication interface 1130 may be interconnected via a bus 1140 .

[0218] The processor 1110 can read the program code (including instructions) stored in the memory 1120 and execute the program code stored in the memory 1120, so that the computing device 1100 executes the code generation method shown in Figures 3, 5, 6, and 8, or enables the computing device 1100 to deploy the code generation device 1000.

[0219] Processor 1110 can be implemented in various forms, such as a CPU, or a combination of a CPU and a hardware chip. The hardware chip can be an ASIC, a programmable logic device (PLD), or a combination thereof. The PLD can be a CPLD, an FPGA, a GAL, or any combination thereof. Processor 1110 executes various types of digitally stored instructions, such as software or firmware programs stored in memory 1120, enabling computing device 1100 to provide various services.

[0220] The memory 1120 is used to store program code and is controlled for execution by the processor 1110. The program code may include one or more software modules, which may be the software modules provided in the embodiment of FIG10 , such as the acquisition module 1010, the problem decomposition module 1020, the knowledge retrieval module 1030, the code generation module 1040, and the sending module 1050. Optionally, the one or more software modules may also be the knowledge update module 1060, the first model training module 1070, and the second model training module 1080 provided in the embodiment of FIG10 (not shown in FIG11 ).

[0221] The memory 1120 may include a volatile memory, such as a random access memory (RAM); the memory 1120 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid-state drive (SSD); the memory 1120 may also include a combination of the above types.

[0222] The communication interface 1130 may be a wired interface (e.g., an Ethernet interface, a fiber optic interface, or other types of interfaces (e.g., an InfiniBand interface)) or a wireless interface (e.g., a cellular network interface or a wireless local area network interface) for communicating with other computing devices or apparatuses. The communication interface 1130 may utilize a protocol suite based on the Transmission Control Protocol / Internet Protocol (TCP / IP), such as the Remote Function Call (RFC) protocol, the Simple Object Access Protocol (SOAP) protocol, the Simple Network Management Protocol (SNMP) protocol, the Common Object Request Broker Architecture (CORBA) protocol, and distributed protocols.

[0223] Bus 1140 may be a Peripheral Component Interconnect Express (PCIe) bus, an Extended Industry Standard Architecture (EISA) bus, a Unified Bus (UBus or UB), a Compute Express Link (CXL), a Cache Coherent Interconnect for Accelerators (CCIX), or the like. Bus 1140 may be divided into an address bus, a data bus, a control bus, or the like. In addition to a data bus, bus 1140 may also include a power bus, a control bus, and a status signal bus. However, for clarity, various buses are labeled as bus 1140 in the figure. For ease of illustration, FIG11 uses only one thick line, but this does not mean that there is only one bus or one type of bus.

[0224] The computing device 1100 is used to execute the code generation method shown in FIG3 , FIG5 , FIG6 , and FIG8 . The specific implementation process is detailed in the above method embodiment and will not be repeated here.

[0225] It should be understood that computing device 1100 is only an example provided in an embodiment of the present application, and computing device 1100 may have more or fewer components than those shown in FIG. 11 , may combine two or more components, or may have different configurations of components.

[0226] The present application also provides a computing device cluster 1200, which can deploy the code generation apparatus 1000 shown in FIG10. The operations and / or functions of each module in the computing device cluster 1200 are respectively to implement the corresponding steps in the code generation method shown in FIG3, FIG5, FIG6, and FIG8.

[0227] As shown in FIG12 , the computing device cluster 1200 includes at least one computing device 1100. The memory 1120 in one or more computing devices 1100 in the computing device cluster may store the same instructions for executing the code generation method shown in FIG3 , FIG5 , FIG6 , and FIG8 . The computing device 1100 may be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device 1100 may also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.

[0228] In some possible implementations, the memory 1120 of one or more computing devices 1100 in the computing device cluster 1200 may also store partial instructions for executing the code generation methods shown in Figures 3, 5, 6, and 8. In other words, the combination of one or more computing devices 1100 can jointly execute instructions for executing the code generation methods shown in Figures 3, 5, 6, and 8.

[0229] It should be noted that the memory 1120 in different computing devices 1100 in the computing device cluster 1200 may store different instructions, each for executing part of the functions of the code generation apparatus 1000. That is, the instructions stored in the memory 1120 in different computing devices 1100 may implement the functions of one or more of the acquisition module 1010, the problem decomposition module 1020, the knowledge retrieval module 1030, the code generation module 1040, and the sending module 1050.

[0230] In some possible implementations, one or more computing devices 1100 in the computing device cluster 1200 can be connected via a network. The network can be a wide area network or a local area network, etc. Figure 13 shows a possible implementation. As shown in Figure 13, two computing devices 1100A and 1100B are connected via a network. Specifically, the connection to the network is made through the communication interface in each computing device. In this type of possible implementation, the memory 1120 in the computing device 1100A stores instructions for executing the functions of the acquisition module 1010, the problem decomposition module 1020 and the sending module 1050. At the same time, the memory 1120 in the computing device 1100B stores instructions for executing the functions of the knowledge retrieval module 1030 and the code generation module 1040.

[0231] The connection method between the computing device cluster 1200 shown in Figure 13 may be considered to be that the code generation method provided in the embodiment of the present application needs to be searched in the code knowledge base based on the solution steps of a large number of problems, and code generation needs to be performed based on a large number of problems. Therefore, it is considered to hand over the functions implemented by the knowledge retrieval module 1030 and the code generation module 1040 to the computing device 1100B for execution.

[0232] It should be understood that the functionality of the computing device 1100A shown in FIG13 may also be implemented by multiple computing devices 1100. Similarly, the functionality of the computing device 1100B may also be implemented by multiple computing devices 1100.

[0233] The present application also provides a computer program product comprising instructions, which may be software or a program product comprising instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the code generation method shown in Figures 3, 5, 6, and 8.

[0234] The present application also provides a computer-readable storage medium, which can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a high-density digital video disc (DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the code generation method shown in Figures 3, 5, 6, and 8.

[0235] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0236] In the above embodiments, it can be implemented in whole or in part by software, hardware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium, or a semiconductor medium.

[0237] The above is only a specific embodiment of the present application. Those skilled in the art may conceive of changes or substitutions based on the specific embodiment provided in this application, and all such changes or substitutions shall fall within the scope of protection of this application.

Claims

1. A code generation method, characterized in that: Applied to a code generation system, the code generation system includes a cloud computing platform and a terminal device, and the method includes: The cloud computing platform receives a code generation request carrying a first question sent by the terminal device; The cloud computing platform decomposes the first problem to obtain steps for solving the first problem; The cloud computing platform retrieves a code knowledge base based on each step in the solution to the first problem to obtain target code knowledge, wherein the target code knowledge includes code knowledge in the code knowledge base that matches each step in the solution to the first problem; The cloud computing platform inputs the solution steps of the first problem and the target code knowledge into a code generation model, and uses the code output by the code generation model as the target code, wherein the code generation model is obtained by using artificial intelligence AI technology to train the solution steps of multiple known problems, the code knowledge matching the solution steps of the multiple known problems, and the code for solving the multiple known problems, wherein the code for solving each known problem includes the code in the code knowledge matching the solution steps of each known problem; The cloud computing platform sends the target code to the terminal device.

2. The method according to claim 1, characterized in that The code knowledge base includes the language type to which each code knowledge in the code knowledge base belongs; The method further comprises: The cloud computing platform obtains a desired code language type of a first user, where the first user is a user of the terminal device; The cloud computing platform retrieves a code knowledge base based on each step in the solution steps of the first problem to obtain target code knowledge, wherein the target code knowledge includes code knowledge matched by each step in the solution steps of the first problem, including: The cloud computing platform retrieves a code knowledge base based on each step in the solution steps of the first problem and the expected code language type to obtain target code knowledge, wherein the target code knowledge includes code knowledge in the code knowledge base that has the same language type as the expected code language type and that matches each step in the solution steps of the first problem.

3. The method according to claim 1 or 2, characterized in that: The method further comprises: The cloud computing platform obtains information of a first user, queries a first corresponding relationship based on the information of the first user, and uses a prompt template corresponding to the information of the first user among multiple prompt templates as a target prompt template, wherein the first corresponding relationship indicates a corresponding relationship between multiple user information and the multiple prompt templates, the first user is a user of the terminal device, and the first user belongs to the multiple users; The cloud computing platform inputs the solution steps of the first problem and the target code knowledge into a code generation model, including: The cloud computing platform fills the solution steps of the first problem and the target code knowledge into the target prompt template; The cloud computing platform inputs the target prompt template into a code generation model.

4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: The cloud computing platform receives an update request for the code knowledge base sent by the terminal device; The cloud computing platform updates the code knowledge base based on the update request.

5. The method according to claim 4, characterized in that The update request carries new code knowledge; The cloud computing platform updates the code knowledge base based on the update request, including: The cloud computing platform adds the new code knowledge carried in the update request to the code knowledge base.

6. The method according to any one of claims 2 to 5, characterized in that: The language type to which the code knowledge in the code knowledge base belongs includes any one or more of the following: C language, C++ language, C# language, Java language, Python language, JavaScript language, Visual Basic language and Golang language.

7. The method according to any one of claims 1 to 6, characterized in that: The terminal device is installed with an integrated development environment IDE, and the code generation request is generated based on the first question by the IDE on the terminal device after receiving the first question and sent to the cloud computing platform.

8. A code generating device, characterized in that: Applied to a cloud computing platform, the cloud computing platform belongs to a code generation system, the code generation system also includes a terminal device, and the device includes: An acquisition module, configured to receive a code generation request carrying a first question sent by the terminal device; A problem decomposition module, used for decomposing the first problem to obtain solution steps for the first problem; A knowledge retrieval module, configured to retrieve a code knowledge base based on each step in the solution to the first problem to obtain target code knowledge, wherein the target code knowledge includes code knowledge in the code knowledge base that matches each step in the solution to the first problem; The code generation module is used to input the solution steps of the first problem and the target code knowledge into a code generation model, and use the code output by the code generation model as the target code. The code generation model is a solution model trained by artificial intelligence AI technology for multiple known problems. The code for solving each known problem includes the code in the code knowledge matching the solution step of each known problem; A sending module is used to send the target code to the terminal device.

9. The device according to claim 8, characterized in that The code knowledge base includes the language type to which each code knowledge in the code knowledge base belongs; The acquisition module is further used to acquire the desired code language type of a first user, where the first user is a user of the terminal device; The knowledge retrieval module is used to retrieve the code knowledge base based on each step in the solution steps of the first problem and the expected code language type to obtain target code knowledge, wherein the target code knowledge includes code knowledge in the code knowledge base that has the same language type as the expected code language type and matches each step in the solution steps of the first problem.

10. The device according to claim 8 or 9, characterized in that The acquisition module is further used to acquire information of a first user, and query a first corresponding relationship based on the information of the first user, and use a prompt template corresponding to the information of the first user among multiple prompt templates as a target prompt template, wherein the first corresponding relationship indicates a corresponding relationship between multiple user information and the multiple prompt templates, the first user is a user of the terminal device, and the first user belongs to the multiple users; The code generation module is specifically used for: Fill the solution steps of the first problem and the target code knowledge into the target prompt template; The target prompt template is input into the code generation model.

11. The device according to any one of claims 8 to 10, characterized in that The device also includes: a knowledge updating module; The acquisition module is further used to receive an update request for the code knowledge base sent by the terminal device; The knowledge updating module is used to update the code knowledge base based on the update request.

12. The device according to claim 11, characterized in that The update request carries new code knowledge; The knowledge updating module is used to add the new code knowledge carried in the update request to the code knowledge base.

13. The device according to any one of claims 8 to 12, characterized in that The language type to which the code knowledge in the code knowledge base belongs includes any one or more of the following: C language, C++ language, C# language, Java language, Python language, JavaScript language, Visual Basic language and Golang language.

14. The device according to any one of claims 8 to 13, characterized in that The terminal device is installed with an IDE, and the code generation request is generated based on the first question by the IDE on the terminal device after receiving the first question and sent to the acquisition module.

15. A computing device cluster, characterized in that: comprising at least one computing device, each computing device of the at least one computing device comprising a processor and a memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the method according to any one of claims 1 to 7.

16. A computer-readable storage medium, characterized in that: The method comprises computer program instructions. When the computer program instructions are executed by a computing device cluster, the computing device cluster performs the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Code generation method and device and computer readable storage medium

    CN119883269A

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

    CN114924721A

  • Code generation method and device, equipment and storage medium

    CN115048102A

  • Code generation method and device

    CN116719520A

  • Code processing model training method and device, electronic equipment and storage medium

    CN116820429A

Cited By

  • Internet of Things project end-to-end automatic generation method and device based on large language model

    CN122450466A