Code conversion method and device, electronic equipment and storage medium

By automatically converting the robot's native code into a universal open protocol using an intelligent agent, the problem of high integration difficulty and high cost caused by manual conversion in existing technologies is solved. This achieves efficient and accurate code conversion, reducing human intervention and system risks.

CN121680863APending Publication Date: 2026-03-17MIDEA GRP (SHANGHAI) CO LTD +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511836725.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-05
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

In existing technologies, when integrating industrial robots with automation systems, it is necessary to manually convert the robot's native code to a general open protocol, which results in high integration difficulty, high cost, and easy introduction of human error.

Method used

By deploying intelligent agents and utilizing preset rules and target knowledge bases, the robot's native code is automatically converted into code that conforms to common open protocols. Combined with a trained code simplification model, simplification and anomaly detection are performed to ensure the accuracy and efficiency of the conversion.

Benefits of technology

It achieves the goal of eliminating the need for manual code conversion, reducing integration difficulty and cost, improving conversion efficiency and system stability, and reducing the risk of manual intervention and semantic bias.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121680863A_ABST
    Figure CN121680863A_ABST
Patent Text Reader

Abstract

The invention provides a code conversion method and device, electronic equipment and a storage medium, the method is applied to an intelligent agent running in the electronic equipment, and the method comprises the steps that to-be-converted original code data is acquired, and the original code data follows a first protocol; on the basis of a preset rule and a target knowledge base, a function module area and a variable definition area corresponding to the original code data are generated, and the preset rule is used for limiting basic constraint standards of different variables and motion instructions in a second protocol; a plurality of variable definition cases matched with the second protocol and function module cases corresponding to different motion instructions are stored in the target knowledge base; and generating target code data corresponding to the original code data according to the function module area and the variable definition area. According to the method, the robot native code can be automatically converted into the code conforming to the universal open protocol of the automatic system, manual code conversion is not needed, the conversion efficiency is high, and the integration difficulty and cost of the automatic system can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automation technology, and more specifically, to code conversion methods, apparatus, electronic devices, and storage media in the field of automation technology. Background Technology

[0002] In the field of modern industrial automation, the collaborative work of industrial robots and programmable logic controllers (PLCs) is a core element for the efficient operation of such systems. Industrial robots, with their advantages of high precision and high stability, are widely used in industries such as automotive manufacturing, machining, and electronics.

[0003] Currently, to achieve collaborative control of multiple devices, most automation systems adopt universal open protocols as a unified communication standard. However, to ensure their own control accuracy and functional specificity, many industrial robots are designed based on dedicated control systems and programming languages, forming a unique motion command system. This motion command system has significant incompatibility with universal open protocols. Therefore, when integrating industrial robots into automation systems, it is necessary to arrange professional technicians to manually convert the robot's native code to make it compatible with universal open protocols, which greatly increases the difficulty and cost of system integration. Summary of the Invention

[0004] This application provides a code conversion method, apparatus, electronic device, and storage medium. The code conversion method can automatically convert the robot's native code into code that conforms to the common open protocol of the automation system without the need for manual code conversion.

[0005] In a first aspect, this application provides a code conversion method applied to an intelligent agent running in an electronic device, the method comprising: Obtain the raw code data to be converted, wherein the raw code data conforms to a first protocol; Based on preset rules and target knowledge base, a functional module area and variable definition area corresponding to the original code data are generated. The preset rules are used to limit the basic constraint standards of different variables and motion commands in the second protocol. The target knowledge base stores multiple variable definition cases adapted to the second protocol and functional module cases corresponding to different motion commands. Based on the functional module area and the variable definition area, target code data corresponding to the original code data is generated, and the target code data follows the second protocol.

[0006] In this embodiment, by deploying an intelligent agent and defining compliance boundaries with preset rules as a rigid framework, and filling in scenario-based details with cases in the target knowledge base as flexible support, the intelligent agent is assisted in completing code conversion in conjunction with preset rules and the target knowledge base. This enables the robot's native code to be automatically converted into code that conforms to the general open protocol of the automation system without the need for manual code conversion. The conversion efficiency is high, which helps to reduce the integration difficulty and cost of the automation system.

[0007] In conjunction with the first aspect, in some possible implementations, before generating the functional module area and variable definition area corresponding to the original code data based on preset rules and the target knowledge base, the method further includes: The trained code simplification model is invoked to simplify the original code data.

[0008] In this embodiment, by calling the training model to simplify the code before code conversion, the difficulty of code conversion and the risk of semantic deviation can be effectively reduced, ensuring the correctness and efficiency of code conversion. Moreover, with the model's strong syntax parsing ability, semantic understanding ability and domain knowledge transfer ability, it can automatically adapt to the syntax differences of the native code of robots from different manufacturers and automatically learn complex and redundant patterns. There is no need for frequent manual updates of rules / templates, which effectively reduces the cost of manual intervention and improves the efficiency and versatility of code simplification.

[0009] In conjunction with the first aspect, in some possible implementations, the invocation of the trained code simplification model to simplify the original code data includes: Call the trained code simplification model and check whether the length of the original code data exceeds the model input length; When the length of the original code data exceeds the length of the model input, the original code data is split into multiple data segments. Each of the aforementioned data segments is simplified to obtain multiple simplified data segments, and these multiple simplified data segments are merged through context checking.

[0010] In conjunction with the first aspect, in some possible implementations, the training steps of the code-simplified model include: Obtain a set of converted code samples, wherein each converted code sample in the set includes an original code data sample and a simplified code data sample; Based on preset simplified prompts, the original code data sample is simplified using a large language model to obtain the model output result; Based on the model output and the corresponding simplified code data samples, the parameters of the large language model are adjusted to obtain a trained simplified code model.

[0011] In conjunction with the first aspect, in some possible implementations, the training steps of the code-simplified model further include: Anomaly detection is performed on the output results of the model; If an anomaly is detected in the model output, the model output is marked and backed up, and the corresponding original code data sample is simplified again using the large language model.

[0012] In this embodiment, by introducing anomaly detection of model output results during model training, and triggering a retry mechanism and marking backups if anomalies occur, the model can be effectively prevented from exhibiting illusions during training, thereby improving the accuracy and reliability of model simplification.

[0013] In conjunction with the first aspect, in some possible implementations, the anomaly detection of the model output includes: Detect whether the executable file in the model output contains Chinese characters; If the executable file contains Chinese characters, the model output is deemed abnormal.

[0014] In conjunction with the first aspect, in some possible implementations, before generating the functional module area and variable definition area corresponding to the original code data based on preset rules and the target knowledge base, the method further includes: The original code data is simplified according to preset redundancy rules, preset simplification templates, and / or preset custom functions.

