Code processing method and device, electronic equipment and storage medium

By performing code optimization and verification using a target large language model, the lack of automated processes in code refactoring is solved, achieving full-process automated management and improving the efficiency of code refactoring.

CN121742897APending Publication Date: 2026-03-27HANGZHOU NETEASE CLOUD MUSIC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-29
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

The lack of automated processes in existing technologies leads to low efficiency in code refactoring, and the analysis, evaluation and data verification of optimized code still rely on manual work by developers.

Method used

By performing code optimization, code verification, and data comparison of code before and after optimization using a target large language model, the system provides a fully automated code processing workflow, including generating prompt words and executing corresponding tasks to output optimized code and data comparison results.

Benefits of technology

It achieves automated closed-loop management of the entire code refactoring process, improving processing efficiency and reducing reliance on manual operations by developers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121742897A_ABST
    Figure CN121742897A_ABST
Patent Text Reader

Abstract

The invention discloses a code processing method and device, electronic equipment and a storage medium. Target codes are executed through a target large language model for code optimization, code verification of the optimized codes, comparison of data generated by the codes before and after optimization and other operations; therefore, a complete automatic code processing flow covering code optimization and reconstruction, online data verification and data result automatic comparison is provided, key links such as optimized code analysis and evaluation, data verification and the like do not need to be manually completed by a developer, and automatic closed-loop management of the whole code reconstruction flow is achieved. And the processing efficiency of code reconstruction is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and more specifically to a method, apparatus, electronic device, and storage medium for processing code. Background Technology

[0002] In the entire software development lifecycle, code refactoring is a crucial step in improving code quality, optimizing system performance, and reducing maintenance costs. It is widely used in scenarios such as system upgrades, business logic iterations, and technical architecture migrations. The core goal of code refactoring is to optimize code without changing its original core functionality, in order to adapt to the needs of business development and technology upgrades.

[0003] Currently, the mainstream code refactoring methods in the industry are still mainly manual. Typically, technical personnel use code interpretation tools or manual analysis to logically analyze and identify problems in the existing target code, and then generate optimized target code based on the interpretation results. However, existing code optimization methods only complete the single step from code interpretation to optimized code generation. Subsequent key steps such as optimized code analysis and evaluation, and data verification all rely on developers to complete manually. There is a lack of an automated processing flow for code refactoring, resulting in low processing efficiency. Summary of the Invention

[0004] This application provides a code processing method, apparatus, electronic device, and storage medium. By executing target code through a target large language model, it performs operations such as code optimization, code verification of the optimized code, and data comparison of the code before and after optimization. This provides a complete automated code processing flow covering code optimization and refactoring, online data verification, and automatic comparison of data results. Key steps such as post-optimized code analysis and evaluation and data verification do not require manual completion by developers. It realizes automated closed-loop management of the entire code refactoring process and effectively improves the processing efficiency of code refactoring.

[0005] In a first aspect, embodiments of this application provide a code processing method, including: Obtain the target code to be processed, and the first metadata information of the target code; Based on the target code, the first metadata information, and at least one optimization requirement for the code optimization task of the target code, a first prompt word for the code optimization task is generated; The code optimization task is performed based on the first prompt word using the target large language model to output the optimized target code; Based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code, a second prompt word for the code verification language generation task is generated; The code verification language generation task is performed by the target large language model based on the second prompt word to output the target code verification language; Based on the target code, the optimized target code, the target code validation language, and the data analysis requirements of the data analysis task, a third prompt word for the data analysis task is generated; The data analysis task is performed based on the third prompt word using the target large language model to output a data comparison result between the target code and the optimized target code. The data comparison result is used to indicate the accuracy of the data obtained when the optimized target code is run.

[0006] Secondly, embodiments of this application provide a code processing apparatus, including: The acquisition unit is used to acquire the target code to be processed, and the first metadata information of the target code; The first generation unit is used to generate a first prompt word for the code optimization task based on the target code, the first metadata information, and at least one optimization requirement for the code optimization task of the target code. The first execution unit is used to perform the code optimization task based on the first prompt word through the target large language model, so as to output the optimized target code; The second generation unit is used to generate a second prompt word for the code verification language generation task based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code. The second execution unit is used to execute the code verification language generation task based on the second prompt word through the target large language model, so as to output the target code verification language; The third generation unit is used to generate a third prompt word for the data analysis task based on the target code, the optimized target code, the target code verification language, and the data analysis requirements of the data analysis task. The third execution unit is used to perform the data analysis task based on the third prompt word through the target large language model, so as to output the data comparison result between the target code and the optimized target code. The data comparison result is used to indicate the accuracy of the data obtained when the optimized target code is run.

[0007] Thirdly, embodiments of this application also provide an electronic device, including a memory storing multiple instructions; a processor loading instructions from the memory to execute the steps of any of the code processing methods provided in embodiments of this application.

