Code conversion method and device, storage medium and program product

By obtaining initial code and knowledge information and calling the code conversion model, the code conversion from one programming language to another is realized, solving the high cost of manually developing codes of different operating systems or device types, and reducing the cost and manual dependence of code conversion.

CN119902775APending Publication Date: 2025-04-29TAOBAO CHINA SOFTWARE
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411908783.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

In software development, it is costly to manually develop the same function for different operating systems or device types, and it is difficult for the existing technology to effectively solve this problem.

Method used

A code conversion method is provided, by obtaining initial code written in the first programming language, obtaining knowledge information in the target knowledge base, including functional attribute information and programming knowledge information, and calling the code conversion model for conversion, to generate object code written in the second programming language.

Benefits of technology

It greatly reduces the dependence of code conversion operations on manual, reduces the cost of code conversion operations, and can handle conversions between general and specialized programming languages.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902775A_ABST
    Figure CN119902775A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code conversion method and device, a storage medium and a program product. In the code conversion method, a code acquisition operation can be responded, an initial code of a target function object written in a first programming language is acquired, and knowledge information required for converting the initial code into a target code written in a second programming language is acquired in a target knowledge base. And calling a code conversion model, and converting the initial code according to the knowledge information to obtain a target code. Wherein the knowledge information at least comprises functional attribute information and / or programming knowledge information of the target functional object, so that the code conversion model can learn or supplement specific domain knowledge required for converting an initial code written in a first programming language into a target code written in a second programming language, and the target code written in the second programming language can be converted by utilizing the specific domain knowledge. The initial code is converted into the target code meeting the requirement, so that the dependence of the code conversion operation on manpower is greatly reduced, and the cost of the code conversion operation is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a code conversion method, device, storage medium and program product. Background Art

[0002] In software development scenarios, the appropriate programming language is usually selected based on the operating system or device type supported by the software. For example, when developing a shopping application, in order to meet the needs of consumers using different terminals for online consumption, a variety of different coding languages ​​can be used to achieve unified functions. For example, when developing online shopping applications corresponding to different operating systems, for the same function, it is necessary to develop functional modules adapted to different operating systems. For example, for the same function, it is necessary to develop a web application or a mini-program application to meet the usage requirements of different scenarios. For another example, when displaying the same function on different pages of an application, different programming languages ​​are needed to write the corresponding functional modules.

[0003] In some conventional technical means, manual development is usually adopted, and different programming languages ​​are used to develop the same function, which consumes high manpower costs. Therefore, a new solution is yet to be proposed. Summary of the invention

[0004] Multiple aspects of the present application provide a code conversion method, device, storage medium and program product to improve the cost of code conversion.

[0005] An embodiment of the present application provides a code conversion method, including: in response to a code acquisition operation, obtaining an initial code of a target functional object written in a first programming language; obtaining knowledge information required to convert the initial code into a target code written in a second programming language in a target knowledge base, the knowledge information at least including functional attribute information and / or programming knowledge information of the target functional object; calling a code conversion model, converting the initial code according to the knowledge information to obtain the target code, the first programming language and the second programming language are different.

[0006] An embodiment of the present application also provides an electronic device, comprising: a memory and a processor; the memory is used to store one or more computer instructions; the processor is used to execute the one or more computer instructions to: execute the steps in the method provided in the embodiment of the present application.

[0007] The embodiment of the present application also provides a computer-readable storage medium storing a computer program, which can implement the steps in the method provided in the embodiment of the present application when the computer program is executed by a processor.

[0008] The embodiment of the present application also provides a computer program product, including: a computer program / instructions, which, when executed by a processor, can implement the steps in the method provided in the embodiment of the present application.

[0009] In an embodiment of the present application, the code acquisition operation can be responded to, the initial code of the target functional object written in the first programming language can be acquired, and the knowledge information required to convert the initial code into the target code written in the second programming language can be acquired in the target knowledge base. The code conversion model is called to convert the initial code according to the knowledge information to obtain the target code. Among them, the knowledge information at least includes the functional attribute information and / or programming knowledge information of the target functional object, and then the code conversion model can learn or supplement the specific domain knowledge required to convert the initial code written in the first programming language into the target code written in the second programming language with the assistance of the knowledge information, and use the learned or supplemented specific domain knowledge to convert the initial code into the target code that meets the requirements, which greatly reduces the dependence of the code conversion operation on manual work and reduces the cost of the code conversion operation. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0011] Figure 1 A flowchart of a code conversion method provided by an exemplary embodiment of the present application;

[0012] Figure 2 A flowchart of a code conversion method provided by another exemplary embodiment of the present application;

[0013] Figure 3 A schematic diagram of an editing page of a converted target code provided by an exemplary embodiment of the present application;

[0014] Figure 4 A schematic diagram of a function migration scenario provided for an exemplary embodiment of the present application;

[0015] Figure 5 A schematic diagram of a code conversion method provided by another exemplary embodiment of the present application;

[0016] Figure 6 A schematic diagram of the structure of an electronic device provided as an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0017] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.

[0018] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings, and "multiple" generally includes at least two, but does not exclude the inclusion of at least one.

[0019] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0020] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a product or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such a product or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the product or system including the element.

[0021] When developing an application, in order to run the application on different operating systems or different terminals, it is necessary to use a variety of different coding languages ​​to achieve unified functions. For example, when developing online shopping applications corresponding to different operating systems, for the same function, it is necessary to develop functional modules adapted to different operating systems. For example, when the same function is displayed on different pages of an application, different programming languages ​​are required to write the functional pages. Taking a shopping application as an example, a shopping application can display information flow cards, which are used to display recommended products, advertising cards, etc. Information flow cards can be displayed on the homepage of the shopping application, or on the payment success page after placing an order. When developing a shopping application, a certain programming language can be used to develop information flow cards for displaying on the homepage, and another programming language can be used to develop information flow cards for displaying on the payment success page.

