A generative AI-based programming assistance method, device, and medium
By using generative AI technology, requirement text, interface text, and historical code are extracted and integrated to generate a set of state fragments and train a code generation model. This solves the problem of interface specification and architecture consistency in existing technologies and achieves a more efficient programming assistance effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHANGCHUN VOCATIONAL INST OF TECH
- Filing Date
- 2026-04-16
- Publication Date
- 2026-07-10
AI Technical Summary
Existing generative AI programming assistance technologies struggle to balance interface specifications, resource management, and architectural consistency, resulting in generated code that fails to meet fine-grained interface constraints and resource management standards. Furthermore, incremental code completion results are prone to deviating from the original architectural design.
By receiving requirement text, interface text, and historical code, the system extracts sets of functional items, interface items, and pattern items, generates a set of state fragments, generates candidate patches by training a code generation model, performs consistency verification, and finally generates updated code to ensure consistency between interface specifications and architecture.
It improves the targeting and location of programming assistance, and enhances the stability and usability of programming assistance results.
Smart Images

Figure CN122363733A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent programming technology, and in particular to a programming assistance method, device and medium based on generative AI. Background Technology
[0002] With the increasing complexity of software systems and the widespread application of agile development models, automated programming assistance technology has become a key research direction for improving software development efficiency. In the field of code generation based on generative artificial intelligence, mainstream solutions typically revolve around large-scale pre-trained language models, generating preliminary code structures through direct mapping of natural language requirement descriptions or by combining some interface definitions. These methods focus on capturing semantic features from unstructured text and converting them into a general code framework, demonstrating strong generalization ability in common business logic generation scenarios. Furthermore, some studies have introduced historical code repository retrieval mechanisms, providing local completion suggestions by matching similar code snippets to enhance the consistency of the generated results with the style of existing projects.
[0003] While existing methods can quickly generate basic code skeletons, they still have limitations when dealing with complex engineering scenarios. On the one hand, most solutions do not fully integrate heterogeneous information from multiple sources, such as requirement texts, interface contracts, and historical implementation patterns, making it difficult for the generated code to meet fine-grained interface constraints and resource management specifications. On the other hand, the lack of trajectory modeling and dynamic constraint propagation mechanisms for code modification processes makes incremental code completion results prone to deviating from the original architecture design, requiring repeated manual verification to ensure system consistency. Summary of the Invention
[0004] In view of the aforementioned existing problems, the present invention is proposed.
[0005] Therefore, this invention provides a programming assistance method based on generative AI to solve the problem that existing technologies struggle to balance interface specifications, resource management, and architectural consistency when generating code.
[0006] To solve the above-mentioned technical problems, the present invention provides the following technical solution: In a first aspect, the present invention provides a programming assistance method based on generative AI, comprising: receiving and standardizing requirement text, interface text, and historical code; extracting and generating a set of functional items, a set of interface items, and a set of pattern items, respectively, and then converting them into functional item state fragments, interface item state fragments, and pattern item state fragments, and merging them in the order of their sources to obtain a set of state fragments; sorting the set of state fragments and establishing a unified scanning order; calculating the connection value between functional item state fragments and interface item state fragments and determining uniquely connected interface item state fragments and pattern item state fragments, thereby generating a set of target trajectories, a set of constraint chains, and corresponding slot sets and a set of reference fragments; constructing training samples and training a code generation model based on the set of target trajectories, the set of constraint chains, the set of slots, and the set of reference fragments; generating a set of candidate patches through the trained code generation model; performing consistency verification on each candidate patch and forming a set of consistency records; determining the target patch or rollback patch corresponding to the current slot based on the set of consistency records, and writing the target patch into the pattern item function code to form update code; verifying the update code through the set of target trajectories and the set of constraint chains to obtain valid update code; summarizing all valid update codes in slot order to generate a programming assistance result.
[0007] As a preferred embodiment of the generative AI-based programming assistance method of the present invention, the steps for merging the state fragment set are as follows: receiving the current task's requirement text, interface text, and historical code, and standardizing and organizing them; based on the organized requirement text, extracting action verbs, action objects, and state conditions sentence by sentence, and combining them to generate a set of function items arranged in the original sentence order; based on the organized interface text, extracting interface names, parameter constraints, return constraints, exception constraints, and call order constraints, and generating a set of interface items arranged in segment order; based on the organized historical code, identifying call statements, resource request positions, resource release positions, exception handling blocks, key call order, and prohibited modes, and merging them by function to generate a set of pattern items; uniformly converting the set of function items, the set of interface items, and the set of pattern items to generate corresponding function item state fragments, interface item state fragments, and pattern item state fragments respectively; merging the function item state fragments, interface item state fragments, and pattern item state fragments according to their source order to obtain a set of state fragments.
[0008] As a preferred embodiment of the generative AI-based programming assistance method of the present invention, the standardization and organization steps are as follows: the requirement text is segmented into sentences by periods, semicolons, and newlines while maintaining the original sentence order; the interface text is segmented into segments by interface signature, parameter description, return description, and exception description while maintaining the original segment position; lexical and syntactic analysis is performed on the historical code to identify function boundaries, variable declaration positions, resource request positions, resource release positions, exception handling positions, and call positions, and the historical code is segmented by function, retaining the file name, function name, and line number range corresponding to each function.
[0009] As a preferred embodiment of the generative AI-based programming assistance method of the present invention, the steps of generating a set of target trajectories and determining the code range corresponding to the target trajectories to form a slot set and a reference fragment set are as follows: sorting the set of state fragments and establishing a unified scanning order; calculating the connection value between functional item state fragments and interface item state fragments and determining the connection threshold; determining a uniquely connected interface item state fragment for each functional item state fragment based on the comparison result of the connection value and the connection threshold; filtering the mode item state fragments and determining the mode item state fragments that can be connected to the interface item state fragments, and selecting the uniquely connected ones. The process involves: generating a target trajectory set based on the state fragments of the function item, interface item, and mode item; generating parameter chains, call chains, resource chains, and exception chains based on the interface item and mode item, and summarizing them to form a constraint chain set; determining the code range corresponding to the target trajectory in the function corresponding to the mode item, forming a slot set and a reference fragment set; and filtering the mode item state fragments, including: retaining mode item state fragments where the called identifier in the call statement has an intersection with the interface name in the name fragment, the key call order does not violate the call order constraint, and the mode does not conflict with the call order constraint, exception constraint, or return constraint.
[0010] As a preferred embodiment of the generative AI-based programming assistance method of the present invention, the training of the code generation model includes the following steps: constructing a target trajectory string, parameter chain string, call chain string, resource chain string, exception chain string, and reference fragment string based on the target trajectory, parameter chain, call chain, resource chain string, exception chain, and reference fragment set; simultaneously extracting code strings outside the slots to construct input samples; constructing the original code corresponding to the slots as output samples; forming a training sample set by matching the input samples with the output samples; and training the code generation model based on the training sample set to obtain a trained code generation model.
[0011] As a preferred embodiment of the generative AI-based programming assistance method of the present invention, the code generation model includes an embedding layer, a position encoding layer, a trajectory encoding layer, a constraint encoding layer, a context encoding layer, a cross-attention decoding layer, and an output layer. The target trajectory string is input into the trajectory encoding layer to obtain a trajectory encoding result. The parameter chain, call chain, resource chain, and exception chain are input into the constraint encoding layer to obtain a constraint encoding result. The reference fragment string and slot-outside code string are input into the context encoding layer to obtain a context encoding result. The trajectory encoding result, constraint encoding result, and context encoding result are input into the cross-attention decoding layer to generate target patch code position by position based on the code content prior to the current position. The generated target patch code is input into the output layer to output a code sequence.
[0012] As a preferred embodiment of the generative AI-based programming assistance method of the present invention, the steps for performing consistency verification on each candidate patch and forming a consistency record set are as follows: The target trajectory string, parameter chain string, call chain string, resource chain string, exception chain string, reference fragment string, and slot-outside code string are used as the model input sequence for the corresponding slot. The trained code generation model is input to obtain candidate patches, which are then aggregated into a candidate patch set. Each candidate patch in the candidate patch set is analyzed to obtain the patch trajectory. The patch trajectory is compared for consistency with the corresponding target trajectory, call chain, resource chain, and exception chain. Based on the comparison results, it is determined whether each candidate patch passes the test, and the results are aggregated to form a consistency record set.
[0013] As a preferred embodiment of the generative AI-based programming assistance method of the present invention, the steps for generating programming assistance results are as follows: Based on the consistency record set, determine the target patch or rollback patch from the candidate patch set corresponding to the current slot; write the target patch into the mode item function code corresponding to the current slot to obtain the update code; verify the update code based on the target trajectory set and the constraint chain set to determine the valid update code; summarize all valid update codes in slot order to generate programming assistance results.
[0014] In a second aspect, the present invention provides a computer device including a memory and a processor, wherein the memory stores a computer program, wherein when the computer program is executed by the processor, it implements any step of the programming-assisted method based on generative AI as described in the first aspect of the present invention.
[0015] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, it implements any step of the programming-aided method based on generative AI as described in the first aspect of the present invention.
[0016] The beneficial effects of this invention are as follows: by determining the uniquely connected interface item state fragment and mode item state fragment, the pertinence and location of programming assistance are improved; by determining the target patch or rollback patch corresponding to the current slot, the stability and usability of programming assistance results are enhanced. Attached Figure Description
[0017] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a flowchart of a programming-aided method based on generative AI.
[0019] Figure 2 This is a schematic diagram of the architecture of a programming aid method based on generative AI.
[0020] Figure 3 This is a schematic diagram illustrating the interaction between training samples and candidate patches.
[0021] Figure 4 A diagram is generated to illustrate the patch determination and update results.
[0022] Figure 5 The impact of connection threshold on key performance indicators.
[0023] Figure 6 A comparison chart of the success rates of different programming assistance methods. Detailed Implementation
[0024] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0025] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of the invention. Therefore, the invention is not limited to the specific embodiments disclosed below.
[0026] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in different places in this specification does not necessarily refer to the same embodiment, nor is it a single or selective embodiment that is mutually exclusive with other embodiments.
[0027] Reference Figures 1-6This is one embodiment of the present invention, which provides a programming assistance method based on generative AI, including the following steps: S1. Receive the requirement text, interface text, and historical code, and standardize and organize them. Extract and generate the function item set, interface item set, and pattern item set respectively. Then, transform them into function item state fragments, interface item state fragments, and pattern item state fragments, and merge them in the order of their sources to obtain the state fragment set.
[0028] Furthermore, the system receives the current task's requirement text, interface text, and historical code. The requirement text is segmented by periods, semicolons, and newlines, preserving the original sentence order. The interface text is segmented by interface signature, parameter description, return statement, and exception description, preserving the original position of each segment. The historical code undergoes lexical and syntactic analysis to identify function boundaries, variable declaration locations, resource allocation locations, resource release locations, exception handling locations, and call locations. The historical code is then segmented by function, preserving the filename, function name, and line number range for each function. After this process, three types of standardized input are formed for further processing: the standardized requirement text, the standardized interface text, and the standardized historical code.
[0029] It should be noted that lexical analysis is performed on the historical code. The historical code is read sequentially from file to file, starting from the first character of each file and scanning character by character according to their order of appearance in the source code. During scanning, consecutive letters, numbers, and underscores are grouped into the same name segment, while parentheses, curly braces, square brackets, semicolons, commas, assignment operators, and operators are identified as independent symbol segments. Spaces, tabs, newlines, and comments are not considered as program semantic segments in subsequent judgments, but their line and column numbers are recorded simultaneously. During the scanning process, for each identified name segment or independent symbol segment, the source file, starting line number, ending line number, starting column number, and ending column number are immediately appended and written into the same sequence in the order of the source code. Position records are established for left parentheses, right parentheses, left curly braces, and right curly braces, resulting in a sequence of symbols arranged in the order of the source code, with each segment bearing a precise position mark. Syntax analysis is performed on the token sequence. Starting from the beginning of the sequence, a continuous segment matching the pattern "return type or modifier + identifier + parameter list + left curly brace" is searched. Once matched, this continuous segment is identified as a function header. The matching continues from the left curly brace following the function header until a matching right curly brace is found. This pair of braces is used as the function boundary, and all code between the braces is identified as the function body. The function body is then divided into determinate code segments. A scan of the function body reveals code segments ending with semicolons, which are classified as basic statement segments. Complete blocks enclosed by left and right curly braces are treated as a single statement segment. Segments beginning with a type name or a recognizable declaration pattern and ending with a semicolon are classified as declaration statements; segments containing paired exception handling structures are classified as exception handling blocks; and segments containing "identifier followed by brackets call structure" are classified as call statements. After the call statements are merged, if the resource corresponding to the called identifier in the call statement enters the operation, the location of the call statement is recorded as the resource request location; if the resource corresponding to the called identifier in the call statement exits the operation, the location of the call statement is recorded as the resource release location.
[0030] Specifically, resource entry operations include creation, opening, acquisition, and initialization; resource exit operations include closing, releasing, committing, rolling back, and destroying.
[0031] The processed requirement text is segmented sentence by sentence, and sentence components are labeled. Words indicating the action are selected from the predicate as action verbs. The action object is extracted from the corresponding object or the object being operated on. State conditions are extracted from components indicating changes in time, condition, or state. The extracted action verbs, action objects, and state conditions from the same sentence are combined into a single functional item, and the original sentence position and original text fragment corresponding to the functional item are recorded. After all sentences have been processed, all functional items are arranged in their original sentence order to generate a functional item set.
[0032] The processed interface text is segmented according to the boundaries of interface signature, parameter description, return description, and exception description. Semantically continuous and positionally independent text segments are identified as interface segments, and their original segment positions within the processed interface text are preserved. For each interface segment, the interface name, parameter name, parameter type, parameter constraint, return value type, return constraint, exception constraint, and call order constraint are extracted sequentially, and the source segment position is recorded. After all interface segments have been processed, they are arranged in their original segment order to generate an interface item set.
[0033] The processed historical code is analyzed function by function to identify call statements, resource allocation locations, resource release locations, exception handling blocks, and key call sequences, and further, prohibited modes within functions are identified. The identified call statements, resource allocation locations, resource release locations, exception handling blocks, key call sequences, prohibited modes, and the original code content within the function boundaries of the same function are merged and organized to form pattern items. The filename, function name, line number range, and corresponding function code for each pattern item are recorded. After all functions have been processed, they are arranged in the order of their appearance to generate a set of pattern items.
[0034] It should be noted that prohibited modes include accessing resources again after they have been released, recommitting after the transaction has ended, and returning without releasing resources in the exception handling block.
[0035] The function item set, interface item set, and mode item set are uniformly transformed to generate a state fragment set. For each function item in the function item set, read the action verb, action object, and state condition of the function item. Determine the pre-state based on the content in the state condition indicating time, condition, or sequence relationship, and determine the post-state based on the result of the action verb acting on the action object. Use the original sentence position and original text fragment corresponding to the function item as the source position of the state fragment to generate the function item state fragment. For each interface item in the interface item set, read the parameter constraints, return constraints, and exception constraints of the interface item. Determine the pre-state based on the parameter conditions limited by the parameter constraints, and determine the post-state based on the return conditions limited by the return constraints or the exception conditions limited by the exception constraints. Use the source segment of the interface item as the source position of the state fragment to generate the interface item state fragment. For each pattern item in the pattern item set, read the call statement, resource allocation position, resource release position, exception handling block, critical call order, and prohibited mode of the pattern item. Determine the pre-state based on the state when the function corresponding to the pattern item starts execution, and determine the post-state based on the processing completion status corresponding to the resource release position and the processing completion status corresponding to the exception handling block. Use the file name, function name, and line number range corresponding to the pattern item as the source position of the state fragment to generate the pattern item state fragment. The state fragments of functional items, interface items, and mode items are merged in the order of their origin to obtain a set of state fragments.
[0036] S2. Sort the set of state segments and establish a unified scanning order. Calculate the connection value between the functional item state segments and the interface item state segments and determine the uniquely connected interface item state segments and mode item state segments. Then generate the target trajectory set, constraint chain set, and corresponding slot set and reference segment set.
[0037] Furthermore, the state fragment set is read, and the function item state fragments are sorted from beginning to end according to their original sentence position; the interface item state fragments are sorted from beginning to end according to their source segment position; the mode item state fragments are first sorted by filename, then by function name, and finally by the starting line number of the line number range in ascending order. After sorting, a unified scanning order is established according to the order of the function item state fragments, interface item state fragments, and mode item state fragments.
[0038] The subsequent states of functional item state fragments are segmented using underscores, case boundaries, punctuation, and spaces to obtain a sequence of subsequent state words. The preceding states of interface item state fragments are segmented using the same segmentation rules as the subsequent states of functional item state fragments to obtain a sequence of preceding state words. The action verbs and action objects corresponding to functional items are concatenated in their original order and then segmented by character, word, or phrase boundaries to obtain a sequence of functional name fragments. The interface names and parameter names corresponding to interface items are concatenated in their original order and then segmented using underscores, case boundaries, numeric boundaries, punctuation, and spaces to obtain a sequence of interface name fragments. The total number of state words in the subsequent states of functional item state fragments and the total number of state words in the preceding states of interface item state fragments are counted. The state words in the subsequent states of functional item state fragments are compared one by one with the state words in the preceding states of interface item state fragments, and the number of identical state words is counted. The percentage of non-repeating state words in the state words of the subsequent states of functional item state fragments and the state words of the preceding states of interface item state fragments is used as the state word overlap ratio, expressed as: ; in, For the first The status fragment of the first function item and the first The overlap ratio of state words between state fragments of each interface item For the first The status fragment of the first function item and the first The number of identical state words in each interface item state fragment. For the first The total number of state words in the state after each functional item state fragment. For the first The total number of state words in the previous state of each interface item's state fragment. For function item index, For the interface item index.
[0039] The function name fragment sequence is counted to obtain its length; the interface name fragment sequence is counted to obtain its length; the function name fragment sequence and the interface name fragment sequence are then compared sequentially to extract name fragments that appear in both sequences in the same order. The sequence with the most name fragments is taken as the longest order-preserving common subsequence, and the number of name fragments in the longest order-preserving common subsequence is determined as its length. The minimum of the function name fragment sequence length and the interface name fragment sequence length is extracted, and the name fragment order-preserving overlap ratio is calculated by comparing it with the longest order-preserving common subsequence length. The expression is as follows: ; in, For the first The status fragment of the first function item and the first The name fragment overlap ratio between the state fragments of each interface item, while maintaining order. For the first Length of each function name segment sequence For the first Length of each interface name fragment For the first The sequence of function name fragments and the first The length of the longest ordered common subsequence of a sequence of interface name fragments.
[0040] Based on the overlap ratio of status words and the order-preserving overlap ratio of name fragments, the connection value between function item status fragments and interface item status fragments is calculated, expressed as: ; in, For the first The status fragment of the first function item and the first The connection value between the state fragments of each interface item.
[0041] It should be noted that the connection value needs to reflect two aspects simultaneously: firstly, whether the state fragments of functional items and interface items are similar in state content; and secondly, whether the name fragments corresponding to functional items and interface items are in a consistent order. Using the geometric mean can reflect the requirement that "both conditions must be met." The result reflects both the similarity of state content and the consistency of the name fragment order, and the result consistently falls between zero and one, facilitating subsequent comparisons.
[0042] It should be noted that if the total number of state words in the state after the function item state fragment and the total number of state words in the state before the interface item state fragment are both 0, then the state word overlap ratio is recorded as 0; if the function name fragment sequence or the interface name fragment sequence is empty, then the name fragment order-preserving overlap ratio is recorded as 0.
[0043] Sort the connection values of each functional item state fragment with all interface item state fragments in ascending order, extract the median and maximum values, and calculate the connection threshold of the functional item state fragments. The expression is: ; in, For the first The connection threshold of each functional item state segment For the first The maximum value of the connection value of each functional item status segment. For the first The median value of the connection values of each functional item state fragment.
[0044] It should be noted that the maximum value of the connection value is used to characterize the optimal upper bound of the connection that the function item can achieve, reflecting the pulling effect of the strongest candidate interface; the median value of the connection value is used to characterize the normal distribution level of the function item among all candidate interfaces, reflecting the overall matching background and suppressing extreme value disturbances; the connection threshold, as an adaptive judgment threshold after combining the two, is used to distinguish between "effective connection that is significantly better than the general level" and "weak connection that is only at the ordinary level". It adopts a geometric mean form to have a synchronous constraint effect on the two factors. If one factor is low, the connection threshold will not be pulled up by the other factor alone, so that the connection threshold retains both the sensitivity to high-quality matching and the constraint on distribution stability.
[0045] The connection value is compared with the connection threshold. If the connection value between the functional item state fragment and all interface item state fragments is 0, the functional item state fragment is marked as having no valid connection. If there is a connection value greater than 0, the interface item state fragment with a connection value not less than the connection threshold is recorded as a connectable interface item state fragment of the functional item state fragment, and the interface item state fragment with the largest connection value is selected as the unique connection object of the functional item state fragment. If multiple interface item state fragments have the same maximum connection value, the interface item state fragment with the earliest source segment is selected as the unique connection object of the functional item state fragment. If the connection value is less than the connection threshold, the corresponding interface item state fragment is marked as an unconnectable interface item state fragment.
[0046] The pattern item state fragments are filtered, retaining those where the called identifier in the call statement overlaps with the interface name in a name fragment, the critical call order does not violate call order constraints, and the prohibited pattern does not conflict with call order constraints, exception constraints, or return constraints. The subsequent states of the interface item state fragments and the preceding states of the pattern item state fragments are read and segmented into an interface subsequent state word sequence and a pattern preceding state word sequence according to the same segmentation rules as the subsequent states of the function item state fragments. If all state words in the interface subsequent state word sequence can be found in the pattern preceding state word sequence, then the two are considered connectable.
[0047] For all connectable pattern item state fragments, first select the pattern item state fragment with the most key call order constraints covering the call order; if they are the same, select the pattern item state fragment with the smallest line number range; if they are still the same, select the pattern item state fragment that appears first in the pattern item set as the unique connection object. After determining the unique pattern item state fragment, sequentially read the previous state of the corresponding function item state fragment, the next state of the function item state fragment, the next state of the interface item state fragment, and the next state of the pattern item state fragment, forming the starting state, first intermediate state, second intermediate state, and ending state to obtain the target trajectory; if there are duplicate state words in adjacent states, they are merged. All target trajectories are generated in the original order to obtain the target trajectory set.
[0048] The parameter names, parameter types, and parameter constraints are associated and combined according to their original order in the interface text to obtain a parameter chain. The key call order in the pattern item is matched with the call order constraints in the interface item according to their execution sequence to form a call chain. The resource request and release positions in the pattern item are paired and arranged according to their order of appearance in the source code to form a resource chain. The exception constraints in the interface item are matched with the exception handling blocks, resource release positions, and return or throw positions in the pattern item according to their exception handling sequence to obtain an exception chain. The parameter chain, call chain, resource chain, and exception chain are summarized into a constraint chain set and uniformly recorded under the target trajectory.
[0049] Within the function of the pattern item, basic statement segments or block structures corresponding to the call order, resource processing order, and exception handling order in the target trajectory are selected. The first line appearing in the basic statement segment or block structure is used as the starting line of the code range, and the last line appearing is used as the ending line of the code range, thus obtaining the code range corresponding to the target trajectory. This code range is then defined as the slot corresponding to the target trajectory. Within the function of the pattern item, basic statement segments and complete block structures between the starting and ending line numbers of the slot are removed. Among the remaining basic statement segments and complete block structures in the function content of the pattern item, statement segments with consecutive line numbers and located at the same complete block structure level are grouped into the same reference fragment. All slots are numbered, and they are summarized with all reference fragments to form a slot set and a reference fragment set, respectively.
[0050] To verify the impact of the connection threshold on the key performance indicators of this invention Figure 5 This paper illustrates the trends in interface item state fragment matching accuracy, pattern item state fragment matching accuracy, slot location accuracy, and programming assistance result success rate under different connection thresholds. The horizontal axis represents the connection threshold, and the vertical axis represents the corresponding indicator value; different curves represent different performance indicators. Figure 5It can be seen that when the connection threshold adjustment coefficient is in a moderate range, the overall indicators are better. This indicates that the present invention can achieve a good balance between reducing misconnections and avoiding missing connections by combining the connection value and the connection threshold, thereby improving the connection accuracy of interface item state fragments and mode item state fragments, and further improving the slot positioning effect and the success rate of programming assistance results.
[0051] S3. Based on the target trajectory set, constraint chain set, slot set and reference segment set, construct training samples and train the code generation model. Generate a candidate patch set through the trained code generation model, perform consistency verification on each candidate patch and form a consistency record set.
[0052] Furthermore, the starting state, first intermediate state, second intermediate state, and ending state in the current target trajectory are concatenated sequentially to form the target trajectory string; the parameter chain is concatenated according to the original order in the interface text to form the parameter chain string; the call chain is concatenated according to the order of calls to form the call chain string; the resource chain is concatenated according to the pairing order of resource request and resource release positions to form the resource chain string; the exception chain is concatenated according to the original order of exception constraints in the interface text to form the exception chain string; the reference fragment code in the reference fragment set formed by removing the code range of the current slot from the function content of the current slot's mode item is read, and concatenated according to the generation order of the reference fragments to form the reference fragment string; from the source code fragment of the mode item corresponding to the target trajectory, the code before the starting line number and the code after the ending line number are extracted, and concatenated according to the source code order to form the slot-out code string. The above contents are arranged in a fixed order as the target trajectory string, parameter chain string, call chain string, resource chain string, exception chain string, reference fragment string, and slot-out code string to form the input sample for the training sample.
[0053] From the source code snippet of the pattern item corresponding to the target trajectory, extract the original code between the start and end line numbers of the slot as the target patch code for the training samples. Divide the code snippet corresponding to the start state in the target patch code into the entry segment, the code snippet corresponding to the call chain into the implementation segment, the code snippet corresponding to the resource chain into the resource segment, the code snippet corresponding to the exception chain into the exception segment, and the code snippet corresponding to the end state into the exit segment. Concatenate the entry segment, implementation segment, resource segment, exception segment, and exit segment in sequence to obtain the output sample for the training samples.
[0054] All input samples are matched one-to-one with output samples and summarized to obtain a training sample set. The training sample set is then divided into a training subset and a validation subset according to a preset ratio (e.g., the ratio of training subset to validation subset is 8:2). The code generation model is trained using the training subset.
[0055] It should be noted that the code generation model includes an embedding layer, a position encoding layer, a trajectory encoding layer, a constraint encoding layer, a context encoding layer, a cross-attention decoding layer, and an output layer. The target trajectory string is input into the trajectory encoding layer to obtain the trajectory encoding result; the parameter chain, call chain, resource chain, and exception chain are input into the constraint encoding layer to obtain the constraint encoding result; the reference fragment string and the out-of-slot code string are input into the context encoding layer to obtain the context encoding result; the trajectory encoding result, constraint encoding result, and context encoding result are input into the cross-attention decoding layer to generate target patch code position by position based on the code content preceding the current position; the generated target patch code is input into the output layer to output the code sequence.
[0056] For each training sample in the training subset, the input sample is first fed into the embedding layer and the position encoding layer, and then into the trajectory encoding layer, the constraint encoding layer and the context encoding layer respectively to obtain the trajectory encoding result, the constraint encoding result and the context encoding result; then the real code content of the previous position of the output sample is fed into the cross-attention decoding layer, and the code content of the next position of the output sample is predicted position by position in the cross-attention decoding layer; finally, the output layer gives the predicted code sequence.
[0057] The input samples are segmented into four levels: target trajectory string, parameter chain string, call chain string, resource chain string, exception chain string, reference fragment string, and slot-out code string. Within each level segment, consecutive letters, numbers, and underscores are grouped into a single input fragment, while parentheses, curly braces, square brackets, semicolons, commas, periods, colons, equal signs, and operators are segmented into separate input fragments. Spaces, tabs, and newlines are used as separators between input fragments instead of being retained as separate fragments. For Chinese descriptions, the input is segmented into consecutive Chinese characters, numbers, and punctuation marks, resulting in a sequence of consecutive input fragments arranged in their original order. Each consecutive input fragment is then fed into an embedding layer, where it is converted into a corresponding vector representation. The order of each consecutive input fragment within the input sample is written into a positional encoding layer, ensuring that the vector representation of each consecutive input fragment also carries order information, resulting in an input sequence representation with order information.
[0058] The input sequence representation is divided according to its components. The portion corresponding to the target trajectory string is sent to the trajectory encoding layer, the portions corresponding to the parameter chain, call chain, resource chain, and exception chain are sent to the constraint encoding layer, and the portions corresponding to the reference segment string and out-of-slot code string are sent to the context encoding layer. The trajectory encoding layer scans the input sequence representation corresponding to the target trajectory string segment by segment and outputs the trajectory encoding result; the constraint encoding layer scans the input sequence representation corresponding to the parameter chain, call chain, resource chain, and exception chain string segment by segment and outputs the constraint encoding result; the context encoding layer scans the input sequence representation corresponding to the reference segment string and out-of-slot code string segment by segment and outputs the context encoding result.
[0059] The output sample is read position by position. The actual code content before the current position is fed into the cross-attention decoding layer. Then, the trajectory encoding result, constraint encoding result, and context encoding result are simultaneously fed into the cross-attention decoding layer, which generates the prediction result for the current position. The prediction result for the current position is then fed into the output layer to obtain the predicted code content for the current position. Predicting continues from the starting position to the ending position of the output sample to obtain the predicted code sequence corresponding to the training sample.
[0060] It should be noted that the predicted code sequence means that at each position, a candidate predicted code group is obtained, and the predicted probability of each candidate predicted code in this candidate predicted code group is given.
[0061] The output samples are numbered sequentially according to their positions. All parameters that need to be trained are recorded as trainable parameters. The predicted code sequence is matched one-to-one with the real code content in the output samples according to their corresponding positions. The length of the output sample is calculated. The prediction probability of the real code content in the candidate predicted code group of the predicted code sequence is extracted. The training error is calculated, and the expression is: ; in, For training error, To output the sample length, This is the position number of the output sample. For the first The predicted probability of the actual code content at each position in the candidate predicted code group of the predicted code sequence. These are trainable parameters.
[0062] It should be noted that if the actual code content does not appear in the prediction results, the lowest prediction probability in the prediction results will be taken as the prediction probability of the actual code content.
[0063] It should be noted that the trainable parameters include the embedding matrix parameters in the embedding layer, the position encoding matrix parameters in the position encoding layer, the self-attention weight parameters, feedforward network weight parameters, feedforward network bias parameters, and normalization parameters in the trajectory encoding layer, the self-attention weight parameters, feedforward network weight parameters, feedforward network bias parameters, and normalization parameters in the constraint encoding layer, the self-attention weight parameters, feedforward network weight parameters, feedforward network bias parameters, and normalization parameters in the context encoding layer, the self-attention weight parameters, cross-attention weight parameters, feedforward network weight parameters, feedforward network bias parameters, and normalization parameters in the cross-attention decoding layer, and the output mapping weight parameters and output bias parameters in the output layer.
[0064] The gradient of the trainable parameters is calculated based on the training error, expressed as follows: ; in, For the first The gradient of the trainable parameters in the next update. For the first The next update of trainable parameters. This represents the number of updates.
[0065] Let the first momentum parameter and the second momentum parameter be defined, and the first-order cumulant and the second-order cumulant be calculated respectively, with the following expressions: ; ; in, For the first The first-order cumulative amount updated next time. For the first The first-order cumulative amount updated next time. The first momentum parameter, For the first The second-order cumulative amount in the next update For the first The second-order cumulative amount in the next update This is the second momentum parameter.
[0066] It should be noted that the first momentum parameter is used to smoothly accumulate the parameter update direction, reducing directional fluctuations during adjacent updates; while preserving the characteristics of the current gradient direction, it improves the continuity and stability of the update direction, and its preferred value is 0.9. The second momentum parameter is used to accumulate and statistically analyze the squared gradient, adjusting the update scale in different parameter dimensions; while ensuring the stability of the update scale, it suppresses the amplifying effect of local abnormal gradients on parameter updates, and its preferred value is 0.95.
[0067] The first-order and second-order cumulants are corrected, and the expression is as follows: ; ; in, For the first The next update corrects the first-order cumulative amount. For the first The second-order cumulative amount is corrected in the next update.
[0068] Set a base learning rate and a warm-up number of steps. Update the base learning rate when the number of updates is no greater than the number of warm-up steps. The expression is: ; in, For the first The learning rate updated next time. Based on learning rate This represents the number of preheating steps.
[0069] It should be noted that the base learning rate is used to control the parameter update step size, ensuring the code generation model maintains convergence during both the initial and stable training phases. It is a value that guarantees a continuous decrease in training error while avoiding excessively large parameter update amplitudes that could cause training oscillations, and also prevents excessively slow convergence. A value of 0.0001 is preferred. The warm-up steps are used in the initial training phase when the parameters are not yet stable, ensuring the learning rate does not immediately reach the target update intensity. Based on the rate of decrease in training error and the stability of parameter updates in the initial training phase, the number of updates required for the learning rate to gradually increase from low to high is determined, with a preferred value of 500.
[0070] If the number of updates exceeds the number of warm-up steps, the base learning rate is used.
[0071] The trainable parameters are updated based on the learning rate, as expressed by: ; in, For the first The next update of trainable parameters. To prevent extremely small constants with a denominator of zero.
[0072] It should be noted that the minimum constant is taken as the minimum value that ensures the denominator is not zero.
[0073] One training round involves updating all trainable parameters across all training samples in the training subset. After each round, the training error of the validation subset is calculated using the updated trainable parameters and all validation samples. The average training error of all validation subsets is then used to obtain the validation error. The validation error is then smoothed, with a smoothing window length set to [value missing]. Extract the verification error of the current round and the previous rounds. The validation error of the training rounds affects the extracted... The average of the verification errors is calculated to obtain the smoothed verification error for the current round. If the number of rounds is less than... Then, the average value of all the verification errors calculated so far is used to obtain the smoothed verification error for the current round.
[0074] It should be noted that the length of the smooth window is preferably 3 or 5.
[0075] Starting from the first round of training, the smoothed validation error obtained in the first round is taken as the optimal smoothed validation error. The smoothed validation error obtained in the second round is compared with the optimal smoothed validation error. If the smoothed validation error obtained in the second round is less than the optimal smoothed validation error, then the smoothed validation error obtained in the second round is taken as the optimal smoothed validation error, and the model corresponding to the current round is saved as the optimal model; if the smoothed validation error obtained in the second round is not less than the optimal smoothed validation error, it is recorded as one instance of no improvement. This comparison is performed sequentially for each round of smoothed validation error with the optimal smoothed validation error. When the number of consecutive instances of no improvement reaches a preset number, training of the code generation model is stopped, and the current optimal model is taken as the completed code generation model.
[0076] It should be noted that the preset number of consecutive periods of no improvement is calculated based on the smoothing window length, and the expression is as follows: ; in, This is a preset number of consecutive periods without improvement. To smooth out window length.
[0077] Specifically, because the smoothing verification error is caused by the most recent consecutive The average validation error obtained from each training round has a certain lag compared to the single validation error. The real changes in the performance of the code generation model will not be immediately and completely reflected in the current round. Therefore, the number of consecutive unimproved iterations used to determine whether to stop training should be greater than the length of the smoothing window to avoid stopping training prematurely before a complete fluctuation process has been fully observed. At the same time, the number of consecutive unimproved iterations should not be set too large, otherwise the model will continue to train for too many rounds when there is no obvious improvement, increasing the training cost and possibly missing the best stopping time near the optimal model.
[0078] The target trajectory string, parameter chain string, call chain string, resource chain string, anomaly chain string, reference fragment string, and slot-out code string are used as the model input sequence for the corresponding slot. The model input sequence is then fed into the trained code generation model to generate the first code segment corresponding to the initial state and parameter chain, and this first code segment is designated as the entry segment. After appending the entry segment to the model input sequence, it is re-entered into the trained code generation model to generate the code corresponding to the call chain, and this code segment is designated as the implementation segment. After appending the entry segment and implementation segment to the model input sequence, it is re-entered into the trained code generation model to generate the code corresponding to the resource chain, and this code segment is designated as the resource segment. After appending the entry segment, implementation segment, and resource segment to the model input sequence, it is re-entered into the trained code generation model to generate the code corresponding to the anomaly chain, and this code segment is designated as the anomaly segment. Finally, after appending the entry segment, implementation segment, resource segment, and anomaly segment to the model input sequence, it is re-entered into the trained code generation model to generate the final code segment corresponding to the final state, and this final code segment is designated as the exit segment.
[0079] By concatenating the entry segment, implementation segment, resource segment, exception segment, and exit segment in sequence, a candidate patch is obtained. All candidate patches are then combined to obtain a candidate patch set.
[0080] Based on the same rules for generating the set of state fragments, the current candidate patch is analyzed to obtain the patch state fragments, and the patch state fragments are spliced together in the order of entry segment, implementation segment, resource segment, exception segment and exit segment to form the patch trajectory.
[0081] The patch trajectory undergoes four consistency comparisons. First, the target trajectory corresponding to the current candidate patch is read, and the patch trajectory is compared state-by-state sequentially with the target trajectory. If the patch trajectory corresponds sequentially to the start state, first intermediate state, second intermediate state, and end state in the target trajectory, it is considered consistent with the target trajectory. If there are missing states, reversed states, or additional states that cannot be matched, they are added to the unsatisfied item list. Second, the call chain corresponding to the current candidate patch is read, and the call statements in the candidate patch are arranged in order of appearance and compared item-by-item with the call chain. If the call orders in the call chain appear in the same order in the candidate patch, the call chain is considered consistent. If there are missing calls, reversed call orders, or additional calls that disrupt the original order, they are added to the unsatisfied item list. Third, read the resource chain corresponding to the current candidate patch. Pair the resource request and release positions in the candidate patch according to the source code order and compare them item by item with the resource chain. If the resource request and release positions in the resource chain can all be matched in the candidate patch, it is recorded as a consistent resource chain. If there are cases where resources are requested but not released, the resource release order is incorrect, or the release objects do not correspond, they are recorded in the list of unsatisfactory items. Fourth, read the exception chain corresponding to the current candidate patch. Arrange the exception handling blocks in the candidate patch according to their appearance order and compare them item by item with the exception chain. If the exception handling blocks, resource release positions, and return or throw positions in the exception chain all have corresponding relationships in the candidate patch, it is recorded as a consistent exception chain. If there are cases where exception handling is missing, the exception handling block lacks a resource release position, or lacks a return or throw position, they are recorded in the list of unsatisfactory items. If all four consistency comparisons are consistent, the current candidate patch is recorded as passed. If any one of them is inconsistent, the inconsistent content is recorded in the list of unsatisfactory items, and the current candidate patch is recorded as failed.
[0082] The processing results corresponding to each candidate patch are summarized to obtain a set of consistency records.
[0083] S4. Determine the target patch or rollback patch corresponding to the current slot based on the consistency record set, and write the target patch into the mode item function code to form the update code. After verification by the target trajectory set and constraint chain set, the valid update code is obtained. All valid update codes are summarized in slot order to generate programming assistance results.
[0084] Furthermore, for the current slot, all candidate patches corresponding to the current slot are filtered out, and the consistency record is read. If a candidate patch is marked as passed in the consistency record, it is retained as the target patch. If there is no passed candidate patch for the current slot, the candidate patch with the shortest unmet item list length is selected from the failed candidate patches as the rollback patch, and a "manual confirmation required" flag is recorded. At the same time, the unmet item list corresponding to the rollback patch is recorded. When generating programming assistance results, the rollback patch, unmet item list, and "manual confirmation required" flag for the current slot are written into the programming assistance results for developers to review.
[0085] The code snippet reads the function code corresponding to the pattern item in the current slot, retaining the code before the slot's start line number and the code after the slot's end line number. The target patch is then written between these two lines to obtain the updated code. During writing, the entry segment is directly appended to the preceding code snippet in the current slot, the implementation segment to the entry segment, the resource segment to the implementation segment, the exception segment to the resource segment, and the exit segment to the exception segment. After writing, the code snippet reads the target trajectory set and constraint chain set corresponding to the current slot and verifies each item in the updated code. First, it checks if the updated code corresponds sequentially to the start state, first intermediate state, second intermediate state, and end state. Then, it checks if the call statements maintain the order in the call chain. Next, it checks if the resource request and release positions maintain the pairing relationship in the resource chain. Finally, it checks if the exception handling block contains the exception handling block, resource release position, and return or throw position required by the exception chain. If all four conditions are met, the current update code is recorded as a valid update code; if any one condition is not met, the target patch code is retained and no further writing is continued into the official project file, and the current slot is marked as "write failed".
[0086] All valid update code is summarized in slot number order to generate programming assistance results. If the current slot corresponds to a rollback patch, a list of unmet requirements for that slot is also written into the programming assistance results for developers to view directly.
[0087] To verify the improvement effect of this invention on the overall programming assistance effect, Figure 6 The presentation compares the success rates of programming assistance results under different schemes. The horizontal axis represents the scheme type, and the vertical axis represents the success rate of programming assistance results. By comparing the scheme of this invention, the non-unique connection scheme, the scheme with inconsistent record sets, and the scheme without rollback patches, it can be seen that the scheme of this invention has the highest success rate of programming assistance results. This indicates that by determining the state fragments of unique connection interface items and pattern items, and combining this with the determination mechanism of target patches or rollback patches, the present invention can more effectively improve the success rate of the final programming assistance results, demonstrating good overall targeting, locationability, stability, and usability.
[0088] This embodiment also provides a computer device applicable to programming assistance methods based on generative AI, including: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the programming assistance method based on generative AI as proposed in the above embodiment.
[0089] The computer device can be a terminal, comprising a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.
[0090] This embodiment also provides a storage medium storing a computer program that, when executed by a processor, implements the programming-assisted method for generative AI as proposed in the above embodiments. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0091] In summary, this invention improves the targeting and location of programming assistance by: determining the uniquely connected interface item state fragment and mode item state fragment; and enhances the stability and usability of programming assistance results by determining the target patch or rollback patch corresponding to the current slot.
[0092] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A programming assistance method based on generative AI, characterized in that, include: Receive and standardize the requirement text, interface text, and historical code, extract and generate the function item set, interface item set, and pattern item set respectively, and then transform them into function item state fragments, interface item state fragments, and pattern item state fragments, and merge them in the order of their source to obtain the state fragment set. The state fragment set is sorted and a unified scanning order is established. The connection value between the functional item state fragment and the interface item state fragment is calculated and the uniquely connected interface item state fragment and mode item state fragment are determined. Then, the target trajectory set, constraint chain set, and corresponding slot set and reference fragment set are generated. Based on the target trajectory set, constraint chain set, slot set and reference segment set, training samples are constructed and a code generation model is trained. A candidate patch set is generated through the trained code generation model. Consistency verification is performed on each candidate patch and a consistency record set is formed. The target patch or rollback patch corresponding to the current slot is determined based on the consistency record set, and the target patch is written into the mode item function code to form the update code. After verification by the target trajectory set and constraint chain set, the valid update code is obtained. All valid update codes are summarized in slot order to generate programming assistance results.
2. The programming assistance method based on generative AI as described in claim 1, characterized in that, The merging process yields a set of state fragments, and the steps are as follows: Receive the current task's requirement text, interface text, and historical code, and then standardize and organize them. Based on the organized requirements text, action verbs, action objects, and state conditions are extracted sentence by sentence and combined to generate a set of functional items arranged in the original sentence order; Based on the organized interface text, extract the interface name, parameter constraints, return constraints, exception constraints, and call order constraints to generate a set of interface items arranged in segment order; Based on the reorganized historical code, identify call statements, resource request locations, resource release locations, exception handling blocks, key call sequences, and prohibited modes, and generate a set of mode items by function; The function item set, interface item set, and mode item set are uniformly transformed to generate corresponding function item state fragments, interface item state fragments, and mode item state fragments, respectively. The status fragments of functional items, interface items, and mode items are merged in order of origin to obtain a set of status fragments.
3. The programming assistance method based on generative AI as described in claim 2, characterized in that, The standardization and organization process involves the following steps: The required text is segmented into sentences using periods, semicolons, and line breaks while maintaining the original sentence order; The interface text is segmented according to the interface signature, parameter description, return description, and exception description, while maintaining the original segmentation. Lexical and syntactic analysis is performed on historical code to identify function boundaries, variable declaration locations, resource allocation locations, resource release locations, exception handling locations, and call locations. Historical code is then segmented by function, retaining the file name, function name, and line number range corresponding to each function.
4. The programming assistance method based on generative AI as described in claim 2 or 3, characterized in that, The steps for generating the target trajectory set and determining the code range corresponding to the target trajectory to form the slot set and reference fragment set are as follows: Sort the set of state fragments and establish a unified scanning order; Calculate the connection value between the functional item state fragment and the interface item state fragment, and determine the connection threshold; Based on the comparison between the connection value and the connection threshold, a uniquely connected interface item state segment is determined for each functional item state segment. Filter the pattern item state fragments and determine the pattern item state fragments that can be connected to the interface item state fragments, and select the uniquely connected pattern item state fragment. Generate a set of target trajectories based on functional item state fragments, interface item state fragments, and mode item state fragments; Parameter chains, call chains, resource chains, and exception chains are generated based on interface items and pattern items, and then summarized to form a set of constraint chains. In the function corresponding to the pattern item, the code range corresponding to the target trajectory is determined, forming a slot set and a reference fragment set; The filtering of mode item state fragments includes: retaining mode item state fragments in which the called identifier and the interface name have an intersection of name fragments, the critical call order does not violate the call order constraint, and the prohibited mode does not conflict with the call order constraint, exception constraint, or return constraint.
5. The programming assistance method based on generative AI as described in claim 4, characterized in that, The steps for training the code generation model are as follows: Based on the target trajectory, parameter chain, call chain, resource chain, exception chain, and reference fragment set, construct the target trajectory string, parameter chain string, call chain string, resource chain string, exception chain string, and reference fragment string. At the same time, extract the code string outside the slot to construct the input sample, and construct the original code corresponding to the slot as the output sample. The input samples are matched with the output samples to form a training sample set; The code generation model is trained based on the training sample set to obtain the trained code generation model.
6. The programming assistance method based on generative AI as described in claim 5, characterized in that, The code generation model includes an embedding layer, a position encoding layer, a trajectory encoding layer, a constraint encoding layer, a context encoding layer, a cross-attention decoding layer, and an output layer; The target trajectory string is input into the trajectory encoding layer to obtain the trajectory encoding result; the parameter chain string, call chain string, resource chain string and exception chain string are input into the constraint encoding layer to obtain the constraint encoding result. The reference fragment string and the out-of-slot code string are input into the context encoding layer to obtain the context encoding result; The trajectory encoding result, constraint encoding result, and context encoding result are input into the cross-attention decoding layer, and target patch code is generated position by position based on the code content before the current position; The generated target patch code is input into the output layer, and the output code sequence is generated.
7. The programming assistance method based on generative AI as described in claim 5, characterized in that, The steps for performing consistency checks on each candidate patch and forming a consistency record set are as follows: The target trajectory string, parameter chain string, call chain string, resource chain string, exception chain string, reference fragment string, and code string outside the slot are used as the model input sequence for the corresponding slot. The trained code generation model is input to obtain candidate patches, which are then summarized into a candidate patch set. Each candidate patch in the candidate patch set is analyzed to obtain the patch trajectory; The patch trajectory is compared with the corresponding target trajectory, call chain, resource chain, and exception chain for consistency. Based on the comparison results, it is determined whether each candidate patch passes and the results are aggregated to form a consistency record set.
8. The programming assistance method based on generative AI as described in claim 7, characterized in that, The steps for generating programming assistance results are as follows: Based on the consistency record set, determine the target patch or rollback patch from the candidate patch set corresponding to the current slot; Write the target patch into the mode item function code corresponding to the current slot to obtain the update code; The update code is validated based on the target trajectory set and constraint chain set to determine the valid update code; All valid update code is summarized in slot order to generate programming assistance results.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the programming assistance method based on generative AI as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the programming assistance method based on generative AI as described in any one of claims 1 to 8.