[0008] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute the steps of any of the code processing methods provided in embodiments of this application.

[0009] Fifthly, embodiments of this application also provide a computer program product, including a computer program or instructions, which, when executed by a processor, implement the steps in any of the code processing methods provided in embodiments of this application.

[0010] The solution adopted in this application can perform code optimization, code verification of the optimized code, and data comparison of the code before and after optimization by executing the target code through the target large language model. This provides a complete automated code processing flow covering code optimization and refactoring, online data verification, and automatic comparison of data results. Key steps such as code analysis and evaluation and data verification do not need to be manually completed by the developer. This achieves automated closed-loop management of the entire code refactoring process and effectively improves the processing efficiency of code refactoring. Attached Figure Description

[0011] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 This is a schematic diagram of a scenario for the code processing system provided in the embodiments of this application. Figure 2 This is a schematic flowchart of an embodiment of the code processing method provided in this application. Figure 3a This is a connection diagram of the processing nodes of the code processing system provided in the embodiments of this application; Figure 3b This is a connection diagram of the processing nodes of the code processing system provided in the embodiments of this application; Figure 3c This is a connection diagram of the processing nodes of the code processing system provided in the embodiments of this application; Figure 3d This is a connection diagram of the processing nodes of the code processing system provided in the embodiments of this application; Figure 3e This is a connection diagram of the processing nodes of the code processing system provided in the embodiments of this application; Figure 4 This is a schematic diagram illustrating an application scenario of the code processing method provided in the embodiments of this application; Figure 5 This is a schematic diagram illustrating an application scenario of the code processing method provided in the embodiments of this application; Figure 6 This is a schematic diagram illustrating an application scenario of the code processing method provided in the embodiments of this application; Figure 7 This is a schematic diagram of the structure of the code processing device provided in the embodiments of this application; Figure 8 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0013] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application. At the same time, in the description of the embodiments of this application, the terms "first," "second," etc., are only used to distinguish descriptions and should not be construed as indicating or implying relative importance. Thus, features defined with "first" and "second" may explicitly or implicitly include one or more features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly specified.

[0014] This application provides a code processing method, apparatus, electronic device, and computer-readable storage medium. Specifically, this embodiment will be described from the perspective of a code processing apparatus, which can be integrated into an electronic device. That is, the code processing method of this application embodiment can be executed by an electronic device. Optionally, the electronic device may include a terminal device. The terminal device may be a mobile phone, tablet computer, smart Bluetooth device, laptop computer, or personal computer (PC), etc.

[0015] The code processing method provided in this application can be applied to interactive systems, such as terminal devices and servers. The terminal can be a device that includes both receiving and transmitting hardware, i.e., a device with receiving and transmitting hardware capable of performing bidirectional communication over a bidirectional communication link. The terminal device and the server can communicate bidirectionally via a network.

[0016] Optionally, the server can be a standalone server, or a server network or server cluster, including but not limited to computers, network hosts, single network servers, multiple network server sets, or cloud servers composed of multiple servers. Cloud servers consist of a large number of computers or network servers based on cloud computing.

[0017] In one embodiment of this disclosure, the code processing method can run on a local terminal device or a server. When the game interaction method runs on a server, the method can be implemented and executed based on a cloud interaction system, wherein the cloud interaction system includes a server and a client device.

[0018] Please see Figure 1 , Figure 1 This is a schematic diagram of a code processing system provided in an embodiment of this application. The system may include at least one terminal, at least one server, at least one database, and a network. A user's terminal can connect to different servers via the network. The terminal is any device with computing hardware capable of supporting and executing software products corresponding to model generation. Furthermore, when the system includes multiple terminals, multiple servers, and multiple networks, different terminals can connect to each other through different networks and servers. The network can be a wireless network or a wired network, such as a wireless local area network (WLAN), local area network (LAN), cellular network, 2G network, 3G network, 4G network, 5G network, etc. Additionally, different terminals can also connect to other terminals or servers using their own Bluetooth networks or hotspot networks. For example, multiple users can connect online through different terminals via appropriate networks and synchronize with each other to support multi-user access. Furthermore, the system may include multiple databases coupled to different servers, and information related to the operating environment can be continuously stored in the databases while different users are using the system online.

[0019] The following detailed description is provided in conjunction with the accompanying drawings. In this embodiment, the execution subject is a terminal device as an example. It should be noted that the order of description in the following embodiments is not intended to limit the preferred order of the embodiments. Although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be performed in a different order than that shown in the accompanying drawings.