[0015] In conjunction with the first aspect, in some possible implementations, generating the functional module area and variable definition area corresponding to the original code data based on preset rules and a target knowledge base includes: Read and parse the executable program file and data file from the original code data; The retrieval enhancement generation tool is invoked to retrieve variable definition cases and functional module cases related to the parsed content from the target knowledge base; Based on preset rules and the retrieved variable definition cases and functional module cases, the functional module area and variable definition area corresponding to the parsed content are generated.

[0016] In conjunction with the first aspect, in some possible implementations, generating the functional module area and variable definition area corresponding to the parsed content based on preset rules and the retrieved variable definition cases and functional module cases includes: Based on the preset rules and the variable definition examples, a variable definition area corresponding to the parsed content is generated; Based on the preset rules and the functional module examples, the functional module area corresponding to the parsed content is generated.

[0017] In conjunction with the first aspect, in some possible implementations, generating the target code data corresponding to the original code data based on the functional module area and the variable definition area includes: Merge the variable definition area and the functional module area; Check if there is at least one unconverted code data segment in the merged code data; If it exists, a preset identifier is added to the corresponding code data segment for verification, and the verified code data is used as the target code data corresponding to the original code data. If it does not exist, the merged code data will be used as the target code data corresponding to the original code data.

[0018] In conjunction with the first aspect, in some possible implementations, the method further includes, before obtaining the original code data to be converted: Receive raw input data from the user; The original input data is subjected to intent recognition to determine the user's intent; When the user intent indicates code conversion, the original code data to be converted is determined from the original input data.

[0019] In this embodiment, by performing intent recognition when receiving the user's original input data, the conversion requirements and conversion range can be determined, thereby ensuring that the code conversion direction is correct from the source, reducing conversion errors caused by intent deviation, and improving the accuracy of code conversion.

[0020] Secondly, this application provides a code conversion device for use with an intelligent agent running in an electronic device, the device comprising: An acquisition unit is used to acquire the raw code data to be converted, wherein the raw code data conforms to a first protocol; The first generation unit is used to generate the functional module area and variable definition area corresponding to the original code data based on preset rules and target knowledge base. The preset rules are used to limit the basic constraint standards of different variables and motion instructions in the second protocol. The target knowledge base stores multiple variable definition cases adapted to the second protocol and functional module cases corresponding to different motion instructions. The second generation unit is used to generate target code data corresponding to the original code data based on the functional module area and the variable definition area, wherein the target code data follows the second protocol.

[0021] Thirdly, this application provides an electronic device, the electronic device comprising: Memory, used to store executable program code; A processor is configured to call and run the executable program code from the memory, causing the electronic device to perform the method of the first aspect or any possible implementation thereof.

[0022] Fourthly, this application provides a computer program product comprising: computer program code, which, when executed on a computer, causes the computer to perform the method described in the first aspect or any possible implementation thereof.

[0023] Fifthly, this application provides a computer-readable storage medium storing computer program code that, when executed on a computer, causes the computer to perform the methods described in the first aspect or any possible implementation thereof. Attached Figure Description

[0024] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the 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.

[0025] Figure 1 This is an exemplary system architecture diagram of a code conversion method provided in an embodiment of this application; Figure 2 This is a flowchart illustrating a code conversion method provided in an embodiment of this application; Figure 3 This is a flowchart illustrating another code conversion method provided in an embodiment of this application; Figure 4 This is a flowchart illustrating another code conversion method provided in an embodiment of this application; Figure 5 This is a schematic diagram of the overall process framework of the code conversion method provided in the embodiments of this application; Figure 6 This is a schematic diagram of the structure of a code conversion device provided in an embodiment of this application; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0027] In the description of this application, it should be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances. Furthermore, in the description of this application, unless otherwise stated, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship.

[0028] Before introducing this application, the relevant technologies will be introduced first.

[0029] With the development of automation technology, automation systems typically integrate various types of robots to work collaboratively. Currently, automation systems generally use universal open protocols as a unified communication standard. These universal open protocols are recognized cross-vendor / cross-device "data exchange and communication standards" in the automation field, developed by international organizations (such as IEC and ISO) or industry alliances, and have their own fixed data formats, instruction sets, and communication specifications. However, robot manufacturers design proprietary systems to adapt to their own hardware (such as joint motors and reducers) and application scenarios (such as welding and material handling). The robot's native code data (complete program data package) is directly bound to the robot manufacturer's proprietary system, adapting to the protocol specifications of the proprietary system, and cannot run directly in non-vendor proprietary systems (such as automation systems) or devices.

[0030] When integrating robots into automation systems, the robot's native code data needs to be converted. This involves transforming the "manufacturer-specific instructions, data formats, and interaction logic" under proprietary protocols into "standardized instructions, data formats, and communication interfaces" under a universal open protocol. This allows the automation system to directly control the robot based on the universal open protocol, enabling different robots that originally relied on manufacturer-specific protocols to seamlessly integrate into the automation system and achieve standardized communication and collaborative work between different devices. However, this code conversion work has a high technical threshold and often requires a lot of tedious manual programming and debugging by professional technicians. This not only results in low code conversion efficiency, increases the difficulty and cost of system integration, but also easily introduces human error, seriously affecting the stability and reliability of the system.

[0031] To address at least one of the aforementioned technical problems, embodiments of this application provide a code conversion method, apparatus, electronic device, storage medium, and computer program product.

[0032] Please see Figure 1 , Figure 1 This is an exemplary system architecture diagram of a code conversion method provided in an embodiment of this application. Figure 1 As shown, the system architecture may include an agent 101, a network 102, and a lower-level control system 103. The network 102 serves as the medium for providing a communication link between the agent 101 and the lower-level control system 103. The network 102 may include various types of wireless and wired communication links. Wireless communication links include Bluetooth and Wi-Fi links, while wired communication links include Controller Area Network (CAN), LIN bus, FlexRay bus, MOST bus, and Ethernet bus.

[0033] The intelligent agent 101 can interact with the underlying control system 103 via network 102 to receive or send messages to the underlying control system 103. Specifically, the intelligent agent 101 is deployed in electronic devices (such as computers, servers, intelligent development terminals, etc.), and its core function is to receive user code conversion requests (such as converting robot program code into general open protocol code), parse the raw code data, and send instructions, signals, and other messages to the underlying control system 103. After receiving the messages sent by the intelligent agent 101, the underlying control system 103 schedules various underlying functional modules in the electronic device that support code conversion (such as code parsing modules, syntax adaptation modules, knowledge retrieval modules, verification modules, etc.) based on the message scheduling. These modules provide technical support for the entire code conversion process through hardware computing power support and software algorithm collaboration.

