A method, apparatus and system for code generation
By employing parallel recall and group analysis methods, high-quality code is generated, addressing the issue of poor code quality generated from large models with complex modifications and large-scale historical codebases, thereby improving the efficiency and accuracy of code generation.
Patent Information
- Application Number
- CN202510109885.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2045-01-21
AI Technical Summary
In existing technologies, when generating code for large models, it is difficult to handle complex modifications and large-scale historical codebases, resulting in poor quality of the generated code.
By recalling multiple datasets in parallel, a set of target language files is generated. The summary results are then grouped and subjected to CoT analysis. The selected file set is then filtered out for a second data recall to generate complete contextual information. Finally, the data is input into a large language model to generate the target code.
It improves the quality and efficiency of code generation from large models, making it suitable for high-frequency demand scenarios and complex projects in small and medium-sized applications.
Smart Images

Figure CN120085871B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, more particularly, to a code generation method, device and system. BACKGROUND
[0002] In the software development process, artificial intelligence (AI) large models are often used to assist in the development of applications, for example, high-frequency requirements of small and medium-sized applications are generated by large models to generate code.
[0003] In the prior art, there are limitations when generating code using large models, which can only handle simple requirements and small-scale code libraries, and when dealing with complex modifications and large-scale historical code libraries, the quality of the generated code is poor.
[0004] To sum up, how to improve the quality of the code generated by the large model is a problem to be solved at present. SUMMARY
[0005] Therefore, the embodiments of the present application provide a code generation method, device and system, which can improve the quality of the code generated by the large model.
[0006] In a first aspect, the embodiments of the present application provide a code generation method, which comprises:
[0007] Obtain user demand information;
[0008] Recall a plurality of first data in at least two databases in parallel according to the user demand information, and generate a target language file set, wherein the target language file set includes the plurality of first data;
[0009] Obtain a file corresponding to each of the first data in the target language file set, and generate an abstract result set, wherein the abstract result set includes an abstract corresponding to each of the files;
[0010] Group the abstract result set, perform pre-set CoT analysis on each group of abstracts, select a selected file in each group of abstracts, and generate a selected file set;
[0011] Recall second data according to each selected file in the selected file set, and generate a recall result set, wherein the recall result set includes a plurality of second data;
[0012] Generate complete context information according to the recall result set;
[0013] Input the complete context information into a first large language model to generate target code.
[0014] Optionally, the step of retrieving multiple first data in parallel from at least two databases based on the user demand information to generate a target language file set specifically includes:
[0015] Based on the user demand information, multiple first data are recalled in parallel from the code library, the change request history data set, and the interface library. The first data is a first code fragment, change request data, or implementation class data.
[0016] The multiple first data are combined into a target language file set.
[0017] Optionally, obtaining the file corresponding to each of the first data in the target language file set and generating a summary result set specifically includes:
[0018] Obtain the file corresponding to each of the first data in the target language file set;
[0019] Each file is compressed in parallel, generating multiple digests;
[0020] The multiple summaries are combined into the summary result set.
[0021] Optionally, the step of performing a pre-set CoT analysis on each group of summaries to select the chosen files from each group of summaries specifically includes:
[0022] Each set of summaries is input into a second large-scale language model. Based on the pre-set CoT (Cooperation of Thought) analysis in the second large-scale language model, the selected files in each set of summaries are filtered out.
[0023] Optionally, the pre-set CoT analysis of the thought chain specifically includes:
[0024] One or more of the following: requirements analysis, historical change analysis, call analysis, and planning analysis.
[0025] Optionally, the step of performing a second data retrieval based on each selected file in the selected file set to generate a retrieval result set specifically includes:
[0026] For each selected file, multiple second data items are retrieved from the codebase in parallel, wherein the second data items are second code snippets;
[0027] The multiple sets of second data are combined to form a recall result set.
[0028] Optionally, generating complete context information based on the recall result set specifically includes:
[0029] Based on the recall result set and the pre-set prompt word template, generate complete context information.
[0030] Optionally, based on the recall result set and the pre-set prompt word template, complete context information is generated, specifically including:
[0031] The recall result set and the pre-set prompt word template are input into the third large-scale language model;
[0032] Based on the third large-scale language model, demand analysis, historical analysis, call analysis, incremental analysis, and execution plan formulation are performed on the recall result set and the pre-set prompt word template to generate complete context information.
[0033] Secondly, embodiments of the present invention provide a method for code generation, the method comprising:
[0034] Obtain user demand information;
[0035] Based on the user demand information, multiple first data are retrieved in parallel from at least two databases to generate a target language file set, wherein the target language file set includes the multiple first data;
[0036] Obtain the file corresponding to each of the first data in the target language file set, and generate a summary result set, wherein the summary result set includes the summary corresponding to each file;
[0037] The summary results are grouped, and a pre-set CoT analysis of each group of summaries is performed to filter out the selected files in each group of summaries and generate a set of selected files.
[0038] The selected set of files is input into the first large-scale language model to generate target code.
[0039] Thirdly, embodiments of the present invention provide a code generation method, the method comprising:
[0040] Obtain user demand information;
[0041] Based on the user demand information, multiple first data are sequentially retrieved from at least two databases to generate a target language file set, wherein the target language file set includes the multiple first data;
[0042] Obtain the file corresponding to each of the first data in the target language file set, and generate a summary result set, wherein the summary result set includes the summary corresponding to each file;
[0043] The summary results are grouped, and a pre-set CoT analysis of each group of summaries is performed to filter out the selected files in each group of summaries and generate a set of selected files.
[0044] A second data recall is performed on each selected file in the selected file set to generate a recall result set, wherein the recall result set includes multiple second data;
[0045] Generate complete context information based on the recall result set;
[0046] The complete context information is input into the first large-scale language model to generate target code.
[0047] Fourthly, embodiments of the present invention provide a code generation apparatus, the apparatus comprising:
[0048] The acquisition unit is used to acquire user demand information;
[0049] The recall unit is used to recall multiple first data in parallel in at least two databases based on the user demand information, and generate a target language file set, wherein the target language file set includes the multiple first data.
[0050] A generation unit is configured to acquire the file corresponding to each of the first data in the target language file set and generate a summary result set, wherein the summary result set includes a summary corresponding to each of the files;
[0051] The generation unit is also used to group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a set of selected files.
[0052] The recall unit is further configured to perform a second data recall based on each selected file in the selected file set, and generate a recall result set, wherein the recall result set includes multiple second data.
[0053] The generation unit is further configured to generate complete context information based on the recall result set;
[0054] The generation unit is also used to input the complete context information into a first large-scale language model to generate target code.
[0055] Fifthly, embodiments of the present invention provide a code generation apparatus, the apparatus comprising:
[0056] The acquisition unit is used to acquire user demand information;
[0057] The recall unit is used to recall multiple first data in parallel in at least two databases based on the user demand information, and generate a target language file set, wherein the target language file set includes the multiple first data.
[0058] A generation unit is configured to acquire the file corresponding to each of the first data in the target language file set and generate a summary result set, wherein the summary result set includes a summary corresponding to each of the files;
[0059] The generation unit is also used to group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a set of selected files.
[0060] The generation unit is also used to input the selected file set into a first large-scale language model to generate target code.
[0061] Sixthly, embodiments of the present invention provide a code generation apparatus, the apparatus comprising:
[0062] The acquisition unit is used to acquire user demand information;
[0063] The recall unit is used to sequentially recall multiple first data in at least two databases according to the user demand information, and generate a target language file set, wherein the target language file set includes the multiple first data;
[0064] A generation unit is configured to acquire the file corresponding to each of the first data in the target language file set and generate a summary result set, wherein the summary result set includes a summary corresponding to each of the files;
[0065] The generation unit is also used to group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a set of selected files.
[0066] The recall unit is further configured to perform a second data recall based on each selected file in the selected file set, and generate a recall result set, wherein the recall result set includes multiple second data.
[0067] The generation unit is further configured to generate complete context information based on the recall result set;
[0068] The generation unit is also used to input the complete context information into a first large-scale language model to generate target code.
[0069] In a seventh aspect, embodiments of the present invention provide a code generation system, the system comprising:
[0070] Terminal-side and cloud server;
[0071] The terminal side is used to receive user demand information and send the user demand information to the cloud server;
[0072] The cloud server is used to execute the method as described in the first aspect, any possible version of the first aspect, the second aspect, or the third aspect, and to send the generated target code to the terminal side.
[0073] In a seventh aspect, embodiments of the present invention provide an electronic device, including a memory and a processor, the memory being used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in any one of the first aspect, any possible first aspect, the second aspect, or the third aspect.
[0074] Eighthly, embodiments of the present invention provide a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the method as described in any one of the first aspect, any possible first aspect, the second aspect, or the third aspect.
[0075] In this embodiment of the invention, user demand information is obtained; multiple first data points are retrieved in parallel from at least two databases based on the user demand information to generate a target language file set, wherein the target language file set includes the multiple first data points; files corresponding to each first data point in the target language file set are obtained to generate a summary result set, wherein the summary result set includes a summary corresponding to each file; the summary result set is grouped, and a pre-set CoT (Cooperation of Thought) analysis is performed on each group of summaries to select selected files in each group of summaries, generating a selected file set; second data retrieval is performed based on each selected file in the selected file set to generate a recall result set, wherein the recall result set includes multiple second data points; complete context information is generated based on the recall result set; and the complete context information is input into a first large-scale language model to generate target code. This method can improve the quality of the code generated by the large model. Attached Figure Description
[0076] The above and other objects, features and advantages of the present invention will become clearer from the following description of embodiments of the invention with reference to the accompanying drawings, in which:
[0077] Figure 1 This is a flowchart of a code generation method according to an embodiment of the present invention;
[0078] Figure 2 This is a flowchart of a code generation method according to an embodiment of the present invention;
[0079] Figure 3 This is a flowchart of another code generation method in an embodiment of the present invention;
[0080] Figure 4 This is a flowchart of another code generation method in an embodiment of the present invention;
[0081] Figure 5 This is a flowchart of another code generation method in an embodiment of the present invention;
[0082] Figure 6 This is a flowchart of a code generation method according to an embodiment of the present invention;
[0083] Figure 7 This is a flowchart of another code generation method in an embodiment of the present invention;
[0084] Figure 8 This is a schematic diagram of a code generation device according to an embodiment of the present invention;
[0085] Figure 9 This is a schematic diagram of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0086] The present application is described below based on embodiments, but it is not limited to these embodiments. In the detailed description of the present application below, certain specific details are described in detail. Those skilled in the art can fully understand the present application without these details. To avoid obscuring the substance of the present application, well-known methods, processes, flows, elements, and circuits are not described in detail.
[0087] Furthermore, those skilled in the art should understand that the accompanying drawings provided herein are for illustrative purposes only and are not necessarily drawn to scale.
[0088] Unless the context explicitly requires it, words such as "including" or "contains" throughout the application should be interpreted as including rather than exclusive or exhaustive; that is, meaning "including but not limited to".
[0089] In the description of this application, it should be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0090] In existing technologies, for small and medium-sized applications, due to their smaller scale and fewer developers, AI-assisted solutions are needed to develop these applications and meet user needs. These AI-assisted solutions refer to using artificial intelligence technology to assist in software development, such as using large models to generate code that meets user requirements. However, there are limitations to using large models to generate code. For example, current AI-driven code implementation solutions, such as RAG code refactoring and RAG front-end page code generation, can only handle simple requirements and small-scale codebases. When dealing with complex modifications and large-scale historical codebases, the generated code quality is poor. Therefore, improving the quality of code generated by large models is a problem that needs to be solved.
[0091] In this embodiment of the invention, the large model can also be called an Artificial Intelligence (AI) model or a Large Language Model (LLM). The large language model is a deep learning model based on a transformer architecture that can process and generate natural language text. It is usually trained on a large amount of text data and has the ability to understand and generate language. It is widely used in dialogue systems, text generation and other natural language processing tasks.
[0092] In this embodiment of the invention, to solve the above problems, a code generation method is proposed, specifically as follows: Figure 1 As shown, the method includes:
[0093] Step S101: Obtain user demand information.
[0094] Specifically, users can input their requirements into the front-end interface of the pre-designed code generation system. For example, if a user's requirement is "find all projects submitted by a user within a year", the code generation system will obtain the user's requirements after the user inputs the above requirements. The requirements here are only for illustrative purposes and should be determined according to the actual situation.
[0095] Step S102: Based on the user demand information, retrieve multiple first data in parallel from at least two databases to generate a target language file set.
[0096] The target language file set includes multiple sets of first data.
[0097] In one possible implementation, the first data is a first code snippet, change request data, or implementation class data. The step of recalling the first data based on the user demand information and generating a target language file set specifically includes: recalling multiple first data in the code library, the change request historical data set, and the interface library based on the user demand information, and combining the multiple first data into a target language file set.
[0098] In one possible implementation, the target language can be Java, TypeScript, Kotlin, etc., depending on the specific circumstances.
[0099] Specifically, such as Figure 2 As shown, after receiving the requirement information sent by the user, the code generation system performs the first data retrieval in parallel, which includes retrieving the first code fragment in the code library, retrieving change request data in the historical data set of change requests (CR), and retrieving implementation class data in the interface library.
[0100] Specifically, when recalling the first code snippet in the code repository, the code repository's encoding is first determined, and then the code snippet related to the requirement information is retrieved from the code repository corresponding to the encoding as the first code snippet. When recalling change request data in the CR historical data set, the code repository's encoding is first determined, and then the CR historical data set is determined from the code repository corresponding to the encoding. Then, a similarity scoring service is performed on the historical data in the CR historical data set, and the top 5 ranked code review historical data are used as change request data. Alternatively, the top 3, top 8, or top 10 ranked code review historical data can be selected as change request data, depending on the actual situation. When recalling implementation class data in the interface library, the interface library is first determined in the code platform, and then the implementation class is retrieved from the interface library. The above code generation system integrates the retrieved first code snippet, change request data, or implementation (impl) class data to generate a set of Java files. The impl class refers to a concrete class that implements a certain interface or abstract class.
[0101] In this embodiment of the invention, both the code library and the interface library are stored in the code platform. Through the above-mentioned multi-dimensional parallel recall, the project structure and history can be fully understood, the recall speed is improved, and richer information is provided for subsequent steps.
[0102] Step S103: Obtain the file corresponding to each of the first data in the target language file set, and generate a summary result set.
[0103] The summary result set includes a summary corresponding to each of the files.
[0104] Specifically, the file corresponding to each of the first data in the target language file set is obtained; each file is compressed in parallel to generate multiple summaries; and the multiple summaries are combined into the summary result set.
[0105] For example, such as Figure 3 As described above, after obtaining multiple files corresponding to the target language file set, these files are processed in parallel by multiple threads in a thread pool. Each thread extracts a summary from one file, obtaining the key structural information of each file. For example, assuming the target language is Java and the target language file set is a Java file set, thread 1 extracts a summary from Java file 1, generating summary 1; thread 2 extracts a summary from Java file 2, generating summary 2; thread 3 extracts a summary from Java file 3, generating summary 3; and so on, with thread n extracting a summary from Java file n, generating summary n. Summary 1, summary 2, summary 3, and summary n are then merged to generate a summary result set. The key structural information includes class signatures, member variables, methods, and inner static classes. This method reduces processing time and provides more structured and refined information, helping subsequent large-scale models to more accurately understand file structure and function.
[0106] Step S104: Group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a selected file set.
[0107] In one possible implementation, the pre-set Chain of Thought (CoT) analysis for each set of summaries to filter out selected files specifically includes: inputting each set of summaries into a second large-scale language model, and filtering out selected files for each set of summaries based on the prompts corresponding to the pre-set Chain of Thought (CoT) analysis in the second large-scale language model. The pre-set Chain of Thought (CoT) analysis specifically includes one or more of the following: requirements analysis, historical change analysis, call analysis, and plan analysis. The CoT analysis refers to prompts set by the user to guide the large-scale prediction model in reflecting on existing code; the specific settings are determined based on the actual situation.
[0108] Specifically, such as Figure 4As shown, the files in the summary result set are divided into multiple groups. Assuming the summary result set includes 30 summary files, with 10 summary files per group, there are three groups in total. These three groups of summary files are processed in parallel. Each group of summary files (also called each summary group) undergoes a thought chain analysis. This grouping is only an example; the actual grouping should be based on the specific situation. The CoT analysis includes requirements analysis, historical change analysis, call analysis, and plan analysis. After the CoT analysis, usable files are selected from each group of summaries. The selected files in each group are combined to generate a set of selected files. Specifically, Group 1 undergoes CoT analysis to obtain the selected files in Group 1; Group 2 undergoes CoT analysis to obtain the selected files in Group 2; Group 3 undergoes CoT analysis to obtain the selected files in Group 3; and the selected files from Group 1, Group 2, and Group 3 are combined to generate a set of selected files.
[0109] The parallel CoT analysis described above not only improves processing speed but also significantly enhances the accuracy of summary file selection through fine-grained analysis, effectively solving the selection bias problem in large-scale file processing and ensuring that no potentially useful summary files are overlooked.
[0110] Step S105: Input the selected file set into the first large-scale language model to generate target code.
[0111] In this embodiment of the invention, the above method can quickly generate target code, and parallel recall improves the generation speed and quality of the target code. Furthermore, the quality of the target code can be further improved, specifically as follows: Figure 5 As shown, after step S104, the specific steps include:
[0112] Step S106: Perform a second data recall for each selected file in the selected file set to generate a recall result set.
[0113] The recall result set includes multiple second data.
[0114] Specifically, such as Figure 6As shown, for multiple selected files in the selected file set, the multiple selected files are processed in parallel by multiple threads in a thread pool. Each thread retrieves multiple second data for one selected file from the code library. For example, thread 1 retrieves code for selected file 1 from the code library, generating at least one code fragment 1; thread 2 retrieves code for selected file 2 from the code library, generating at least one code fragment 2; thread 3 retrieves code for selected file 3 from the code library, generating at least one code fragment 3; and so on, thread n retrieves code for selected file n from the code library, generating at least one code fragment n. The code fragments 1, 2, 3, and n are merged to generate a retrieval result set. Here, the second data is the second code fragment. The multiple second data are combined to form the retrieval result set, and the retrieval results for each selected file are aggregated to generate the retrieval result set.
[0115] Because the number of fragments recalled during the first data retrieval is limited, the number of fragments recalled for each file is relatively small. After file filtering, only selected files remain for the second data retrieval. Although the number limit is the same, the number of fragments allocated to each selected file is greater than the number of fragments in the first data retrieval. This not only significantly reduces the retrieval time but also provides richer and more relevant contextual information for each selected file.
[0116] Step S107: Generate complete context information based on the recall result set.
[0117] Specifically, based on the recall result set and the pre-set prompt word template, complete context information is generated.
[0118] In one possible implementation, generating complete context information based on the recall result set and the pre-set prompt word template specifically includes: inputting the recall result set and the pre-set prompt word template into a third large-scale language model; performing requirement analysis, historical analysis, call analysis, incremental analysis, and execution plan formulation on the recall result set and the pre-set prompt word template based on the third large-scale language model, specifically obtaining the requirement analysis results, historical analysis results, call analysis results, and incremental analysis results respectively, and finally generating complete context information through execution plan formulation; wherein, the above historical analysis and call analysis can be executed in parallel to improve efficiency.
[0119] In this embodiment of the invention, through the above-described process of constructing contextual information, a comprehensive and coherent contextual information can be created, enabling the AI model to better understand requirements, project history, and code structure, thereby generating higher quality code that is more in line with the project style.
[0120] Step S108: Input the complete context information into the first large-scale language model to generate target code.
[0121] In this embodiment of the invention, each of the above steps can be regarded as a step that different modules in the code generation system need to perform. Modularizing the code generation system makes it easy to adjust and expand the code generation system for different projects or needs.
[0122] Through the above embodiments, a multi-dimensional parallel recall mechanism was implemented, improving the comprehensiveness and speed of recall; parallel Java file summary extraction uses a thread pool to process multiple Java files in parallel, extracting key structural information to generate summaries, preserving complete information while reducing context usage; grouped parallel file selection: files are grouped and subjected to CoT analysis in parallel, including requirements analysis and historical change analysis, improving the accuracy of large-scale file processing; parallel secondary recall performs separate code recall for each selected file in parallel, enriching context information; structured context construction is designed, including a structured context construction process with steps such as requirements analysis and historical analysis, with some steps using parallel processing to improve processing efficiency; specialized optimization for small and medium-sized applications focuses on the high-frequency demand scenarios of small and medium-sized applications, utilizing their characteristics for targeted optimization; effective utilization of historical CR data integrates historical code review data into the solution, improving the relevance and accuracy of generated code; in summary, through the above processes and their corresponding advantages, a highly efficient and accurate AI-assisted development system is constructed, improving the quality and efficiency of generated code, suitable for high-frequency demand scenarios of small and medium-sized applications, and also suitable for large-scale and complex projects.
[0123] In one possible implementation, if the first data is retrieved sequentially, although the retrieval speed will be reduced, the quality of the generated target code will not be affected. The specific process is as follows: Figure 7 As shown, it includes the following steps:
[0124] Step S701: Obtain user requirement information.
[0125] Step S702: Based on the user demand information, retrieve multiple first data in sequence from at least two databases to generate a target language file set.
[0126] The target language file set includes the plurality of first data.
[0127] Specifically, based on the user requirement information, the first code snippet, change request data, or implementation class data are retrieved sequentially from the code library, the change request history data set, and the interface library. The order of the code library, the change request history data set, and the interface library can be arbitrarily changed and is determined according to the actual situation.
[0128] Step S703: Obtain the file corresponding to each of the first data in the target language file set, and generate a summary result set.
[0129] The summary result set includes a summary corresponding to each of the files.
[0130] Step S704: Group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a selected file set.
[0131] Step S705: Perform a second data recall for each selected file in the selected file set to generate a recall result set, wherein the recall result set includes multiple second data.
[0132] Step S706: Generate complete context information based on the recall result set.
[0133] Step S707: Input the complete context information into the first large-scale language model to generate target code.
[0134] In this embodiment of the invention, a code generation system is designed, the system comprising: a terminal side and a cloud server;
[0135] The terminal side is used to receive user demand information and send the user demand information to the cloud server; the cloud server is used to execute the method described in any one of the above embodiments and send the generated target code to the terminal side.
[0136] In this embodiment of the invention, a code generation apparatus is provided, such as... Figure 8 As shown, it specifically includes: an acquisition unit 801, a recall unit 802, and a generation unit 803;
[0137] The acquisition unit 801 is used to acquire user demand information; the recall unit 802 is used to recall multiple first data in parallel in at least two databases according to the user demand information, and generate a target language file set, wherein the target language file set includes the multiple first data; the generation unit 803 is used to acquire the file corresponding to each first data in the target language file set, and generate a summary result set, wherein the summary result set includes a summary corresponding to each file; the generation unit 803 is further used to group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a selected file set; the recall unit 802 is further used to perform second data recall according to each selected file in the selected file set, and generate a recall result set, wherein the recall result set includes multiple second data; the generation unit 803 is further used to generate complete context information according to the recall result set; the generation unit 803 is further used to input the complete context information into a first large-scale language model to generate target code.
[0138] Furthermore, the recall unit is specifically used for:
[0139] Based on the user demand information, multiple first data are recalled in parallel from the code library, the change request history data set, and the interface library. The first data is a first code fragment, change request data, or implementation class data.
[0140] The multiple first data are combined into a target language file set.
[0141] Furthermore, the generation unit is specifically used for:
[0142] Obtain the file corresponding to each of the first data in the target language file set;
[0143] Each file is compressed in parallel, generating multiple digests;
[0144] The multiple summaries are combined into the summary result set.
[0145] Furthermore, the generation unit is specifically used for:
[0146] Each set of summaries is input into a second large-scale language model. Based on the pre-set CoT (Cooperation of Thought) analysis in the second large-scale language model, the selected files in each set of summaries are filtered out.
[0147] Furthermore, the pre-set CoT analysis of the thought chain specifically includes:
[0148] One or more of the following: requirements analysis, historical change analysis, call analysis, and planning analysis.
[0149] Furthermore, the recall unit is specifically used for:
[0150] For each selected file, multiple second data items are retrieved from the codebase in parallel, wherein the second data items are second code snippets;
[0151] The multiple sets of second data are combined to form a recall result set.
[0152] Furthermore, the generation unit is specifically used for:
[0153] Based on the recall result set and the pre-set prompt word template, generate complete context information.
[0154] Furthermore, the generation unit is specifically used for:
[0155] The recall result set and the pre-set prompt word template are input into the third large-scale language model;
[0156] Based on the third large-scale language model, demand analysis, historical analysis, call analysis, incremental analysis, and execution plan formulation are performed on the recall result set and the pre-set prompt word template to generate complete context information.
[0157] Figure 9 This is a schematic diagram of the structure of the electronic device described in an embodiment of the present invention. Figure 9 As shown, it includes a general computer hardware architecture, which includes at least a processor 901 and a memory 902. The processor 901 and the memory 902 are connected via a bus 903. The memory 902 is adapted to store instructions or programs executable by the processor 901. The processor 901 can be a standalone microprocessor or a collection of one or more microprocessors. Thus, the processor 901 executes the instructions stored in the memory 902 to perform the method flow of the embodiments of the present invention as described above, thereby realizing data processing and control of other devices. The bus 903 connects the above-mentioned components together, and also connects the above-mentioned components to a display controller 904, a display device, and an input / output (I / O) device 905. The input / output (I / O) device 905 can be a mouse, keyboard, modem, network interface, touch input device, motion-sensing input device, printer, and other devices known in the art. Typically, the input / output device 905 is connected to the system via an input / output (I / O) controller 906.
[0158] The instructions stored in memory 902 are executed by at least one processor 901 to achieve the following: acquiring user demand information; retrieving multiple first data in parallel from at least two databases based on the user demand information to generate a target language file set, wherein the target language file set includes the multiple first data; acquiring the file corresponding to each first data in the target language file set to generate a summary result set, wherein the summary result set includes a summary corresponding to each file; grouping the summary result set, performing a pre-set CoT analysis on each group of summaries, filtering out selected files in each group of summaries, and generating a selected file set; retrieving second data based on each selected file in the selected file set to generate a recall result set, wherein the recall result set includes multiple second data; generating complete context information based on the recall result set; and inputting the complete context information into a first large-scale language model to generate target code.
[0159] Specifically, the electronic device includes: one or more processors 901 and a memory 902. Figure 9 Take processor 901 as an example. Processor 901 and memory 902 can be connected via a bus or other means. Figure 9 Taking a bus connection as an example, memory 902, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Processor 901 executes various functional applications and data processing of the device by running the non-volatile software programs, instructions, and modules stored in memory 902, thereby implementing the aforementioned method of deterministic code generation.
[0160] Memory 902 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; the data storage area may store an option list, etc. Furthermore, memory 902 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 902 may optionally include memory remotely located relative to processor 901, and these remote memories may be connected to external devices via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0161] One or more modules are stored in memory 902, and when executed by one or more processors 901, they execute the code generation method in any of the above method embodiments.
[0162] As those skilled in the art will recognize, various aspects of the embodiments of the present invention can be implemented as a system, method, or computer program product. Therefore, various aspects of the embodiments of the present invention can take the form of a completely hardware implementation, a completely software implementation (including firmware, resident software, microcode, etc.), or an implementation combining software and hardware aspects, which may generally be referred to herein as a "circuit," "module," or "system." Furthermore, various aspects of the embodiments of the present invention can take the form of a computer program product implemented in one or more computer-readable media having computer-readable program code implemented thereon.
[0163] Any combination of one or more computer-readable media can be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example, (but not limited to) an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination thereof. More specific examples (not an exhaustive list) of computer-readable storage media will include: an electrical connection having one or more wires, a portable computer floppy disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable optical disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the context of embodiments of the present invention, a computer-readable storage medium can be any tangible medium capable of containing or storing a program used by or in conjunction with an instruction execution system, device, or apparatus.
[0164] Computer-readable signal media may include propagated digital signals having computer-readable program code implemented therein, such as in baseband or as part of a carrier wave. Such propagated signals may take any of a variety of forms, including, but not limited to, electromagnetic, optical, or any suitable combination thereof. A computer-readable signal medium may be any computer-readable medium that is not a computer-readable storage medium and can communicate, propagate, or transmit a program used by or in conjunction with an instruction execution system, device, or apparatus.
[0165] Program code implemented on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, fiber optic cable, RF, or any suitable combination thereof.
[0166] Computer program code for performing operations relating to various aspects of embodiments of the present invention can be written in any combination of one or more programming languages, including: object-oriented programming languages such as Java, Smalltalk, C++, etc.; and conventional procedural programming languages such as the "C" programming language or similar programming languages. The program code can be executed as a standalone software package entirely on the user's computer, partially on the user's computer, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet provided by an Internet service provider).
[0167] The flowchart illustrations and / or block diagrams of the methods, apparatus (systems), and computer program products according to embodiments of the present invention describe various aspects of the embodiments of the present invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus to produce a machine such that the instructions (executed via the processor of the computer or other programmable data processing apparatus) create means for implementing the functions / actions specified in the flowchart and / or block diagram blocks or blocks.
[0168] These computer program instructions may also be stored in a computer-readable medium that can direct a computer, other programmable data processing apparatus or other means to operate in a particular manner, such that the instructions stored in the computer-readable medium produce an article of writing that includes instructions that implement the functions / actions specified in flowchart and / or block diagram blocks or blocks.
[0169] Computer program instructions may also be loaded onto a computer, other programmable data processing apparatus or other device to cause a series of operable steps to be performed on the computer, other programmable apparatus or other device to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide for implementing the functions / actions specified in flowchart and / or block diagram blocks or blocks.
[0170] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
[0171] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of such data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding access points are provided for users to choose to authorize or refuse processing. A user's refusal to process personal information beyond what is necessary for basic functions will not affect the user's use of basic functions.
Claims
1. A method for code generation, characterized in that, The method includes: Obtain user demand information; Based on the user demand information, multiple first data are recalled in parallel from the code library, the change request history data set, and the interface library. The multiple first data are combined into a target language file set, wherein the target language file set includes the multiple first data, and the first data is a first code snippet, change request data, or implementation class data. Obtain the file corresponding to each of the first data in the target language file set, and generate a summary result set, wherein the summary result set includes the summary corresponding to each file; The summary results are grouped, and a pre-set CoT analysis of each group of summaries is performed to filter out the selected files in each group of summaries and generate a set of selected files. For each selected file in the selected file set, multiple second data are recalled in parallel in the code library, and the multiple second data are combined into a recall result set, wherein the recall result set includes multiple second data, and the second data is a second code fragment; Generate complete context information based on the recall result set; The complete context information is input into the first large-scale language model to generate target code.
2. The method according to claim 1, characterized in that, The step of obtaining the file corresponding to each of the first data in the target language file set and generating a summary result set specifically includes: Obtain the file corresponding to each of the first data in the target language file set; Each file is compressed in parallel, generating multiple digests; The multiple summaries are combined into the summary result set.
3. The method according to claim 1, characterized in that, The step of performing a pre-set CoT (Cooperation of Thought) analysis on each group of summaries to select the chosen files from each group of summaries specifically includes: Each set of summaries is input into a second large-scale language model. Based on the CoT analysis of the pre-set thought chain in the second large-scale language model, the selected files in each set of summaries are filtered out.
4. The method according to claim 1, characterized in that, The pre-set CoT analysis specifically includes: One or more of the following: requirements analysis, historical change analysis, call analysis, and planning analysis.
5. The method according to claim 1, characterized in that, The step of generating complete context information based on the recall result set specifically includes: Based on the recall result set and the pre-set prompt word template, generate complete context information.
6. The method according to claim 5, characterized in that, Based on the recall result set and the pre-set prompt word template, complete context information is generated, specifically including: The recall result set and the pre-set prompt word template are input into the third large-scale language model; Based on the third large-scale language model, demand analysis, historical analysis, call analysis, incremental analysis, and execution plan formulation are performed on the recall result set and the pre-set prompt word template to generate complete context information.
7. A method for code generation, characterized in that, The method includes: Obtain user demand information; Based on the user demand information, multiple first data are recalled in parallel from the code library, the change request history data set, and the interface library. The multiple first data are combined into a target language file set, wherein the target language file set includes the multiple first data, wherein the first data is a first code snippet, change request data, or implementation class data. Obtain the file corresponding to each of the first data in the target language file set, and generate a summary result set, wherein the summary result set includes the summary corresponding to each file; The summary results are grouped, and a pre-set CoT analysis of each group of summaries is performed to filter out the selected files in each group of summaries and generate a set of selected files. The selected set of files is input into the first large-scale language model to generate target code.
8. A method for code generation, characterized in that, The method includes: Obtain user demand information; Based on the user demand information, multiple first data are sequentially retrieved from the code library, the change request history data set, and the interface library to generate a target language file set. The target language file set includes the multiple first data, which are first code snippets, change request data, or implementation class data. Obtain the file corresponding to each of the first data in the target language file set, and generate a summary result set, wherein the summary result set includes the summary corresponding to each file; The summary results are grouped, and a pre-set CoT analysis of each group of summaries is performed to filter out the selected files in each group of summaries and generate a set of selected files. For each selected file in the selected file set, multiple second data are recalled in parallel in the code library, and the multiple second data are combined into a recall result set, wherein the recall result set includes multiple second data, and the second data is a second code fragment; Generate complete context information based on the recall result set; The complete context information is input into the first large-scale language model to generate target code.
9. A code generation apparatus, characterized in that, The device includes: The acquisition unit is used to acquire user demand information; The recall unit is used to recall multiple first data in parallel from the code library, the change request history data set and the interface library according to the user demand information, and to form a target language file set from the multiple first data. The target language file set includes the multiple first data, and the first data is a first code fragment, change request data or implementation class data. A generation unit is configured to acquire the file corresponding to each of the first data in the target language file set and generate a summary result set, wherein the summary result set includes a summary corresponding to each of the files; The generation unit is also used to group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a set of selected files. The recall unit is further configured to recall multiple second data in parallel in the code library for each selected file in the selected file set, and to form a recall result set of the multiple second data, wherein the recall result set includes multiple second data, and the second data is a second code fragment; The generation unit is further configured to generate complete context information based on the recall result set; The generation unit is also used to input the complete context information into a first large-scale language model to generate target code.
10. A code generation apparatus, characterized in that, The device includes: The acquisition unit is used to acquire user demand information; The recall unit is used to recall multiple first data in parallel from the code library, the change request history data set and the interface library according to the user demand information, and to form a target language file set from the multiple first data. The target language file set includes the multiple first data, and the first data is a first code fragment, change request data or implementation class data. A generation unit is configured to acquire the file corresponding to each of the first data in the target language file set and generate a summary result set, wherein the summary result set includes a summary corresponding to each of the files; The generation unit is also used to group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a set of selected files. The generation unit is also used to input the selected file set into a first large-scale language model to generate target code.
11. A code generation apparatus, characterized in that, The device includes: The acquisition unit is used to acquire user demand information; The recall unit is used to recall multiple first data in the code library, the change request history data set and the interface library in sequence according to the user demand information, and generate a target language file set, wherein the target language file set includes the multiple first data, and the first data is a first code fragment, change request data or implementation class data; A generation unit is configured to acquire the file corresponding to each of the first data in the target language file set and generate a summary result set, wherein the summary result set includes a summary corresponding to each of the files; The generation unit is also used to group the summary result set, perform a pre-set CoT analysis on each group of summaries, filter out the selected files in each group of summaries, and generate a set of selected files. The recall unit is further configured to recall multiple second data in parallel in the code library for each selected file in the selected file set, and to form a recall result set of the multiple second data, wherein the recall result set includes multiple second data, and the second data is a second code fragment; The generation unit is further configured to generate complete context information based on the recall result set; The generation unit is also used to input the complete context information into a first large-scale language model to generate target code.
12. A code generation system, characterized in that, The system includes: Terminal-side and cloud server; The terminal side is used to receive user demand information and send the user demand information to the cloud server; The cloud server is used to execute the method of any one of claims 1-8 and send the generated target code to the terminal side.
Citation Information
Patent Citations
Method and system for automatically generating reusable API based on code snippets
CN117892031A
Code generation method and device, equipment and storage medium
CN119271211A