[0020] Please refer to the following: Figure 2 , Figure 3a , Figure 3b , Figure 3c , Figure 3d and Figure 3e , Figure 3a , Figure 3b , Figure 3c , Figure 3d and Figure 3e The processing node connection diagram of the code processing system provided for the implementation of this application. Figure 2 This is a flowchart illustrating a code processing method provided in an embodiment of this application. The specific flow of the code processing method can be summarized in steps 101 to 107, wherein: Step 101: Obtain the target code to be processed and the first metadata information of the target code.

[0021] In one embodiment, please refer to the following: Figure 3a , Figure 3b , Figure 3c , Figure 3d and Figure 3e The code processing system provided in this application integrates a large language model, static code analysis tools, a metadata management system, and an automated execution engine, thus forming an end-to-end code optimization pipeline. Users only need to input the target code to be optimized or the code location information of the target code, and the system can automatically complete the entire process from code understanding, solution generation, code rewriting to data verification, and output the optimized code, verification report, and technical documentation.

[0022] In this embodiment of the application, before the step of "obtaining the target code to be processed and the first metadata information of the target code", the method further includes: Obtain user input information and determine the first code to be processed based on the user input information; The first code to be processed is parsed to obtain the parsed first code and the corresponding first metadata information, and the parsed first code is used as the target code.

[0023] Specifically, the step "determining the first code to be processed based on the user data information" includes: If the user input information is code query information, then based on the code query information, a first code that matches the code query information is determined from the candidate codes stored in the preset database; If the user input information is a code file, then the code in the code file will be used as the first code.

[0024] For example, please refer to the following: Figure 3a , Figure 3b , Figure 3c , Figure 3d and Figure 3e Users input their optimization goals through the "Start" node in the workflow. This system supports the following two modes: (1) Metadata mode: Users can enter the database name and table name (i.e. code query information), and the system will automatically obtain the corresponding SQL code from the metadata management center (i.e. the preset database); (2) File upload mode: Users can directly upload code files (such as ".jar", ".sql", ".java", etc.), and the system will automatically retrieve the code from the code file.

[0025] Specifically, the start node can transmit the acquired user input data to the conditional branch node "conditional branch", thereby determining which mode is currently being applied through the conditional branch node.

[0026] For further details, please refer to the following: Figure 3a , Figure 3b , Figure 3c , Figure 3d and Figure 3e The system can use JAR document extractors, SQL document extractors, and / or metadata JSON parsing nodes for subsequent operations. Specifically, the system parses the input target code. For SQL code, it uses a Python scripting tool to parse its structure and generates optimization schemes using metadata. For JAR packages, it uses CodeMaker code analysis tools to scan and parse them, analyzing dependency files. Furthermore, the system automatically obtains the task execution context, such as the data warehouse's T+1 partition time.

[0027] Step 102: Based on the target code, the first metadata information, and at least one optimization requirement for the code optimization task of the target code, generate a first prompt word for the code optimization task.

[0028] The optimization requirements include performance optimization, logic optimization, and syntax optimization. Performance bottlenecks refer to code execution bottlenecks caused by logical design flaws or mismatch with engine characteristics, resulting in extremely low execution efficiency, excessive resource (CPU / memory / storage) consumption, and even failure to complete within the business-required time window (e.g., a data warehouse T+1 task requiring completion before 5 AM, but the code takes 3 hours and times out). Therefore, performance optimization is needed. Redundant logic exists in the code, meaningless repetitive operations, ineffective execution, and unnecessary processing. This logic neither adds business value nor changes the core result, but it consumes additional resources and slows down execution. Therefore, logic optimization is needed. Poor coding habits lead to syntax errors, meaning code that does not conform to industry standards, data warehouse standards, or best practices. While this may not affect execution in the short term, it easily introduces bugs, increases maintenance costs, and reduces code readability in the long term. Therefore, syntax optimization is needed.

[0029] For example, please see Figure 4 Based on the target code, the first metadata information, and at least one optimization requirement for the code optimization task targeting the target code, a first prompt word for the code optimization task can be generated. The first prompt word is as follows: Figure 4 The content corresponding to SYSTEM is shown below.

[0030] Step 103: Execute the code optimization task based on the first prompt word using the target large language model to output the optimized target code.

[0031] In one embodiment, the step "performing the code optimization task based on the first prompt word using the target large language model to output optimized target code" includes: The optimization scheme for the optimization requirement is determined by the target large language model based on the first prompt word and the configuration information pre-configured by the target large language model and associated with the optimization requirement. Based on the optimization scheme, the target language model performs the code optimization task on the target code in the first prompt word to output the optimized target code.

[0032] Specifically, the optimization requirements include performance optimization requirements; the step "determining an optimization scheme for the optimization requirements based on the first prompt word and the pre-configured configuration information associated with the optimization requirements by the target large language model" includes: The target large language model determines a performance optimization scheme for the performance optimization requirement based on the first prompt word and the performance optimization configuration information pre-configured by the target large language model related to the performance optimization requirement.