[0034] Based on the above system architecture, please refer to Figure 2 , Figure 2 This is a flowchart illustrating a code conversion method provided in an embodiment of this application. The code conversion method is applied to an intelligent agent running in an electronic device, including but not limited to servers, personal computers, laptops, tablets, and smartphones. Specifically, the code conversion method includes the following steps S201-S203, wherein: S201. Obtain the raw code data to be converted, which conforms to the first protocol.

[0035] The raw code data consists of the robot's complete program data package, supporting the robot in completing its tasks (such as industrial grasping, mobile navigation, and autonomous inspection). Typically, for a robot to execute an actual task (e.g., "grab a part - move to the assembly position - complete assembly - return to the origin"), it relies on a series of continuous motion instructions (potentially dozens or even hundreds) and corresponding logic control (such as conditional judgments, parameter definitions, and module calls). The first protocol is the protocol followed by the robot manufacturer's proprietary system. Different robot manufacturers may design different proprietary systems, and different proprietary systems may follow different protocols.

[0036] The raw code data typically includes various strongly related files. The absence of any of these files will cause the robot's functionality to fail. Specifically, the raw code data includes executable program files (e.g., files in ".src" format), data files (e.g., files in ".dat" format), protocol adaptation files (e.g., manufacturer-defined formats such as ".proto / .prt"), descriptive files, and dependency files. The executable program file, as the "logical carrier" for robot task execution, contains the core business process code for the robot to complete a specific task (such as path planning logic, action execution sequences, sensor data processing logic, etc.), and fully complies with the robot manufacturer's proprietary protocol. Data files and executable program files are bound one-to-one. The data file stores the static configuration, dynamic thresholds, hardware adaptation parameters, and other data required for the corresponding executable program file to run, such as motor speed thresholds, sensor calibration parameters, and task execution time windows.

[0037] In some embodiments, when deploying an agent into an electronic device, the agent needs to be initialized to equip it with the necessary capabilities, such as the ability to invoke various tools to perform code conversion. After initialization, the agent enters a standby state, continuously listening to the input interface and waiting to receive raw user input for code conversion. In other embodiments, the initialized agent may also possess other capabilities, which are not limited here. For example, the agent may also have user intent recognition capabilities, that is, it can identify whether the user wants code conversion and the specific conversion range based on the user's raw input.

[0038] S202. Based on preset rules and target knowledge base, generate functional module area and variable definition area corresponding to the original code data. Preset rules are used to limit the basic constraint standards of different variables and motion instructions in the second protocol. The target knowledge base stores multiple variable definition cases adapted to the second protocol and functional module cases corresponding to different robot motion instructions.

[0039] The second protocol is a universally recognized open protocol in the field of automation. Preset rules ensure that the code conversion output conforms to the rigid adaptation requirements of the second protocol. Its basic constraint standards define the naming conventions and data types of different types of variables (such as coordinate variables, velocity variables, attitude variables, and device identifier variables) in the second protocol. It also specifies the corresponding functional module structures and parameter settings for different motion commands (such as robot point-to-point motion commands, linear motion commands, and circular motion commands) in the second protocol.

[0040] The knowledge data in the target knowledge base primarily provides scenario-based and practical case studies and solutions for key stages of code conversion. Generally, the target knowledge base is retrieved using Retrieval-Augmented Generation (RAG) technology. Specifically, the target knowledge base can provide variable definition cases for different types of variables under the second protocol, functional module cases for different motion instructions under the second protocol, and common error correction examples for variable definitions and functional module generation (such as correction schemes for naming that does not conform to protocol specifications or missing required parameters). It can also provide reference cases for highly similar conversion scenarios (such as a unified conversion paradigm for similar motion instructions from different robot manufacturers) to avoid common conversion errors and improve conversion efficiency.

[0041] Specifically, during the code conversion process, preset rules are mainly used to build the basic framework, such as clarifying rigid constraints like variable naming / data type specifications, functional module structure corresponding to motion instructions, input / output parameter boundaries, and control flow execution flow, thus defining the compliance baseline for code conversion. The target knowledge base is mainly used to provide detailed code examples for reference, such as outputting practical references like variable definition examples for similar scenarios, function decomposition details, logic block implementation code, and exception handling paradigms, to assist in generating detailed code within the basic framework.

[0042] Considering that relying solely on preset rules for code conversion might result in variable definitions or functional modules in the final converted code being unable to adapt to the requirements of the desired motion scenario, and relying solely on cases provided by the target knowledge base might result in variable definitions or functional modules in the final converted code not conforming to general open protocols and unable to be integrated into the automation system, this embodiment combines preset rules and knowledge provided by the target knowledge base. Leveraging the complementary characteristics and strong correlation between the two, it jointly assists in completing the code conversion. Preset rules serve as a rigid framework to define compliance boundaries, while knowledge base cases provide flexible support to fill in scenario-specific details. This ensures that the final generated target code data strictly adheres to the adaptation requirements of general open protocols and actual motion scenarios, while also conforming to the business characteristics of the current robot program (such as device compatibility and accuracy requirements). It completely restores the core logic and data links of the original code data, and possesses the characteristics of a well-structured, detailed, and directly integrateable design.

[0043] S203. Based on the functional module area and variable definition area, generate the target code data corresponding to the original code data. The target code data follows the second protocol.

[0044] The agent can call a dedicated merging tool to perform the merging operation. Specifically, it can merge the functional module area and the variable definition area according to the code organization specifications of the second protocol. For example, it can merge the variables, structures, functions, and finally the module entry points in the order of concatenation. It can also complete the dependency imports (such as protocol SDK packages) and syntax closing information (such as parentheses and semicolons) to finally obtain the complete target code data.

[0045] In some embodiments, considering the possibility that some code may fail to be converted successfully, the agent can automatically check the verification after merging and mark the unconverted code parts for the user to check. That is, step 203 above specifically includes: Merge the variable definition area and the functional module area; Check if there is at least one unconverted code data segment in the merged code data; If it exists, a preset identifier is added to the corresponding code data segment for verification, and the verified code data is used as the target code data corresponding to the original code data. If it does not exist, the merged code data will be used as the target code data corresponding to the original code data.

