Generative intelligent model-based code generation method and program product

By structurally transforming user requirements and adjusting environment adaptation tags, the problem of generative AI not being able to run directly in the browser environment was solved, enabling the effective generation and execution of code in the browser.

CN121300775APending Publication Date: 2026-01-09CHENGDU BOSS INNOVATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511627577.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-07
Publication Date
2026-01-09

AI Technical Summary

Technical Problem

Existing generative AI generates code that cannot be run directly in a browser environment, making it unusable in a browser environment.

Method used

By parsing and transforming the user's natural language requirements, a structured task description is generated. Initial code is then generated using a generative intelligent model, and adaptation adjustments are made in conjunction with environment adaptation tags to ensure that the code conforms to the constraints of the browser environment.

Benefits of technology

The generated code can be run directly in the browser environment, improving the efficiency and accuracy of adaptation and adjustment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121300775A_ABST
    Figure CN121300775A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method based on a generative intelligent model and a program product, and the method comprises the steps: carrying out the analysis and conversion of a natural language demand of a user, so as to obtain a structured task description, and injecting the structured task description into a prompt word template of the generative intelligent model, the generative intelligent model generates an initial code conforming to the target language according to the content in the prompt word template, and adaptive adjustment is conducted on the code provided by the generative intelligent model according to the environment adaptive mark to obtain a target code. According to the method, the environment adaptation mark added in the code generation process is used as a reference, statements which are not matched with the environment constraint rule base are adjusted, and the adaptation adjustment efficiency and accuracy are improved under the condition that it is guaranteed that the adapted and adjusted code can run in a browser.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence large language model, in particular to a code generation method and program product based on a generative intelligent model. BACKGROUND

[0002] Writing code is an important part of the programmer's development work, which requires a lot of manpower and time cost. In order to improve the development efficiency and reduce the manpower and time cost, a generative intelligent model can be used to generate code.

[0003] The existing generative AI can generate code, and the generated code may depend on native modules and cannot be directly run in a browser environment. SUMMARY

[0004] The purpose of the present application is to provide a code generation method and program product based on a generative intelligent model to improve the above problems.

[0005] In order to achieve the above purpose, the technical scheme adopted by the embodiments of the present application is as follows: In a first aspect, the embodiments of the present application provide a code generation method based on a generative intelligent model, which comprises: analyzing and converting user natural language requirements to obtain a structured task description, wherein the structured task description includes key information in the user natural language requirements, a target dependent library matched with the key information, metadata of a current project, and an environment constraint rule library corresponding to a browser, the metadata of the current project includes an installed dependent list, and the key information includes a target language and a function point; injecting the structured task description into a prompt word template of a generative intelligent model, wherein the generative intelligent model generates an initial code conforming to the target language according to the content in the prompt word template, the initial code includes a dependent declaration statement and a core function logic statement corresponding to each function point, the dependent declaration statement is matched with the target dependent library and the metadata of the current project, each segment of the core function logic statement carries a corresponding environment adaptation mark, the environment adaptation mark is used to indicate whether the core function logic statement is adapted to the environment constraint rule library, if not, the environment adaptation mark further includes a replacement object in the core function logic statement and a corresponding replacement rule; According to the environment adaptation mark, the code provided by the generative intelligent model is adapted and adjusted to obtain a target code.

[0006] In a second aspect, the embodiments of the present application provide a program product, which, when executed by a processor, implements the above-mentioned code generation method based on a generative intelligent model.

[0007] Thirdly, embodiments of the present invention provide a storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method.

[0008] Fourthly, embodiments of the present invention provide an electronic device, the electronic device comprising: a processor and a memory, the memory being used to store one or more programs; when the one or more programs are executed by the processor, the above-described method is implemented.

[0009] Compared to existing technologies, the code generation method and program product based on a generative intelligent model provided in this invention parses and transforms user natural language requirements to obtain a structured task description. This structured task description is then injected into a prompt word template of the generative intelligent model. The generative intelligent model generates initial code conforming to the target language based on the content of the prompt word template. The code provided by the generative intelligent model is then adapted and adjusted according to environment adaptation tags to obtain the target code. By using environment adaptation tags added during the code generation process as a reference, statements that are incompatible with the environment constraint rule base are adjusted, improving the efficiency and accuracy of adaptation adjustment while ensuring that the adapted code can run in a browser.