[0033] Among them, the performance optimization configuration information pre-configured in the target large language model related to the performance optimization requirements can be programming language execution rules. The programming language execution rules can include: parsing the AST to identify whether there is a partition field (dt) filtering, linking metadata to confirm that the table is a large table (e.g., 100TB), and combining the T+1 rule to determine whether dt=${dt} should be filtered but was not; determining whether there are inefficient JSON operations, specifically parsing the JOIN order (large table JOIN small table / Cartesian product), and combining the Hive / Spark execution rules to determine whether the JOIN method is reasonable; it can also identify whether the aggregation field (SUM / COUNT) is based on the partition / index field, deduce the execution plan, and determine whether there is global aggregation; and determining whether the T+1 task has a timeout risk, by parsing the code data processing volume (e.g., full table scan), and combining the scheduling metadata (timeout threshold of 1 hour) to predict the execution time.

[0034] Specifically, the optimization requirements include logical optimization requirements; the step "determining the optimization scheme for the optimization requirements based on the first prompt word and the configuration information pre-configured by the target large language model and associated with the optimization requirements" includes: Based on the first prompt word and the logic optimization configuration information pre-configured by the target large language model related to the logic optimization requirements, a logic optimization scheme is determined for the logic optimization requirements.

[0035] The pre-configured logic optimization configuration information of the target large language model, related to the aforementioned logic optimization requirements, can identify whether the code performs repetitive work or executes meaningless logic through semantic-level logic comparison and execution path deduction. Specifically, this includes: parsing the AST to identify duplicate subqueries / function calls and determining whether the duplicate logic is business-necessary; deducing conditional logic to identify unexecuted code blocks; and identifying unreused temporary tables and, in conjunction with data warehouse storage rules, determining resource waste.

[0036] Specifically, the optimization requirements include grammatical optimization requirements; the step "determining an optimization scheme for the optimization requirements based on the first prompt word and the pre-configured configuration information associated with the optimization requirements by the target large language model" includes: Based on the first prompt word and the pre-configured syntax optimization information related to the syntax optimization requirements, the target large language model determines a syntax optimization scheme for the syntax optimization requirements.

[0037] The pre-configured syntax optimization configuration information related to the syntax optimization requirements in the target large language model can be programming language specifications, specifically including: identifying fixed values ​​(such as dates, table names), and determining whether context parameters should be used in conjunction with the T+1 rule; identifying whether variable / table names conform to naming conventions and determining whether core logic has comments; identifying whether temporary tables are dropped after creation and determining resource usage in conjunction with storage metadata; and identifying whether SELECT * is used and determining whether sensitive fields are anonymized in conjunction with data compliance metadata.

[0038] In this embodiment, the system can perform code analysis and optimization based on a Large Language Model (LLM). Specifically, the parsed target code, metadata information (such as table size and JOIN relationships), and preset optimization hints can be submitted to the LLM. The LLM performs in-depth code analysis, identifies performance bottlenecks, redundant logic, and poor programming habits, and generates corresponding optimization schemes: syntax optimization schemes, logic refactoring schemes, and performance tuning suggestions. Furthermore, the Large Language Model can directly output the refactored target code (i.e., the optimized target code) based on the above optimization schemes.

[0039] Optionally, to ensure that the optimized target code can process data automatically, completely, and accurately, before the step "generating the second prompt word for the code verification language generation task based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code", the method further includes: The optimized target code is filtered and extracted based on preset code processing conditions to obtain the latest optimized target code.

[0040] For example, please refer to the following: Figure 3a , Figure 3b , Figure 3c , Figure 3d and Figure 3e The system can use the parameter extractor (i.e., the SQL extractor node "SQL extractor") to filter and extract the optimized target code, so as to extract the clean optimized target code.

[0041] Step 104: Based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code, generate a second prompt word for the code verification language generation task.

[0042] In one embodiment, before the step of "generating the second prompt word for the code verification language generation task based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code", the method further includes: Obtain a first data table of the target code and a second data table of the optimized target code. The first data table is used to collect data generated after the target code executes a preset task, and the second data table is used to collect data generated after the optimized target code executes the preset task.

[0043] Among them, the temporary tables generated before and after the code optimization are the core temporary result tables generated after executing the same data warehouse task based on the same batch of source data. These two temporary tables can be used for verification. Specifically, by comparing the differences in the results before and after the optimization, the correctness of the optimized code can be verified.

[0044] In this embodiment, the system can automatically create a temporary table using the optimized target code and execute it to obtain a second data table in an isolated environment (such as a test library); it can also automatically create a temporary table using the target code and execute it to obtain a first data table, or directly obtain the first data table obtained from the historical execution of the target code.

