Backend computer program generation method and apparatus
Patent Information
- Application Number
- CN202610746325.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-27
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2046-05-27
AI Technical Summary
[0005]本申请提供了一种后端计算机程序生成方法及装置,以至少解决相关技术中,大语言模型生成代码时的接口定义规范性较差,缺乏数据校验机制,且数据库交互的安全性和效率较低,无法有效进行异常处理操作,极大影响所生成代码的质量和复用性的技术问题
[0011]通过本申请,可以确定目标用户的自然语言程序需求对应的模型接口约束,以确定模型接口约束对应的项目上下文;结合模型接口约束和项目上下文,构造自然语言程序需求对应的增强提示词,并根据增强提示词生成对应的初始计算机程序;基于模型接口约束,构建对应的多维度质量检测机制,并通过多维度质量检测机制对初始计算机程序执行预设自动化质量检测操作,以得到初始计算机程序的质量检测结果,且响应于质量检测结果满足预设计算机程序异常条件的情况下,根据质量检测结果对初始计算机程序迭代执行预设修正操作,直至迭代过程满足预设迭代终止条件,生成满足自然语言程序需求的目标后端计算机程序,因此,可以解决相关技术中,大语言模型生成代码时的接口定义规范性较差,缺乏数据校验机制,且数据库交互的安全性和效率较低,无法有效进行异常处理操作,极大影响所生成代码的质量和复用性的技术问题,达到了通过构建多层级的上下文约束与自动化质量检测,有力保障了所生成的代码在数据库交互、数据验证、代码复用、代码检测及异常处理方面能够很好地符合企业级质量标准,提高了生成代码的可靠性和实用性的技术效果。
Smart Images

