Code generation method and device based on dynamic adoption closed-loop system, storage medium and server
By using a dynamic adoption closed-loop system, user interaction operations are monitored to generate code adoption information, a programming habit graph is constructed, and the code generation model is updated. This solves the problem of insufficient adaptation between code generation and user personalization in existing technologies, and improves the personalization and accuracy of code generation.
Patent Information
- Application Number
- CN202511057963.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-30
- Publication Date
- 2025-11-14
AI Technical Summary
Existing code generation technologies are not sufficiently adapted to enterprise-level development scenarios, struggle to cover customized frameworks and have poor compatibility with enterprise technology stacks, resulting in generated code that does not meet user needs.
A dynamic adoption closed-loop system is adopted, which generates code adoption information by receiving user interaction operations, constructs a user programming habit map, and updates the network parameters of the code generation model to form a continuously optimized dynamic closed-loop system.
It improves the personalization and adaptability of code generation, enhances code quality and user satisfaction, and adapts to changes in user needs at different stages.
Smart Images

Figure CN120950047A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of office automation, and in particular to a code generation method, apparatus, storage medium and server based on a dynamic adoption closed-loop system. Background Technology
[0002] As project size and complexity continue to rise, developers' need for efficient programming tools is becoming increasingly urgent. Code generation tools and auxiliary plugins, as core means to improve development efficiency, have been widely used in various software development scenarios. Their core value lies in reducing repetitive coding work by automatically generating basic code structures, allowing developers to focus on business logic design and system architecture optimization, thereby significantly shortening project delivery cycles and reducing the risk of human error.
[0003] Current mainstream code generation technologies are primarily based on large-scale pre-trained language models. These models, through deep learning on large-scale public code datasets, have mastered general programming syntax and common algorithmic patterns, enabling them to generate code snippets with basic functionality. However, existing technologies have significant limitations: First, the models typically use static parameters after deployment, resulting in insufficient adaptability of the generated code to the user's individual needs; second, enterprise-level development scenarios are highly specialized, involving complex constraints such as customized frameworks, internal API specifications, and security compliance requirements, while models trained on public data struggle to cover such vertical domain knowledge, leading to poor compatibility between the generated code and the enterprise's technology stack. Summary of the Invention
[0004] This application provides a code generation method, apparatus, storage medium, and server based on a dynamic adoption closed-loop system, which can solve the problems of insufficient adaptation between generated code and user personalization and low enterprise satisfaction in the prior art. The technical solution is as follows:
[0005] In a first aspect, embodiments of this application provide a code generation method based on a dynamic adoption closed-loop system, the method comprising:
[0006] Receive code generation requests from users via IDE plugins;
[0007] In response to the code generation request, code writing knowledge is retrieved from the enterprise-specific code knowledge base, and the code context of the code output location is obtained;
[0008] Based on the code writing knowledge and the code context, output code snippets using the current code generation model;
[0009] The code adoption information is obtained by monitoring user interaction with the code snippet and the code adoption information is written into the code adoption dataset.
[0010] When the preset update cycle arrives, a user programming habit map is generated based on the code adoption dataset;
[0011] The network parameters of the current code generation model are updated based on the user programming habit graph.
[0012] Secondly, embodiments of this application provide a code generation apparatus based on a dynamic adoption closed-loop system, the apparatus comprising:
[0013] The receiving unit is used to receive code generation requests generated by users through IDE plugins.
[0014] The acquisition unit is used to retrieve code writing knowledge from the enterprise-specific code knowledge base and acquire the code context of the code output location in response to the code generation request.
[0015] The output unit is used to output a code snippet based on the code writing knowledge and the code context, using the current code generation model.
[0016] The monitoring unit is used to monitor the user's interactive operations on the code snippet to obtain code adoption information, and to write the code adoption information into the code adoption dataset;
[0017] The generation unit is used to generate a user programming habit map based on the code adoption dataset when a preset update cycle arrives.
[0018] The update unit is used to update the network parameters of the current code generation model according to the user programming habit graph.
[0019] Thirdly, embodiments of this application provide a computer storage medium storing a plurality of instructions adapted for loading by a processor and executing the above-described method steps.
[0020] Fourthly, embodiments of this application provide a server that may include a processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and to execute the above-described method steps.
[0021] The beneficial effects of the technical solutions provided in some embodiments of this application include at least the following:
[0022] By monitoring user interactions to generate code adoption information, a user programming habit map is constructed. Based on this map, the parameters of the code generation model are updated, making the generated code more aligned with individual user programming habits and improving code generation quality and user satisfaction. Based on a preset update cycle, the model is continuously updated using accumulated code adoption data, forming a dynamic closed-loop system that enables continuous optimization of the code generation model to adapt to changing user needs at different stages. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 This is a schematic diagram of the network architecture provided in the embodiments of this application;
[0025] Figure 2 This is a flowchart illustrating the code generation method based on a dynamic adoption closed-loop system provided in an embodiment of this application;
[0026] Figure 3 This is a schematic diagram of the structure of a code generation device based on a dynamic adoption closed-loop system provided in this application;
[0027] Figure 4 This is a schematic diagram of a computer storage medium provided in an embodiment of this application;
[0028] Figure 5 This is a schematic diagram of the structure of a server provided in this application. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0030] It should be noted that the code generation method based on the dynamic adoption closed-loop system provided in this application is generally executed by the server, and correspondingly, the code generation device based on the dynamic adoption closed-loop system is generally set in the server.
[0031] Figure 1 An exemplary network architecture is shown that can be applied to the code generation method or apparatus based on the dynamic adoption closed-loop system of this application.
[0032] like Figure 1 As shown, the network architecture may include: terminal device 101 and server 102. Terminal device 101 and server 102 can communicate with each other via the network, which serves as the medium for providing communication links between the various units. The network may include various types of wired or wireless communication links, such as: wired communication links including fiber optic cables, twisted-pair cables, or coaxial cables; and wireless communication links including Bluetooth communication links, Wi-Fi communication links, or microwave communication links.
[0033] Among them, server 102 controls the execution of the review process for the power distribution network relocation project, and the terminal equipment is the client of each review user.
[0034] It should be noted that the terminal device 101 and the server 102 can be either hardware or software. When the terminal device 101 and the server 102 are hardware, they can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the terminal device 101 and the server 102 are software, they can be implemented as multiple software programs or software modules (e.g., used to provide distributed services), or as a single software program or software module; no specific limitations are made here.
[0035] The terminal device of this application can be equipped with various communication client applications, such as video recording applications, video playback applications, voice interaction applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0036] A terminal device can be either hardware or software. When the terminal device is hardware, it can be various terminal devices with a display screen, including but not limited to smartphones, tablets, laptops, and desktop computers. When the terminal device is software, it can be installed on the terminal devices listed above. It can be implemented as multiple software programs or software modules (e.g., used to provide distributed services) or as a single software program or software module; no specific limitation is made here.
[0037] When the terminal device is hardware, it can also be equipped with a display device and a camera. The display device can be any device capable of displaying information, and the camera is used to capture video streams. For example, the display device can be a cathode ray tube display (CR), a light-emitting diode display (LED), an e-ink screen, a liquid crystal display (LCD), or a plasma display panel (PDP). Users can use the display device on the terminal device to view displayed text, images, videos, and other information.
[0038] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is for illustrative purposes only. Depending on implementation needs, there can be any number of terminal devices, networks, and servers.
[0039] The following will be combined with the appendix Figure 2This application provides a detailed description of the code generation method based on a dynamic adoption closed-loop system provided in its embodiments. The code generation device based on the dynamic adoption closed-loop system in these embodiments may be... Figure 1 The server shown.
[0040] Please see Figure 2 This document provides a flowchart illustrating a code generation method based on a dynamic adoption closed-loop system, as described in an embodiment of this application. Figure 2 As shown, the method described in this application embodiment may include the following steps:
[0041] S201: Receive code generation requests generated by users through IDE plugins.
[0042] The server listens for and receives code generation requests from Integrated Development Environment (IDE) plugins via a network interface. These requests are typically generated when a user triggers a specific action within the IDE (such as clicking a button or entering a command) and are transmitted via a secure communication protocol (such as HTTPS). The server parses the metadata in the request, including user identification, project context, and code generation target description, to initialize subsequent processing. At this stage, the server performs request verification to ensure the request origin is legitimate and the data format is compliant, preventing invalid or malicious input from interfering with system operation.
[0043] For example:
[0044] For example, when using the Visual Studio Code IDE, a user clicks the "Generate Sorting Function" button via an installed plugin. The plugin collects a brief description of the user input (such as "Implement an ascending sort of an integer array") and encapsulates it into a request message. Upon receiving this request, the server parses out the user ID "dev_123", the project ID "project_alpha", and the target code type "sorting algorithm", thus providing the basis for further processing.
[0045] Furthermore, in some possible embodiments of this application, the server continuously listens for request traffic from the IDE plugin through a pre-configured communication port (such as HTTPS443). This channel employs a two-way TLS encryption protocol to ensure transport layer security. The listening service is deployed in a highly available cluster mode, distributing requests through a load balancer to avoid response interruptions caused by single points of failure.
[0046] When a request arrives at the server, the following authentication operations are performed in sequence:
[0047] Request format authentication: Verify the integrity of the JSON data structure, check the existence and format compliance of required fields (such as request_id, timestamp), and discard requests with invalid formats.
[0048] User authentication: Call the enterprise unified identity service to verify the validity of the digital signature token (JWT) in the request header and confirm whether the user's permissions include code generation functionality.
[0049] Security Authentication: The rule engine scans request content to detect risks such as malicious code injection characteristics (e.g., abnormal recursive call patterns) and out-of-bounds parameter access, and blocks high-risk requests.
[0050] After successful authentication, the server performs structured parsing:
[0051] Extract the user_id field and map it to the enterprise account system, converting it into a unique internal user identifier.
[0052] Parse the project_id field and associate it with the project metadata in the version control system (such as the Git repository path).
[0053] The code_description natural language description is semantically normalized, including removing ambiguous abbreviations, completing technical terms (such as "sorting" → "quick sorting algorithm"), and outputting explicit instructions that can be processed by machines.
[0054] This embodiment establishes a trusted request processing pipeline: encrypted communication ensures data confidentiality, a triple authentication mechanism effectively isolates unauthorized access and malicious input, and structured parsing ensures downstream services obtain accurate operation instructions. The technical benefits include: building a secure access barrier for the enterprise development environment, reducing the risk of unauthorized code generation; improving the robustness of the request processing flow, preventing invalid requests from consuming system resources; and providing standardized input for subsequent knowledge retrieval and code generation, enhancing consistency in end-to-end decision-making.
[0055] S202. In response to the code generation request, retrieve code writing knowledge from the enterprise-specific code knowledge base and obtain the code context of the code output location.
[0056] After verifying the request, the server first accesses the enterprise-specific code knowledge base, typically a structured database or knowledge graph system. Based on the target description in the request, it performs a retrieval to obtain relevant coding knowledge. This includes querying structured knowledge entries such as best practices, design patterns, and security guidelines. Simultaneously, the server obtains contextual information about the code output location through APIs provided by the IDE plugin, such as the current file content, code blocks near the cursor position, variable definitions, and dependencies. The server integrates these two parts of data to form a complete input context, ensuring that subsequent code generation conforms to enterprise standards and the user's actual environment. This process involves efficient data query algorithms and context parsing mechanisms to optimize retrieval speed and accuracy.
[0057] For example, when generating a sorting function in response to a user request, the server retrieves an entry for "Efficient Sorting Algorithm Guide" from the enterprise knowledge base, which includes best practices for quicksort and mergesort. Simultaneously, it uses an IDE plugin to access the content of the user's currently edited Java file, finding the cursor within a method named "sortArray," with the context indicating that the method's input is an integer array variable "data." The server integrates this information into a structured context to guide the next step of code generation.
[0058] In some possible embodiments of this application, the server requests code content near the cursor position through a standardized interface provided by the IDE plugin. After locating the line number of the cursor, this process automatically expands to capture several adjacent lines of code to form a continuous segment, while simultaneously identifying the syntactic boundaries of this segment to ensure semantic integrity. The server performs desensitization processing on the original code, removing any potentially sensitive data or internal keys, and generating a clean context that can be used for subsequent processing.
[0059] When a user actively selects a specific code segment, the server receives the original content of the selected area from the IDE plugin. This content retains the precise start and end positions selected by the user. The server further parses the project path and dependencies of the file to which it belongs, forming an independent context unit with metadata tags. If the selected content contains cross-file references, the server automatically associates the fragments from related files to form a complete context.
[0060] For build requests aimed at code optimization, the server performs in-depth analysis on the selected code. It extracts logical structure patterns, performance bottlenecks, and API call chains, and merges these analysis results with traditional context to construct an enhanced context data body with optimization guidance, providing a basis for subsequent refactoring recommendations.
[0061] This embodiment achieves precise capture of development intent and scenario adaptation. The cursor positioning mode meets the need for rapid insertion, while the code selection mode supports in-depth optimization scenarios. Technical benefits include: ensuring strict consistency between the acquired context and the user's actual coding position or operation target; maintaining the semantic integrity of code blocks through syntax boundary recognition and dependency analysis; and ensuring the security of enterprise code asset transmission through de-identification and metadata tagging.
[0062] S203. Based on the code writing knowledge and the code context, output code snippets on the IDE plugin using the current code generation model.
[0063] The server takes retrieved code writing knowledge and code context as input, loads and runs the currently deployed code generation model (such as an AI model based on the Transformer architecture). This model generates context-appropriate code snippets through natural language processing and code semantic analysis. The generation process includes: the model parsing the input data, predicting the most likely code sequence, and performing syntax and logic checks to ensure output usability. The generated code snippets are then returned via the communication channel between the server and the IDE plugin and displayed in the user's IDE interface. During this stage, the server monitors model execution latency and resource consumption to ensure real-time response.
[0064] For example:
[0065] For example, based on retrieved knowledge of sorting algorithms and context (an integer array "data"), the code generation model outputs a code snippet implementing quicksort, including loop structures and recursive calls. The server sends this snippet back to the IDE plugin, and the user sees the generated code displayed at the cursor position in Visual Studio Code, showing the complete method body of "public void sortArray(int[]data){…}".
[0066] Furthermore, the server loads the pre-deployed code to generate model instances into the in-memory computing environment. The model loading process includes weight parameter verification and runtime self-checks to ensure the model is in a stable working state that can respond to requests. The model runtime environment is configured with hardware acceleration resources to meet low-latency computing requirements.
[0067] The server logically integrates the code writing knowledge retrieved from the enterprise knowledge base with the user's code context. The integration process extracts the core features of both types of data and reconstructs them into an enhanced contextual data volume that includes syntactic rule constraints, business logic relationships, and performance optimization points. This data volume is then converted by a standardization engine into the input format specified by the model, including sequence length normalization and alignment of key feature dimensions.
[0068] The formatted data is input into the code generation model's computational unit. The model, based on a deep neural network architecture, performs multi-level feature parsing and pattern matching, progressively generating code character sequences that conform to technical specifications. During the generation process, a syntax validation module is nested to eliminate logical conflicts and structural errors in real time, outputting basic code snippets with direct executable functionality.
[0069] The server transmits the generated code to the user's IDE plugin via a dedicated communication link. The transmission protocol ensures data integrity and encryption. Upon receiving the code, the plugin accurately inserts or replaces the target area in the editor interface based on the code output location metadata recorded in the initial request. The insertion process maintains the original code indentation style and formatting rules.
[0070] S204. Monitor the user's interaction with the code snippet to obtain code adoption information, and write the code adoption information into the code adoption dataset.
[0071] The server continuously monitors user interactions with generated code snippets through the IDE plugin's callback mechanism, such as code adoption, editing, rejection, or ignoring. These actions are captured as code adoption information, including structured data such as adoption status (e.g., fully adopted or partially modified), modification content, and operation timestamps. The server then writes this information to a code adoption dataset, which is typically a distributed database or log system, employing transactional writes to ensure data consistency and durability. The dataset is designed with a scalable architecture to support efficient storage and subsequent analysis. The monitoring process involves an event-driven mechanism to ensure real-time capture of user behavior without impacting IDE performance.
[0072] For example:
[0073] For example, a user modifies the generated sorting function: removing the recursive part and replacing it with an iterative implementation. The server detects this operation, records the adoption information as "partially adopted," the edit details as "replace recursion with loop," and associates it with the user ID and timestamp. This information is written to a record in the dataset, stored in a JSON format including fields such as {"user_id":"dev_123","adoption_status":"modified","change_details":"iterative_implementation"}.
[0074] In some possible embodiments of this application, the step of monitoring user interaction with the code snippet to obtain code adoption information and writing the code adoption information into the code adoption dataset includes:
[0075] The monitoring process is initiated through the callback mechanism of the IDE plugin to listen for user interaction events with the generated code snippets. These interaction events include: edit events, copy events, and ignore events.
[0076] Capture event data and extract code adoption information, which includes: adoption status, modification details, and timestamp;
[0077] The code adoption information is converted into structured data, and the structured data is written into the code adoption dataset.
[0078] The server establishes a continuous listening channel through the IDE plugin's callback interface, initiating a monitoring process for the generated code snippets. This channel captures user action event streams in real time, including editing actions, content copying operations, and UI ignore actions. The event capture engine automatically filters out invalid operations such as UI scrolling, accurately identifying the interaction intent directly related to the code snippets.
[0079] When a valid event is triggered, the server extracts the core feature data of the event. An adoption status classifier determines the essential attributes of the operation, distinguishing between three states: full adoption, modified adoption, and rejected adoption. A modification detail extraction module records the location of code additions and deletions, the content of changes, and refactoring pattern characteristics. Event timestamps are synchronously recorded to millisecond precision, and a unified clock source on the associated server ensures timing accuracy.
[0080] The extracted raw information is input into a structured transformation engine. This engine maps unstructured operation logs to a predefined data model, generating standard data units containing fields such as event type labels, code difference summaries, and operation timelines. The transformation process automatically completes user environment metadata, including the development language version and operating system type.
[0081] Structured data is persistently stored in the code adoption dataset via a batch write interface. The storage layer adopts a sharded architecture, allocating storage nodes based on user identifier hashes. Transaction consistency checks are added during the write process to ensure data integrity and prevent data loss under high concurrency scenarios. The storage engine synchronously builds time-range indexes and operation-type indexes to support subsequent efficient querying and analysis.
[0082] S205. When the preset update cycle arrives, generate a user programming habit map based on the code adoption dataset.
[0083] The server, triggered at preset periodic update cycles (e.g., daily or weekly), batches of data are read from the code adoption dataset and data analysis algorithms (e.g., clustering or association rule mining) are applied to generate a user programming habit graph. This graph is a structured knowledge representation, for example, built on a graph database, where nodes represent programming habits (e.g., preferred code patterns, frequently used libraries, or modification tendencies), and edges represent the strength of associations between habits. The generation process includes: data cleaning, feature extraction (e.g., adoption frequency and edit type statistics), graph modeling, and visualization preparation. The server ensures that graph generation is efficient and scalable to handle large-scale datasets, ultimately outputting a dynamically updated knowledge model that reflects the programming preferences of user groups or individuals.
[0084] For example:
[0085] For example, during the weekly update cycle, server analysis of the dataset revealed that user "dev_123" repeatedly modified the generated sorting code, preferring iteration over recursion. After the graph was generated, the nodes included "prefers_iterative_loops" and "avoids_recursion," with edge weights indicating that this preference occurred 80% of the time in the sorting scenario. The graph was stored in a graph structure for easy subsequent queries and model updates.
[0086] In some possible embodiments of this application, the enterprise-specific code knowledge base is updated when a preset update cycle arrives. The update process includes:
[0087] The server automatically initiates the knowledge base update process at a preset update cycle (such as during low-load periods each day). First, it scans system logs and code repositories, using a statistical analysis module to identify data that meets the following criteria:
[0088] High-frequency API extraction: Calculate the call frequency based on API call logs, filter API interfaces that exceed a preset threshold (e.g., weekly call volume > 1000 times), and record their usage scenarios, parameter patterns, and performance data.
[0089] Excellent code capture: Extracting code snippets that meet specific quality standards from version control systems (such as Git). These standards include code review pass rate, static analysis score (such as SonarQube rating of A or above), and reuse frequency.
[0090] New standard integration: Synchronize the latest programming standard documents (such as Markdown or XML format) released by the enterprise, and parse the rule entries, security requirements and design pattern constraints.
[0091] The server converts the above three types of raw data into a unified knowledge representation format:
[0092] High-frequency API information is converted into standardized use case templates, which include fields such as API signature, typical call examples, and performance optimization suggestions.
[0093] Excellent code snippets undergo semantic abstraction, stripping away business logic while retaining core structures such as general design patterns (e.g., factory pattern implementation) and boundary handling logic (e.g., null value checking).
[0094] Programming standards are broken down into executable rule entries; for example, "thread pools must be configured with a rejection policy" is transformed into validation rules in a knowledge base.
[0095] The server injects the processed data into the enterprise-specific code knowledge base through the following process:
[0096] Conflict detection: Compare newly added knowledge with existing entries to identify duplicate or contradictory content (such as multiple optimization schemes for the same API) and trigger a manual review process.
[0097] Incremental update: A non-overwrite writing strategy is adopted, adding version tags and effective timestamps to each knowledge entry, and retaining historical versions to support backtracking.
[0098] Index optimization: Reconstruct knowledge graph relationships (e.g., associate high-frequency APIs with relevant design pattern nodes) to ensure retrieval efficiency.
[0099] The update mechanism in this embodiment enables the dynamic closed-loop evolution of the enterprise code knowledge base: by automatically collecting high-frequency API practices, high-quality code paradigms, and real-time specifications, implicit development experience is transformed into explicit structured knowledge.
[0100] Furthermore, in some embodiments of this application, the process of generating a user programming habit map includes:
[0101] A trigger signal is generated when the preset update cycle arrives;
[0102] Based on the trigger signal, code adoption data is read in batches from the code adoption dataset;
[0103] Clean the read data and extract features;
[0104] Clustering algorithms are applied to process the cleaned dataset to construct a graph of user programming habits;
[0105] Optimize the graph structure and store it in a graph database system.
[0106] Specifically, the server's built-in scheduling engine automatically generates a trigger signal when the preset update cycle arrives. This signal activates the graph generation task queue, and the trigger condition is typically configured to a low-load system time window, such as the early morning hours each day. After verifying the time conditions and system resource availability, the scheduler sends an execution command to the data processing module.
[0107] The data processing module initiates batch data read operations based on trigger signals. This operation locates the latest incremental partition of the dataset and filters valid records by time range. The read process employs a paginated streaming mechanism to avoid overwhelming the database service with large amounts of data. Data shards are loaded in parallel based on user identifiers, ensuring efficient retrieval of tens of millions of records.
[0108] The raw data is read and enters the cleaning pipeline. The pipeline sequentially performs invalid record removal, outlier correction, and format standardization. The feature extraction engine then scans the cleaned data to identify key programming habit features, including code modification patterns, high-frequency refactoring operation types, and API selection preferences. Feature vectors are aggregated at the user level to generate an intermediate dataset.
[0109] Intermediate datasets are input into a distributed clustering computing cluster. The algorithm engine identifies groups with similar habits based on density clustering, generating an initial graph structure with habitual features as nodes and group association strength as edges. Graph nodes automatically inherit core attributes from feature vectors, such as habitual labels like "preference iterative loop" or "strict anomaly handling".
[0110] The graph optimization module performs topology compression and redundant edge elimination on the initial structure. The optimized graph is then imported into a graph database storage system, where the stored procedure automatically creates multi-dimensional indexes, including time-range indexes, user group indexes, and habitual tag indexes. The database engine performs storage sharding mapping to ensure horizontal scalability.
[0111] S206. Update the network parameters of the current code generation model according to the user programming habit graph.
[0112] The server uses the generated user programming habit graph as training data to update the parameters of the current code generation model. This typically involves transfer learning or fine-tuning techniques: the server loads the model's existing weights, converts the graph data into feature vectors (such as habit preference embeddings), and adjusts network parameters (such as the weights of neural network layers) through backpropagation. The update process is executed in the server's high-performance computing environment, with the optimization goal of improving the model's adaptability to user habits, such as reducing the editing rate of generated code. After the update is complete, the server deploys the new version of the model and monitors its performance metrics (such as improved adoption rate). This step ensures that the model evolves dynamically, forming a closed-loop optimization.
[0113] For example:
[0114] For example, based on the "preference for iterative loops" in the graph, the server fine-tunes the code generation model: when generating the sorting algorithm, the model parameters are adjusted to prioritize outputting the iterative implementation rather than recursion. After the update, when the same user requests the sorting function again, the model directly generates the iterative version, reducing the need for user editing and thus improving overall efficiency.
[0115] This application has the following specific beneficial effects:
[0116] First, the system receives code generation requests from users via IDE plugins. Then, in response, it retrieves code writing knowledge from an enterprise-specific code knowledge base and obtains the context of the code output location. Next, it uses the current code generation model, combined with the aforementioned knowledge and context, to output code snippets. Afterward, it monitors user interactions with the code snippets to obtain code adoption information, which is then written into the code adoption dataset. At preset update intervals, it generates a user programming habit graph based on the code adoption dataset and updates the network parameters of the current code generation model accordingly. This dynamic closed-loop system continuously optimizes the code generation model based on user programming habits, effectively improving the personalization and accuracy of code generation.
[0117] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0118] Please see Figure 3 This document illustrates a schematic diagram of a code generation apparatus based on a dynamic adoption closed-loop system provided in an exemplary embodiment of this application, hereinafter referred to as apparatus 3. Apparatus 3 can be implemented as all or part of a server through software, hardware, or a combination of both. Apparatus 3 includes: a receiving unit 301, an acquiring unit 302, an output unit 303, a monitoring unit 304, a generation unit 305, and an updating unit 306.
[0119] The receiving unit 301 is used to receive code generation requests generated by users through IDE plugins;
[0120] The acquisition unit 302 is used to retrieve code writing knowledge from the enterprise-specific code knowledge base and acquire the code context of the code output location in response to the code generation request.
[0121] Output unit 303 is used to output code snippets using the current code generation model based on the code writing knowledge and the code context;
[0122] The monitoring unit 304 is used to monitor the user's interactive operations on the code snippet to obtain code adoption information, and to write the code adoption information into the code adoption dataset;
[0123] The generation unit 305 is used to generate a user programming habit map based on the code adoption dataset when a preset update cycle arrives.
[0124] The update unit 306 is used to update the network parameters of the current code generation model according to the user programming habit graph.
[0125] In one or more possible embodiments, when a preset update cycle arrives, generating a user programming habit map based on the code adoption dataset further includes:
[0126] The system retrieves APIs with a call frequency exceeding a preset value, extracts excellent code, and acquires newly added programming standards. The retrieved code writing knowledge is then written into the enterprise-specific code knowledge base.
[0127] In one or more possible embodiments, receiving a code generation request generated by a user through an IDE plugin includes:
[0128] Listen for network request channels from IDE plugins;
[0129] When a user's code generation request arrives, perform request format authentication, user identity authentication, and security authentication.
[0130] After successful authentication, the code generation request is parsed to obtain the user identifier, project identifier, and code generation target description.
[0131] In one or more possible embodiments, the code context for obtaining the code output location includes:
[0132] Get the code adjacent to the cursor position and use the obtained code as the code context; or
[0133] The code selected by the user is used as the code context; the code generation request is used to optimize the selected code.
[0134] In one or more possible embodiments, the step of outputting code snippets using the current code generation model based on the code writing knowledge and the code context includes:
[0135] Load the currently deployed code generation model;
[0136] The code writing knowledge and the code context are integrated into enhanced context data, and the enhanced context data is converted into model input data in a preset format.
[0137] The input data of the model is passed to the current code generation model to generate a code snippet;
[0138] The code snippet is sent to the code output location in the user's IDE plugin.
[0139] In one or more possible embodiments, the step of monitoring user interactions with the code snippet to obtain code adoption information and writing the code adoption information into a code adoption dataset includes:
[0140] The monitoring process is initiated through the callback mechanism of the IDE plugin to listen for user interaction events with the generated code snippets. These interaction events include: edit events, copy events, and ignore events.
[0141] Capture event data and extract code adoption information, which includes: adoption status, modification details, and timestamp;
[0142] The code adoption information is converted into structured data, and the structured data is written into the code adoption dataset.
[0143] In one or more possible embodiments, generating a user programming habit map based on the code adoption dataset when a preset update cycle arrives includes:
[0144] A trigger signal is generated when the preset update cycle arrives;
[0145] Based on the trigger signal, code adoption data is read in batches from the code adoption dataset;
[0146] Clean the read data and extract features;
[0147] Clustering algorithms are applied to process the cleaned dataset to construct a graph of user programming habits;
[0148] Optimize the graph structure and store it in a graph database system.
[0149] It should be noted that the above-described embodiment of the device 3, when executing the code generation method based on the dynamic adoption closed-loop system, only illustrates the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the above functions. Furthermore, the code generation device based on the dynamic adoption closed-loop system and the code generation method embodiment based on the dynamic adoption closed-loop system provided in the above embodiment belong to the same concept, and their implementation process is detailed in the method embodiment, which will not be repeated here.
[0150] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0151] See Figure 4 The diagram shown is a schematic of a computer storage medium provided in an embodiment of this application. The computer storage medium can store multiple instructions (i.e., Figure 4 The computer program shown above, the instructions of which are adapted to be loaded and executed by a processor as described above. Figure 2 The method steps of the illustrated embodiment can be found in the following documentation for detailed execution. Figure 2 The specific details of the illustrated embodiments will not be elaborated here.
[0152] This application also provides a computer program product that stores at least one instruction, which is loaded and executed by the processor to implement the code generation method based on the dynamic adoption closed-loop system as described in the above embodiments.
[0153] Please see Figure 5 This provides a schematic diagram of a server structure for an embodiment of this application. For example... Figure 5 As shown, the server 500 may include: at least one processor 501, at least one network interface 504, a user interface 503, a memory 505, and at least one communication bus 502.
[0154] The communication bus 502 is used to enable communication between these components.
[0155] The user interface 503 may include a display screen and a camera. Optionally, the user interface 503 may also include a standard wired interface and a wireless interface.
[0156] The network interface 504 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0157] The processor 501 may include one or more processing cores. The processor 501 connects to various parts of the server 500 via various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 505, and by calling data stored in the memory 505. Optionally, the processor 501 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 501 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content to be displayed on the screen; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 501 and may be implemented as a separate chip.
[0158] The memory 505 may include random access memory (RAM) or read-only memory. Optionally, the memory 505 may include a non-transitory computer-readable storage medium. The memory 505 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 505 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 505 may also be at least one storage device located remotely from the aforementioned processor 501. Figure 5 As shown, the memory 505, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and application programs.
[0159] exist Figure 5In the server 500 shown, the user interface 503 is mainly used to provide an input interface for users and obtain user input data; while the processor 501 can be used to call the application program stored in the memory 505 and specifically execute, such as Figure 2 The method shown can be referred to for details. Figure 2 As shown, it will not be elaborated further here.
[0160] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory, or random access memory, etc.
[0161] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A code generation method based on a dynamic adoption closed-loop system, characterized in that, include: Receive code generation requests from users via IDE plugins; In response to the code generation request, code writing knowledge is retrieved from the enterprise-specific code knowledge base, and the code context of the code output location is obtained; Based on the code writing knowledge and the code context, output code snippets using the current code generation model; The code adoption information is obtained by monitoring user interaction with the code snippet and the code adoption information is written into the code adoption dataset. When the preset update cycle arrives, a user programming habit map is generated based on the code adoption dataset; The network parameters of the current code generation model are updated based on the user programming habit graph.
2. The method according to claim 1, characterized in that, When the preset update cycle arrives, a user programming habit map is generated based on the code adoption dataset, which also includes: The system retrieves APIs with a call frequency exceeding a preset value, extracts excellent code, and acquires newly added programming standards. The retrieved code writing knowledge is then written into the enterprise-specific code knowledge base.
3. The method according to claim 1 or 2, characterized in that, The process of receiving code generation requests generated by users through IDE plugins includes: Listen for network request channels from IDE plugins; When a user's code generation request arrives, perform request format authentication, user identity authentication, and security authentication. After successful authentication, the code generation request is parsed to obtain the user identifier, project identifier, and code generation target description.
4. The method according to claim 3, characterized in that, The code context for obtaining the code output location includes: Get the code adjacent to the cursor position and use the obtained code as the code context; or The code selected by the user is used as the code context; the code generation request is used to optimize the selected code.
5. The method according to claim 1, 2, or 4, characterized in that, The step of outputting code snippets using the current code generation model based on the code writing knowledge and the code context includes: Load the currently deployed code generation model; The code writing knowledge and the code context are integrated into enhanced context data, and the enhanced context data is converted into model input data in a preset format. The input data of the model is passed to the current code generation model to generate a code snippet; The code snippet is sent to the code output location in the user's IDE plugin.
6. The method according to claim 5, characterized in that, The process of monitoring user interactions with the code snippet to obtain code adoption information and writing the code adoption information into the code adoption dataset includes: The monitoring process is initiated through the callback mechanism of the IDE plugin to listen for user interaction events with the generated code snippets. These interaction events include: edit events, copy events, and ignore events. Capture event data and extract code adoption information, which includes: adoption status, modification details, and timestamp; The code adoption information is converted into structured data, and the structured data is written into the code adoption dataset.
7. The method according to claim 6, characterized in that, The step of generating a user programming habit map based on the code adoption dataset when the preset update cycle arrives includes: A trigger signal is generated when the preset update cycle arrives; Based on the trigger signal, code adoption data is read in batches from the code adoption dataset; Clean the read data and extract features; Clustering algorithms are applied to process the cleaned dataset to construct a graph of user programming habits; Optimize the graph structure and store it in a graph database system.
8. A code generation device based on a dynamic adoption closed-loop system, characterized in that, include: The receiving unit is used to receive code generation requests generated by users through IDE plugins. The acquisition unit is used to retrieve code writing knowledge from the enterprise-specific code knowledge base and acquire the code context of the code output location in response to the code generation request. The output unit is used to output a code snippet based on the code writing knowledge and the code context, using the current code generation model. The monitoring unit is used to monitor the user's interactive operations on the code snippet to obtain code adoption information, and to write the code adoption information into the code adoption dataset; The generation unit is used to generate a user programming habit map based on the code adoption dataset when a preset update cycle arrives. The update unit is used to update the network parameters of the current code generation model according to the user programming habit graph.
9. A computer storage medium, characterized in that, The computer storage medium stores a plurality of instructions, which are adapted to be loaded by a processor and executed as method steps as claimed in any one of claims 1 to 7.
10. A server, characterized in that, include: A processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and executed the method steps as claimed in any one of claims 1 to 7.