[0045] The isolated environment (test database) is a testing ground for the code. It is an independent database / data warehouse environment that is completely isolated from the production database (for example, the production database is dw_prod and the test database is dw_test). The data in the isolated environment is a mirror copy of the production data. Operations performed in the isolated environment will not affect production business (for example, deleting tables or modifying data in the test database will not affect the production database at all), and the data generated is consistent with the data generated in the production database.

[0046] Furthermore, the step "generating the second prompt word for the code verification language generation task based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code" includes: Based on the first data table of the target code, the second data table of the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code, a second prompt word for the code verification language generation task is generated.

[0047] For example, please see Figure 5 The system can call the Large Language Model (LLM) to automatically generate verification SQL (i.e., target code verification language) for comparing the consistency of data generated by the code before and after optimization. The second prompt word is as follows: Figure 5 The content corresponding to USER is shown below.

[0048] Among them, Structured Query Language (SQL) is a standardized programming language specifically designed for managing, manipulating, and analyzing relational databases / data warehouses. It focuses on data dialogue and can accurately define data structures, process data, and analyze data without needing to concern itself with the underlying storage details.

[0049] Step 105: Execute the code verification language generation task based on the second prompt word using the target large language model to output the target code verification language.

[0050] For example, please see Figure 6 The system can call the Large Language Model (LLM) and automatically generate a verification SQL (i.e., target code verification language) based on the second prompt word to compare the consistency of the data generated by the code before and after optimization.

[0051] Step 106: Based on the target code, the optimized target code, the target code verification language, and the data analysis requirements of the data analysis task, generate the third prompt word for the data analysis task.

[0052] In one embodiment, generating a third prompt word for the data analysis task based on the target code, the optimized target code, the target code validation language, and the data analysis requirements of the data analysis task includes: Based on the first data table of the target code, the second data table of the optimized target code, the target code verification language, and the data analysis requirements of the data analysis task, a third prompt word for the data analysis task is generated.

[0053] Specifically, the system executes data validation SQL to obtain the differences between the data before and after optimization. LLM analyzes and interprets the differences to determine whether the optimization was completed while ensuring data accuracy.

[0054] Step 107: Perform the data analysis task based on the third prompt word using the target large language model to output the data comparison results between the target code and the optimized target code. The data comparison results are used to indicate the accuracy of the data obtained when the optimized target code is run.

[0055] Based on the above description, the following examples will further illustrate the code processing method of this application. Specific embodiments of the code processing method are described below.

[0056] In one embodiment, after the step "performing the data analysis task based on the third prompt word using the target large language model to output a data comparison result between the target code and the optimized target code, the data comparison result being used to indicate the accuracy of the data obtained when the optimized target code is run", the method further includes: Based on the optimization requirements, the optimization scheme, the optimized target code, and the data comparison results, a target file is generated and stored in a preset database.

[0057] Specifically, this application embodiment can automate the document accumulation process through the system. The system's node workflow will automatically integrate the entire code optimization process—code analysis report, optimization plan, rewritten code, data verification results, and expected performance improvements—into a structured Markdown document. This document can be saved as a technical asset, facilitating subsequent review and reuse of experience.

[0058] In summary, the embodiments of this application provide a code processing method that can perform code optimization, code verification of the optimized code, and data comparison of the code before and after optimization by executing the target code through the target large language model. This provides a complete automated code processing flow covering code optimization and refactoring, online data verification, and automatic comparison of data results. Key steps such as post-optimized code analysis and evaluation and data verification do not require manual completion by developers, realizing automated closed-loop management of the entire code refactoring process and effectively improving the processing efficiency of code refactoring.

[0059] This embodiment also provides a code processing device, which can be specifically integrated into a terminal device. For example, such as Figure 7 As shown, the processing device for this code may include: The acquisition unit 201 is used to acquire the target code to be processed and the first metadata information of the target code; The first generation unit 202 is used to generate a first prompt word for the code optimization task based on the target code, the first metadata information, and at least one optimization requirement for the code optimization task of the target code. The first execution unit 203 is used to perform the code optimization task based on the first prompt word through the target large language model, so as to output the optimized target code; The second generation unit 204 is used to generate a second prompt word for the code verification language generation task based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code. The second execution unit 205 is used to execute the code verification language generation task based on the second prompt word through the target large language model, so as to output the target code verification language; The third generation unit 206 is used to generate a third prompt word for the data analysis task based on the target code, the optimized target code, the target code verification language, and the data analysis requirements of the data analysis task. The third execution unit 207 is used to perform the data analysis task based on the third prompt word through the target large language model, so as to output the data comparison result between the target code and the optimized target code, and the data comparison result is used to indicate the accuracy of the data obtained when the optimized target code is run.

[0060] In some embodiments, the code processing apparatus includes a processing subunit for: The optimization scheme for the optimization requirement is determined by the target large language model based on the first prompt word and the configuration information pre-configured by the target large language model and associated with the optimization requirement. Based on the optimization scheme, the target language model performs the code optimization task on the target code in the first prompt word to output the optimized target code.

