Code generation method, model optimization method, system, medium and equipment
By building an end-to-end automated collaboration system and optimizing the code generation model using cloud servers and enterprise private knowledge bases, the problems of process fragmentation and insufficient quality in cross-platform code conversion have been solved, achieving efficient and accurate code generation and improved model adaptability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-18
- Publication Date
- 2026-03-10
AI Technical Summary
In enterprise-level development, cross-platform code conversion tasks involve complex collaborative chains with multiple stages. Existing technologies struggle to effectively utilize high-value feedback information for model optimization, resulting in insufficient code generation quality and adaptability. Furthermore, multi-platform collaborative development suffers from process fragmentation and efficiency bottlenecks.
Build an end-to-end automated collaboration system that automatically triggers code conversion, automated testing, and merging requests through cloud servers, provides real-time feedback of test results and review comments and tags to optimize the model, and leverages the enterprise's private knowledge base and dynamic update mechanism to improve code generation quality.
It eliminates the need for manual toolchain switching and manual process initiation, improves the efficiency of multi-terminal collaborative development, significantly enhances the accuracy of code generation and the applicability of private engineering, and continuously optimizes the model to meet the quality requirements of enterprise-level scenarios.
Smart Images

Figure CN121635897A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code generation method, a model optimization method, a system, a medium, and a device. Background Technology
[0002] With the rapid development of artificial intelligence, code generation tools based on large-scale natural language models have provided a new technical approach to solving the problem of repetitive code writing across multiple platforms during software development. These tools can automatically generate code based on user-provided prompts. However, in actual enterprise-level development processes, especially cross-platform code conversion tasks, it involves far more than a single code generation action; it is a complex collaborative chain with multiple stages. After completing the source code development for one platform (e.g., Android), engineers typically need to manually launch conversion tools to generate code for the target platform (e.g., iOS or Web). Subsequently, they also need to manually trigger automated testing and submit code review requests. This fragmented workflow, reliant on manual coordination, increases development and coordination costs. Summary of the Invention
[0003] To overcome the aforementioned problems in the prior art, this disclosure provides a code generation method, a model optimization method, a system, a medium, and a device. Specifically, this invention is achieved through the following technical solutions: According to a first aspect of the embodiments of this specification, a code generation method is provided, comprising: The program code to be converted and the target language type are obtained and sent to the cloud server, so that the cloud server can generate the target code based on the conversion model; A merge request is created based on the target code; the target code branch stores program code of the target language type. Automated tests are performed on the target code to obtain test result parameters; Obtain the review comment tags for the target code; The merge request is processed based on the review comment tags and test result parameters to obtain the merge processing result, and the program code of the target code branch after the merge processing is output; the merge processing result is to pass / reject the merge request.
[0004] Optionally, generating target code based on the transformation model includes: Based on the program code to be converted and the matching rules, a reference knowledge base is queried to determine several reference code segments; the matching rules are used to select several reference code segments from the reference knowledge base whose relevance to the program code to be converted meets preset conditions; The target code is obtained by inputting the reference code segments, the program code to be converted, and the preset prompt text into the conversion model.
[0005] Optionally, after obtaining the merging result, the process further includes: Obtain the template program code and divide the template program code into several semantically independent code blocks; Convert the aforementioned code blocks into several semantic vectors; The syntactic structure features of the code block are obtained through an abstract syntax tree; The semantic vector is fused with the syntactic structure features to obtain the code features of the code block; The code block and its code features are sent to a cloud server so that the cloud server updates the reference knowledge base.
[0006] According to a second aspect of the embodiments of this specification, a model optimization method is provided, comprising: The review comment tags, test result parameters, and merged processing results are obtained by the method described in the first aspect; The review comment tags, test result parameters, and merged processing results are sent to the cloud server so that the cloud server can adjust the conversion model based on the review comment tags, test result parameters, and merged processing results.
[0007] Optionally, adjusting the conversion model based on the reviewed comment tags, test result parameters, and merged processing results includes: A reward signal is generated based on the review comment tags, test result parameters, and merged processing results; The matching rules are adjusted based on the reward signal.
[0008] Optionally, adjusting the conversion model based on the reviewed comment tags, test result parameters, and merged processing results further includes: The conversion model is fine-tuned and trained based on the reward signal.
[0009] Optionally, generating a reward signal based on the reviewed comment tags, test result parameters, and merged processing results includes: Based on preset mapping rules, the review comment tags, test result parameters, and merged processing results are processed into quantified evaluation parameters, and a reward signal is generated based on the evaluation parameters.
[0010] According to a third aspect of the embodiments of this specification, a code generation system is provided, including a first server, a second server, and at least one client; the second server is a server deployed in the cloud. The client is used to send the program code to be converted and the target language type to the first server; The first server is used to send the received program code to be converted and the target language type to the second server; The second server is used to generate target code based on the conversion model and send it to the first server; The first server is further configured to send the target code to the client, create a merge request for the target code branch based on the target code, and perform automated tests on the target code to obtain test result parameters; the target code branch stores the program code of the target language type as a code branch storing the program code of the target language type. The client is also used to send review comment tags for the target code to the first server; The first server is further configured to process the merge request based on the review comment tags and test result parameters, obtain a merge processing result, and output the program code of the target code branch after the merge processing to the client; and send the review comment tags, test result parameters, and merge processing result to the second server; the merge processing result is to approve / reject the merge request; The second server is also used to adjust the conversion model based on the reviewed comment tags, test result parameters, and merged processing results.
[0011] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, wherein the storage medium stores a computer program that, when executed by a processor, implements the method described in the first aspect.
[0012] According to a fifth aspect of the embodiments of this specification, a computing device is provided, including a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program to implement the method described in the first aspect.
[0013] Based on the acquired program code to be converted and the target language type, the embodiments of this disclosure automatically trigger the cloud server to generate target code, create a merge request for the target code branch, execute automated tests and obtain test result parameters, and obtain review comment tags. This eliminates the need for manual toolchain switching and manual process initiation in the traditional model, and solves the efficiency bottleneck caused by process fragmentation in multi-terminal collaborative development.
[0014] This disclosure also uses the review comment tags, test result parameters, and merged processing results obtained in the above process as high-value data from a real production environment, which can drive the cloud server to adjust the conversion model, thereby improving the code generation quality in enterprise private application scenarios. Attached Figure Description
[0015] Figure 1 This is a flowchart illustrating a code generation method according to an embodiment of this disclosure; Figure 2 This is a flowchart illustrating the updating of a reference knowledge base as shown in an embodiment of this disclosure; Figure 3 This is a schematic diagram illustrating an application example of a code generation method and a model optimization method according to an embodiment of this disclosure; Figure 4 This is a structural diagram of an optimization apparatus for code generation shown in an embodiment of this disclosure; Figure 5 This is a structural diagram of a code generation system shown in an embodiment of this disclosure; Figure 6 This is a structural diagram of a computing device shown in an embodiment of the present disclosure. Detailed Implementation
[0016] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0017] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0018] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0019] In the software development field, multi-platform adaptation has become a common and critical requirement. Typical application scenarios include mobile applications needing to support operating systems such as iOS, Android, and HarmonyOS, and web applications needing to be compatible with diverse browser environments. In traditional development models, developers have to repeatedly write code with highly similar functional logic for each target platform. This significant duplication of effort not only consumes a great deal of human resources but also severely restricts the overall development efficiency of the team, leading to longer project cycles and leaving considerable room for optimization. While cross-platform development frameworks emerged to alleviate this problem, they often come with a high learning curve and unavoidable performance compromises. These inherent flaws limit their widespread application in large or performance-sensitive projects.
[0020] The rapid development of artificial intelligence technology, especially code generation tools based on large natural language models, has provided a new technical path to solve the problem of repetitive code writing across multiple platforms. These tools can automatically generate code based on user-provided prompts. However, in actual enterprise-level development processes, especially cross-platform code conversion tasks, it involves far more than a single code generation action; it is a complex collaborative chain with multiple stages. After completing the source code development for one platform (e.g., Android), engineers typically need to manually launch conversion tools to generate code for the target platform (e.g., iOS or Web). Subsequently, they also need to manually trigger automated testing and submit code review requests. This fragmented workflow, reliant on manual coordination, is particularly problematic in the rapid iteration of large-scale products. For example, when an application needs to launch a new payment function simultaneously on Android, iOS, and Web, three development teams need to independently implement essentially the same business logic using Java, Swift, and JavaScript, respectively. Although the core algorithms are completely identical, each team must independently complete the development, testing, and review processes for its respective platform. These fragmented operations not only significantly increase development and coordination costs but also make it easier for different platform versions to fail to launch synchronously due to disconnected workflows, causing product release delays.
[0021] Furthermore, existing widely used natural language processing models primarily rely on publicly available codebases for training, making it difficult for them to meet the stringent quality requirements of enterprise-level private development scenarios. Public datasets lack the representation of key knowledge such as enterprise-specific business logic, internally enforced coding standards, and legacy technical debt. This knowledge gap leads to model-generated code that, while syntactically correct, is prone to conflict with the enterprise's internal architectural design and practices, creating potential quality issues. For example, when a team used a general model to transform an inventory management module, the generated Swift code, while syntactically correct, ignored the mandatory calling standards of specific caching components within the enterprise, ultimately causing a serious data consistency failure on the iOS platform. More critically, under the existing model, high-value feedback information generated during the development, testing, and review processes of code transformation tasks—such as insufficient boundary condition coverage revealed by automated tests, potential design flaws pointed out by code reviews, and key business rules underlying merge decisions—is difficult to collect, structure, and feed back into the model optimization process efficiently. The inability to effectively recover and utilize these dynamic quality signals from real production environments has led to a bottleneck in the iterative optimization of models, which heavily relies on static public data and cannot continuously improve the code generation quality and adaptability in private and enterprise scenarios.
[0022] Against this backdrop, this solution constructs an end-to-end automated collaboration system. By integrating multi-platform code conversion, automated testing, and the creation of merge requests into the workflow, the entire process is automatically triggered upon submission of original code, eliminating manual configuration steps. Furthermore, dynamic data such as test result parameters output by automated testing, review comments and tags marked during the review process, and merge decision results are fed back to the cloud server in real time to optimize the model. These high-value signals from the real production environment drive the model to continuously learn the calling patterns of the enterprise's proprietary technology stack, the exception handling mechanisms of business modules, and the coding style approved by the team.
[0023] The principles of this disclosure will now be explained in detail with reference to several representative embodiments thereof.
[0024] Figure 1 This is a flowchart illustrating a code generation method according to an embodiment of the present disclosure, including: S100: Obtain the program code to be converted and the target language type and send them to the cloud server so that the cloud server can generate the target code based on the conversion model.
[0025] The method described in this embodiment can be applied to a server that implements a code version control service. This server is referred to as the first server in this specification. The first server can be a locally deployed server or a cloud-based server. The code version control service can be implemented using GitLab. For ease of description, the first server will be referred to as... Figure 1 The execution entity of the illustrated method flow is the first server. In this step, the first server obtains the program code to be converted and the target language type based on a pre-configured pipeline program, which can be a CI / CD script. When the developer pushes code commits to a specified branch through the development client, the pipeline program automatically captures the commit content and sends the code entity and target language parameters to the second server via an HTTPS request. It should be noted that this second server is a server deployed in the cloud. Using a second server deployed in the cloud allows for better computing performance at a lower cost, while also providing an interface for remote access and specifying code translation tasks. For ease of distinction, this specification will refer to the second server directly as the cloud server in the following text. After receiving the request, the cloud server activates the conversion model, ultimately generating target code that conforms to the target platform specifications and returning it to the pipeline.
[0026] The program code to be converted refers to the source code entity that needs cross-platform conversion; the target language type explicitly identifies the target technology stack, such as Swift for the iOS platform. These two types of data are transmitted to a cloud server through a standardized interface, activating the conversion model deployed in the cloud. The conversion model, which can be a trained natural language model, transforms the structure and semantics of the input code into an equivalent implementation in the target language type, outputting target code that conforms to the target technology stack specifications. It should be noted that for each piece of program code to be converted, the corresponding target language type can include one or more language types, such as Java for Android, Swift and Objective-C for iOS, ArkTS for HarmonyOS, and JS and HTML for Web platforms.
[0027] S102: Create a merge request for the target code branch based on the target code; the target code branch stores program code of the target language type.
[0028] After receiving the target code generated in the cloud, the pipeline matches the code repository's branch management strategy based on the target language type. This step automatically identifies the target language type and matches a preset code branch strategy. A target code branch is an isolated branch specifically designed to store program code for a particular language type. For example, a separate branch can be set up for each language type's code generation task; alternatively, multiple branches can be set up for each language type's code generation task, with the target code branch being one selected from these multiple branches before executing the embodiments described in this specification.
[0029] Then, a merge request is created for that branch, which is a formal proposal to merge code into the target code branch. A merge request is a request to integrate the generated target code into the target code branch of the code repository. If the request is approved, the target code becomes part of the program code stored in the target code branch, thereby achieving functional synchronization and version unification of the code under that language type.
[0030] For example, after the target code is generated, it is first temporarily stored in a pre-defined development branch. This development branch is used to integrate new features developed by various teams, including the new features implemented by the target code. In contrast to this development branch, the target code branch is the main branch of the runnable, official product code. The generated target code is isolated in a separate development branch and will not affect the stability of the target code branch. In subsequent processes, automated testing and review comments can be performed on the target code based on this development branch.
[0031] This process enables the generated code to automatically enter the review queue, and the generated target code is temporarily stored in an independent development branch. There is no need for manual branch selection and request initialization, and the merge request status is synchronized to the project collaboration visualization interface in real time.
[0032] S104: Perform automated testing on the target code and obtain test result parameters.
[0033] The merge request creation event in step S102 triggers the pipeline to start the test task. The pipeline invokes the pre-integrated test framework to execute automated tests on the codebase of the target code branch. Automated tests may include compilation checks and unit tests, covering quantitative scores in dimensions such as syntax verification, functional logic, and performance benchmarks. Test result parameters refer to the set of quantitative indicators generated by this test run, including but not limited to performance throughput, memory usage, and the number of exceptions triggered. The pipeline archives the test result parameters and associates them with the merge request's pipeline report interface, thereby objectively reflecting the behavioral characteristics of the target code in the target platform environment and constituting the core basis for code quality assessment.
[0034] S106: Obtain the review comment tags for the target code.
[0035] The creation event of the merge request in step S102 triggers the pipeline to push the review request to the preset review client. Review comment tags are generated by the preset review client, which can be the development client from step S100 or another independent client. For example, the review comment tags are those selected by the developer from a predefined category library (such as "memory leak" or "concurrency defect"), captured by the pipeline and stored in a structured manner.
[0036] S108: Process the merge request based on the review comment tags and test result parameters to obtain the merge processing result, and output the program code of the target code branch after the merge processing; the merge processing result is to pass / reject the merge request.
[0037] The pipeline integrates a decision engine. After generating test result parameters for the target code and listening for submission events of review comment tags, the decision engine synchronously analyzes the test result parameters and review comment tags to process the merge request. Based on pre-configured merge rules, the decision engine, for example, outputs a rejected merge result if the test result parameters are below a quality threshold or if a high-risk review comment tag (such as "[security vulnerability]") exists; otherwise, it triggers automatic merging. For example, the decision result can update the request status via the GitLab Merge Request API, and automatically generate a blocking reason report upon rejection.
[0038] Accordingly, based on the acquired program code to be converted and the target language type, this embodiment of the disclosure automatically triggers the cloud server to generate target code, creates a merge request for the target code branch, executes automated tests and obtains test result parameters, and obtains review comment tags. This eliminates the need for manual toolchain switching and manual process initiation in the traditional model, and solves the efficiency bottleneck caused by process fragmentation in multi-terminal collaborative development.
[0039] During enterprise development, proprietary internal technical specifications (such as security encryption standards), business logic (such as order risk control rules), and platform adaptation experience continuously evolve, but this knowledge is not incorporated into the publicly available training data of the conversion model. To optimize the proprietary performance of the conversion model, a cloud server stores a reference knowledge base required for code generation. In some embodiments of this disclosure, target code is generated based on the conversion model, including: Based on the program code to be converted and the matching rules, a reference knowledge base is queried to determine several reference code segments; wherein, the matching rules are used to select several reference code segments from the reference knowledge base whose relevance to the program code to be converted meets preset conditions.
[0040] The target code is obtained by inputting the reference code segments, the program code to be converted, and the preset prompt text into the conversion model.
[0041] First, the cloud server queries the reference knowledge base based on the program code to be converted and preset matching rules, selecting several highly relevant reference code segments. The reference knowledge base is a dynamically updated structured storage system that not only contains general code snippets but, more importantly, integrates the historical implementation of the enterprise's proprietary technology stack, internal coding standards, and high-frequency business logic templates. The matching rules play a filtering role here, quantitatively calculating the semantic and syntactic similarity between the code to be converted and the knowledge base entries. This allows for the precise extraction of reference code from massive amounts of data that meets preset relevance criteria for the current conversion task, providing crucial technical context support for the conversion model.
[0042] In one embodiment, querying a reference knowledge base based on the program code to be converted and the matching rules may include the following steps: The semantic vector and syntactic structure features of the code to be converted are analyzed to generate the code features of the code to be converted; The code features of the code to be converted are compared with the code features of the reference code in the reference knowledge base to obtain a similarity score. For example, the similarity score can be calculated by multiplying the similarity between the code features of each code to be converted and the code features of the reference code by the corresponding preset feature weight and summing the results.
[0043] Based on the removal of reference codes with similarity scores below the preset similarity threshold, the optimal number of reference code segments are then selected according to the reference quantity threshold (e.g., if the reference quantity threshold is set to 5, only the top 5 results with higher similarity thresholds are retained).
[0044] Then, the cloud server automatically executes the conversion model by inputting several selected reference code segments, the program code to be converted, and pre-set prompt text. The pre-set prompt text is an engineered guidance instruction that clearly constrains the target language type, architectural specifications, and quality requirements. The conversion model integrates multi-source input information: the code to be converted carries the core business logic, the reference code injects platform adaptation experience and technical constraints, and the prompt text directs and standardizes the output format and style. By deeply understanding the relationship between these three elements, the model generates target code that conforms to the target platform's technical specifications based on semantic alignment and structural mapping.
[0045] This disclosure addresses the problem that general code generation models are difficult to adapt to private technology ecosystems and that cross-platform collaboration suffers from severe process breaks. It queries a reference knowledge base based on the program code to be converted and matching rules, and uses the obtained reference code to generate target code, which can significantly improve the accuracy of the generated code and its applicability to private engineering.
[0046] Based on the aforementioned embodiments, previously verified high-quality code implementations were only stored in scattered code repositories and could not be directly and effectively absorbed by the reference knowledge base. Therefore, this solution further constructs a dynamic update mechanism for the reference knowledge base after processing the merge request. This mechanism continuously enriches the technical assets of the cloud-based reference knowledge base through intelligent code feature extraction and structured storage. In some embodiments of this disclosure, after obtaining the merge processing result, the reference knowledge base is also updated. Figure 2 This is a flowchart illustrating an embodiment of the present disclosure of an updated reference knowledge base, including: S200: Obtain template program code and divide the template program code into several semantically independent code blocks. The pipeline program of this embodiment is further configured to listen for submission events of the template program code, and trigger the optimization process of the reference knowledge base in response to the submission event. This step obtains newly submitted template program code and divides it into several semantically independent code blocks. The template program code can be target code that has passed review and meets quality standards, or it can be actively configured program code that is highly relevant to the target code. Dividing the template program code into several semantically independent code blocks is based on code logic boundaries, for example, treating class definitions, independent functions, or complete algorithm modules as independent units, ensuring that each code block carries a clear technical intent.
[0047] S201: Convert the code blocks into semantic vectors. A pre-trained code model is used to convert the code blocks into high-dimensional semantic vectors. These semantic vectors deeply encode the functional semantics of the code, such as the functional semantics of a code block being "thread-safe queue implementation" or "database transaction rollback logic," capturing business intent expressions that go beyond the surface syntax.
[0048] S202: Obtain the syntactic structure features of the code block through an abstract syntax tree. Extract the syntactic structure features of the code block by constructing an abstract syntax tree (AST), and record rigid constraints such as control flow nodes, data type declarations, and API call relationships.
[0049] S203: The semantic vector is fused with the syntactic structure features to obtain the code features of the code block. This step fuses the obtained semantic vector with the syntactic structure features to generate composite code features of the code block—containing both an abstract expression of functional semantics and retaining the precise framework of technical implementation.
[0050] S204: The code block and its code features are sent to the cloud server to update the reference knowledge base. After the code features are extracted, the pipeline program sends the code block and its corresponding code features to the cloud server. Upon receiving the data, the cloud server performs an update operation on the reference knowledge base. For example, the update operation of the reference knowledge base may include building a feature index, specifically storing the code features as retrieval keys in a vector database to establish a multi-dimensional index structure. The index design supports efficient similarity queries; for example, when new input code is to be converted, reference entries with similar functional semantics and syntactic patterns can be quickly located.
[0051] It is understood that the above steps S200-S204 can also be performed during the initial construction phase of the reference knowledge base, and this manual will not elaborate on this process.
[0052] This disclosure transforms template program code into reusable knowledge assets, upgrading the reference knowledge base from a static archive to a dynamically growing enterprise technology hub, providing continuously enhanced domain knowledge support for cross-platform code conversion.
[0053] After completing the output of the program code of the target code branch after the merging process, in order to effectively utilize the program code and quality feedback information generated in the real production environment through the above methods, and improve the code generation quality and adaptability of the conversion model in private and enterprise scenarios, this disclosure proposes a model optimization method.
[0054] The model optimization method proposed in this disclosure includes the following steps: The review comment tags, test result parameters, and merged processing results are obtained using the code generation method described above.
[0055] The review comment tags, test result parameters, and merged processing results are sent to the cloud server so that the cloud server can adjust the conversion model based on the review comment tags, test result parameters, and merged processing results.
[0056] Continuing with the aforementioned pipeline explanation, the final stage of the pipeline calls the feedback transmission module, which encapsulates the review comment tags, test result parameters, and merged processing results. This data is then pushed to the model optimization interface on the cloud server. Specifically, the review comment tags pinpoint defect patterns in the generated code, the test result parameters reveal runtime bottlenecks, and the merged processing results verify the final usability of the generated code. The cloud service parses the data received from the model optimization interface and performs model adjustments, specifically optimizing the model output for high-frequency defect scenarios, ensuring the model continuously adapts to the quality requirements of the actual development environment.
[0057] Accordingly, the model optimization method provided in this disclosure uses the obtained review comment tags, test result parameters, and merged processing results as high-value data from a real production environment, which can effectively drive the cloud server to adjust the conversion model, thereby improving the code generation quality in enterprise private application scenarios.
[0058] For example, the following is combined with Figure 3 This document illustrates the application examples of code generation and model optimization methods. A developer writes Java code for the Android platform. Using the methods provided in the embodiments of this document, the conversion model can automatically translate this code into code in other languages, then automatically execute tests, receive review results, process merge requests, and optimize the model. Figure 3 This is a schematic diagram illustrating an application example of the code generation method and model optimization method shown in the embodiments of this disclosure. The execution flow of the above application example includes: The client submits the program code to be converted and the target language type to the first server. The developers push the functional module code of the Android platform (written in Java) to the android-control branch managed by the first server, and indicate the target language type [iOS-Swift, Web-JS] in the commit message.
[0059] The first server sends the program code to be converted and the target language type to the cloud server. The GitLab CI / CD pipeline listens for this commit through a pre-configured event triggering mechanism, automatically extracts the code file and target language type, and calls the preset API to send the extracted data to the cloud server.
[0060] The cloud server generates target code based on the conversion model and sends it to the first server. After receiving the request, the cloud server generates model input based on the received data and a preset template, thereby driving the conversion model to perform the code conversion function.
[0061] The first server creates a merge request for the target code branch based on the target code and executes automated tests on the target code to obtain test result parameters. The Swift and JavaScript code generated by the cloud server are automatically pushed to pre-defined independent branches in the GitLab repository. Prior to this, this method pre-defines at least one code branch for each language type to manage the output of the conversion model, ensuring isolated management of code changes across multiple platforms. For example, Swift code is stored in the `ios-Swift-auto-translate` branch, and JavaScript code is stored in the `web-JS-auto-translate` branch. After receiving the target code from the cloud server, a merge request is created for each language type's corresponding code branch. This merge request can be automatically associated with the event number of the original Android commit and the code blocks generated by the conversion model are marked in the Diff view, ensuring traceability of changes across multiple platforms.
[0062] The GitLab pipeline initiates automated test jobs on the target code branch. For Swift target code generated in the cloud, the pipeline calls the Xcode build toolchain to perform compilation checks and verify syntax compatibility; simultaneously, it runs unit test suites to cover and verify core functional logic. For JavaScript target code, the pipeline performs DOM manipulation tests via Headless Chrome to detect browser compatibility issues. Quantitative metrics generated during the testing process (such as code coverage, peak memory usage, and request latency) are collected in a structured manner as test result parameters and archived in the pipeline artifact repository in JUnit report format.
[0063] The client receives the target code sent by the first server and returns review comment tags for the target code. When reviewing the target code in the GitLab merge request interface, the reviewer marks code defects using the built-in tagging system. When an algorithm logic error is found, the "Logic Error" tag is selected from the preset tag library and associated with the specific line of code; when improper resource release is detected, the "Resource Leak" tag is added. The pipeline captures these review comment tags in real time via the GitLab Notes API, parses the tag type and severity level, and constructs a machine-readable quality feedback dataset.
[0064] The first server processes the merge request based on the review comment tags and test result parameters, obtaining the merge result. The pipeline-integrated decision engine synchronously analyzes the test result parameters and review comment tags. The engine loads pre-configured rules: if the test result parameters do not meet the standards, or if there are high-risk review comment tags related to security vulnerabilities, a rejection merge result is output; if there are no dangerous tags or only low-risk tags related to code style, and all test parameters meet the standards, an automatic merge is triggered. The decision result updates the request status via the GitLab MR status API, automatically generating a report containing blocking entries upon rejection.
[0065] The first server sends the review comment tags, test result parameters, and merged processing results to the cloud server, which then adjusts the transformation model. After these steps are completed, the pipeline can extract the complete quality dataset, including the review comment tags and associated code context, test result parameters, and merged processing results. Then, the data package is pushed to the model optimization interface on the cloud server to optimize the model output.
[0066] When the matching rules of the reference knowledge base fail to accurately filter high-value enterprise-level code snippets, the target code generated by the model is prone to conflicts with the private technology stack (such as ignoring internal caching specifications and causing data consistency failures), which significantly restricts the accuracy of code generation and its engineering applicability.
[0067] In some embodiments of this disclosure, the conversion model is adjusted based on the review comment tags, test result parameters, and merged processing results, including: A reward signal is generated based on the review comment tags, test result parameters, and merged processing results. Upon receiving these data, the cloud server first integrates them into a quantifiable reward signal. The review comment tags directly reflect the defect patterns identified by manual reviewers, the test result parameters objectively expose runtime bottlenecks in the generated code, and the merged processing results comprehensively reflect the final usability of the code. These three types of data together constitute a multi-dimensional quality assessment system. The core of the reward signal is to transform discrete quality feedback data into continuous numerical signals. For example, high-risk review tags (such as security vulnerabilities) correspond to strong negative penalties, achieving test coverage targets provides positive incentives, and the merged processing results further amplify the positive reward weight. Essentially, this signal is a quantitative score of the generated code's overall performance in a real-world enterprise scenario.
[0068] In one embodiment, the reward signal is generated through a reward model. When the code generation system needs optimization, a key obstacle lies in the fact that review comment tags, test result parameters, and merge processing results are three different forms of feedback. Review comment tags such as memory leaks annotated by engineers cannot be directly compared to millisecond-level latency data in performance tests, while the business rules implied by merge rejections are difficult to quantify. This multi-source heterogeneous feedback is difficult for machines to understand directly, resulting in a lack of clear direction for model optimization. Based on this, the reward model in this embodiment stores preset mapping rules, processes review comment tags, test result parameters, and merge processing results into quantified evaluation parameters based on these rules, and generates a reward signal based on these evaluation parameters. For example, review comment tags are graded by severity and assigned corresponding scores; high-risk tags such as memory leaks are assigned high negative scores. Furthermore, for different indicator types of test result parameters, normalized scores corresponding to their actual parameter values are set.
[0069] The matching rules are adjusted based on the reward signal. Based on this reward signal, the cloud server optimizes the matching rules of the reference knowledge base. The matching rules are used to retrieve reference fragments from the knowledge base that are semantically related to the code to be converted, and their parameters directly determine the knowledge quality of the input model. The optimization process dynamically adjusts the parameters of the matching rules through the reward signal.
[0070] Based on the aforementioned embodiment of querying the reference knowledge base based on the program code to be converted and the matching rules in this specification, the parameters of the matching rules include a similarity threshold, feature weights, and a reference quantity threshold. For example, in the process of adjusting the matching rules based on the reward signal, if the reward signal indicates that a certain type of reference code is associated with high-quality output (e.g., fewer review tags, better test parameters, and successful merging), then the retrieval feature weight of this type of code is increased; conversely, for reference code categories that frequently trigger negative rewards (e.g., code involving specific internal components), the feature weight is decreased. If the reward signal is consistently a high positive value, indicating that the generated target code is superior, then the similarity threshold is increased or the reference quantity threshold is decreased to force higher matching accuracy and avoid introducing irrelevant code; conversely, the similarity threshold is decreased or the reference quantity threshold is increased to expand the search scope.
[0071] The embodiments in this specification drive the retrieval logic of the reference knowledge base to continuously adapt to the changing trends of the enterprise's proprietary technology stack, ensuring that subsequent code generation tasks prioritize the recall of high-value reference code snippets that conform to the specifications.
[0072] When the code generated by the conversion model exhibits deep logical flaws in cross-platform conversion scenarios, simply adjusting the matching rules of the reference knowledge base is insufficient to eliminate the cognitive biases inherent in the conversion model itself. This problem stems from the fact that the model weights do not encode enterprise-specific technical constraints, and traditional fine-tuning relies on static datasets, failing to absorb high-value feedback generated in real-time in the production environment, such as audit conclusions, test metrics, and merging decisions. This causes model iteration to lag behind actual quality requirements.
[0073] In some embodiments of this disclosure, adjusting the conversion model based on the reviewed comment tags, test result parameters, and merged processing results further includes: The conversion model is fine-tuned and trained based on the reward signal.
[0074] To address the aforementioned bottlenecks, this solution introduces a model fine-tuning training mechanism based on the aforementioned reward signal. In practice, the pipeline program stores each acquired program code to be converted, its corresponding target code, and the reward signal as task samples. When model fine-tuning training is required, task samples from historical conversion tasks are extracted as the training dataset for model fine-tuning, and this training dataset is sent to the cloud server, enabling the cloud server to fine-tune the conversion model based on the training dataset.
[0075] Corresponding to the aforementioned code generation method embodiments, this application also provides an embodiment of an optimization apparatus for code generation.
[0076] Figure 4 This is a structural diagram of an optimization apparatus for code generation shown in an embodiment of this disclosure, comprising: The acquisition module 401 is used to acquire the program code to be converted and the target language type and send them to the cloud server, so that the cloud server generates the target code based on the conversion model; and to acquire the review comment tags for the target code; Test module 402 is used to perform automated tests on the target code and obtain test result parameters; The branch management module 402 is used to create a merge request for a target code branch based on the target code, and to process the merge request based on the review comment tags and test result parameters to obtain a merge processing result; the merge processing result is to approve / reject the merge request; the target code branch is a code branch that stores program code of the target language type; Feedback module 402 is used to send the review comment tags, test result parameters and merged processing results to the cloud server, so that the cloud server can adjust the conversion model based on the review comment tags, test result parameters and merged processing results.
[0077] In one embodiment, the cloud server is configured to query the reference knowledge base based on the program code to be converted and matching rules to determine several reference code segments; and to input the several reference code segments, the program code to be converted, and a preset prompt text into the conversion model to obtain the target code. The matching rules are used to select several reference code segments from the reference knowledge base whose relevance to the program code to be converted meets preset conditions.
[0078] In one embodiment, the cloud server is further configured to generate a reward signal based on the review comment tags, test result parameters, and merged processing results; and to adjust the matching rules based on the reward signal.
[0079] In one embodiment, the cloud server is further configured to perform model fine-tuning training on the conversion model based on the reward signal.
[0080] In one embodiment, the cloud server is further configured to process the review comment tags, test result parameters, and merged processing results into quantified evaluation parameters based on preset mapping rules, and generate a reward signal based on the evaluation parameters.
[0081] In one embodiment, the optimization apparatus for code generation further includes a knowledge base configuration module, used for: Obtain the template program code and divide the template program code into several semantically independent code blocks; Convert the aforementioned code blocks into several semantic vectors; The syntactic structure features of the code block are obtained through an abstract syntax tree; The semantic vector is fused with the syntactic structure features to obtain the code features of the code block; The code block and its code features are sent to a cloud server so that the cloud server updates the reference knowledge base.
[0082] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0083] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0084] Figure 5 This is a multi-terminal interaction diagram of a code generation system shown in an embodiment of the present disclosure. The system includes a first server 501, a second server 502, and at least one client 503; the second server 502 is a server deployed in the cloud.
[0085] The client 503 is used to send the program code to be converted and the target language type to the first server 501; The first server 501 is used to send the received program code to be converted and the target language type to the second server 502; The second server 502 is used to generate target code based on the conversion model and send it to the first server 501; The first server 501 is further configured to send the target code to the client 503, create a merge request for the target code branch based on the target code, and perform automated tests on the target code to obtain test result parameters; the target code branch stores program code of the target language type; The client 503 is also used to send review comment tags for the target code to the first server 501; The first server 501 is further configured to process the merge request based on the review comment tags and test result parameters, obtain a merge processing result, output the program code of the target code branch after the merge processing to the client 503; and send the review comment tags, test result parameters, and merge processing result to the cloud server; the merge processing result is to approve / reject the merge request; The second server 502 is also used to adjust the conversion model based on the review comment tags, test result parameters, and merged processing results.
[0086] This disclosure also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the methods of any embodiment of this disclosure. The computer-readable medium includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology for information storage. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change 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), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient media, such as modulated data signals and carrier waves.
[0087] This disclosure also provides a computing device, including a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program to implement the method of any embodiment of this disclosure.
[0088] Figure 6 This is a schematic diagram illustrating the structure of a computing device according to an embodiment of this disclosure. Embodiments of the computing device of this application can be applied to a server. At the hardware level, the computing device includes a processor, an internal bus, a network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to implement the method of any embodiment of this disclosure. Of course, besides software implementations, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution entity of the following processing flow is not limited to individual logic units, but can also be hardware or logic devices.
[0089] The embodiments of the subject matter and functional operation described in this specification can be implemented in the following ways: digital electronic circuits, tangibly embodied computer software or firmware, computer hardware including the structures disclosed in this specification and their structural equivalents, or combinations thereof. Embodiments of the subject matter described in this specification can be implemented as one or more computer programs, i.e., one or more modules of computer program instructions encoded on a tangible, non-transitory program carrier for execution by a data processing apparatus or for controlling the operation of a data processing apparatus. Alternatively or additionally, the program instructions may be encoded on artificially generated propagation signals, such as machine-generated electrical, optical, or electromagnetic signals, which are generated to encode information and transmit it to a suitable receiving device for execution by the data processing apparatus. The computer storage medium may be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or combinations thereof.
[0090] The processing and logic described in this specification can be executed by one or more programmable computers that execute one or more computer programs to perform corresponding functions by operating on input data and generating output.
[0091] Suitable computers for executing computer programs include, for example, general-purpose and / or special-purpose microprocessors, or any other type of central processing unit. Typically, the central processing unit receives instructions and data from read-only memory and / or random access memory. The basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data. Typically, a computer will also include one or more mass storage devices for storing data, such as disks, magneto-optical disks, or optical disks, or the computer will be operatively coupled to such mass storage devices to receive data from or transfer data to them, or both. However, a computer is not required to have such devices. Furthermore, a computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, to name a few.
[0092] Computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media, and memory devices, such as semiconductor memory devices (e.g., EPROM, EEPROM, and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and CD-ROM and DVD-ROM disks. Processors and memory may be supplemented by or incorporated into dedicated logic circuitry.
[0093] While this specification contains numerous specific implementation details, these should not be construed as limiting the scope of any invention or the scope of the claims, but rather are primarily intended to describe features of specific embodiments of a particular invention. Certain features described in the various embodiments herein may also be implemented in combination in a single embodiment. Conversely, various features described in a single embodiment may also be implemented separately in various embodiments or in any suitable sub-combination. Furthermore, while features may function in certain combinations as described above and even initially claimed in this way, one or more features from a claimed combination may be removed from that combination in some cases, and a claimed combination may refer to a sub-combination or a variation thereof.
[0094] Similarly, although the operations are depicted in a specific order in the accompanying drawings, this should not be construed as requiring these operations to be performed in the specific order shown or sequentially, or requiring all illustrated operations to be performed to achieve the desired result. In some cases, multitasking and parallel processing may be advantageous. Furthermore, the separation of various system modules and components in the above embodiments should not be construed as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product or packaged into multiple software products.
[0095] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recited in the claims may be performed in a different order and still achieve the desired result. Furthermore, the processes depicted in the drawings are not necessarily shown in a specific order or sequence to achieve the desired result. In some implementations, multitasking and parallel processing may be advantageous.
[0096] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A code generation method characterized by, The method comprises the following steps: acquiring program code to be converted and a target language type and sending them to a cloud server, so that the cloud server generates target code based on a conversion model; creating a merge request for a target code branch based on the target code; the target code branch stores program code in the target language type; performing automated testing on the target code to obtain test result parameters; acquiring review comment labels for the target code; processing the merge request based on the review comment labels and the test result parameters to obtain a merge processing result, and outputting program code of the target code branch after the merge processing; the merge processing result is to pass or reject the merge request.
2. The code generation method of claim 1, wherein, The method of generating target code based on a conversion model comprises the following steps: querying a reference knowledge base based on the program code to be converted and a matching rule to determine a plurality of reference codes; the matching rule is used to select a plurality of reference codes from the reference knowledge base that meet a predetermined condition in terms of relevance to the program code to be converted; inputting the plurality of reference codes, the program code to be converted and a preset prompt text into the conversion model to obtain the target code.
3. The code generation method of claim 2, wherein, After obtaining the merge processing result, the method further comprises the following steps: segmenting a template program code into a plurality of code blocks that are semantically independent; converting the plurality of code blocks into a plurality of semantic vectors; obtaining the syntax structure features of the code blocks through an abstract syntax tree; fusing the semantic vectors and the syntax structure features to obtain the code features of the code blocks; sending the code blocks and the code features of the code blocks to the cloud server to enable the cloud server to update the reference knowledge base.
4. A model optimization method characterized by, The method comprises the following steps: acquiring review comment labels, test result parameters and merge processing results by the method of any one of claims 1-3; sending the review comment labels, test result parameters and merge processing results to the cloud server, so that the cloud server adjusts the conversion model based on the review comment labels, test result parameters and merge processing results.
5. The model optimization method of claim 4, wherein, The method of adjusting the conversion model based on the review comment labels, test result parameters and merge processing results comprises the following steps: generating a reward signal based on the review comment labels, test result parameters and merge processing results; adjusting the matching rule based on the reward signal.
6. The model optimization method of claim 5, wherein, The method of adjusting the conversion model based on the review comment labels, test result parameters and merge processing results further comprises the following steps: performing model fine-tuning training on the conversion model based on the reward signal.
7. The model optimization method of claim 5, wherein, The method of generating a reward signal based on the review comment labels, test result parameters and merge processing results comprises the following steps: processing the review comment labels, test result parameters and merge processing results into quantitative evaluation parameters based on a preset mapping rule, and generating a reward signal based on the evaluation parameters.
8. A code generation system characterized by, The method comprises a first server, a second server and at least one client; the second server is a server deployed in the cloud; the client is configured to send program code to be converted and a target language type to the first server; The first server is configured to send the received program code to be converted and a target language type to a second server; The second server is configured to generate target code based on a conversion model and send the target code to the first server; The first server is further configured to send the target code to a client, create a merge request for a target code branch based on the target code, and perform automated testing on the target code to obtain a test result parameter; The target code branch stores program code of the target language type; The client is further configured to send an audit comment label for the target code to the first server; The first server is further configured to process the merge request based on the audit comment label and the test result parameter to obtain a merge processing result, output the program code of the target code branch after the merge processing to the client, and send the audit comment label, the test result parameter, and the merge processing result to the second server; the merge processing result is pass or reject of the merge request; The second server is further configured to adjust the conversion model based on the audit comment label, the test result parameter, and the merge processing result. The storage medium stores a computer program, and the computer program is executed by a processor to implement the method in any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that, A device includes a memory and a processor; the memory is configured to store a computer program; and the processor is configured to execute the computer program to implement the method in any one of claims 1 to 7.
10. A computing device, comprising: