Online code writing intelligent dynamic prompt method and system

By receiving and analyzing code snippets entered by users in the integrated development environment, using a large language model to identify business fields and combining domain knowledge to generate candidate lists, the problem of difficult to understand project-specific context and business semantics in the prior art is solved, intelligent dynamic prompts are realized, and code writing efficiency and accuracy are improved.

CN119149001BActive Publication Date: 2025-03-14冠骋信息技术(苏州)有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411657008.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-03-14
Estimated Expiration
2044-11-19

AI Technical Summary

Technical Problem

Existing code prompts the system to find it difficult to accurately understand project-specific contexts and business semantics, and to effectively identify and recommend fields or methods related to the current business logic.

Method used

By receiving code snippets entered by users in the integrated development environment, extract information such as syntax structure, variable names, and integrate them into structured data. Use pre-trained large language models to analyze code semantics, business logic and data flow, identify potential business fields and data structures, combine domain knowledge to generate a business field candidate list that conforms to the context, and dynamically adjust prompts based on user interaction behavior.

Benefits of technology

It realizes intelligent dynamic prompts for business fields, can accurately understand the code context and business logic, improve code writing efficiency and accuracy, and adapt to the needs of specific projects and users.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149001B_ABST
    Figure CN119149001B_ABST
Patent Text Reader

Abstract

The present invention provides an online code writing intelligent dynamic prompt method and system, which relates to the field of code technology, including inputting 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; identifying potential business fields and data structures based on the analysis results; generating a business field candidate list that conforms to the context in combination with project-specific domain knowledge and coding specifications; sorting and screening the business field candidate list by relevance; generating a detailed description of each business field; displaying the generated business field prompt in real time in the user's integrated development environment; dynamically adjusting the display order and content of the business field based on user interaction behavior; regularly analyzing changes in the project code base and automatically updating the knowledge base of the business field prompt.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of code technology, and in particular to an intelligent dynamic prompt method and system for online code writing. Background Art

[0002] As software development continues to expand in scale and complexity, improving development efficiency and code quality has become an important topic in the current software engineering field. Online coding has become the preferred method for many developers, and the intelligent code prompt function, as a key tool to improve coding efficiency, has received widespread attention.

[0003] Traditional code hint systems are mainly based on static analysis and predefined grammar rules. Although they can provide basic syntax completion and API suggestions, they are often inadequate when dealing with code in specific business areas. These systems usually lack understanding of the specific context of the project and cannot effectively identify and recommend fields or methods related 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 according to user feedback while ensuring the diversity and personalization of recommendations is a technical problem that needs to be solved urgently. Summary of the invention

[0005] The embodiments of the present invention provide an online code writing intelligent dynamic prompt method and system, 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 a grammatical structure, a variable name, a function name, and a class name in the code snippet; obtain a programming language type, project configuration information, and a code base dependency of the code snippet; collect a 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 base 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 through 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 in combination with project-specific domain knowledge and coding specifications; 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;