[0061] In some embodiments, the code processing apparatus includes a processing subunit for: The target large language model determines a performance optimization scheme for the performance optimization requirement based on the first prompt word and the performance optimization configuration information pre-configured by the target large language model related to the performance optimization requirement.

[0062] In some embodiments, the code processing apparatus includes a processing subunit for: Based on the first prompt word and the logic optimization configuration information pre-configured by the target large language model related to the logic optimization requirements, a logic optimization scheme is determined for the logic optimization requirements.

[0063] In some embodiments, the code processing apparatus includes a processing subunit for: Based on the first prompt word and the pre-configured syntax optimization information related to the syntax optimization requirements, the target large language model determines a syntax optimization scheme for the syntax optimization requirements.

[0064] In some embodiments, the code processing apparatus includes a processing subunit for: The optimized target code is filtered and extracted based on preset code processing conditions to obtain the latest optimized target code.

[0065] In some embodiments, the code processing apparatus includes a processing subunit for: Obtain a first data table of the target code and a second data table of the optimized target code. The first data table is used to collect data generated after the target code executes a preset task, and the second data table is used to collect data generated after the optimized target code executes the preset task.

[0066] In some embodiments, the code processing apparatus includes a processing subunit for: Based on the first data table of the target code, the second data table of the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code, a second prompt word for the code verification language generation task is generated.

[0067] In some embodiments, the code processing apparatus includes a processing subunit for: Based on the first data table of the target code, the second data table of the optimized target code, the target code verification language, and the data analysis requirements of the data analysis task, a third prompt word for the data analysis task is generated.

[0068] In some embodiments, the code processing apparatus includes a processing subunit for: Based on the optimization requirements, the optimization scheme, the optimized target code, and the data comparison results, a target file is generated and stored in a preset database.

[0069] In some embodiments, the code processing apparatus includes a processing subunit for: Obtain user input information and determine the first code to be processed based on the user input information; The first code to be processed is parsed to obtain the parsed first code and the corresponding first metadata information, and the parsed first code is used as the target code.

[0070] In some embodiments, the code processing apparatus includes a processing subunit for: If the user input information is code query information, then based on the code query information, a first code that matches the code query information is determined from the candidate codes stored in the preset database; If the user input information is a code file, then the code in the code file will be used as the first code.

[0071] This application discloses a code processing apparatus. An acquisition unit 201 acquires target code to be processed and first metadata information of the target code. A first generation unit 202 generates a first prompt word for the code optimization task based on the target code, the first metadata information, and at least one optimization requirement for a code optimization task targeting the target code. A first execution unit 203 executes the code optimization task based on the first prompt word using a target large language model to output optimized target code. A second generation unit 204 generates the code based on the target code, the optimized target code, and the task requirements for a code verification language generation task targeting the target code and the optimized target code. The second execution unit 205 executes the code verification language generation task based on the second prompt word using the target large language model to output the target code verification language; the third generation unit 206 generates a third prompt word for the data analysis task based on the target code, the optimized target code, the target code verification language, and the data analysis requirements of the data analysis task; the third execution unit 207 executes the data analysis task based on the third prompt word using the target large language model to output a data comparison result between the target code and the optimized target code, wherein the data comparison result is used to indicate the accuracy of the data obtained when the optimized target code is run. This embodiment of the application can perform code optimization, code verification of the optimized code, and data comparison of the code before and after optimization by executing the target code using the target large language model, thereby providing a complete automated code processing flow covering code optimization and refactoring, online data verification, and automatic comparison of data results. Key steps such as optimized code analysis and evaluation and data verification do not require manual completion by developers, achieving automated closed-loop management of the entire code refactoring process and effectively improving the processing efficiency of code refactoring.

[0072] Accordingly, this application also provides an electronic device, which can be a terminal, such as a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. Alternatively, the electronic device can be a server.

[0073] like Figure 8 As shown, Figure 8This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device 300 includes a processor 301 with one or more processing cores, a memory 302 with one or more computer-readable storage media, and a computer program stored in the memory 302 and executable on the processor. The processor 301 and the memory 302 are electrically connected. Those skilled in the art will understand that the electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0074] The processor 301 is the control center of the electronic device 300. It connects various parts of the electronic device 300 via various interfaces and lines. By running or loading software programs and / or units stored in the memory 302, and by calling data stored in the memory 302, it executes various functions and processes data of the electronic device 300, thereby providing overall monitoring of the electronic device 300. The processor 301 can be a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), etc., and can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application.