[0022] In some development schemes, in order to improve the efficiency of developing the same functional module using different programming languages, a code conversion scheme based on artificial intelligence (AI) can be adopted. In this scheme, developers can use AI models to convert functional modules developed in a certain programming language into functional modules developed in another specified programming language by constructing prompt words. At present, this development scheme is suitable for the conversion of general programming languages, but not for the conversion of some special programming languages ​​or programming languages ​​for specific purposes. In addition, this development scheme does not take into account the application attributes of the functional module, resulting in the functional module obtained after the conversion of the programming language not being consistent with the pre-designed function.

[0023] In view of the above technical problems, a solution is provided in some embodiments of the present application. The technical solutions provided by the embodiments of the present application are described in detail below in conjunction with the accompanying drawings.

[0024] Figure 1 is a flow chart of a code conversion method provided by an exemplary embodiment of the present application, which may include: Figure 1 Steps shown:

[0025] Step 101: In response to a code acquisition operation, an initial code of a target functional object written in a first programming language is acquired.

[0026] Step 102: In a target knowledge base, obtain knowledge information required to convert the initial code into a target code written in a second programming language, wherein the knowledge information at least includes function attribute information and / or programming knowledge information of the target function object.

[0027] Step 103: Call a code conversion model to convert the initial code according to the knowledge information to obtain the target code, wherein the first programming language is different from the second programming language.

[0028] This embodiment can be executed by an electronic device, and a tool for executing the code conversion method can be run on the electronic device, hereinafter referred to as a code conversion tool. The code conversion tool can be a client program, a web page program or a back-end service program, which can be determined by the implementation form of the electronic device. For example, in some embodiments, the electronic device is implemented as a terminal device such as a desktop computer, a laptop computer or a smart phone, and the code conversion tool can be implemented as a client program running on the above terminal device. In other embodiments, the electronic device is implemented as a server device such as a conventional server, a cloud server or a server array, and the code conversion tool can be implemented as a back-end service program running on the server device. In some optional embodiments, the code conversion tool can be implemented as a web page program in which the front-end component runs in a browser on the terminal device and the back-end component runs on the server, and this embodiment does not limit this. In this embodiment, the code conversion tool is used to convert the programming language used in the code of the target functional object, and the following will be specifically illustrated in combination with the above steps.

[0029] In step 101, the code acquisition operation is used to trigger the code conversion tool to acquire the initial code of the target functional object. Optionally, under the triggering of the code operation, the code conversion tool can acquire the initial code uploaded by the user, or acquire the initial code from a specified path, or acquire the initial code from a specified code library, which is not limited in this embodiment.

[0030] Optionally, the code acquisition operation may be initiated by the user, or may be initiated by a system event, which will be described below in conjunction with different embodiments. In some optional embodiments, the electronic device is implemented as a terminal device, and the terminal device may display a page of a client program corresponding to the code conversion tool, or the terminal device may display a page of a front-end component corresponding to the code conversion tool through a browser. The terminal device may detect the code acquisition operation by detecting the user's operation on the above page. Optionally, the terminal device may display a control for acquiring the code in the above page, such as a code upload control, and may determine that a code acquisition operation has been detected when a user triggers the control. Optionally, the terminal device may detect the user's voice command through an audio component thereon, and determine that a code acquisition operation has been detected when the content of the voice command is recognized for acquiring the code.

[0031] In other optional embodiments, when the electronic device is implemented as a server device, a backend service corresponding to the code conversion tool or a backend component corresponding to the code conversion tool is run on the server device. Optionally, the server device may receive a request sent based on a communication protocol, and may determine that a code acquisition operation has been detected when it is determined that the content of the request contains parameters, code storage addresses or methods associated with the code acquisition operation. Optionally, the server device may receive a call request for a specified API (Application Programming Interface), and determine that a code acquisition operation has been detected when the parameters, code storage addresses or methods associated with the code acquisition operation are parsed from the call request. Optionally, the server device may monitor a specified event, which may be an event for triggering a code acquisition operation, such as a timed event, a function migration event or other event. The server device may determine that a code acquisition operation has been detected when the above-mentioned specified event is triggered.

[0032] The code conversion tool can respond to the code acquisition operation to obtain the initial code of the target functional object written in the first programming language. In this embodiment, the target functional object can be an application that can run independently, such as a client program, a small program, a web program, or a functional module or component within the application, such as a user interface component or a small-grained functional unit, which is not limited in this embodiment. The first programming language can be any general programming language, or it can be a special programming language used internally by certain enterprise users, which is not limited in this embodiment. The initial code refers to the code obtained by writing the target functional object in the first programming language before conversion.

[0033] In this embodiment, the code conversion tool can use the Retrieval-Augmented Generation (RAG) method to provide context information for the conversion process of the initial code. After obtaining the initial code, in step 102, the code conversion tool obtains the knowledge information required to convert the initial code of the target functional object into a target code written in a second programming language in the target knowledge base. In this embodiment, the second programming language is different from the first programming language. The second programming language can be any general programming language, or it can be a special programming language used internally by some enterprise users, which is not limited in this embodiment. In this embodiment, the use of "first" and "second" to limit the programming language is only used to distinguish similar description objects, and does not constitute other restrictions on the described programming language.

[0034] In this embodiment, the target knowledge base may be one knowledge base or multiple knowledge bases, for example, the target knowledge base may include at least one of a general knowledge base, a special domain knowledge base corresponding to the target functional object, a special domain knowledge base corresponding to the first programming language, and a special domain knowledge base corresponding to the second programming language, and this embodiment does not limit this. In this embodiment, the knowledge information obtained from the target knowledge base is used to guide the conversion operation of the initial code, so that the converted target code meets the coding specification of the second programming language, and enables the target code to achieve the functional requirements of the target functional object.