[0010] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0011] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.

[0013] Figure 2 This is one of the flowcharts illustrating the code generation method based on a generative intelligent model provided in an embodiment of the present invention.

[0014] Figure 3 This is the second flowchart illustrating the code generation method based on a generative intelligent model provided in this embodiment of the invention.

[0015] Figure 4 This is the third flowchart illustrating the code generation method based on a generative intelligent model provided in this embodiment of the invention.

[0016] Figure 5The fourth flowchart illustrates the code generation method based on a generative intelligent model provided in this embodiment of the invention.

[0017] Figure 6 The fifth flowchart illustrates the code generation method based on a generative intelligent model provided in this embodiment of the invention.

[0018] In the diagram: 10-Processor; 11-Memory; 12-Bus; 13-Communication interface. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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 embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0020] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0021] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this invention, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0022] In the description of this invention, it should also be noted that, unless otherwise explicitly specified and limited, the terms "set" and "connection" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0023] The following detailed description of some embodiments of the present invention is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0024] Glossary of terms (technical terms): WebAssembly (Wasm) is a low-level binary instruction format that can run efficiently in a browser and supports compilation of languages ​​such as C / C++ and Rust into browser-executable code. This article aims to achieve near-native performance.

[0025] WebContainers: A browser-based runtime environment based on WebAssembly that can simulate a Node.js environment, supporting npm dependency installation, terminal command execution, and file system operations, without requiring a backend server.

[0026] Generative AI (large language models): AI models based on the Transformer architecture, such as GPT-4 and CodeLlama, can generate code snippets that conform to syntax and logic based on text input.

[0027] AST (Abstract Syntax Tree): A tree-like representation of the abstract syntax structure of source code. Each node represents the syntax structure in the code (such as function calls and variable declarations), which facilitates program analysis and modification.

[0028] Virtual File System (VFS): A logical layer that simulates a file system in memory or browser storage (such as IndexedDB), providing APIs consistent with the native file system (such as readFile / writeFile), but storing data within the browser sandbox.

[0029] Prompt Engineering: Designing and optimizing the text instructions (prompt words) input to the AI ​​model to guide the model to generate expected output (such as specifying code style, environmental constraints).

[0030] SourceMap: A file that stores the mapping between source code and compiled code (such as WebAssembly bytecode), used to convert error locations during execution (such as line numbers in WASM) into the locations in the original source code.

[0031] Vector databases: Databases used to store and retrieve high-dimensional vector data (such as Pinecone), which use algorithms such as cosine similarity to quickly match similar contexts (such as user history interaction records).

[0032] Sandbox: A security mechanism that restricts a program's access to resources (such as file system paths and network domains) to prevent malicious operations or unauthorized access.

[0033] Code adaptation / porting refers to the process of modifying or converting code from one runtime environment or platform (such as Node.js) to another incompatible or partially compatible environment (such as WebAssembly). One of the core innovations of this invention is the automation and intelligentization of this process.

[0034] Token Counting: When generative AI models process text, they first divide the text into individual tokens. The model's processing capacity is typically limited by the total number of input and output tokens. A token can be a word, an affix, or a punctuation mark. In the iterative optimization module of this invention, it is necessary to accurately calculate the token count for each prompt word to ensure that it does not exceed the model's limit and to optimize the efficiency of context utilization.

[0035] Access Control List (ACL): A list used to define access permissions for specific resources (such as files, network addresses). It explicitly specifies which subjects (such as users, programs) are allowed or prohibited from performing which operations (such as read, write, execute) on which resources. This invention uses ACLs in the execution monitoring engine to define secure access policies for virtual file systems and network requests.

[0036] Dependency Injection: A design pattern that refers to passing other objects (dependencies) that an object depends on to it through constructors, methods, or properties when the object is created, instead of the object creating or looking up dependencies itself. In the WebAssembly adaptation layer of this invention, when code is detected to depend on the fs module, the vfs module is proactively injected into the runtime environment of the code, achieving seamless replacement.