[0046] The checks on merged data can include code integrity verification, protocol compliance verification, and / or logical consistency verification. Code integrity verification primarily checks whether the core functional modules, key variables, and motion instructions of the original code have been omitted or not converted, ensuring that the core logic of the original code is not lost during the conversion process and avoiding functional deficiencies caused by "converting only part of the code." Protocol compliance verification verifies the converted code against the explicit requirements of the second protocol, checking for incompatible code segments in terms of format and rules. For example, it verifies whether variable names, data types, and scopes conform to the specifications of the second protocol, and whether the structure of functional modules, motion instruction formats, and I / O interaction methods conform to the specifications of the second protocol. Logical consistency verification mainly verifies whether the converted code itself is logically consistent and free of dependency conflicts. For example, it checks whether its variable references are valid, and whether the dependencies between variables, functional modules, and motion instructions are valid.

[0047] If the check passes, the merged data will be used as the final output code conversion result. If the check fails, preset identifiers will be automatically added to the failed locations to mark them, and the marked conversion data will be output. This allows users to quickly and accurately locate the failure points for verification and modification, improving verification efficiency. Furthermore, different preset identifiers can be set for different failure types, adding corresponding preset identifiers based on the failure type, so users can directly determine the cause and location of the failure based on the identifier.

[0048] As described above, the code conversion method provided in this embodiment is applied to an intelligent agent running in an electronic device. The intelligent agent acquires the original code data to be converted, which follows a first protocol. Based on preset rules and a target knowledge base, it generates a functional module area and a variable definition area corresponding to the original code data. The preset rules are used to limit the basic constraint standards of different variables and motion instructions in the second protocol. The target knowledge base stores multiple variable definition cases adapted to the second protocol and functional module cases corresponding to different motion instructions. According to the functional module area and the variable definition area, the target code data corresponding to the original code data is generated. That is, by deploying an intelligent agent, the preset rules serve as a rigid framework to define compliance boundaries, and the cases in the target knowledge base serve as flexible support to fill in scenario-based details. The preset rules and the target knowledge base work together to assist the intelligent agent in completing the code conversion, thereby automatically converting the robot's native code into code that conforms to the general open protocol of the automation system. There is no need for manual code conversion, the conversion efficiency is high, and it is beneficial to reduce the integration difficulty and cost of the automation system.

[0049] Based on the code conversion method described in the above embodiments, this embodiment also provides another code conversion method. Please refer to... Figure 3 , Figure 3This is a flowchart illustrating another code conversion method provided in an embodiment of this application. This code conversion method is applied to an intelligent agent running in an electronic device and includes the following steps S301-S304, wherein: S301. Obtain the raw code data to be converted, which conforms to the first protocol.

[0050] Step S301 is the same as step S201 above, and will not be repeated here.

[0051] S302. Call the trained code simplification model to simplify the original code data.

[0052] The purpose of code simplification is to remove redundant information and retain key information related to core business logic and data. This reduces the difficulty of subsequent code conversion and the risk of semantic deviation, ensuring the correctness and efficiency of the code conversion. For example, comments and parameters not read by the compiler may be considered redundant information and need to be removed, while the structure and basic parameters of motion instructions and the sequential structure of algorithms are considered key information and need to be retained.

[0053] Code simplification models can be trained from large language models. By training large language models for code simplification, and leveraging their powerful syntax parsing, semantic understanding, and domain knowledge transfer capabilities, they can automatically adapt to the syntactic differences of native robot code from different vendors and automatically learn complex and redundant patterns. This eliminates the need for frequent manual updates to rules / templates, effectively reducing human intervention costs and improving code simplification efficiency and versatility.

[0054] Specifically, during the code simplification process, the original code data (complete code) is directly provided to the code simplification model. The model then simplifies certain files within the original code data (such as the src file) and stores them according to a preset path. Files that are not simplified (such as dat files) are stored in their original paths. The simplified original code data includes the simplified new files (such as the src file, stored in a new path) and the original files that were not simplified (such as the dat file, stored in the original path).

[0055] In some embodiments, step 302 specifically includes: Call the trained code simplification model and check whether the length of the original code data exceeds the model input length; When the length of the original code data exceeds the length of the model input, the original code data is split into multiple data segments. Each data shard is simplified to obtain multiple simplified data shards, and these simplified data shards are then merged through context checking.

[0056] The code simplification model receives the raw input code data and first analyzes its length. If the length does not exceed the model's input length, the input data is directly simplified. If it does exceed the input length, the input data is first segmented, for example, based on the functional module boundaries and code syntax structure of the robot program. This avoids semantic fragmentation of the segmented data, which could affect the subsequent code simplification results. After segmentation, each segment is simplified based on the model's learning results. Then, all the simplified segmented data are reassembled and integrated into a coherent and complete code according to the logical order, syntax structure, and contextual relationships of the original code data, ensuring a one-to-one correspondence with the unsimplified strongly associated files (such as .dat files).

[0057] It's easy to understand that the code simplification model needs to be trained in advance. Optionally, the training steps for this code simplification model include: Obtain a set of converted code samples, each of which includes a sample of original code data and a sample of simplified code data. Based on the preset simplified prompts, the original code data sample is simplified using a large language model to obtain the model output. Based on the model's output and the corresponding simplified code data samples, the parameters of the large language model are adjusted to obtain a well-trained simplified code model.

[0058] The core of the code simplification tool is built upon example learning based on a large language model. First, a large number of robot code conversion examples (converted code samples) are collected to establish an example library. These examples include complete original code (i.e., original code data samples) and code that has been manually simplified while retaining key information (i.e., simplified code data samples). The core data of the example library consists of paired examples of original and simplified code. Based on the example library, the model learns which information in the original code is redundant and which is critical. For example, comments and parameters not read by the compiler in the original code may be judged as redundant information and need to be deleted, while the structure and basic parameters of motion instructions, the sequential structure of algorithms, etc., are considered critical information that needs to be retained.

[0059] Simultaneously, users can break down and summarize these examples to find key patterns in code simplification and set simplification prompts for the model. For example, simplification prompts can define a simplified process (e.g., inputting original code → identifying redundant information → retaining key information → outputting simplified code), clarify task boundaries (e.g., simplifying only the code without modifying the core logic), and supplement constraints (e.g., retaining the basic parameters of motion instructions). This helps the model quickly grasp the core logic of simplification, improves the model's learning efficiency, and allows the model to achieve better simplification results by continuously adjusting the example and prompt architecture. Furthermore, for examples with excessively long inputs, the prompt architecture can guide the model to segment them and relearn the example rules for each segment to prevent model illusions. Finally, context checks are used to couple the content of multiple segments together.