[0035] In this embodiment, the knowledge information at least includes the functional attribute information and / or programming knowledge information of the target functional object. The functional attribute information of the target functional object is used to describe the behavior and characteristics of the target functional object, including but not limited to at least one of the main purpose of the target functional object, the interface layout style, the interface interaction logic, the interaction logic with other modules, and the background processing logic. The programming knowledge information of the target functional object is used to describe the relevant knowledge information of the programming language used to encode the target functional object, which may include but not limited to the knowledge information related to at least one of the syntax, library, tool, framework, code specification and security technology of the programming language.

[0036] After the knowledge information required for code conversion is obtained, in step 103, the code conversion model can be called to convert the initial code according to the knowledge information to obtain the target code.

[0037] Among them, the code conversion model can be a neural network model trained on a code data set and capable of performing code conversion operations. In some optional embodiments, the code conversion model can be a large language model, which is a natural language processing (NLP) model that has been trained on a large scale. Large language models are usually built based on deep learning technology and trained on large-scale training data sets, so that they can show strong performance when processing natural language tasks. Given a piece of text (i.e., context), the large language model will try to predict the words that are most likely to appear next. The number of parameters of the large language model is greater than the set threshold, which is usually on the order of millions or billions. During the training process, these parameters are continuously adjusted and optimized according to the difference between the predicted results of the large language model and the actual results to improve the prediction accuracy of the large language model. In some embodiments, the large language model usually uses an advanced neural network architecture, such as a Transformer architecture, to build a model structure, which enables the large language model to capture complex patterns in the text and handle long-distance dependencies. After sufficient training, the large language model has a strong generation capability and can produce coherent and contextual text content based on given prompts.

[0038] In this embodiment, a large language model pre-trained on a large number of general data sets can be used as the base model of the code conversion model. In order to adapt to the specific application scenario of the present application, that is, for code conversion, the pre-trained large language model can be fine-tuned on a data set formed by code data written in a large number of different programming languages, so that the fine-tuned large language model is more suitable for performing code conversion tasks.

[0039] In this embodiment, the code conversion tool can respond to the code acquisition operation, obtain the initial code of the target functional object written in the first programming language, and obtain the knowledge information required to convert the initial code into the target code written in the second programming language in the target knowledge base. The code conversion tool can call the code conversion model to convert the initial code according to the knowledge information to obtain the target code. Among them, the knowledge information at least includes the functional attribute information and / or programming knowledge information of the target functional object, and then the code conversion model can learn or supplement the specific domain knowledge required to convert the initial code written in the first programming language into the target code written in the second programming language with the assistance of the knowledge information, and use the learned or supplemented specific domain knowledge to convert the initial code into the target code that meets the requirements, which greatly reduces the dependence of the code conversion operation on manual work and reduces the cost of the code conversion operation.

[0040] In addition, even if the first programming language or the second programming language is a non-universal programming language, the code conversion model can learn the conversion method between special-purpose programming languages ​​and the conversion between special-purpose programming languages ​​and general programming languages ​​from knowledge information based on its powerful learning ability, thereby realizing the conversion between special-purpose programming languages, or the conversion between special-purpose programming languages ​​and general programming languages.

[0041] In some optional embodiments, the target knowledge base may be composed of relevant knowledge documents of the target functional object, and the code conversion tool may obtain the knowledge information required for code conversion of the target functional object by searching the documents in the target knowledge base.

[0042] Optionally, the target knowledge base includes documents related to the functional attributes of different functional objects. When the code conversion tool obtains the knowledge information required to convert the initial code into the target code written in the second programming language in the target knowledge base, it can search the target knowledge base according to the identification information of the target functional object to obtain the functional attribute document corresponding to the target functional object. Among them, the functional attribute document may include: the design document and / or product document of the target functional object, and the design document and / or product document may be generated during the requirements analysis and design process of the target functional object. The code conversion tool can obtain the functional attribute information of the target functional object as the knowledge information based on the functional attribute document. Optionally, the code conversion tool can identify text fragments and / or pictures related to the target functional object from the functional attribute document, and vectorize the identified text and / or pictures so that the code conversion model can directly process the knowledge information input in the form of vectors after conversion.

[0043] Based on this implementation, knowledge information is obtained from the design documents and / or product documents of the target functional object, and knowledge information related to the functional design of the target functional object can be provided to the code conversion model. Such knowledge information can help the code conversion model understand the functions of the target functional object and related processing logic, thereby facilitating the generation of code that meets the requirements during the code conversion process, so that when the converted target code is run, it can achieve functions that are consistent with the design expectations.

[0044] Optionally, the target knowledge base includes documents related to programming knowledge of different programming languages. Documents related to programming knowledge of any programming language may include, but are not limited to: user manuals provided by developers of the programming language, experience documents written by technicians who use the programming language for software development, knowledge documents / posts related to the programming language obtained from relevant technical communities / forums, etc. In some optional embodiments, in the target knowledge base, the knowledge information required to convert the initial code into a target code written in a second programming language is obtained, including: searching the target knowledge base according to the first programming language and / or the second programming language to obtain the knowledge documents corresponding to the first programming language and / or the second programming language. According to the knowledge documents corresponding to the first programming language and / or the second programming language, programming knowledge information is obtained as knowledge information. Optionally, the code conversion tool can vectorize the knowledge documents corresponding to the first programming language and / or the second programming language obtained, so that the code conversion model can directly process the programming knowledge information input in the form of vectors after conversion.