[0075] In this embodiment, the processor 301 in the electronic device 300 loads the instructions corresponding to the processes of one or more applications into the memory 302 according to the following steps, and the processor 301 runs the applications stored in the memory 302 to realize various functions, such as: Obtain the target code to be processed, and the first metadata information of the target code; Based on the target code, the first metadata information, and at least one optimization requirement for the code optimization task of the target code, a first prompt word for the code optimization task is generated; The code optimization task is performed based on the first prompt word using the target large language model to output the optimized target code; Based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code, a second prompt word for the code verification language generation task is generated; The code verification language generation task is performed by the target large language model based on the second prompt word to output the target code verification language; Based on the target code, the optimized target code, the target code validation language, and the data analysis requirements of the data analysis task, a third prompt word for the data analysis task is generated; The data analysis task is performed based on the third prompt word using the target large language model to output a data comparison result between the target code and the optimized target code. The data comparison result is used to indicate the accuracy of the data obtained when the optimized target code is run.

[0076] The electronic device provided in this application embodiment can perform operations such as code optimization, code verification of the optimized code, and data comparison of the code before and after optimization by executing the target code through the target large language model. This provides a complete automated code processing flow covering code optimization and refactoring, online data verification, and automatic comparison of data results. Key steps such as post-optimized code analysis and evaluation and data verification do not require manual completion by the developer. This achieves automated closed-loop management of the entire code refactoring process and effectively improves the processing efficiency of code refactoring.

[0077] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0078] Optional, such as Figure 8 As shown, the electronic device 300 also includes: a touch display screen 303, a radio frequency circuit 304, an audio circuit 305, an input unit 306, and a power supply 307. The processor 301 is electrically connected to the touch display screen 303, the radio frequency circuit 304, the audio circuit 305, the input unit 306, and the power supply 307. Those skilled in the art will understand that... Figure 8 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0079] The touch display screen 303 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 303 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the electronic device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 301. It can also receive and execute commands from the processor 301. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 301 to determine the type of touch event. Subsequently, the processor 301 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 303 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 303 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 303 can also be used as part of the input unit 306 to achieve input functions.

[0080] The radio frequency circuit 304 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other electronic devices, and to transmit and receive signals with network devices or other electronic devices.

[0081] Audio circuitry 305 can be used to provide an audio interface between a user and an electronic device via a speaker and a microphone. Audio circuitry 305 converts received audio data into electrical signals, transmits them to the speaker, and the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuitry 305, converted back into audio data, and then processed by processor 301 before being transmitted via radio frequency circuitry 304 to, for example, another electronic device, or output to memory 302 for further processing. Audio circuitry 305 may also include an earphone jack to facilitate communication between peripheral headphones and electronic devices.

[0082] The input unit 306 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.

[0083] Power supply 307 is used to supply power to various components of electronic device 300. Optionally, power supply 307 can be logically connected to processor 301 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 307 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0084] although Figure 8 As not shown in the diagram, the electronic device 300 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.

[0085] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0086] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0087] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of computer programs, which can be loaded by a processor to execute any of the code processing methods provided in embodiments of this application. The computer program can execute the steps of the following code processing method: Obtain the target code to be processed, and the first metadata information of the target code; Based on the target code, the first metadata information, and at least one optimization requirement for the code optimization task of the target code, a first prompt word for the code optimization task is generated; The code optimization task is performed based on the first prompt word using the target large language model to output the optimized target code; Based on the target code, the optimized target code, and the task requirements for the code verification language generation task for the target code and the optimized target code, a second prompt word for the code verification language generation task is generated; The code verification language generation task is performed by the target large language model based on the second prompt word to output the target code verification language; Based on the target code, the optimized target code, the target code validation language, and the data analysis requirements of the data analysis task, a third prompt word for the data analysis task is generated; The data analysis task is performed based on the third prompt word using the target large language model to output a data comparison result between the target code and the optimized target code. The data comparison result is used to indicate the accuracy of the data obtained when the optimized target code is run.

[0088] Because the computer program stored in this storage medium can perform operations such as code optimization, code verification of the optimized code, and data comparison of the code before and after optimization by executing the target code through the target large language model, it provides a complete automated code processing flow covering code optimization and refactoring, online data verification, and automatic comparison of data results. Key steps such as post-optimized code analysis and evaluation and data verification do not need to be manually completed by developers, realizing automated closed-loop management of the entire code refactoring process and effectively improving the processing efficiency of code refactoring.

[0089] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0090] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0091] Since the computer program stored in the computer-readable storage medium can execute any of the code processing methods provided in the embodiments of this application, it can achieve the beneficial effects that any of the code processing methods provided in the embodiments of this application can achieve, as detailed in the preceding embodiments, and will not be repeated here.

[0092] According to one aspect of this application, a computer program product or computer program is also provided, comprising computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the methods provided in the various optional implementations of the above embodiments.

