An applet generation method and system
By introducing a runtime semantic verification mechanism during the mini-program generation process, code deviations are automatically detected and corrected, solving the problem of code generation deviating from user-expected functionality in existing technologies, and achieving efficient and accurate mini-program code generation.
Patent Information
- Application Number
- CN202611428832.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-15
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies lack a feedback and correction mechanism when generating mini-program code, which makes it impossible to effectively verify the deviation between the generated code and the user's expected functions. This is especially true for mini-programs with multiple pages and branching logic, where the workload of manual debugging is enormous, exceeding the capabilities and time costs of ordinary users.
A runtime semantic verification mechanism is introduced. The source code of the mini-program is generated through a large language model, and the interface state and interaction response data are captured in a virtual sandbox environment. Runtime semantic feature vectors are extracted, semantic deviation is calculated, and correction prompts are generated based on the deviation, so as to realize the automatic correction and iterative optimization of the code.
It enables automated quantitative evaluation of the actual functional behavior of generated code, discovers and corrects logical deviations that the compiler cannot detect, improves the applicability and quality of code, reduces waste of computing resources, and enhances user experience and system interpretability.
Smart Images

Figure CN123177801A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of code generation, and in particular to a method and system for generating mini-programs. Background Technology
[0002] Mini-programs, as lightweight applications that can be used without downloading or installation, have been widely adopted in the mobile internet field in recent years. With the rapid development of artificial intelligence technology, automatic code generation technology based on large language models has gradually been introduced into the mini-program development field, aiming to lower the development threshold and improve development efficiency. Currently, some technologies attempt to generate mini-program source code through natural language interaction; users only need to describe their functional requirements, and the system can automatically generate the corresponding program code. However, while the code generated by this method can usually be compiled at the syntactic level, there is still a lack of effective means to verify whether its actual runtime behavior truly matches the user's intent.
[0003] Chinese invention patent application CN119271212A, published on January 7, 2025, proposes a method for generating WeChat mini-program source code based on WXCL. This method uses the intermediate code WXCL language to describe the mini-program structure. By setting lexical and grammatical definitions, a lexical analyzer, a syntax analyzer, and a WXCL language to target code translation program, the method achieves automatic generation of mini-program source code. At the same time, the method also includes a backend code translation system, which deploys WXCL language translation software on the server backend to translate WXCL language into WeChat mini-program source code in real time and send it to the user.
[0004] However, this method adopts a one-way translation process, that is, a one-way mapping from input to output, which lacks a feedback correction mechanism. Once the translation result deviates from the user's expected function, the user can only debug and modify it himself. For mini programs that contain multiple pages and multiple branch logic, the path combination grows exponentially. The amount of work required to manually traverse all interaction paths has far exceeded the ability and time cost of ordinary users. Summary of the Invention
[0005] In order to enable automated semantic verification of runtime behavior of mini-program source code generated based on a large language model, and to drive closed-loop correction of the code based on the verification results, so as to automatically eliminate the semantic deviation between the functional behavior of the generated code and the user's natural language requirement description, this application provides a mini-program generation method and system.
[0006] Firstly, this application provides a method for generating mini-programs, employing the following technical solution:
[0007] A method for generating a mini-program includes the following steps:
[0008] Obtain the user's input in natural language to describe their needs, and generate the first version of the mini-program source code based on the natural language description using a large language model;
[0009] Run the first version of the mini-program source code in a virtual sandbox environment, capture the interface state sequence and interaction response data during the running process, and extract runtime semantic feature vectors based on the interface state sequence and interaction response data;
[0010] Calculate the semantic deviation between the runtime semantic feature vector and the requirement semantic vector of the natural language requirement description;
[0011] If the semantic deviation exceeds a preset threshold, a correction prompt is generated based on the deviation positioning information, and the correction prompt is fed back to the large language model to generate the second version of the mini-program source code.
[0012] By adopting the above scheme, this application introduces runtime semantic verification mechanism into the field of mini-program code generation for the first time, realizing automated quantitative evaluation of the actual functional behavior of the generated code. It can discover functional logic deviations that compilers and static analysis tools cannot detect, enabling the large language model to make targeted code corrections based on the deviation between actual runtime behavior and requirements, thereby improving the applicability of the mini-program source code generated by the large model.
[0013] Optionally, following the source code of the second version of the mini-program, the following also includes:
[0014] The second version of the mini-program source code is redeployed to the virtual sandbox environment and run again to capture a new round of interface state sequence and interaction response data, and to calculate a new round of semantic deviation.
[0015] If the semantic deviation in the new round is still higher than the preset threshold, the value of the preset threshold is dynamically lowered or maintained according to the deviation reduction of the previous correction, and the lowered preset threshold is used as the convergence condition to repeat the correction and verification loop until the semantic deviation in the new round is lower than the preset threshold or the number of loops reaches the upper limit.
[0016] When the number of iterations reaches the upper limit and the semantic deviation is still higher than the preset threshold, a difference diagnosis report is generated based on the previous correction records, and the system switches to the manual intervention interface.
[0017] By adopting the above technical solution, this application constructs a complete automated iterative convergence mechanism. The dynamic threshold adjustment method enables the convergence condition to gradually improve as the correction effect improves, so that the quality of the final output code is continuously optimized as the number of iterations increases. It can be judged by the deviation reduction, effectively avoiding the waste of computing resources caused by invalid correction.
[0018] Optionally, the method further includes: when the semantic deviation exceeds the preset threshold, generating a visual heatmap based on the deviation positioning information, and highlighting the interface elements corresponding to the deviation position in the interactive interface.
[0019] By adopting the above technical solution, this application transforms the abstract quantitative data of semantic deviation into an intuitive visual heatmap presentation, enabling users to clearly identify which pages, controls, or interactive behaviors in the mini-program do not meet their needs. It also makes the functional deviations that were originally hidden in the code logic explicit in the interface highlighting, which not only makes it easier for users to understand the goal and direction of automatic correction, but also provides a visual operation entry point for human-computer collaborative correction, improving user experience and system interpretability.
[0020] Optionally, after highlighting the UI element corresponding to the offset position in the interactive interface, the following may also be included:
[0021] In response to the user's drag-and-drop rearrangement of highlighted interface elements or text correction input on the interactive interface, a manual correction instruction is generated.
[0022] Update the corresponding dimension components in the runtime semantic feature vector according to the manual correction instruction, and recalculate the updated semantic deviation.
[0023] If the updated semantic deviation is lower than the preset threshold, the manual correction instruction is converted into a code-level fixed-point modification patch, and the fixed-point modification patch is written into the current version of the mini-program source code.
[0024] By adopting the above technical solution, this application establishes a direct mapping path between the user's intuitive operation and the underlying code correction. Users do not need to have any programming knowledge and can complete the accurate correction of the generated code through simple interaction on the interface. At the same time, manual correction instructions can be converted into targeted modification patches instead of regenerating the entire code, which improves the efficiency and locality of correction. The human-machine collaborative correction method adopted in this application fills the blind spots that may exist in pure automated correction, enabling the system to make full use of the user's domain knowledge and intuitive judgment.
[0025] Optionally, after obtaining the user's natural language description of the requirements, and before generating the first version of the mini-program source code through a large language model, the following steps are also included:
[0026] Based on the platform identifier field in the natural language requirement description, the sandbox environment template of the corresponding target mini-program is retrieved from the configuration library. The sandbox environment template includes simulated host environment parameters and an API injection list.
[0027] By adopting the above technical solution, this application achieves adaptive adaptation to different mini-program platforms. It can automatically call the corresponding sandbox environment template according to the target platform specified in the user's requirements, so that the generated mini-program source code can run under conditions that highly simulate the real host environment in the subsequent virtual sandbox running verification stage. This improves the accuracy and representativeness of the running verification results, effectively avoids verification distortion caused by environmental differences, and also makes the method of this application universal across platforms with good scalability.
[0028] Optionally, before running the first version of the applet source code in a virtual sandbox environment, the method further includes:
[0029] Inject event listener hooks into the virtual sandbox environment to record DOM structure snapshots after each page rendering and callback execution results of user-triggered events.
[0030] The event listener hook in this application proxies the page rendering method and event dispatch method at the framework level, which can automatically and non-intrusively capture key data during the running process without modifying the source code logic of the mini program. The DOM structure snapshot fully records the overall appearance of the interface after each rendering, and the event callback execution result accurately records the response result of the interaction behavior. The combination of the two improves the completeness and accuracy of the data source on which the subsequent semantic feature extraction depends.
[0031] Optionally, the extraction of runtime semantic feature vectors includes:
[0032] The text nodes and control types in the interface state sequence are encoded to form an interface semantic vector;
[0033] Encode the jump path and data processing logic in the interactive response data into a behavioral semantic vector;
[0034] The interface semantic vector and the behavior semantic vector are concatenated to form the runtime semantic feature vector.
[0035] By adopting the above technical solution, this application decomposes the runtime behavior of the mini-program into two orthogonal semantic dimensions: interface presentation and interactive behavior, and encodes them separately. The runtime semantic feature vector formed by concatenating the two dimensions fully covers the two core aspects of the mini-program's functional semantics. Compared with the solution that only verifies from a single dimension, this application provides a more complete and accurate semantic expression of the mini-program's runtime behavior.
[0036] Optionally, calculating the semantic deviation between the runtime semantic feature vector and the requirement semantic vector includes:
[0037] The runtime semantic feature vector and the demand semantic vector are mapped to the same high-dimensional semantic space, and the weighted sum of the cosine distance and Euclidean distance between them is calculated as the semantic deviation.
[0038] Cosine distance measures the consistency of two vectors in direction, effectively capturing semantic similarity. Euclidean distance measures the absolute positional difference of two vectors in high-dimensional space, reflecting the difference in semantic intensity. The weighted sum of the two combines information from both direction and distance dimensions, making the deviation calculation results more comprehensive and accurate.
[0039] Optionally, the step of generating a correction prompt based on the deviation positioning information and feeding the correction prompt back to the large language model includes:
[0040] Parse the deviation location information to obtain the code path, function name, and line number of the deviation node in the source code of the first version of the mini program;
[0041] Based on the code path and the line number information, locate the AST subtree corresponding to the off-node in the source code abstract syntax tree, and extract the variable identifiers and function call relationships in the AST subtree as an influence factor chain;
[0042] The influencing factor chain, the corresponding functional statements in the natural language requirement description, and the deviation direction vector corresponding to the semantic deviation degree are combined into a structured correction instruction, which is then input into the large language model as a correction prompt.
[0043] Precise location of the AST subtree refines the correction target from the entire code file to the AST segment where the deviation node is located. Extraction of the influence factor chain enables the large language model to understand the variables and function call relationships that the deviation node depends on, thus avoiding the introduction of new errors during modification. The deviation direction vector indicates the target direction of the correction for the model. The structured correction instruction formed by the combination of these three elements contains both precise location of where to change and guidance on how to change it, enabling the large language model to perform efficient point-to-point correction, improving the accuracy and computational efficiency of the correction.
[0044] Secondly, this application provides a mini-program generation system, which adopts the following technical solution:
[0045] A mini-program generation system includes: a processor, and a memory communicatively connected to the processor;
[0046] The memory is provided with a computer-readable storage medium, and a computer program is stored on the computer-readable storage medium.
[0047] When the processor processes a computer program stored on the computer-readable storage medium, it implements the method as described in the first aspect.
[0048] In summary, this application includes at least one of the following beneficial technical effects:
[0049] 1. This application introduces runtime semantic verification mechanism into the field of mini-program code generation for the first time, realizing automated quantitative evaluation of the actual functional behavior of the generated code. It can discover functional logic deviations that compilers and static analysis tools cannot detect, enabling large language models to make targeted code corrections based on the deviation between actual runtime behavior and requirements, thereby improving the applicability of mini-program source code generated by large models.
[0050] 2. This application constructs a complete automated iterative convergence mechanism. The dynamic threshold adjustment method enables the convergence condition to gradually improve as the correction effect improves, so that the quality of the final output code is continuously optimized as the number of iterations increases. It can be judged by the deviation reduction, effectively avoiding the waste of computing resources caused by invalid correction. Attached Figure Description
[0051] Figure 1 This is a flowchart of Embodiment 1 of this application;
[0052] Figure 2 This is a flowchart of the method from interface semantic encoding in S51 to vector concatenation in Embodiment 1 of this application. Detailed Implementation
[0053] The following combination Figure 1 and Figure 2 This application will be described in further detail.
[0054] Example 1: This example discloses a method for generating a mini-program, referring to... Figure 1 The method includes: S1 requirement acquisition, S2 code generation, S3 sandbox operation, S4 data capture, S5 feature extraction, S6 deviation calculation, S7 feedback correction, S8 iterative verification, S9 threshold dynamic adjustment, and S10 manual intervention switching. First, the user's input natural language requirement description is obtained. Then, a first version of the mini-program source code is generated using a large language model. Next, the source code is run in a virtual sandbox environment, capturing interface state sequences and interaction response data. Then, runtime semantic feature vectors are extracted and their deviation from the requirement semantic vector is calculated. If the deviation exceeds the standard, a correction prompt is generated and fed back to the large language model to generate corrected code. This embodiment includes the following steps:
[0055] S1 Requirement Acquisition: In this embodiment, the user's requirement description for the mini-program is received in natural language through an interactive interface. The natural language requirement description includes a description of the mini-program's functions (e.g., the user can view an order list after logging in, and click on an order to view order details), a description of the page style (e.g., a simple interface style with blue as the main color), and the target platform identifier.
[0056] A structured requirement description template is displayed in the interactive interface to guide users in inputting requirement information according to dimensions such as functional modules, number of pages, and interaction methods, thereby improving the accuracy of subsequent semantic vector extraction. The natural language requirement description is saved as a text file and transmitted to the backend server for processing.
[0057] S11 platform identification extracts the target platform identifier from the user's input natural language description of the request, such as WeChat Mini Program, Alipay Mini Program, Baidu Smart Mini Program, or ByteDance Mini Program.
[0058] If the user does not explicitly specify the target platform, the WeChat Mini Program will be selected as the default target platform.
[0059] Based on the identified platform identifier field, the sandbox environment template of the corresponding target mini-program is retrieved from the configuration library. The sandbox environment template includes simulated host environment parameters and API injection list.
[0060] This embodiment takes a WeChat mini program as an example. The sandbox environment template includes: simulated WeChat JS-SDK interfaces (including wx.request, wx.navigateTo, wx.showToast, etc.), simulated user login status information (including openid, session_key), simulated system-level events (including page loading onLoad, page display onShow, page hiding onHide, page unloading onUnload), and simulated device parameters (including screen width, screen height, system version, etc.).
[0061] S12 Prompt word construction: Based on the business category (e.g., e-commerce, tool, social, etc.) in the natural language requirement description, select the corresponding prompt word template from the preset prompt word library. The prompt word template includes code generation constraints (e.g., using the native mini-program framework, all network requests must include exception handling) and directory structure constraints (e.g., page files are stored in the pages directory, and component files are stored in the components directory).
[0062] The natural language requirement description is combined with the selected prompt word template to form a complete large language model input prompt.
[0063] S2 code generation involves submitting the natural language requirement description obtained in S1 requirement acquisition or the input prompt constructed in S12 prompt word construction to a preset large language model, which then generates the corresponding mini-program source code. The large language model includes large language models such as GPT-4, Claude 3, or the open-source Llama 3, deployed on a cloud server, and a generation request is sent to it via an API interface.
[0064] The large language model generates the corresponding first-version mini-program source code based on the input prompts, including wxml (view layer), wxss (style layer), js (logic layer), and json (configuration file). The first-version mini-program source code is a complete, compileable, and runnable code package.
[0065] The S3 sandbox runs by calling a preset virtual sandbox environment to deploy and run the first version of the mini-program source code generated in the S2 code generation process. This virtual sandbox environment can run the mini-program code independently, without relying on a real WeChat client or physical mobile device.
[0066] In this embodiment, a virtual sandbox environment is configured based on the sandbox environment template retrieved from the S11 platform identification. The sandbox environment template includes simulated host environment parameters and an API injection list.
[0067] S31 Hook Injection: In this embodiment, event listening hooks are injected into the virtual sandbox environment by rewriting or proxying the page rendering method and event dispatch method of the underlying mini-program framework. The event listening hooks are a set of JavaScript functions.
[0068] This embodiment uses the Proxy pattern to proxy the lifecycle functions and event handling functions of the Mini Program Page object. When the page is rendered or a user interaction event is triggered, the event listening hook automatically captures the corresponding event data.
[0069] S32 automated traversal injects an automated test script into a virtual sandbox environment. The automated test script clicks on each interactive control in the interface state sequence sequentially according to a preset traversal depth (e.g., traversing all interactive controls to a depth of 3 levels), and records the full state change data packet after each click. The full state change data packet includes page data update volume (i.e., a comparison before and after data changes) and network request load data (including request URLs, request parameters, and return results).
[0070] S4 data capture records the interface state sequence and interaction response data during the running of the applet source code in the virtual sandbox environment through pre-injected event listener hooks.
[0071] S41 interface state capture: After each page rendering, the event listener hook automatically captures a snapshot of the current page's DOM structure. The DOM structure snapshot includes information about all nodes on the page, including node types (e.g., view, text, button, input, image, etc.), node attributes (e.g., id, class, style, etc.), node text content, and the hierarchical relationship between nodes.
[0072] The DOM structure snapshots are stored in JSON format, with each snapshot corresponding to a timestamp, forming a sequence of interface states.
[0073] The S42 interaction response capture, specifically the event listener hook, also records the callback execution results after each user-triggered event (e.g., clicking a button, sliding a list, entering text, etc.). This includes: the event object at the time of event triggering (containing information such as event type, trigger control ID, and trigger coordinates); the page navigation path after the event callback function is executed (e.g., navigation from page A to page B); and the execution results of data processing logic (e.g., data returned from network requests, updated content in local data storage, etc.). The interaction response data is also stored in JSON format and associated with the corresponding interface state sequence via timestamps.
[0074] S5 feature extraction performs semantic encoding on the interface state sequence and interaction response data captured in S4 data capture, and extracts runtime semantic feature vectors that can characterize the semantics of the actual running behavior of the mini program.
[0075] Reference Figure 2 S51 interface semantic encoding encodes the text nodes and control types in the interface state sequence. It extracts the text content of all text nodes and the control type identifiers (e.g., button, input, navigator, switch, etc.) from the DOM structure snapshot of the interface state sequence.
[0076] The extracted text content is encoded using a pre-set text encoder (such as a pre-trained language model like Sentence-BERT or RoBERTa) to generate corresponding text vectors; the control type identifier is one-hot encoded or embedded encoded to generate control type vectors.
[0077] The text vector and control type vector of the same interface state are concatenated according to the depth order of the nodes in the DOM tree to form the interface semantic vector of that interface.
[0078] The interface semantic vectors of all interfaces in the interface state sequence are arranged in chronological order to form an interface semantic vector sequence.
[0079] S52 Behavioral semantic encoding encodes the jump path and data processing logic in the interactive response data into a behavioral semantic vector.
[0080] Extract page navigation paths from interactive response data, encode page nodes in the navigation paths into graph embedding vectors, and form path semantic vectors.
[0081] Extract the data processing logic operation sequence from the interactive response data, and encode each operation type in the operation sequence into an operation semantic vector.
[0082] The path semantic vector and the operation semantic vector are weighted and concatenated to form the behavior semantic vector.
[0083] S53 vector concatenation performs L2 norm normalization on both the interface semantic vector and the behavior semantic vector. The normalized interface semantic vector is then concatenated with the normalized behavior semantic vector to form a complete runtime semantic feature vector.
[0084] S6 offset calculation encodes the natural language requirement description into a requirement semantic vector, which has the same vector dimension as the runtime semantic feature vector.
[0085] The semantic deviation between the runtime semantic feature vector and the demand semantic vector of the natural language demand description is calculated. In this embodiment, the semantic deviation is characterized by a weighted sum of cosine distance and Euclidean distance, and the calculation model is as follows:
[0086]
[0087] Where A represents the semantic deviation; This is a runtime semantic feature vector. For demand semantic vectors, The cosine similarity function is used. The distance is the Euclidean distance (L2 distance), and α and β are weighting coefficients. The values of α and β are both in the range [0, 1], and α + β = 1. In this embodiment, both α and β are taken as 0.5.
[0088] If the calculated semantic deviation is lower than or equal to the preset threshold (e.g., 0.15), it indicates that the actual running behavior of the first version of the mini program source code is highly consistent with the user's needs, and the system will directly output the first version of the mini program source code as the final release code.
[0089] If the calculated semantic deviation exceeds a preset threshold, it indicates a significant discrepancy between the actual behavior of the first version of the mini-program's source code and user needs, triggering S7 feedback correction. Simultaneously,
[0090] In other embodiments, when the semantic deviation exceeds a preset threshold, a visual heatmap is generated based on the deviation positioning information, and the interface elements corresponding to the deviation position are highlighted in the interactive interface.
[0091] The visualization heatmap maps the distribution intensity of the semantic deviation on different interface elements in the interactive interface in a way that uses color depth. That is, the interface element with higher deviation is darker (e.g., red), and the interface element with lower deviation or no deviation is lighter (e.g., green or transparent).
[0092] S7 provides feedback correction and acquires deviation positioning information generated during the semantic deviation calculation process. This deviation positioning information includes: which interface states, interface elements, and interactive response steps caused the semantic deviation, and their respective deviation contributions.
[0093] S71 Off-location parsing: Parses the off-location information to obtain the code path, function name, and line number of the off-location node in the first version of the mini-program's source code. This embodiment maintains a reverse mapping table from interface element identifiers (such as control IDs) and interaction event identifiers to source code file paths and line numbers. This mapping table is generated by the large language model when the first version of the source code is generated, or dynamically constructed during sandbox operation through a source map mechanism. Through this mapping table, the corresponding source code location can be found by reverse tracing the interface element identifiers and interaction event identifiers in the off-location information.
[0094] S72 Impact Factor Extraction: Based on the code path and line number information, locate the AST subtree corresponding to the off-node in the source code abstract syntax tree (AST), and extract the variable identifiers and function call relationships in the AST subtree into an impact factor chain. The impact factor chain includes: the variables that the off-node depends on, the functions called, and the execution order of the node in the page lifecycle.
[0095] The S73 structured correction instruction is generated by combining the influence factor chain, the corresponding functional statements in the natural language requirement description, and the deviation direction vector corresponding to the semantic deviation degree into a structured correction instruction.
[0096] The structured correction instruction is a formatted text input, the structure of which is as follows:
[0097] [Correction Target]: Deviated from node identifier
[0098] [Deviation Phenomenon]: Description of Actual Operational Behavior
[0099] [Impact Factor]: Impact Factor Chain
[0100] [Deviation Direction]: Deviation direction vector (indicator of the corrective direction to move closer to the expected semantics)
[0101] [Original User Requirement]: The original requirement description statement corresponding to this function.
[0102] [Revised Constraints]: Keep other unrelated functions unaffected, only modify the deviation parts.
[0103] The S74 model is corrected by inputting the structured correction instructions as correction prompts into the large language model. Based on these prompts and the context of the first version of the mini-program source code, the large language model makes targeted modifications only to code snippets related to off-nodes, generating the second version of the mini-program source code.
[0104] In S8 iteration verification, the second version of the mini-program source code is redeployed to the virtual sandbox environment and run again. Following the same method as S4 data capture to S6 deviation calculation, a new round of interface state sequence and interaction response data is captured, a new round of runtime semantic feature vector is extracted, and a new round of semantic deviation is calculated.
[0105] If the semantic deviation of the new round is lower than or equal to the preset threshold, the semantic verification is passed, and the source code of the current version (i.e., the second version) of the mini program is output as the final release code, and the iterative correction ends.
[0106] S9 threshold dynamic adjustment: If the semantic deviation of the new round is still higher than the preset threshold, it indicates that although the correction has improved the situation, it has not yet converged to a qualified level and the correction needs to continue.
[0107] In this embodiment, the value of the preset threshold is dynamically adjusted or maintained based on the deviation reduction of the previous correction (i.e., the deviation before correction minus the deviation after correction).
[0108] In this embodiment, if the deviation reduction is greater than the reduction threshold (e.g., 0.02), it indicates that the correction direction is correct, and the preset threshold is slightly lowered (e.g., reduced by 5%) to improve the quality requirements of the final output; if the deviation reduction is less than or equal to the reduction threshold, it indicates that the correction effect is not obvious, and the preset threshold is kept unchanged.
[0109] Using the lowered preset threshold as the new convergence condition, repeat the above loop operation until the calculated semantic deviation is lower than the current preset threshold (i.e. the convergence condition is met) or the number of loops reaches the preset upper limit (e.g., 5 times).
[0110] S10 Manual intervention switch: When the number of cycles reaches the upper limit and the semantic deviation of the last round is still higher than the corresponding preset threshold, the automatic correction is determined to have failed. A difference diagnosis report is generated based on the correction records and the system switches to the manual intervention interface.
[0111] The difference diagnosis report includes: deviation change curves for each correction, the top three pages or controls with the largest deviations, correction prompts for each correction and their corresponding correction effect evaluations, and possible failure reason analysis.
[0112] When a user drags and rearranges a highlighted interface element or corrects text input, a manual correction instruction is generated in response to the user's operation. The manual correction instruction includes: operation type (drag and rearrange or text correction), operation object (interface element identifier), state changes before and after the operation, and page information associated with the operation.
[0113] The corresponding dimension component in the runtime semantic feature vector is updated according to the manual correction instruction, and the manual correction instruction is converted into the corresponding semantic correction vector to obtain the updated runtime semantic feature vector.
[0114] Based on the updated runtime semantic feature vector, the semantic deviation between it and the requirement semantic vector is recalculated.
[0115] If the updated semantic deviation is lower than the preset threshold, it indicates that the user's intuitive correction operation has been able to eliminate the functional deviation. Through the reverse mapping of the influence factor chain, the user's operation on the interface element is mapped back to the corresponding code location and code modification method in the source code.
[0116] The targeted modification patch is written into the current version of the mini-program's source code to form the corrected final code.
[0117] If the updated semantic deviation is still not lower than the preset threshold, it indicates that the user's single intuitive correction is insufficient to completely eliminate the deviation. The semantic correction vector corresponding to the manual correction instruction is used as an additional correction prompt parameter and input into the large language model together with the structured correction instruction for a new round of automatic iterative correction.
[0118] Example 2: This example discloses a mini-program generation system, the system including: a processor, and a memory communicatively connected to the processor;
[0119] The memory is provided with a computer-readable storage medium, and a computer program is stored on the computer-readable storage medium.
[0120] When the processor executes a computer program stored on the computer-readable storage medium, it implements the method.
[0121] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application.
Claims
1. A method for generating a mini-program, characterized in that, include: Obtain the user's input in natural language to describe their needs, and generate the first version of the mini-program source code based on the natural language description using a large language model; Run the first version of the mini-program source code in a virtual sandbox environment, capture the interface state sequence and interaction response data during the running process, and extract runtime semantic feature vectors based on the interface state sequence and interaction response data; Calculate the semantic deviation between the runtime semantic feature vector and the requirement semantic vector of the natural language requirement description; If the semantic deviation exceeds a preset threshold, a correction prompt is generated based on the deviation positioning information, and the correction prompt is fed back to the large language model to generate the second version of the mini-program source code.
2. The method for generating a mini-program according to claim 1, characterized in that, After generating the source code for the second version of the mini-program, the following is also included: The second version of the mini-program source code is redeployed to the virtual sandbox environment and run again to capture a new round of interface state sequence and interaction response data, and to calculate a new round of semantic deviation. If the semantic deviation in the new round is still higher than the preset threshold, the value of the preset threshold is dynamically lowered or maintained according to the deviation reduction of the previous correction, and the lowered preset threshold is used as the convergence condition to repeat the correction and verification loop until the semantic deviation in the new round is lower than the preset threshold or the number of loops reaches the upper limit. When the number of iterations reaches the upper limit and the semantic deviation is still higher than the preset threshold, a difference diagnosis report is generated based on the previous correction records, and the system switches to the manual intervention interface.
3. The method for generating a mini-program according to claim 1, characterized in that, The method further includes: when the semantic deviation exceeds the preset threshold, generating a visual heatmap based on the deviation positioning information, and highlighting the interface elements corresponding to the deviation position in the interactive interface.
4. The method for generating a mini-program according to claim 3, characterized in that, After highlighting the UI elements that are off-center in the interactive interface, it also includes: In response to the user's drag-and-drop rearrangement of highlighted interface elements or text correction input on the interactive interface, a manual correction instruction is generated. Update the corresponding dimension components in the runtime semantic feature vector according to the manual correction instruction, and recalculate the updated semantic deviation. If the updated semantic deviation is lower than the preset threshold, the manual correction instruction is converted into a code-level fixed-point modification patch, and the fixed-point modification patch is written into the current version of the mini-program source code.
5. The method for generating a mini-program according to claim 1, characterized in that, After obtaining the user's natural language description of their needs, and before generating the first version of the mini-program's source code using a large language model, the following steps are also included: Based on the platform identifier field in the natural language requirement description, the sandbox environment template of the corresponding target mini-program is retrieved from the configuration library. The sandbox environment template includes simulated host environment parameters and an API injection list.
6. The method for generating a mini-program according to any one of claims 1-5, characterized in that, Before running the first version of the applet source code in a virtual sandbox environment, the method further includes: Inject event listener hooks into the virtual sandbox environment to record DOM structure snapshots after each page rendering and callback execution results of user-triggered events.
7. The method for generating a mini-program according to any one of claims 1-6, characterized in that, The extraction of runtime semantic feature vectors includes: The text nodes and control types in the interface state sequence are encoded to form an interface semantic vector; Encode the jump path and data processing logic in the interactive response data into a behavioral semantic vector; The interface semantic vector and the behavior semantic vector are concatenated to form the runtime semantic feature vector.
8. The method for generating a mini-program according to claim 7, characterized in that, The calculation of the semantic deviation between the runtime semantic feature vector and the demand semantic vector includes: The runtime semantic feature vector and the demand semantic vector are mapped to the same high-dimensional semantic space, and the weighted sum of the cosine distance and Euclidean distance between them is calculated as the semantic deviation.
9. The method for generating a mini-program according to claim 1, characterized in that, The step of generating correction prompts based on the deviation positioning information and feeding the correction prompts back to the large language model includes: Parse the deviation location information to obtain the code path, function name, and line number of the deviation node in the source code of the first version of the mini program; Based on the code path and the line number information, locate the AST subtree corresponding to the off-node in the source code abstract syntax tree, and extract the variable identifiers and function call relationships in the AST subtree as an influence factor chain; The influencing factor chain, the corresponding functional statements in the natural language requirement description, and the deviation direction vector corresponding to the semantic deviation degree are combined into a structured correction instruction, which is then input into the large language model as a correction prompt.
10. A mini-program generation system, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory is provided with a computer-readable storage medium, and a computer program is stored on the computer-readable storage medium. When the processor processes a computer program stored on the computer-readable storage medium, it implements the method as described in any one of claims 1-9.
Citation Information
Patent Citations
Wechat applet source code generation method based on WXCL and storage medium
CN119271212A