[0045] Based on this implementation, knowledge information is obtained from knowledge documents corresponding to the first programming language and / or the second programming language, and knowledge information related to at least one of the syntax, libraries, tools, frameworks, code specifications and security technologies related to the first programming language and / or the second programming language can be provided to the code conversion model, thereby facilitating the code conversion model to determine a relatively complete conversion rule between the first programming language and the second programming language based on the above knowledge information and pre-learned code conversion knowledge, so that the converted target code conforms to the programming specifications of the second programming language.

[0046] In some optional embodiments, when the code conversion model is implemented as a large language model, when the code conversion tool calls the code conversion model and converts the initial code according to the knowledge information, it can respond to the code conversion operation, generate conversion prompt words according to the initial code and the conversion rules from the first programming language to the second programming language, and call the code conversion model according to the conversion prompt words and the knowledge information, so that the code conversion model converts the initial code according to the knowledge information under the prompt of the conversion prompt words.

[0047] In this embodiment, the code conversion operation may be initiated by the user or by a system event. In some optional embodiments, when the electronic device is implemented as a terminal device, the terminal device may display the page of the client program corresponding to the code conversion tool, or display the page of the front-end component corresponding to the code conversion tool through a browser. The terminal device may detect the code acquisition operation by detecting the user's operation on the above page. Optionally, the terminal device may display a control for initiating the code conversion operation in the above page, and determine that the code conversion operation is detected when the user's trigger operation on the control is detected. Optionally, the terminal device may detect the user's voice instruction through the audio component thereon, and determine that the code conversion operation is detected when the content of the voice instruction is recognized for code conversion. In other optional embodiments, when the electronic device is implemented as a server device, the server device runs a back-end service corresponding to the code conversion tool or a back-end component corresponding to the code conversion tool, and the server device may determine that the code conversion operation is detected when a call request to a specified API is detected or a specified event is monitored, which will not be repeated.

[0048] Optionally, when generating the conversion prompt word, the code conversion tool may fill the initial code and the conversion rule from the first programming language to the second programming language into a preset structured prompt word template to obtain a structured conversion prompt word, such as Figure 2For example, the conversion prompt word can be: {Task: Code conversion task; User input: {Question text: Please convert the following initial code into a target code written in the second programming language; Initial code: xxxx; Original programming language: First programming language; Target programming language: Second programming language; Conversion rule from the original programming language to the target programming language: xxxxxx}}.

[0049] The code conversion tool can call the code conversion model according to the conversion prompt word and the knowledge information, so that the code conversion model converts the initial code according to the knowledge information under the prompt of the conversion prompt word. Figure 2 As shown, the code conversion tool can input conversion prompts and knowledge information into the code conversion model. The knowledge information can be provided to the code conversion model as additional context information. In the code conversion model, the conversion prompts can be parsed to identify the conversion task of converting the initial code into the target code written in the second programming language. In the process of performing the conversion task, the code conversion model can identify the conversion rules from the first programming language corresponding to the initial code to the second programming language from the conversion prompts. The code conversion model can encode the conversion rules and knowledge information to obtain a context encoding vector, and according to the context encoding vector and the pre-learned code conversion knowledge, the initial code is converted section by section to obtain the target code.

[0050] In this embodiment, the code conversion model not only considers the content in the conversion prompt words, but also combines the information in the knowledge document, which enhances the understanding of the code conversion task and supplements the knowledge required for code conversion, so that the code conversion model can generate more accurate code conversion results.

[0051] In some optional embodiments, after calling the code conversion model and converting the initial code according to the knowledge information to obtain the target code written in the second programming language, the code conversion tool can call the code conversion model to modify the target code until the modified target code meets the preset requirements. Optionally, when the target function object is a front-end component of a webpage program or a client program, the code conversion tool can obtain the design page of the target function object and the preview page corresponding to the target code. Among them, the design page of the target function object can be obtained from the function attribute information of the target function object. For example, when the function attribute information includes the design document or product document of the target function object, the code conversion tool can obtain the design page of the target function object from the design document or product document. The code conversion tool can provide an editor, which can run the target code and output the preview page corresponding to the target code. The code conversion tool can generate a modification prompt word according to the target code, the preview page and the design page, and call the code conversion model according to the modification prompt word, so that the code conversion model obtains the difference between the preview page and the design page, and when the difference is greater than a set threshold, the target code is modified according to the difference. In some optional embodiments, the code conversion model can save the knowledge information input in the initial code conversion process. In the process of modifying the target code, the code conversion model can continue to extract the knowledge required to modify the target code from the saved knowledge information, and modify the target code based on the extracted knowledge and the difference between the preview page and the design page. The above operation can be repeated until the difference between the preview page corresponding to the modified target code and the design page of the target functional object is less than or equal to the set threshold.

[0052] In this implementation, the code conversion tool can modify and improve the converted target code using the code conversion model, thereby further improving the degree of correspondence between the converted target code and actual design requirements.

[0053] In some optional embodiments, when the target functional object is a front-end component of a web page program or a client program, the code conversion tool can output a preview of the code conversion result after obtaining the target code written in the second programming language, and can provide an operation entry for manually modifying the code conversion result to facilitate manual debugging. Optionally, the code conversion tool can display a preview page corresponding to the target code and the target code, and can respond to an editing operation on the target code and display a preview page corresponding to the edited target code. Figure 3 As shown, the code conversion tool can display an editing page, which includes an editing window and a preview window displayed on the same screen, the editing window is used to display the target code, and the preview window is used to display the preview page corresponding to the target code. The code conversion tool can detect the editing operation of the user (such as the developer) on the target code in the editing window, and synchronously display the preview effect after editing in the preview window.

[0054] Based on this implementation, a combination of automatic code conversion based on a code conversion model and manual debugging is achieved, making the code conversion process more flexible and further ensuring that the converted target code has high accuracy and meets expectations.