[0060] In some embodiments, the training steps of the code-simplified model may further include: Perform anomaly detection on the model's output; If an anomaly is detected in the model's output, the model's output will be marked and backed up, and the corresponding original code data sample will be simplified again using the large language model.

[0061] To prevent model "hallucinations" during training (e.g., logical explanations and thought processes that sometimes occur during debugging), an anomaly detection process can be added after the model output. Anomaly detection primarily checks for unfounded additions, such as new variables or functions, or false annotations or explanations. If an anomaly is detected in the model output, a retry (corrected using prompts) and backup are necessary. On one hand, the retry mechanism provides an opportunity to correct initial model output anomalies (e.g., Chinese characters in the output's source file), guiding the model to optimize its generation logic by providing supplementary error messages, reducing invalid outputs caused by single "hallucinations." On the other hand, the backup mechanism preserves error cases, facilitating the tracing of model deviations (e.g., flawed prompts, insufficient training data), improving the efficiency of manual intervention, and providing data support for subsequent model iterations (e.g., supplementing targeted training samples, optimizing prompt rules), forming a closed loop of detection-correction-iteration, thus improving the accuracy and reliability of model simplification.

[0062] Furthermore, the above step of "performing anomaly detection on the model output" specifically includes: Check if the executable file in the output of the detection model contains Chinese characters; If the executable file contains Chinese characters, the model output result is considered abnormal.

[0063] The code simplification operation mainly simplifies the src file in the complete data package. Since the standard src file generally does not contain Chinese characters, Chinese character detection is performed on the final src file after the model outputs it. If Chinese characters are found, such as Chinese comments or Chinese logical explanations, the model output result is considered abnormal, and a retry (corrected and retried through prompt words) and backup are required.

[0064] In other embodiments, in addition to simplifying the original code data by training a large language model, the agent can also directly simplify the original code data according to preset redundancy rules, preset simplification templates and / or preset custom functions, which is not limited here.

[0065] The preset redundancy rules can be specifically set based on the abstract syntax tree structure and syntactic characteristics of the robot's native program code. The core of this approach is to limit the nodes / content in the abstract syntax tree that "have no impact on the core logic of the code and can be safely deleted / optimized." For example, this includes explicitly deleting empty comments without substantial information, debugging remnants of comments, merging duplicate variable declarations and constants, and eliminating meaningless redundant syntax modifiers and invalid conditional branches. During simplification, the abstract syntax tree of the original code data must first be parsed, then each node in the abstract syntax tree is traversed, and the target nodes are identified and processed according to the preset redundancy rules (such as deleting redundant comment nodes and merging duplicate variable declaration nodes). This simplification method does not require large model resources, thus accelerating code simplification and making it suitable for scenarios with high real-time requirements and large amounts of data.

[0066] The preset simplified template can be a standardized simplified template built for commonly used robot motion commands (such as point-to-point motion commands, linear motion commands, circular motion commands, etc.). The template defines the core elements to be extracted, including function block names (such as motion control function blocks, parameter configuration function blocks), code statement structure, key motion parameters (such as target coordinates, motion speed, acceleration threshold, etc.). By performing a structured comparison between the original code data and the template, the necessary information matching the template in the original code data is accurately extracted, and redundant information outside the template (such as non-standardized comments, redundant syntax modifiers, invalid auxiliary statements, etc.) is automatically removed. This template is continuously updated through manual configuration. It can be supplemented with template elements and adjusted comparison rules according to the command characteristics of robots from different manufacturers, the addition of new motion command types, or actual simplification needs, thereby improving the adaptability to native code data of various robots.

[0067] Preset custom functions are primarily used to accurately identify and extract custom function bodies (such as robot-specific business logic functions, hardware adaptation functions, etc.) and corresponding parameters (including parameter names and value ranges) from raw code data. These preset custom functions can be continuously updated through manual configuration, flexibly adjusted according to the syntax characteristics and function definition formats of custom functions for different manufacturers' robots. Furthermore, after multiple iterations, it can support cross-file correlation analysis, automatically matching and extracting parameters, parameter types, and parameter call relationships of the same custom function from multiple related files, ensuring the completeness and relevance of the extracted content.

[0068] S303. Based on preset rules and target knowledge base, generate functional module area and variable definition area corresponding to the original code data. The preset rules are used to limit the basic constraint standards of different variables and motion commands in the second protocol. The target knowledge base stores multiple variable definition cases adapted to the second protocol and functional module cases corresponding to different motion commands.

[0069] Step S303 is almost identical to step S202 above, and will not be repeated here. The only difference is that the original code data in step S303 is the original code data after model simplification, including partially simplified new files and partially unsimplified original files.

[0070] S304. Based on the functional module area and variable definition area, generate target code data corresponding to the original code data, which conforms to the second protocol.

[0071] Step S304 is the same as step S203 above, and will not be repeated here.

[0072] As described above, the code conversion method provided in this embodiment is applied to intelligent agents running in electronic devices. It first calls a trained code simplification model to simplify the original code data, and then converts the simplified original code data based on preset rules and a target knowledge base. This effectively reduces the difficulty of code conversion and the risk of semantic bias, ensuring the correctness and efficiency of the code conversion. Furthermore, during the training process of the code simplification model, Chinese character detection is introduced in the model's output results. If Chinese characters are found, a retry mechanism is triggered and a backup is marked. This effectively avoids model illusions during training, improving the accuracy and reliability of model simplification.

[0073] Based on the code conversion method described in the above embodiments, this embodiment also provides another code conversion method. Please refer to... Figure 4 , Figure 4 This is a flowchart illustrating another code conversion method provided in an embodiment of this application. This code conversion method is applied to an intelligent agent running in an electronic device and includes the following steps S401-S406, wherein: S401. Receive the user's raw input data and perform intent recognition on the raw input data to determine the user's intent.

[0074] S402. When the user intent indicates code conversion, determine the original code data to be converted from the original input data.

[0075] Among them, the intelligent agent can have built-in intent recognition function. Based on its own intent recognition function, it can determine whether the user wants to perform code conversion (conversion requirement) and the specific conversion range, ensuring that the conversion direction is correct from the source and reducing conversion errors caused by intent deviation. For example, for ambiguous intent, it can automatically trigger follow-up questions to clarify the user's intent. For code conversion requirements, it can then call a series of tools to perform code conversion.

[0076] The intent recognition function can be implemented based on rules and training with a small number of samples, or it can be implemented simply by configuring matching rules of "core keywords + related keywords". For example, core keywords include words that clearly indicate the conversion request, such as "code conversion", "protocol adaptation", and "code migration"; related keywords include robot program-related file format identifiers such as "src", "dat", "proto", and "prt", as well as words related to fields such as "robot code" and "motion instructions". When the original input data contains at least one core keyword and matches at least one related keyword, the user's intent can be determined to be code conversion; at the same time, robot program data packages containing the above file formats (including executable code files, data files, protocol adaptation files, etc.) are extracted from the original input data as the original code data to be converted.

[0077] In some embodiments, when deploying an agent to an electronic device, initialization settings for the agent are required. For example, when starting the electronic device or the agent, the system loads a preset agent configuration file. This configuration file contains the basic parameters required for the agent to run, and may also include parameters related to user intent recognition (such as intent recognition rules / templates), a tool list of callable tools (including tool call permissions, interface protocols, etc.), etc. For example, the tool list may include code simplification models, retrieval-augmented generation (RAG) tools, code reading and parsing tools, etc. Different tools in the tool list are configured with different functions. The purpose is to break down complex code conversion tasks, realize modular processing of the code conversion process, and allow for the direct addition or modification of corresponding tools if new requirements are added or a certain step is modified during the code conversion process. The modular tool setup facilitates subsequent updates and maintenance, and offers high flexibility. These tools can be deployed directly in the electronic device where the agent resides, or partially deployed in other devices that have established communication connections with the electronic device; there are no restrictions here.

[0078] Based on the configuration file and preset initialization prompts, the agent executes its own initialization process. These prompts guide the agent on how to parse the configuration file, which core parameters to extract, and what state to achieve after initialization, ensuring the agent completes initialization according to a unified standard and avoiding parameter omissions or parsing errors. After initialization, the agent enters a standby state, continuously listening to the input interface and waiting to receive user input (such as code conversion requests, file path specifications, etc.).

[0079] S403. Read and parse the executable program file and data file in the original code data.

[0080] The agent can invoke the `read_files` tool from the tool list to read all pairs of `src` and `dat` files in the subdirectories based on the file storage path. The read content is then loaded into memory and matched to ensure that they correspond to files related to the same set of code logic. It should be noted that if the original code data was simplified before code conversion, the `src` files will generally be simplified, so the read `src` files will be the simplified versions. However, the `dat` files generally do not require simplification, so the read `dat` files will be the original versions.

[0081] Please see Figure 5 , Figure 5 This is a schematic diagram of the overall process framework of the code conversion method provided in this application embodiment. After matching, the src and dat files are structured and parsed to obtain three core pieces of information: first, the overall logical structure of the code (such as motion control flow, conditional branching, loop execution logic, etc.), including switch structures, GOTO structures, loop structures, and conditional structures; second, all functions involved in this logical structure, including robot native functions, custom business functions, hardware adaptation functions, etc.; and third, the variables associated with each function (including variable names, data types, parameter values, and associated bound parameters), providing a structured basis for subsequent variable definition generation and function body conversion.

[0082] S404. Invoke the Retrieval Enhancement Generation (RAG) tool to retrieve variable definition cases and functional module cases related to the parsed content from the target knowledge base.

[0083] The RAG retrieval tool searches the target knowledge base for variable definition cases and functional module cases related to the parsed variables, functions, and logical structures, and assists in generating variable definition areas and functional module areas that meet the requirements.

[0084] S405. Based on the preset rules and the retrieved variable definition cases and functional module cases, generate the functional module area and variable definition area corresponding to the parsed content. The preset rules are used to limit the basic constraint standards of different variables and motion commands in the second protocol. The target knowledge base stores multiple variable definition cases adapted to the second protocol and functional module cases corresponding to different motion commands.

[0085] In this process, the system combines preset rules and cases provided by the target knowledge base, leveraging their complementary characteristics and strong correlation to jointly assist in the generation of the functional module area and variable definition area.

[0086] In some embodiments, step S405 specifically includes: Based on preset rules and variable definition examples, generate the variable definition area corresponding to the parsed content; Based on preset rules and the example of this functional module, generate the functional module area corresponding to the parsed content.

[0087] This system uses pre-defined rules as a rigid framework to define compliance boundaries, and knowledge base examples as flexible support to fill in scenario-based details. The intelligent agent invokes tools from the toolkit, such as `generate_variables` and `generate_body`, to generate the variable definition area and functional module area, respectively. For details, please refer to [link to documentation]. Figure 5 Based on the original semantic parsing results, the system can first generate a plan for input, output, and variable parameters based on rules or models. The `generate_variables` tool can treat the plan results as a blueprint and generate a variable definition area based on preset rules and variable definition cases, including input variables, output variables, constants / local variables, etc. The `generate_body` tool can translate the code blocks of the logical structure in the parsed content based on rules or models, and generate the execution code (such as computational logic and I / O operations) inside each function by combining preset rules and functional module cases to construct the function body. Then, the function body, the translated logical structure code blocks, and the adapted protocol are integrated to obtain the functional module area.

[0088] S406. Based on the functional module area and variable definition area, generate the target code data corresponding to the original code data. The target code data follows the second protocol.

[0089] The agent can use the `merge_program` tool to merge the functional module area and variable definition area, forming preliminary conversion code. The `merge_program` tool can then concatenate the code according to the protocol syntax, adding necessary parentheses, semicolons, and comments to ensure the merged code is compileable and runnable. Furthermore, the `merge_program` tool can further inspect the merged code (such as checking variable references) to identify unconverted code segments (e.g., parts that do not conform to the general open protocol specification), marking them with identifiers. Afterward, the agent can use the `save_file` tool to save the marked conversion code to a specified path, outputting the unconverted portions for manual verification.

[0090] As described above, the code conversion method provided in this embodiment is applied to an intelligent agent running in an electronic device. By receiving the user's original input data and performing intent recognition on the original input data, the conversion requirements and scope are determined, thereby ensuring that the code conversion direction is correct from the source, reducing conversion errors caused by intent deviation, and improving the accuracy of code conversion. Furthermore, when the user's intent is code conversion, various tools in the tool list are invoked to parse executable program files and data files, and variable definition cases and functional module cases related to the parsed content are retrieved from the target knowledge base. Code conversion is then performed according to preset rules and the retrieved variable definition cases and functional module cases, thus breaking down complex code conversion tasks and achieving modular processing of the code conversion process. If new requirements are added or a certain step is modified during the code conversion process, corresponding tools can be directly added or modified. The modular tool setup facilitates subsequent updates and maintenance, offering high flexibility.

[0091] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0092] Based on the method described in the above embodiments, this application also provides a code conversion apparatus for performing the steps in the above code conversion method. Please refer to... Figure 6 , Figure 6This is a schematic diagram of the code conversion device 500 provided in an embodiment of this application. The code conversion device 500 is applied to an intelligent agent running in an electronic device. Specifically, the code conversion device 500 includes an acquisition unit 501, a first generation unit 502, and a second generation unit 503, wherein: Acquisition unit 501 is used to acquire the raw code data to be converted, which conforms to the first protocol; The first generation unit 502 is used to generate the functional module area and variable definition area corresponding to the original code data based on preset rules and target knowledge base. The preset rules are used to limit the basic constraint standards of different variables and motion instructions in the second protocol. The target knowledge base stores multiple variable definition cases adapted to the second protocol and functional module cases corresponding to different motion instructions. The second generation unit 503 is used to generate target code data corresponding to the original code data based on the functional module area and the variable definition area, and the target code data follows the second protocol.