[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 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. 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.

[0014] 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;

[0015] 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;

[0016] 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;

[0017] Adopting a multi-task learning paradigm, we simultaneously optimize 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 specifications, a candidate list of business fields that meet the context is generated, including:

[0021] 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;

[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 the encoder and decoder of the conditional variational autoencoder both adopt the Transformer architecture.

[0023] In an optional embodiment,

[0024] The candidate list of business fields is sorted and screened for relevance; a detailed description of each business field is generated, including field type, value range and usage suggestions including:

[0025] The candidate list of business fields is sorted and screened by relevance, including:

[0026] 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;

[0027] 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.

[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 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.

[0032] In an optional embodiment,

[0033] Monitor the user's interactive behavior on the prompt, 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 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 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;

[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 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;

[0038] 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:

[0039] 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;

[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 used to receive a code snippet input by a user in an integrated development environment; extract a grammatical structure, a variable name, a function name, and a class name in the code snippet; obtain a programming language type, project configuration information, and a 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 used 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 through 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 in combination with project-specific domain knowledge and coding specifications; 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;

[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] A fourth aspect of the embodiments of the present invention is:

[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 aforementioned method 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 can intelligently identify potential business fields and data structures, and generate a candidate list of business fields that conform to the context by combining domain knowledge. This method can significantly improve the efficiency and accuracy of code writing, especially when dealing with complex business logic. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] Figure 1 A schematic diagram of a process for an online code writing intelligent dynamic prompting method according to an embodiment of the present invention;

[0056] Figure 2 The present invention is a schematic diagram of the structure of an intelligent dynamic prompt system for online code writing according to an embodiment of the present invention. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the 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 creative work are within the scope of protection of the present invention.

[0058] The technical solution of the present invention is described in detail with specific embodiments below. 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 The flowchart of the method for online code writing intelligent dynamic prompting according to the embodiment of the present invention is as follows: Figure 1 As shown, the method includes:

[0060] S101. Receive a code snippet input by a user in an integrated development environment; extract a grammatical structure, a variable name, a function name, and a class name in the code snippet; obtain a programming language type, project configuration information, and a code library dependency of the code snippet; collect a 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;

[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 through 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 in combination with project-specific domain knowledge and coding specifications; 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;

[0062] S103. 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.

[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. 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.

[0066] 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;

[0067] 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;

[0068] 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;

[0069] Adopting a multi-task learning paradigm, we simultaneously optimize 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] Exemplarily, the present invention proposes an intelligent code analysis method based on a large language model, which can deeply understand the code semantics, business logic and data flow, and provide intelligent dynamic prompt business fields when writing code online. The specific implementation steps of the method are described in detail below:

[0072] First, the structured data is input into the pre-trained large language model. This step includes two stages: data preprocessing and model input.

[0073] In the data preprocessing stage, structured data needs to be converted into a format suitable for large language model input. Specifically, the code snippets are tokenized to split the code into the smallest semantic units. For example, for the Python code "def calculate_total(price, quantity):", after tokenization, ["def", "calculate_total", "(", "price", ",", "quantity", ")", ":"] may be obtained. Subsequently, these tags are converted into dense vector representations using a pre-trained word embedding model. In order to preserve the sequential information of the code, position encoding is also required. The sine and cosine functions can be used to generate the position vector and add it to the tag vector. Finally, the context information is fused, such as connecting the vector representations of several lines of code before and after to form a larger context window.

[0074] In the model input stage, the preprocessed data is input into the pre-trained large language model. The model adopts a multi-layer Transformer encoder structure, and each layer contains a multi-head self-attention mechanism and a feedforward neural network. The multi-head self-attention mechanism allows the model to focus on different aspects of the code at the same time, while the feedforward neural network further processes the output of the attention mechanism to enhance the expressiveness of the model.

[0075] Next, a semantic understanding enhancement layer is added on top of the large language model. This layer uses a graph neural network to model the abstract syntax tree (AST) of the code. First, the code is parsed into an AST, and then the AST is processed using a graph convolutional network or a graph attention network. This can capture the structural information of the code and improve the model's ability to understand the semantics of the code. For example, for a simple assignment statement "x = a + b", its AST may contain assignment nodes, variable nodes, and operator nodes, and a graph neural network can effectively process this tree structure.

[0076] To better understand the business logic, design and apply task-specific attention mechanisms. This attention mechanism focuses on the parts of the code that contain business logic, such as function names, variable names, and comments. These key parts can be identified through predefined rules or using additional business dictionaries, and given higher weights during attention calculation.

[0077] Then, a data flow analysis module based on program slicing technology is implemented. This module is used to track the definition and use of variables in the code. First, a program dependency graph is built, and then for each variable of interest, its influence range and affected range are determined by traversing the graph forward and backward. This helps to understand the flow and transformation process of data in the program. For example, for the code snippet "x = 5; y = x + 1; print(y)", data flow analysis can track how the definition of x affects the value of y, and how y is finally used.

[0078] A multi-task learning paradigm is adopted to optimize the three goals of code completion, variable type inference, and function usage classification at the same time. This approach allows the model to learn a more general and robust code representation. In specific implementation, a shared encoder and three independent decoder heads can be designed, corresponding to the three tasks respectively. During the training process, the total loss is calculated according to the loss functions of different tasks, and the model parameters are updated through backpropagation.

[0079] Finally, the 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, some dimensions reflect information related to business logic, and 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, corresponding decoders or classifiers 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 specifications, a candidate list of business fields that meet the context is generated, including:

[0084] 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;

[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 the encoder and decoder of the conditional variational autoencoder both adopt the Transformer architecture.

[0086] Exemplarily, the present invention proposes a business field identification and generation method based on multimodal fusion and domain knowledge graph, which can intelligently identify potential business fields and data structures and generate a candidate list of business fields that conform to the context. The specific implementation steps of the method are described in detail below:

[0087] First, the 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] In the information extraction phase, the semantic vector representation, abstract syntax tree node representation, and data flow information of the code are obtained respectively. The semantic vector representation can be obtained through a pre-trained code embedding model, such as CodeBERT or GraphCodeBERT. The abstract syntax tree node representation can be obtained by parsing the code to obtain the AST, and then encoding the AST using a tree-shaped LSTM or graph neural network. Data flow information can be obtained through static program analysis technology, including variable definition-use chains and control flow information.

[0089] In the feature fusion stage, the multi-head attention mechanism is used to fuse the above three types of information. Specifically, the semantic vector, AST node representation, and data flow information can be input into the multi-head attention layer as query, key, and value. By setting multiple attention heads, the model can learn the association between these 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 that "price" and "quantity" are function parameters, and the data flow information may show that these two parameters are used in the function body. The multi-head attention mechanism can synthesize this information to get a more comprehensive understanding of the code.

[0090] In the field recognition stage, based on the fused representation, a multi-layer perceptron is used to identify business fields and data structures. The multi-layer perceptron can learn complex nonlinear mappings and convert the fused representation into the probability distribution of business fields and data structures. Multiple output nodes can be set to correspond to different types of business fields (such as price, quantity, date, etc.) and data structures (such as lists, dictionaries, classes, etc.). By setting a threshold, potential business fields and data structures with high confidence can be screened out.

[0091] Next, we build a domain knowledge graph to guide the generation of business fields. The domain knowledge graph contains entity sets and relationship sets, where entities can be business concepts, data types, or common variable names, and relationships can represent semantic associations or usage patterns between entities. For example, in the e-commerce field, entities may include "product", "price", "order", etc., and relationships may include "product-includes-price", "order-association-product", etc.

[0092] Use graph attention networks to learn the representation of each node in the domain knowledge graph. Graph attention networks can consider the neighbor information of nodes to learn richer entity representations. For example, the representation of a "price" node not only contains its own information, but is also affected by related nodes such as "product" and "discount".

[0093] Design a context-aware attention mechanism to align the 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. In specific implementation, the representation of the potential business field can be used as a query, and the representation of the entity in the domain knowledge graph can be used as the key and value, and the alignment score can be obtained through attention calculation. 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 is used to generate a candidate list of business fields that match the context. Both the encoder and decoder of the conditional variational autoencoder use the Transformer architecture, which enables the model to process variable-length inputs and capture long-distance dependencies. The encoder encodes the current code context and the aligned knowledge graph information into latent variables, and the decoder generates candidate business fields based on this information.

[0095] During the training process, 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. In the inference phase, a diverse list of business field candidates can be generated by sampling latent variables and feeding them into the decoder.

[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 the 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 generate a candidate list of business fields that conform to the context by combining domain knowledge. This method can significantly improve the efficiency and accuracy of code writing, especially when dealing with complex business logic.

[0098] In an optional embodiment,

[0099] The candidate list of business fields is sorted and screened for relevance; a detailed description of each business field is generated, including field type, value range and usage suggestions including:

[0100] The candidate list of business fields is sorted and screened by relevance, including:

[0101] 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;

[0102] 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.

[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 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.

[0107] Exemplarily, the present invention proposes an intelligent business field sorting and description generation method, which can sort and filter the business field candidate list by relevance, and generate a detailed description for each business field. The specific implementation steps of the method are described in detail below:

[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] In the similarity calculation phase, the similarity between the candidate field and the current code context is calculated. In specific implementation, a pre-trained code embedding model (such as CodeBERT) can be used to encode the candidate field and the current code context respectively to obtain vector representations. The relevance of the candidate field and the code context is then measured by calculating the cosine similarity between these vectors. For example, assuming that the current code context involves order processing, the candidate field "order_total_price" may get a higher similarity score, while "user_login_time" may get a lower score.

[0110] In the frequency of use statistics phase, the frequency of use of each candidate field in similar contexts is calculated based on the historical data of the project. This requires the establishment of an index system to record the number of times each field in the project appears in different contexts. An inverted index structure can be used to improve query efficiency. For each candidate field, find historical contexts similar to the current context, count the frequency of occurrence of the field in these contexts, and normalize it to the frequency of use. Continuing with the above example, if "order_total_price" appears frequently in code related to order processing, it will get a higher frequency of use score.

[0111] In the diversity balance stage, the maximum marginal relevance algorithm is used to balance relevance and diversity. The core idea of ​​this algorithm is to consider not only its relevance to the context, but also its difference from the selected fields when selecting the next field. In specific implementation, a set of selected fields can be maintained, and a field can be selected from the candidate fields each time to maximize its relevance to the context and minimize its maximum similarity to the selected fields. This can avoid recommending fields that are too similar and improve the coverage of the recommendation list. For example, after selecting "order_total_price", the algorithm may tend to choose "shipping_address" instead of "item_price" because the former can provide users with more diverse information.

[0112] In the multi-objective sorting stage, the multi-objective sorting model is used for final sorting based on the calculation results. The multi-objective sorting model can consider multiple factors at the same time, such as similarity, frequency of use, and diversity. Algorithms such as LambdaMART can be used to achieve multi-objective sorting. The input features of the model include the similarity scores, frequency of use, and diversity indicators calculated previously, and the output is the final sorting score of each candidate field. The candidate fields are sorted according to 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] In the model fine-tuning stage, a pre-trained large language model (such as GPT-3 or BERT) is selected as the base model and fine-tuned using domain-specific document data to adapt to the document generation task in a specific domain. The fine-tuning dataset should contain a large number of field description samples, each of which includes information such as field name, field type, value range, and usage suggestions. A supervised fine-tuning method can be used to let the model learn the task of generating a complete description from a field name. For example, a data dictionary or API documentation in a software project can be collected as training data.

[0115] In the text generation phase, the fine-tuned model is used to generate detailed descriptions for each sorted business field. Control codes are introduced during the generation process to guide the generated content and structure. Control codes can be special tags or prefixes that instruct the model to generate a specific type of content. For example, you can use "[TYPE]" to indicate that the field type should be generated next, "[RANGE]" to indicate that a value range should be generated, and "[USAGE]" to indicate that usage recommendations should be generated. This approach ensures that the generated descriptions contain all necessary information and have a consistent structure.

[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; the parsed information is organized into structured field descriptions.

[0119] For example, for the "order_total_price" field, the generated detailed description may be as follows: Field name: order_total_price; Field type: Decimal; Value range: non-negative, accurate to two decimal places; Usage suggestion: used to store the total amount of the order, which should include the sum of all fees such as product price, tax, and shipping. Pay attention to the currency unit 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 method not only improves the accuracy and diversity of field recommendations, but also greatly improves the efficiency and code quality of developers through automatically generated detailed descriptions. In practical applications, this system can be integrated into the integrated development environment (IDE) to provide developers with real-time field recommendation and description services.

[0121] In an optional embodiment,

[0122] Monitor the user's interactive behavior on the prompt, 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 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 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;

[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 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;

[0127] 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:

[0128] 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;

[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] Exemplarily, the present invention proposes an intelligent business field recommendation system, which can monitor user interaction behavior, dynamically adjust recommendation strategies, and generate personalized business field recommendation lists based on user preferences. The specific implementation steps of the system are described in detail below:

[0131] First, a multi-dimensional behavior monitoring system is built to comprehensively capture and analyze user interaction behaviors. The system includes three core modules: event-driven real-time behavior capture module, micro-behavior analysis module, and Bloom filter module.

[0132] The event-driven real-time behavior capture module is responsible for recording the user's 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 field, an "ignore" event is triggered; when a user modifies an inserted business field, a "modification" event is triggered. Each event records relevant context information, such as timestamp, current code location, field name of the operation, etc.

[0133] The micro-behavior analysis module is used to monitor the user's mouse hover time and scrolling behavior. This module can capture the user's interest in a certain business field. For example, if the user stays on the "order_total_price" field for a long time, it may mean that the user is more interested in this field or needs more information. Monitoring scrolling behavior can help understand whether the user has viewed the entire recommendation list. These micro-behavior data can be used as implicit feedback of user interests for subsequent recommendation strategy adjustments.

[0134] The Bloom filter module is used to efficiently determine whether a business field has been viewed by the user. The 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 allowed 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 through a hash function and the corresponding position is set to 1. This allows for a 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, the reinforcement learning method is used to dynamically adjust the display strategy of the business field. This process includes state space definition, action space definition, reward function design and deep Q network training.

[0136] The state space is defined as the combination of the current code context and the user's most recent N interactions. The code context can include information such as the current file name, function name, and surrounding variable names, which can be obtained through the IDE's API and encoded into a vector. The user's most recent N interactions can include the names of selected, ignored, and modified fields, as well as the corresponding timestamps. For example, the state may 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 the order of fields, updating field content, adding new fields, and removing old fields. Specifically, "adjusting the order of fields" can be to move a field to the top or bottom of the list; "updating field content" can be to modify the description or example of a field; "adding new fields" is to introduce related fields that have not been recommended before based on the current context; "removing old fields" is to remove fields that users have ignored many times.

[0138] The reward function is designed as a weighted sum of user selection rate, modification rate, ignore rate, and display field diversity. The higher the selection rate, the higher the reward; the higher the modification rate or ignore rate, the lower the reward; the higher the diversity of display fields, the higher the reward. The goal of this reward function is to maintain the diversity and relevance of recommendations while increasing user adoption rate.

[0139] The optimal presentation strategy is learned using a dual deep Q network (DDQN). The network structure of DDQN uses a long short-term memory network (LSTM) enhanced by an attention mechanism. The attention mechanism allows the model to focus on different historical behaviors at different time steps, while LSTM can effectively process sequence data. The input of the network is the encoded state, and the output is the Q value of each possible action. During training, the ε-greedy strategy is used for exploration, and the ε value is gradually reduced to reduce random exploration.

[0140] Then, an adaptive user preference model is constructed, which is 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 over time.

[0141] Input features include user ID, business field ID, contextual features, and time features. User ID can be a developer's unique ID; business field ID is a unique identifier for a field; contextual features include relevant information about the current code; and time features can be time of day, day of the week, etc.

[0142] Use factorization machines to model second-order interactions between features. Factorization machines contain global bias, feature weights, and feature latent vectors. The global bias represents the overall baseline preference; the feature weights capture the first-order effects of each feature; and the feature latent vectors are used to model interactions between features. For example, a user may prefer to use the "order_total_price" field when processing order-related codes.

[0143] Use recurrent neural networks (RNNs) to capture the temporal evolution of user preferences. The input of the RNN is the features of the current moment, and the output is the user preference prediction. This allows the model to learn how user preferences change over time. For example, users may pay more attention to basic fields in the early stages of a project, but more attention to complex business logic-related fields in the later stages.

[0144] An online learning strategy is used to update the model parameters each time a user adopts a business field. This allows the model to quickly adapt to changes in user preferences. In specific implementations, 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 solve the cold start problem. You can use the model-agnostic meta-learning algorithm (MAML) to pre-train the model on historical data of multiple users so that it can quickly adapt to the scenarios of 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, the reinforcement learning model generates an initial field display strategy. Input these fields into the adaptive user preference model to obtain personalized preference scores for each field. Reorder the fields according to the preference scores to generate the final recommendation list. Display the personalized business field recommendation list to the user. Monitor the user's interaction behavior with the recommendation list and feed these behaviors back to the multi-dimensional behavior monitoring system. The multi-dimensional behavior monitoring system processes these new interaction data and updates the user behavior model. Based on the updated behavior model, the reinforcement learning algorithm and the user preference model perform parameter updates respectively.

[0148] Through this closed-loop optimization process, the system can continuously learn and adapt to user preferences and behavior patterns, providing increasingly accurate business field recommendations. For example, if the system observes that users often select the "transaction_id" and "payment_method" fields when processing payment-related codes, then these fields will be recommended first in similar contexts in the future. At the same time, if users frequently modify the naming of certain fields, the system will learn this pattern and directly provide the user's preferred naming method in future recommendations.

[0149] Figure 2 Schematic diagram of the structure of the online code writing intelligent dynamic prompt system according to the embodiment of the present invention. Figure 2 As shown, the system comprises:

[0150] The first unit is used to receive a code snippet input by a user in an integrated development environment; extract a grammatical structure, a variable name, a function name, and a class name in the code snippet; obtain a programming language type, project configuration information, and a 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 used 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 through 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 in combination with project-specific domain knowledge and coding specifications; 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;

[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] A fourth aspect of the embodiments of the present invention is:

[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 aforementioned method 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 aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned 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 prompting 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