[0055] It should be noted that, in some optional embodiments, the code conversion tool can also use one or more agents to automatically perform multiple operations on the converted target code to further save labor costs. Among them, the agent refers to a software entity that can perceive information through an interface in a specific environment and make action decisions based on the perceived information to achieve a predetermined goal. Some AI agents can perform knowledge reasoning, decision making, and response generation based on large language models. An exemplary description will be given below.

[0056] In some optional embodiments, after the code conversion tool calls the code conversion model and converts the initial code according to the knowledge information to obtain the target code written in the second programming language, it can display at least one control, and the at least one control can be displayed on Figure 3 The page shown or other pages of the code conversion tool. Wherein, any control corresponds to an agent with a specified function, and the code conversion tool can detect the calling operation of the agent by detecting the triggering operation of any control. Optionally, if multiple controls are displayed, the multiple controls can correspond to the same agent or different agents. If multiple controls correspond to the same agent, the agent can be used to perform the information perception operations and corresponding action decision operations corresponding to the multiple controls.

[0057] Optionally, the code conversion tool can respond to the selection operation of the deployment control in at least one control, call the intelligent agent corresponding to the deployment control, obtain the deployment rules of the target function object, and deploy the target function object in the specified online running environment according to the target code and the deployment rules. Among them, the deployment rules of the target function object can include grayscale rules, rollback rules in case of failure, etc. Based on this implementation method, after the target code is converted, the automatic deployment of the target code is realized, which further reduces manual participation and reduces the cost of code deployment.

[0058] In some optional embodiments, before calling the agent corresponding to the deployment control to deploy the target function object according to the target code, the code conversion tool may call an agent with a code verification function to verify the target code. Optionally, the code conversion tool may respond to the selection operation of the verification control in at least one control, call the agent corresponding to the verification control, and perform a predefined verification operation on the target code, so that after the target code passes the verification operation, the target function object is deployed in a specified online operating environment according to the target code and the deployment rules. Optionally, the predefined verification operation may include: comparing the preview page corresponding to the target code with the design page of the target function object. When the difference between the preview page and the design page of the target function object is less than a set threshold, it is determined that the target code has passed the functional verification. Optionally, the predefined verification operation may include: calling a target model, such as a code conversion model, to review the readability, maintainability and consistency of the target code to review the target code. Optionally, if the target code passes the functional verification or the target model returns the result that the target code has passed the review, the agent corresponding to the verification control can send a notification message to a designated user (e.g., a tester or developer) through the API provided by the social platform, so that the designated user can perform manual testing or manual review on the target code. In some embodiments, if the target code passes the functional verification and the target model returns the result that the target code has passed the review, the agent corresponding to the verification control can directly call the API of the agent corresponding to the deployment control, so that the agent corresponding to the deployment control can automatically deploy the target code.

[0059] In this implementation, the converted target code is automatically tested through the intelligent agent, which reduces the cost required for testing and greatly improves the testing efficiency.

[0060] In some optional embodiments, after calling the agent corresponding to the deployment control to deploy the target function object according to the target code, the code conversion tool may call the agent with online monitoring function to continuously monitor the online running status of the target code. Optionally, the code conversion tool responds to the selection operation of the monitoring control in at least one control, calls the agent corresponding to the monitoring control, and obtains feedback information after the target function object is launched from the online running environment and / or the specified social platform. For example, the running log of the target function object can be monitored in the online running environment, and the topic data such as posts, discussions, and articles related to the target function object can be searched in social media, forums, or communities. According to the obtained feedback information, the running problem of the target function object can be identified. For example, information related to abnormal events can be obtained from the running log of the target function object, or the searched topic data can be clustered to identify keywords related to the running problem. When the running problem meets the set conditions, a predefined early warning operation can be executed. The running problem meeting the set conditions may include: the abnormal level of the abnormal event is greater than the set level threshold, the number of error reports of the abnormal event is greater than the set number threshold, and the discussion heat of the keywords related to the running problem is greater than the set heat threshold, etc. Optionally, when executing a predefined warning operation, the intelligent agent corresponding to the monitoring control can send a warning message to a designated user (such as a developer or operation and maintenance personnel) through the API provided by the social platform, so that the designated user can perform troubleshooting and problem repair operations on the target code.

[0061] Based on this implementation method, after the converted target code is put into operation, the intelligent agent can continuously monitor the operation status of the target code, thereby facilitating timely patching and improvement of the target code and reducing the risk of major operation problems in the target code.

[0062] The code conversion method provided in the embodiment of the present application can be applied to the function migration scenario in the software development process. The function migration refers to migrating any function module in the software system from its original location to another location in the software system for use. For example, taking a shopping application as an example, Figure 4 As shown, the shopping application can display information flow cards, which are used to display recommended products, advertising cards, etc. After the information flow card is displayed on the homepage of the shopping application, if the display effect of the information flow card is good, the information flow card is migrated to other pages of the shopping application, such as Figure 4 If the homepage of the shopping application is written in a first programming language and the other pages are written in a second programming language, the code conversion method of the embodiment of the present application can be used to convert the initial code written in the first programming language corresponding to the information flow card into the target code written in the second programming language.

[0063] like Figure 5 As shown, the code conversion method mainly includes the following steps:

[0064] S1. Obtain an initial code of an information flow card, where the initial code is written in a first programming language.

[0065] S2, construct prompt words and perform knowledge retrieval. When constructing prompt words, write conversion prompt words according to the conversion rules for converting the first programming language into the second programming language. The conversion prompt words include various rules such as layout, style, and adaptation of different devices. Among them, the conversion rules can be mainly determined based on the development experience of converting the first programming language into the second programming language. The written prompt words will be input into the code conversion model in the form of text in the subsequent steps. When performing knowledge retrieval, the knowledge documents related to the first programming language and the second programming language and the corresponding product documents, design documents and other knowledge information of the information flow cards can be retrieved in the knowledge base. The retrieved knowledge information can be provided to the code conversion model as context information to supplement the conversion rules in the conversion prompt words.