[0093] In some embodiments, the code conversion device 500 further includes a simplification module for: Before the first generation unit 502 generates the functional module area and variable definition area corresponding to the original code data based on preset rules and target knowledge base, it calls the trained code simplification model to simplify the original code data.

[0094] In some embodiments, the simplification module is specifically used for: Call the trained code simplification model and check whether the length of the original code data exceeds the model input length; When the length of the original code data exceeds the length of the model input, the original code data is split into multiple data segments. Each data shard is simplified to obtain multiple simplified data shards, and these multiple simplified data shards are merged through context checking.

[0095] In some embodiments, the training steps of the code-simplified model include: Obtain a set of converted code samples, each of which includes a sample of original code data and a sample of simplified code data. Based on the preset simplified prompts, the original code data sample is simplified using a large language model to obtain the model output. Based on the model's output and the corresponding simplified code data samples, the parameters of the large language model are adjusted to obtain a well-trained simplified code model.

[0096] In some embodiments, the training steps of the code-simplified model further include: Perform anomaly detection on the model's output; If the model output contains Chinese characters, the model output is marked and backed up, and the corresponding original code data sample is simplified again using the large language model.

[0097] In some embodiments, the acquisition unit 501 is further configured to: Before the first generation unit 502 generates the functional module area and variable definition area corresponding to the original code data based on preset rules and target knowledge base, the original code data is simplified according to preset redundancy rules, preset simplification templates and / or preset custom functions.

