Code generation method and device, electronic equipment and readable storage medium

By analyzing user requirements and generating code using a target model, the inefficiency of manually writing code in operations research project development is solved, achieving automated code generation and improving code accuracy and stability.

CN121785581APending Publication Date: 2026-04-03新奥新智科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-21
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

In existing technologies, the development of operations research projects relies on manual coding, which leads to low development efficiency and the existence of human misunderstanding bias and errors.

Method used

The system analyzes user requirements information using a target model, generates target statements, and automatically generates code based on an operations research model template and a preset configuration file, avoiding manual intervention.

Benefits of technology

It improves code accuracy and stability, reduces later maintenance costs, and enhances development efficiency and code automation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121785581A_ABST
    Figure CN121785581A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code generation method and device, electronic equipment and a readable storage medium, and the method comprises the steps: determining a target statement based on user demand information input by a target user and a supplementary demand replied by a target conversation initiated by the target user according to a target model; generating a target intermediate file based on a target operation model template matched with the target statement; and generating a target code based on the target intermediate file and a preset configuration file. In this way, the user demand information input by the target user and the supplementary demand replied by the target dialogue are accurately analyzed by using the target model, the target statement is determined, manual understanding deviation is avoided, and demand accuracy is ensured. The target operation model template is automatically matched according to the target statement to generate the target intermediate file, and the target code is generated in combination with the preset configuration file, so that manual modeling and coding processes are avoided, errors caused by manual intervention can be reduced, the code accuracy and stability are improved, and the later maintenance cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a code generation method, apparatus, electronic device, and readable storage medium. Background Technology

[0002] In today's era of rapid digital and intelligent development, operations research plays a crucial role in solving complex planning and optimization problems, and is widely applied in various fields such as logistics scheduling, production planning, and resource allocation. As business scenarios become increasingly complex, higher demands are being placed on the development efficiency, versatility, and scalability of operations research projects.

[0003] In related technologies, the development process of operations research projects often relies on developers manually writing code and designing test cases to test the code based on user requirements. However, this development approach requires manual intervention at every stage, resulting in low overall development efficiency. Summary of the Invention

[0004] To overcome the problems existing in related technologies, the present invention provides a code generation method, apparatus, electronic device, and readable storage medium.

[0005] In a first aspect, the present invention provides a code generation method, the method comprising: The target statement is determined based on the user demand information input by the target user and the supplementary demands responded by the target user in the target dialogue initiated by the target model; Based on the target operations research model template that matches the target statement, generate the target intermediate file; Based on the target intermediate file and the preset configuration file, target code is generated.

[0006] In a second aspect, the present invention provides a code generation apparatus, the apparatus comprising: The first determining module is used to determine the target statement based on the user demand information input by the target user and the supplementary demands responded by the target user in the target dialogue initiated by the target model; The first generation module is used to generate a target intermediate file based on a target operations model template that matches the target statement; The second generation module is used to generate target code based on the target intermediate file and the preset configuration file.

[0007] Thirdly, the present invention provides an electronic device comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the code generation method described in any one of the first aspects above.

[0008] Fourthly, the present invention provides a readable storage medium that, when the instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to perform the steps of the code generation method as described in any of the embodiments of the first aspect above.

[0009] In this embodiment of the invention, a target statement is determined based on user requirement information input by the target user and supplementary requirements responded to by the target user in a target dialogue initiated by the target model. A target intermediate file is generated based on a target operations model template matching the target statement. Target code is then generated based on the target intermediate file and a preset configuration file. This approach utilizes the target model to accurately analyze the user requirement information input by the target user and the supplementary requirements responded to in the target dialogue, determining the target statement and avoiding human interpretation biases, ensuring accurate understanding of the requirements. Furthermore, the target intermediate file is automatically generated based on the target statement and matched with the target operations model template, and then combined with the preset configuration file to generate the target code. This fully automated process avoids manual modeling and coding, reducing errors caused by human intervention, improving code accuracy and stability, and lowering later maintenance costs. Attached Figure Description

[0010] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0011] Figure 1 This is a flowchart of the steps of a code generation method provided in an embodiment of the present invention; Figure 2 This is a structural diagram of a code generation device provided in an embodiment of the present invention; Figure 3 This is a structural diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0013] Figure 1 This is a flowchart of the steps of a code generation method provided in an embodiment of the present invention, as follows: Figure 1 As shown, the method may include: Step 101: Determine the target statement based on the user demand information input by the target user and the supplementary demands responded by the target user in the target dialogue initiated by the target model.

[0014] In this embodiment of the invention, the target user organizes user requirement information into a requirement document. This requirement information may include target requirement parameters such as project background, project type, business constraints, and optimization goals. The project background outlines the reasons and general circumstances for the project; for example, in a logistics and delivery project, the background might be the need to optimize delivery routes to improve service efficiency due to business expansion into a new area. Business constraints are the rules that must be followed during project implementation; for example, in the field of natural gas supply and demand matching, some city gas companies have requirements such as weight limits and delivery ranges, which must be met as a business constraint. Optimization goals define the expected results of the project; for example, in a logistics and delivery project, optimization goals might be reducing delivery costs and improving on-time delivery rates. Simultaneously, the target user can provide relevant tables and fields of dependent data to the target model along with the user requirement information. For example, in a logistics and delivery scenario, the target user can provide a data table containing fields such as delivery location, quantity of goods, and delivery time. The target model then comprehensively understands the user requirement information and constructs a preliminary requirement cognition framework.

[0015] After the target model has initially grasped the requirements, it can interact with a knowledge base for any unclear parts. The knowledge base stores knowledge information related to different types of business. By interacting with the knowledge base, the target model can obtain reference information related to the user's needs to further understand the requirements. However, if unclear details of the requirements remain after interacting with the knowledge base, the target model can automatically initiate multi-turn dialogues with the target user, asking questions to clarify the ambiguous requirements. For example, when a user requests "optimize logistics delivery routes," the target model will further ask questions such as "Is the delivery range within the city or across cities?" "Are there vehicle weight restrictions?" "Is the delivery time window considered?" Through these questions, the user's ambiguous requirements can be gradually clarified, such as determining that the delivery range is within the city, the vehicle weight limit is 5 tons, and the delivery time window needs to be considered between 9 am and 6 pm as supplementary requirements.