[0066] S3, the initial code of the information flow card, the conversion prompt word and the retrieved knowledge information are converted by calling the API of the code conversion model. The code conversion model can convert the initial code into the target code according to the conversion rules and knowledge information in the prompt word. After obtaining the converted target code, the preview page corresponding to the target code can be directly displayed in the code editor, and the preview page of the debugged code can be synchronously displayed according to the manual debugging operation of the code. In some embodiments, the code conversion model has a multi-modal processing capability, and the preview page and design page of the target code can be input into the code conversion model again, so as to utilize the multi-modal processing capability of the code conversion model, compare the preview page and design page of the target code, and continue to modify the target code or make modification suggestions according to the compared differences.

[0067] S4. Use AI agents to perform operations such as testing, deployment, and monitoring of the target code. For example, the AI ​​agent can be called to test the target code, and when it is detected that the preview page of the target code is slightly different from the design page, the API of the instant messaging platform is called to send a manual test reminder message to the tester. After the target code passes the test, the AI ​​agent can be called to perform a code review operation. In the process of performing the code review operation, the AI ​​agent can call a large language model to automatically review the readability, maintainability, and consistency of the code. After the target code passes the review, the AI ​​agent can be called to automatically deploy the target code to the online environment and perform grayscale release according to certain rules. After the deployment of the target code is completed, the AI ​​agent can be called to automatically monitor error prompts and user public opinion in the online environment, and when suspicious situations are detected, a notification message is sent to the corresponding developer to troubleshoot the error.

[0068] Based on this implementation, existing knowledge information can be used to assist the code conversion model in performing code conversion operations, so that the code conversion model can generate code that meets the programming specifications and product requirements of specific fields, greatly reducing the labor cost required for code conversion. In addition, the AI ​​agent can be used to call different interfaces to realize the automatic testing, deployment, and monitoring capabilities of the target code, making the code conversion method more intelligent, flexible, and reliable.

[0069] It should be noted that the execution subject of each step of the method provided in the above embodiment can be the same device, or the method can be executed by different devices. For example, the execution subject of steps 101 to 104 can be device A; for another example, the execution subject of steps 101 and 102 can be device A, and the execution subject of step 103 can be device B; and so on.

[0070] In addition, in some of the processes described in the above embodiments and the accompanying drawings, multiple operations that appear in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this article or executed in parallel, and the sequence numbers of the operations, such as 101, 102, etc., are only used to distinguish between different operations, and the sequence numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in this article are used to distinguish different messages, devices, modules, etc., do not represent the order of precedence, and do not limit the "first" and "second" to be different types.

[0071] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0072] Figure 6 FIG. 1 is a schematic diagram showing the structure of an electronic device provided by an exemplary embodiment of the present application, and the electronic device is applicable to the code conversion method provided by the above embodiment. Figure 6 As shown, the electronic device includes: a memory 601 and a processor 602.

[0073] The memory 601 is used to store computer programs and can be configured to store various other data to support operations on the electronic device. Examples of such data include instructions for any application program or method operating on the electronic device.

[0074] The processor 602 is coupled to the memory 601 and is used to execute the computer program in the memory 601, so as to: respond to the code acquisition operation, obtain the initial code of the target functional object written in the first programming language; obtain the knowledge information required to convert the initial code into the target code written in the second programming language in the target knowledge base, and the knowledge information at least includes the functional attribute information and / or programming knowledge information of the target functional object; call the code conversion model, convert the initial code according to the knowledge information, and obtain the target code, wherein the first programming language and the second programming language are different.

[0075] Optionally, when the processor 602 obtains the knowledge information required to convert the initial code into the target code written in the second programming language in the target knowledge base, it is specifically used to: search the target knowledge base according to the identification information of the target functional object to obtain the functional attribute document corresponding to the target functional object, the functional attribute document including: design documents and / or product documents; according to the functional attribute document, obtain the functional attribute information of the target functional object as the knowledge information.

[0076] Optionally, when the processor 602 obtains the knowledge information required to convert the initial code into the target code written in the second programming language in the target knowledge base, it is specifically used to: search the target knowledge base according to the first programming language and / or the second programming language to obtain the knowledge document corresponding to the first programming language and / or the second programming language; obtain the programming knowledge information as the knowledge information according to the knowledge document corresponding to the first programming language and / or the second programming language.

[0077] Optionally, when calling the code conversion model to convert the initial code according to the knowledge information, the processor 602 is specifically configured to: in response to the code conversion operation, generate a conversion prompt word according to the initial code and a conversion rule from the first programming language to the second programming language; and call the code conversion model according to the conversion prompt word and the knowledge information, so that the code conversion model converts the initial code according to the knowledge information under the prompt of the conversion prompt word.

[0078] Optionally, when the processor 602 calls the code conversion model according to the conversion prompt word and the knowledge information so that the code conversion model converts the initial code according to the knowledge information under the prompt of the conversion prompt word, it is specifically used to: input the conversion prompt word and the knowledge information into the code conversion model; parse the conversion prompt word in the code conversion model to identify the conversion task of converting the initial code into the target code written in the second programming language; in the process of executing the conversion task, identify the conversion rule from the first programming language to the second programming language from the conversion prompt word; encode the conversion rule and the knowledge information to obtain a context encoding vector; and convert the initial code segment by segment according to the context encoding vector and the pre-learned code conversion knowledge to obtain the target code.