[0098] In some embodiments, the first generating unit 502 is specifically used for: Read and parse the executable program file and data file from the raw code data; The retrieval enhancement generation tool is invoked to retrieve variable definition cases and functional module cases related to the parsed content from the target knowledge base; Based on preset rules, as well as the retrieved variable definition cases and functional module cases, the corresponding functional module area and variable definition area are generated.

[0099] In some embodiments, the first generating unit 502 is specifically used for: Based on the preset rules and the variable definition case, the variable definition area corresponding to the parsed content is generated; Based on the preset rules and the functional module example, the functional module area corresponding to the parsed content is generated.

[0100] In some embodiments, the second generating unit 503 is specifically used for: Merge the variable definition area and the functional module area; Check if there is at least one unconverted code data segment in the merged code data; If it exists, a preset identifier is added to the corresponding code data segment for verification, and the verified code data is used as the target code data corresponding to the original code data. If it does not exist, the merged code data will be used as the target code data corresponding to the original code data.

[0101] In some embodiments, before acquiring the original code data to be converted, the acquisition unit 501 is further configured to: Receive raw input data from the user; Perform intent recognition on the raw input data to determine the user's intent; When the user intent indicates code conversion, the original code data to be converted is determined from the original input data.

[0102] Each module in the aforementioned code conversion device 500 can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0103] As described above, the code conversion device 500 provided in this embodiment is applied to an intelligent agent running in an electronic device. The acquisition unit 501 acquires the original code data to be converted, which follows a first protocol. The first generation unit 502 generates a functional module area and a variable definition area corresponding to the original code data based on preset rules and a target knowledge base. The preset rules are used to limit the basic constraint standards of different variables and motion instructions in the second protocol. The target knowledge base stores multiple variable definition cases adapted to the second protocol and functional module cases corresponding to different motion instructions. The second generation unit 503 generates target code data corresponding to the original code data based on the functional module area and the variable definition area. In other words, by deploying an intelligent agent, the preset rules serve as a rigid framework to define compliance boundaries, while the cases in the target knowledge base provide flexible support to fill in scenario-based details. The preset rules and the target knowledge base work together to assist the intelligent agent in completing the code conversion, thereby automatically converting the robot's native code into code that conforms to the general open protocol of the automation system. This eliminates the need for manual code conversion, resulting in high conversion efficiency and reducing the integration difficulty and cost of the automation system.

[0104] The code conversion method provided in this application can be implemented by an intelligent agent running in an electronic device, including but not limited to in-vehicle terminals, servers, personal computers, laptops, tablets, and smartphones. The operating system of the electronic device can include Android, Apple's iOS, Microsoft's Windows operating system, etc., and this disclosure does not limit this. The electronic device can operate independently to implement this disclosure, or it can connect to a network and implement this disclosure through interaction with other computer devices on the network. The network where the electronic device is located includes, but is not limited to, the Internet, wide area networks, metropolitan area networks, local area networks, and virtual private networks (VPNs).

[0105] This application also provides an electronic device; please refer to [link to relevant documentation]. Figure 7 , Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0106] For example, such as Figure 7 As shown, the electronic device 600 includes a memory 601 and a processor 602. The memory 601 stores executable program code 6011, and the processor 602 is used to call and execute the executable program code 6011 to perform a code conversion method.

[0107] The processor 602 is the control center of the electronic device 600. It connects various parts of the electronic device 600 through various interfaces and lines. By running or loading the application program stored in the memory 601 and calling the data stored in the memory 601, it performs various functions of the electronic device 600 and processes data, thereby monitoring the electronic device 600 as a whole.

[0108] Memory 601 can be used to store application programs and data. The application programs stored in memory 601 contain instructions that can be executed in processor 602. The application programs can be composed of various functional modules. Processor 602 executes various functional applications and data processing by running the application programs stored in memory 601.

[0109] In some embodiments, the electronic device 600 further includes: a radio frequency (RF) circuit, an input unit, an audio circuit, a sensor, and a power supply. The processor 602 is electrically connected to the RF circuit, the input unit, the audio circuit, the sensor, and the power supply. The RF circuit is used to transmit and receive RF 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. The input unit can be used to receive user-inputted numerical and character information, and to generate inputs related to user settings and function control. The audio circuit can provide an audio interface between the user and the electronic device 600 through a speaker or microphone. The power supply is used to power the various components of the electronic device 600. In some embodiments, the power supply can be logically connected to the processor 602 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system.