[0037] This invention provides an electronic device, which may be a computer device, a mobile phone device, or a server device. Please refer to... Figure 1 This is a schematic diagram of the structure of an electronic device. The electronic device includes a processor 10, a memory 11, and a bus 12. The processor 10 and the memory 11 are connected via the bus 12. The processor 10 is used to execute executable modules, such as computer programs, stored in the memory 11.

[0038] Processor 10 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the code generation method based on the generative intelligent model can be completed through integrated logic circuits in the hardware or software instructions within processor 10. Processor 10 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0039] The memory 11 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage.

[0040] Bus 12 can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. Figure 1 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus 12 or one type of bus 12.

[0041] The memory 11 is used to store programs, such as programs corresponding to a code generation device based on a generative intelligent model. The code generation device based on a generative intelligent model includes at least one software functional module that can be stored in the memory 11 as software or firmware, or embedded in the operating system (OS) of the electronic device. Upon receiving an execution instruction, the processor 10 executes the program to implement the code generation method based on the generative intelligent model.

[0042] The electronic device provided in this embodiment of the invention may further include a communication interface 13. The communication interface 13 is connected to the processor 10 via a bus.

[0043] It should be understood that, Figure 1The structure shown is only a partial schematic diagram of the electronic device; the electronic device may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.

[0044] The code generation method based on a generative intelligent model provided in this embodiment of the invention can be applied to, but is not limited to, [various applications]. Figure 1 For the specific process of the electronic devices shown, please refer to [link / reference]. Figure 2 The code generation method based on the generative intelligent model includes S11, S12 and S14, which are described in detail below.

[0045] S11 parses and transforms the user's natural language requirements to obtain a structured task description.

[0046] The structured task description includes key information from the user's natural language requirements, target dependency libraries matching the key information, metadata of the current project, and the browser's corresponding environment constraint rule base. The current project's metadata includes a list of installed dependencies, and the key information includes the target language and functionalities. Optionally, Redis can be used to cache the current project's metadata to avoid repeated readings. Optionally, the current project's metadata also includes the path to the code file (which could be the path to a data.json file), and the key information may also include output requirements (e.g., console output). The browser can be a WebAssembly-based browser.

[0047] For example, a user's natural language requirement is: write a Node.js script to read JSON and calculate the average value, with the target language being Node.js and the functionalities being reading JSON and calculating the average value.

[0048] S12, inject the structured task description into the prompt word template of the generative intelligent model, and the generative intelligent model generates initial code that conforms to the target language based on the content in the prompt word template.

[0049] The initial code includes dependency declaration statements and core functional logic statements corresponding to each functional point. The dependency declaration statements (such as const vfs = require('virtual-fs')) match the target dependency library and the metadata of the current project. Each core functional logic statement carries the corresponding environment adaptation tag (such as / / @webcontainer: replace the native fs with the virtual fs). The environment adaptation tag is used to indicate whether the core functional logic statement is compatible with the environment constraint rule library. If it is not compatible, the environment adaptation tag also includes the replacement object and the corresponding replacement rule in the core functional logic statement. For example, the prompt template includes "Environmental constraint prompt: Please generate code that can run in WebContainers, avoid using the native fs module, and use a virtual file system instead" and "Format requirements: Include detailed comments + ESLint specification code".

[0050] Generative intelligent models can be lightweight generative AI models deployed on the browser or AI models deployed in the cloud (via API calls).

[0051] Lightweight generative AI models can be based on the Transformer architecture, such as the CodeLlama-7B model, and deployed in the browser via ONNXRuntime to reduce memory usage. When the generative intelligent model is deployed in the cloud, it can be invoked using the WebSocket protocol to achieve streaming code generation, returning code as it is generated, thus reducing waiting time.

[0052] S14, adapt and adjust the code provided by the generative intelligent model according to the environment adaptation tag to obtain the target code.

[0053] Optionally, adaptation adjustments can be made in the browser's adaptation layer.

[0054] In the code generation method based on generative intelligent models provided in this embodiment of the invention, in order to avoid the generated code not being able to run directly in the browser environment, the environment adaptation mark added during the code generation process is used as a reference to adjust the statements that are not compatible with the environment constraint rule library. While ensuring that the adapted code can run in the browser, the efficiency and accuracy of the adaptation adjustment are improved.