[0079] Optionally, after calling the code conversion model and converting the initial code according to the knowledge information to obtain the target code written in the second programming language, the processor 602 is also used to: obtain the design page of the target functional object and the preview page corresponding to the target code; generate modification prompt words according to the target code, the preview page and the design page; according to the modification prompt words, call the code conversion model to obtain the difference between the preview page and the design page, and when the difference is greater than a set threshold, modify the target code according to the difference.

[0080] Optionally, after calling the code conversion model and converting the initial code according to the knowledge information to obtain the target code written in the second programming language, the processor 602 is also used to: display a preview page corresponding to the target code and the target code; and respond to an editing operation on the target code by displaying a preview page corresponding to the edited target code.

[0081] Optionally, after calling the code conversion model and converting the initial code according to the knowledge information to obtain the target code written in the second programming language, the processor 602 is also used to: display at least one control, each control corresponding to an intelligent agent with a specified function; respond to a selection operation of a deployment control in the at least one control, call the intelligent agent corresponding to the deployment control, obtain the deployment rules of the target function object, and deploy the target function object in a specified online running environment according to the target code and the deployment rules.

[0082] Optionally, before calling the intelligent agent corresponding to the deployment control, obtaining the deployment rules of the target functional object, and deploying the target functional object in a specified online operating environment according to the target code and the deployment rules, the processor 602 is also used to: respond to a selection operation of a verification control in at least one of the controls, call the intelligent agent corresponding to the verification control, perform a predefined verification operation on the target code, so as to deploy the target functional object in the specified online operating environment according to the target code and the deployment rules after the target code passes the verification operation.

[0083] Optionally, after calling the intelligent agent corresponding to the deployment control, obtaining the deployment rules of the target functional object, and deploying the target functional object in a specified online operating environment according to the target code and the deployment rules, the processor 602 is also used to: respond to a selection operation of a monitoring control in at least one of the controls, call the intelligent agent corresponding to the monitoring control, obtain feedback information after the target functional object is launched from the online operating environment and / or the specified social platform; identify operating problems of the target functional object according to the feedback information; and, when the operating problem meets the set conditions, execute predefined early warning operations.

[0084] Further, if Figure 6 As shown, the electronic device also includes: a communication component 603, a power component 604, a display component 605, an audio component 606 and other components. Figure 6 Only some components are shown schematically, which does not mean that the electronic device only includes Figure 6 Components shown. Figure 6Components in the dashed box are optional components, not mandatory components, and may depend on the product form of the electronic device. The electronic device of this embodiment may be implemented as a terminal device such as a desktop computer, a laptop computer, a smart phone, or an IOT device, or may be a server device such as a conventional server, a cloud server, or a server array. If the electronic device of this embodiment is implemented as a terminal device such as a desktop computer, a laptop computer, a smart phone, etc., it may include Figure 6 If the electronic device of this embodiment is implemented as a server device such as a conventional server, a cloud server or a server array, it may not include Figure 6 Components within the dashed box.

[0085] Among them, the memory 601 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.

[0086] Among them, the communication component 603 is configured to facilitate wired or wireless communication between the device where the communication component is located and other devices. The device where the communication component is located can access a wireless network based on a communication standard, such as 2G (such as Global System for Mobile Communications (GSM)), 3G (such as Wideband Code Division Multiple Access (WCDMA), 4G (such as Long Term Evolution (LTE)), 4G+ (such as upgraded version of Long Term Evolution (LTE-Advanced, LTE-A)) or 5G (fifth generation mobile communication technology (5th Generation Mobile Communication Technology)), or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel.

[0087] The power supply component 604 is used to provide power to various components of the device where the power supply component is located. The power supply component may include a power management system, one or more power supplies, and other components associated with generating, managing and distributing power to the device where the power supply component is located.

[0088] The display assembly includes a screen, which may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.

[0089] The audio component may be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC), and when the device where the audio component is located is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal may be further stored in a memory or sent via a communication component. In some embodiments, the audio component also includes a speaker for outputting an audio signal.

[0090] In this embodiment, the electronic device can respond to the code acquisition operation, acquire the initial code of the target function object written in the first programming language, and acquire the knowledge information required to convert the initial code into the target code written in the second programming language in the target knowledge base. The electronic device can call the code conversion model, convert the initial code according to the knowledge information, and obtain the target code. Among them, the knowledge information at least includes the function attribute information and / or programming knowledge information of the target function object, and then the code conversion model can learn or supplement the specific domain knowledge required to convert the initial code written in the first programming language into the target code written in the second programming language with the assistance of the knowledge information, and use the learned or supplemented specific domain knowledge to convert the initial code into the target code that meets the requirements, which greatly reduces the dependence of the code conversion operation on manual work and reduces the cost of the code conversion operation. In addition, even if the first programming language or the second programming language is a non-universal programming language, the code conversion model can learn the conversion method between special programming languages ​​and the conversion between special programming languages ​​and general programming languages ​​from the knowledge information based on the strong learning ability, so as to realize the conversion between special programming languages, or the conversion between special programming languages ​​and general programming languages.