[0016] Furthermore, when processing user demand information, the target model will further clarify any contradictory information within that demand. For example, in the field of natural gas demand matching, the user's input indicates that some city gas companies' demands must be met, while the goal is to maximize profits. There may be a contradiction between "must meet the city gas companies' demands" and "profit maximization," because meeting some city gas companies' demands could increase costs and affect profits. Therefore, the target model can ask the target user the question, "Is it acceptable to lose money when demanding certain demands?" This clarifies the handling principles specified by the target user when facing contradictory situations.

[0017] Furthermore, after parsing the user's demand information, the target demand parameters can be obtained. These parameters, along with the supplementary demands from the target user's responses via dialogue, are then transformed into operations research language descriptions. These operations research language descriptions can utilize relevant theories and methods from operations research to precisely and formally express the demands; for example, using mathematical models to describe route planning problems in logistics and distribution.

[0018] The target model generates target statements based on the operations research language description obtained in the requirements analysis phase. These target statements can be Data Definition Language (DDL) statements used to define the database structure, such as creating tables and modifying table structures. Data tables are then newly constructed using these target statements. These data tables can be divided into two categories: one is for user data collection, such as a "delivery demand table" in a logistics delivery scenario. This table contains fields such as demand ID (to uniquely identify each delivery demand), delivery location (specifying the specific location where the goods should be delivered), quantity of goods (determining the amount of goods to be delivered), and demand time (the user's expected delivery time), used to collect actual user delivery demand information. The other category is for algorithm modeling, such as a "vehicle scheduling algorithm interface table." This table contains fields such as algorithm ID (identifying different vehicle scheduling algorithms), input parameters (data required for algorithm operation, such as delivery location and quantity of goods), output parameters (results generated after algorithm operation, such as optimal delivery route and estimated delivery time), and call frequency (limiting the number of times the algorithm interface can be called), providing data interface support for subsequent algorithm modeling and operation.

[0019] Step 102: Generate the target intermediate file based on the target operations model template that matches the target statement.

[0020] In this embodiment of the invention, the operations research model template can be a pre-defined model framework with a general structure and logic. Different types of templates are suitable for optimization problems with different characteristics and complexities. Based on the project characteristics described by the target statement, such as the project scale, variable types, and constraint complexity, a matching target operations research model template is selected from multiple templates. The operations research model template can include mixed integer programming model templates, heuristic operations research model templates, and general optimization model templates. For example, in a logistics delivery scenario, if the target statement is used to solve for the optimal delivery route to minimize cost, and the problem involves discrete decision variables (such as whether a vehicle goes to a delivery point) and continuous variables (such as transportation volume), then a mixed integer programming model template is more suitable because it can handle optimization problems that simultaneously contain integer and continuous variables. If the problem is large in scale and complex in structure, making it difficult to solve using algorithms within a reasonable time, a heuristic operations research model template is more appropriate, as it can quickly find an approximate optimal solution through heuristic rules. For example, the content of a mixed integer programming model template can be as follows: { "set_config":{}, # Set definition "param_config:{}, # Constant definition "decision_var_config:{},# Decision variable "constraint_config":{}, # Constraint definition "object_config":{} # Target function definition } Based on the requirements analysis results and the data table structure built during the data creation phase, the operations research logic is constructed and the target intermediate file is generated. The data table structure stores various data information related to the problem, such as delivery locations, cargo demand, and vehicle information in logistics and distribution. Using the selected target operations research model template as a framework, the system maps the key elements of the problem into the model. For example, after selecting a mixed integer programming model template for logistics and distribution optimization requirements, the system determines the objective function. The objective function is the core of the optimization problem, defining the direction of optimization, such as "minimizing the total delivery cost," which can include vehicle transportation costs, warehousing costs, etc. Next, the decision variables are determined. Decision variables are unknown quantities that need to be determined during the optimization process, such as "the amount of transportation by vehicles from the distribution center to each delivery point." The optimal solution is found by adjusting the values ​​of the variables. At the same time, constraints are defined. Constraints restrict the decision variables to ensure the feasibility and rationality of the solution, such as "the cargo demand of each delivery point must be met" to ensure that each delivery point receives sufficient cargo, and "vehicle load limits" to prevent vehicles from overloading.

[0021] The operational logic, including the objective function, decision variables, and constraints, is organized into a target intermediate file according to a specific format and specification. This intermediate file can be in JSON (JavaScript Object Notation) or YAML (YAML Ain't Markup Language) format. The target intermediate file serves as a bridge connecting the operational model and subsequent algorithm implementation, containing complete operational logic information. For example, operational logic elements can be categorized and organized based on the framework of the target operational model template. Operational logic elements refer to the specific business entities involved in the target statement, the relationships between them, and related parameters and constraints. For instance, business entities such as distribution centers and customer points can be treated as nodes, and the transportation and delivery relationships between them as edges. Furthermore, cargo volume, transportation costs, and delivery time constraints can be used as attributes of nodes or edges. In this way, the originally scattered operational logic elements are organized into a hierarchical and clearly structured data set. For example, the JSON format can be shown as follows: { "set_config":{}, # Set definition "param_config:{}, # Constant definition "decision_var_config:{},# Decision variable "constraint_config":{}, # Constraint definition "object_config":{} # Target function definition } Step 103: Generate target code based on the target intermediate file and the preset configuration file.

[0022] In this embodiment of the invention, after obtaining the target intermediate file, preprocessing and postprocessing can be performed on the target intermediate file. Preprocessing may include dependency field injection and logical tag field injection. Postprocessing may include adding runtime parameters, such as solver parameters, weight settings, and custom function configurations, to the preprocessed target intermediate file. The preprocessed and postprocessed target intermediate file is parsed, and tools, such as Python AST abstract syntax tree generation tools, are used to transform the operations research logic in the target intermediate file into an abstract syntax tree structure. Based on the generated abstract syntax tree structure, it can be further transformed into actual executable target code. Based on the rich syntactic and semantic information contained in the abstract syntax tree, code generation algorithms and tools are used to convert each node and branch in the abstract syntax tree into specific programming language code (such as Python code), obtaining the target code. The target code is used to implement functions such as modeling, solving, and result processing of operations research optimization problems, and can adapt to actual operating environments and complex business needs.

[0023] In one possible implementation, a template engine (such as Jinja2) can be used to generate the target code. For example, by passing the operational logic parameters (such as the objective function expression and the number of constraints) to a preset Jinja2 template, the complete code is directly rendered to obtain the target code.

[0024] In summary, in this embodiment of the invention, the target statement is determined based on the user requirement information input by the target user and the supplementary requirements responded by the target user in the target dialogue initiated by the target model; a target intermediate file is generated based on the target operation model template that matches the target statement; and target code is generated based on the target intermediate file and a preset configuration file. In this way, the target model is used to accurately parse the user requirement information input by the target user and the supplementary requirements responded by the target dialogue to determine the target statement, avoiding human interpretation bias and ensuring accurate understanding of the requirements. Furthermore, the target intermediate file is automatically generated based on the target statement and matched with the target operation model template, and then the target code is generated by combining it with the preset configuration file. This fully automated operation avoids manual modeling and coding processes, reducing errors caused by human intervention, improving code accuracy and stability, and lowering later maintenance costs.

[0025] Optionally, step 101 may include the following steps: Step 201: Perform semantic analysis on the user demand information input by the target user to obtain target demand parameters; the target demand parameters include project type, business constraints, and optimization objectives.

[0026] In this embodiment of the invention, the target user inputs user requirement information, and the target model performs semantic analysis on the user requirement information to identify key information. Target requirement parameters are extracted from the structured data output by the target model. These target requirement parameters include project type, business constraints, and optimization objectives. The extracted target requirement parameters are integrated to form a complete and accurate set of target requirement parameters, providing clear and explicit guidance for subsequent model construction and code generation.

[0027] Step 202: Based on the target model, ask the target user supplementary questions according to the target requirement parameters, and obtain the target user's supplementary requirements in response.

[0028] In this embodiment of the invention, the target model uses a built-in logical judgment mechanism to identify potentially ambiguous, incomplete, or further refined parts of the target requirement parameters. The target model then generates supplementary questions based on a preset questioning strategy. These supplementary questions guide the target user to provide more detailed and accurate information to refine the requirement description. The questioning strategy may include designing questions based on the criticality and ambiguity of the parameters, as well as common requirements in the business scenario. The target model presents the generated supplementary questions to the target user in natural language. The user responds with supplementary requirement information via input devices (such as keyboards, voice input, etc.). The system receives and records the supplementary responses, providing data support for subsequent processing. This supplementary questioning mechanism based on the target model ensures that the target requirement parameters are more complete and accurate, reducing subsequent development errors caused by unclear requirements.

[0029] Step 203: Based on the preset terminology library corresponding to the project type, map the target requirement parameters and the business terms contained in the supplementary requirements into business rules.

[0030] In this embodiment of the invention, a pre-built terminology library is constructed for different project types. This library contains common professional business terms and related business rules within the relevant field. Upon obtaining the target requirement parameters and the supplementary requirements from the target user, a business terminology mapping process is initiated. First, the text in the target requirement parameters and supplementary requirements is segmented into individual words. Then, a pre-built terminology recognition algorithm is used to identify business terms and corresponding business rules belonging to the pre-built terminology library from the segmentation results. For example, when processing the requirements of a logistics and delivery project, the term "take-or-pay" is identified. Once a business term is identified, the corresponding business rules are retrieved from the pre-built terminology library. For instance, for "take-or-pay," the system retrieves its meaning as "regardless of whether the buyer actually picks up the goods, for the portion used being less than 80%, payment must be made according to the quantity and price agreed upon in the contract," and extracts business rules such as "payment according to the agreed quantity," "payment according to the agreed price," and "unrelated to the quantity picked up." Finally, the system stores and organizes the business rules in a structured form (such as JSON format) so that they can be accurately invoked when building operational models and generating code, ensuring the correct implementation of business logic in the system.

[0031] Step 204: Generate the target statement based on the business constraints, the optimization objectives, the supplementary requirements, and the business rules.

[0032] In this embodiment of the invention, the large model transforms the business description into a language understandable by operations research, which is a crucial step. Specifically, this includes data mapping, clarifying the correspondence between business data and operations research model data. For example, in an energy trading project, "sales revenue" in the business is mapped to "gas matching quantity demand price" in the model, and gas cost is mapped to "resource price gas matching quantity." This mapping establishes a connection between actual business data and variables in the operations research model.

[0033] For example, the target model identifies sets of information such as users who must be satisfied, users who can be satisfied with the minimum amount, resources that must be allocated, contracted capacity, and uncontracted capacity. In vehicle dispatching, for instance, it clarifies which customers must receive on-time delivery, which customers can have their delivery appropriately delayed, and which vehicle resources must be deployed. Regarding implicit constraint extraction, the large model uncovers constraints not explicitly mentioned in the business description but actually existing. For example, in a vehicle delivery scenario, there might be an implicit constraint such as "vehicle delivery time must not exceed the driver's working hours." Simultaneously, the large model categorizes constraints into hard constraints that must be satisfied and soft constraints that should be satisfied as much as possible, based on the constraint description. For example, "vehicle weight limit" is a hard constraint that must be strictly adhered to; "shortest delivery route" is a soft constraint that should be optimized as much as possible while satisfying other conditions. For hard constraints that are difficult to strictly satisfy, the target model can set slack variables, such as allowing vehicles to exceed their weight limit by 5% under special circumstances, and quantifying the degree of overweight through slack variables. Through these operations, the target model can transform complex business information into a precise language description that operations research can process.

[0034] Based on the transformed operations research language description, target statements are generated. These target statements are the core instructions used for subsequent operations research model building, code generation, and other operations. According to different business scenarios and requirements, and following preset syntax rules and logical structures, key information from the operations research description, such as business constraints, optimization objectives, set information, and constraint types, is organized into complete target statements. For example, in a production scheduling project, based on the previously transformed operations research description, the generated target statement might include the meaning of "under the premise of satisfying the equipment usage time limits (hard constraints) and raw material supply limits (hard constraints) of each production line, with the goal of minimizing the total production cost (optimization objective), optimizing the scheduling of the production quantity (decision variables) of different products, allowing some production tasks to be appropriately delayed under special circumstances (setting slack variables)."

[0035] The entire process, through in-depth analysis and intelligent transformation of the target model, as well as target statement generation logic, achieves the transformation from complex business information to precise target statements, effectively improving development efficiency and accuracy, and reducing errors and deviations that may occur during manual processing.

[0036] Optionally, embodiments of the present invention may further include the following steps: Step 301: Generate a first similarity vector based on the business constraints, the optimization objective, the supplementary requirements, and the business rules.

[0037] In this embodiment of the invention, the collected information undergoes feature extraction and quantization processing, transforming different types of information into computable feature vectors. For example, for business constraints, features such as the type of constraint (e.g., time constraint, resource constraint, etc.) and the numerical range of the constraint are extracted; for optimization objectives, features such as the type of objective (e.g., cost minimization, profit maximization, etc.) and the priority of the objective are extracted. Then, these feature vectors of different dimensions are fused to generate a first similarity vector.

[0038] Step 302: If the similarity between the first similarity vector and the similarity vector corresponding to any existing project is greater than a preset threshold, generate the target statement based on the project statement corresponding to the existing project.

[0039] In this embodiment of the invention, the generated first similarity vector is compared with the similarity vector corresponding to an existing project. Various algorithms can be used for similarity calculation, such as cosine similarity algorithm and Euclidean distance algorithm, to measure the degree of similarity between two vectors by calculating the angle or distance between them. When the similarity between the first similarity vector and the similarity vector corresponding to any existing project is greater than a preset threshold, it indicates that the current project and the existing project have a high degree of similarity in business characteristics and requirements, and the existing project can be used as a reference project. The project statement corresponding to the reference project is then automatically obtained. The project statement is an accurate description of the core business logic and requirements of the reference project, including the objective function, constraints, etc. Then, the project statement of the reference project is analyzed and understood using the target model. Combined with the business constraints, optimization objectives, supplementary requirements, and business rules of the current project, a detailed comparative analysis of the data requirements of the current project and the existing project is performed, including the addition or removal of fields, changes in field data types, and adjustments to field constraints. The project statement is then appropriately adjusted and optimized to generate a target statement suitable for the current project.

[0040] For example, taking the "Vehicle Information Table" as an example, an existing project's "Vehicle Information Table" includes vehicle ID, load capacity, and volume fields. The current project, in addition to the above basic information, also needs to record vehicle fuel consumption. The difference in table structure between the current project and similar projects lies in the addition of a "Vehicle Fuel Consumption" field. To address this difference, the statement "ALTER TABLE Vehicle Information Table ADD COLUMN Vehicle Fuel Consumption FLOAT" is generated. Here, "ADD COLUMN Vehicle Fuel Consumption FLOAT" indicates that a column named "Vehicle Fuel Consumption" will be added, with its data type being FLOAT (floating-point type).

[0041] Accordingly, step 204 may include: Step 303: If the similarity between the first similarity vector and the similarity vector corresponding to any existing project is less than or equal to the preset threshold, generate a target statement based on the business constraints, the optimization objective, the supplementary requirements, and the business rules.

[0042] In this embodiment of the invention, when the similarity between the first similarity vector and the similarity vector corresponding to any existing project is less than or equal to a preset threshold, it indicates that the current project and the existing project have significant differences in business characteristics and requirements, and a suitable reference project cannot be found. Therefore, the target statement can be generated directly using a large model based on the current project's business constraints, optimization goals, supplementary requirements, and business rules.

[0043] For example, the target model automatically constructs the table structure based on user requirements and pre-defined table creation plans and processes in the background. The table structure defines the composition of the data table, including table name, column names, data types, constraints, etc. Taking user requirements as an example, after analysis, the large model determines the table name to be "Customer Order Table", and the column names to be "Order ID", "Customer Name", "Order Amount", and "Order Time". According to preset rules, appropriate data types are selected for each column, such as "Order ID" as INT (integer type), "Customer Name" as VARCHAR(50) type, "Order Amount" as DECIMAL(10,2) type (used to store decimal numbers with two decimal places), and "Order Time" as DATETIME (date and time type). At the same time, "Order ID" is set as the primary key according to user requirements. After the table structure is constructed, the large model converts it into the corresponding CREATE DDL statement, namely "CREATE TABLE Customer Order Table (Order ID INT PRIMARY KEY, Customer Name VARCHAR (50), Order Amount DECIMAL (10,2), Order Time DATETIME)".

[0044] In this embodiment of the invention, through the mechanism of similarity vector matching and intelligent generation of target sentences, target sentences suitable for the current project can be generated efficiently and accurately according to different situations. This realizes the transformation from user natural language requirements to target sentences, effectively reduces the threshold of data table development, and provides a solid foundation for subsequent operations research model construction and solution.

[0045] Optionally, embodiments of the present invention may further include the following steps: Step 401: Based on the user requirement information, the target intermediate file, and the target code, automatically generate test cases.

[0046] In this embodiment of the invention, user requirement information includes the functions and conditions that the code needs to implement. For example, in a logistics and delivery system, user requirement information includes key information such as delivery range and delivery time requirements. The target intermediate file is an intermediate product generated during software development, used to record key data and logic from requirements to code implementation, including intermediate calculation results of algorithms and definitions of data structures. The target code is the final program code to be run. Based on the user requirement information, the target intermediate file, and the target code, test cases are automatically generated. The test cases can cover normal business scenarios, boundary scenarios, and abnormal scenarios.

[0047] For example, taking a logistics and distribution system as an example, normal business scenarios include logistics and distribution needs that meet all constraints, such as the weight of goods and delivery time. Boundary scenarios include situations where the vehicle's load capacity just reaches the limit or the order amount is at the threshold of segmented pricing. Abnormal scenarios include situations where there are no available vehicles at the delivery point or data is missing. Assuming that the constraint "vehicle load capacity is limited to 5 tons" is applied, the target model will generate test cases for "total weight of delivered goods is 5 tons" (boundary scenario) and "total weight of delivered goods is 6 tons" (abnormal scenario). At the same time, it will specify the input data (such as delivery point, quantity of goods, and vehicle information) and expected output results (such as the optimal delivery route in normal scenarios and error messages in abnormal scenarios) for each test case.

[0048] Step 402: Obtain the code execution results corresponding to the test cases.

[0049] In this embodiment of the invention, the data is input into the target code according to the input data specified in the test cases, and the code execution results are obtained. In the logistics and distribution optimization scenario, the intelligent agent device will run the target code according to the input data such as delivery points, goods quantity, and vehicle information set in the test cases, and output key indicators such as "total delivery cost", "delivery time", and "vehicle utilization rate". These indicators are used as the code execution results, which can reflect the performance of the target code in the actual operation process.

[0050] Step 403: If the code execution result is inconsistent with the expected result, modify the target intermediate file based on the code execution result, and regenerate the target code based on the modified target intermediate file and the preset configuration file.

[0051] In this embodiment of the invention, when the code execution result is inconsistent with the expected result, it indicates that there is a problem with the current target code. At this time, the target intermediate file is modified based on the code execution result. Then, the target code is regenerated based on the new target intermediate file and the preset configuration file. By modifying the target intermediate file, the parameters and configuration information required for code execution can be adjusted, thereby correcting the code's execution logic. The target intermediate file, as an important intermediate product in the code development process, directly affects the generation of the target code. For example, if the total delivery cost in the code execution result exceeds expectations, analysis reveals an error in reading the transportation unit price parameter. In this case, the part of the target intermediate file related to reading the transportation unit price parameter is modified. The modified target intermediate file, combined with the preset configuration file, is used to regenerate the target code. The preset configuration file may contain various rules and parameter settings for code generation, ensuring that the regenerated target code can correct previous problems. Through this iterative modification and regeneration method, the code is gradually optimized to meet the expected requirements.

[0052] Step 404: If the code execution result is consistent with the expected result, generate the target project file based on the target code, data access code, preprocessing code, common dependency files, and unified dependency method file.

[0053] In this embodiment of the invention, when the code execution result is consistent with the expected result, it indicates that the target code has met the business requirements. At this point, the target project file is further generated based on the target code, data access code, preprocessing code, common dependency files, and unified dependency method files.

[0054] Based on the data table structure, data access code adapted to mainstream databases (such as MySQL and PostgreSQL) is automatically generated. This data access code provides an interface for interacting with the database. For example, for the "delivery demand table," a "data query (SELECT)" function like "get_delivery_demand (demand_id)" will be generated, allowing users to retrieve specific delivery information by passing in the demand ID. Generating data access code ensures that the project can accurately retrieve the required data from the database, providing data support for subsequent business processing.

[0055] Preprocessing code ensures that the data input to the algorithm conforms to specifications. It enables various data processing functions, such as data cleaning (removing outliers like negative delivery volumes to ensure data rationality and validity), data format conversion (converting time strings like '2024-05-20' to datetime format for easier subsequent time calculations and processing), and data normalization (e.g., converting vehicle load (tons) to kilograms to ensure comparability across different data volumes). During the generation of the target project file, the preprocessing code works closely with the target code, preprocessing the data retrieved from the database before inputting it into the target code for business logic calculations, ensuring a smooth data processing flow throughout the project.

[0056] The automatically generated code files are scanned to identify and export dependent third-party libraries (such as the "PuLP" library for operations research and the "Pandas" library for data processing) and custom utility classes (such as "cost calculation utility class" and "constraint verification utility class"), which are then compiled into a "requirements.txt" public dependency file. This public dependency file specifies the external resources that the project depends on. Including these dependencies in the generated target project files ensures that the project can correctly load and use these dependencies during deployment and runtime, preventing project malfunctions due to missing dependencies.

[0057] Extract frequently called methods from the target code (such as "calculate the distance between two points" or "check if constraints are met") and integrate them into a unified dependency method file, such as "common_utils.py". This avoids redundant method definitions, reduces code redundancy, and improves code maintainability and readability. The unified dependency method file is then included in the generated target project files, allowing various parts of the project to easily call it, thus achieving code reuse and sharing.

[0058] The target code, data access code, preprocessing code, common dependency files, unified dependency method files, and runtime verification reports are automatically compressed into a single archive, which serves as the target project file. For example, the archive can be categorized and stored as "code / " (code folder), "dependencies / " (dependency folder), and "report / " (report folder), facilitating direct decompression and deployment by users. This allows users to quickly find the files and resources they need. For instance, after decompression, users can directly access the "code / " folder to view and modify the code, the "dependencies / " folder to manage the project's dependency libraries, and the "report / " folder to view the project's runtime verification reports, understanding the project's operational status and performance metrics.

[0059] In this embodiment of the invention, by generating and running test cases, the correctness of the code can be ensured before code deployment, thus avoiding deployment failures caused by code defects.

[0060] Optionally, step 103 may include the following steps: Step 501: Inject dependency fields and logical tag fields into the target intermediate file and add target runtime parameters to obtain the preprocessed file.

[0061] In this embodiment of the invention, dependency fields and logical marker fields are injected into the target intermediate file. Dependency field injection is based on the dependency relationships between JSON elements. For example, in complex operations optimization problems, different fields are often closely related. In logistics delivery optimization scenarios, route planning may depend on the geographical location information of the delivery location and attributes such as the weight and volume of the goods. Through dependency field injection, the system automatically injects some key attributes of the dependent fields, such as geographical coordinates and cargo weight values, into the dependent fields. This reduces the coupling and dependency between different parts during subsequent code generation, making the code structure clearer, more independent, and easier to maintain and modify.

[0062] Operations research optimization problems typically involve multiple logical blocks. For example, the objective function block defines the direction of optimization (e.g., minimizing cost or maximizing profit), and the constraint block limits the range of decision variables (e.g., the vehicle's load cannot exceed its rated value). Adding marker fields, such as "objective function marker" and "constraint marker," to different logical blocks in the intermediate target file—this is called logical marker field injection—provides clear guidance for subsequent code parsing and generation processes, enabling the system to accurately identify and process each logical block.

[0063] After injecting dependency fields and logical marker fields into the target intermediate file, target runtime parameters are added. These parameters can include solver parameters, weight settings, and custom function configuration parameters. Solver parameters configure the settings of the solver used in the optimization process, such as the number of iterations and convergence accuracy. Different solvers have different parameter configuration requirements, and setting these parameters appropriately can affect the efficiency and quality of the solution. Weight settings are for multi-objective optimization problems. When there are multiple optimization objectives (such as simultaneously considering minimum cost and maximum service quality), setting weights for different objectives can adjust the importance of each objective in the optimization process. Custom function configurations are for cases with complex module logic. Since relying entirely on large model code generation for some complex modules is prone to errors, modules can be saved using pre-built configuration files. The large model passes parameters and uses function calls to fully embed these pre-built modules into the overall code. For example, if a tiered pricing feature exists, a rule can be set through custom feature configuration such as "when the order amount exceeds 1,000 yuan, the discount rate is 0.9; otherwise, the discount rate is 1.0", ensuring that the generated code can accurately implement complex business logic.

[0064] After injecting dependency fields and logical tag fields into the target intermediate file and adding the target runtime parameters, a preprocessed file can be obtained.

[0065] Step 502: Construct the target syntax tree based on the preprocessed file.

[0066] In this embodiment of the invention, an abstract syntax tree (AST) generation tool is used to transform the operational logic in the preprocessed file into an AST structure. An AST is a tree-like structure used to represent the structure of program source code, capable of displaying various syntactic elements in the code and their interrelationships. During the process of transforming the operational logic into an AST, several key methods are generated, including: main flow method generation, set creation method generation, constant creation method generation, decision variable creation and initialization method generation, objective function creation method generation, constraint condition creation method generation, and custom constraint generation.

[0067] The methods for creating sets are used to generate common set types in operations research and optimization, such as sets of delivery locations and vehicles in logistics and distribution problems. The methods for creating constants are used to define fixed values ​​in the problem, such as fixed vehicle costs or fixed coordinates of distribution centers. The methods for creating and initializing decision variables are used to determine decision variables in the optimization problem and assign them initial values; for example, in production scheduling problems, decision variables might be the start and end times of each production task on various machines. The methods for creating objective functions are used to construct the objective function of the optimization problem, clarifying the direction and objective of optimization. The methods for creating constraints are used to define various restrictions that decision variables need to satisfy to ensure the feasibility and rationality of the solution. The methods for generating custom constraints are used to generate corresponding constraints for some special business logic that cannot be expressed by conventional constraints.

[0068] The main process method generation includes key steps such as data reading, data preprocessing, and model construction, and is responsible for coordinating and executing the entire optimization process. The generated abstract syntax tree structure can fully express the entire process from data reading and model building to optimization solution and result output, laying the foundation for the final generation of executable target code.

[0069] Step 503: Generate the target code based on the target syntax tree.

[0070] In this embodiment of the invention, the target syntax tree is transformed into actual executable target code. Utilizing the syntactic and semantic information contained in the target syntax tree, code generation algorithms and tools are used to convert each node and branch in the target syntax tree into specific programming language code (such as Python code), thus obtaining the target code.

[0071] In this embodiment of the invention, by injecting dependency fields and logical tag fields into the target intermediate file and adding target runtime parameters to obtain a preprocessed file, and then constructing the target syntax tree to generate target code, the logic and maintainability of the code can be enhanced, development efficiency can be improved, the error rate can be reduced, and the quality and stability of the generated code can be ensured.

[0072] Optionally, embodiments of the present invention may further include the following steps: Step 601: Perform syntax checking, structure and naming verification, expression syntax verification, compound syntax verification, and business logic verification on the target intermediate file.

[0073] In this embodiment of the invention, the target intermediate file undergoes comprehensive verification, covering multiple dimensions including syntax checking, structure and naming verification, expression syntax verification, compound syntax verification, and business logic verification. This ensures that the target intermediate file meets requirements in terms of syntax conformity, structural rationality, expression correctness, and the accuracy of compound logic, laying the foundation for the subsequent generation of compliant and business-logical operational intermediate files. It is understood that the verification standards and tools used in the verification process are compatible with the format of the target intermediate file.

[0074] A JSON validation tool scans the target intermediate file according to the JSON syntax specification, checking for matching brackets, correct key-value pair format, and appropriate data types. If a syntax error is found, the validation tool locates the error, such as indicating "line 5 is missing a closing bracket" or "the value type of the 10th key-value pair should be a number, but is actually a string." The error information is then fed back to the target model, guiding it to correct the errors and regenerate the JSON file until it passes the JSON syntax check. The JSON syntax specification refers to the standard rules defining the format and structure of a JSON file.

[0075] Structure and naming validation can be performed using a pre-defined JSON Schema. JSON Schema is a schema language used to describe JSON data structures, providing clear specifications and constraints for the structure and content of the target intermediate file. It defines the target intermediate file's structural framework, object naming rules, field types, and required fields. For example, it can be specified that the "target function" object must contain "function expression" and "optimization direction (maximize or minimize)" fields, with the "function expression" field being a string. During validation of the target intermediate file, if the "target function" object is found to be missing the "optimization direction" field, or the "function expression" field is of numeric type, violating the Schema specifications, the validation fails, and this error message is fed back to the target model for correction.

[0076] For various expressions contained in the target intermediate file, such as query expressions, conditional expressions, operations research expressions, aggregation expressions, and initialization expressions, specialized syntax validation can be performed. Taking the operations research expression "Total delivery cost = Σ(transportation unit price × transportation volume) + Σ(vehicle fixed cost × number of vehicles used)" as an example, the validation tool can check whether the operators in the expression are used correctly, whether there are any omissions or errors in multiplication or addition signs; whether the variables are defined, such as whether variables such as "transportation unit price" and "transportation volume" are explicitly assigned values ​​in other parts of the file; and whether the function calls are standardized, such as whether the use of the summation function "Σ" conforms to the syntax requirements. If problems such as "undefined transportation unit price" or "missing multiplication sign" are found, they will be promptly fed back to the target model to guide its correction.

[0077] Compound syntax validation can be used to check the complex syntactic structure formed by the combination of multiple elements in the target intermediate file. This can include: verifying the correctness of the combination relationships of compound expressions, such as whether the logical relationship of "if condition A is true, then perform operation B" is reasonable and whether there are any logical contradictions or errors; checking the dependencies between objects, such as whether the association between tables and fields is correct, and whether the reference relationships between different objects are valid, ensuring that there are no undefined dependencies (such as a field referencing an undefined object) or circular dependencies (such as objects referencing each other to form a closed loop); checking naming conventions, such as whether variable names conform to the rule of "starting with a letter and containing letters, numbers, and underscores"; and identifying and deleting useless objects or fields, such as variables that are defined but not referenced, to ensure the simplicity and logical consistency of the target intermediate file.

[0078] The business logic is validated by combining the target model and human prompts to check whether the objective function and constraints meet user requirements. The operational logic in the intermediate target file is compared with the requirements analysis results to determine if there are any discrepancies; for example, the objective function should be "minimize total delivery cost," but it is actually "minimize delivery route length." Simultaneously, the operational logic can be supplemented and adjusted based on business experience, such as adding constraints like "delivery efficiency decreases during holidays." The target model can improve the operational logic in the intermediate target file based on human prompts and its own analysis, ensuring that the intermediate file accurately meets user business needs, ultimately generating a compliant and business-logic-compliant intermediate target file.

[0079] In this embodiment of the invention, by performing syntax checks, structure and naming verifications, expression syntax verifications, and compound syntax verifications on the target intermediate file, the target intermediate file can be checked and corrected from different perspectives, effectively ensuring the quality and usability of the target intermediate file, ensuring that the target intermediate file meets the specifications and requirements in all aspects, and providing a strong guarantee for the subsequent generation of accurate and compliant operations research intermediate files.

[0080] Furthermore, through a five-layer verification mechanism of "JSON syntax verification → Schema structure and naming verification → Expression and compound syntax verification → Business logic verification → Runtime testing", the accuracy of the technical solution is controlled at each layer. This enables errors to be discovered in the middle stages in advance, avoiding verification and testing of the code only in the final stage, and reducing the cost of code modification to a certain extent.

[0081] The code generation method provided in this invention can specifically include two stages: a data creation stage and an operations creation stage. The data creation stage involves the target model determining the target statement (DDL statement) based on user requirement information input by the target user and supplementary requirements responded by the target user in a target dialogue initiated by the target model. The operations creation stage involves the target model generating a target intermediate file based on a target operations model template matching the target statement, and generating target code based on the target intermediate file and a preset configuration file. After verifying the target code, a target project file is generated based on the target code and deployed.

[0082] Figure 2 This is a schematic diagram of the structure of a code generation device provided in an embodiment of the present invention, such as... Figure 2 As shown, the device may specifically include: The first determining module 701 is used to determine the target statement based on the user demand information input by the target user and the supplementary demands responded by the target user in the target dialogue initiated by the target model; The first generation module 702 is used to generate a target intermediate file based on a target operations model template that matches the target statement; The second generation module 703 is used to generate target code based on the target intermediate file and the preset configuration file.

[0083] Optionally, the first determining module 701 includes: The first analysis module is used to perform semantic analysis on the user demand information input by the target user to obtain target demand parameters; the target demand parameters include project type, business constraints, and optimization objectives. The first acquisition module is used to ask the target user supplementary questions based on the target model and the target requirement parameters, and to obtain the supplementary requirements replied by the target user. The first mapping module is used to map the target requirement parameters and the business terms contained in the supplementary requirements into business rules based on the preset terminology library corresponding to the project type. The first generation submodule is used to generate target statements based on the business constraints, the optimization objectives, the supplementary requirements, and the business rules.

[0084] Optionally, the device further includes: The third generation module is used to generate a first similarity vector based on the business constraints, the optimization objective, the supplementary requirements, and the business rules. The fourth generation module is used to generate the target statement based on the project statement corresponding to the existing project when the similarity between the first similarity vector and the similarity vector corresponding to any existing project is greater than a preset threshold. The first generation submodule includes: The second generation submodule is used to generate a target statement based on the business constraints, the optimization objective, the supplementary requirements, and the business rules, when the similarity between the first similarity vector and the similarity vector corresponding to any existing project is less than or equal to the preset threshold.

[0085] Optionally, the device further includes: The fifth generation module is used to automatically generate test cases based on the user requirement information, the target intermediate file, and the target code; The second acquisition module is used to acquire the code execution results corresponding to the test cases; The sixth generation module is used to modify the target intermediate file based on the code execution result when the code execution result is inconsistent with the expected result, and to regenerate the target code based on the modified target intermediate file and the preset configuration file. The seventh generation module is used to generate a target project file based on the target code, data access code, preprocessing code, common dependency files, and unified dependency method files, provided that the code execution result is consistent with the expected result.

[0086] Optionally, the second generation module 703 includes: The first processing module is used to inject dependency fields and logical tag fields into the target intermediate file and add target runtime parameters to obtain a preprocessed file. The first construction module is used to construct the target syntax tree based on the preprocessed file; The eighth generation module is used to generate the target code based on the target syntax tree.

[0087] Optionally, the device further includes: The first verification module is used to perform syntax checking, structure and naming verification, expression syntax verification, and compound syntax verification on the target intermediate file.

[0088] The present invention also provides an electronic device, see [link to relevant documentation]. Figure 3It includes: a processor 801, a memory 802, and a computer program 8021 stored in the memory and executable on the processor. When the processor executes the program, it implements the code generation method of the foregoing embodiments.

[0089] The present invention also provides a readable storage medium, wherein when the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is able to execute the code generation method of the foregoing embodiments.

[0090] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.

[0091] The algorithms and displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used in conjunction with the teachings herein. The required structure for constructing such systems is apparent from the above description. Furthermore, this invention is not directed to any particular programming language. It should be understood that the contents of the invention described herein can be implemented using various programming languages, and the above description of specific languages ​​is for the purpose of disclosing the best mode of implementation of the invention.

[0092] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.

[0093] Similarly, it should be understood that, in order to simplify the invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof. However, this disclosure should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as reflected in the following claims, inventive aspects lie in fewer than all features of a single foregoing disclosed embodiment. Therefore, the claims following the detailed description are hereby expressly incorporated into this detailed description, wherein each claim itself is a separate embodiment of the invention.

[0094] Those skilled in the art will understand that modules in the device of the embodiments can be adaptively changed and placed in one or more devices different from that embodiment. Modules, units, or components in the embodiments can be combined into a single module, unit, or component, and further, they can be divided into multiple sub-modules, sub-units, or sub-components. Except where at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or device so disclosed. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature that serves the same, equivalent, or similar purpose.

[0095] The various component embodiments of the present invention can be implemented in hardware, or as software modules running on one or more processors, or a combination thereof. Those skilled in the art will understand that microprocessors or digital signal processors (DSPs) can be used in practice to implement some or all of the functions of some or all of the components in the sorting device according to the present invention. The present invention can also be implemented as a device or apparatus program for performing part or all of the methods described herein. Such a program implementing the present invention can be stored on a computer-readable medium, or can be in the form of one or more signals. Such signals can be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.

[0096] It should be noted that the above embodiments are illustrative of the invention and not restrictive, and that those skilled in the art can devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words can be interpreted as names.

[0097] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0098] It should be noted that all actions involving the acquisition of signals, information, or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization granted by the owner of the relevant device. The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

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

Claims

1. A code generation method, characterized in that, The method includes: The target statement is determined based on the user demand information input by the target user and the supplementary demands responded by the target user in the target dialogue initiated by the target model; Based on the target operations research model template that matches the target statement, generate the target intermediate file; Based on the target intermediate file and the preset configuration file, target code is generated.

2. The method according to claim 1, characterized in that, The determination of the target statement based on the user demand information input by the target user and the supplementary demands responded by the target user in the target dialogue initiated by the target model includes: Semantic analysis is performed on the user demand information input by the target user to obtain target demand parameters; the target demand parameters include project type, business constraints, and optimization objectives. Based on the target model, supplementary questions are asked to the target user according to the target requirement parameters, and the supplementary requirements in response to the target user are obtained. Based on the preset terminology library corresponding to the project type, the target requirement parameters and the business terms contained in the supplementary requirements are mapped to business rules; Based on the business constraints, the optimization objectives, the supplementary requirements, and the business rules, a target statement is generated.

3. The method according to claim 2, characterized in that, The method further includes: Based on the business constraints, the optimization objective, the supplementary requirements, and the business rules, a first similarity vector is generated. If the similarity between the first similarity vector and the similarity vector corresponding to any existing project is greater than a preset threshold, the target statement is generated based on the project statement corresponding to the existing project. The step of generating a target statement based on the business constraints, the optimization objective, the supplementary requirements, and the business rules includes: If the similarity between the first similarity vector and the similarity vector corresponding to any existing project is less than or equal to the preset threshold, a target statement is generated based on the business constraints, the optimization objective, the supplementary requirements, and the business rules.

4. The method according to claim 1, characterized in that, The step of generating target code based on the target intermediate file and the preset configuration file includes: Inject dependency fields and logical tag fields into the target intermediate file and add target runtime parameters to obtain the preprocessed file; Based on the preprocessed file, construct the target syntax tree; The target code is generated based on the target syntax tree.

5. The method according to any one of claims 1-4, characterized in that, The method further includes: The target intermediate file is subjected to syntax checking, structure and naming verification, expression syntax verification, and compound syntax verification.

6. The method according to claim 5, characterized in that, The method further includes: Test cases are automatically generated based on the user requirements information, the target intermediate file, and the target code. Obtain the code execution results corresponding to the test cases; If the code execution result is inconsistent with the expected result, the target intermediate file is modified based on the code execution result, and the target code is regenerated based on the modified target intermediate file and the preset configuration file. If the code execution result matches the expected result, the target project file is generated based on the target code, data access code, preprocessing code, common dependency files, and unified dependency method file.

7. A code generation device, characterized in that, The device includes: The first determining module is used to determine the target statement based on the user demand information input by the target user and the supplementary demands responded by the target user in the target dialogue initiated by the target model; The first generation module is used to generate a target intermediate file based on a target operations model template that matches the target statement; The second generation module is used to generate target code based on the target intermediate file and the preset configuration file.

8. The apparatus according to claim 7, characterized in that, The first determining module includes: The first analysis module is used to perform semantic analysis on the user demand information input by the target user to obtain target demand parameters; the target demand parameters include project type, business constraints, and optimization objectives. The first acquisition module is used to ask the target user supplementary questions based on the target model and the target requirement parameters, and to obtain the supplementary requirements replied by the target user. The first mapping module is used to map the target requirement parameters and the business terms contained in the supplementary requirements into business rules based on the preset terminology library corresponding to the project type. The first generation submodule is used to generate target statements based on the business constraints, the optimization objectives, the supplementary requirements, and the business rules.

9. An electronic device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the code generation method as described in any one of claims 1-6.

10. A readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device is able to perform the code generation method according to any one of claims 1-6.