[0110] Furthermore, embodiments of this application also protect an apparatus that may include a memory and a processor, wherein the memory stores executable program code, and the processor is used to call and execute the executable program code to perform a code conversion method.

[0111] This embodiment can divide the device into functional modules based on the above method example. For example, each module can correspond to a separate function, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0112] It should be noted that all relevant content of each step involved in the above method embodiments can be referenced from the functional description of the corresponding functional module, and will not be repeated here.

[0113] It should be understood that the apparatus provided in this embodiment is used to execute the above-described code conversion method, and therefore can achieve the same effect as the above-described implementation method.

[0114] When using integrated units, the device may include a processing module and a storage module. When applied to an electronic device, the processing module can be used to control and manage the operation of the electronic device. The storage module can be used to support the execution of relevant program code by the electronic device.

[0115] The processing module may be a processor or a controller, which can implement or execute various exemplary logic blocks, modules, and circuits shown in conjunction with the disclosure of this application. The processor may also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc., and the storage module may be a memory.

[0116] In addition, the apparatus provided in the embodiments of this application may specifically be a chip, component or module. The chip may include a connected processor and a memory. The memory is used to store instructions. When the processor calls and executes the instructions, the chip can execute a code conversion method provided in the above embodiments.

[0117] This embodiment also provides a computer-readable storage medium storing computer program code. When the computer program code is run on a computer, the computer executes the aforementioned method steps to implement the code conversion method provided in the above embodiment.

[0118] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement the code conversion method provided in the above embodiment.

[0119] In this embodiment, the device, computer-readable storage medium, computer program product, or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0120] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0121] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0122] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A transcoding method, characterized by, The method applied to an agent running in an electronic device, the method comprises: obtaining original code data to be converted, the original code data complying with a first protocol; generating a function module area and a variable definition area corresponding to the original code data based on a preset rule and a target knowledge base, the preset rule being used to limit the basic constraint standard of different variables and motion instructions in a second protocol, the target knowledge base storing a plurality of variable definition cases and function module cases corresponding to different motion instructions adapted to the second protocol; generating target code data corresponding to the original code data according to the function module area and the variable definition area, the target code data complying with the second protocol.

2. The method of claim 1, wherein, Before generating the function module area and the variable definition area corresponding to the original code data based on the preset rule and the target knowledge base, the method further comprises: calling a trained code simplification model to simplify the original code data.

3. The method of claim 2, wherein, The calling of the trained code simplification model to simplify the original code data comprises: calling the trained code simplification model to check whether the length of the original code data exceeds the model input length; when the length of the original code data exceeds the model input length, fragmenting the original code data to obtain a plurality of fragmented data; simplifying each of the fragmented data to obtain a plurality of simplified fragmented data, and merging the plurality of simplified fragmented data through context checking.

4. The method of claim 2, wherein, The training step of the code simplification model comprises: obtaining a conversion code sample set, each conversion code sample in the conversion code sample set comprising an original code data sample and a simplified code data sample; simplifying the original code data sample by using a large language model according to a preset simplification prompt word to obtain a model output result; adjusting parameters of the large language model according to the model output result and the corresponding simplified code data sample to obtain a trained code simplification model.

5. The method of claim 4, wherein, The training step of the code simplification model further comprises: detecting the model output result for abnormalities; if the model output result is detected to be abnormal, marking and backing up the model output result, and re-simplifying the corresponding original code data sample by using the large language model.

6. The method of claim 5, wherein, The detection of the model output result for abnormalities comprises: detecting whether Chinese appears in the executable program file in the model output result; if Chinese appears in the executable program file, it is determined that the model output result is abnormal.

7. The method of claim 1, wherein, Before generating the function module area and the variable definition area corresponding to the original code data based on the preset rule and the target knowledge base, the method further comprises: simplifying the original code data according to a preset redundancy rule, a preset simplification template and / or a preset custom function.

8. The method according to any one of claims 1 to 7, characterized in that, The generation of the function module area and the variable definition area corresponding to the original code data based on the preset rule and the target knowledge base comprises: reading and parsing the executable program file and the data file in the original code data; Call a retrieval enhancement generation tool to retrieve a variable definition case and a function module case related to the parsed content from a target knowledge base; Generate a function module area and a variable definition area corresponding to the parsed content according to a preset rule and the retrieved variable definition case and function module case.

9. The method of claim 8, wherein, The generating of the function module area and the variable definition area corresponding to the parsed content according to the preset rule and the retrieved variable definition case and function module case comprises: Generating the variable definition area corresponding to the parsed content according to the preset rule and the variable definition case; Generating the function module area corresponding to the parsed content according to the preset rule and the function module case.

10. The method according to any one of claims 1-7, characterized in that, The generating of the target code data corresponding to the original code data according to the function module area and the variable definition area comprises: Merging the variable definition area and the function module area; Checking whether there is at least one code data segment that fails to be converted in the merged code data; If there is, adding a preset identifier at the corresponding code data segment for checking, and taking the checked code data as the target code data corresponding to the original code data; If there is not, taking the merged code data as the target code data corresponding to the original code data.

11. The method according to any one of claims 1-7, characterized in that, Before the obtaining of the original code data to be converted, the method further comprises: Receiving original input data of a user; Performing intent recognition on the original input data to determine a user intent; When the user intent indicates code conversion, determining the original code data to be converted from the original input data.

12. A transcoding device, characterized by An application for an intelligent agent running in an electronic device, the apparatus comprising: An obtaining unit configured to obtain original code data to be converted, the original code data complying with a first protocol; A first generating unit configured to generate a function module area and a variable definition area corresponding to the original code data based on a preset rule and a target knowledge base, the preset rule being used to define basic constraint standards of different variables and motion instructions in a second protocol, and the target knowledge base storing a plurality of variable definition cases and function module cases corresponding to different motion instructions adapted to the second protocol; A second generating unit configured to generate target code data corresponding to the original code data according to the function module area and the variable definition area, the target code data complying with the second protocol.

13. An electronic device, comprising: The electronic device comprises: A memory configured to store executable program code; A processor configured to call and run the executable program code from the memory, so that the electronic device performs the code conversion method according to any one of claims 1 to 11.

14. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, when the computer program is executed, the code conversion method according to any one of claims 1 to 11 is realized.

15. A computer program product, characterised in that, The computer program product comprises computer program code, when the computer program code is run on a computer, the computer executes the code conversion method according to any one of claims 1 to 11.

Citation Information

Cited By

  • Code completion model training method and device based on semantic attribution

    CN121979506A