[0091] Accordingly, the embodiment of the present application also provides a computer-readable storage medium storing a computer program, and when the computer program is executed, each step that can be performed by the electronic device in the above method embodiment can be implemented. Among them, the computer-readable storage medium includes volatile or non-volatile or a combination thereof, and can be removable or non-removable. Examples of computer-readable storage media include, but are not limited to, phase-change random access memory (Phase-change Random Access Memory, PRAM), static random access memory (SRAM), dynamic random access memory (Dynamic Random Access Memory, DRAM), other types of random access memory (Random-Access Memory, RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technology, read-only compact disc read-only memory (CD-ROM), digital versatile disc (Digital Video Disc, DVD) or other optical storage, magnetic cassette, tape disk storage or other magnetic storage device or any other non-transmission medium.

[0092] The present application embodiment also provides a computer program product, including: a computer program / instruction, which can implement the steps in the method provided in the present application embodiment when the computer program / instruction is executed by a processor. It should be understood that each process or a combination of multiple processes in the above method flow can be implemented by a computer program or instruction. In addition, these computer programs or instructions can be applied to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device, so that the processor of the general-purpose computer, the special-purpose computer, the embedded processor or other programmable data processing device can be implemented as a device for implementing the corresponding functions in the above method embodiment.

[0093] It should also be noted that the terms "comprises", "includes" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, product or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, product or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, product or device including the element.

[0094] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims

1. A code conversion method, characterized in that: include: In response to the code acquisition operation, an initial code of the target functional object written in the first programming language is acquired; In the target knowledge base, obtaining knowledge information required to convert the initial code into a target code written in a second programming language, the knowledge information at least including function attribute information and / or programming knowledge information of the target function object; A code conversion model is called to convert the initial code according to the knowledge information to obtain the target code, wherein the first programming language is different from the second programming language.

2. The method according to claim 1, characterized in that In the target knowledge base, knowledge information required to convert the initial code into a target code written in a second programming language is obtained, including: According to the identification information of the target functional object, the target knowledge base is searched to obtain the functional attribute document corresponding to the target functional object, wherein the functional attribute document includes: design document and / or product document; According to the functional attribute document, functional attribute information of the target functional object is acquired as the knowledge information.

3. The method according to claim 1, characterized in that In the target knowledge base, knowledge information required to convert the initial code into a target code written in a second programming language is obtained, including: Searching the target knowledge base according to the first programming language and / or the second programming language to obtain knowledge documents corresponding to the first programming language and / or the second programming language; The programming knowledge information is acquired according to the knowledge document corresponding to the first programming language and / or the second programming language as the knowledge information.

4. The method according to claim 1, characterized in that Calling a code conversion model to convert the initial code according to the knowledge information includes: In response to the code conversion operation, generating a conversion prompt word according to the initial code and a conversion rule from the first programming language to the second programming language; The code conversion model is called according to the conversion prompt word and the knowledge information, so that the code conversion model converts the initial code according to the knowledge information under the prompt of the conversion prompt word.

5. The method according to claim 4, characterized in that The code conversion model is called according to the conversion prompt word and the knowledge information, so that the code conversion model converts the initial code according to the knowledge information under the prompt of the conversion prompt word, including: Inputting the conversion cue words and the knowledge information into the code conversion model; In the code conversion model, the conversion hint word is parsed to identify a conversion task of converting the initial code into a target code written in the second programming language; In the process of executing the conversion task, identifying a conversion rule from the first programming language to the second programming language from the conversion prompt word; Encoding the conversion rule and the knowledge information to obtain a context encoding vector; According to the context coding vector and pre-learned code conversion knowledge, the initial code is converted section by section to obtain the target code.

6. The method according to any one of claims 1 to 5, characterized in that: After calling the code conversion model and converting the initial code according to the knowledge information to obtain the target code written in the second programming language, the method further includes: Obtaining a design page of the target functional object and a preview page corresponding to the target code; Generate a modification prompt word according to the target code, the preview page and the design page; According to the modification prompt word, the code conversion model is called to obtain the difference between the preview page and the design page, and when the difference is greater than a set threshold, the target code is modified according to the difference.

7. The method according to any one of claims 1 to 5, characterized in that: After calling the code conversion model and converting the initial code according to the knowledge information to obtain the target code written in the second programming language, the method further includes: Displaying a preview page corresponding to the target code and the target code; In response to the editing operation on the target code, a preview page corresponding to the edited target code is displayed.

8. The method according to any one of claims 1 to 5, characterized in that: After calling the code conversion model and converting the initial code according to the knowledge information to obtain the target code written in the second programming language, the method further includes: Display at least one control, each of which corresponds to an agent with a specified function; In response to a selection operation on a deployment control among the at least one control, the intelligent agent corresponding to the deployment control is called to obtain the deployment rules of the target function object, and the target function object is deployed in a specified online running environment according to the target code and the deployment rules.

9. The method according to claim 8, characterized in that Before calling the agent corresponding to the deployment control to obtain the deployment rule of the target function object and deploying the target function object in a specified online running environment according to the target code and the deployment rule, the method further includes: In response to a selection operation of a verification control in at least one of the controls, the intelligent agent corresponding to the verification control is called to perform a predefined verification operation on the target code, so that after the target code passes the verification operation, the target function object is deployed in a specified online running environment according to the target code and the deployment rules.

10. The method according to claim 8, characterized in that After calling the agent corresponding to the deployment control, obtaining the deployment rule of the target function object, and deploying the target function object in a specified online running environment according to the target code and the deployment rule, the method further includes: In response to a selection operation of a monitoring control in the at least one control, an agent corresponding to the monitoring control is called to obtain feedback information after the target functional object goes online from the online operating environment and / or the designated social platform; identifying, based on the feedback information, operational problems of the target functional object; and, When the operation problem meets the set conditions, a predefined early warning operation is executed.

11. An electronic device, characterized in that: include: Memory and processor; The memory is used to store one or more computer instructions; The processor is configured to execute the one or more computer instructions to: perform the steps in the method according to any one of claims 1-10.

12. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps in the method described in any one of claims 1 to 10 can be implemented.

13. A computer program product, characterized in that include: A computer program / instruction, which, when executed by a processor, can implement the steps of the method according to any one of claims 1 to 10.

Citation Information

Cited By

  • Multi-source heterogeneous hybrid code unified standardization method oriented to intelligent model service

    CN120085845A

  • Code conversion method and device, electronic equipment and storage medium

    CN120872325A

  • Delaration element code conversion method and device

    CN121683700A