[0055] Based on the preceding text, regarding the content of S11, this embodiment of the invention also provides an optional implementation method, please refer to the following. S11, parsing and converting the user's natural language requirements to obtain a structured task description, includes: S111, S112, S113, and S114, as detailed below.

[0056] S111 extracts key information from the user's natural language requirements.

[0057] Optionally, a word segmentation tool (Jieba segmentation for Chinese scenarios or NLTK segmentation for English scenarios) is first used to split the user's natural language requirements into sentences. Then, an NLP intent recognition model (based on BERT fine-tuning) is adopted to extract key information from the split sentences using pre-trained code domain word vectors (such as those trained on the CodeSearchNet dataset), thereby improving the accuracy of key information recognition and ensuring the completeness of element extraction.

[0058] S112, use key information to perform vector feature matching in a vector database (e.g., the Pinecone vector database) to determine the target historical record. Vector feature matching may, but is not limited to, using the cosine similarity algorithm. The vector database is, for example, the Pinecone vector database. The vector database is used to store user historical interaction records (e.g., the user's past natural language records, generated code, and error records). The target historical record is the user's historical interaction record that meets the matching requirements. The matching requirements can be that the matching degree with the key information exceeds the matching threshold or is the highest matching degree.

[0059] S113, retrieve the target dependency library corresponding to the target history.

[0060] The target dependency library is, for example, the data processing tool lodash.

[0061] S114 integrates key information, target dependency libraries, metadata of the current project, and the browser's corresponding environment constraint rule library into a standardized structured task description.

[0062] Among them, the environment constraint rule base is, for example, "prohibit access to the local real file system" and "does not support the child_process module". The standardized format can be any pre-configured format, and it can be, but is not limited to, JSON format.

[0063] Optionally, key information, target dependency libraries, metadata of the current project, and the browser's corresponding environment constraint rule library are populated into the structured task description template corresponding to the standardized format. Then, a validation tool (which may be, but is not limited to, Another JSON Schema Validator, AJV) is used to validate the populated structured task description template. After the validation passes, it is used as a structured task description for input into the generative intelligent model to ensure the integrity and standardization of fields and avoid parsing errors in subsequent modules.

[0064] To ensure code readability and executability, this embodiment of the invention also provides an optional implementation method, please refer to... Figure 3 In S14, before adapting and adjusting the code provided by the generative intelligent model according to the environment adaptation tag to obtain the target code, the code generation method based on the generative intelligent model also includes: S13, which is described in detail below.

[0065] S13, standardizes the initial code after adding environment adaptation tags.

[0066] Optionally, the normalized code can be sent to the browser for execution.

[0067] You can use code validation tools (such as ESLint) to perform syntax validation on the initial code (such as checking bracket closures and variable declarations) and automatically fix syntax errors. The code validation tool can be a tool with an environment constraint rule base already configured. Then, code formatting tools (such as PrettierAPI) are used to automatically format the syntax-checked code (e.g., 2-space indentation, single quotes); then, custom plugins are used to adapt the code comment style (e.g., function comments include parameter descriptions and return values, such as " / / read data.json in the virtual file system") to ensure code readability and executability.

[0068] Building upon the preceding text, this embodiment of the invention also provides an optional implementation method for ensuring compatibility between the target code and the browser, as described below. S14: The code provided by the generative intelligent model is adapted and adjusted according to the environment adaptation markers to obtain the target code, including: S141, S142, S143, S144, and S145, which are specifically described below.

[0069] S141 utilizes an Abstract Syntax Tree (AST) parser to traverse the abstract syntax tree of the code provided by the generative intelligent model to locate context adaptation tags and extract dependency declaration statements (such as require or import statements).

[0070] The code provided by the generative intelligent model can be either initial code or normalized code, and the dependency declaration statement can be a require or import statement.

[0071] S142, determine the replacement object and corresponding replacement rule in the core functional logic statement according to the environment adaptation mark of the indication mismatch, and make corresponding adaptation adjustments to obtain the replaced core functional logic statement.

[0072] The replacement rules can involve modifying AST nodes using the Recast tool to avoid syntax errors caused by direct string replacement. The self-developed Virtual File System (VFS) module encapsulates methods such as readFile / writeFile based on IndexedDB to support POSIX-style paths (e.g., / workspace / data.json); the network module uses isomorphic-fetch to encapsulate the HTTP module interface, adapting to the browser's network sandbox.

[0073] S143. Construct a dependency graph based on the extracted dependency declaration statements. The dependency graph includes the dependency library name, the dependency library version, and the compatibility relationship between each version of the dependency library and the environment constraint rule base.

[0074] The compatibility relationship can be either "compatible" or "incompatible", such as lodash@4.17.0 being marked as "compatible with WebContainers".

[0075] S144, Install compatible dependencies from the dependency graph.

[0076] Optionally, the `spawn` interface of WebContainers can be called to execute the `npm install` command, which installs compatible dependencies from the dependency graph.

[0077] S145. If any version of the dependency library is incompatible with the environment constraint rule library, a distance algorithm is used to match alternative dependency libraries with similar functions, the alternative dependency libraries are installed, and the dependency declaration statements in the code are modified according to the alternative dependency libraries to obtain the target code.

[0078] The distance algorithm can be, but is not limited to, the Levenshtein distance algorithm. For example, you can replace canvas with fabric.js and modify the dependency declaration statements in the code, such as const canvas = require('canvas') → const fabric = require('fabric'). By installing the alternative dependency library and modifying the dependency declaration statements, you can ensure that the functionality is not affected after the replacement.

[0079] In the code generation method based on a generative intelligent model provided in this embodiment of the invention, a "tag-driven intelligent adaptation engine" is creatively constructed by utilizing an AST parser or code formatting tool. This engine can understand the intent of the code and perform semantic-level equivalent transformations, achieving automation and intelligence.

[0080] Building upon the preceding text, this invention also provides an optional implementation method for achieving closed-loop verification of the generated code. Please refer to [link / reference needed]. Figure 4 In S14, the code provided by the generative intelligent model is adapted and adjusted according to the environment adaptation tag to obtain the target code. The code generation method based on the generative intelligent model also includes S15, S16, S17, S18, S21 and S22, which are described in detail below.

[0081] S15 mounts the target code and installed dependencies to the working directory of an idle instance in the browser to run the target code.

[0082] Optionally, check if there is an idle instance in the browser's instance pool (cached WebContainers instances). If so, reuse it (to avoid the 300ms+ time consumption of repeated initialization). If not, call WebContainer.boot() to create a new instance. Mount the virtual file system (containing project files such as data.json) and installed dependencies corresponding to the target code to the instance's working directory ( / workspace directory) to ensure that the code can access the required resources.

[0083] In this embodiment of the invention, a WebContainers instance pool can be implemented based on the object pool design pattern, and the "idle-occupied-release" state of the instance can be managed through Promise; the virtual file system can be mounted using the mount method of @webcontainer / api, and the underlying implementation uses SharedArrayBuffer to achieve efficient data interaction between the browser thread and the WebAssembly instance.

[0084] S16, Obtain monitoring data for the target code.

[0085] The monitoring data includes execution results, performance data (peak or average execution time and memory usage), and security events. Security events include the number of violations (the number of times paths or domains outside the allowed list were accessed) and the error stacks corresponding to the violations (the code context in the target code where the violation occurred). When the execution result is a failure, the execution result also includes error details (type / location / reason), and the reason is also understood as a problem description.

[0086] Optionally, use WebWorkers to start three monitoring threads: 1. Listen for stdout / stderr events using addEventListener, capture stdout / stderr output (record execution results and error information); 2. Record the start / end time of execution using performance.now(), and calculate the total time; 3. Listen to the memory object of WebAssembly and read the peak memory usage in real time.

[0087] It should be noted that during code execution, the writeFile / readFile methods of the virtual file system and the fetch method of network requests can be proxied through the Proxy to check whether the access path or domain name is in the allowed list (such as prohibiting writing to the / etc path and prohibiting requests to domain names other than http: / / localhost:8080); if the code throws an error (such as ReferenceError: data is not defined), the source-map is used to map to the line number and column number of the original code, thereby capturing the error stack.

[0088] Specifically, a JavaScript Proxy is used to intercept sensitive operations, and the legality of paths / domains is verified based on the Access Control List (ACL). The source-map library is used to parse the WebAssembly execution stack (converting WASM bytecode locations into raw code locations) to ensure accurate error location.

[0089] In one alternative implementation, monitoring data such as execution results, performance data, and security events can be integrated to obtain monitoring data in a standardized format. The source of each field in the monitoring data can also be marked (e.g., error.location from sourcemap parsing, performance.time from performance.now() calculation) and passed to the subsequent feedback analysis module to determine whether the target code is qualified.

[0090] Optionally, type validation can be used to ensure the structural consistency of the monitoring data; MsgPack can be used to compress the data (reduce transmission volume) and improve the efficiency of data transmission between modules.

[0091] S17: Determine whether the target code is qualified based on the monitoring data. If qualified, proceed to S18; if not qualified, proceed to S21.

[0092] In one alternative implementation, if the execution is successful, the performance meets the standards (execution time does not exceed the time threshold of 200ms and the peak or average memory usage does not exceed the bandwidth threshold of 30MB) and the risk is low (the number of violations does not exceed the number threshold and the security risk value after weighted calculation of violations does not exceed the security threshold), the target code is determined to be qualified.

[0093] S18 outputs the target code for the current version.

[0094] S21, Generate corresponding correction instructions based on the reasons for non-compliance. The correction instructions are natural language instructions that the generative intelligent model can understand.

[0095] Optionally, the T5-small model (lightweight text generation model) is used to convert structured data into natural language suggestions (i.e., correction instructions), and the accuracy of the correction instructions is optimized by fine-tuning; the instruction format is fixed based on the Handlebars template engine to ensure that each instruction contains complete elements and avoid AI understanding bias.

[0096] In the code generation method based on generative intelligent models provided in this embodiment of the invention, a feedback analysis hub is constructed. This hub can clean, classify, associate and abstract the original monitoring data, and finally generate structured, highly semantic natural language correction instructions, thereby opening up the key link from execution failure to intelligent repair.

[0097] S22, the correction instructions, structured task descriptions, and code generation records corresponding to the structured task descriptions are injected into the prompt word template of the generative intelligent model, so as to generate a new round of initial code that conforms to the target language based on the content in the prompt word template.

[0098] The code generation record can be the code generation record from the most recent rounds (it can be, but is not limited to, 3 rounds) to avoid duplicate errors.

[0099] Optionally, when injecting correction instructions, structured task descriptions, and corresponding code generation records into the prompt word template of the generative intelligent model: template splicing technology (such as EJS templates) is used to integrate multi-source information, and deduplication algorithms (such as SimHash) are used to filter duplicate error descriptions in the code generation records to reduce prompt word redundancy; token counting tools (such as tiktoken) are used to control the length of prompt words to avoid exceeding the token limit of the AI ​​model.

[0100] In the code generation method based on generative intelligent models provided in this embodiment of the invention, AI is repeatedly invoked through a multi-objective driven iterative control strategy. Based on multiple rounds of historical records, current performance indicators, and demand matching degree, optimization prompts for the next round are dynamically constructed, and clear termination conditions are set to ensure the efficiency and effectiveness of the closed loop.

[0101] Please refer to Figure 5 If the target code is not qualified, the code generation method based on the generative intelligent model also includes: S20, which is described in detail below.

[0102] S20 determines whether the reason for non-compliance in the current round is the same as the reason for non-compliance in the previous N rounds. If they are the same, the iteration ends; otherwise, S21 is executed.

[0103] Where N can be, but is not limited to, 3.

[0104] If the reason for non-compliance in the current round is the same as the reason for non-compliance in the previous N rounds, the iteration ends and no correction instruction is generated. At this time, the intelligent model cannot complete intelligent correction and manual intervention is required to prompt the user to check.

[0105] Please continue to refer to this. Figure 5 If the target code is qualified, the code generation method based on the generative intelligent model also includes: S19, which is described in detail below.

[0106] S19 generates and displays a record report.

[0107] The record report includes the target code generated in each round and its corresponding repair record, environment configuration (such as dependency list, virtual file path) and performance improvement analysis. The repair record corresponds to the correction instructions, and the performance improvement analysis includes the performance improvement corresponding to the target code in each round.

[0108] Optionally, the recorded report can be displayed to the user through the interface, supporting functions such as "one-click copy code", "re-execute verification", and "download execution report".

[0109] Specifically, D3.js is used to generate execution flow sequence diagrams (showing the error types and fixes for each iteration) and performance comparison bar charts (intuitively presenting changes in execution time); execution reports in PDF format are generated based on the Blob API, supporting download on browsers; and one-click code copying is enabled through the Clipboard API, improving the user experience.

[0110] Optionally, when the reason for non-compliance is execution failure (an error occurred), the correction instructions include error details and repair suggestions. For example, "Type: RuntimeError; Location: Row 8, Column 15; Description: The map method was called when the variable data was undefined; Suggestion: Add a non-null check if (data&&Array.isArray(data)) { ...}".

[0111] When the reason for non-compliance is performance failure (execution time exceeds the time threshold by 200ms or peak or average memory usage exceeds the bandwidth threshold by 30MB), the correction instructions include performance failure analysis and repair suggestions.

[0112] When the reason for non-compliance is excessive risk (the number of violations exceeds the threshold, or the weighted safety risk value of the violations exceeds the safety threshold), the correction instruction includes a natural language description of the error stack and repair suggestions.

[0113] Please refer to Figure 6 When fixing code during the development process, the code generation method based on the generative intelligent model also includes: S31, S32 and S33, which are described in detail below.

[0114] S31 parses and transforms the user's natural language requirements to obtain a structured task description.

[0115] S32, inject the structured task description, the generated code snippets, and the error logs into the prompt word template of the generative intelligent model, and the generative intelligent model generates repair code based on the content in the prompt word template.

[0116] S33, adapt and adjust the repair code provided by the generative intelligent model according to the environment adaptation tag to obtain the target repair code.

[0117] This invention also provides a program product that, when executed by a processor, implements the above-described code generation method based on a generative intelligent model.

[0118] This invention also provides a storage medium storing computer instructions and programs, which, when read and executed, perform the code generation method based on the generative intelligent model described above. The storage medium may include memory, flash memory, registers, or a combination thereof.

[0119] The following provides an electronic device, which may be a computer device, a mobile phone device, or a server device, such as... Figure 1 As shown, the above-described code generation method based on a generative intelligent model can be implemented. Specifically, the electronic device includes: a processor 10, a memory 11, and a bus 12. The processor 10 may be a CPU. The memory 11 is used to store one or more programs, and when one or more programs are executed by the processor 10, the code generation method based on a generative intelligent model described in the above embodiment is executed.

[0120] In summary, the code generation method and program product based on a generative intelligent model provided by this invention parses and transforms user natural language requirements to obtain a structured task description. This structured task description is then injected into a prompt word template of the generative intelligent model. The generative intelligent model generates initial code conforming to the target language based on the content of the prompt word template. The code provided by the generative intelligent model is then adapted and adjusted according to environment adaptation tags to obtain the target code. By using environment adaptation tags added during the code generation process as a reference, statements that are incompatible with the environment constraint rule base are adjusted. This improves the efficiency and accuracy of adaptation adjustments while ensuring that the adapted code can run in a browser.

[0121] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

[0122] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered in all respects as exemplary and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.

Claims

1. A code generation method based on a generative intelligent model, characterized in that, The method includes: The user's natural language requirements are parsed and transformed to obtain a structured task description, wherein the structured task description includes key information in the user's natural language requirements, target dependency libraries matching the key information, metadata of the current project, and environment constraint rule library corresponding to the browser. The metadata of the current project includes a list of installed dependencies, and the key information includes the target language and functional points. The structured task description is injected into the prompt word template of the generative intelligent model. The generative intelligent model generates initial code that conforms to the target language based on the content in the prompt word template. The initial code includes dependency declaration statements and core functional logic statements corresponding to each functional point. The dependency declaration statements are matched with the target dependency library and the metadata of the current project. Each core functional logic statement carries a corresponding environment adaptation tag. The environment adaptation tag is used to indicate whether the core functional logic statement is compatible with the environment constraint rule library. If it is not compatible, the environment adaptation tag also includes the replacement object and the corresponding replacement rule in the core functional logic statement. The code provided by the generative intelligent model is adapted and adjusted according to the environment adaptation tags to obtain the target code.

2. The code generation method based on a generative intelligent model as described in claim 1, characterized in that, The process of parsing and transforming the user's natural language requirements to obtain a structured task description includes: Extract key information from the user's natural language requirements; The key information is used to perform vector feature matching in a vector database to determine the target historical record, wherein the vector database is used to store user historical interaction records, and the target historical record is the user historical interaction record that meets the matching requirements; Obtain the target dependency library corresponding to the target historical record; The key information, the target dependency library, the metadata of the current project, and the browser's corresponding environment constraint rule library are integrated into a standardized structured task description.

3. The code generation method based on a generative intelligent model as described in claim 1, characterized in that, Before adapting and adjusting the code provided by the generative intelligent model according to the environment adaptation tags to obtain the target code, the method further includes: The initial code after adding environment adaptation tags is standardized.

4. The code generation method based on a generative intelligent model as described in claim 1, characterized in that, The step of adapting and adjusting the code provided by the generative intelligent model according to the environment adaptation tags to obtain the target code includes: The abstract syntax tree parser is used to traverse the abstract syntax tree of the code provided by the generative intelligent model to locate the environment adaptation tags and extract the dependency declaration statements. Based on the environment adaptation flag indicating incompatibility, determine the replacement objects and corresponding replacement rules in the core functional logic statements, and make corresponding adaptation adjustments to obtain the replaced core functional logic statements. A dependency graph is constructed based on the extracted dependency declaration statements. The dependency graph includes the dependency library name, the version of the dependency library, and the compatibility relationship between each version of the dependency library and the environment constraint rule base. Install compatible dependencies from the dependency graph; If any version of the dependency library is incompatible with the environment constraint rule library, a distance algorithm is used to match an alternative dependency library with similar functions, the alternative dependency library is installed, and the dependency declaration statements in the code are modified according to the alternative dependency library to obtain the target code.

5. The code generation method based on a generative intelligent model as described in claim 1, characterized in that, After adapting and adjusting the code provided by the generative intelligent model according to the environment adaptation tags to obtain the target code, the method further includes: Mount the target code and its installed dependencies to the working directory of an idle instance in the browser to run the target code; The monitoring data of the target code is obtained. The monitoring data includes execution results, performance data, and security events. The security events include the number of violations and the error stacks corresponding to the violations. When the execution result is a failure, the execution result also includes error details. Based on the monitoring data, determine whether the target code is qualified; if qualified, output the target code of the current version. If it fails, a corresponding correction instruction is generated based on the reason for the failure. The correction instruction is a natural language instruction that the generative intelligent model can understand. The correction instructions, the structured task description, and the code generation record corresponding to the structured task description are injected into the prompt word template of the generative intelligent model to generate a new round of initial code that conforms to the target language based on the content in the prompt word template.

6. The code generation method based on a generative intelligent model as described in claim 5, characterized in that, If the target code is not qualified, the method further includes: Determine if the reason for non-compliance in the current round is the same as the reason for non-compliance in the previous N rounds. If they are the same, end the iteration.

7. The code generation method based on a generative intelligent model as described in claim 5, characterized in that, If the target code is qualified, the method further includes: Generate and display a record report, which includes the target code generated in each round and its corresponding repair record, environment configuration, and performance improvement analysis. The repair record corresponds to the correction instruction, and the performance improvement analysis includes the performance improvement corresponding to the target code in each round.

8. The code generation method based on a generative intelligent model as described in claim 5, characterized in that, When the reason for non-compliance is execution failure, the correction instruction includes error details and repair suggestions; When the reason for non-compliance is performance failure, the correction instruction includes performance failure analysis and repair suggestions; When the reason for non-compliance is that the risk is too high, the correction instruction includes a natural language description of the error stack and a repair suggestion.

9. The code generation method based on a generative intelligent model as described in claim 1, characterized in that, When fixing code during development, the method also includes: The user's natural language requirements are parsed and transformed to obtain a structured task description; The structured task description, along with the generated code snippets and error logs, are injected into the prompt word template of the generative intelligent model. The generative intelligent model then generates repair code based on the content of the prompt word template. The repair code provided by the generative intelligent model is adapted and adjusted according to the environment adaptation tag to obtain the target repair code.

10. A program product, characterized in that, When the program product is executed by the processor, it implements the code generation method based on the generative intelligent model as described in any one of claims 1-9.