Component generation method, device, equipment and computer program product
By inputting the code of the component to be detected to the security code agent for code splitting and defect positioning, the context search and rearrangement technology is used to solve the problem of inaccurate identification of code defects in the existing technology, and efficient and accurate code correction and security improvement are achieved.
Patent Information
- Application Number
- CN202510029348.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-07
- Publication Date
- 2025-04-18
AI Technical Summary
The existing component generation method is not accurate enough to identify code defects, and it is difficult to directly give the specific causes and locations of the defects, which increases the difficulty of subsequent repairs.
A component generation method is proposed, by obtaining the component code to be detected and inputting it into the security code agent for code splitting, defect positioning and defect correction, and using context retrieval technology to accurately locate code defects.
It realizes accurate identification of code defects and ensures that the code complies with code security specifications and quality standards, improves code quality and security, and improves code generation efficiency and effectively reduces labor costs.
Smart Images

Figure CN119847495A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software security technology, and in particular to a component generation method, device, equipment and computer program product. Background Art
[0002] Component generation technology (Code Review) is a crucial link in the software development process. It refers to the process of mutual inspection and evaluation of code among team members. It aims to collectively evaluate code quality, discover potential errors, performance issues, security vulnerabilities, etc., and share programming knowledge and best practices. However, the current component generation method is not accurate enough in identifying code defects, and it is difficult to directly give the specific cause and location of the defect, which increases the difficulty of subsequent repairs. Summary of the invention
[0003] The main purpose of the present application is to provide a component generation method, apparatus, device and computer program product, aiming to solve the problem that the current component generation method is not accurate enough in identifying code defects.
[0004] To achieve the above object, the present application proposes a component generation method, the method comprising:
[0005] Get the component code to be detected;
[0006] Inputting the component code to be detected into the security code agent for code splitting, defect location and defect correction to obtain a plurality of first component code blocks, wherein the security code agent locates code defects of the component code to be detected by using context retrieval rearrangement technology;
[0007] Assemble the first component code blocks to generate a target component.
[0008] In one embodiment, the secure code agent includes a task partitioning generation pre-trained transformer, a context retrieval artificial intelligence agent, and a code generation artificial intelligence agent;
[0009] The component code to be detected is input into the security code agent for code splitting, defect location and defect correction to obtain a plurality of first component code blocks, including:
[0010] Input the code of the component to be detected into the task division generation pre-trained transformer for code splitting to obtain a plurality of second component code blocks;
[0011] Locating code defects in each of the second component code blocks by using the context retrieval artificial intelligence agent to determine the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks;
[0012] The code problem statements, code error locations and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence entity to correct code defects, thereby obtaining a plurality of first component code blocks output by the code generation artificial intelligence entity.
[0013] In one embodiment, the second component code block includes context description information;
[0014] The method of locating code defects of each of the second component code blocks by using the context retrieval artificial intelligence agent to determine the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks includes:
[0015] Based on each of the context description information, searching each of the second component code blocks with a preset component corpus through the context retrieval artificial intelligence agent to obtain a plurality of search results;
[0016] Rearranging each of the search results to obtain a rearranged search result sequence;
[0017] Based on the re-arrangement sequence of the retrieval results, the code defects of each second component code block are located through the context retrieval artificial intelligence entity to determine the code problem statements, code error locations and context retrieval analysis information corresponding to each second component code block.
[0018] In one embodiment, the reordering of the search results to obtain a reordered sequence of search results includes:
[0019] Inputting a preset number of search results into a re-ranking model to obtain an importance score corresponding to each of the search results output by the re-ranking model;
[0020] sorting each of the search results based on the importance score;
[0021] The sorted search results are associated and combined to generate a rearranged sequence of search results.
[0022] In one embodiment, the re-arranging sequence based on the search results, locating code defects for each of the second component code blocks through the context retrieval artificial intelligence agent, and determining the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks include:
[0023] Rearranging the sequence according to the search result, searching the first relevant code information corresponding to the second component code block through the context search artificial intelligence agent, and determining whether there is context information meeting a preset condition in the first relevant code information;
[0024] If not, determining a search application programming interface (API) corresponding to the first relevant code information, and searching for second relevant code information corresponding to the first relevant code information based on the search API;
[0025] Determining whether the second relevant code information contains context information that meets a preset condition;
[0026] If so, based on the first related code information and the second related code information, determine the code problem statement, code error location and context retrieval analysis information corresponding to the second component code block.
[0027] In one embodiment, the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence entity to correct code defects, thereby obtaining a plurality of first component code blocks output by the code generation artificial intelligence entity, including:
[0028] Inputting the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks into the code generation artificial intelligence entity to correct code defects, thereby obtaining a plurality of first component code blocks;
[0029] Based on a preset code security specification, verify each of the first component code blocks;
[0030] If the verification fails, a code generation retry prompt is generated, and the code generation retry prompt is sent to the code generation artificial intelligence entity to achieve code re-correction.
[0031] In one embodiment, the training process of the security code agent includes:
[0032] Acquire several groups of code security training data, and perform data preprocessing on each of the code security training data;
[0033] Inputting each of the code security training data into an initial security code agent for iterative training to obtain a pending security code agent;
[0034] Fine-tune the pending security code agent to obtain the security code agent. In addition, to achieve the above purpose, the present application also proposes a component generation device, which includes:
[0035] A code acquisition module is used to obtain the code of the component to be detected;
[0036] A defect correction module is used to input the component code to be detected into the security code agent for code splitting, defect location and defect correction to obtain a plurality of first component code blocks, wherein the security code agent locates code defects of the component code to be detected by using context retrieval and rearrangement technology;
[0037] The component generation module is used to assemble the first component code blocks to generate a target component.
[0038] In addition, to achieve the above objectives, the present application also proposes a component generation device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the component generation method described above.
[0039] In addition, to achieve the above objectives, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the component generation method described above are implemented.
[0040] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the component generation method described above are implemented.
[0041] The present application provides a component generation method, apparatus, device and computer program product. The component generation method obtains the component code to be detected, and then inputs the component code to be detected into a security code agent for code splitting, defect location and defect correction to obtain several first component code blocks, wherein the security code agent locates the code defects of the component code to be detected through context retrieval and rearrangement technology, thereby assembling each of the first component code blocks to generate a target component, thereby accurately identifying code defects and ensuring that the code complies with code safety specifications and quality standards, thereby improving code quality and security, while improving code generation efficiency and effectively reducing labor costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0043] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 A schematic diagram of a flow chart provided for the first embodiment of the component generation method of the present application;
[0045] Figure 2 A brief flowchart of the component generation method provided for this application;
[0046] Figure 3 A brief example diagram of the component development process provided for the component generation method of this application;
[0047] Figure 4 A brief flowchart of the context description information generation method provided by the component generation method of this application;
[0048] Figure 5 A brief flowchart of hierarchical search provided for the component generation method of this application;
[0049] Figure 6 A system architecture diagram provided for the component generation method of this application;
[0050] Figure 7 This is a schematic diagram of the module structure of a component generation device according to an embodiment of the present application;
[0051] Figure 8 A schematic diagram of the device structure of the hardware operating environment involved in the component generation method in the embodiment of the present application.
[0052] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0053] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0054] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0055] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a big data service platform, a component generation system, etc. The following takes the component generation system as an example to illustrate this embodiment and the following embodiments.
[0056] Based on this, the present application embodiment provides a component generation method, referring to Figure 1 , Figure 1 A flowchart diagram of the first embodiment of the component generation method of the present application is provided.
[0057] In this embodiment, the component generation method includes steps S11 to S13:
[0058] Step S11, obtaining the code of the component to be detected;
[0059] It should be noted that the component code to be tested refers to the code part that needs to be reviewed for defect location and correction, wherein the component code to be tested is composed of atomic component code blocks, that is, the smallest, indivisible, independent working unit or module code, which helps to improve the maintainability, testability and scalability of the code.
[0060] Specifically, the component code to be detected input by the user is obtained. In addition, the user can also input user requirements corresponding to the component code to be detected, such as code security specifications (the code security specifications cover a series of principles that should be followed during the component generation process to prevent potential security vulnerabilities and risks), etc., which are not restricted here.
[0061] Step S12, inputting the component code to be detected into the security code agent for code splitting, defect location and defect correction, and obtaining a plurality of first component code blocks, wherein the security code agent locates code defects of the component code to be detected by using context retrieval rearrangement technology;
[0062] It should be noted that the secure code agent refers to an automated integrated tool for performing code review tasks, including code splitting, defect location and defect correction, etc., so as to identify potential problems in the code and automatically apply repair measures. In one embodiment, the secure code agent uses elements such as prompt word engineering (user input), heuristic reasoning, and retrieval enhancement generation (context retrieval) to solve related tasks, thereby avoiding the high false alarm rate and illusion scenarios in traditional large models, and effectively improving the development efficiency of developers, thereby achieving the goal of generating high-quality code and saving manpower.
[0063] It should be further explained that the first component code block refers to a code fragment that has completed the code review process such as defect correction after the security code agent processes the component code to be detected, as well as the accompanying code context description information.
[0064] Specifically, the component code to be detected is input into the task division generation pre-trained transformer for code splitting to obtain a plurality of second component code blocks, and then the context retrieval artificial intelligence agent is used to locate the code defects of each of the second component code blocks, and the code problem statements, code error positions and context retrieval analysis information corresponding to each of the second component code blocks are determined, so that the code problem statements, code error positions and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence agent for code defect correction, and a plurality of first component code blocks output by the code generation artificial intelligence agent are obtained, which can be referred to Figure 2 , Figure 2 A brief flowchart of the component generation method provided for this application.
[0065] Step S13, assembling the first component code blocks to generate a target component.
[0066] It should be noted that the target component refers to the final code product assembled after processing by the security code agent. The target component includes all the reviewed and revised first component code blocks, which are reassembled into a complete, fully functional and security-compliant component.
[0067] Specifically, the first component code blocks are assembled, wherein the assembly can be performed by a code assembly tool to generate a target component, which is not limited here. Figure 3 , Figure 3 A brief process example diagram for component development provided for the component generation method of this application, specifically, the figure shows an automated process for RPA (Robotic Process Automation) component development, which is driven by a secure code agent to ensure the security and compliance of the component code, wherein the user inputs user requirements (user requirements include requirements such as the code to be tested and code security specifications), which are then received by the secure code agent, which has natural language understanding capabilities, can deeply parse the requirements input by developers, and understand the required security specifications. Furthermore, based on the understanding of user requirements, the secure code agent splits the user requirements into finer subtasks and assigns the subtasks to different roles in the secure code agent, such as the context retrieval agent (Agent) and the code generation agent (Agent), thereby strengthening the agent's ability to perform specific tasks through the splitting and allocation process, ensuring that each role can focus on its best areas.
[0068] Furthermore, the security code intelligence will generate the corresponding component business flow, including defining the steps and logic that the component needs to execute, and determining the input parameters and output parameters, thereby generating a detailed component function list, which provides clear guidance for code generation. Then, the code generation agent uses the coding ability of the large model to generate a component code block that meets the specification based on the code security specification, component business flow and component function list, so that the component code block not only complies with the security requirements, but also meets the needs of business logic.
[0069] Finally, the generated component code blocks are packaged through the RPA designer according to the format requirements (the format requirements can be pre-defined or determined by the user) to create RPA components that can be called in the RPA designer, thereby realizing code assembly. Through the intervention of the secure code agent, development efficiency is improved while reducing development costs, and the security and compliance of components are ensured, which not only saves developers' time but also reduces security risks in the component development process.
[0070] This embodiment obtains the component code to be detected, and then inputs the component code to be detected into the security code agent for code splitting, defect location and defect correction to obtain several first component code blocks, wherein the security code agent locates the code defects of the component code to be detected through context retrieval and rearrangement technology, thereby assembling the first component code blocks to generate a target component, thereby accurately identifying code defects and ensuring that the code complies with code security specifications and quality standards, thereby improving code quality and security, while improving code generation efficiency and effectively reducing labor costs.
[0071] In a feasible implementation manner, the security code agent includes a task division generation pre-trained transformer, a context retrieval artificial intelligence agent, and a code generation artificial intelligence agent; the component code to be detected is input into the security code agent for code splitting, defect location, and defect correction to obtain a plurality of first component code blocks, including:
[0072] Step S21, inputting the code of the component to be detected into the task division generation pre-trained transformer MetaGPT for code splitting to obtain a plurality of second component code blocks;
[0073] It should be noted that the task partitioning MetaGPT (Generative Pre-trained Transformer) refers to a component based on a multi-agent system that is used to decompose user requirements or code tasks into smaller and more manageable subtasks. MetaGPT can be a large-scale LLM (Large Language Model) based The framework of the large language model (LLM) is used to realize multi-agent collaboration, environmental interaction, standard operating procedures, hallucination problem review, information exchange routing, institutional / market change subscription, value exchange economic system, etc. Among them, multi-agent collaboration refers to coordinating and managing the work of multiple agents, and each agent has an independent large language model (LLM); environmental interaction means that all agents interact in a common environment, which serves as a platform for their collaboration and allows them to share information and resources; standard operating procedures are to ensure the efficient operation of the entire system, and agents need to follow a set of standard procedures to complete tasks in an orderly and efficient manner; hallucination problem review helps reduce the error rate and ensure the quality and security of the code; information exchange routing promotes collaboration between agents and ensures that information and tasks can be correctly transmitted and distributed between agents; institutional / market change subscription enables agents to obtain external changes in a timely manner, such as new security vulnerability information or code base updates, so as to adapt to changes in a timely manner and maintain the security and relevance of the system; finally, the value exchange economic system determines the allocation of resources and the priority of tasks, which helps to ensure that key tasks are given priority and resources are reasonably allocated to optimize the performance of the entire system. By implementing multifunctional elements, each intelligent agent can perform to the maximum extent possible within its scope of responsibility, and together promote the efficient and intelligent operation of the entire automation system.
[0074] It should be further explained that the second component code block refers to the code fragment and context description information obtained after the task division MetaGPT processing.
[0075] Specifically, the component code to be detected is input into the task division MetaGPT for code splitting to obtain several second component code blocks, wherein the code splitting can be performed by identifying the splitting requirements in the user requirements pre-input by the user, and the input component code to be detected is preprocessed, such as segmented encoding of the component code, and then the preprocessed component code to be detected is input into the task division MetaGPT for forward calculation to generate several component code blocks, thereby processing each component code block, such as component code decoding and formatting, to obtain several second component code blocks.
[0076] Step S22, locating code defects in each of the second component code blocks by using the context retrieval artificial intelligence agent, and determining the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks;
[0077] It should be noted that the context retrieval artificial intelligence agent refers to an artificial intelligence agent used to retrieve and analyze the code context to locate possible defects or problems. The code problem statement refers to a specific statement in the code that may cause errors or may not comply with safety specifications. The code error location refers to the specific location where the problem exists in the code, such as the line number or code segment in a method. The context retrieval analysis information refers to all relevant information collected by the context retrieval artificial intelligence agent when analyzing a code block, such as context retrieval history information, called retrieval API (Application Programming Interface), API retrieval results, and the context retrieval agent's previous analysis of the code context (such as the structure of the code, dependencies, historical change records), etc., which helps to more accurately locate and understand code problems.
[0078] Specifically, based on each of the context description information, each of the second component code blocks is searched against a preset component corpus through the context retrieval artificial intelligence entity to obtain a number of retrieval results, and then each of the retrieval results is reordered to obtain a retrieval result rearrangement sequence, and then based on the retrieval result rearrangement sequence, the code defects of each of the second component code blocks are located through the context retrieval artificial intelligence entity to determine the code problem statements, code error locations and context retrieval analysis information corresponding to each of the second component code blocks.
[0079] Step S23, inputting the code problem statements, code error locations and context retrieval analysis information corresponding to each of the second component code blocks into the code generation artificial intelligence entity to correct code defects, and obtaining a plurality of first component code blocks output by the code generation artificial intelligence entity.
[0080] It should be noted that the code generation artificial intelligence agent is used to generate an agent of a code component to generate code that complies with safety specifications based on the problem statements, error locations and context retrieval analysis information provided by the context retrieval artificial intelligence agent.
[0081] Specifically, the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence body to correct code defects, thereby obtaining a number of first component code blocks. Then, based on preset code safety specifications, each of the first component code blocks is verified. If the verification fails, a code generation retry prompt is generated, and the code generation retry prompt is sent to the code generation artificial intelligence body to achieve code re-correction.
[0082] In this embodiment, the component code to be detected is input into the task division MetaGPT for code splitting to obtain several second component code blocks, and then the context retrieval artificial intelligence body is used to locate code defects in each of the second component code blocks, and the code problem statements, code error positions and context retrieval analysis information corresponding to each of the second component code blocks are determined, so that the code problem statements, code error positions and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence body for code defect correction, and several first component code blocks output by the code generation artificial intelligence body are obtained, and then the context retrieval capability of the artificial intelligence body is used to more accurately identify potential defects and problems in the code, which helps to more accurately understand the nature and impact of code defects, thereby achieving accurate positioning of code defects and automatically correcting identified defects, thereby reducing the workload of developers for manual repair, and effectively improving code review efficiency and overall code quality, shortening the development cycle.
[0083] In a feasible implementation manner, the second component code block includes context description information; the code defect location of each second component code block is performed by the context retrieval artificial intelligence agent to determine the code problem statement, code error location and context retrieval analysis information corresponding to each second component code block, including:
[0084] Step S31, based on each of the context description information, searching each of the second component code blocks with a preset component corpus through the context retrieval artificial intelligence agent to obtain a plurality of search results;
[0085] It should be noted that the preset component corpus refers to a pre-built database or collection, which contains code samples, documents and related information, historical codes, known defect cases, repair solutions, etc. of various software components, which are used to help the agent understand the common patterns, best practices and potential problems of the code. Since manually adding context information to thousands of text blocks in the preset component corpus is a huge workload, in order to more efficiently implement context retrieval, combined with the background information of the entire document, a concise context description information is generated for each text block in the preset component corpus through the secure code agent. Before the text block is embedded and the BM25 index is created, the context description information is added to the front of each text block, so that each text block has its own exclusive context information, so that the context retrieval agent can understand and use the information in the text block more accurately and quickly during retrieval, thereby realizing the rapid location of code defects. Please refer to Figure 4 , Figure 4 A simplified flowchart of the context description information generation method provided for the component generation method of this application.
[0086] It should be further explained that the context description information refers to the context information related to the component code block, such as the functional description of the code, expected behavior, usage scenarios, related documents or comments, etc., so as to help the agent understand the context of the code more comprehensively and perform retrieval and defect location more accurately. The retrieval results include code snippets similar to the query code block, related documents, known defects and repair cases, etc.
[0087] Specifically, based on each of the context description information, the context retrieval artificial intelligence entity searches each of the second component code blocks with the preset component corpus to obtain a number of search results, which can be referred to as Figure 4 , Figure 4 A brief flow chart of context description information generation provided for the component generation method of the present application, wherein the text in the component corpus is divided to determine a number of text blocks, and then in order to improve the accuracy and relevance of the retrieval, context information is added to each text block, and then each text block will go through two different processing paths: one is to convert it into a vector representation through an embedding model and store it in a vector database; the other is to process it through the TF-IDF algorithm to generate a TF-IDF index, thereby improving the retrieval efficiency and accuracy of the text data.
[0088] Furthermore, in the retrieval stage, according to the query requirements, relevant text blocks are retrieved from the vector database or TF-IDF index, and the retrieved results are further optimized through rank fusion and reranker technology to ensure that the most relevant results are ranked first. Finally, the optimized retrieval results will be input into the generative model for further analysis and processing.
[0089] In addition, multiple concurrent searches can be implemented during the context search process, that is, multiple text blocks can be searched at the same time, and the probability of multiple text blocks containing relevant information can be increased by adding more text blocks to the search window. However, adding too many text blocks will interfere with the search process, such as increasing the system load, thereby affecting the search speed and efficiency, introducing noise or irrelevant information, thereby reducing the accuracy and relevance of the search results, etc. Therefore, a reasonable upper limit for transmission can be set. In one embodiment, 5, 10 and 20 text blocks are transmitted to the window. Experimental results show that the best effect is to transmit 10 text blocks, thereby achieving a balance between the search effect and the system performance, and achieving the distinction between the context and the text block itself, and improving the quality of the generated response.
[0090] Step S32, reordering the search results to obtain a reordered search result sequence;
[0091] It should be noted that the retrieval result reordering sequence refers to a reordering sequence generated by the intelligent agent after reordering the retrieval results according to relevance, importance and other criteria, which aims to put the results that are most likely to contain useful information or solutions in front, thereby improving the efficiency and accuracy of subsequent defect location.
[0092] Specifically, a preset number of search results are input into the re-ranking model to obtain the importance score corresponding to each search result output by the re-ranking model, and then the search results are sorted based on each importance score, so as to associate and combine the sorted search results to generate a search result re-ranking sequence.
[0093] Step S33, based on the re-arrangement sequence of the retrieval results, the code defects of each of the second component code blocks are located through the context retrieval artificial intelligence entity to determine the code problem statements, code error locations and context retrieval analysis information corresponding to each of the second component code blocks.
[0094] Specifically, according to the re-arrangement sequence of the search results, the first relevant code information corresponding to the second component code block is retrieved through the context retrieval artificial intelligence entity, and it is determined whether there is context information that meets the preset conditions in the first relevant code information. If not, the search application programming interface API corresponding to the first relevant code information is determined, and the second relevant code information corresponding to the first relevant code information is retrieved based on the search API, so as to determine whether there is context information that meets the preset conditions in the second relevant code information. If so, based on the first relevant code information and the second relevant code information, the code problem statement, code error location and context retrieval analysis information corresponding to the second component code block are determined.
[0095] This embodiment searches each of the second component code blocks against a preset component corpus through the context retrieval artificial intelligence entity based on the context description information to obtain a number of retrieval results, and then reorders each of the retrieval results to obtain a retrieval result reordering sequence, thereby locating code defects for each of the second component code blocks based on the retrieval result reordering sequence through the context retrieval artificial intelligence entity, determining the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks, thereby enhancing retrieval relevance, more accurately identifying and locating defects in the code, thereby improving positioning accuracy, and optimizing the code review process by reducing the time for manual screening and evaluation of code, reducing omissions or errors caused by human factors, and improving the consistency, reliability, and adaptability of code review, thereby effectively accelerating development speed.
[0096] In a feasible implementation manner, the reordering of the search results to obtain a reordered search result sequence includes:
[0097] Step S41, inputting a preset number of search results into a re-ranking model, and obtaining an importance score corresponding to each of the search results output by the re-ranking model;
[0098] It should be noted that the re-ranking technique aims to ensure that only the most relevant text blocks are passed to the model, which can not only improve the quality of the response, but also reduce processing costs and response delays. The preset number refers to the number of search results to be processed from the initial search results before re-ranking, and the preset number can be set based on performance considerations, expected accuracy or system resource limitations, and is not limited here.
[0099] It should be further explained that the re-ranking model is used to evaluate the relevance of the search results from multiple perspectives such as keyword matching, user behavior, historical data, etc., and output the scores of the results based on the evaluation to determine the importance of each search result. The importance score refers to the score assigned by the re-ranking model to each search result, reflecting the relevance or importance of the result to the code to be detected.
[0100] Specifically, a preset number of search results are input into the re-ranking model, for example, the first 100 search results are passed to the re-ranking model, and the importance score corresponding to each of the search results output by the re-ranking model is obtained.
[0101] Step S42, sorting the search results based on the importance scores;
[0102] Specifically, each of the search results is sorted in reverse order according to each of the importance scores, and a sorting sequence number of each of the search results is determined.
[0103] Step S43: associate and combine the sorted search results to generate a rearranged search result sequence.
[0104] It should be noted that the preset sorting refers to a pre-set sorting sequence number.
[0105] Specifically, the sorted search results are associated and combined to generate a search result rearrangement sequence. For example, the first 10 sorted search results are selected and associated and combined to generate a search result rearrangement sequence.
[0106] This embodiment inputs a preset number of search results into a re-ranking model to obtain an importance score corresponding to each of the search results output by the re-ranking model, and then sorts each of the search results based on the importance score, thereby associating and combining the sorted search results to generate a search result re-ranking sequence, thereby identifying the most relevant search results, improving the relevance of the search, and reducing the time for users to screen required information from a large number of irrelevant or low-relevance results, thereby improving search efficiency. At the same time, for complex queries with multiple keywords or conditions, the re-ranking technology can more accurately evaluate the relevance of the results.
[0107] In a feasible implementation manner, the re-arranging sequence based on the search results, locating code defects for each of the second component code blocks through the context retrieval artificial intelligence agent, and determining the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks include:
[0108] Step S51, re-arranging the sequence according to the search result, searching the first relevant code information corresponding to the second component code block through the context search artificial intelligence agent, and determining whether there is context information meeting a preset condition in the first relevant code information;
[0109] It should be noted that the first related code information refers to the first-layer related code information retrieved based on the second component code block, including code lines or code segments that may be defective codes, calling or called functions and methods, related variables and data structures, code comments and document strings, etc., without limitation here.
[0110] It should be further explained that the preset condition refers to the standard or rule used to determine whether the code information meets specific requirements during the retrieval and analysis process, indicating that the current first relevant code information has sufficient context information to accurately locate the code defects in the second component code block. The context information refers to the context information related to the code block, which helps the context retrieval artificial intelligence agent understand the function and purpose of the code.
[0111] Specifically, according to the retrieval result re-arrangement sequence, the first related code information corresponding to the second component code block is retrieved through the context retrieval artificial intelligence entity, and it is determined whether there is context information that meets preset conditions in the first related code information. In one embodiment, in the context retrieval stage, the context retrieval Agent is used to retrieve and extract code fragments related to or similar to the second component code block in the retrieval result re-arrangement sequence, so as to enable the context retrieval Agent to retrieve the functional information of the relevant component and the actual code fragment.
[0112] Step S52: if not, determining a search application programming interface API corresponding to the first relevant code information, and retrieving second relevant code information corresponding to the first relevant code information based on the search API;
[0113] It should be noted that the retrieval application programming interface API refers to an interface used to retrieve additional code information from a code repository or other data source, including an API for searching a code repository (used to find specific functions, classes or variables), an API for accessing a version control system (used to obtain code history and change information), an API for an integrated development environment (IDE) (used to obtain real-time analysis of code), etc.
[0114] It should be further explained that the second-related code information refers to additional code information obtained through the retrieval API when the first-related code information fails to provide sufficient context, including code segments indirectly related to the first-related code information and code related to the problem in other modules or components, etc., which is not limited here.
[0115] Specifically, in one embodiment, if the second-related code information does not contain context information that meets the preset conditions, that is, if there is insufficient context information for defect location, then the retrieval application programming interface API corresponding to the first-related code information is determined. In the process of hierarchical retrieval, the context retrieval agent has multiple APIs, and each API provides different types of information or services. For example, some APIs are used to retrieve specific functions in the code library, while other APIs are used to obtain code documentation or error logs. Therefore, the system can intelligently select the most appropriate API to retrieve the second-related code information corresponding to the first-related code information based on the current first-related code information and context information, thereby implementing a hierarchical state strategy for iteratively calling the retrieval API. The hierarchical state strategy instructs the context retrieval agent to only call the necessary retrieval API based on the available information, and iteratively change the previously used API to return more accurate code-related contexts. Please refer to Figure 5 , Figure 5 A brief flowchart of hierarchical search provided by the component generation method of this application, specifically, Figure 5 A hierarchical search process is shown for locating problems or faults in a code base. The process includes three levels, each of which corresponds to a different search strategy and the addition of context information. Among them, the first level search is performed according to the actual retrieval problem description. In one embodiment, the result of the first level search is:
[0116] Search_class(class A): Search for information related to class A in the component corpus;
[0117] Search_method(method A): Search for method A in class A;
[0118] Search_code_in_file(code_str file A): Search for a specific code string in file A.
[0119] If the results of the first-level search are not sufficient to determine the specific location of the problem (i.e., insufficient context), the second-level search is performed based on the results of the first-level search. The search results of the second-level search are:
[0120] Search_class(class B): Search for information related to class B in the component corpus;
[0121] Search_method_in_class(method B, class A) : Searches for method B in class A, which indicates that the search may span different classes.
[0122] If the results of the second-level search are still insufficient to determine the specific location of the problem (i.e., insufficient context), the K-th level search is performed until the search results are sufficient to determine the specific location of the problem. The results of the K-th level search are:
[0123] Search_method_in_class(method C, class B): Search for method C in class B.
[0124] When the search results of the K-th level search are sufficient to determine the specific location of the problem (sufficient context), the system can accurately locate the fault location, such as "Class A, method B" and "Class B, method C".
[0125] Step S53, determining whether the second related code information contains context information that meets a preset condition;
[0126] Step S54: If yes, then based on the first related code information and the second related code information, determine the code problem statement, code error location and context retrieval analysis information corresponding to the second component code block.
[0127] Specifically, if the second related code information contains context information that meets preset conditions, the code problem statement, code error location and context retrieval analysis information corresponding to the second component code block are determined based on the first related code information and the second related code information.
[0128] It should be noted that the large language model (LLM) embedded in the context retrieval agent may produce inaccurate or irrelevant output when processing natural language, which is the "hallucination" phenomenon. In order to reduce the "hallucination" phenomenon and avoid the formation of very lengthy code contexts that interfere with the code generation stage, it is necessary to control the output of LLM, which can be achieved through multiple controls, including context control: by providing rich context information, guiding LLM to understand tasks more accurately and generate relevant outputs; API call control: by carefully selecting and calling APIs, ensuring that the information received by LLM is accurate and relevant, thereby improving the quality of its output; feedback loop: by analyzing the difference between LLM's output and actual results, constantly adjusting and optimizing LLM's guidance, etc., there is no restriction here, so as to ensure that LLM's output (such as code problem statements, code error locations, and context retrieval analysis information) is more accurate, concise and controlled, thereby improving the efficiency and quality of code retrieval and analysis.
[0129] This embodiment rearranges the sequence according to the search results, retrieves the first relevant code information corresponding to the second component code block through the context search artificial intelligence body, and determines whether there is context information that meets the preset conditions in the first relevant code information, and if not, determines the search application programming interface API corresponding to the first relevant code information, and retrieves the second relevant code information corresponding to the first relevant code information based on the search API, so as to determine whether there is context information that meets the preset conditions in the second relevant code information, and if so, determines the code problem statement, code error location and context search analysis information corresponding to the second component code block based on the first relevant code information and the second relevant code information, so as to more accurately retrieve the context information related to the code problem through layer-by-layer search and conditional judgment, and then deeply mines the relevant code information, so as to realize fast and accurate positioning of code defects and other problems, enhance the problem positioning capability, and then realize more comprehensive analysis of code context, understand the root cause of the problem, and improve the depth of code analysis.
[0130] In a feasible implementation manner, the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence entity to correct code defects, and a plurality of first component code blocks output by the code generation artificial intelligence entity are obtained, including:
[0131] Step S61, inputting the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks into the code generation artificial intelligence agent to perform code defect correction, thereby obtaining a plurality of first component code blocks;
[0132] Specifically, the code problem statements, code error positions, and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence entity to correct code defects, and obtain a number of first component code blocks. In one embodiment, the code generation agent retrieves the precise code snippet located at the error position from the code library based on the code problem statements, code error positions, and context retrieval analysis information corresponding to each of the second component code blocks, and then based on the precise code snippet and other related code contexts, the code generation agent corrects and generates code defects, and obtains a number of first component code blocks output by the code generation artificial intelligence entity, wherein, since most of the RPA component codes are written in Python language, a linker can be used to identify Python-specific syntax problems.
[0133] Step S62, verifying each of the first component code blocks based on a preset code security specification;
[0134] It should be noted that the preset code security specifications refer to a series of pre-defined rules and standards for ensuring the security of the code, including but not limited to: coding standards (specifying how to write code, including naming conventions, code format and structure), secure programming practices (guiding how to write secure code to avoid common security vulnerabilities such as SQL injection, cross-site scripting (XSS)), permissions and access control (ensuring that permission checks are correctly implemented in the code to prevent unauthorized access), data encryption and protection (specifying how to safely store and transmit sensitive data), error and exception handling (guiding how to properly handle errors and exceptions to avoid leaking sensitive information or causing system crashes) and compliance requirements (ensuring that the code complies with relevant laws, regulations and industry standards), etc. The preset code security specifications can be supplemented by identifying user input requirements. If the user input requirements do not have relevant content, subsequent operations are performed based on the code security specifications set in the secure code agent.
[0135] Specifically, based on a preset code safety specification, each of the first component code blocks is verified to determine whether the generated component code block complies with the safety specification, thereby reducing the risk of component code violation.
[0136] Step S63, if the verification fails, a code generation retry prompt is generated, and the code generation retry prompt is sent to the code generation artificial intelligence entity to achieve code re-correction.
[0137] It should be noted that the code generation retry prompt refers to the prompt information generated by the system when the generated code block fails to pass the verification of the preset code safety specifications, including error description (detailed description of the specific reasons why the code block failed to pass the verification), recommended corrective measures (providing possible solutions or improvement suggestions to guide the agent on how to correct the code), retry mechanism (instructing the agent to retry to generate a code block that meets the specifications) and priority or severity level, etc.
[0138] Specifically, if the verification fails, a code generation retry prompt is generated, and the code generation retry prompt is sent to the code generation artificial intelligence agent to achieve code re-correction. In one embodiment, if the generated code block does not follow the specified code format, or cannot be applied to the original component code, the code generation agent will be prompted to re-correct. In order to achieve a better balance between resource consumption and code effect, the number of re-corrections needs to be limited to prevent the occurrence of retry dead loops, etc. After multiple experimental tests, the code generation agent's retry is set to 6 times as the upper limit, and then the code with the best generation effect among the 6 times is returned as the final output.
[0139] In this embodiment, the code problem statements, code error locations and context retrieval analysis information corresponding to each second component code block are input into the code generation artificial intelligence body to correct code defects, thereby obtaining a number of first component code blocks, and then verifying each of the first component code blocks based on preset code security specifications. If the verification fails, a code generation retry prompt is generated, and the code generation retry prompt is sent to the code generation artificial intelligence body to achieve code re-correction, thereby identifying and repairing potential security vulnerabilities, and ensuring that the code complies with security specifications, thereby improving the security and code quality of the software, reducing the risk of component code violations, saving the code review time of component developers and testers, and lowering the threshold for component development.
[0140] In a feasible implementation, the training process of the security code agent includes:
[0141] Step S71, obtaining several groups of code security training data, and performing data preprocessing on each of the code security training data;
[0142] It should be noted that the code security training data refers to a series of data sets used to train secure code agents, which contain various code samples, including secure and vulnerable codes, such as code segments with known security vulnerabilities (such as buffer overflows, SQL (Structured Query Language) injections, cross-site scripting, etc.), secure code practice examples, code metadata, related security test results (such as the output of static code analysis tools, dynamic test results, etc.) and code context information (such as the application, functional module and related documents to which the code belongs).
[0143] Specifically, a large amount of training data on code security is obtained to improve the model's language comprehension and generation capabilities, and the collected code security training data is cleaned and preprocessed. Among them, keyword filtering and identification can be used to remove noise and useless information, and SimHash (similarity hash) and MinHash (minimum hash) algorithms can be used to deduplicate data, and similar documents can be deleted to ensure data quality.
[0144] Step S72, inputting each of the code security training data into the initial security code agent for iterative training to obtain a pending security code agent;
[0145] It should be noted that the initial security code agent refers to an agent model that has been preset or pre-trained before the training process begins. In one embodiment, the initial security code agent uses the "Jiutian" model as the model base, wherein the "Jiutian" model is a generative artificial intelligence model independently developed by China Mobile Research Institute, which aims to realize the intelligence of complex systems through original systematic artificial intelligence technology.
[0146] It should be further explained that the pending security code agent refers to an agent that has not yet completed fine-tuning after preliminary iterative training. At this stage, the agent has learned some knowledge about code security, but further fine-tuning is needed to improve its performance in specific tasks or fields.
[0147] Specifically, each of the code security training data is input into the initial security code agent for iterative training to obtain a pending security code agent, wherein a distributed training strategy is adopted, multiple GPUs (Graphics Processing Units) and TPUs (Tensor Processing Units) are used for parallel computing to speed up the training, and an appropriate loss function is defined. The model parameters are optimized through the back propagation algorithm to reduce the prediction error.
[0148] Step S73, fine-tuning training is performed on the pending security code agent to obtain the security code agent.
[0149] It should be noted that fine-tuning is the process of further optimizing the pre-trained secure code agent to make it better suited to specific tasks. Through fine-tuning, the secure code agent can better handle the language and task requirements of specific fields.
[0150] Specifically, a specific data set suitable for code defect repair is obtained, and then the small-batch gradient descent method is used to fine-tune and train the model of the pending security code agent, so that it can better adapt to specific tasks through fine-tuning, and then the performance of the pending security code agent is evaluated on the validation set, and the generalization ability of the pending security code agent is ensured by adjusting the hyperparameters.
[0151] This embodiment obtains several groups of code security training data, performs data preprocessing on each of the code security training data, and then inputs each of the code security training data into an initial security code agent for iterative training to obtain a pending security code agent, thereby fine-tuning the pending security code agent to obtain the security code agent. Iterative training and fine-tuning training help the agent learn more complex patterns and scenarios, identify and repair security vulnerabilities in the code, improve the security of software products, thereby improving their performance in actual applications, and realize automated code review and security testing processes, reduce manual intervention, and improve development efficiency.
[0152] For example, to help understand the implementation architecture of the component generation method, please refer to Figure 6 , Figure 6 System architecture diagram provided for the component generation method of this application.
[0153] Specifically, the implementation architecture of the component generation method is mainly divided into three layers. The first layer is the application layer, which is mainly divided into two applications: security review and defect optimization. It uses the preset code security specifications as a benchmark, and uses the security code agent to conduct a security review of the component code to be tested, identifying potential code defects and security vulnerabilities. Specifically, the security review includes searching, locating and prompting the potential security risks in the component code to be tested, and generating optimization suggestions according to the corresponding security specifications; defect optimization is to optimize and repair the code based on the defects retrieved and located in the security review, which involves in-depth analysis and reconstruction of the code to ensure the stability and performance of the component. It can be seen that the application layer is the embodiment of the capabilities of the component layer. It converts the abstract functions provided by the component layer into applications and services that users can directly use.
[0154] The second layer is the component layer, which mainly includes RPA components in different fields, such as Excel components in the office field and OCR (Optical Character Recognition) components that borrow AI capabilities. The available components are designed to be reusable and customizable to adapt to various business needs, such as the API interface used in iterative hierarchical retrieval during context retrieval. It can be seen that the component layer is the operation object of the agent layer, which means that the agents in the agent layer directly interact with the component layer and use the functions provided by the component layer to implement higher-level business logic and automation tasks, so that the system can flexibly respond to business needs through architectural design while maintaining the reusability and maintainability of components.
[0155] The third layer is the agent layer, which mainly uses MetaGPT as the base agent, the context retrieval agent as the supporting bridge, and the code generation agent as the output. Among them, the MetaGPT base agent, as the core of the agent layer, is responsible for coordinating and managing the workflow of the entire agent layer, providing a basic framework for other agents so that other agents can collaborate and perform tasks on this basis; the context retrieval agent, as a supporting bridge, uses TF-IDF index and vector database to retrieve, analyze and locate code defects in the component code to be detected, so as to quickly find the code blocks that may have problems and provide the necessary context data for the code generation agent; the code generation agent is the final output. After receiving the information provided by the context retrieval agent, the code generation agent is responsible for generating and outputting the repaired and optimized component code, while ensuring that the generated code meets the safety specifications.
[0156] In general, the three-layer architecture implements standard processes by calling the underlying pre-trained security field model (such as the "Jiutian" model) to ensure orderly and efficient operation within the system. Among them, the component layer is the operation object of the intelligent layer, and the application layer is the specific implementation of the component layer's capabilities. The layers are progressive to achieve the final code review and component generation effect.
[0157] It should be noted that the examples in the figures are only used to understand the present application and do not constitute a limitation on the component generation method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0158] It should be understood that the order of execution of the steps in the above embodiment does not necessarily 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 embodiment of the present invention.
[0159] This application also provides a component generation device, please refer to Figure 7 , the component generating device comprises:
[0160] The code acquisition module 71 is used to acquire the code of the component to be detected;
[0161] The defect correction module 72 is used to input the component code to be detected into the security code agent for code splitting, defect location and defect correction to obtain a plurality of first component code blocks, wherein the security code agent locates the code defects of the component code to be detected by using context retrieval rearrangement technology;
[0162] The component generation module 73 is used to assemble the first component code blocks to generate a target component.
[0163] The component generating device is also used for:
[0164] Input the code of the component to be detected into the task division generation pre-trained transformer for code splitting to obtain a plurality of second component code blocks;
[0165] Locating code defects in each of the second component code blocks by using the context retrieval artificial intelligence agent to determine the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks;
[0166] The code problem statements, code error locations and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence entity to correct code defects, thereby obtaining a plurality of first component code blocks output by the code generation artificial intelligence entity.
[0167] The component generating device is also used for:
[0168] Based on each of the context description information, searching each of the second component code blocks with a preset component corpus through the context retrieval artificial intelligence agent to obtain a plurality of search results;
[0169] Rearranging each of the search results to obtain a rearranged search result sequence;
[0170] Based on the re-arrangement sequence of the retrieval results, the code defects of each second component code block are located through the context retrieval artificial intelligence entity to determine the code problem statements, code error locations and context retrieval analysis information corresponding to each second component code block.
[0171] The component generating device is also used for:
[0172] Inputting a preset number of search results into a re-ranking model to obtain an importance score corresponding to each of the search results output by the re-ranking model;
[0173] sorting each of the search results based on the importance score;
[0174] The sorted search results are associated and combined to generate a rearranged sequence of search results.
[0175] The component generating device is also used for:
[0176] Rearranging the sequence according to the search result, searching the first relevant code information corresponding to the second component code block through the context search artificial intelligence agent, and determining whether there is context information meeting a preset condition in the first relevant code information;
[0177] If not, determining a search application programming interface API corresponding to the first relevant code information, and retrieving second relevant code information corresponding to the first relevant code information based on the search API;
[0178] Determining whether the second relevant code information contains context information that meets a preset condition;
[0179] If so, based on the first related code information and the second related code information, determine the code problem statement, code error location and context retrieval analysis information corresponding to the second component code block.
[0180] The component generating device is also used for:
[0181] Inputting the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks into the code generation artificial intelligence entity to correct code defects, thereby obtaining a plurality of first component code blocks;
[0182] Based on a preset code security specification, verify each of the first component code blocks;
[0183] If the verification fails, a code generation retry prompt is generated, and the code generation retry prompt is sent to the code generation artificial intelligence entity to achieve code re-correction.
[0184] The component generating device is also used for:
[0185] Acquire several groups of code security training data, and perform data preprocessing on each of the code security training data;
[0186] Inputting each of the code security training data into an initial security code agent for iterative training to obtain a pending security code agent;
[0187] Fine-tune the pending security code agent to obtain the security code agent. The component generation device provided in the present application adopts the component generation method in the above embodiment, which can solve the technical problems in the background technology. Compared with the prior art, the beneficial effects of the component generation device provided in the present application are the same as the beneficial effects of the component generation method provided in the above embodiment, and other technical features in the component generation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0188] The present application provides a component generation device, which includes: at least one processor; and a memory that is communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the component generation method in the above-mentioned embodiment 1.
[0189] Reference below Figure 8 , which shows a schematic diagram of a component generation device suitable for implementing an embodiment of the present application. The component generation device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The component generation device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0190] like Figure 8As shown, the component generation device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the component generation device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the component generation device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a component generation device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0191] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0192] The component generation device provided by the present application adopts the component generation method in the above embodiment, which can solve the technical problems in the background technology. Compared with the prior art, the beneficial effects of the component generation device provided by the present application are the same as the beneficial effects of the component generation method provided by the above embodiment, and the other technical features in the component generation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0193] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0194] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0195] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the component generation method in the above-mentioned embodiment.
[0196] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0197] The computer-readable storage medium may be included in the component generation device; or may exist independently without being assembled into the component generation device.
[0198] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the component generation device, the component generation device:
[0199] Obtain the component code to be detected; input the component code to be detected into the security code agent for code splitting, defect location and defect correction to obtain several first component code blocks, wherein the security code agent locates code defects in the component code to be detected through context retrieval and rearrangement technology; assemble the first component code blocks to generate a target component.
[0200] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0201] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0202] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0203] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned component generation method, and can solve the technical problems in the background technology. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the component generation method provided in the above-mentioned embodiment, and will not be repeated here.
[0204] An embodiment of the present application provides a computer program product, including a computer program, which implements the steps of the component generation method as described above when the computer program is executed by a processor.
[0205] The computer program product provided in this application can solve the technical problems in the background technology. Compared with the prior art, the beneficial effects of the computer program product provided in the embodiment of this application are the same as the beneficial effects of the component generation method provided in the above embodiment, which will not be repeated here.
[0206] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A component generation method, characterized in that: include: Get the component code to be detected; Inputting the component code to be detected into the security code agent for code splitting, defect location and defect correction to obtain a plurality of first component code blocks, wherein the security code agent locates code defects of the component code to be detected by using context retrieval rearrangement technology; Assemble the first component code blocks to generate a target component.
2. The component generation method according to claim 1, characterized in that: The secure code agent includes a task division generation pre-trained transformer, a context retrieval artificial intelligence agent, and a code generation artificial intelligence agent; The component code to be detected is input into the security code agent for code splitting, defect location and defect correction to obtain a plurality of first component code blocks, including: Input the code of the component to be detected into the task division generation pre-trained transformer for code splitting to obtain a plurality of second component code blocks; Locating code defects in each of the second component code blocks by using the context retrieval artificial intelligence agent to determine the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks; The code problem statements, code error locations and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence entity to correct code defects, thereby obtaining a plurality of first component code blocks output by the code generation artificial intelligence entity.
3. The component generation method according to claim 2, characterized in that: The second component code block includes context description information; The method of locating code defects of each of the second component code blocks by using the context retrieval artificial intelligence agent to determine the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks includes: Based on each of the context description information, searching each of the second component code blocks with a preset component corpus through the context retrieval artificial intelligence agent to obtain a plurality of search results; Rearranging each of the search results to obtain a rearranged search result sequence; Based on the re-arrangement sequence of the retrieval results, the code defects of each second component code block are located through the context retrieval artificial intelligence entity to determine the code problem statements, code error locations and context retrieval analysis information corresponding to each second component code block.
4. The component generation method according to claim 3, characterized in that: The step of reordering the search results to obtain a reordered sequence of search results includes: Inputting a preset number of search results into a re-ranking model to obtain an importance score corresponding to each of the search results output by the re-ranking model; sorting each of the search results based on the importance score; The sorted search results are associated and combined to generate a rearranged sequence of search results.
5. The component generation method according to claim 3, characterized in that: The re-arranging sequence based on the search results, locating code defects for each of the second component code blocks through the context search artificial intelligence agent, and determining the code problem statements, code error locations, and context search analysis information corresponding to each of the second component code blocks, includes: Rearranging the sequence according to the search result, searching the first relevant code information corresponding to the second component code block through the context search artificial intelligence agent, and determining whether there is context information meeting a preset condition in the first relevant code information; If not, determining a search application programming interface API corresponding to the first relevant code information, and retrieving second relevant code information corresponding to the first relevant code information based on the search API; Determining whether the second relevant code information contains context information that meets a preset condition; If so, based on the first related code information and the second related code information, determine the code problem statement, code error location and context retrieval analysis information corresponding to the second component code block.
6. The component generation method according to claim 2, characterized in that: The code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks are input into the code generation artificial intelligence entity to correct code defects, and a plurality of first component code blocks output by the code generation artificial intelligence entity are obtained, including: Inputting the code problem statements, code error locations, and context retrieval analysis information corresponding to each of the second component code blocks into the code generation artificial intelligence entity to correct code defects, thereby obtaining a plurality of first component code blocks; Based on a preset code security specification, verify each of the first component code blocks; If the verification fails, a code generation retry prompt is generated, and the code generation retry prompt is sent to the code generation artificial intelligence entity to achieve code re-correction.
7. The component generation method according to claim 1, characterized in that: The training process of the security code agent includes: Acquire several groups of code security training data, and perform data preprocessing on each of the code security training data; Inputting each of the code security training data into an initial security code agent for iterative training to obtain a pending security code agent; Fine-tune the pending security code agent to obtain the security code agent.
8. A component generation device, characterized in that: include: A code acquisition module is used to obtain the code of the component to be detected; A defect correction module is used to input the component code to be detected into the security code agent for code splitting, defect location and defect correction to obtain a plurality of first component code blocks, wherein the security code agent locates code defects of the component code to be detected by using context retrieval and rearrangement technology; The component generation module is used to assemble the first component code blocks to generate a target component.
9. A component generation device, characterized in that: The component generation device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the component generation method according to any one of claims 1 to 7.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the component generation method according to any one of claims 1 to 7 are implemented.