Figure CN122284967B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of automated programming technology, and in particular to a method and apparatus for generating backend computer programs. Background Technology
[0002] The application of Large Language Models (LLMs) in code generation is evolving from simple code completion to functional implementation. However, the code generated by LLMs often fails to meet real-world usage needs.
[0003] Currently, in related technologies, developers can directly input code requirements into a general large model, and the model returns code snippets in free format. Based on the database table structure or form configuration, basic CRUD (Create, Read, Update, Delete) code can be generated through pre-set templates. Furthermore, related technologies allow developers to add comments or input simple commands in an IDE (Integrated Development Environment) to generate local functions or code blocks.
[0004] However, the interface definition of large language models in related technologies is poorly standardized, lacks data verification mechanisms, and has low security and efficiency in database interaction, making it impossible to effectively handle exceptions. This greatly affects the quality and reusability of the generated code, and urgently needs to be addressed. Summary of the Invention
[0005] This application provides a backend computer program generation method and apparatus to at least solve the technical problems in related technologies, such as poor interface definition standardization, lack of data verification mechanism, low security and efficiency of database interaction, inability to effectively perform exception handling operations, which greatly affect the quality and reusability of the generated code.
[0006] This application provides a backend computer program generation method, comprising the following steps: determining the model interface constraints corresponding to the natural language program requirements of a target user, and determining the project context corresponding to the model interface constraints; combining the model interface constraints and the project context, constructing enhanced prompt words corresponding to the natural language program requirements, and generating a corresponding initial computer program based on the enhanced prompt words; constructing a corresponding multi-dimensional quality detection mechanism based on the model interface constraints, and performing a preset automated quality detection operation on the initial computer program through the multi-dimensional quality detection mechanism to obtain the quality detection result of the initial computer program, and in response to the quality detection result meeting a preset computer program abnormality condition, iteratively performing a preset correction operation on the initial computer program based on the quality detection result until the iteration process meets a preset iteration termination condition, thereby generating a target backend computer program that meets the natural language program requirements.
[0007] This application also provides a backend computer program generation apparatus, comprising: a constraint determination module, configured to determine model interface constraints corresponding to the natural language program requirements of a target user, thereby determining the project context corresponding to the model interface constraints; a program generation module, configured to combine the model interface constraints and the project context to construct enhanced prompt words corresponding to the natural language program requirements, and generate a corresponding initial computer program based on the enhanced prompt words; and an iterative correction module, configured to construct a corresponding multi-dimensional quality detection mechanism based on the model interface constraints, and perform a preset automated quality detection operation on the initial computer program through the multi-dimensional quality detection mechanism to obtain a quality detection result of the initial computer program, and in response to the quality detection result satisfying a preset computer program abnormality condition, iteratively perform a preset correction operation on the initial computer program based on the quality detection result until the iterative process satisfies a preset iteration termination condition, thereby generating a target backend computer program that meets the natural language program requirements.
[0008] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for implementing the steps of any of the above-described backend computer program generation methods when executing the computer program.
[0009] This application also provides a non-volatile computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any of the aforementioned back-end computer program generation methods.
[0010] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described backend computer program generation methods.
[0011] This application allows for the determination of model interface constraints corresponding to the natural language programming requirements of target users, thereby identifying the project context corresponding to these constraints. By combining the model interface constraints and the project context, enhanced prompts corresponding to the natural language programming requirements are constructed, and an initial computer program is generated based on these prompts. A multi-dimensional quality inspection mechanism is constructed based on the model interface constraints, and this mechanism performs pre-defined automated quality inspection operations on the initial computer program to obtain its quality inspection results. Furthermore, in response to the quality inspection results meeting pre-defined abnormal conditions, pre-defined correction operations are iteratively performed on the initial computer program based on the quality inspection results. The process continues iteratively until the preset iteration termination condition is met, generating a target backend computer program that meets the requirements of a natural language program. Therefore, it can solve the technical problems in related technologies, such as poor interface definition standardization, lack of data verification mechanism, low security and efficiency of database interaction, and inability to effectively handle exceptions when generating code from large language models, which greatly affect the quality and reusability of the generated code. By constructing multi-level context constraints and automated quality detection, it effectively ensures that the generated code can well meet enterprise-level quality standards in terms of database interaction, data verification, code reuse, code detection, and exception handling, thereby improving the reliability and practicality of the generated code. Attached Figure Description
[0012] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 This is a flowchart of a backend computer program generation method provided according to an embodiment of this application; Figure 2 This is an example diagram of a back-end computer program generation apparatus according to an embodiment of this application.
[0014] Among them, 10 is the back-end computer program generation device, 100 is the constraint determination module, 200 is the program generation module, and 300 is the iterative correction module. Detailed Implementation
[0015] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0016] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.
[0017] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0018] The specific application environment architecture or specific hardware architecture on which the execution of the backend computer program generation method depends is described here.
[0019] Embodiments of this application provide a method for generating backend computer programs.
[0020] like Figure 1 The diagram shown is a flowchart of a backend computer program generation method according to an embodiment of this application. The backend computer program generation method includes the following steps: In step S101, the model interface constraints corresponding to the natural language program requirements of the target user are determined, so as to determine the project context corresponding to the model interface constraints.
[0021] Those skilled in the art should understand that the application of large language models in code (i.e., computer program) generation is evolving from simple code completion to meeting actual functional requirements. In related technologies, developers can directly provide code requirement information to a general large model, causing it to return free-format code snippets; secondly, based on the database table structure or form configuration, basic CRUD (Create, Read, Update, Delete) code is generated using pre-set templates; subsequently, local functions or code blocks can be generated in an IDE by adding comments or entering simple commands. However, these technologies still have the following technical problems: 1. Poor interface definition standardization: APIs (Application Programming Interfaces) generated purely in natural language have relatively random paths, methods, and request or response body formats, which cannot be automatically integrated with the routing rules of the project's existing framework and still require manual adjustment.
[0022] 2. Missing or incorrect data validation: The generated code often ignores the validation of input data (such as field type, range, format, and correlation) or uses incorrect validation methods, which can easily lead to serious business logic vulnerabilities and security risks (such as SQL injection, unauthorized access, etc.).
[0023] 3. High security risks and low efficiency in database interaction: The generated SQL statements may be vulnerable to injection, or fail to fully utilize the best practices of ORM (Object-Relational Mapping) framework to map object-oriented programming languages to relational databases, and lack transaction management logic.
[0024] 4. Poor robustness of exception handling strategies: The code struggles to capture and handle business and system exceptions in a unified manner, or it only throws general exceptions, failing to generate structured error messages to return to the front end, which is not conducive to code debugging and monitoring.
[0025] 5. Uncontrollable code quality: The style, naming rules, and complexity of the generated code do not conform to the project specifications, and the generated code has not undergone any static analysis, security scanning, or performance checks, resulting in poor controllability of code quality.
[0026] 6. Poor code reusability: Each time, code generation is required again. It cannot intelligently identify and reuse common modules that already exist in the project (such as user authentication, logging, permission verification, pagination query, etc.), resulting in code redundancy and making code maintenance difficult.
[0027] Therefore, the embodiments of this application can generate the code required by the user by constructing multi-level context constraints, and perform automated quality inspection on the generated code to ensure that the generated code meets enterprise-level quality standards in terms of database interaction, data verification, code reuse, code inspection and exception handling, thereby improving the efficiency of code generation and enhancing the reliability and usability of the generated code.
[0028] In actual implementation, the embodiments of this application first define a lightweight, framework-independent interface description language based on the user's natural language code requirements (i.e., natural language program requirements). The user can describe interface constraints (i.e., model interface constraints, such as paths, methods, input and output parameters, and types) through forms or YAML / JSON, and determine the project context corresponding to the interface constraints. The interface constraints can be used as one of the input data for the subsequent large model (i.e., the large language model). Based on the project context, the embodiments of this application can control the large model to generate controller layer code (i.e., the final target backend code, including backend development framework-specific route registration code and data binding code) that strictly matches the interface constraints, and automatically register it to the corresponding project routes.
[0029] Therefore, this application embodiment provides reliable guidance and basis for subsequent code generation by constructing interface constraints defined by a structured interface description language and determining the project context corresponding to the interface constraints.
[0030] Optionally, in one embodiment of this application, determining the model interface constraints corresponding to the natural language program requirements of the target user includes: identifying the natural language program requirements of the target user, determining the model interface corresponding to the natural language program requirements, and determining the non-functional constraints corresponding to the model interface, wherein the non-functional constraints include interface performance requirements, interface idempotency requirements, and interface security requirements; performing preset functional description operations on the model interface using the target interface description language to generate corresponding interface constraint description information, and constructing model interface constraints based on the interface constraint description information and non-functional constraints.
[0031] It should be noted that, in this embodiment of the application, the user's natural language code requirements are transformed into machine-readable, standardized model interface constraints, which serve as the primary input and core constraint for the backend code generation process. The specific process is as follows: 1. In this embodiment of the application, the user's natural language code requirements can be obtained and received. Since the natural language requirements may have problems such as vague expression and incomplete information, the user needs to be guided to supplement and confirm the requirements. At the same time, the user is guided to supplement, confirm or directly provide machine-readable interface definitions.
[0032] 2. Based on the confirmed natural language code requirements, determine the corresponding model interface and clarify the non-functional constraints corresponding to the model interface. The non-functional constraints specifically include interface performance requirements, interface idempotency requirements (i.e., the same operation performed once or multiple times has the same impact on the system state), and interface security requirements. Among them, interface performance requirements may cover indicators such as response time, and interface security requirements may include authentication, authentication level, etc.
[0033] 3. In this embodiment of the application, a lightweight interface description language can be used as the target interface description language. This language can be a form, markup language or data exchange format. The language is used to perform preset functional description operations on the confirmed model interface, and to clearly define the endpoint path, method, request / response data structure and parameter details (including the position, type and constraints of the parameters) of the interface, so as to generate the corresponding interface constraint description information.
[0034] 4. The embodiments of this application can integrate the generated interface constraint description information with the determined non-functional constraints to construct a complete model interface constraint. This model interface constraint is the primary input and core constraint of the backend code generation process, thereby ensuring that the code generated subsequently strictly follows the interface convention.
[0035] Therefore, the embodiments of this application transform ambiguous natural language code requirements into standardized, machine-readable model interface constraints to fully cover both functional and non-functional interface requirements, avoid requirement ambiguity, and thus provide precise constraints for backend code generation, fundamentally ensuring the standardization, consistency, and testability of the API.
[0036] Optionally, in one embodiment of this application, determining the project context corresponding to the model interface constraints includes: parsing the model interface constraints to obtain corresponding parsed data, and extracting multiple constraint elements corresponding to the parsed data to construct a corresponding constraint feature anchor point set based on the multiple constraint elements; determining the target project to which the natural language program requirement belongs, and based on the constraint feature anchor point set, performing a preset targeted retrieval and feature bidirectional matching operation on the existing assets of the target project to filter out candidate assets associated with the constraint feature anchor points, thereby obtaining a corresponding candidate asset set; performing a preset hierarchical adaptation and correlation sorting operation on the candidate asset set to obtain a corresponding sorting result, and deleting items from the sorting result. Redundant and missing assets that meet preset constraint association requirements are used to generate a corresponding hierarchical adapted asset set. A two-way verification mechanism is constructed between model interface constraints and existing project assets. Based on the two-way verification mechanism and model interface constraints, the hierarchical adapted asset set is verified for adaptation integrity and availability to generate corresponding verification results. Based on the verification results, a preset dynamic calibration operation is performed on the hierarchical adapted asset set to obtain a calibrated hierarchical adapted asset set. The execution scenario characteristics of the model interface constraints are determined, and a preset structured integration operation is performed on the calibrated hierarchical adapted asset set to obtain corresponding integration results. The integration results and execution scenario characteristics are then combined to generate the project context.
[0037] In actual implementation, this application embodiment can receive structured function definitions, which include interface description language specifications. Simultaneously, based on model interface constraints, it initiates the project context determination process, the specific process of which is as follows: 1. This application embodiment comprehensively analyzes the completed model interface constraints, deconstructs its core content, and obtains parsed data containing all information such as interface constraint descriptions and non-functional constraints, ensuring that no constraint details are omitted. Subsequently, this application embodiment can accurately extract multiple key constraint elements from the parsed data. These key constraint elements cover core content related to interface implementation and asset adaptation, such as interface endpoint paths, request / response data structures, parameter constraints, performance requirements, security requirements, and idempotency requirements. Finally, this application embodiment can structure and classify the extracted constraint elements to construct a corresponding set of constraint feature anchor points.
[0038] 2. This application embodiment can clearly identify the target project to which the natural language code requirement belongs, namely, the existing software project that needs to generate backend code and improve the corresponding functions. This project includes various existing project assets that have been accumulated. Subsequently, using the set of constraint feature anchors as the retrieval benchmark, a preset targeted retrieval operation is performed on the existing assets of the target project to avoid the inefficiency caused by indiscriminate retrieval. At the same time, a two-way feature matching operation is performed to verify the fit between the existing assets of the project and the constraint feature anchors, and to verify in reverse whether the constraint feature anchors can be implemented through existing assets, ensuring the accuracy of the matching. Finally, this application embodiment can screen out assets that have a clear association with the constraint feature anchors and can be used to support the implementation of the interface, and integrate them to obtain the corresponding candidate asset set.
[0039] 3. Perform a preset hierarchical adaptation operation on the candidate asset set, and combine it with the layered architecture generated by the backend code (such as controller layer, service layer, persistence layer, etc.) to classify and adapt the candidate assets according to the hierarchical requirements of the interface implementation, clarifying the interface implementation level corresponding to each type of asset; at the same time, sort the adapted candidate assets by correlation, and prioritize retaining assets with high fit with constraint feature anchors, high reusability, and strong adaptability; subsequently, this embodiment can filter the sorting results according to the preset constraint correlation requirements, and delete redundant assets, that is, assets that are irrelevant to the interface implementation, duplicated, or have extremely low adaptability, to avoid redundancy during subsequent integration; at the same time, identify and delete invalid entries corresponding to missing assets that meet the preset constraint correlation requirements (or mark missing items to provide a basis for subsequent supplementation), to ensure that the filtered assets are neither redundant nor do they fit the constraint requirements; finally, this embodiment can perform structured organization of the filtered assets to generate a corresponding hierarchical adapted asset set.
[0040] 4. A two-way verification mechanism is constructed between model interface constraints and existing project assets. This mechanism breaks the one-way verification logic, verifying whether the hierarchical adaptation asset set can fully meet the constraint requirements based on the model interface constraints, and verifying whether some requirements in the model interface constraints are feasible based on the existing project assets, ensuring the comprehensiveness of the verification. Subsequently, based on this two-way verification mechanism and model interface constraints, the hierarchical adaptation asset set can be verified for adaptation completeness and availability, checking whether the assets cover all constraint anchors, whether the assets can be called normally, and whether the assets and interface hierarchical requirements are fully adapted, generating verification results containing information such as verification issues, issue locations, and adaptation deviations. Finally, based on the verification results, the hierarchical adaptation asset set can be subjected to preset dynamic calibration operations. For deviations and missing issues detected by verification, missing assets are supplemented, asset adaptation methods are adjusted, and asset associations are optimized, ultimately obtaining a calibrated hierarchical adaptation asset set.
[0041] 5. Based on the actual application scenarios of the model interface constraints, determine the corresponding execution scenario characteristics. These execution scenario characteristics include core scenario information related to interface execution, such as interface call frequency, data interaction scale, security level requirements, and deployment environment. Subsequently, this embodiment can perform a pre-defined structured integration operation on the calibrated hierarchical adaptation asset set to orderly integrate various assets according to the logic of interface implementation and asset hierarchical classification, forming a standardized and coherent integration result, ensuring the relevance and availability between assets. Finally, this embodiment can deeply integrate the integration result with the determined execution scenario characteristics, optimize the asset adaptation method and adjust the asset priority based on the scenario characteristics, and generate project context.
[0042] It should be noted that the project context loaded in this embodiment, which is associated with the function, mainly includes the data model, exception framework, and code specifications, and explicitly includes a reusable code component library. In the subsequent backend code generation process, the modules in this reusable code component library can be referenced first, so that only differentiated business logic is generated, thereby ensuring the efficiency and standardization of code generation.
[0043] Therefore, the embodiments of this application standardize the process of determining the project context, clarify the core components of the project context and integrate them into a reusable code component library, and ensure that the project context conforms to the model interface constraints and functional requirements, thereby providing reliable data support for subsequent code generation, while improving code generation efficiency by prioritizing component reuse.
[0044] In step S102, by combining the model interface constraints and the project context, enhanced prompt words corresponding to the natural language program requirements are constructed, and the corresponding initial computer program is generated based on the enhanced prompt words.
[0045] Furthermore, in this embodiment of the application, a structured and hierarchical enhanced prompt word containing engineering constraints is automatically constructed based on the model interface constraints and project context, and the enhanced prompt word is sent to the large model (i.e., the natural language processing model) to drive the large model to perform phased and iterative code generation operations, thereby outputting the corresponding initial code (i.e., the initial computer program).
[0046] Therefore, the embodiments of this application combine model interface constraints with project context to construct enhanced prompts and drive the large model to generate initial code, thereby effectively ensuring the compliance and usability of the generated code.
[0047] Optionally, in one embodiment of this application, constructing enhanced prompts corresponding to natural language program requirements by combining model interface constraints and project context includes: determining the constraint requirements of the target backend computer program based on model interface constraints, and determining corresponding interface implementation layer prompts based on the constraint requirements; obtaining parameter constraints in the model interface constraints, generating a corresponding data validation computer program based on the parameter constraints, and generating a data conversion object through the data validation computer program, so as to determine corresponding data validation and object mapping layer prompts based on the data conversion object; determining database security operation strategies based on model interface constraints, and generating corresponding data interaction layer prompts based on the database security operation strategies; obtaining interface error response information corresponding to the model interface constraints, determining the exception handling mechanism corresponding to the interface error response information, and determining the exception handling mechanism based on the exception... The processing mechanism constructs a corresponding global exception handler to generate exception handling layer prompts. Based on the project context, it analyzes the project's computer program library corresponding to the natural language program requirements to identify the corresponding reusable components, design patterns, and common base classes, and generates corresponding reuse analysis layer prompts based on these components. Based on the natural language program requirements, it determines the corresponding computer program coding standards, security conventions, and architectural principles, and constructs corresponding internal constraints based on these principles to generate corresponding embedded quality convention prompts. Based on the interface implementation layer prompts, data validation and object mapping layer prompts, data interaction layer prompts, exception handling layer prompts, reuse analysis layer prompts, and embedded quality convention prompts, it constructs enhanced prompts.
[0048] It should be noted that, based on model interface constraints and project context, the process of constructing the corresponding enhanced prompt words in this embodiment is as follows: 1. Constructing the interface implementation layer prompt: This application embodiment can define the various constraint requirements of the target backend code based on model interface constraints, and at the same time force the generated code to strictly follow the defined model interface constraints. It focuses on the generation of controller layer code, and explicitly requires that it include correct annotations, parameter bindings and return value encapsulation, and integrates them to form the corresponding interface implementation layer prompt words.
[0049] 2. Construct data validation and object mapping layer prompts: This application embodiment can obtain the parameter constraints in the model interface constraints, generate corresponding data validation code based on the parameter constraints, and generate a data conversion object. Combining the data validation code and the data conversion object (such as DTO (DataTransfer Object), which represents a design pattern for efficient and secure data transmission operations between different layers (or systems), it does not contain any business logic, but only data fields and access methods), constructs and determines the corresponding data validation and object mapping layer prompt words to ensure that data validation and object mapping conform to the interface constraints (i.e., model interface constraints).
[0050] 3. Construct prompts for the data interaction layer: This application embodiment can determine a database security operation strategy based on model interface constraints. This strategy incorporates best practices for database operations, including the use of parameterized queries or type-safe object-relational mapping methods, explicit transaction boundary management, efficient query construction, and reasonable join and caching strategies. Based on this database security operation strategy, corresponding data interaction layer prompts are generated.
[0051] 4. Construct error handling layer prompts: Furthermore, this application embodiment can also obtain interface error response information corresponding to model interface constraints, determine the exception system (including verification exception, not found exception, business exception, etc.) corresponding to the error response information, and construct a corresponding global exception processor based on the exception system to ensure that all exceptions can be captured and converted into an error response format that conforms to the interface constraints, thereby generating exception handling layer prompt words through the global exception processor.
[0052] In actual implementation, this application embodiment can predefine project-level exception classifications and global exception handlers, and when generating business logic code, guide the large model to throw corresponding types of exceptions in specific scenarios (such as query result scenarios or illegal parameter scenarios), and generate clear error messages, thereby ensuring that exceptions can be uniformly captured by the global handler and converted into standard HTTP (HyperText Transfer Protocol) error responses.
[0053] 5. Construct reusable analysis layer prompts: Subsequently, embodiments of this application can analyze the project code library corresponding to the natural language code requirements based on the project context, and accurately identify reusable components, design patterns, and common base classes. Reusable components include general pagination queries, log aspects, authentication interception, encryption tools, message sending, etc.; design patterns include strategy patterns, factory patterns, etc. Therefore, embodiments of this application can generate corresponding reuse analysis layer prompts based on the identified reusable components, design patterns, and common base classes to clarify that the instruction model should prioritize the reuse of existing assets.
[0054] It is understood that the embodiments of this application can significantly reduce duplicate code by actively analyzing the project context and guiding model reuse.
[0055] It should be noted that the embodiments of this application can maintain a reusable code pattern library (i.e., project code library) containing general functions. Before generating code, the system can analyze the natural language code requirement description and identify reusable patterns; during the code generation process, the reuse instruction is "call the pagination component to process list queries and implement the business logic of filtering by name on its basis", rather than regenerating all pagination code.
[0056] 6. Construct embedded quality convention prompts: Furthermore, this application embodiment can determine the corresponding code coding standards, security conventions, and architectural principles based on the requirements of natural language code. The coding standards cover requirements such as naming and comments. This application embodiment can integrate the above content and use it as an inherent constraint when generating code, and generate corresponding embedded quality convention prompts through the inherent constraints.
[0057] 7. Integrate and generate enhanced prompt words: This application embodiment can integrate six prompt layers: interface implementation layer prompts, data validation and object mapping layer prompts, data interaction layer prompts, exception handling layer prompts, reuse analysis layer prompts, and embedded quality convention prompts, to construct a structured, hierarchical enhanced prompt (i.e., system prompts) containing clear constraints.
[0058] Therefore, the embodiments of this application organically integrate the relevant requirements of interface definition, data verification, database interaction, exception handling, code detection, and code reuse into the entire process before, during, and after code generation, ensuring that the code generated by the large model is compliant, reusable, and meets the actual needs of users and projects.
[0059] Optionally, in one embodiment of this application, enhanced prompts are constructed based on interface implementation layer prompts, data validation and object mapping layer prompts, data interaction layer prompts, exception handling layer prompts, reuse analysis layer prompts, and embedded quality convention prompts. This includes: performing semantic structured parsing on the interface implementation layer prompts, data validation and object mapping layer prompts, data interaction layer prompts, exception handling layer prompts, reuse analysis layer prompts, and embedded quality convention prompts respectively, extracting the constraint elements and functional orientation information of each layer of prompts to output multi-layer prompt parsing results; and prioritizing and assigning execution order to the parsing results of each layer of prompts according to model interface constraints and project context. The system assigns constraint weights and execution order identifiers to different levels of prompt words, generating a hierarchical prompt word set with sequence and weight attributes. Following preset hierarchical fusion rules, the hierarchical prompt word set is context-linked and semantically deduplicated to form a logically coherent and constraint-complete structured prompt word body, generating initial enhanced prompt words. The initial enhanced prompt words undergo internal constraint consistency verification and semantic fluency calibration to obtain corresponding calibrated prompt words. These calibrated prompt words are then standardized and encapsulated according to a system-recognizable format to generate the final enhanced prompt words. These enhanced prompt words are input into the natural language processing model to drive code generation, serving as direct input for the code generation stage.
[0060] As one possible approach, the process of constructing enhanced prompts based on different prompt words in embodiments of this application is described below: 1. The embodiments of this application can perform semantic structured parsing on the prompt words corresponding to the interface implementation layer, data verification and object mapping layer, data interaction layer, exception handling layer, reuse analysis layer and embedded quality convention layer respectively, extract the constraint elements and functional orientation information of each layer, form multi-layer prompt word parsing results, and provide unified and standardized basic data for subsequent processing.
[0061] 2. Based on the model interface constraints and project context, prioritize and assign execution order to the parsing results of each layer of prompt words. Assign corresponding constraint weights and execution order identifiers to prompt words at different levels to form a hierarchical set of prompt words with sequence and weight attributes, ensuring that the constraints at each level are clearly distinguished in terms of primary and secondary importance and in a reasonable order during fusion.
[0062] 3. According to the preset hierarchical fusion rules, the hierarchical prompt word set is combined with context association and semantic deduplication to integrate the scattered multi-level prompt words into a logically coherent and constrained structured prompt word body, thus obtaining the initial enhanced prompt words.
[0063] 4. Perform internal constraint consistency verification and semantic fluency calibration on the initial enhanced prompt words to eliminate inter-layer conflicts, redundancy and semantic contradictions to obtain calibrated prompt words; then, in this embodiment, the prompt words can be standardized and encapsulated in a format recognizable by the model to form the final enhanced prompt words, which can be directly input into the natural language processing model to generate the corresponding code.
[0064] Therefore, the embodiments of this application construct enhanced prompt words through operations such as parsing, sorting, fusion, and calibration to accurately guide the large model to generate standardized, compliant code that meets project requirements, thereby improving the quality and usability of the generated code.
[0065] Optionally, in one embodiment of this application, generating a corresponding initial computer program based on enhanced prompts includes: inputting enhanced prompts into a pre-trained natural language processing model to generate an interface layer computer program and a data transmission object that satisfy the model interface constraints; determining the business rules and object-relational mapping specifications corresponding to the natural language program requirements, and generating a service layer computer program that satisfies the business rules and a data access layer computer program that satisfies the object-relational mapping specifications based on preset programming logic and transaction declarations; and constructing an initial computer program based on the interface layer computer program, the data transmission object, the service layer computer program, and the data access layer computer program.
[0066] In its specific implementation, this embodiment first initiates a phased code generation process to send enhanced prompts to the natural language processing model, executing the first phase of framework and interface layer generation. In this first phase, this embodiment generates interface layer code and core data transmission objects that strictly conform to the model's interface constraints, ensuring that the interface layer code fits the interface constraints and that the data transmission objects precisely match the interface parameters and response structure, thereby completing the initial code's basic framework construction.
[0067] Secondly, the embodiments of this application execute the second stage of business logic and service layer generation operations. Specifically, the embodiments of this application can first determine the business rules and object relationship mapping specifications corresponding to the natural language code requirements, and the system automatically associates the data model definition and business rule library in the project. Subsequently, the large model can generate service layer code that conforms to the business rules based on the preset programming logic and transaction declarations. The service layer code integrates data verification logic, reuses component calls, and can correctly throw custom exceptions. Among them, the data verification logic can be automatically inserted into the service layer or control layer according to the constraints and business rules in the model definition to ensure that business processing is compliant.
[0068] Subsequently, the embodiments of this application can execute the third stage of data persistence layer generation operation. In this stage, the large model can generate data access layer code that meets the object-relational mapping specification and preset programming logic based on the object-relational mapping specification and preset programming logic. The data access layer code conforms to the project object-relational mapping specification and contains transaction declarations to achieve secure and efficient database interaction. During the data access layer code generation process, the large model can directly reference specific field names, types and relationships in the project data model to perform object-relational mapping operations, while incorporating best practices for database operations to ensure the security and efficiency of the data access layer code.
[0069] Finally, the embodiments of this application can integrate the interface layer code and data transmission object generated in the first stage, the service layer code generated in the second stage, and the data access layer code generated in the third stage to construct a complete initial code, thereby ensuring that the code of each layer is smoothly connected and logically coherent, and fully meets the various constraints and requirements of enhanced prompt word delivery.
[0070] Therefore, the embodiments of this application generate corresponding code at each stage iteratively, and combine enhanced prompts, business rules and project specifications, thereby effectively ensuring that the generated initial code conforms to interface constraints and business requirements, improving the standardization and usability of the code, and reducing the cost of modifying subsequent code.
[0071] Optionally, in one embodiment of this application, before inputting the enhanced prompt words into the pre-trained natural language processing model, the method further includes: determining the application scenario information of the natural language processing model, constructing a corresponding constraint-guided training benchmark based on the application scenario information, and fusing the constraint-guided training benchmark and the application scenario information to generate a corresponding constraint-guided benchmark set; acquiring multi-source program generation data based on the application scenario information and natural language program requirements, and performing preset semantic purification and deviation correction operations on the multi-source program generation data according to the constraint-guided benchmark set, so as to select target multi-source program generation data that meets the model interface constraints from the multi-source program generation data, and to perform target multi-source program generation data... The generated data undergoes a pre-defined structured reconstruction process to generate a training dataset for the natural language processing (NLP) model. This training dataset is then input into the NLP model to obtain the current model parameter iteration bias and semantic bias. A corresponding bias analysis report is generated based on these bias analysis reports and a constraint-guided benchmark set. A corresponding dynamic parameter calibration strategy is determined, and based on this strategy, the NLP model is iteratively optimized until it meets pre-defined performance requirements or reaches a pre-defined number of training iterations, resulting in a fully trained NLP model.
[0072] As one possible approach, the process of training a natural language processing model according to embodiments of this application is as follows: 1. Construct a set of constraint-guided benchmarks: (1) The embodiments of this application can accurately determine the application scenario information of the natural language processing model, which covers the specific scenarios in which the model is subsequently used for backend code generation, the adapted project architecture, interface implementation requirements and other core contents; (2) Based on the application scenario information, construct the corresponding constraint-guided training benchmark. This benchmark incorporates scenario adaptation rules, code generation quality requirements and model interface constraint-related standards to standardize the direction of model training. (3) Deeply integrate the constraint-guided training benchmark with the application scenario information to form a corresponding constraint-guided benchmark set, which serves as the core basis for subsequent data screening and model calibration, ensuring that the model training does not deviate from the actual application requirements.
[0073] 2. Filter and reconstruct the training dataset: (1) Based on the established application scenario information and natural language code requirements, a wide range of source code generation data is obtained. This source code generation data covers various backend code generation related samples, including code generation samples at different levels such as interface layer, service layer, and data access layer. (2) Using the constraint-guided benchmark set as the screening criterion, the acquired multi-source code generation data is subjected to preset semantic purification and deviation correction operations. Semantic purification is used to retain valid data related to the current requirements and scenarios; deviation correction is used to correct erroneous content in the data that does not conform to the model interface constraints and coding specifications, thereby selecting target multi-source code generation data that meets the model interface constraint requirements and fits the application scenario from the multi-source code generation data. (3) Perform pre-defined structured reconstruction processing on the target multi-source code generated data, so as to organize the target multi-source code generated data in a unified format at multiple levels, so as to meet the training data requirements of the natural language processing model and generate a training dataset dedicated to the model.
[0074] 3. Detect model deviations and generate a deviation analysis report: (1) In this embodiment of the application, the completed training dataset can be input into the natural language processing model, start the model training and testing process, capture the running status of the model training process in real time, and accurately obtain the current model parameter iteration deviation and semantic deviation corresponding to the model. Among them, parameter iteration deviation refers to the situation where the model parameters deviate from the optimal value during the update process, and semantic deviation refers to the situation where the model output results are inconsistent with the training data and constraints at the semantic level. (2) Summarize and analyze the two types of deviations obtained, clarify the type, degree and cause of deviation, and generate the corresponding deviation analysis report to clearly present the current problems of the model, so as to provide accurate and detailed basis for subsequent model parameter optimization.
[0075] 4. Iterative optimization of model parameters: (1) Based on the generated deviation analysis report and constraint-guided benchmark set, and combined with the deviation type and cause, determine the corresponding dynamic parameter calibration strategy. This strategy formulates differentiated parameter adjustment schemes for different types and degrees of deviation to ensure the pertinence of parameter optimization. (2) Based on the dynamic parameter calibration strategy, the natural language processing model is iteratively optimized. After each round of parameter optimization, the model performance is tested again using the training dataset to check whether the deviation has been improved. The optimization process is continuously iterated until the natural language processing model meets the preset performance requirements (i.e., the model output accuracy, code compliance, etc. reach the corresponding standards) or reaches the preset number of iterations. Finally, the trained natural language processing model is obtained, which provides reliable support for receiving enhanced prompt words and outputting initial code.
[0076] Therefore, the embodiments of this application optimize the natural language processing model through targeted training, and through operations such as building constraint benchmarks, screening high-quality training data, and iteratively calibrating parameters, the model is adapted to the corresponding requirements, reducing the model output deviation, and accurately outputting initial code that meets the model interface constraints and fits the actual needs of the project.
[0077] In step S103, based on model interface constraints, a corresponding multi-dimensional quality detection mechanism is constructed, and a preset automated quality detection operation is performed on the initial computer program through the multi-dimensional quality detection mechanism to obtain the quality detection result of the initial computer program. In response to the quality detection result meeting the preset abnormal conditions of the computer program, a preset correction operation is iteratively performed on the initial computer program according to the quality detection result until the iteration process meets the preset iteration termination condition, thereby generating a target backend computer program that meets the requirements of the natural language program.
[0078] Subsequently, embodiments of this application can construct a multi-dimensional quality inspection mechanism based on model interface constraints to perform automated quality inspection operations on the initial code and obtain the corresponding inspection results; if the inspection results meet the code anomaly conditions, the inspection results are fed back to the large model (i.e., the natural language processing model) to iteratively correct the initial code until the target backend code that meets the quality inspection requirements is generated.
[0079] Therefore, the embodiments of this application ensure that the final generated target backend code conforms to the model interface constraints through initial code quality detection and iterative correction operations, thereby improving the quality of the generated code. Optionally, in one embodiment of this application, a multi-dimensional quality inspection mechanism is used to perform preset automated quality inspection operations on the initial computer program to obtain the quality inspection result of the initial computer program. This includes: performing preset contract testing on the initial computer program to obtain the corresponding contract test result; sequentially performing preset static analysis, security scanning, and business rule checking operations on the initial computer program to obtain the corresponding computer program analysis result; determining at least one critical path in the initial computer program that meets preset criticality requirements, and performing preset anomaly coverage checking operations on the at least one critical path to obtain the corresponding coverage check result; obtaining historical computer programs corresponding to the natural language program requirements, calculating the computer program similarity between the historical computer program and the initial computer program, and performing a preset reuse effectiveness evaluation operation on the initial computer program based on the computer program similarity to obtain the corresponding evaluation result; and integrating the contract test result, computer program analysis result, coverage check result, computer program similarity, and evaluation result to obtain the quality inspection result.
[0080] In actual execution, this embodiment first performs preset contract testing on the initial code, automatically generating and executing basic contract test cases. The focus is on verifying whether the generated API, in terms of endpoint paths, request methods, and request and response formats, is completely consistent with the interface conventions defined in the model interface constraints, thus obtaining the corresponding contract test results. Furthermore, this embodiment can also sequentially perform static analysis, security scanning, and specific business rule checks on the initial code to comprehensively identify code syntax errors, potential risks, security vulnerabilities, and content that does not conform to business rules, thereby obtaining the corresponding code analysis results. It should be noted that, in the embodiments of this application, the automated quality inspection of the initial code includes at least static code analysis, security vulnerability scanning, and consistency verification with the project data model.
[0081] Secondly, the embodiments of this application can determine at least one critical path in the initial code that meets the preset criticality requirements. As the core link of interface implementation and business logic execution, the critical path is crucial to the stability of code operation. The embodiments of this application can perform a preset exception coverage check operation on at least one critical path to analyze whether the critical path has been completely covered by the exception types defined in the model interface constraints, so as to ensure that all kinds of exceptions on the critical path can be effectively captured and processed, and obtain the corresponding coverage check results.
[0082] Furthermore, this application embodiment can obtain the project's historical code (i.e., the project's existing code) corresponding to the natural language code requirement, calculate the code similarity between the historical code and the initial code using a preset algorithm, and check for duplication between the new code and the existing code; at the same time, based on the calculated code similarity, a preset reuse effectiveness assessment operation is performed on the initial code, focusing on evaluating the execution effect of reuse instructions in the enhanced prompt words, so as to provide prompts for the parts of the project's existing assets that are not effectively reused, and obtain the corresponding reuse effectiveness assessment results.
[0083] Finally, the embodiments of this application can comprehensively integrate the contract test results, code analysis results, coverage check results, code similarity data and reuse effectiveness evaluation results obtained from the above steps, and sort out the problems and compliance status in each check to form a complete and detailed quality inspection result, thereby providing a precise basis for the subsequent correction and optimization of the initial code.
[0084] Therefore, the embodiments of this application take model interface constraints as the basis, embed quality inspection operations such as code inspection, security scanning, and functional testing into the code generation process, and comprehensively check the interface compliance, security, anomaly coverage and reusability of the initial code through multi-dimensional automated inspection, so that meeting quality requirements (i.e. quality qualified) becomes the default attribute of subsequent generated code, providing a basis for the correction of the initial code and ensuring the quality of the final code.
[0085] Optionally, in one embodiment of this application, at least one critical path in the initial code (i.e., the initial computer program) that meets preset criticality requirements is determined, and a preset anomaly coverage check operation is performed on the at least one critical path to obtain the corresponding coverage check result. This includes: determining the corresponding business execution logic and interface execution link based on model interface constraints and natural language code requirements, and parsing the model interface constraints and business execution logic to extract functional nodes and flow relationships in the interface execution link, and outputting an interface execution link graph; assigning weights and thresholds to the interface execution link graph according to preset criticality requirements to output a set of critical paths, wherein the preset criticality requirements include the degree of business impact, the importance level of data flow, and the sensitivity to anomaly risks; constructing an anomaly type system corresponding to the model interface constraints, performing bidirectional matching verification between the anomaly type system and the set of critical paths to determine whether each critical path is bound to the corresponding anomaly handling logic, and outputting a path-anomaly matching relationship table; performing anomaly coverage statistics and compliance judgment based on the path-anomaly matching relationship table to generate a coverage check result, which is used to evaluate the completeness of anomaly handling in the initial code and serves as a direct input basis for subsequent code iteration and correction.
[0086] Specifically, this embodiment first uses model interface constraints as the standard and natural language code requirements as the business guideline, clarifying the corresponding business execution logic and interface execution chain. That is to say, the business execution logic originates from the core business process in the natural language code requirements, while the interface execution chain is derived from the model interface constraints, representing the concrete implementation of the business logic at the interface level. Subsequently, this embodiment can parse the model interface constraints and the streamlined business execution logic to extract all functional nodes (such as parameter validation, data interaction, and business processing) and the flow relationships between each node in the interface execution chain. It then structurally integrates the relevant functional nodes and flow relationships, outputting a clear interface execution chain diagram. This diagram can be used to fully present the entire interface execution process, serving as the core input for subsequent critical path selection.
[0087] Secondly, according to the embodiments of this application, each execution path in the interface execution link graph can be weighted and threshold filtered based on preset critical requirements. Specifically, the preset critical requirements include three dimensions: business impact, data flow importance level, and sensitivity to anomaly risks. The weighting can be determined based on the performance of each path in the three dimensions, and the threshold filtering removes non-critical paths with weights below the standard. Finally, a set of critical paths is output, which limits the scope of subsequent anomaly coverage checks and serves as the input object for the next step of bidirectional matching verification.
[0088] Subsequently, this embodiment of the application can construct an exception type system corresponding to the model interface constraints to ensure that the exception types conform to the error response requirements in the interface constraints and the business scenario requirements. The exception type system is then bidirectionally matched and verified with the set of critical paths. It is determined one by one whether the corresponding exception handling logic has been bound to each critical path and whether the bound exception logic is suitable for the path requirements. The matching status of each critical path and exception type is sorted out and recorded to output a path-exception matching relationship table. This path-exception matching relationship table is used to clarify the current status of exception coverage of each critical path and serves as the core input for subsequent coverage statistics.
[0089] Finally, this embodiment of the application can statistically analyze the anomaly coverage of all critical paths based on the path-anomaly matching relationship table, calculate the anomaly coverage ratio, identify critical paths with uncovered anomalies, and conduct compliance judgment to check whether the matched anomaly handling logic conforms to the specifications. By combining the statistical results and the compliance judgment conclusions, a coverage check result is generated. This coverage check result can be used to accurately assess the completeness of anomaly handling of critical paths in the initial code, and directly serve as the input basis for subsequent initial code iteration and correction, providing a clear direction for code defect repair.
[0090] Therefore, the embodiments of this application standardize the process of critical path identification and anomaly coverage checking, accurately locate critical paths and anomaly coverage gaps, and the generated check results can provide a reliable basis for code iteration and correction, ensuring the integrity and compliance of the initial code anomaly handling.
[0091] As a feasible approach, in the process of calculating the code similarity between historical code and initial code to evaluate the reusability of the initial code, the embodiments of this application first determine the business scenario and interface implementation specifications corresponding to the requirements based on natural language code requirements and model interface constraints, extract the core features of the requirements and key elements of the interface implementation, and output a requirement-interface feature mapping table; secondly, the embodiments of this application can perform targeted retrieval and preliminary screening of the historical code of the project to which the natural language code requirements belong based on the requirement-interface feature mapping table, eliminate redundant historical code that is not related to the requirements features and interface specifications, integrate the screened effective historical code and perform structured decomposition, extract reusable modules, logic fragments and constraint adaptation information from the historical code, and output a set of structured historical code; Furthermore, the embodiments of this application can synchronously and structurally decompose the initial code to obtain the initial code layer decomposition results corresponding to the three accounting dimensions of code structure layer, logic implementation layer and constraint adaptation layer. Based on the initial code layer decomposition results and the structured historical code set, a layered similarity accounting mechanism is constructed to calculate the similarity between the initial code and the historical code under different dimensions. The similarity results of each dimension are integrated and weighted to generate the corresponding code similarity. Finally, the embodiments of this application can combine code similarity to construct a multi-dimensional reuse effectiveness evaluation system, and incorporate three evaluation indicators: reuse adaptability, logical consistency, and constraint compliance, to comprehensively determine the reuse status of the initial code, so as to distinguish between effective reuse, redundant reuse, and ineffective reuse, thereby outputting the reuse effectiveness evaluation result.
[0092] Therefore, the embodiments of this application construct a requirement-interface feature mapping table to selectively filter valid historical code, and obtain a comprehensive similarity through operations such as hierarchical decomposition and hierarchical similarity calculation. Furthermore, the reuse situation is determined by combining a multi-dimensional evaluation system, thereby accurately completing the evaluation of the reuse effectiveness of the initial code, ensuring that the code can well fit the requirements and model interface constraints, and improving the code quality.
[0093] Optionally, in one embodiment of this application, a preset correction operation is performed iteratively on the initial computer program based on the quality inspection results until the iteration process meets the preset iteration termination condition, generating a target backend computer program that meets the requirements of a natural language program. This includes: determining whether the initial computer program meets the preset quality inspection requirements based on the quality inspection results; in response to the initial computer program not meeting the preset quality inspection requirements, determining the computer program defect type, defect location, repair suggestion, and defective computer program segment corresponding to the initial computer program, and integrating the computer program defect type, defect location, repair suggestion, defective computer program segment, and model interface constraints to obtain the corresponding correction prompt word; re-inputting the correction prompt word into a pre-trained natural language processing model to perform a preset computer program correction operation on the initial computer program iteratively until a preset number of iterations is reached or the corrected initial computer program in the current iteration meets the preset quality requirements, thereby generating a target backend computer program.
[0094] As one possible approach, this application embodiment can first determine whether the initial code meets the preset quality inspection requirements based on the results of automated quality inspection; if it is determined that it does not meet the requirements, that is, the code has quality defects, this application embodiment can further clarify the code defect type, the specific location of the defect, the targeted repair suggestions and the defective code segment corresponding to the initial code.
[0095] Secondly, the embodiments of this application can integrate the code defect types, specific locations of defects, targeted repair suggestions, and defective code segments identified above with the original model interface constraints to generate corresponding correction prompts, so that the correction prompts fully carry the problem information and constraint benchmarks.
[0096] Subsequently, in this embodiment of the application, the correction prompt words can be re-input into the natural language processing model to iteratively perform code correction operations on the initial code, thereby repeating the above-mentioned steps of quality detection, constructing correction prompt words, and model iterative correction until the corrected code meets the preset quality requirements or reaches the maximum number of iterations, at which point the iteration process is terminated, thereby generating the final target backend code. In summary, this application embodiment establishes an automated closed-loop operation process of "generation-analysis-feedback-correction" to sequentially trigger code style checks, static security analysis, dependency vulnerability scanning, and business logic rule checks after the initial code is generated. The output results of the checking tools (such as the front-end code syntax checking tool ESLint, the full-stack code quality / vulnerability scanning checking tool SonarQube, and the code security vulnerability checking tool Bandit), along with the problematic code segments, are used to construct new system prompt words (i.e., correction prompt words). The correction prompt words are then input into the large model to iteratively correct the initial code until all quality detection requirements are met.
[0097] Therefore, the embodiments of this application accurately locate code defects based on quality inspection results, and construct correction prompts to drive the model to iteratively correct the code, thereby ensuring that the final generated backend code meets the preset quality requirements and model interface constraint specifications.
[0098] Optionally, in one embodiment of this application, after generating the target backend computer program, the method further includes: extracting multiple program information corresponding to the target backend computer program, performing a preset data comparison operation on the multiple program information and the interface document corresponding to the natural language program requirements to obtain the corresponding comparison results, and updating the interface document according to the comparison results to generate unit test computer programs and integration test stub computer programs corresponding to the model interface constraints; obtaining configuration information corresponding to the target backend computer program, and deploying the unit test computer program, integration test stub computer program and target backend computer program to a preset system backend environment according to the configuration information.
[0099] In the specific implementation process, after generating target backend code that meets preset quality requirements, this application embodiment can automatically complete the source code output and generate supporting development assets to promote the code to quickly reach the integration-ready state. The specific process is as follows: 1. Generate and update supporting development assets: This application embodiment can parse the target backend code (i.e., the target backend computer program) and extract multiple program information such as the corresponding interface path, request method, parameter structure, return value format, exception response, and constraint rules. It then compares this program information (i.e., the actual code information) with the original interface documentation item by item, replacing or supplementing any inconsistencies to ensure the interface documentation is completely consistent with the final code. This achieves automatic updating of the project interface documentation corresponding to the natural language code requirements, ensuring that the documentation content is completely synchronized with the generated target backend code, without any version inconsistency issues. Subsequently, this application embodiment can extract multiple interface information such as interface constraints, parameter rules, response format, exception scenarios, and interface dependencies from the updated interface documentation. Based on this information, it constructs corresponding normal and exception test cases to generate unit test code that verifies the interface functionality. Furthermore, based on the call relationships between interfaces, it generates integration test stubs that simulate external dependencies and verify the overall process, covering both normal business scenarios and exception scenarios based on verification rules. 2. Output deployment and configuration related content: The embodiments of this application can extract the configuration information corresponding to the target backend code to generate corresponding deployment and configuration prompts, including database migration scripts, dependency injection configurations and other related configuration instructions or code snippets.
[0100] 3. Complete deployment and integration: According to the embodiments of this application, the generated unit test code, integration test stub code and target backend code can be deployed together to the preset system backend environment based on the extracted configuration information, thereby realizing the integration and implementation of code and supporting assets.
[0101] It is understood that the embodiments of this application can automatically update the interface documentation, generate test suites and deployment configuration related content after generating the target backend code, and complete the deployment and integration of code and supporting assets, thereby ensuring consistent development assets and rapid code integration and readiness, and improving development and delivery efficiency. In addition, the final output of the embodiments of this application includes not only code snippets, but also functional module packages with supporting tests and updated documentation, which greatly reduces code integration and subsequent development costs.
[0102] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0103] Embodiments of this application also provide a back-end computer program generation apparatus.
[0104] like Figure 2 As shown, the back-end computer program generation device 10 includes: a constraint determination module 100, a program generation module 200, and an iterative correction module 300.
[0105] The constraint determination module 100 is used to determine the model interface constraints corresponding to the natural language program requirements of the target user, so as to determine the project context corresponding to the model interface constraints.
[0106] The program generation module 200 is used to combine model interface constraints and project context to construct enhanced prompt words corresponding to natural language program requirements, and generate corresponding initial computer programs based on the enhanced prompt words.
[0107] The iterative correction module 300 is used to construct a corresponding multi-dimensional quality detection mechanism based on model interface constraints, and to perform preset automated quality detection operations on the initial computer program through the multi-dimensional quality detection mechanism to obtain the quality detection results of the initial computer program. In response to the quality detection results meeting the preset abnormal conditions of the computer program, the module iteratively performs preset correction operations on the initial computer program according to the quality detection results until the iterative process meets the preset iteration termination conditions, thereby generating a target backend computer program that meets the requirements of the natural language program.
[0108] Optionally, in one embodiment of this application, the program generation module 200 includes: an interface implementation prompt word determination unit, a data verification prompt word determination unit, a data interaction prompt word determination unit, an exception prompt word determination unit, a reuse analysis prompt word determination unit, a quality agreement prompt word determination unit, and a first integration unit.
[0109] The interface implementation prompt word determination unit is used to determine the constraint requirements of the target backend computer program based on the model interface constraints, and determine the corresponding interface implementation layer prompt words according to the constraint requirements.
[0110] The data validation prompt word determination unit is used to obtain the parameter constraints in the model interface constraints, generate the corresponding data validation computer program based on the parameter constraints, and generate a data transformation object through the data validation computer program, so as to determine the corresponding data validation and object mapping layer prompt words based on the data transformation object.
[0111] The data interaction prompt word determination unit is used to determine the database security operation strategy based on the model interface constraints, and generate corresponding data interaction layer prompt words according to the database security operation strategy.
[0112] The exception prompt word determination unit is used to obtain the interface error response information corresponding to the model interface constraints, determine the exception handling mechanism corresponding to the interface error response information, and construct the corresponding global exception processor according to the exception handling mechanism, so as to generate exception handling layer prompt words through the global exception processor.
[0113] The reuse analysis prompt word determination unit is used to analyze the project computer program library corresponding to the natural language program requirements based on the project context, in order to identify the corresponding reuse components, design patterns and common base classes, and generate corresponding reuse analysis layer prompt words based on the reuse components, design patterns and common base classes.
[0114] The quality convention prompt word determination unit is used to determine the corresponding computer program coding standards, security conventions and architectural principles based on the requirements of natural language programs, and to construct the corresponding internal constraints based on the computer program coding standards, security conventions and architectural principles, so as to generate the corresponding embedded quality convention prompt words through the internal constraints.
[0115] The first integration unit is used to construct enhanced prompts based on interface implementation layer prompts, data validation and object mapping layer prompts, data interaction layer prompts, exception handling layer prompts, reuse analysis layer prompts, and embedded quality convention prompts.
[0116] Optionally, in one embodiment of this application, the program generation module 200 further includes: a first generation unit, a second generation unit, and a construction unit.
[0117] The first generation unit is used to input enhanced prompt words into a pre-trained natural language processing model to generate an interface layer computer program and a data transmission object that satisfy the model interface constraints.
[0118] The second generation unit is used to determine the business rules and object-relational mapping specifications corresponding to the natural language program requirements, and to generate service layer computer programs that meet the business rules and data access layer computer programs that meet the object-relational mapping specifications based on preset programming logic and transaction declarations.
[0119] The building unit is used to build an initial computer program based on the interface layer computer program, the data transfer object, the service layer computer program, and the data access layer computer program.
[0120] Optionally, in one embodiment of this application, the iterative correction module 300 includes: a contract testing unit, an anomaly coverage checking unit, a similarity calculation unit, and a second integration unit.
[0121] The contract testing unit is used to perform preset contract tests on the initial computer program to obtain the corresponding contract test results, and to sequentially perform preset static analysis, security scanning and business rule checks on the initial computer program to obtain the corresponding computer program analysis results.
[0122] An anomaly coverage checking unit is used to determine at least one critical path in the initial computer program that meets preset criticality requirements, and to perform preset anomaly coverage checking operations on at least one critical path to obtain the corresponding coverage check results.
[0123] The similarity calculation unit is used to obtain the historical computer program corresponding to the natural language program requirement, calculate the computer program similarity between the historical computer program and the initial computer program, and perform a preset reuse effectiveness evaluation operation on the initial computer program based on the computer program similarity to obtain the corresponding evaluation result.
[0124] The second integration unit is used to integrate contract test results, computer program analysis results, coverage check results, computer program similarity and evaluation results to obtain quality inspection results.
[0125] Optionally, in one embodiment of this application, the iterative correction module 300 further includes: a judgment unit, a third integration unit, and an iteration unit.
[0126] The judgment unit is used to determine whether the initial computer program meets the preset quality inspection requirements based on the quality inspection results.
[0127] The third integration unit is used to determine the computer program defect type, defect location, repair suggestions, and defective computer program segment corresponding to the initial computer program when the initial computer program does not meet the preset quality inspection requirements, and to integrate the computer program defect type, defect location, repair suggestions, defective computer program segment, and model interface constraints to obtain the corresponding correction prompt words.
[0128] The iterative unit is used to re-input the correction prompts into the pre-trained natural language processing model to perform preset computer program correction operations on the initial computer program iteratively until the preset number of iterations is reached or the initial computer program after correction in the current iteration meets the preset quality requirements, so as to generate the target backend computer program.
[0129] Optionally, in one embodiment of this application, the back-end computer program generation apparatus 10 further includes: a fusion module, a screening module, a deviation analysis module, and a calibration module.
[0130] The fusion module is used to determine the application scenario information of the natural language processing model before inputting the enhanced prompt words into the pre-trained natural language processing model, and to construct the corresponding constraint-guided training benchmark based on the application scenario information. The constraint-guided training benchmark and the application scenario information are fused to generate the corresponding constraint-guided benchmark set.
[0131] The filtering module is used to acquire multi-source program-generated data based on application scenario information and natural language processing requirements, and to perform preset semantic purification and deviation correction operations on the multi-source program-generated data according to the constraint-guided benchmark set, so as to filter out the target multi-source program-generated data that meets the model interface constraints from the multi-source program-generated data, and to perform preset structured reconstruction processing on the target multi-source program-generated data to generate the training dataset of the natural language processing model.
[0132] The bias analysis module is used to input the training dataset into the natural language processing model to obtain the current model parameter iteration bias and semantic bias, and generate a corresponding bias analysis report based on the current model parameter iteration bias and semantic bias.
[0133] The calibration module is used to determine the corresponding dynamic parameter calibration strategy based on the deviation analysis report and the constraint-guided benchmark set, and to perform model parameter optimization operations on the natural language processing model iteratively based on the dynamic parameter calibration strategy until the natural language processing model meets the preset performance requirements or reaches the preset number of training iterations, so as to obtain the trained natural language processing model.
[0134] Optionally, in one embodiment of this application, the constraint determination module 100 includes: a parsing unit, a filtering unit, a sorting unit, a verification unit, and a fourth integration unit.
[0135] The parsing unit is used to parse the model interface constraints to obtain the corresponding parsed data, and extract multiple constraint elements corresponding to the parsed data to construct a set of corresponding constraint feature anchor points based on the multiple constraint elements.
[0136] The filtering unit is used to determine the target project to which the natural language program requirement belongs, and based on the set of constraint feature anchors, to perform a pre-defined targeted retrieval and bidirectional feature matching operation on the existing assets of the target project, and to filter out candidate assets associated with the constraint feature anchors to obtain the corresponding candidate asset set.
[0137] The sorting unit is used to perform preset hierarchical adaptation and correlation sorting operations on the candidate asset set to obtain the corresponding sorting results, and to delete redundant and missing assets that meet the preset constraint correlation requirements in the sorting results to generate the corresponding hierarchical adapted asset set.
[0138] The verification unit is used to build a two-way verification mechanism between the model interface constraints and the existing assets of the project. Based on the two-way verification mechanism and the model interface constraints, it performs adaptation integrity and availability verification on the hierarchical adaptation asset set to generate corresponding verification results. Based on the verification results, it performs preset dynamic calibration operations on the hierarchical adaptation asset set to obtain the calibrated hierarchical adaptation asset set.
[0139] The fourth integration unit is used to determine the execution scenario characteristics of the model interface constraints and perform a preset structured integration operation on the calibrated hierarchical adaptation asset set to obtain the corresponding integration results. The integration results and execution scenario characteristics are then combined to generate the project context.
[0140] Optionally, in one embodiment of this application, the constraint determination module 100 further includes an identification unit and a description unit.
[0141] The identification unit is used to identify the natural language program requirements of the target user, determine the model interface corresponding to the natural language program requirements, and determine the non-functional constraints corresponding to the model interface. The non-functional constraints include interface performance requirements, interface idempotency requirements, and interface security requirements.
[0142] The description unit is used to perform preset functional description operations on the model interface using the target interface description language to generate corresponding interface constraint description information, and to construct model interface constraints based on the interface constraint description information and non-functional constraints.
[0143] Optionally, in one embodiment of this application, the backend computer program generation apparatus 10 further includes an update module and a deployment module.
[0144] The update module is used to extract multiple program information corresponding to the target backend computer program, and perform a preset data comparison operation on the multiple program information and the interface document corresponding to the natural language program requirements to obtain the corresponding comparison results. Based on the comparison results, the interface document is updated to generate the unit test computer program and integration test stub computer program corresponding to the model interface constraints.
[0145] The deployment module is used to obtain the configuration information corresponding to the target backend computer program, and deploy the unit test computer program, integration test stub computer program and target backend computer program to the preset system backend environment according to the configuration information.
[0146] For a description of the features in the embodiment corresponding to the backend computer program generation apparatus, please refer to the relevant description in the embodiment corresponding to the backend computer program generation method, which will not be repeated here.
[0147] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any of the above-described backend computer program generation method embodiments.
[0148] Embodiments of this application also provide a non-volatile computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described backend computer program generation method embodiments at runtime.
[0149] In one exemplary embodiment, the aforementioned non-volatile computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0150] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described backend computer program generation method embodiments.
[0151] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described backend computer program generation method embodiments.
[0152] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0153] The foregoing has provided a detailed description of a backend computer program generation method, apparatus, device, and medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and core ideas of this application. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. A method for generating a backend computer program, characterized in that, Includes the following steps: Determine the model interface constraints corresponding to the natural language programming requirements of the target users, and then determine the project context corresponding to the model interface constraints; Combining the model interface constraints and the project context, prompt words for the interface implementation layer, data validation and object mapping layer, data interaction layer, exception handling layer, reuse analysis layer, and embedded quality convention are generated. Based on the prompt words of each layer, enhanced prompt words corresponding to the natural language program requirements are constructed, and the corresponding initial computer program is generated according to the enhanced prompt words. Based on the model interface constraints, a corresponding multi-dimensional quality detection mechanism is constructed. This mechanism performs preset automated quality detection operations on the initial computer program, generating contract test results, computer program analysis results, coverage check results, computer program similarity, and evaluation results. These results are then integrated to obtain the quality detection result of the initial computer program. Furthermore, in response to the quality detection result meeting preset computer program anomaly conditions, preset correction operations are iteratively performed on the initial computer program based on the quality detection result until the iteration process meets a preset iteration termination condition, generating a target backend computer program that meets the requirements of the natural language program. The step of constructing enhanced prompt words corresponding to the natural language program requirements based on prompt words at each layer includes: Semantic structured parsing is performed on the interface implementation layer prompts, the data verification and object mapping layer prompts, the data interaction layer prompts, the exception handling layer prompts, the reuse analysis layer prompts, and the embedded quality convention prompts to extract the constraint elements and functional orientation information of each layer prompts to obtain multi-layer prompt parsing results; Based on the model interface constraints and the project context, the priority and execution order of the parsing results of each layer of prompt words are marked, so as to assign the constraint weights and execution order identifiers corresponding to different levels of prompt words, and generate a hierarchical prompt word set with sequence and weight attributes; Based on preset hierarchical fusion rules, the hierarchical prompt word set is subjected to context association splicing and semantic deduplication operations to generate initial enhanced prompt words; The initial enhanced prompt words are subjected to constraint consistency verification and semantic fluency calibration to obtain corresponding calibration prompt words, and the calibration prompt words are standardized and encapsulated to generate the enhanced prompt words; The process of performing preset automated quality detection operations on the initial computer program through the multi-dimensional quality detection mechanism to generate contract test results, computer program analysis results, coverage check results, computer program similarity and evaluation results includes: Based on the model interface constraints and natural language code requirements, the corresponding business execution logic and interface execution chain are determined, and the model interface constraints and the business execution logic are parsed to extract the functional nodes and flow relationships in the interface execution chain, thereby obtaining the corresponding interface execution chain graph. The interface execution chain graph is then weighted and threshold-filtered to generate the corresponding critical path set. Construct an anomaly type system corresponding to the model interface constraints, perform bidirectional matching verification between the anomaly type system and the critical path set, generate a path-anomaly matching relationship table, and perform anomaly coverage statistics and compliance judgment based on the path-anomaly matching relationship table to obtain the coverage check results.
2. The backend computer program generation method according to claim 1, characterized in that, The step of constructing enhanced prompt words corresponding to the natural language program requirements by combining the model interface constraints and the project context includes: Based on the model interface constraints, the constraint requirements of the target backend computer program are determined, and the corresponding interface implementation layer prompt words are determined according to the constraint requirements; Obtain the parameter constraints in the model interface constraints, generate the corresponding data validation computer program based on the parameter constraints, and generate a data conversion object through the data validation computer program, so as to determine the corresponding data validation and object mapping layer prompt words based on the data conversion object; Based on the model interface constraints, a database security operation strategy is determined, and corresponding data interaction layer prompts are generated according to the database security operation strategy. Obtain the interface error response information corresponding to the model interface constraint, determine the exception handling mechanism corresponding to the interface error response information, and construct a corresponding global exception processor according to the exception handling mechanism to generate exception handling layer prompt words through the global exception processor. Based on the project context, the project computer program library corresponding to the natural language program requirements is analyzed to identify the corresponding reusable components, design patterns and common base classes, and corresponding reusable analysis layer prompt words are generated according to the reusable components, design patterns and common base classes; Based on the natural language program requirements, the corresponding computer program coding standards, security conventions, and architectural principles are determined, and corresponding internal constraints are constructed according to the computer program coding standards, security conventions, and architectural principles, so as to generate corresponding embedded quality convention prompt words through the internal constraints; The enhanced prompt words are constructed based on the interface implementation layer prompt words, the data verification and object mapping layer prompt words, the data interaction layer prompt words, the exception handling layer prompt words, the reuse analysis layer prompt words, and the embedded quality convention prompt words.
3. The back-end computer program generation method according to claim 2, characterized in that, The step of generating the corresponding initial computer program based on the enhanced prompt words includes: The enhanced prompt words are input into a pre-trained natural language processing model to generate an interface layer computer program and a data transmission object that satisfy the model interface constraints. The business rules and object-relational mapping specifications corresponding to the natural language program requirements are determined, and based on the preset programming logic and transaction declarations, a service layer computer program that satisfies the business rules and a data access layer computer program that satisfies the object-relational mapping specifications are generated. The initial computer program is constructed based on the interface layer computer program, the data transmission object, the service layer computer program, and the data access layer computer program.
4. The backend computer program generation method according to claim 1, characterized in that, The step of performing a preset automated quality detection operation on the initial computer program through the multi-dimensional quality detection mechanism to obtain the quality detection result of the initial computer program includes: The initial computer program is subjected to a preset contract test to obtain the corresponding contract test results. The initial computer program is then subjected to preset static analysis, security scanning and business rule checking operations in sequence to obtain the corresponding computer program analysis results. Identify at least one critical path in the initial computer program that meets preset criticality requirements, and perform a preset anomaly coverage check operation on the at least one critical path to obtain the corresponding coverage check result. Obtain the historical computer program corresponding to the natural language program requirement, calculate the computer program similarity between the historical computer program and the initial computer program, and perform a preset reuse effectiveness evaluation operation on the initial computer program based on the computer program similarity to obtain the corresponding evaluation result; The quality inspection result is obtained by integrating the contract test results, the computer program analysis results, the coverage check results, the computer program similarity, and the evaluation results.
5. The back-end computer program generation method according to claim 4, characterized in that, The step of iteratively performing preset correction operations on the initial computer program based on the quality detection results until the iteration process meets the preset iteration termination condition, thereby generating a target backend computer program that meets the requirements of the natural language program, includes: Based on the quality inspection results, determine whether the initial computer program meets the preset quality inspection requirements; In response to the initial computer program failing to meet the preset quality inspection requirements, the computer program defect type, defect location, repair suggestion, and defective computer program segment corresponding to the initial computer program are determined, and the computer program defect type, defect location, repair suggestion, defective computer program segment, and model interface constraints are integrated to obtain the corresponding correction prompt words; The corrected prompts are re-inputted into the pre-trained natural language processing model to perform preset computer program correction operations on the initial computer program iteratively until a preset number of iterations is reached or the corrected initial computer program in the current iteration meets the preset quality requirements, so as to generate the target backend computer program.
6. The back-end computer program generation method according to claim 3, characterized in that, Before inputting the enhanced prompt words into the pre-trained natural language processing model, the method further includes: The application scenario information of the natural language processing model is determined, and a corresponding constraint-guided training benchmark is constructed based on the application scenario information. The constraint-guided training benchmark and the application scenario information are then fused to generate a corresponding constraint-guided benchmark set. Based on the application scenario information and the natural language processing requirements, multi-source program generation data is obtained, and the multi-source program generation data is subjected to preset semantic purification and deviation correction operations according to the constraint-guided benchmark set, so as to select target multi-source program generation data that meets the model interface constraints from the multi-source program generation data, and the target multi-source program generation data is subjected to preset structured reconstruction processing to generate the training dataset of the natural language processing model. The training dataset is input into the natural language processing model to obtain the current model parameter iteration bias and semantic bias corresponding to the natural language processing model, and a corresponding bias analysis report is generated based on the current model parameter iteration bias and semantic bias. Based on the deviation analysis report and the constraint-guided benchmark set, a corresponding dynamic parameter calibration strategy is determined. Based on the dynamic parameter calibration strategy, the natural language processing model is iteratively optimized until the natural language processing model meets the preset performance requirements or reaches the preset number of training iterations, so as to obtain a trained natural language processing model.
7. The back-end computer program generation method according to claim 1, characterized in that, Determining the project context corresponding to the model interface constraints includes: The model interface constraints are parsed to obtain the corresponding parsed data, and multiple constraint elements corresponding to the parsed data are extracted to construct a set of corresponding constraint feature anchor points based on the multiple constraint elements. The target project to which the natural language program requirement belongs is determined, and based on the set of constraint feature anchors, the existing assets of the target project are subjected to a preset targeted retrieval and bidirectional feature matching operation to filter out candidate assets associated with the constraint feature anchors, so as to obtain the corresponding candidate asset set. The candidate asset set is subjected to preset hierarchical adaptation and correlation sorting operations to obtain the corresponding sorting results. Redundant and missing assets that meet the preset constraint correlation requirements in the sorting results are deleted to generate the corresponding hierarchical adaptation asset set. A two-way verification mechanism is constructed between the model interface constraints and the existing assets of the project. Based on the two-way verification mechanism and the model interface constraints, the hierarchical adaptation asset set is verified for adaptation integrity and availability to generate corresponding verification results. Based on the verification results, a preset dynamic calibration operation is performed on the hierarchical adaptation asset set to obtain a calibrated hierarchical adaptation asset set. The execution scenario characteristics of the model interface constraints are determined, and a preset structured integration operation is performed on the calibrated hierarchical adaptation asset set to obtain the corresponding integration result. The integration result and the execution scenario characteristics are then fused to generate the project context.
8. The back-end computer program generation method according to claim 1, characterized in that, The model interface constraints corresponding to the natural language program requirements of the target user include: Identify the natural language program requirements of the target user, determine the model interface corresponding to the natural language program requirements, and determine the non-functional constraints corresponding to the model interface, wherein the non-functional constraints include interface performance requirements, interface idempotency requirements, and interface security requirements; The model interface is described using a target interface description language to generate corresponding interface constraint description information, and the model interface constraints are constructed based on the interface constraint description information and the non-functional constraints.
9. The back-end computer program generation method according to claim 5, characterized in that, After generating the target backend computer program, the process also includes: Extract multiple program information corresponding to the target backend computer program, and perform a preset data comparison operation on the multiple program information and the interface document corresponding to the natural language program requirements to obtain the corresponding comparison results. Update the interface document according to the comparison results to generate the unit test computer program and integration test stub computer program corresponding to the model interface constraints. Obtain the configuration information corresponding to the target backend computer program, and deploy the unit test computer program, the integration test stub computer program, and the target backend computer program to the preset system backend environment according to the configuration information.
10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the back-end computer program generation method as described in any one of claims 1 to 9.
Citation Information
Patent Citations
Code generation and evaluation method and system based on RAG and multilevel decision tree
CN121478244A