[0093] In the above embodiments of the code processing apparatus, computer-readable storage medium, electronic device, and computer program product, the descriptions of each embodiment have different focuses. Parts not described in detail in a particular embodiment can be referred to in the relevant descriptions of other embodiments. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process and beneficial effects of the above-described code processing apparatus, computer-readable storage medium, computer program product, electronic device, and their corresponding units can be referred to the description of the code processing method in the above embodiments, and will not be repeated here.

[0094] The foregoing has provided a detailed description of a code processing method, apparatus, electronic device, computer-readable storage medium, and computer program product provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A method of processing code, characterized by, The method comprises: acquiring target code to be processed and first metadata information of the target code; generating a first prompt word of a code optimization task based on the target code, the first metadata information, and optimization requirements of at least one of the code optimization task for the target code; executing the code optimization task based on the first prompt word by a target large language model to output optimized target code; generating a second prompt word of a code verification language generation task based on the target code, the optimized target code, and task requirements of the code verification language generation task for the target code and the optimized target code; executing the code verification language generation task based on the second prompt word by the target large language model to output target code verification language; generating a third prompt word of a data analysis task based on the target code, the optimized target code, the target code verification language, and data analysis requirements of the data analysis task; executing the data analysis task based on the third prompt word by the target large language model to output a data comparison result between the target code and the optimized target code, the data comparison result being used to indicate an accuracy degree of data obtained when the optimized target code is running.

2. The method of claim 1, wherein, The execution of the code optimization task based on the first prompt word by the target large language model to output the optimized target code comprises: determining an optimization scheme for the optimization requirements based on the first prompt word and configuration information associated with the optimization requirements and preconfigured by the target large language model; executing the code optimization task for the target code in the first prompt word based on the optimization scheme by the target large language model to output the optimized target code.

3. The method of claim 2, wherein, The optimization requirements comprise performance optimization requirements; the determination of the optimization scheme for the optimization requirements based on the first prompt word and the configuration information associated with the optimization requirements and preconfigured by the target large language model comprises: determination of a performance optimization scheme for the performance optimization requirements based on the first prompt word and performance optimization configuration information related to the performance optimization requirements and preconfigured by the target large language model.

4. The method of claim 2, wherein, The optimization requirements comprise logic optimization requirements; the determination of the optimization scheme for the optimization requirements based on the first prompt word and the configuration information associated with the optimization requirements and preconfigured by the target large language model comprises: determination of a logic optimization scheme for the logic optimization requirements based on the first prompt word and logic optimization configuration information related to the logic optimization requirements and preconfigured by the target large language model.

5. The method of claim 2, wherein, The optimization requirements comprise syntax optimization requirements; the determination of the optimization scheme for the optimization requirements based on the first prompt word and the configuration information associated with the optimization requirements and preconfigured by the target large language model comprises: The target large language model determines a grammar optimization scheme for the grammar optimization requirement based on the first prompt word and grammar optimization configuration information related to the grammar optimization requirement pre-configured by the target large language model.

6. The method of claim 1, wherein, Before the second prompt word of the code verification language generation task is generated based on the target code, the optimized target code, and a task requirement of the code verification language generation task for the target code and the optimized target code, the method further includes: The optimized target code is subjected to screening and extraction processing based on a preset code processing condition to obtain the latest optimized target code.

7. The method of claim 1, wherein, Before the second prompt word of the code verification language generation task is generated based on the target code, the optimized target code, and a task requirement of the code verification language generation task for the target code and the optimized target code, the method further includes: A first data table of the target code and a second data table of the optimized target code are obtained, the first data table is used to count data generated after the target code executes a preset task, and the second data table is used to count data generated after the optimized target code executes the preset task.

8. A processing apparatus of a code, characterized by, Comprise: An acquisition unit is configured to acquire a target code to be processed and first metadata information of the target code; A first generation unit is configured to generate a first prompt word of a code optimization task based on the target code, the first metadata information, and at least one optimization requirement of the code optimization task for the target code; A first execution unit is configured to execute the code optimization task based on the first prompt word by a target large language model to output an optimized target code; A second generation unit is configured to generate a second prompt word of a code verification language generation task based on the target code, the optimized target code, and a task requirement of the code verification language generation task for the target code and the optimized target code; A second execution unit is configured to execute the code verification language generation task based on the second prompt word by the target large language model to output a target code verification language; A third generation unit is configured to generate a third prompt word of a data analysis task based on the target code, the optimized target code, the target code verification language, and a data analysis requirement of the data analysis task; A third execution unit is configured to execute the data analysis task based on the third prompt word by the target large language model to output a data comparison result between the target code and the optimized target code, the data comparison result being used to indicate an accuracy degree of data obtained when the optimized target code is running.

9. An electronic device, comprising: The processor and the memory, the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps of the code processing method of any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a plurality of instructions adapted to be loaded by the processor to execute the steps of the processing method of the code according to any one of claims 1-7.