Intelligent dynamic prompting method and system for online code writing
By integrating the code snippets entered by the user into structured data and inputting large language models, and generating a business field candidate list with domain knowledge, the problem of not being able to identify business logic-related fields in the existing technology is solved, and intelligent and accurate code prompts are achieved , significantly improves development efficiency and code quality.
Patent Information
- Application Number
- CN202411657008.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-11-19
AI Technical Summary
Existing code prompts the system that cannot effectively identify and recommend fields or methods related to the current business logic, and lacks an understanding of the project-specific context, which makes it difficult to improve development efficiency and code quality.
By receiving code snippets input by users, extracting syntax structure and related information, integrating them into a pre-trained large language model for structured data input, analyzing code semantics and business logic, combining domain knowledge to generate a business field candidate list, and based on user interaction Dynamically adjust the prompt content and order of behavior, and use incremental learning to optimize the model.
It realizes a deep understanding of code semantics, business logic and data flow, provides intelligent and accurate dynamic prompts for online code writing, significantly improving development efficiency and code quality, especially when dealing with complex business logic.
Smart Images

Figure CN119149001A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of code technology, and in particular to a method and system for intelligent dynamic prompting of online code writing. Background Art
[0002] As software development continues to expand in scale and complexity, improving development efficiency and code quality has become a critical issue in software engineering. Online coding has become the preferred method for many developers, and intelligent code prompts, as a key tool for improving coding efficiency, have garnered widespread attention.
[0003] Traditional code hinting systems, primarily based on static analysis and predefined syntax rules, can provide basic syntax completion and API suggestions, but they often fall short when dealing with code in specific business domains. These systems often lack an understanding of the project's specific context and are unable to effectively identify and recommend fields or methods relevant to the current business logic.
[0004] Therefore, developing an online code writing assistance system that can intelligently and dynamically prompt business fields, accurately understand the current code context and business semantics, and adjust the recommendation strategy in real time based on user feedback, while ensuring the diversity and personalization of recommendations, is a technical problem that urgently needs to be solved. Summary of the Invention
[0005] The embodiments of the present invention provide a method and system for intelligent dynamic prompting for online code writing, which can solve the problems in the prior art.
[0006] According to a first aspect of the embodiments of the present invention,
[0007] Provides intelligent dynamic prompts for online code writing, including:
[0008] Receive a code snippet input by a user in an integrated development environment; extract the grammatical structure, variable name, function name, and class name in the code snippet; obtain the programming language type, project configuration information, and code library dependency of the code snippet; collect the user's coding history, project documents, and related annotation information; integrate the code snippet, grammatical structure, variable name, function name, class name, programming language type, project configuration information, code library dependency, coding history, project documents, and annotation information into structured data;
[0009] Input the structured data into a pre-trained large language model; analyze the code semantics, business logic, and data flow in the structured data using the large language model; identify potential business fields and data structures based on the analysis results; generate a candidate list of business fields that conform to the context by combining project-specific domain knowledge and coding specifications; sort and filter the candidate list of business fields by relevance; and generate a detailed description of each business field, including field type, value range, and usage recommendations.
[0010] Display generated business field prompts in real time in the user's integrated development environment; monitor user interaction with prompts, including selection, ignoring, and modification operations; dynamically adjust the display order and content of business fields based on user interaction; record the business fields adopted by users and update the user's encoding preference model; use incremental learning technology to continuously optimize the adaptability of large language models to specific projects and users; regularly analyze changes in project code bases and automatically update the knowledge base of business field prompts.
[0011] In an optional embodiment,
[0012] Inputting the structured data into a pre-trained large language model; analyzing the code semantics, business logic, and data flow in the structured data by using the large language model includes:
[0013] Convert structured data into a format suitable for large language model input. This conversion includes tokenizing code snippets, converting the tokenized code snippets into dense vector representations, performing positional encoding to preserve the sequential information of the code, and integrating contextual information.
[0014] Input the converted data into a pre-trained large language model, which contains a multi-layer Transformer encoder, each layer of which contains a multi-head self-attention mechanism and a feedforward neural network;
[0015] Adding a semantic understanding enhancement layer to the large language model, which uses a graph neural network to model the abstract syntax tree of the code; designing and applying a task-specific attention mechanism that focuses on the parts of the code that contain business logic;
[0016] Implementing a data flow analysis module based on program slicing technology, which is used to track the definition and use of variables in the code;
[0017] Adopting a multi-task learning paradigm, it simultaneously optimizes three goals: code completion, variable type inference, and function usage classification.
[0018] The output contains code representation of deep semantic information, business logic understanding and data flow analysis results.
[0019] In an optional embodiment,
[0020] Based on the analysis results, potential business fields and data structures are identified. Combined with project-specific domain knowledge and coding standards, a candidate list of business fields that meet the context is generated, including:
[0021] Identifying potential business fields and data structures using a multimodal fusion method, the multimodal fusion method comprising: combining semantic vector representation, abstract syntax tree node representation, and data flow information, fusing information through a multi-head attention mechanism to obtain a fused representation; and identifying business fields and data structures using a multilayer perceptron based on the fused representation;
[0022] A domain knowledge graph is constructed, wherein the domain knowledge graph includes an entity set and a relationship set; a graph attention network is used to learn the representation of each node in the domain knowledge graph; a context-aware attention mechanism is designed to align the identified potential business fields with the entities in the domain knowledge graph; based on the alignment results, a conditional variational autoencoder is used to generate a candidate list of business fields that conform to the context, wherein both the encoder and decoder of the conditional variational autoencoder adopt the Transformer architecture.
[0023] In an optional embodiment,
[0024] Sort and filter the candidate list of business fields by relevance; generate a detailed description of each business field, including field type, value range, and usage suggestions, including:
[0025] Sorting and screening the candidate list of business fields by relevance includes:
[0026] Calculate the similarity between candidate fields and the current code context; based on historical project data, calculate the frequency of use of each candidate field in similar contexts; use the maximum marginal relevance algorithm to balance relevance and diversity; based on the calculation results, use a multi-objective ranking model to sort;
[0027] A text generator is constructed to generate detailed descriptions for each sorted business field. The text generator is fine-tuned to adapt to document generation tasks in a specific field; control codes are introduced during the generation process to guide the generation process.
[0028] In an optional embodiment,
[0029] Based on the calculation results, the ranking is performed using a multi-objective ranking model including:
[0030] ;
[0031] Among them, S(f i) represents the candidate field f i The final ranking score, f i represents the i-th candidate field, λ represents the balance parameter, c represents the current code context, sim(f i ,c) represents the similarity between the candidate field and the current code context, freq() represents the usage frequency function, μ represents the weight of the diversity penalty term, Represents the candidate field f i and all candidate fields f that come before it j The maximum similarity, f j Indicates that it is ranked in f i The preceding candidate field.
[0032] In an optional embodiment,
[0033] Monitor user interactions with prompts, including selection, ignoring, and modification. Dynamically adjust the display order and content of business fields based on user interactions. Record the business fields adopted by users and update the user's coding preference model, including:
[0034] Construct a multi-dimensional behavior monitoring system, the multi-dimensional behavior monitoring system comprising:
[0035] An event-driven real-time behavior capture module records user selection, ignoring, and modification behaviors; a micro-behavior analysis module monitors user mouse hover time and scrolling behavior; and a Bloom filter module determines whether a service field has been viewed by the user. The number of hash functions and bit array size of the Bloom filter are determined based on the expected number of different service fields and the allowable error rate.
[0036] Based on the output of the multi-dimensional behavior monitoring system, a reinforcement learning method is used to dynamically adjust the display strategy of the business field, including:
[0037] The state space is defined as the combination of the current code context and the user's most recent N interactions. The action space is defined to include adjusting field order, updating field content, adding new fields, and removing old fields. A reward function is designed, which is a weighted sum of user selection rate, modification rate, ignore rate, and display field diversity. The optimal display strategy is learned using a dual deep Q-network whose network structure adopts a long short-term memory network enhanced by an attention mechanism.
[0038] Construct an adaptive user preference model based on a factorization machine combined with a recurrent neural network to process time series information, including:
[0039] Input features are defined, including user ID, business field ID, contextual features, and time features. A factorization machine is used to model second-order interactions between features, which includes a global bias, feature weights, and feature latent vectors. A recurrent neural network is used to capture the temporal evolution of user preferences, with the input of the recurrent neural network being the features at the current moment and the output being the user preference prediction. An online learning strategy is used to update the model parameters each time a user adopts a business field. A model-independent meta-learning method is used to pre-train the model to address the cold start problem.
[0040] Based on the output of the adaptive user preference model and combined with the display strategy learned by the reinforcement learning method, a personalized business field recommendation list is generated; the personalized business field recommendation list is displayed to the user, and the user's interactive behavior is fed back to the multi-dimensional behavior monitoring system to form a closed-loop optimization.
[0041] According to a second aspect of the embodiments of the present invention,
[0042] Provides an intelligent dynamic prompt system for online code writing, including:
[0043] The first unit is configured to receive a code snippet input by a user in an integrated development environment; extract a grammatical structure, variable name, function name, and class name from the code snippet; obtain a programming language type, project configuration information, and code library dependency of the code snippet; collect a user's coding history, project documents, and related annotation information; and integrate the code snippet, grammatical structure, variable name, function name, class name, programming language type, project configuration information, code library dependency, coding history, project documents, and annotation information into structured data;
[0044] The second unit is configured to input the structured data into a pre-trained large language model; analyze the code semantics, business logic, and data flow in the structured data using the large language model; identify potential business fields and data structures based on the analysis results; generate a candidate list of business fields that conform to the context by combining project-specific domain knowledge and coding standards; sort and filter the candidate list of business fields by relevance; and generate a detailed description of each business field, including field type, value range, and usage recommendations.
[0045] The third unit is used to display the generated business field prompts in real time in the user's integrated development environment; monitor the user's interactive behavior on the prompts, including selection, ignoring and modification operations; dynamically adjust the display order and content of the business fields based on the user's interactive behavior; record the business fields adopted by the user and update the user's encoding preference model; use incremental learning technology to continuously optimize the adaptability of the large language model to specific projects and users; regularly analyze changes in the project code base and automatically update the knowledge base of business field prompts.
[0046] According to a third aspect of the embodiments of the present invention,
[0047] An electronic device is provided, comprising:
[0048] processor;
[0049] a memory for storing processor-executable instructions;
[0050] The processor is configured to call the instructions stored in the memory to execute the aforementioned method.
[0051] According to a fourth aspect of the embodiments of the present invention,
[0052] A computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method described above is implemented.
[0053] The comprehensive code representation of this application can be used for a variety of downstream tasks, such as code completion, error detection, and refactoring suggestions. In practical applications, corresponding decoders or classifiers can be designed according to specific needs to convert this rich code representation into the required output form. Through the above steps, this method can deeply understand the semantics, business logic, and data flow of the code, provide smarter and more accurate dynamic prompts when writing code online, and significantly improve development efficiency and code quality.
[0054] This method intelligently identifies potential business fields and data structures and, combined with domain knowledge, generates a list of candidate business fields that align with the context. This approach can significantly improve code efficiency and accuracy, especially when dealing with complex business logic. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 A schematic diagram of the process of an intelligent dynamic prompt method for online code writing according to an embodiment of the present invention;
[0056] Figure 2 This is a structural diagram of the intelligent dynamic prompt system for online code writing according to an embodiment of the present invention. DETAILED DESCRIPTION
[0057] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0058] The following specific embodiments are used to describe the technical solution of the present invention in detail. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0059] Figure 1 This is a flow chart of the method for online code writing intelligent dynamic prompting according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0060] S101. Receive a code snippet input by a user in an integrated development environment; extract the syntax structure, variable names, function names, and class names from the code snippet; obtain the programming language type, project configuration information, and code library dependencies of the code snippet; collect the user's coding history, project documents, and related annotation information; integrate the code snippet, syntax structure, variable names, function names, class names, programming language type, project configuration information, code library dependencies, coding history, project documents, and annotation information into structured data;
[0061] S102. Input the structured data into a pre-trained large language model; analyze the code semantics, business logic, and data flow in the structured data using the large language model; identify potential business fields and data structures based on the analysis results; combine project-specific domain knowledge and coding standards to generate a candidate list of business fields that match the context; sort and filter the candidate list of business fields by relevance; and generate a detailed description of each business field, including field type, value range, and usage recommendations.
[0062] S103. Display generated business field prompts in real time in the user's integrated development environment; monitor user interaction with prompts, including selection, ignoring, and modification operations; dynamically adjust the display order and content of business fields based on user interaction; record the business fields adopted by users and update the user's coding preference model; use incremental learning technology to continuously optimize the adaptability of the large language model to specific projects and users; regularly analyze changes in the project code base and automatically update the knowledge base of business field prompts.
[0063] In an optional embodiment,
[0064] Inputting the structured data into a pre-trained large language model; analyzing the code semantics, business logic, and data flow in the structured data by using the large language model includes:
[0065] Convert structured data into a format suitable for large language model input. This conversion includes tokenizing code snippets, converting the tokenized code snippets into dense vector representations, performing positional encoding to preserve the sequential information of the code, and integrating contextual information.
[0066] Input the converted data into a pre-trained large language model, which contains a multi-layer Transformer encoder, each layer of which contains a multi-head self-attention mechanism and a feedforward neural network;
[0067] Adding a semantic understanding enhancement layer to the large language model, which uses a graph neural network to model the abstract syntax tree of the code; designing and applying a task-specific attention mechanism that focuses on the parts of the code that contain business logic;
[0068] Implementing a data flow analysis module based on program slicing technology, which is used to track the definition and use of variables in the code;
[0069] Adopting a multi-task learning paradigm, it simultaneously optimizes three goals: code completion, variable type inference, and function usage classification.
[0070] The output contains code representation of deep semantic information, business logic understanding and data flow analysis results.
[0071] For example, this paper proposes an intelligent code analysis method based on a large language model. This method can deeply understand the code semantics, business logic, and data flow, and provide intelligent dynamic prompts for business fields when writing code online. The following describes the specific implementation steps of this method in detail:
[0072] First, the structured data is fed into a pre-trained large language model. This step includes two stages: data preprocessing and model input.
[0073] During the data preprocessing phase, structured data needs to be converted into a format suitable for large language model input. Specifically, code snippets are tokenized to break the code into its smallest semantic units. For example, the Python code "def calculate_total(price, quantity):" might be tokenized to produce ["def", "calculate_total", "(", "price", ",", "quantity", ")", ":"]. These tokens are then converted into dense vector representations using a pretrained word embedding model. To preserve the sequential information of the code, positional encoding is also required. Sine and cosine functions can be used to generate a position vector, which is then added to the token vector. Finally, contextual information is incorporated, for example, by concatenating the vector representations of several preceding and following lines of code to form a larger context window.
[0074] During the model input phase, preprocessed data is fed into a pre-trained large language model. This model uses a multi-layer Transformer encoder architecture, with each layer comprising a multi-head self-attention mechanism and a feedforward neural network. The multi-head self-attention mechanism allows the model to simultaneously focus on different aspects of the code, while the feedforward neural network further processes the output of the attention mechanism, enhancing the model's expressive power.
[0075] Next, a semantic understanding enhancement layer is added to the large language model. This layer uses a graph neural network to model the code's abstract syntax tree (AST). First, the code is parsed into an AST, which is then processed using a graph convolutional network or a graph attention network. This captures the code's structural information and improves the model's understanding of the code's semantics. For example, for a simple assignment statement "x = a + b," the AST may contain assignment nodes, variable nodes, and operator nodes. Graph neural networks can effectively process this tree-like structure.
[0076] To better understand business logic, we design and apply task-specific attention mechanisms. This attention mechanism focuses on parts of the code that contain business logic, such as function names, variable names, and comments. These key parts can be identified using predefined rules or an additional business dictionary, and given higher weight in the attention calculation.
[0077] Next, we implement a data flow analysis module based on program slicing technology. This module is used to track the definition and use of variables in the code. First, a program dependency graph is constructed. Then, for each variable of interest, the graph is traversed forward and backward to determine its influence and affected scopes. This helps us understand the flow and transformation of data in the program. For example, for the code snippet "x = 5; y = x + 1; print(y)", data flow analysis can trace how the definition of x affects the value of y and how y is ultimately used.
[0078] This approach employs a multi-task learning paradigm to simultaneously optimize three objectives: code completion, variable type inference, and function usage classification. This allows the model to learn more general and robust code representations. Specifically, a shared encoder and three independent decoder heads are designed, one for each of these three tasks. During training, the total loss is calculated based on the loss functions for each task, and the model parameters are updated through backpropagation.
[0079] The final output is a code representation that contains deep semantic information, business logic understanding, and data flow analysis results. This representation is a high-dimensional vector, where different dimensions encode different aspects of the code. For example, some dimensions may correspond to the grammatical structure of the code, others reflect information related to business logic, and still others contain the results of data flow analysis.
[0080] This comprehensive code representation can be used for a variety of downstream tasks, such as code completion, error detection, and refactoring suggestions. In practical applications, a corresponding decoder or classifier can be designed according to specific needs to convert this rich code representation into the desired output form.
[0081] Through the above steps, this method can deeply understand the semantics, business logic and data flow of the code, provide smarter and more accurate dynamic prompts when writing code online, and significantly improve development efficiency and code quality.
[0082] In an optional embodiment,
[0083] Based on the analysis results, potential business fields and data structures are identified. Combined with project-specific domain knowledge and coding standards, a candidate list of business fields that meet the context is generated, including:
[0084] Identifying potential business fields and data structures using a multimodal fusion method, the multimodal fusion method comprising: combining semantic vector representation, abstract syntax tree node representation, and data flow information, fusing information through a multi-head attention mechanism to obtain a fused representation; and identifying business fields and data structures using a multilayer perceptron based on the fused representation;
[0085] A domain knowledge graph is constructed, wherein the domain knowledge graph includes an entity set and a relationship set; a graph attention network is used to learn the representation of each node in the domain knowledge graph; a context-aware attention mechanism is designed to align the identified potential business fields with the entities in the domain knowledge graph; based on the alignment results, a conditional variational autoencoder is used to generate a candidate list of business fields that conform to the context, wherein both the encoder and decoder of the conditional variational autoencoder adopt the Transformer architecture.
[0086] For example, the present invention proposes a method for identifying and generating business fields based on multimodal fusion and domain knowledge graphs. This method can intelligently identify potential business fields and data structures and generate a list of candidate business fields that match the context. The following describes the specific implementation steps of this method in detail:
[0087] First, a multimodal fusion method is used to identify potential business fields and data structures. This step includes three stages: information extraction, feature fusion, and field identification.
[0088] During the information extraction phase, the code's semantic vector representation, abstract syntax tree node representation, and data flow information are obtained. The semantic vector representation can be obtained using pre-trained code embedding models, such as CodeBERT or GraphCodeBERT. The abstract syntax tree node representation can be obtained by parsing the code to obtain an AST, which is then encoded using a tree-shaped LSTM or graph neural network. Data flow information, including variable definition-use chains and control flow information, can be obtained using static program analysis techniques.
[0089] During the feature fusion stage, a multi-head attention mechanism is used to fuse the three types of information mentioned above. Specifically, the semantic vector, AST node representation, and data flow information can be input into the multi-head attention layer as queries, keys, and values. By setting multiple attention heads, the model can learn the associations between this information from different perspectives. For example, for the code snippet "defcalculate_total_price(price, quantity):", the semantic vector may capture that "calculate_total_price" is a function related to price calculation, the AST node representation may identify "price" and "quantity" as function parameters, and the data flow information may show that these two parameters are used within the function body. The multi-head attention mechanism can integrate this information to obtain a more comprehensive understanding of the code.
[0090] During the field recognition phase, a multi-layer perceptron (MLP) is used to identify business fields and data structures based on the fused representation. MLPs can learn complex nonlinear mappings, converting the fused representation into probability distributions for business fields and data structures. Multiple output nodes can be configured, corresponding to different types of business fields (such as price, quantity, and date) and data structures (such as lists, dictionaries, and classes). By setting thresholds, high-confidence potential business fields and data structures can be screened.
[0091] Next, we build a domain knowledge graph to guide the generation of business fields. A domain knowledge graph consists of a set of entities and a set of relationships. Entities can be business concepts, data types, or common variable names, while relationships represent semantic associations or usage patterns between entities. For example, in the e-commerce domain, entities might include "product," "price," and "order," while relationships might include "product-includes-price" and "order-association-product."
[0092] Use a graph attention network to learn representations for each node in the domain knowledge graph. The graph attention network can consider information about a node's neighbors, thereby learning richer entity representations. For example, the representation of a "price" node not only includes its own information but is also influenced by related nodes such as "product" and "discount."
[0093] Design a context-aware attention mechanism to align identified potential business fields with entities in the domain knowledge graph. This step aims to establish a connection between the business fields in the code and the domain knowledge. Specifically, the representation of the potential business field can be used as the query, and the representation of the entity in the domain knowledge graph can be used as the key and value. An attention calculation is used to obtain an alignment score. For example, if the variable "item_price" appears in the code, the attention mechanism may find that it is highly correlated with the "price" entity in the knowledge graph.
[0094] Based on the alignment results, a conditional variational autoencoder (CVA) is used to generate a list of candidate business fields that match the context. Both the encoder and decoder of the CVA employ the Transformer architecture, enabling the model to handle variable-length inputs and capture long-range dependencies. The encoder encodes the current code context and the aligned knowledge graph into latent variables, and the decoder generates candidate business fields based on this information.
[0095] During training, code-field pairs from real projects can be used as training data. The model is optimized by maximizing the reconstruction probability and minimizing the KL divergence. During inference, latent variables are sampled and fed into the decoder to generate a diverse list of business field candidates.
[0096] For example, suppose the current code context involves order processing and the fields "order_id" and "customer_name" are already used. These candidate fields not only match the current code context but also reflect order-related concepts and relationships in the domain knowledge graph.
[0097] Through the above steps, this method can intelligently identify potential business fields and data structures, and combine domain knowledge to generate a list of candidate business fields that match the context. This approach can significantly improve code writing efficiency and accuracy, especially when dealing with complex business logic.
[0098] In an optional embodiment,
[0099] Sort and filter the candidate list of business fields by relevance; generate a detailed description of each business field, including field type, value range, and usage suggestions, including:
[0100] Sorting and screening the candidate list of business fields by relevance includes:
[0101] Calculate the similarity between candidate fields and the current code context; based on historical project data, calculate the frequency of use of each candidate field in similar contexts; use the maximum marginal relevance algorithm to balance relevance and diversity; based on the calculation results, use a multi-objective ranking model to sort;
[0102] A text generator is constructed to generate detailed descriptions for each sorted business field. The text generator is fine-tuned to adapt to document generation tasks in a specific field; control codes are introduced during the generation process to guide the generation process.
[0103] In an optional embodiment,
[0104] Based on the calculation results, the ranking is performed using a multi-objective ranking model including:
[0105] ;
[0106] Among them, S(f i ) represents the candidate field f i The final ranking score, f i represents the i-th candidate field, λ represents the balance parameter, c represents the current code context, sim(f i ,c) represents the similarity between the candidate field and the current code context, freq() represents the usage frequency function, μ represents the weight of the diversity penalty term, Represents the candidate field f i and all candidate fields f that come before it j The maximum similarity, f j Indicates that it is ranked in f i The preceding candidate field.
[0107] For example, the present invention proposes an intelligent business field sorting and description generation method, which can sort and filter the candidate list of business fields by relevance and generate detailed descriptions for each business field. The following describes the specific implementation steps of this method in detail:
[0108] First, the candidate list of business fields is sorted and screened for relevance. This step includes four stages: similarity calculation, usage frequency statistics, diversity balance, and multi-objective sorting.
[0109] During the similarity calculation phase, the similarity between the candidate field and the current code context is calculated. In practice, a pre-trained code embedding model (such as CodeBERT) can be used to encode the candidate field and the current code context separately, generating vector representations. The cosine similarity between these vectors is then calculated to measure the relevance of the candidate field and the code context. For example, if the current code context involves order processing, the candidate field "order_total_price" might receive a higher similarity score, while "user_login_time" might receive a lower score.
[0110] During the usage frequency statistics phase, the frequency of use of each candidate field in similar contexts is calculated based on historical project data. This requires establishing an index system to record the number of times each field appears in different contexts within the project. An inverted index structure can be used to improve query efficiency. For each candidate field, historical contexts similar to the current context are searched, the frequency of occurrence of the field in these contexts is counted, and the result is normalized to the usage frequency. Continuing with the above example, if "order_total_price" appears frequently in code related to order processing, it will receive a higher usage frequency score.
[0111] During the diversity balancing phase, the maximum marginal relevance algorithm is used to balance relevance and diversity. The core idea of this algorithm is to consider not only the relevance of the next field to the context but also its difference from the already selected fields when selecting the next field. In practice, a set of selected fields can be maintained, and each time a field is selected from the candidate fields to maximize its relevance to the context while minimizing its maximum similarity to the already selected fields. This avoids recommending overly similar fields and improves the coverage of the recommendation list. For example, after selecting "order_total_price," the algorithm may prefer "shipping_address" over "item_price" because the former provides users with more diverse information.
[0112] During the multi-objective ranking phase, a multi-objective ranking model is used to perform the final ranking based on the calculated results. This model can simultaneously consider multiple factors, such as similarity, frequency of use, and diversity. Algorithms such as LambdaMART can be used to implement multi-objective ranking. The model's input features include the previously calculated similarity scores, frequency of use, and diversity metrics. The output is the final ranking score for each candidate field. The candidate fields are ranked based on these scores, and the top N fields are selected as the final recommendation results.
[0113] Next, we build a text generator to generate detailed descriptions for each sorted business field. This step includes two stages: model fine-tuning and text generation.
[0114] During the model fine-tuning phase, a pre-trained large-scale language model (such as GPT-3 or BERT) is selected as the base model and fine-tuned using domain-specific document data to adapt it to the domain-specific document generation task. The fine-tuning dataset should contain a large number of field description samples, each including information such as the field name, field type, value range, and usage suggestions. A supervised fine-tuning approach can be used to teach the model to generate complete descriptions from field names. For example, data dictionaries or API documentation from software projects can be collected as training data.
[0115] During the text generation phase, the fine-tuned model is used to generate detailed descriptions for each ranked business field. Control codes are introduced during the generation process to guide the generated content and structure. Control codes are special tags or prefixes that instruct the model to generate specific types of content. For example, "[TYPE]" can be used to indicate that the field type should be generated next, "[RANGE]" to indicate a value range, and "[USAGE]" to indicate usage recommendations. This approach ensures that the generated descriptions contain all necessary information and are consistently structured.
[0116] The specific generation process is as follows:
[0117] Combine field names and control codes into an input sequence, such as "order_total_price [TYPE] [RANGE] [USAGE]";
[0118] The input sequence is fed into the fine-tuned language model; the model generates the corresponding text content; the generated text is parsed to extract information such as field type, value range, and usage suggestions; and the parsed information is organized into structured field descriptions.
[0119] For example, the generated detailed description for the "order_total_price" field might be as follows: Field Name: order_total_price; Field Type: Decimal; Value Range: Non-negative, accurate to two decimal places; Usage Recommendation: Used to store the total amount of an order, which should include the sum of all charges, including product price, tax, and shipping. Be careful with currency units and precision when calculating and displaying.
[0120] Through the above steps, this method can intelligently sort and filter the candidate list of business fields and generate detailed descriptions for each field. This approach not only improves the accuracy and diversity of field recommendations, but also significantly enhances developer efficiency and code quality through the automatically generated detailed descriptions. In practical applications, this system can be integrated into integrated development environments (IDEs) to provide developers with real-time field recommendations and descriptions.
[0121] In an optional embodiment,
[0122] Monitor user interactions with prompts, including selection, ignoring, and modification. Dynamically adjust the display order and content of business fields based on user interactions. Record the business fields adopted by users and update the user's coding preference model, including:
[0123] Construct a multi-dimensional behavior monitoring system, the multi-dimensional behavior monitoring system comprising:
[0124] An event-driven real-time behavior capture module records user selection, ignoring, and modification behaviors; a micro-behavior analysis module monitors user mouse hover time and scrolling behavior; and a Bloom filter module determines whether a service field has been viewed by the user. The number of hash functions and bit array size of the Bloom filter are determined based on the expected number of different service fields and the allowable error rate.
[0125] Based on the output of the multi-dimensional behavior monitoring system, a reinforcement learning method is used to dynamically adjust the display strategy of the business field, including:
[0126] The state space is defined as the combination of the current code context and the user's most recent N interactions. The action space is defined to include adjusting field order, updating field content, adding new fields, and removing old fields. A reward function is designed, which is a weighted sum of user selection rate, modification rate, ignore rate, and display field diversity. The optimal display strategy is learned using a dual deep Q-network whose network structure adopts a long short-term memory network enhanced by an attention mechanism.
[0127] Construct an adaptive user preference model based on a factorization machine combined with a recurrent neural network to process time series information, including:
[0128] Input features are defined, including user ID, business field ID, contextual features, and time features. A factorization machine is used to model second-order interactions between features, which includes a global bias, feature weights, and feature latent vectors. A recurrent neural network is used to capture the temporal evolution of user preferences, with the input of the recurrent neural network being the features at the current moment and the output being the user preference prediction. An online learning strategy is used to update the model parameters each time a user adopts a business field. A model-independent meta-learning method is used to pre-train the model to address the cold start problem.
[0129] Based on the output of the adaptive user preference model and combined with the display strategy learned by the reinforcement learning method, a personalized business field recommendation list is generated; the personalized business field recommendation list is displayed to the user, and the user's interactive behavior is fed back to the multi-dimensional behavior monitoring system to form a closed-loop optimization.
[0130] For example, the present invention proposes an intelligent business field recommendation system that can monitor user interaction behavior, dynamically adjust recommendation strategies, and generate personalized business field recommendation lists based on user preferences. The following describes the specific implementation steps of the system in detail:
[0131] First, we built a multi-dimensional behavior monitoring system to comprehensively capture and analyze user interaction behaviors. The system consists of three core modules: an event-driven real-time behavior capture module, a micro-behavior analysis module, and a Bloom filter module.
[0132] The event-driven, real-time behavior capture module is responsible for recording user selection, ignoring, and modification behaviors. This module is implemented by registering event listeners in the integrated development environment (IDE). For example, when a user selects a business field from the recommendation list, a "selection" event is triggered; when a user closes the recommendation window without selecting any fields, an "ignore" event is triggered; and when a user modifies an inserted business field, a "modification" event is triggered. Each event records relevant contextual information, such as the timestamp, current code location, and the name of the field being manipulated.
[0133] The micro-behavior analysis module monitors user mouse hover time and scrolling behavior. This module can capture a user's interest in a specific business field. For example, if a user spends a long time on the "order_total_price" field, it may indicate that the user is interested in this field or requires more information. Monitoring scrolling behavior can help understand whether the user has viewed the entire list of recommendations. This micro-behavior data can serve as implicit feedback on user interest and be used to adjust subsequent recommendation strategies.
[0134] The Bloom filter module is used to efficiently determine whether a business field has been viewed by the user. A Bloom filter is a highly space-efficient probabilistic data structure used to determine whether an element is in a set. In this system, the number of hash functions and the size of the bit array of the Bloom filter are determined based on the expected number of different business fields and the allowable error rate. For example, if there are expected to be 10,000 different business fields and a 0.1% error rate is allowed, 14 hash functions and a 143,775-bit bit array can be used. Whenever a user views a business field, the field is mapped to the bit array using a hash function, and the corresponding position is set to 1. This allows for quick determination of whether a user has already viewed a field, helping to avoid duplicate recommendations.
[0135] Next, based on the output of the multi-dimensional behavior monitoring system, reinforcement learning methods are used to dynamically adjust the display strategy of the business field. This process includes defining the state space, defining the action space, designing the reward function, and training the deep Q network.
[0136] The state space is defined as the combination of the current code context and the user's last N interactions. The code context can include information such as the current file name, function name, and surrounding variable names. This information can be retrieved and encoded into a vector through the IDE's API. The last N user interactions can include the names of selected, ignored, and modified fields, along with their corresponding timestamps. For example, the state might be: "file: order_processing.py, function: calculate_total, context:[item_price, quantity], last_actions: [select:order_id, ignore:customer_name,modify:shipping_address]".
[0137] The action space includes adjusting field order, updating field content, adding new fields, and removing old fields. Specifically, "adjusting field order" can move a field to the top or bottom of the list; "updating field content" can modify a field's description or example; "adding new fields" introduces relevant fields that weren't previously recommended based on the current context; and "removing old fields" removes fields that users have repeatedly ignored.
[0138] The reward function is designed as a weighted sum of user selection rate, modification rate, ignore rate, and display field diversity. A higher selection rate results in a higher reward; a high modification rate or ignore rate results in a lower reward; and a higher diversity of display fields results in a higher reward. This reward function aims to increase user adoption while maintaining recommendation diversity and relevance.
[0139] The Dual Deep Q-Network (DDQN) is used to learn the optimal presentation policy. The DDQN network architecture uses a Long Short-Term Memory (LSTM) network augmented with an attention mechanism. The attention mechanism allows the model to focus on different historical behaviors at different time steps, while the LSTM is effective at processing sequential data. The network input is the encoded state, and the output is the Q-value for each possible action. During training, an ε-greedy strategy is used for exploration, with the ε value gradually reduced to reduce random exploration.
[0140] Next, we built an adaptive user preference model based on a factorization machine combined with a recurrent neural network to process time series information. The goal of this model is to capture user preferences for different business fields and dynamically adjust them over time.
[0141] Input features include user ID, business field ID, contextual features, and time features. The user ID can be a developer's unique ID; the business field ID is a unique identifier for a field; the contextual features include information about the current code; and the time features can be time of day, day of the week, etc.
[0142] Use a factorization machine to model second-order interactions between features. A factorization machine consists of a global bias, feature weights, and feature latent vectors. The global bias represents the overall baseline preference; the feature weights capture the first-order influence of each feature; and the feature latent vectors are used to model interactions between features. For example, a user might prefer to use the "order_total_price" field when processing order-related code.
[0143] Use a recurrent neural network (RNN) to capture the temporal evolution of user preferences. The RNN input is the features of the current moment, and the output is the predicted user preferences. This allows the model to learn how user preferences change over time. For example, users may focus more on basic fields in the early stages of a project, but more on complex business logic-related fields later in the project.
[0144] Using an online learning strategy, model parameters are updated each time a user adopts a business field. This allows the model to quickly adapt to changes in user preferences. In practice, stochastic gradient descent can be used to minimize the loss between predicted preferences and actual behavior.
[0145] Use model-agnostic meta-learning methods to pre-train models to address the cold start problem. Model-agnostic meta-learning (MAML) can be used to pre-train models on historical data from multiple users, enabling them to quickly adapt to new users or new projects.
[0146] Finally, based on the output of the adaptive user preference model and the display strategy learned by the reinforcement learning method, a personalized business field recommendation list is generated. The specific steps are as follows:
[0147] Using the current code context as input, a reinforcement learning model generates an initial field display strategy. These fields are then fed into an adaptive user preference model to obtain a personalized preference score for each field. Fields are reordered based on the preference scores to generate a final recommendation list. This personalized list of business field recommendations is then presented to the user. User interactions with the recommendation list are monitored and fed back to the multi-dimensional behavior monitoring system. The multi-dimensional behavior monitoring system processes this new interaction data and updates the user behavior model. Based on the updated behavior model, the reinforcement learning algorithm and user preference model parameters are updated.
[0148] Through this closed-loop optimization process, the system continuously learns and adapts to user preferences and behavior patterns, providing increasingly accurate business field recommendations. For example, if the system observes that users frequently select the "transaction_id" and "payment_method" fields when processing payment-related codes, these fields will be prioritized in similar contexts in the future. Furthermore, if users frequently modify the names of certain fields, the system will learn this pattern and directly provide the user's preferred naming method in future recommendations.
[0149] Figure 2 This is a structural diagram of the intelligent dynamic prompt system for online code writing according to an embodiment of the present invention. Figure 2 As shown, the system includes:
[0150] The first unit is configured to receive a code snippet input by a user in an integrated development environment; extract a grammatical structure, variable name, function name, and class name from the code snippet; obtain a programming language type, project configuration information, and code library dependency of the code snippet; collect a user's coding history, project documents, and related annotation information; and integrate the code snippet, grammatical structure, variable name, function name, class name, programming language type, project configuration information, code library dependency, coding history, project documents, and annotation information into structured data;
[0151] The second unit is configured to input the structured data into a pre-trained large language model; analyze the code semantics, business logic, and data flow in the structured data using the large language model; identify potential business fields and data structures based on the analysis results; generate a candidate list of business fields that conform to the context by combining project-specific domain knowledge and coding standards; sort and filter the candidate list of business fields by relevance; and generate a detailed description of each business field, including field type, value range, and usage recommendations.
[0152] The third unit is used to display the generated business field prompts in real time in the user's integrated development environment; monitor the user's interactive behavior on the prompts, including selection, ignoring and modification operations; dynamically adjust the display order and content of the business fields based on the user's interactive behavior; record the business fields adopted by the user and update the user's encoding preference model; use incremental learning technology to continuously optimize the adaptability of the large language model to specific projects and users; regularly analyze changes in the project code base and automatically update the knowledge base of business field prompts.
[0153] According to a third aspect of the embodiments of the present invention,
[0154] An electronic device is provided, comprising:
[0155] processor;
[0156] a memory for storing processor-executable instructions;
[0157] The processor is configured to call the instructions stored in the memory to execute the aforementioned method.
[0158] According to a fourth aspect of the embodiments of the present invention,
[0159] A computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method described above is implemented.
[0160] The present invention may be a method, an apparatus, a system and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for executing various aspects of the present invention.
[0161] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An intelligent dynamic prompt method for online code writing, characterized in that: include: Receive code snippets input by users in an integrated development environment; Extracting the syntax structure, variable name, function name and class name in the code snippet; obtaining the programming language type, project configuration information and code base dependency of the code snippet; collecting the user's coding history, project documents and related annotation information; integrating the code snippet, syntax structure, variable name, function name, class name, programming language type, project configuration information, code base dependency, coding history, project documents and annotation information into structured data; Inputting the structured data into a pre-trained large language model; analyzing the code semantics, business logic and data flow in the structured data through the large language model; Based on the analysis results, identify potential business fields and data structures; combine project-specific domain knowledge and coding specifications to generate a candidate list of business fields that fit the context; Sorting and screening the candidate list of business fields for relevance; generating a detailed description of each business field, including field type, value range and usage suggestions; Display generated business field prompts in real time in the user's integrated development environment; Monitor user interactions with prompts, including selection, ignoring, and modification operations; dynamically adjust the display order and content of business fields based on user interactions; Record the business fields adopted by users and update the user's encoding preference model; use incremental learning technology to continuously optimize the adaptability of large language models to specific projects and users; regularly analyze changes in project code bases and automatically update the knowledge base of business field prompts.
2. The method according to claim 1, characterized in that Inputting the structured data into a pre-trained large language model; analyzing the code semantics, business logic, and data flow in the structured data by using the large language model includes: Convert structured data into a format suitable for large language model input. The conversion includes tokenizing code snippets, converting the tokenized code snippets into dense vector representations, performing position encoding to preserve the order information of the code, and integrating context information. Input the converted data into a pre-trained large language model, wherein the large language model comprises a multi-layer Transformer encoder, each layer of which comprises a multi-head self-attention mechanism and a feed-forward neural network; Add a semantic understanding enhancement layer based on the large language model, which uses a graph neural network to model the abstract syntax tree of the code; design and apply a task-specific attention mechanism, which focuses on the part of the code that contains business logic; Implement a data flow analysis module based on program slicing technology, which is used to track the definition and use of variables in the code; Adopting a multi-task learning paradigm, we simultaneously optimize three goals: code completion, variable type inference, and function usage classification. The output contains code representation of deep semantic information, business logic understanding, and data flow analysis results.
3. The method according to claim 1, characterized in that Based on the analysis results, potential business fields and data structures are identified; combined with project-specific domain knowledge and coding specifications, a candidate list of business fields that meet the context is generated, including: Using a multimodal fusion method to identify potential business fields and data structures, the multimodal fusion method includes: combining semantic vector representation, abstract syntax tree node representation and data flow information, fusing information through a multi-head attention mechanism to obtain a fused representation; based on the fused representation, using a multi-layer perceptron to identify business fields and data structures; A domain knowledge graph is constructed, wherein the domain knowledge graph includes an entity set and a relationship set; a graph attention network is used to learn the representation of each node in the domain knowledge graph; a context-aware attention mechanism is designed to align the identified potential business fields with the entities in the domain knowledge graph; based on the alignment results, a conditional variational autoencoder is used to generate a candidate list of business fields that conform to the context, wherein the encoder and decoder of the conditional variational autoencoder both adopt the Transformer architecture.
4. The method according to claim 1, characterized in that: Sorting and screening the candidate list of business fields according to their relevance; Generate detailed descriptions of each business field, including field type, value range, and usage suggestions including: Sorting and screening the candidate list of business fields by relevance includes: Calculate the similarity between the candidate field and the current code context; calculate the usage frequency of each candidate field in similar contexts based on project historical data; use the maximum marginal relevance algorithm to balance relevance and diversity; and use a multi-objective ranking model to sort based on the calculation results; A text generator is constructed to generate detailed descriptions for each sorted business field, wherein the text generator is fine-tuned to adapt to document generation tasks in a specific field; control codes are introduced during the generation process to guide the generation process.
5. The method according to claim 4, characterized in that Based on the calculation results, the ranking is performed using a multi-objective ranking model including: ; Among them, S(f i ) represents the candidate field f i The final ranking score, f i represents the i-th candidate field, λ represents the balancing parameter, c represents the current code context, sim(f i ,c) represents the similarity between the candidate field and the current code context, freq() represents the usage frequency function, and μ represents the weight of the diversity penalty term. Represents the candidate field f i and all candidate fields f that precede it j The maximum similarity, f j Indicates that it is ranked in f i The preceding candidate field.
6. The method according to claim 1, characterized in that Monitor user interactions with prompts, including selection, ignoring, and modification operations; dynamically adjust the display order and content of business fields based on user interactions; Record the business fields adopted by the user and update the user's coding preference model including: Construct a multi-dimensional behavior monitoring system, the multi-dimensional behavior monitoring system comprising: An event-driven real-time behavior capture module for recording user selection, ignoring and modification behaviors; a micro-behavior analysis module for monitoring the user's mouse hover time and scrolling behavior; a Bloom filter module for determining whether a business field has been viewed by the user, wherein the number of hash functions and the size of the bit array of the Bloom filter are determined according to the expected number of different business fields and the allowed error rate; Based on the output of the multi-dimensional behavior monitoring system, a reinforcement learning method is used to dynamically adjust the display strategy of the business field, including: The state space is defined as the combination of the current code context and the user's most recent N interactive behaviors; the action space is defined to include adjusting the field order, updating the field content, adding new fields, and removing old fields; a reward function is designed, which is a weighted sum of the user selection rate, modification rate, ignore rate, and display field diversity; the optimal display strategy is learned using a dual-depth Q network, the network structure of which adopts a long short-term memory network enhanced by an attention mechanism; Constructing an adaptive user preference model, wherein the adaptive user preference model is based on a factorization machine and combines a recurrent neural network to process time series information, including: The input features are defined to include user ID, business field ID, contextual features and time features; a factorization machine is used to model the second-order interaction between features, and the factorization machine includes a global bias, feature weights and feature latent vectors; a recurrent neural network is used to capture the time evolution of user preferences, and the input of the recurrent neural network is the features at the current moment, and the output is the user preference prediction; an online learning strategy is adopted to update the model parameters each time the user adopts a business field; a model-independent meta-learning method is used to pre-train the model to solve the cold start problem; Based on the output of the adaptive user preference model and combined with the display strategy learned by the reinforcement learning method, a personalized business field recommendation list is generated; the personalized business field recommendation list is displayed to the user, and the user's interactive behavior is fed back to the multi-dimensional behavior monitoring system to form a closed-loop optimization.
7. An online code writing intelligent dynamic prompt system, used to implement the method described in any one of claims 1 to 6, characterized in that: include: The first unit is used to receive a code snippet input by a user in an integrated development environment; Extracting the syntax structure, variable name, function name and class name in the code snippet; obtaining the programming language type, project configuration information and code base dependency of the code snippet; collecting the user's coding history, project documents and related annotation information; integrating the code snippet, syntax structure, variable name, function name, class name, programming language type, project configuration information, code base dependency, coding history, project documents and annotation information into structured data; The second unit is used to input the structured data into a pre-trained large language model; and analyze the code semantics, business logic and data flow in the structured data through the large language model; Based on the analysis results, identify potential business fields and data structures; combine project-specific domain knowledge and coding specifications to generate a candidate list of business fields that fit the context; Sorting and screening the candidate list of business fields for relevance; generating a detailed description of each business field, including field type, value range and usage suggestions; The third unit is used to display the generated business field prompts in real time in the user's integrated development environment; Monitor user interactions with prompts, including selection, ignoring, and modification operations; dynamically adjust the display order and content of business fields based on user interactions; Record the business fields adopted by users and update the user's encoding preference model; use incremental learning technology to continuously optimize the adaptability of large language models to specific projects and users; regularly analyze changes in project code bases and automatically update the knowledge base of business field prompts.
8. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Intelligent software agile development method and system based on large language model
CN118276829A
Intelligent cabinet interaction method and device based on large language model and electronic equipment
CN118468880A
Visual interface construction method and device, equipment and storage medium
CN118689475A
Dynamic code generation method and system based on interface document
CN118860356A
Code Generation Platform
US20210263834A1
Cited By
Large model driven local code warehouse-based programming method and device
CN119396407A
Method and system for integrating code structure into large model based on multiple modes
CN119576389A
A method and system for integrating multimodal code structure into large models
CN119576389B
Code management system and method based on software demand design
CN120162034A
Code Management System and Method Based on Software Requirement Design
CN120162034B
