Code conversion method and device, storage medium and program product
By dividing the code file into fragments, using conversion rules and knowledge fragments to generate target prompt words, and guiding the code conversion model to rewrite the code, it solves the problem that existing tools cannot accurately perceive framework changes and achieves highly accurate code conversion.
Patent Information
- Application Number
- CN202510413558.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-07-18
AI Technical Summary
Existing code conversion tools cannot accurately perceive syntax or function changes when the framework version is upgraded, resulting in the converted code that may retain the syntax or functions of the old version, fail to run correctly, and lack understanding of the code context semantics, resulting in inconsistent logic.
By dividing the code file into multiple fragments, using the preset conversion rule library and the user's private knowledge base to retrieve matching rules and knowledge fragments, generate target prompt words, and guide the code conversion model to rewrite to ensure the accuracy of the conversion.
Improve the accuracy of code conversion results between different versions, avoid syntax errors and logical inconsistencies, and generate high-quality object code files.
Smart Images

Figure CN120335816A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and particularly to a code conversion method, device, storage medium, and program product. Background Art
[0002] With the rapid development of science and technology, Internet applications are constantly updating and upgrading their versions to provide a faster and more efficient user experience. For example, in the field of front-end development, a new framework version (such as Vue3) usually brings a significant performance improvement compared to an old version (such as Vue 2). However, the upgrade of the framework version is often accompanied by adjustments in syntax and functions. Every time there is an upgrade, users need to spend a lot of time understanding the differences between the two framework versions and then converting the code under the existing framework version into the code under the new framework version.
[0003] Currently, for the problem of code conversion, code conversion tools based on Abstract Syntax Trees (ASTs) are mainly used to achieve automated or semi-automated code conversion. The code conversion tool converts the code file of the old version into an abstract syntax tree, then modifies the obtained abstract syntax tree to conform to the syntax of the new version, and then uses the modified abstract syntax tree to generate a code file converted into the new version.
[0004] However, in practical applications, in a new version framework (such as Vue 3), some syntax or functions have been adjusted or deprecated, but existing code conversion tools cannot perceive these changes, resulting in the possibility that the converted code snippet may still retain the syntax or functions of the old version, causing the converted code to not run correctly. Moreover, existing code conversion tools mainly focus on the syntax structure of the code and lack a good understanding of the context semantics of the code, which may lead to syntax errors or logical inconsistencies in the converted code during runtime. Summary of the Invention
[0005] Multiple aspects of this application provide a code conversion method, device, storage medium, and program product to improve the accuracy of code conversion results between different versions.
[0006] An embodiment of this application provides a code conversion method, which includes:
[0007] In response to a code conversion request triggered by a client for a code file to be converted, the code file to be converted is segmented into multiple code snippets, where the code conversion request is used to request to convert the code file to be converted in the current version into a code file in the target version specified by the client;
[0008] Retrieve a conversion rule matching each code snippet from a preset conversion rule library;
[0009] Retrieve knowledge fragments that match each of the code snippets from the user's private knowledge base;
[0010] Fill each of the code snippets, the conversion rules that match each of the code snippets, and the knowledge fragments that match each of the code snippets into a preset prompt template to generate a target prompt;
[0011] Input the target prompt and the code file to be converted into the code conversion model to obtain the target code file corresponding to the code file to be converted;
[0012] Among them, under the guidance of the target prompt, the code conversion model identifies the code snippets to be converted from the multiple code snippets, and rewrites the code snippets to be converted based on the conversion rules that match the code snippets to be converted and the knowledge fragments that match the code snippets to be converted, so as to generate the target code file based on the rewritten code snippets.
[0013] An embodiment of the present application provides a code conversion device, and the device includes:
[0014] A splitting module, configured to split the code file to be converted into multiple code snippets in response to a code conversion request triggered by the user terminal for the code file to be converted, where the code conversion request is used to request to convert the current version of the code file to be converted into a code file in the target version specified by the user terminal;
[0015] A first retrieval module, configured to retrieve conversion rules that match each of the code snippets from a preset conversion rule library;
[0016] A second retrieval module, configured to retrieve knowledge fragments that match each of the code snippets from the user's private knowledge base;
[0017] A generation module, configured to fill each of the code snippets, the conversion rules that match each of the code snippets, and the knowledge fragments that match each of the code snippets into a preset prompt template to generate a target prompt;
[0018] A processing module, configured to input the target prompt and the code file to be converted into a code conversion model to obtain the target code file corresponding to the code file to be converted; among them, under the guidance of the target prompt, the code conversion model identifies the code snippets to be converted from the multiple code snippets, and rewrites the code snippets to be converted based on the conversion rules that match the code snippets to be converted and the knowledge fragments that match the code snippets to be converted, so as to generate the target code file based on the rewritten code snippets.
[0019] An embodiment of the present application further provides an electronic device, including: a memory and a processor; the memory is used to store a computer program; the processor is coupled to the memory and is used to execute the computer program to implement the steps in the code conversion method provided by the embodiment of the present application.
[0020] An embodiment of the present application further provides a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to implement the steps in the code conversion method provided by the embodiment of the present application.
[0021] An embodiment of the present application further provides a computer program product, including computer program / instructions, which, when executed by a processor, cause the processor to implement the steps in the code conversion method provided by the embodiment of the present application.
[0022] In the code conversion solution provided by the embodiment of the present application, code conversion services between different versions can be provided for users. Specifically, in implementation, first, in response to a code conversion request triggered by the user side for the code file to be converted, the code file to be converted is split into multiple code segments. The code conversion request is used to request to convert the code file to be converted in the current version into a code file in the target version specified by the user side. Then, conversion rules matching each code segment are retrieved from a preset conversion rule library, and knowledge segments matching each code segment are retrieved from the user's private knowledge library. Then, each code segment, the conversion rule matching each code segment, and the knowledge segment matching each code segment are filled into a preset prompt template to generate a target prompt. Finally, the target prompt and the code file to be converted are input into a code conversion model to obtain a target code file corresponding to the code file to be converted. The code conversion model, under the guidance of the target prompt, identifies the code segments to be converted from multiple code segments, and rewrites the code segments to be converted based on the conversion rules matching the code segments to be converted and the knowledge segments matching the code segments to be converted, so as to generate a target code file corresponding to the code file to be converted based on the rewritten code segments.
[0023] In the above solution, during the process of converting the code file to be converted in the current version into the target code file in the target version, based on multiple code snippets in the code file to be converted, the conversion rules matched by each code snippet, and the knowledge snippets matched by each code snippet, the target prompt words corresponding to the model are generated. By guiding the code conversion model with the target prompt words, the code snippets to be converted are identified from multiple code snippets, and the code snippets to be converted are rewritten based on the conversion rules matched by the code snippets to be converted and the knowledge snippets matched by the code snippets to be converted, which can enable the code conversion model to more accurately convert the code file to be converted into the target code file in the target version, and improve the accuracy of the code conversion result between different versions. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] 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 to the present application. In the drawings:
[0025] Figure 1 is a schematic flowchart of a code conversion method provided by an exemplary embodiment of the present application;
[0026] Figure 2 is a schematic flowchart of a process for retrieving conversion rules matching each code snippet provided by an exemplary embodiment of the present application;
[0027] Figure 3 is a schematic flowchart of a process for retrieving knowledge snippets matching each code snippet provided by an exemplary embodiment of the present application;
[0028] Figure 4 is a schematic flowchart of another code conversion method provided by an exemplary embodiment of the present application;
[0029] Figure 5 is a code conversion device provided by an exemplary embodiment of the present application;
[0030] Figure 6 is a schematic structural diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0031] In order to make the objectives, technical solutions, and advantages of the present application clearer, the technical solutions of the present application will be clearly and completely described below in conjunction with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0032] 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 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. Moreover, the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions, and corresponding operation entrances are provided for users to choose to authorize or reject.
[0033] The various models (including but not limited to language models or large models) involved in this application comply with relevant laws and standards.
[0034] With the continuous upgrade of the front-end framework version, it is necessary to convert the code under the existing Vue 2 framework version into the code under the new Vue 3 framework version. Currently, code conversion tools based on the Abstract Syntax Tree (AST) are mainly used to achieve automated or semi-automated code conversion. However, such code conversion tools generate new version code files based on the abstract syntax tree, focusing on the syntax structure of the code and lacking a better understanding of the context semantics of the code, which may lead to syntax errors or logical inconsistencies in the converted code during runtime. Moreover, in the Vue 3 version framework, some syntax or functions have been adjusted or deprecated, but the existing code conversion tools cannot perceive these changes, resulting in the converted code snippets possibly still retaining the syntax or functions of the old version, causing the converted code to not run correctly.
[0035] To address the above technical problems, this application proposes a new code conversion scheme. In this scheme, by combining the conversion rules and knowledge fragments retrieved and matched with each code snippet in the code file to be converted, a code conversion model is used to perform code conversion processing between different versions on the code to be converted, so as to automatically generate the target code file after conversion. Moreover, by generating target generation words, the code conversion model can be guided to perform code conversion processing between different versions, enabling the code conversion model to more accurately convert the code file to be converted into the target code file under the target version, improving the accuracy of the code conversion results between different versions.
[0036] The following will detail the code conversion scheme provided by the embodiments of this application in conjunction with the accompanying drawings.
[0037] Figure 1 It is a schematic flowchart of a code conversion method provided for an exemplary embodiment of this application. As Figure 1 shown, the execution subject of this method can be a code conversion device. Specifically, this method includes the following steps:
[0038] 101. In response to a code conversion request triggered by a user terminal for a code file to be converted, the code file to be converted is segmented into multiple code snippets. The code conversion request is used to request the conversion of the code file to be converted in the current version into a code file in the target version specified by the user terminal.
[0039] 102. Retrieve conversion rules matching each code snippet from a preset conversion rule library.
[0040] 103. Retrieve knowledge snippets matching each code snippet from the user's private knowledge library.
[0041] 104. Fill each code snippet, the conversion rule matching each code snippet, and the knowledge snippet matching each code snippet into a preset prompt template to generate a target prompt.
[0042] 105. Input the target prompt and the code file to be converted into a code conversion model to obtain the target code file corresponding to the code file to be converted. Among them, under the guidance of the target prompt, the code conversion model identifies the code snippets to be converted from multiple code snippets, and rewrites the code snippets to be converted based on the conversion rules matching the code snippets to be converted and the knowledge snippets matching the code snippets to be converted, so as to generate the target code file based on the rewritten code snippets.
[0043] The code conversion solution provided by the embodiments of this application can provide code conversion services between different versions for the user terminal. In practical applications, when the user terminal wants to upgrade the framework corresponding to the current application version, it can obtain the code file to be converted corresponding to the current application version, and trigger a code conversion request for the code file to be converted to the code conversion device to request the conversion of the code file to be converted in the current version into a code file in the target version specified by the user terminal. Among them, the code file to be converted refers to the code file that needs to be processed for version conversion in the current version.
[0044] After receiving the code conversion request triggered by the user terminal, in response to the code conversion request triggered by the user terminal for the code file to be converted, the code file to be converted is segmented into multiple code snippets. In practical applications, a code file to be converted may include the source codes of multiple different functional functions. In order to enable the code conversion model to accurately convert the source codes of each different functional function in the code file to be converted, the code to be converted can be segmented into multiple code snippets first, and each code snippet can represent a functional function.
[0045] In specific implementation, the code file to be converted can also be segmented according to different preset segmentation strategies. For example, segmenting by functional modules, the code file to be converted is segmented according to different functional modules, and each module implements a specific function or a set of related functions. Or segmenting by classes or interfaces, each class or interface in the code file to be converted is segmented into separate code snippets. Segmenting by functions or methods, large functions or methods are segmented into smaller and more specific functions or methods. Or, segmenting according to the hierarchical structure of the code, such as dividing the code into levels of packages, classes, methods, code blocks, etc. Or, leveraging the semantic understanding ability of large language models (such as the GPT series) to segment according to the semantic structure of the code. Or, large functions or methods are segmented into smaller and more specific functions or methods.
[0046] Since code conversion between different versions may not only involve syntax conversion, but also the deprecation of different functions, the addition of new functional modules, and the update of functional modules, in order to more accurately implement code conversion processing between different versions, before converting multiple code snippets, each code snippet can be analyzed first to retrieve the conversion rules that match each code snippet from the preset conversion rule library.
[0047] Among them, a large number of code conversion rules between different versions are stored in the preset conversion rule library. The code conversion rules can include syntax conversion rules, semantic conversion rules, programming mode conversion rules, technology upgrade rules between different versions of code, framework design concept transformation rules, framework design paradigm upgrade rules, deprecation and upgrade rules for old and new functions, etc.
[0048] In specific implementation, a preset conversion rule library can be created in advance, and a large number of code conversion rules between different versions are stored in the preset conversion rule library, so that when providing code conversion services for the user side, each conversion rule in the preset conversion rule library created in advance can be directly used for code conversion processing.
[0049] Among them, common version conversion rules can be extracted from historical project changes. For example, analyze the change records from Vue2.x to Vue 3.x and extract rules such as API replacement and configuration adjustment. Use code analysis tools (such as AST parsers) to extract patterns and change laws in code of different versions to generate conversion rules. And the existing version conversion experience in the open source community, official documents, or technical blogs can also be referred to extract general conversion rules. For some complex conversion logics, developers can manually write the rules.
[0050] In addition, a unified structure can be designed for each rule. Each rule includes a rule ID, a rule description, matching conditions, transformation logic, and scope of application. Among them, the matching conditions refer to the conditions for triggering the rule (such as code patterns, version ranges, etc.). The transformation logic refers to the specific transformation operations (such as replacing code snippets, modifying configuration parameters, etc.). The scope of application refers to the code types and version ranges to which the rule applies. Moreover, each rule can be converted into a unified vector representation.
[0051] Next, retrieve the knowledge fragments that match each code snippet from the user's private knowledge base. In practical applications, a user's private knowledge base can be pre-constructed, which can store background knowledge related to different versions of the code and the corresponding project information on the user side. For example, the user's private knowledge base includes MarkDown documents or website addresses of the Vue2 ecosystem, Element UI, Vue3 ecosystem, Element Plus, and the changes in Vue3 compared to Vue2.
[0052] By retrieving knowledge fragments from the user's private knowledge base, background knowledge related to each code snippet can be searched out. The knowledge fragments that match each retrieved code snippet are used as context information to better understand the syntax information, semantic information, structural information, functional information, and corresponding version upgrade content of each code snippet. In this way, code transformation processing can be better performed on each code snippet based on the knowledge fragments that match each code snippet.
[0053] After obtaining the transformation rules that match each code snippet and the knowledge fragments that match each code snippet, in order to enable the code transformation model to better combine the transformation rules and knowledge fragments to perform transformation processing on each code snippet, target prompt words corresponding to the model can be generated to perform code transformation processing under the guidance of the target prompt words.
[0054] Specifically, each code snippet, the transformation rules that match each code snippet, and the knowledge fragments that match each code snippet are filled into a preset prompt word template to generate target prompt words. Among them, the preset prompt word template includes task description information, output format information, transformation examples, etc. Multiple preset prompt word templates corresponding to the code transformation model can be pre-constructed. In practical applications, the corresponding preset prompt word template can be selected according to the task to be processed to generate target prompt words.
[0055] Next, input the target prompt and the code file to be converted into the code conversion model to obtain the target code file corresponding to the code file to be converted. Among them, under the guidance of the target prompt, the code conversion model identifies the code segments to be converted from multiple code segments, and rewrites the code segments to be converted based on the conversion rules matched with the code segments to be converted and the knowledge segments matched with the code segments to be converted, so as to generate the target code file corresponding to the code file to be converted based on the rewritten code segments.
[0056] Among them, the code conversion model is used to convert the code file to be converted under the current version into the target code file under the target version. For example, the code conversion model can be the DeepSeek Coder model, the large language model (Large Language Model, LLM), etc.
[0057] When the code conversion model performs conversion processing on the code to be converted, it can first determine the changes in the code of the current version relative to the code of the target version, and based on the changes, identify the code segments to be converted from multiple code segments. Then, perform syntax analysis and semantic analysis on the code segments to be converted, and rewrite the code segments to be converted in combination with the conversion rules matched with each code segment to be converted and the knowledge segments matched with the code segments to be converted, and generate the target code file corresponding to the code file to be converted based on the rewritten code segments. That is, when the code conversion model rewrites each code segment to be converted, it can rewrite each code segment to be converted targeted based on the retrieved conversion rules and knowledge segments, avoiding errors in the conversion process caused by inaccurate information searched when the code conversion model searches for relevant knowledge by itself, and improving the quality of code conversion.
[0058] In summary, in the process of converting the code file to be converted under the current version into the target code file under the target version in the embodiments of the present application, based on multiple code segments in the code file to be converted, the conversion rules matched with each code segment, and the knowledge segments matched with each code segment, a target prompt corresponding to the model is generated, and the code conversion model is guided by the target prompt to identify the code segments to be converted from multiple code segments, and rewrite the code segments to be converted based on the conversion rules matched with the code segments to be converted and the knowledge segments matched with the code segments to be converted, which can make the code conversion model more accurately convert the code file to be converted into the target code file under the target version, and improve the accuracy of the code conversion result between different versions.
[0059] Among them, the conversion rules corresponding to each code snippet input into the code conversion model and the quality of the knowledge snippets will directly determine the quality of the conversion results of the code conversion model. Then, in order to obtain a target code file with higher quality after conversion. In specific implementation, different retrieval strategies can be used to retrieve the conversion rules and matching knowledge snippets that match each code snippet. The following embodiments will be used to illustrate this process in detail.
[0060] It should be noted that: The specific implementation processes for processing multiple code snippets in the code file to be converted are generally the same. In the following embodiments, only the target code snippet will be used as an example to exemplarily illustrate the specific implementation processes of retrieving conversion rules and retrieving knowledge snippets. Among them, the target code snippet is any one of the multiple code snippets in the code file to be converted.
[0061] Figure 2 The figure is a schematic flow chart of a method for retrieving conversion rules that match each code snippet provided by an exemplary embodiment of this application. As Figure 2 shown, specifically, the method includes the following steps:
[0062] 201. Use an embedding model to vectorize the target code snippet to obtain a first vector representation corresponding to the target code snippet.
[0063] 202. Retrieve a second vector representation from a preset conversion rule library whose similarity to the first vector representation meets the requirements.
[0064] 203. Encode the second vector representation to obtain a first conversion rule corresponding to the target code snippet.
[0065] Among them, the first conversion rule that matches the target code snippet can be retrieved by comparing the similarity between vector representations. Specifically, an embedding model can be used to vectorize the target code snippet first to obtain a first vector representation corresponding to the target code snippet.
[0066] The embedding model is used to vectorize each code snippet, each conversion rule in the preset conversion rule library, and each knowledge snippet in the user's private knowledge library. The embedding model can be a word vector embedding model, a convolutional neural network (CNN), etc. For example: The embedding model is a Word2Vec model.
[0067] In practical applications, the embedding model can also be used to process each transformation rule in the preset transformation rule library to obtain the vector representation corresponding to each transformation rule. To improve the code transformation processing speed, before executing the code transformation request corresponding to the user side, each transformation rule in the preset transformation rule library can be vectorized in advance to obtain the vector representation corresponding to each transformation rule, and the vector representation corresponding to each transformation rule can be stored in the preset transformation rule library for subsequent direct reading of the vector representation corresponding to each transformation rule.
[0068] Next, compare the similarity between the first vector representation corresponding to the target code snippet and each vector representation in the preset transformation rule library to filter out the second vector representation whose similarity with the first vector representation meets the requirements from the preset transformation rule library. Among them, the retrieved second vector representation can be one or more.
[0069] In an alternative embodiment, a first neural network model can be used to filter out the second vector representation whose similarity with the first vector representation meets the requirements from the preset transformation rule library. Among them, the first neural network model learns to calculate the similarity between vectors and outputs the top n vector representations with the highest similarity. For example, the first neural network model can be Milvu, FAISS, etc. Perform ANN search in Milvus / FAISS and return the Top5 vector representations.
[0070] Then, encode the second vector representation to obtain the first transformation rule corresponding to the target code snippet. Among them, the first transformation rule corresponding to the second vector representation can also be determined from the preset transformation rule library based on the identifier corresponding to the second vector representation.
[0071] In addition, in practical applications, the keyword retrieval method can also be used to retrieve the first transformation rule that matches the target code snippet. To retrieve the first transformation rule that matches the target code snippet more comprehensively and accurately, in another alternative embodiment, two methods can be used simultaneously to retrieve the first transformation rule that matches the target code snippet.
[0072] Specifically, the method may further include: performing keyword recognition processing on the target code snippet to obtain the target keyword corresponding to the target code snippet. Retrieve the second transformation rule whose similarity with the target keyword meets the requirements from the preset transformation rule library.
[0073] In an alternative embodiment, a second neural network model may be employed to retrieve from a preset conversion rule library a second conversion rule that meets the requirement of similarity to the target keyword. Generally, the first neural network model and the second neural network model are set to output the top n vector representations with the highest similarity to the target code snippet or the top n conversion rules with the highest similarity to the target keyword corresponding to the target code snippet. Then, to avoid the technical problem that the retrieved conversion rule has low relevance to the target code snippet, resulting in deviation in the code conversion result, in the embodiment of the present application, the respective allocation weights corresponding to the two methods and application of reordering may also be set to select from the two types of query results the conversion rule most relevant to the target code snippet.
[0074] Specifically, when the conversion rules matching the target code snippet are screened out through the above two methods, the first weight corresponding to the first conversion rule and the second weight corresponding to the second conversion rule may be determined, and the first weight is less than the second weight. Based on the first weight and the second weight, the first conversion rule and the second conversion rule are sorted in descending order of relevance to the target code snippet, so as to screen out from the first conversion rule and the second conversion rule the target conversion rule most relevant to the target code snippet.
[0075] Among them, the allocation weight corresponding to the vector retrieval method and the allocation weight corresponding to the keyword retrieval method may also be set according to actual needs, so as to determine the respective weights of the first conversion rule and the second conversion rule according to the preset allocation weights corresponding to the two retrieval methods.
[0076] In addition, to more accurately screen out the conversion rule most relevant to the target code snippet, a pre-trained retrieval and sorting model may also be used to sort the first conversion rule and the second conversion rule, so as to screen out from the first conversion rule and the second conversion rule the target conversion rule most relevant to the target code snippet.
[0077] Specifically, in an alternative embodiment, the first weight corresponding to the first conversion rule, the second weight corresponding to the second conversion rule, the first conversion rule, and the second conversion rule are input into a pre-trained retrieval and sorting model to obtain the target conversion rule most relevant to the target code snippet.
[0078] Among them, the retrieval and sorting model is used to sort each conversion rule based on the weight corresponding to each conversion rule and the relevance between each conversion rule and the target code snippet, and output the target conversion rule most relevant to the target code snippet based on the sorting result.
[0079] In the embodiment of the present application, by using an embedding model to perform vectorization processing on a target code snippet, a first vector representation corresponding to the target code snippet is obtained, and a second vector representation that meets the similarity requirement is retrieved from a preset conversion rule library. Encoding the second vector representation to obtain a first conversion rule corresponding to the target code snippet can screen out the most relevant conversion rule to the target code snippet from the preset conversion rule library, thereby ensuring the accuracy of the code conversion processing effect.
[0080] Figure 3 It is a schematic flowchart for retrieving knowledge fragments matching each code snippet provided by an exemplary embodiment of the present application. As Figure 3 shown, the user private knowledge base includes a first knowledge base corresponding to the current version code, a second knowledge base corresponding to the target version code, and a third knowledge base for storing the change content of the target version code relative to the current version code. The embodiment of the present application provides an implementation manner for retrieving knowledge fragments matching each code snippet from the user private knowledge base. Specifically, the method includes the following steps:
[0081] 301. Retrieve a third vector representation from the first knowledge base that meets the similarity requirement with the first vector representation.
[0082] 302. Retrieve a fourth vector representation from the second knowledge base that meets the similarity requirement with the first vector representation.
[0083] 303. Retrieve a fifth vector representation from the third knowledge base that meets the similarity requirement with the first vector representation.
[0084] 304. Encode the third vector representation, the fourth vector representation, and the fifth vector representation respectively to obtain a first sub-knowledge fragment corresponding to the third vector representation, a second sub-knowledge fragment corresponding to the fourth vector representation, and a third sub-knowledge fragment corresponding to the fifth vector representation.
[0085] 305. Integrate the first sub-knowledge fragment, the second sub-knowledge fragment, and the third sub-knowledge fragment to obtain a first knowledge fragment matching the target code snippet.
[0086] Among them, in order to better provide more comprehensive and relevant background knowledge fragments for each code snippet in the code file to be converted, when creating the first knowledge base corresponding to the current version code, the second knowledge base corresponding to the target version code, and the third knowledge base for storing the change content of the target version code relative to the current version code, they are jointly used as the user private knowledge base. In addition, a project knowledge base corresponding to the user side can also be specifically created.
[0087] When retrieving knowledge fragments that match the target code snippet, the matching sub-knowledge fragments can be retrieved from each sub-knowledge base in the user's private knowledge base respectively. Specifically, the third vector representation that meets the similarity requirement with the first vector representation can be retrieved from the first knowledge base. The fourth vector representation that meets the similarity requirement with the first vector representation can be retrieved from the second knowledge base. The fifth vector representation that meets the similarity requirement with the first vector representation can be retrieved from the third knowledge base.
[0088] Among them, the method of comparing the similarity between vector representations can be used to retrieve the knowledge fragments that match the target code snippet. Specifically, the embedding model can be used to vectorize each knowledge fragment in the first knowledge base, each knowledge fragment in the second knowledge base, and each knowledge fragment in the third knowledge base, so as to obtain the vector representation corresponding to each knowledge fragment.
[0089] Moreover, in an optional embodiment, a third neural network model can be used to screen out the vector representations that meet the similarity requirement with the first vector representation from each knowledge base. Among them, the third neural network model can be the above-mentioned first neural network model, or a neural network model retrained for retrieving from the knowledge base.
[0090] Then, the third vector representation, the fourth vector representation, and the fifth vector representation are encoded respectively to obtain the first sub-knowledge fragment corresponding to the third vector representation, the second sub-knowledge fragment corresponding to the fourth vector representation, and the third sub-knowledge fragment corresponding to the fifth vector representation. And the first sub-knowledge fragment, the second sub-knowledge fragment, and the third sub-knowledge fragment are integrated to obtain the first knowledge fragment that matches the target code snippet.
[0091] In addition, in actual applications, the keyword retrieval method can also be used to retrieve the second knowledge fragment that matches the target code snippet. In order to retrieve the second knowledge fragment that matches the target code snippet more comprehensively and accurately, in another optional embodiment, two methods can be used simultaneously to retrieve the knowledge fragment that matches the target code snippet.
[0092] Specifically, the method may further include: performing keyword recognition processing on the target code snippet to obtain the target keyword corresponding to the target code snippet. Retrieving the fourth sub-knowledge fragment that meets the similarity requirement with the target keyword from the first knowledge base. Retrieving the fifth sub-knowledge fragment that meets the similarity requirement with the target keyword from the second knowledge base. Retrieving the sixth sub-knowledge fragment that meets the similarity requirement with the target keyword from the third knowledge base. Integrating the first sub-knowledge fragment, the second sub-knowledge fragment, and the third sub-knowledge fragment to obtain the second knowledge fragment that matches the target code snippet.
[0093] In an alternative embodiment, a fourth neural network model may be employed to retrieve, from each knowledge base, a second knowledge fragment whose similarity to the target keyword meets the requirements. Generally, the third neural network model and the fourth neural network model are set to output the top n vector representations with the highest similarity to the target code fragment or the top n transformation rules with the highest similarity to the target keyword corresponding to the target code fragment. Then, to avoid the technical problem that the retrieved knowledge fragment has low relevance to the target code fragment, resulting in deviation in the code conversion result, in the embodiments of the present application, the respective allocation weights corresponding to the two methods may also be set, and re-ranking may be applied to select the knowledge fragment most relevant to the target code fragment from the two types of query results.
[0094] Specifically, when the knowledge fragments matching the target code fragment are screened out through the above two methods, the third weight corresponding to the first knowledge fragment and the fourth weight corresponding to the second knowledge fragment may be determined, and the third weight is less than the fourth weight. Based on the third weight and the fourth weight, the first knowledge fragment and the second knowledge fragment are sorted in descending order of relevance to the target code fragment, so as to screen out the target knowledge fragment most relevant to the target code fragment from the first knowledge fragment and the second knowledge fragment.
[0095] Among them, the allocation weight corresponding to the vector retrieval method and the allocation weight corresponding to the keyword retrieval method may also be set according to actual needs, so as to determine the respective weights of the first knowledge fragment and the second knowledge fragment according to the preset allocation weights corresponding to the two retrieval methods.
[0096] In addition, to more accurately screen out the knowledge fragment most relevant to the target code fragment, a pre-trained retrieval ranking model may also be used to rank the first knowledge fragment and the second knowledge fragment, so as to screen out the target knowledge fragment most relevant to the target code fragment from the first knowledge fragment and the second knowledge fragment.
[0097] Specifically, in an alternative embodiment, the first weight corresponding to the first knowledge fragment, the second weight corresponding to the second knowledge fragment, the first knowledge fragment, and the second knowledge fragment are input into a pre-trained retrieval ranking model to obtain the target knowledge fragment most relevant to the target code fragment.
[0098] Among them, the retrieval ranking model is used to rank each knowledge fragment based on the weight corresponding to each knowledge fragment and the relevance between each knowledge fragment and the target code fragment, and output the target knowledge fragment most relevant to the target code fragment based on the ranking result.
[0099] In the embodiments of the present application, by retrieving vector representations that meet the requirements of similarity with the first vector representation from each knowledge base in the user's private knowledge base, and encoding the retrieved three vector representations to obtain the first sub-knowledge fragment, the second sub-knowledge fragment, and the third sub-knowledge fragment, and integrating the first sub-knowledge fragment, the second sub-knowledge fragment, and the third sub-knowledge fragment, a first knowledge fragment matching the target code fragment can be obtained, and the knowledge fragment most relevant to the target code fragment can be screened out from each knowledge base, thereby ensuring the accuracy of the code conversion processing effect.
[0100] In addition, in practical applications, in order to facilitate the user to view the converted target code file, after obtaining the target code file output by the code conversion model, the target code file can also be directly sent to the corresponding user terminal. Or, after obtaining the target code file output by the code conversion model, the target code file can also be first processed such as code detection and performance optimization, and the processed target code file can be sent to the corresponding user terminal. Among them, code detection includes syntax checking, semantic logic detection, code style detection, etc. Performance optimization includes performance optimization, code style optimization, etc.
[0101] At the same time, in order to enable the code conversion model to more accurately convert the target code file required by the user, the feedback information corresponding to the target code file output by the code conversion model can also be collected, and the code conversion model can be optimized based on the user feedback information.
[0102] This process will be described in detail in combination with the following embodiments.
[0103] Figure 4 It is a schematic flowchart of another code conversion method provided by an exemplary embodiment of the present application. As Figure 4 shown, on the basis of the above embodiments, specifically, the method may further include the following steps:
[0104] 401. Send the target code file to the user.
[0105] 402. Receive the feedback information sent by the user for the target code file.
[0106] 403. Generate optimized training data according to the feedback information to optimize the code conversion model based on the optimized training data.
[0107] Among them, after obtaining the target code file output by the code conversion model, the target code file can be directly sent to the user. Or, after detecting and optimizing the target code file, it is sent to the user.
[0108] After sending the target code file to the user, the user can provide feedback on the target code file to generate corresponding feedback information. The feedback information sent by the user for the target code file is received, and optimized training data is generated based on the feedback information to optimize the code conversion model based on the optimized training data.
[0109] In the embodiments of the present application, by generating optimized training data according to the feedback information sent by the user for the target code file output by the code conversion model, and optimizing the code conversion model based on the optimized training data, the code conversion model can be continuously optimized, so that the code conversion model can accurately rewrite each code segment in the code file to be converted to generate a target code file of higher quality.
[0110] To facilitate the understanding of the code conversion process in the above embodiments, the following embodiments are used to illustrate this process by way of example. Suppose the user wants to convert the code file to be converted with the current version of Vue2 to a target code file with the Vue3 version. Specifically, in implementation:
[0111] In response to the code conversion request triggered by the user side for the code file to be converted with the Vue2 version, the code file to be converted is split into multiple code segments. Among them, the code conversion request is used to request the conversion of the code file to be converted with the Vue2 version to a code file with the Vue3 version. Then, the conversion rules matching each code segment are retrieved from the preset conversion rule library, and the knowledge segments matching each code segment are retrieved from the user's private knowledge library. Then, each code segment, the conversion rule matching each code segment, and the knowledge segment matching each code segment are filled into the preset prompt template to generate a target prompt. Finally, the target prompt and the code file to be converted with the Vue2 version are input into the code conversion model to obtain the target code file with the Vue3 version corresponding to the code file to be converted with the Vue2 version.
[0112] Among them, under the guidance of the target prompt, the code conversion model identifies the code segments to be converted from the multiple code segments of the code file to be converted with the Vue2 version, and rewrites the code file to be converted with the Vue2 version based on the conversion rules matching the code segments to be converted and the knowledge segments matching the code segments to be converted, so as to generate a target code file with the Vue3 version based on the rewritten code segments.
[0113] In addition, the code conversion device provided in the embodiments of the present application is inserted into the VSCode editor in the form of a VSCode extension plugin, so that the user side can directly call the VSCode extension plugin when using the VSCode editor to perform code conversion processing on the selected code file to be converted.
[0114] In addition, an AI agent can be used to complete the above code conversion process or to complete some of the above content. Specifically, collect MarkDown documents or document website addresses related to the Vue2 ecosystem, Element UI, Vue3 ecosystem, Element Plus, and the changes in Vue3 compared to Vue2.
[0115] Create a user private knowledge base, upload the collected MarkDown documents to the knowledge base of the Dify platform to generate vectors; or enter the document website address and directly obtain the vectors corresponding to each knowledge fragment from the website page. Among them, the user private knowledge base can be uploaded locally or a crawler model can be used to crawl the official documents of vue2 and vue3, etc.
[0116] Create a preset rule knowledge base, generate conversion rules based on the information searched above, and store the conversion rules in the preset rule knowledge base. Create an AI agent, configure the corresponding model, such as the DeepSeek Coder model, and set the knowledge base as the created user private knowledge base and preset conversion rule library for context retrieval. Set prompts to clarify its task objectives, work processes, resources, and limitations, etc. Create a server-side API for users to directly call the AI agent using the API for inference tasks, and after the task is completed, return the converted target code file.
[0117] In the VSCode extension plugin code, add a right-click menu button, click to call the server-side API created in step 4, obtain the returned result, and develop the display interface for Vue3 code. Publish the developed VSCode plugin to the plugin market.
[0118] Among them, the reasoning process of the AI agent can be as follows: in response to a code conversion request triggered by the user terminal for the code file to be converted, the code file to be converted is sliced into multiple code segments. Among them, the code conversion request is used to request to convert the code file to be converted in the current version into a code file in the target version specified by the user terminal. Then, retrieve the conversion rules matching each code segment from the preset conversion rule library, and retrieve the knowledge segments matching each code segment from the user's private knowledge library. Then, fill each code segment, the conversion rule matching each code segment, and the knowledge segment matching each code segment into the preset prompt template to generate the target prompt. Finally, input the target prompt and the code file to be converted into the code conversion model to obtain the target code file corresponding to the code file to be converted. Among them, under the guidance of the target prompt, the code conversion model identifies the code segment to be converted from multiple code segments, and rewrites the code segment to be converted based on the conversion rule matching the code segment to be converted and the knowledge segment matching the code segment to be converted, so as to generate the target code file corresponding to the code file to be converted based on the rewritten code segment.
[0119] As can be seen from the above description: using the Vue official documentation content as the knowledge base for DeepSeek Coder to perform context retrieval, DeepSeek Coder can perform code conversion more accurately. And when performing code conversion, semantics are considered, encoding is done according to specifications, combining deep learning technology and code analysis capabilities, accurately converting Vue2 code files to Vue3 code files.
[0120] In addition, the AI agent also has capabilities such as syntax checking, semantic logic error prompts, performance optimization, and code style optimization. And when the Vue3 syntax changes, only need to upload the latest official documentation (MarkDown format) to the user's private knowledge base. When the user wants to convert code, the AI agent can perform context retrieval based on the new user's private knowledge base, and the update operation is simple and convenient.
[0121] The code conversion device of one or more embodiments of the present application will be described in detail below. Those skilled in the art can understand that these devices can all be configured by using commercially available hardware components through the steps taught by this solution.
[0122] Figure 5 A code conversion device provided for an exemplary embodiment of the present application, as Figure 5 shown, the device includes: a slicing module 11, a first retrieval module 12, a second retrieval module 13, a generation module 14, and a processing module 15.
[0123] The splitting module 11 is configured to split the code file to be converted into multiple code segments in response to a code conversion request triggered by the client for the code file to be converted. The code conversion request is used to request to convert the code file to be converted in the current version into a code file in the target version specified by the client.
[0124] The first retrieval module 12 is configured to retrieve conversion rules matching each of the code segments from a preset conversion rule library.
[0125] The second retrieval module 13 is configured to retrieve knowledge segments matching each of the code segments from the user's private knowledge library.
[0126] The generation module 14 is configured to fill each of the code segments, the conversion rules matching each of the code segments, and the knowledge segments matching each of the code segments into a preset prompt template to generate a target prompt.
[0127] The processing module 15 is configured to input the target prompt and the code file to be converted into a code conversion model to obtain a target code file corresponding to the code file to be converted. Wherein, under the guidance of the target prompt, the code conversion model identifies code segments to be converted from the multiple code segments, and rewrites the code segments to be converted based on the conversion rules matching the code segments to be converted and the knowledge segments matching the code segments to be converted, so as to generate the target code file based on the rewritten code segments.
[0128] Optionally, the first retrieval module 12 is specifically configured to: for a target code segment, perform vectorization processing on the target code segment by using an embedding model to obtain a first vector representation corresponding to the target code segment, where the target code segment is any one of the multiple code segments; retrieve a second vector representation from a preset conversion rule library whose similarity with the first vector representation meets the requirements; and encode the second vector representation to obtain a first conversion rule corresponding to the target code segment.
[0129] Optionally, the device further includes a sorting module, and the sorting module is configured to: perform keyword recognition processing on the target code segment to obtain a target keyword corresponding to the target code segment; retrieve a second conversion rule that meets the similarity requirement with the target keyword from the preset conversion rule library; determine a first weight corresponding to the first conversion rule and a second weight corresponding to the second conversion rule, where the first weight is less than the second weight; based on the first weight and the second weight, sort the first conversion rule and the second conversion rule in descending order of relevance to the target code segment, so as to screen out a target conversion rule that is most relevant to the target code segment from the first conversion rule and the second conversion rule.
[0130] Optionally, the sorting module is specifically configured to: input the first weight, the second weight, the first conversion rule, and the second conversion rule into a pre-trained retrieval and sorting model to obtain a target conversion rule that is most relevant to the target code segment.
[0131] Optionally, the user private knowledge base includes a first knowledge base corresponding to the current version code, a second knowledge base corresponding to the target version code, and a third knowledge base for storing the change content of the target version code relative to the current version code; the second retrieval module 13 is specifically configured to: retrieve a third vector representation that meets the similarity requirement with the first vector representation from the first knowledge base; retrieve a fourth vector representation that meets the similarity requirement with the first vector representation from the second knowledge base; retrieve a fifth vector representation that meets the similarity requirement with the first vector representation from the third knowledge base; respectively encode the third vector representation, the fourth vector representation, and the fifth vector representation to obtain a first sub-knowledge segment corresponding to the third vector representation, a second sub-knowledge segment corresponding to the fourth vector representation, and a third sub-knowledge segment corresponding to the fifth vector representation; perform integration processing on the first sub-knowledge segment, the second sub-knowledge segment, and the third sub-knowledge segment to obtain a first knowledge segment that matches the target code segment.
[0132] Optionally, the device further includes a screening module, which is configured to: perform keyword recognition processing on the target code snippet to obtain target keywords corresponding to the target code snippet; retrieve a fourth sub-knowledge snippet that meets the similarity requirement with the target keywords from the first knowledge base; retrieve a fifth sub-knowledge snippet that meets the similarity requirement with the target keywords from the second knowledge base; retrieve a sixth sub-knowledge snippet that meets the similarity requirement with the target keywords from the third knowledge base; perform integration processing on the first sub-knowledge snippet, the second sub-knowledge snippet, and the third sub-knowledge snippet to obtain a second knowledge snippet that matches the target code snippet; determine a third weight corresponding to the first knowledge snippet and a fourth weight corresponding to the second knowledge snippet, where the third weight is less than the fourth weight; based on the third weight and the fourth weight, sort the first knowledge snippet and the second knowledge snippet in descending order of relevance to the target code snippet, so as to screen out the target knowledge snippet that is most relevant to the target code snippet from the first knowledge snippet and the second knowledge snippet.
[0133] Optionally, the current version is Vue2 version, and the target version is Vue3 version; the processing module 15 is specifically configured to: input the target prompt and the Vue2 version of the code file to be converted into a code conversion model to obtain a Vue3 version of the target code file corresponding to the Vue2 version of the code file to be converted; wherein, under the guidance of the target prompt, the code conversion model identifies the code snippet to be converted from multiple code snippets of the Vue2 version of the code file to be converted, and rewrites the Vue2 version of the code file to be converted based on the conversion rules and knowledge snippets that match the code snippet to be converted, so as to generate the Vue3 version of the target code file based on the rewritten code snippets.
[0134] Optionally, the device further includes an optimization module, which is configured to: send the target code file to the user; receive feedback information sent by the user for the target code file; generate optimization training data according to the feedback information, so as to optimize the code conversion model based on the optimization training data.
[0135] Figure 6 This is a schematic structural diagram of an electronic device provided by an embodiment of the present application. As Figure 6 shown, in practice, the electronic device includes: a memory 21 and a processor 22.
[0136] A memory 21 for storing computer programs and configurable to store various other data to support operations on the electronic device. Examples of such data include instructions for any application or method for operating on the electronic device, data structures, contact data, phone book data, messages, pictures, videos, etc.
[0137] A processor 22 coupled to the memory 21 for executing the computer programs in the memory 21 to implement the code conversion method provided by the foregoing embodiments.
[0138] Furthermore, as Figure 6 shown, the electronic device further includes: other components such as a communication component 23, a display 24, a power supply component 25, an audio component 26, etc. Figure 6 Only some components are schematically shown in the figure, which does not mean that the electronic device only includes Figure 6 the components shown in the figure. The electronic device of this embodiment can be implemented as a terminal device such as a desktop computer, a laptop computer, a smart phone, or an IOT device, or can also be a server device such as a conventional server, a cloud server, or a server array.
[0139] The above-mentioned memory 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 memory, flash memory, magnetic disk, or optical disk.
[0140] The above-mentioned communication component is configured to facilitate communication between the device where the communication component is located and other devices in a wired or wireless manner. The device where the communication component is located can access a wireless network based on a communication standard, such as a mobile communication network such as 2G, 3G, 4G / LTE, 5G, etc., or a combination thereof. In an exemplary embodiment, the communication component receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel.
[0141] The above-mentioned display 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 can be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of touch or swipe actions, but also detect the duration and pressure associated with the touch or swipe operations.
[0142] The above-mentioned power supply component provides power for 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 for the device where the power supply component is located.
[0143] The above-mentioned audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC), which is configured to receive external audio signals when the device where the audio component is located is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals can be further stored in the memory or transmitted via the communication component. In some embodiments, the audio component further includes a speaker for outputting audio signals.
[0144] Correspondingly, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to be able to implement the steps in the above-mentioned method embodiments.
[0145] Among them, the computer-readable storage medium can be implemented by a 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 (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of 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 technologies, Compact Disc Read-Only Memory (CD-ROM), Digital Video Disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices or any other non-transmission medium.
[0146] Accordingly, an embodiment of the present application further provides a computer program product, which includes a computer program or instruction. When the computer program or instruction is executed by a processor, it causes the processor to be able to implement each step in the above method embodiment.
[0147] It should be understood that each process or the 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 the processors of general-purpose computers, special-purpose computers, embedded processors or other programmable data processing devices, so that the processors of general-purpose computers, special-purpose computers, embedded processors or other programmable data processing devices can be used as devices to implement the corresponding functions in the above method embodiment.
[0148] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A code conversion method, characterized in that, Including: In response to a code conversion request triggered by a client for a code file to be converted, splitting the code file to be converted into multiple code segments, where the code conversion request is used to request to convert the code file to be converted in the current version into a code file in the target version specified by the client; Retrieving conversion rules matching each code segment from a preset conversion rule library; Retrieving knowledge segments matching each code segment from the user's private knowledge library; Filling each code segment, the conversion rule matching each code segment, and the knowledge segment matching each code segment into a preset prompt template to generate a target prompt; Inputting the target prompt and the code file to be converted into a code conversion model to obtain a target code file corresponding to the code file to be converted; wherein, under the guidance of the target prompt, the code conversion model identifies a code segment to be converted from the multiple code segments, and rewrites the code segment to be converted based on the conversion rule matching the code segment to be converted and the knowledge segment matching the code segment to be converted, so as to generate the target code file based on the rewritten code segment.
2. The method according to claim 1, wherein The retrieving conversion rules matching each code segment from a preset conversion rule library includes: For a target code segment, performing vectorization processing on the target code segment by using an embedding model to obtain a first vector representation corresponding to the target code segment, where the target code segment is any one of the multiple code segments; Retrieving a second vector representation with a similarity meeting the requirements from a preset conversion rule library; Encoding the second vector representation to obtain a first conversion rule corresponding to the target code segment.
3. The method according to claim 2, wherein The method further includes: Performing keyword recognition processing on the target code segment to obtain a target keyword corresponding to the target code segment; Retrieving a second conversion rule with a similarity meeting the requirements from the preset conversion rule library; Determining a first weight corresponding to the first conversion rule and a second weight corresponding to the second conversion rule, where the first weight is less than the second weight; Based on the first weight and the second weight, sorting the first conversion rule and the second conversion rule in descending order of relevance to the target code segment, so as to screen out a target conversion rule most relevant to the target code segment from the first conversion rule and the second conversion rule.
4. The method according to claim 3, wherein The sorting the first conversion rule and the second conversion rule in descending order of relevance to the target code segment based on the first weight and the second weight to screen out a target conversion rule most relevant to the target code segment from the first conversion rule and the second conversion rule includes: Inputting the first weight, the second weight, the first conversion rule, and the second conversion rule into a pre-trained retrieval and sorting model to obtain a target conversion rule most relevant to the target code segment.
5. The method according to claim 2, wherein, The user's private knowledge base includes a first knowledge base corresponding to the current version code, a second knowledge base corresponding to the target version code, and a third knowledge base for storing the change content of the target version code relative to the current version code; Retrieving, from the user's private knowledge base, knowledge fragments that match each code snippet includes: Retrieving a third vector representation from the first knowledge base that meets the requirement for similarity to the first vector representation; Retrieving a fourth vector representation from the second knowledge base that meets the requirement for similarity to the first vector representation; Retrieving a fifth vector representation from the third knowledge base that meets the requirement for similarity to the first vector representation; Encoding the third vector representation, the fourth vector representation, and the fifth vector representation respectively to obtain a first sub-knowledge fragment corresponding to the third vector representation, a second sub-knowledge fragment corresponding to the fourth vector representation, and a third sub-knowledge fragment corresponding to the fifth vector representation; Performing an integration process on the first sub-knowledge fragment, the second sub-knowledge fragment, and the third sub-knowledge fragment to obtain a first knowledge fragment that matches the target code snippet.
6. The method according to claim 5, wherein The method further includes: Performing keyword recognition processing on the target code snippet to obtain target keywords corresponding to the target code snippet; Retrieving a fourth sub-knowledge fragment from the first knowledge base that meets the requirement for similarity to the target keywords; Retrieving a fifth sub-knowledge fragment from the second knowledge base that meets the requirement for similarity to the target keywords; Retrieving a sixth sub-knowledge fragment from the third knowledge base that meets the requirement for similarity to the target keywords; Performing an integration process on the first sub-knowledge fragment, the second sub-knowledge fragment, and the third sub-knowledge fragment to obtain a second knowledge fragment that matches the target code snippet; Determining a third weight corresponding to the first knowledge fragment and a fourth weight corresponding to the second knowledge fragment, where the third weight is less than the fourth weight; Based on the third weight and the fourth weight, sorting the first knowledge fragment and the second knowledge fragment in descending order of relevance to the target code snippet to screen out the target knowledge fragment that is most relevant to the target code snippet from the first knowledge fragment and the second knowledge fragment.
7. The method according to claim 1, characterized in that, The current version is the Vue2 version, and the target version is the Vue3 version; Inputting the target prompt and the code file to be converted into the code conversion model to obtain a target code file corresponding to the code file to be converted includes: Inputting the target prompt and the code file to be converted in the Vue2 version into the code conversion model to obtain a target code file in the Vue3 version corresponding to the code file to be converted in the Vue2 version; Among them, under the guidance of the target prompt word, the code conversion model identifies the code snippets to be converted from multiple code snippets of the code file to be converted in the Vue2 version, and rewrites the code file to be converted in the Vue2 version based on the conversion rules matched with the code snippets to be converted and the knowledge snippets matched with the code snippets to be converted, so as to generate the target code file in the Vue3 version based on the rewritten code snippets.
8. The method according to claim 1, wherein The method further includes: Sending the target code file to the user; Receiving feedback information sent by the user for the target code file; Generating optimized training data according to the feedback information, so as to optimize the code conversion model based on the optimized training data.
9. An electronic device, characterized in that, Including: A memory and a processor; The memory is used to store a computer program; the processor is coupled to the memory and is used to execute the computer program to implement the steps in the code conversion method according to any one of claims 1-8.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, the processor is caused to implement the steps in the code conversion method according to any one of claims 1-8.
11. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, the processor is caused to implement the steps in the code conversion method according to any one of claims 1-8.
Citation Information
Cited By
Code transplantation method and device, computer equipment, storage medium and program product
CN122431719A
