Code auxiliary optimization method and system suitable for integrated development environment

By integrating the code completion optimization management model in the integrated development environment, and using context-aware and adaptive auxiliary management models, the target source code is optimized, which solves the problems of low code completion performance and limited context understanding in the existing technology, and improves code optimization and development efficiency.

CN119556899APending Publication Date: 2025-03-04CCORE TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411501568.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-03-04

AI Technical Summary

Technical Problem

Code completion or recommended methods in existing integrated development environments have issues of performance and latency, contextual limitations, dependencies and stability, security and privacy, and limited customization capabilities.

Method used

It provides a code-assisted optimization method suitable for an integrated development environment. Through the integrated code completion optimization management model, the context-aware module and the adaptive auxiliary management model are used to assist in the optimization and optimization of the target source code to generate target source code optimization management information that is suitable for the current development behavior.

Benefits of technology

Effectively implement the optimization of code, improve development efficiency and code quality, solve problems such as low performance, limited context understanding, and dependence on external services in the existing technology, and improve the accuracy of code completion and personalized customization capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119556899A_ABST
    Figure CN119556899A_ABST
Patent Text Reader

Abstract

The invention relates to a code auxiliary optimization method and system suitable for an integrated development environment. The method comprises the steps that an integrated development environment is provided, a code completion optimization management model is integrated in the integrated development environment, and for any target source code in the integrated development environment, when a development behavior for the target source code is matched with a preset code auxiliary management behavior, the code completion optimization management model is started; triggering the code completion optimization management model to perform auxiliary optimization on a target source code; when the target source code is subjected to auxiliary optimization, the code completion optimization management model obtains code target context information of the target source code; based on the obtained code target context information, target source code optimization management information matched with the current development behavior is generated, and the target source code optimization management information comprises target source code completion information and / or target source code optimization suggestion information. According to the method, code optimization can be effectively realized, and the development efficiency and the code quality are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a code-assisted optimization method and system, in particular to a code-assisted optimization method and system suitable for an integrated development environment. Background Art

[0002] In the software development process, the integrated development environment (IDE) is an important development tool used by developers. With the widespread application of large language models (LLM), it has become a trend to integrate large language models into IDE to provide intelligent code completion and suggestions.

[0003] At present, when integrating large language models into IDEs, most of them are integrated by API or IDE plug-in.

[0004] When a large language model is integrated using an API, code analysis and suggestion generation are implemented by calling cloud services. Specifically, the IDE sends a request to the cloud model through the API interface, and the request sent includes code snippets and context information. The cloud model processes the request, generates suggestions or completes the code, and then returns the results to the IDE through the API interface. A typical example is: GitHub Copilot is integrated with Visual Studio Code, and the OpenAI Codex model in the cloud is called through the API to generate code suggestions.

[0005] When integrating large language models using APIs, there are the following main shortcomings:

[0006] 1) Performance and latency: API calls usually require data to be transmitted over the network, which may result in longer response times and affect the development experience;

[0007] 2) Context limitation: API calls are usually limited to the context of the current code snippet, making it difficult to fully understand the structure and logic of the entire project;

[0008] 3) Dependency and stability: Dependence on external API services. If the service is interrupted or the API is changed, the normal operation of the system may be affected;

[0009] 4) Security and privacy: Data needs to be transmitted to a remote server for processing, which may result in potential data leakage and privacy risks;

[0010] 5) Limited customization capabilities: APIs usually provide general functions and are difficult to deeply customize according to specific project requirements.

[0011] When integrating a large language model with an IDE plug-in, the LLM function is embedded into the IDE by developing a dedicated IDE plug-in, where the plug-in can handle some code analysis tasks locally, or interact with cloud services through the plug-in, integrating the LLM's code completion and suggestion functions into the IDE, enabling it to interact with modules such as editors, debuggers, and project managers. A typical example is TabNine (a code completion plug-in using a deep learning model), which can be integrated into a variety of IDEs, including the JetBrains series and Visual Studio Code.

[0012] When using plug-ins to integrate large language models, there are the following main shortcomings:

[0013] 1) Performance and resource consumption: When the plug-in runs in the IDE, it may consume a lot of resources, causing the IDE to become slow or unstable;

[0014] 2) Maintenance and compatibility issues: Plug-ins need to be adapted and maintained as IDE versions are updated, which increases development and maintenance costs;

[0015] 3) Functional limitations: The functions of plug-ins are usually pre-defined and difficult to flexibly adjust according to specific project requirements;

[0016] 4) Limited contextual understanding: Although the plugin can run locally, it may still lack a global understanding of the entire project;

[0017] 5) Integration complexity: Different plug-ins may require complex configuration and integration processes, increasing the usage threshold.

[0018] From the above description, it can be seen that the code completion or suggestion methods in the existing integrated environment are difficult to meet actual needs. Summary of the invention

[0019] The purpose of the present invention is to overcome the deficiencies in the prior art and to provide a code-assisted optimization method and system suitable for an integrated development environment, which can effectively optimize the code and improve development efficiency and code quality.

[0020] According to the technical solution provided by the present invention, a code-assisted optimization method suitable for an integrated development environment comprises:

[0021] An integrated development environment is provided, and a code completion optimization management model is integrated in the integrated development environment, so as to use the integrated code completion optimization management model to assist in optimizing the target source code in the integrated development environment, wherein:

[0022] For any target source code in the integrated development environment, when the development behavior for the target source code matches the preset code auxiliary management behavior, the code completion optimization management model is triggered to perform auxiliary optimization on the target source code;

[0023] When assisting in optimizing the target source code, the code completion optimization management model obtains the code target context information corresponding to the target source code and the current development behavior;

[0024] Based on the acquired code target context information, target source code optimization management information adapted to the current development behavior is generated, wherein the target source code optimization management information includes target source code completion information and / or target source code optimization suggestion information.

[0025] The code completion optimization management model includes a context-aware module and an adaptive auxiliary management model adapted to the context-aware module, wherein:

[0026] When assisting in optimizing the target source code, the context-aware module is used to extract code target context information of the target source code, and the acquired code target context information is loaded into the adaptive assist management model;

[0027] The adaptive auxiliary management model generates target source code optimization management information based on at least the code target context information, and returns the generated target source code optimization management information to the integrated development environment.

[0028] The context-aware module extracts the code target context information of the target source code, including:

[0029] Obtain static context information, dynamic context information, and code semantic information of the target source code.

[0030] Based on static context information, dynamic context information and code semantic information, the target context information of the generated code is extracted.

[0031] When extracting code target context information of the target source code by using the context awareness module, the target source code is firstly subjected to code optimization preprocessing to generate target source code preprocessing information after the code optimization preprocessing;

[0032] Code optimization preprocessing of the target source code includes code parsing processing and / or behavior parsing processing, wherein:

[0033] When performing code parsing processing on the target source code, code body information of the target source code is extracted, wherein the code body information at least includes syntax information of the target source code and structure information of the target source code;

[0034] When performing behavior analysis processing on the target source code, development interaction information in the integrated development environment is analyzed to generate code behavior information based on the analyzed development interaction information, wherein the code behavior information includes an interaction operation sequence and interaction context information;

[0035] Based on the target source code preprocessing information, the context-aware module extracts the code target context information, where:

[0036] Performing static analysis and capturing of code body information of the target source code to generate static context information after static analysis and capturing;

[0037] Dynamic analysis is performed on code behavior information of the target source code to generate dynamic context information after dynamic analysis and capture.

[0038] The adaptive auxiliary management model is constructed based on a large language model.

[0039] When building an adaptive auxiliary management model based on a large language model, it at least includes a model training step, wherein:

[0040] When executing the management model training steps, including:

[0041] Constructing a management model training data set, wherein the management model training data set includes a plurality of training samples;

[0042] Constructing an adaptive auxiliary management basic model based on a large language model, and using the management module training data set to perform model training on the adaptive auxiliary management basic model;

[0043] When the model training of the adaptive assisted management basic model reaches the target state, an adaptive assisted management model is formed based on the adaptive assisted management basic model.

[0044] After the code completion optimization management model is integrated into the integrated development environment, at least the adaptive auxiliary management model is dynamically adjusted based on the adaptive learning method, wherein:

[0045] The adaptive learning method includes an incremental learning method and / or an online learning method;

[0046] When dynamically adjusting the adaptive auxiliary management model based on the incremental learning method, it includes:

[0047] In the integrated development environment, collecting auxiliary management feedback information, wherein the auxiliary management feedback information includes accepted operation information, modified operation information or rejected operation information;

[0048] Fine-tuning training is performed on the adaptive assisted management model based on the assisted management feedback information, so as to dynamically adjust the adaptive assisted management model based on the fine-tuning training.

[0049] When the adaptive auxiliary management model is dynamically adjusted, the dynamic adjustment method includes vocabulary, generation strategy, code snippet priority, naming style parameters, library and framework preferences, code formatting parameters and / or comment generation and use parameters.

[0050] When building a model training dataset, include:

[0051] Collecting training data, wherein any collected training data at least includes a training source code and source code interaction information corresponding to the training source code;

[0052] Performing training data preprocessing on each of the training data collected above to generate preprocessed training data after the training data preprocessing;

[0053] Context understanding and capture processing is performed on each of the pre-processed training data to generate training samples after the context understanding and capture processing, wherein the training samples include training source code context information.

[0054] It also includes a personalized customization optimization module for personalized processing of target source code optimization management information, wherein:

[0055] The personalized customization optimization module optimizes the target source code optimization management information according to a preset coding style and / or coding habit, so as to generate personalized optimization management information of the target source code after optimization;

[0056] Return the target source code personalized optimization management information to the integrated development environment.

[0057] A code-assisted optimization system suitable for an integrated development environment includes a terminal device installed with an integrated development environment, wherein the terminal device uses the above-mentioned code-assisted optimization method to perform code-assisted optimization on the target source code in the integrated development environment, so as to provide target source code optimization management information after the code-assisted optimization.

[0058] The advantages of the present invention are as follows: the context-aware module is used to perform context-awareness on the target source code, wherein, during context-awareness, multi-level semantic analysis is performed on the target source code through real-time static analysis, dynamic analysis and natural language processing technology to generate instant context information. The adaptive auxiliary management model generates target source code optimization management information according to the target code context model, thereby effectively optimizing the code and improving development efficiency and code quality. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Figure 1 A schematic diagram of a flow chart of an embodiment of code-assisted optimization of the present invention.

[0060] Figure 2 The present invention is a structural block diagram of an embodiment of the code completion optimization management model and the integrated development environment.

[0061] Figure 3 A schematic diagram of an embodiment of data collection and processing of the present invention.

[0062] Figure 4 A schematic diagram of an embodiment for capturing and understanding the context of the present invention.

[0063] Figure 5 A schematic diagram of an embodiment of model training and optimization of the adaptive auxiliary management model of the present invention.

[0064] Figure 6 A schematic diagram of an embodiment of the system integration and expansion of the present invention.

[0065] Figure 7 A flow chart of an embodiment of code-assisted optimization of the present invention. DETAILED DESCRIPTION

[0066] The present invention will be further described below in conjunction with specific drawings and embodiments.

[0067] In order to effectively optimize the code and improve the development efficiency and code quality, the present invention provides a code-assisted optimization method suitable for an integrated development environment. Specifically, the code-assisted optimization method includes:

[0068] An integrated development environment is provided, and a code completion optimization management model is integrated in the integrated development environment, so as to use the integrated code completion optimization management model to assist in optimizing the target source code in the integrated development environment, wherein:

[0069] For any target source code in the integrated development environment, when the development behavior for the target source code matches the preset code auxiliary management behavior, the code completion optimization management model is triggered to perform auxiliary optimization on the target source code;

[0070] When assisting in optimizing the target source code, the code completion optimization management model obtains the code target context information corresponding to the target source code and the current development behavior;

[0071] Based on the acquired code target context information, target source code optimization management information adapted to the current development behavior is generated, wherein the target source code optimization management information includes target source code completion information and / or target source code optimization suggestion information.

[0072] Figure 1A flow chart of an embodiment of code-assisted optimization is shown in the figure. It can be seen from the figure that when performing code-assisted optimization, it is necessary to provide an integrated development environment (IDE), and integrate a code completion optimization management model in the provided integrated development environment, wherein the integrated development environment can be an existing commonly used programming environment that can be used for code development, and the type of the integrated development environment can be selected according to needs. The code completion optimization management model can be used to perform code-assisted optimization on the target source code in the integrated development environment. Specifically, the target source code is the current code in the integrated development environment, that is, the code being developed in the integrated development environment. The code-assisted optimization of the target source code can generally include code completion and / or code optimization suggestions. The specific meanings of code completion and code optimization suggestions can be consistent with the prior art and are not given by examples here.

[0073] It should be noted that when configuring the code completion optimization management model to assist in optimizing the target source code, it is necessary to monitor the development behavior of the target source code in the integrated development environment. When there is a development behavior that should be assisted in optimizing, the code completion optimization management model will be triggered. Thereafter, the code completion optimization management model can be used to assist in optimizing the target source code. It can be understood that by monitoring the development behavior of the target source code and triggering the code completion optimization management model to assist in optimizing the target source code only when the development behavior of the target source code matches the preset code assisted management behavior, interference with the normal development behavior of the target source code can be avoided.

[0074] In order to effectively monitor development behaviors, code-assisted management behaviors should be preset in the integrated development environment, where the preset code-assisted management behaviors may include code editing behaviors, refactoring behaviors, debugging behaviors, submission behaviors and / or static analysis behaviors that occur in the integrated development environment. Specifically, code editing behaviors refer to editing operations on target source code in the integrated development environment, and debugging behaviors refer to debugging target source code in the integrated development environment; refactoring behaviors may include multiple renaming and moving code blocks; debugging behaviors may include multiple analysis and breakpoint setting behaviors; preset code-assisted management behaviors may be selected according to actual needs so as to provide developers with real-time and accurate assisted optimization.

[0075] In one embodiment of the present invention, when assisting in optimizing the target source code, the code completion optimization management model needs to first obtain the code target context information of the target source code, and thereafter, the target source code optimization management information can be generated based on the obtained code target context information; it can be understood that the code target context information can be used to achieve a deep understanding of the global context of the target source code, and thus, more accurate and relevant target source code optimization management information can be generated based on the code target context information, specifically, the global context specifically refers to the context information covering the entire target source code or code library, so as to provide a deep understanding of the entire target source code. Corresponding to the global context is the local context, wherein the local context specifically refers to the code area corresponding to the current development behavior in the integrated environment, and focuses on the information of the logic and structure of the current code segment.

[0076] It should be understood that the generated target source code optimization management information should generally be adapted to the current development behavior. For example, when the development behavior is code editing behavior, the target source code optimization management information can be target source code completion information. When the development behavior is debugging behavior, the target source code optimization management information can be target source code optimization suggestion information. The adaptation between the generated target source code optimization management information and the current development behavior will not be illustrated one by one here.

[0077] When it is necessary to explain, after generating the target source code optimization management information, the target source code optimization management information should be returned to the integrated development environment, that is, the target source code optimization management information should be returned to the user interface of the integrated development environment. After that, the developer can directly observe the corresponding target source code optimization management information so as to accept / reject the auxiliary optimization of the target source code according to the target source code optimization management information. The following is a detailed description of the code completion optimization management model, the method and process of obtaining code target context information using the code completion optimization management model, and the generation of target source code optimization management information.

[0078] In one embodiment of the present invention, the code completion optimization management model includes a context-aware module and an adaptive auxiliary management model adapted to the context-aware module, wherein:

[0079] When assisting in optimizing the target source code, the context-aware module is used to extract code target context information of the target source code, and the acquired code target context information is loaded into the adaptive assist management model;

[0080] The adaptive auxiliary management model generates target source code optimization management information based on at least the code target context information, and returns the generated target source code optimization management information to the integrated development environment.

[0081] Figure 2 An embodiment of the code completion optimization management model of the present invention is shown in the figure. In the figure, the code completion optimization management model includes a context awareness module and an adaptive auxiliary management model. The context awareness module can be used to extract code target context information of the target source code, and the extracted code target context information will be loaded into the adaptive auxiliary management model. After receiving the code target context information, the adaptive auxiliary management model can generate target source code optimization management information based on at least the code target context information. As can be seen from the above description, the generated target source code optimization management information is returned to the user interface of the integrated development environment.

[0082] In one embodiment of the present invention, when the context awareness module extracts the code target context information of the target source code, it includes:

[0083] Obtain static context information, dynamic context information, and code semantic information of the target source code.

[0084] Based on static context information, dynamic context information and code semantic information, the target context information of the generated code is extracted.

[0085] Figure 2 An embodiment of extracting target context information of generated code by the context-aware module is also shown. In the figure, when extracting target source code context information, it is necessary to perform static analysis, dynamic analysis and semantic understanding on the target source code. After static analysis on the target source code, the static context information of the target source code can be obtained; after dynamic analysis on the target source code, the dynamic context information of the target source code can be obtained; after semantic understanding on the target source code, the code semantic information of the target source code can be obtained. Thereafter, based on the static context information, dynamic context information and code semantic information, the target context information of the generated code is extracted.

[0086] Specifically, static context information refers to structural information that can be extracted from the target source code through static analysis tools (such as AST analysis, type checking, etc.) when the target source code is not running, such as function call relationships, type inference, dependencies, etc. Static context information may include the grammatical structure of the code (such as the definition of functions, variables, classes, and modules), control flow (such as loops, conditional statements), and dependencies (such as import relationships between modules and libraries).

[0087] When the target source code is PHP-like code, an example of extracting static context information may be:

[0088] import math

[0089] def calculate_area(radius):

[0090] return math.pi*radius**2

[0091] In the above example, the dependency of the math library, the definition and return value of the function calculate_area can be extracted. It can be seen that the dependency of the math library, the definition and return value of the function calculate_area are the corresponding static context information. It should be noted that the corresponding development behavior can be one of the above mentioned. The method of extracting the static context information corresponding to the target source code can refer to the example here, which is explained one by one here.

[0092] Dynamic context information is information collected when the target source code is running, reflecting the state of the code at the current runtime (such as variable values, function calls, etc.), usually including runtime variable values, call stack, execution path, function call order, variable value changes, thread activity and exception handling, etc.; generally, the collection of dynamic context information corresponding to the runtime behavior is achieved through instrumentation technology, debugging tools or runtime monitoring tools to collect runtime behavior, such as variable values, running paths, exception handling, etc.; dynamic context information can generally include the stack information of the current code execution (such as function call stack), the actual value of the variable and its state at runtime and / or the program execution path.

[0093] When the target source code is PHP-like code, an example of extracting dynamic context information may be:

[0094] radius=5#The dynamic context can extract the runtime value of radius to be 5

[0095] calculate_area(radius)

[0096] In the above example, when the target source code is running, the dynamic context will capture radius=5. Specifically, the extracted dynamic context information is radius=5. It should be noted that the corresponding development behavior can be one of the above-mentioned ones.

[0097] It should be noted that when extracting static context information, it is extracted directly from the source code through static analysis tools without running the code. Extracting dynamic context information needs to be collected during the operation of the target source code, such as through manual debugging of the code by the developer, or automatically collected by running code snippets in the background of the IDE environment.

[0098] Code semantic information is the meaning of the target source code that can be extracted through natural language processing (NLP) technology to understand the business logic of the target source code. The understood business logic of the target source code usually comes from comments, documents, and variable and function names in the target source code. The code semantic meaning can generally include the intention description in the comments (such as "this function is used to calculate the area of ​​a circle") and / or the semantics revealed by the variable and function names (such as calculate_area indicates that this is a function used to calculate the area).

[0099] When the target source code is Python class code, an example of extracting code semantic information is:

[0100] #Calculate the area of ​​the circle

[0101] def calculate_area(radius):

[0102] return math.pi*radius**2

[0103] In the above example, the business purpose of the function (calculating the area of ​​a circle) is extracted from the comments of the target source code, and the semantics of the code is inferred based on the function name, parameter name, etc.

[0104] As can be seen from the above description, when code target context information can be generated based on static context information, dynamic context information and code semantic information, the system generates a context model based on static, dynamic and semantic information, such as Figure 2 As shown, it should be noted that Figure 2 The context model in is a dynamically generated abstract model. It is not a fixed entity built through training, but is updated in real time according to the development behavior. That is, it integrates static context information, dynamic context information and code semantic information to fully understand the status, operation status and business logic of the current target source code. The integration here can be to associate static context information, dynamic context information and code semantic information with each other, which can be regarded as the overall code development information corresponding to the current development behavior.

[0105] The abstract context model integrates static context information, dynamic context information, and code semantics in a new example: through static context information, it can be determined that calculate_area is a function that depends on the math library. At the same time, dynamic context information can determine that the value of radius at runtime is 5. Through code semantic information, this function is used to calculate the area, which may involve mathematical formulas. Through the example information, when the developer enters the calculate_area function, it is recommended to automatically complete the value of radius and ensure that the completed code conforms to the current business logic and running status.

[0106] In one embodiment of the present invention, when extracting code target context information of a target source code using a context awareness module, the target source code is firstly subjected to code optimization preprocessing to generate target source code preprocessing information after the code optimization preprocessing;

[0107] Code optimization preprocessing of the target source code includes code parsing processing and / or behavior parsing processing, wherein:

[0108] When performing code parsing processing on the target source code, code body information of the target source code is extracted, wherein the code body information at least includes syntax information of the target source code and structure information of the target source code;

[0109] When performing behavior analysis processing on the target source code, development interaction information in the integrated development environment is analyzed to generate code behavior information based on the analyzed development interaction information, wherein the code behavior information includes an interaction operation sequence and interaction context information;

[0110] Based on the target source code preprocessing information, the context-aware module extracts the code target context information, where:

[0111] Performing static analysis and capturing of code body information of the target source code to generate static context information after static analysis and capturing;

[0112] Dynamic analysis is performed on code behavior information of the target source code to generate dynamic context information after dynamic analysis and capture.

[0113] In order to effectively obtain the code target context information, the target source code should be preprocessed for code optimization, that is, the target source code needs to be preprocessed; after the target source code is preprocessed, the target source code preprocessing information can be generated. Code optimization preprocessing can include code parsing and behavior parsing, that is, when the target source code is preprocessed for code optimization, the main focus is on extracting the subject information of the target source code, and more attention is paid to the grammatical information and structural information of the target source code. Figure 3 An embodiment of code optimization preprocessing is shown in the figure. As can be seen from the figure, the code optimization preprocessing of the present invention may include code parsing processing and behavior parsing processing. The method and process of code optimization preprocessing are specifically described below.

[0114] During specific implementation, when the target source code is parsed, the code body information of the target source code can be extracted. When the code body information is extracted, a feasible solution may be: using a static analysis tool to parse the target source code. Specifically, after parsing the target source code, an abstract syntax tree (AST) of the target source code may be generated. Thereafter, the syntax information of the target source code and the structural information of the target source code may be extracted based on the generated abstract syntax tree. Based on the syntax information of the target source code and the structural information of the target source code, the code body information of the target source code may be generated.

[0115] Specifically, the grammatical information involves the grammatical rules and structures of the target source code, including the use of keywords, operators, statements, expressions, etc., such as the following code:

[0116] if condition:

[0117] #dosomething

[0118] In the above code examples, if is the keyword of the conditional statement, and condition is the conditional expression.

[0119] The structural information of the target source code involves the overall organization and hierarchical relationship of the target source code, including the relationship between modules, classes, functions, and variables, and how they depend on and call each other, such as the following code:

[0120] import math

[0121] class MyClass:

[0122] def my_method(self):

[0123] pass

[0124] In the above code example, MyClass is the class name, my_method is a method in the class, indicating the structural information of the class, and the current code depends on the math module, which illustrates the structural relationship between modules.

[0125] When the target source code is subjected to behavior analysis, code behavior information can be generated. When the code behavior information is generated, a feasible solution may be: analyzing the development interaction information when the developer develops the target source code in an integrated development environment, the analyzed development interaction information includes the interaction operation sequence when developing the target source code, and the interaction context information during the interaction. Thereafter, the corresponding code behavior information may be generated according to the interaction operation sequence and the interaction context information; wherein, the interaction operation sequence refers to a series of specific operations (such as inserting code, deleting code, debugging, submitting, etc.) performed by the developer when writing, debugging, and refactoring the code; and the interaction context information refers to the code context when the developer performs these operations, including environmental information such as the current function, variable, and running status.

[0126] Based on the code body information and the code behavior information, target source code preprocessing information may be generated, and thereafter, context capture and understanding are performed on at least the target source code preprocessing information to generate code target context information, such as Figure 4 As shown. Specifically, when performing context capture and understanding, the code body information can be statically analyzed and captured to generate static context information after static analysis and capture. When performing static analysis and capture on the target source code preprocessing information, existing commonly used static analysis tools can be used, such as static analysis tools Clang or static analysis tools Pylint. It should be noted that when performing static analysis and capture on the code body information, the abstract syntax tree and dependency relationship of the target source code are mainly parsed. In addition, the abstract syntax tree of the target source code can also be generated using static analysis tools.

[0127] Specifically, the code body information of the target source code provides the static structure basis of the target source code, such as the definition of the calculate_area function and its dependency on the math library mentioned in the above description; through static analysis tools, the system can extract the definition and dependency of the function, and identify how the function depends on external modules (such as the math library); the code behavior information describes the interactive behavior of the developer when operating these static structures; when the code body information is combined with the code behavior information, the context can be better understood to obtain the corresponding static context information.

[0128] It can be seen from the above description that when the target source code preprocessing information is statically analyzed and captured, the static information refers to various structural, grammatical and dependency information extracted from the target source code by the static analysis tool. The information can be directly obtained from the target source code when the target source code is not running (i.e., in a static state). Generally, the static information may include: 1) grammatical structure information; 2) type information; 3) dependency information; 4) control flow information; 5) symbol table information; 6) namespace and scope information; 7) constant and literal information; 8) comment information, wherein the comment information is generally non-essential static information; based on the above static information, the code grammatical structure, control flow, and dependency relationship in the static context information can be formed, such as the code grammatical structure of the above static context information may include 1) grammatical structure information, 2) type information and 5) symbol table information, the control path may include 4) control flow information and 6) namespace and scope information, the dependency relationship may include 3) dependency information and 7) constant and literal information, and here, the comment information may form additional static information.

[0129] In the above description, type information refers to the type definitions of various variables, functions, parameters, return values, etc. in the target source code. This information helps understand the nature of the data and how to operate on the data. Dependency information describes the dependencies between modules, classes, and functions in the target source code, including references to external libraries and calls to internal modules. This information helps understand the structure and coupling of the target source code. Control flow information describes the execution flow of the program, including conditional statements, loops, jumps, etc. This information helps understand the execution path of the target source code.

[0130] Symbol table information includes several symbol tables. A symbol table is a data structure used to store the names of identifiers such as variables, functions, and classes and their attributes (such as type, scope, address, etc.). It helps analysis tools track the definition and usage of identifiers. Namespace and scope information describes the namespace and scope of identifiers (such as variables, functions, and classes) in the code, helping to understand their visibility and life cycle. Constant and literal information refers to constants and literal values ​​defined in the target source code. This information provides fixed values ​​in the code, such as numbers, strings, Boolean values, etc.

[0131] The code behavior information of the target source code is dynamically analyzed and captured, so that dynamic context information can be generated after dynamic analysis and capture. When performing dynamic analysis and capture, the code behavior information can be dynamically analyzed using existing commonly used dynamic analysis tools, such as the dynamic analysis tool Dynatrace or the dynamic analysis tool JProfiler. It should be noted that the dynamic analysis and capture of the code behavior information mainly collects the data and behavior of the target source code at runtime, that is, analyzes the interactive operation sequence and interactive context information in the code behavior information. In addition, during code optimization preprocessing, the target source code can also be analyzed using dynamic analysis tools. The method and process of using dynamic analysis tools to analyze the target source code can be consistent with the existing ones, which will not be repeated here.

[0132] In specific implementation, the code behavior information of the target source code is dynamically analyzed and captured, and the data and behavior of the target source code at runtime can also be collected through instrumentation technology and runtime monitoring. Among them, instrumentation technology specifically refers to inserting additional instructions (probes) into the target source code to monitor the execution process of the program, such as function calls, variable changes, etc., such as using the Java Instrumentation API to insert code to record execution time at the method entry, or generating a gprof performance analysis report through GCC instrumentation; runtime monitoring specifically refers to real-time monitoring of program runtime status information, such as memory usage, thread activity, system calls, etc., such as using JVM tools to monitor the memory and thread status of Java applications, or recording system calls of Linux programs through strace.

[0133] The dynamic context information generated above is used to help understand the actual running behavior of the program. The content of the dynamic context information can be selected according to actual needs, so as to achieve auxiliary optimization of the target source code.

[0134] It can be seen from the above description that when generating code target context information, the code semantic information of the target source code should also be obtained. When obtaining the code semantic information of the target source code, the code comments and documents of the target source code can be analyzed to understand the business and development logic intentions of the target source code. In specific implementation, when obtaining the code semantic information of the target source code, a feasible solution is to use the NLP method to analyze the code comments and documents of the target source code to generate code semantic information after analysis. It should be noted that the NLP method is a natural language processing technology specially customized for natural languages ​​(such as comments and documents) in programming environments and can be optimized. It can help understand the business and development logic intentions of the target source code based on the comments and documents contained in the target source code and the context of the target source code, so that code semantic information can be generated based on the understood business and logical intentions. The method and process of generating code semantic information using the NLP method can be consistent with the prior art and will not be repeated here.

[0135] The following is an example of the process of obtaining the code semantic information of the target source code, specifically:

[0136] Annotation documentation for analysis classes in java code

[0137] / **

[0138] *User account management class.

[0139] *Responsible for handling user registration, login and account information update.

[0140] *Main methods include: register(), login(), updateProfile()

[0141] * /

[0142] public class UserAccountManager{

[0143] / / ...

[0144] }

[0145] From the above description, we can see that the process of obtaining code semantic information includes:

[0146] 1) Text extraction: extract the content from Java comments.

[0147] 2) NLP analysis: Identify “registration”, “login”, and “account information update” as core business operations.

[0148] 3) Entity recognition: Identify register(), login(), and updateProfile() as method names.

[0149] 4) Intent inference: The system understands that this class is used to manage user accounts and associates these operations with corresponding methods.

[0150] In summary, by combining NLP technology, we can analyze the comments and document content in the target source code and understand the business logic and developer intentions behind the target source code. This process, from text extraction, language processing to semantic analysis, ultimately generates a comprehensive semantic model to help better understand and optimize the code.

[0151] Depend on Figure 2 It can be seen that after obtaining static context information, dynamic context information and code semantic information, the code target context information can be generated through the context model in the context-aware module. The context model generates the code target context information by describing the current state, structure and development background of the target source code. It can be seen that the generated target code context information can represent the global and local conditions of the target source code.

[0152] It can be seen from the above description that when extracting the code target context information of the target source code, a variety of tools (such as the static analysis tools and dynamic analysis tools mentioned above) are used to capture the structural information of the target source code, and the global changes of the target source code are understood by analyzing the version control history of the target source code. Therefore, the target source code optimization management information can be dynamically adjusted according to the different versions, files and dependency changes of the target source code. Specifically, the different versions of the target source code refer to the different versions in the process of developing the target source code. According to the version changes of the target source code, the overall trend of the evolution of the target source code over time can be understood; text and dependency changes refer to the modification, addition or deletion of code files in the target source code. Among them, dependency changes refer to changes in the target source code's dependencies on external libraries, modules or APIs. These changes may affect the understanding of the overall architecture of the target source code.

[0153] In one embodiment of the present invention, the adaptive auxiliary management model is constructed based on a large language model.

[0154] When building an adaptive auxiliary management model based on a large language model, it at least includes a model training step, wherein:

[0155] When executing the management model training steps, including:

[0156] Constructing a management model training data set, wherein the management model training data set includes a plurality of training samples;

[0157] Constructing an adaptive auxiliary management basic model based on a large language model, and using the management module training data set to perform model training on the adaptive auxiliary management basic model;

[0158] When the model training of the adaptive assisted management basic model reaches the target state, an adaptive assisted management model is formed based on the adaptive assisted management basic model.

[0159] In specific implementation, the adaptive auxiliary management model can be generated based on the large language model (LLM). The large language model can adopt the existing commonly used form, such as the GPT-4 model or the Codex model. The type of large language model adopted by the adaptive auxiliary management model can be selected according to actual needs. When the GPT-4 model or the Codex model is selected, since the GPT-4 model and the Codex model already have the ability to generate code, it is usually not necessary to improve the GPT-4 model and the Codex model. It can be understood that when the adaptive auxiliary management model is constructed based on the large language model, the adaptive auxiliary management basic model should be constructed based on the large language model adopted. After that, the adaptive auxiliary management basic model is trained, so that after the model training of the adaptive auxiliary management basic model reaches the target state, the adaptive auxiliary management basic model after the model training reaches the target state can be configured as the adaptive auxiliary management model.

[0160] When training the model of the adaptive auxiliary management basic model, the model training step is executed. When executing the model training step, it is necessary to first construct a management model training data set. Generally, the management model training data set includes a number of training samples. The method and process of constructing the management model training data set are specifically described below.

[0161] In one embodiment of the present invention, when constructing a model training data set, it includes:

[0162] Collecting training data, wherein any collected training data at least includes a training source code and source code interaction information corresponding to the training source code;

[0163] Performing training data preprocessing on each of the training data collected above to generate preprocessed training data after the training data preprocessing;

[0164] Context understanding and capture processing is performed on each of the pre-processed training data to generate training samples after the context understanding and capture processing, wherein the training samples include training source code context information.

[0165] It should be noted that when collecting training data, multiple training data should generally be collected, among which the multiple training data should include large-scale code libraries in different programming languages, that is, the collected multiple training data should contain multiple programming examples and patterns; the training data generally includes at least the training source code and the source code interaction information of the training source code development process. The following is a specific description of the collection method and process of the training source code and source code interaction information in the training data.

[0166] Specifically, general training source code mainly comes from open source code platforms such as GitHub and GitLab, which have a large number of open source projects covering various programming languages, frameworks and application fields; customized standard training source code generally comes from the company's own enterprise code base. From the above description, it can be seen that the training source code should contain various programming paradigms and pattern requirements, among which programming paradigms and pattern requirements may include but are not limited to the following: design patterns: such as singleton pattern, factory pattern, observer pattern, etc.; common algorithms and data structures: sorting algorithms, search algorithms, trees, graphs, linked lists, etc.; typical programming paradigms: such as object-oriented programming (OOP), functional programming, event-driven programming, etc.

[0167] It is understandable that when the training source code contains multiple programming paradigms and pattern requirements, different code types can be covered to ensure that the model has a wide range of knowledge and skills so that it can provide accurate and relevant code completion and optimization suggestions in practical applications.

[0168] When collecting training source code, a feasible collection method is:

[0169] Step 1: Define the scope of collection

[0170] Specifically, determine the programming languages ​​and application fields to be collected. For example, you can choose mainstream programming languages ​​such as Java, Python, C++, and cover different fields such as Web development, mobile application development, and embedded systems. The definition of the collection scope can be determined according to actual needs.

[0171] Step 2: Get the source code;

[0172] Specifically, use crawler technology or API calls to automatically download project codes from platforms such as GitHub and Bitbucket. For example, you can use the GitHub API to obtain popular repositories in a certain language or filter by keywords; use code static analysis tools (such as Clang, Javaparser) to automatically identify and annotate examples and patterns in source code.

[0173] Step 3: Data cleaning and classification;

[0174] Specifically, the collected source code is cleaned to remove irrelevant files (such as README, test files) and comments to ensure the purity of the source code;

[0175] The codes were categorized according to predefined paradigms and patterns, ensuring that each category had sufficient representation and numbers.

[0176] Step 4: Storage and indexing;

[0177] Specifically, the organized code data is stored in an efficient database (such as PostgreSQL, MongoDB), and indexes are created to facilitate fast retrieval and analysis; thereby, the collection and storage of training source code can be achieved.

[0178] In specific implementation, the collection method shown above is adopted. For example, the keyword "singleton pattern Java" can be used to search on the GitHub platform, so that the project code containing the singleton pattern implementation can be obtained after the search. These project codes will be classified and stored in the database to facilitate the adaptive auxiliary management model to learn how to identify and generate singleton patterns in Java.

[0179] For modular project codes used by complex systems, for example, a large open source project (such as Apache Hadoop) is selected, and the code snippets of its modular design and cross-module calls are extracted. These codes will be used to train the adaptive auxiliary management model on how to handle complex system architectures. Specifically, when extracting code snippets of modular design and cross-module calls, the code snippets need to be judged mainly based on the following criteria:

[0180] 1) Clear module boundaries: whether the internal logic and functions of the module are independent.

[0181] 2) Cross-module calls: whether the code reflects the dependencies and communications between modules.

[0182] 3) Complex system architecture: Does the code demonstrate the complexity and abstraction level of the system architecture?

[0183] 4) Code complexity and typicality: whether the code demonstrates complex logic and typical architectural patterns.

[0184] In specific implementation, when the above judgment criteria are met, the corresponding code snippets should be extracted. It can be seen that the above criteria are helpful in extracting code snippets suitable for training adaptive auxiliary management models, and helping the model understand and process key designs and call logic in complex system architectures. It should be noted that the meaning of the above-mentioned judgment criteria and the method of extracting code snippets according to the judgment criteria are consistent with the existing technology and will not be repeated here.

[0185] Furthermore, the source code interaction information in the training source code specifically refers to the developer's operation interaction data during the process of developing the training source code. The operation interaction data generally may include code writing interaction data, modification interaction data, debugging interaction data and / or submission interaction data. The type of source code interaction information can be selected according to actual needs.

[0186] For source code interaction data in training source code, a feasible collection method is:

[0187] Step 10: Design pattern collection:

[0188] Specifically, the pattern collection can be designed according to the development mode of the training source code, and the collection can be an IDE plug-in or extension collection, or a log record collection, wherein,

[0189] IDE plug-in or extension: Develop and deploy an IDE plug-in or extension that can monitor and record the developer's operations in real time. This plug-in can be installed in the integrated development environment commonly used by developers (such as Visual Studio Code, IntelliJ IDEA, Eclipse, etc.). In specific implementation, the IDE plug-in / extension can be developed and deployed using the technical means commonly used in the technical field of this technology, and the specific implementation is based on the ability to monitor and record the developer's operations during the development and training of the source code. That is, for different IDEs, develop corresponding IDE plug-ins / extensions. Taking Visual Studio Code as an example, its API can be used to monitor the user's keystrokes, file saving and debugging operations.

[0190] Logging: Operation records can be stored locally on the developer's machine and uploaded or synchronized to a central server during idle time periods. This approach can reduce the latency caused by real-time transmission.

[0191] Step 11: Define the specific content collected

[0192] As can be seen from the above description, the collected content may include code writing, code modification, code debugging or code submission; specifically,

[0193] Code Writing: Records every keystroke, insertion and deletion, and cursor movement in the IDE editor, including timestamps, code changes, and locations.

[0194] Code modification: records each save, refactor, cut, and paste operation, including: the specific modified code snippet, the context of the modification, and the complete status of the modified code.

[0195] Debugging behavior: records the breakpoints set during debugging, the execution steps (such as single-step execution, entering a function, skipping, etc.), the observed variables and their value changes, the captured exceptions, and other debugging-related data.

[0196] Code commit: Records the commit information each time the code is submitted to a version control system (such as Git), including the time of the commit, the files involved, the difference (diff), and the content of the commit information.

[0197] It can be seen from the above description that, according to the collected specific content definition, the preset code auxiliary management behavior can be determined, so as to define the situation that triggers the code completion optimization management model to assist in optimizing the target source code.

[0198] Step 12: Collection of source code interaction data

[0199] Based on the configurations of steps 10 and 11 above, source code interaction data is collected and the collected operation records are formatted into a standardized data structure, such as JSON or XML, for subsequent processing and analysis. Each operation record should contain a timestamp, operation type, operation details, file name, and related code snippets.

[0200] For source code interaction data collected through log recording, when online, the collected log data can be uploaded to the server in real time; when offline, the log will be automatically synchronized after reconnecting to the network. To ensure data security, the upload process can use encrypted transmission protocols (such as HTTPS).

[0201] On the server side, the collected data can be cleaned to remove noise and irrelevant records to ensure the accuracy and relevance of the data. The cleaned data is then stored in the database for subsequent use.

[0202] Specifically, an example of collecting source code interaction data is: in the Eclipse IDE, when collecting interactive data on code writing behavior, a plug-in is used to assist in monitoring the developer's keystrokes. For example, when the developer types an "if" statement, the plug-in records the location of the "if", the context code, and a timestamp. This information is packaged into JSON format and uploaded to the server.

[0203] If the above-mentioned training source code is the source code optimized by the large language model, source code feedback data should also be collected. The source code feedback data specifically refers to the feedback information on code completion and / or suggestions when optimized by the large language model. It can be seen that the source code feedback data may include accepted operation records, modified operation records or rejected suggestion operation records.

[0204] The collection of source code feedback data may include:

[0205] Step 20: Configure source code feedback data collection method

[0206] Specifically, source code feedback data collection may include IDE plug-in monitoring collection, user interface interaction data, and automatic log record collection, among which:

[0207] IDE plug-in monitoring: By developing IDE plug-ins, real-time monitoring is performed on developers when they receive, modify, or reject code completion suggestions. These operations include using auto-completion suggestions, modifying generated code snippets, or directly deleting unnecessary suggestions. In specific implementation, the developed IDE plug-in should also be able to record related operations when developers accept, modify, or reject code completion suggestions. Taking Visual Studio Code as an example, the IDE plug-in can monitor the developer's operations on the code completion suggestion panel and record each selected suggestion.

[0208] User interface interaction: Within the IDE, feedback options are provided that allow developers to clearly mark which suggestions are helpful and which are unnecessary; developers can provide feedback with a simple button click or shortcut key, and this information will be automatically recorded and transmitted.

[0209] Automatic logging: The IDE can automatically record every action taken by the developer, including details of accepting, modifying, or rejecting code completion suggestions. These logs are regularly collected and sent to the server for analysis.

[0210] When collecting source code feedback data, in addition to recording the above operations, you should also record relevant information, specifically:

[0211] Acceptance record: When a developer accepts a code completion suggestion provided by LLM and uses it directly, this operation is recorded, including the time of acceptance, the content of the suggestion, the context in the source code, etc. A corresponding example may be: when a developer is writing a Python function, LLM automatically completes a commonly used code snippet (such as a for loop). The developer directly accepts this suggestion and continues to write code. The plug-in records this operation, including the time of acceptance, the suggested code snippet, and the context information of the current file.

[0212] Records of modification suggestions: If the developer accepts a suggestion but then makes a modification, it is necessary to record the corresponding code snippets before and after the modification to analyze why the suggestion does not fully meet the requirements. This record helps to adjust the adaptive auxiliary management model and improve future suggestions. A corresponding example is: LLM suggests a SQL query statement, but the developer modifies the generated query condition part. The plug-in records the developer's modification behavior, including the original suggestion and the modified code. Through these records, LLM can learn preferences in specific situations and improve future suggestions.

[0213] Recording of rejected suggestions: When a developer deletes or ignores a suggestion, this action is recorded and possible reasons are tried to be analyzed, such as context mismatch or logic errors in the suggestion. A corresponding example is that LLM provides a code refactoring suggestion, but the developer chooses to ignore it and continue writing the original method. The plugin records this behavior, including the developer's ignore action and the reason (if the developer provides a reason). This data helps LLM identify when similar suggestions should be avoided.

[0214] In specific implementation, the source code feedback data collected above needs to be formatted and stored after data formatting. The collected feedback data can be standardized into a structured log file, and the format can be JSON or XML. Each record should include timestamp, operation type, code context, suggestion content, modification content and other information.

[0215] In addition, the collected logs can be uploaded to the central server regularly for LLM to analyze. Through these logs, LLM can identify which suggestions are frequently accepted or rejected, thereby optimizing its generation strategy. LLM updates its model in real time based on the analysis results and reflects these improvements in future code completions and suggestions. This feedback loop helps the model to continue to evolve and gradually improve the accuracy and practicality of code suggestions.

[0216] It can be seen from the above description that when the code completion optimization management model is triggered to assist in optimizing the target source code, it is mainly based on whether the development behavior for the target source code matches the preset code assistance management behavior. Therefore, after collecting the source code, each collected source code needs to be segmented and processed to form the required training source code and the source code interaction information corresponding to the training source code; wherein, the training source code and the corresponding source code interaction information formed by segmentation specifically refer to the code and source code interaction behavior that require code completion or optimization suggestions.

[0217] It can be seen from the above description that the training data may include training source code, source code interaction information and source code feedback data. Therefore, when performing training data preprocessing on the training data, it specifically refers to performing corresponding preprocessing on the training source code, source code interaction information and source code feedback data respectively. Among them, the training data preprocessing of the training source code specifically refers to performing code parsing on the training source code through a static analysis tool, generating an abstract syntax tree of the training source code, and extracting the grammatical information and structural information of the training source code. For the training data preprocessing of the training source code, please refer to the above-mentioned code parsing processing instructions for the target source code.

[0218] When preprocessing the training data of source code interaction information, the main focus is to analyze the developer's interactive behavior, extract the operation sequence and context information, so as to understand the developer's intention and provide targeted suggestions. The training data preprocessing method for source code interaction information may include extracting operations and constructing sequences, extracting context information, and analyzing behavior patterns.

[0219] When performing an extraction operation and building a sequence step, include:

[0220] 1) Operation identification: Identify the developer's specific operations, such as "function definition", "variable declaration", "debugging step", etc.

[0221] 2) Sequence construction: Organize these operations into sequences in chronological or logical order to reflect the developer's behavior process.

[0222] When executing the step of extracting context information, it includes:

[0223] 1) Current editing context: records the type, location and other information of the currently edited file;

[0224] 2) Historical operation context: Track all operations in the current session and identify the continuity of operations.

[0225] 3) Global context: Analyze the overall structure of the project, such as file dependencies and class inheritance relationships.

[0226] When performing the behavioral pattern analysis steps, include:

[0227] 1) Pattern recognition: Analyze operation sequences and context information to identify behavioral patterns (such as code refactoring and debugging).

[0228] 2) Intent inference: Infer the developer’s intention based on operations and context, and provide corresponding suggestions.

[0229] When any training data includes source code feedback data, the training data of the source code feedback data is preprocessed, and the correct completion suggestions or incorrect completion suggestions are marked. Among them, the correct completion suggestion means that the developer basically recognizes the code completion or optimization suggestion provided by LLM and accepts it or makes minor adjustments to it; the incorrect completion suggestion means that the developer rejects, significantly modifies, or does not use the suggestion provided by LLM at all, which indicates that the suggestion fails to meet the developer's needs or deviates from expectations.

[0230] The training data collected above are preprocessed to generate preprocessed training data. The method and process of preprocessing the training data can refer to the method and process of preprocessing the target source code, which will not be repeated here.

[0231] In specific implementation, each of the above pre-processed training data is subjected to context understanding and capture processing to generate training samples after the context understanding and capture processing. Specifically, the context awareness module can be used to perform context understanding and capture processing, from which it can be seen that the generated training samples include code training context information. In addition, the training samples can also include other forms, such as: 1) fragments from the original code library (original code that has not been completed); 2) manually annotated high-quality code fragments; 3) completed code automatically generated by the system.

[0232] The above shows the method of constructing the training data set. After the training data set is constructed, the model training conditions for the adaptive assisted management basic model should also be configured, where the configured model training conditions may include loss function (LossFunction), learning rate (Learning Rate), batch size (Batch Size), number of training rounds (Epochs) and weight initialization (Weight Initialization). The model training conditions are described in detail below.

[0233] The loss function is used to measure the difference between the code completion suggestions generated by the adaptive auxiliary management basic model during the training process and the actual code. By minimizing the loss function, the adaptive auxiliary management basic model can gradually optimize the parameters and generate more accurate completion optimization results. In one embodiment of the present invention, the loss function can use cross-entropy loss (Cross-Entropy Loss). The cross-entropy loss can measure the difference between the probability distribution generated by the model and the actual target distribution, and then:

[0234]

[0235] Among them, L cross-entropy is the cross entropy loss value, y_ iis the i-th character or word, P(y_ i |x) is the probability of the i-th character predicted by the adaptive auxiliary management basic model, and x is the input code context.

[0236] Specifically, the input code context x refers to the code snippet and its surrounding environment that the adaptive auxiliary management basic model relies on when generating code completion suggestions. This includes the grammatical structure of the code, variable definitions, function calls, dependencies between classes and modules, and even comments and documentation in the code, all of which provide information about the current code logic and help the model predict the next character or code snippet.

[0237] The learning rate determines the magnitude of the weight adjustment of the adaptive assisted management basic model at each parameter update. If the learning rate is too large, the adaptive assisted management basic model may skip the optimal solution; if the learning rate is too small, the training convergence is too slow. The learning rate is usually set between 1e-4 and 1e-5, and the specific value can be tuned through experiments. The batch size determines the number of training samples input into the adaptive assisted management basic model during each training. A larger batch size will increase the computational stability but occupy more memory; a smaller batch size can speed up the training but may cause unstable gradient updates. Generally, the batch size is often set to 32, 64, or 128, and the specific value depends on the computing resources and task complexity.

[0238] The number of training rounds determines how many times the model performs complete iterations on the entire training data set. More training rounds can help the adaptive assisted management basic model learn more fully, but too many rounds may lead to overfitting. The number of training rounds is usually set to 10 to 50 epochs, depending on the size and complexity of the training data set. Early Stopping technology can be used to automatically terminate training when the performance of the adaptive assisted management basic model no longer improves.

[0239] At the beginning of training, it is necessary to set the initial weight value for the adaptive auxiliary management basic model. Good weight initialization can speed up the convergence of the model and avoid falling into a bad local optimum. Common weight initialization methods can be Xavier initialization or He initialization. The weight initialization method can be selected according to needs.

[0240] It can be understood that after configuring the above-mentioned model training conditions, the training data set can be used to perform model training on the adaptive assisted management basic model until the model training of the adaptive assisted management basic model reaches the target state, such as the training discussion of the adaptive assisted management basic model reaches a preset number of training rounds, etc. The termination condition of the training can be selected and determined according to actual needs.

[0241] In one embodiment of the present invention, after the code completion optimization management model is integrated into the integrated development environment, at least the adaptive auxiliary management model is dynamically adjusted based on the adaptive learning method, wherein:

[0242] The adaptive learning method includes an incremental learning method and / or an online learning method;

[0243] When dynamically adjusting the adaptive auxiliary management model based on the incremental learning method, it includes:

[0244] In the integrated development environment, collecting auxiliary management feedback information, wherein the auxiliary management feedback information includes accepted operation information, modified operation information or rejected operation information;

[0245] Fine-tuning training is performed on the adaptive assisted management model based on the assisted management feedback information, so as to dynamically adjust the adaptive assisted management model based on the fine-tuning training.

[0246] It should be understood that the code completion optimization management model generated by the above training can be used as the initial model. Thereafter, the initial model can be adaptively learned and dynamically adjusted. During the dynamic adjustment, it can be adjusted through incremental learning methods or online learning methods. The incremental learning method specifically means that during the developer's use, the initial model will receive the developer's feedback in real time (such as accepting, modifying or rejecting completion suggestions), and will be continuously updated and optimized through the incremental learning algorithm without the need to retrain the entire model from scratch.

[0247] In specific implementation, when the incremental learning method is adopted, the learning samples are the auxiliary management feedback information of the developer in actual operation, that is, the feedback data of the developer in actual operation. It can be understood that the auxiliary management feedback information needs to be collected in the actual operation in the integrated development environment. The following is an example of the way to collect and form the auxiliary management feedback information.

[0248] Specifically, when collecting and forming auxiliary management feedback information, the integrated development environment will record the developer's feedback on the completion suggestion, such as acceptance, modification or rejection; each completion suggestion feedback is used as an incremental learning basic sample, and the incremental learning basic sample is preprocessed to form an incremental learning sample. When preprocessing the incremental learning basic sample, it includes extracting the code context and identifying the difference between the completion suggestion and the developer's operation. Among them, identifying the completion suggestion is the above-mentioned acceptance suggestion, modification suggestion or rejection suggestion.

[0249] After the incremental learning samples are formed in the above way, the initial model is adaptively learned, such as Figure 5As shown, when the initial model is incrementally learned using incremental learning samples, fine-tuning of the initial model can be achieved, wherein the fine-tuning is to use incremental learning samples for small updates instead of large-scale retraining, and by updating the parameters of the adaptive assisted management model, the adaptive assisted management model can be more adapted to the personalized needs of developers.

[0250] In one embodiment of the present invention, fine-tuning the initial model includes:

[0251] Prepare incremental learning samples and perform preprocessing;

[0252] Select specific model layers for small parameter updates;

[0253] Define a loss function to measure the difference between the model output and the actual feedback;

[0254] Adjust model parameters and use optimization algorithms to gradually fine-tune the model over multiple iterations;

[0255] Verify and test the fine-tuning effect to ensure that the model's completion suggestions better meet the developer's personalized needs.

[0256] Specifically, when the incremental learning samples are preprocessed, the incremental learning samples are converted into input data suitable for fine-tuning the adaptive auxiliary management model. The preprocessing mainly includes:

[0257] Extract code context: Analyze the context of the current code, including functions, classes, and dependencies;

[0258] Identify the differences between completion suggestions and developer operations: record the developer's feedback on completion suggestions and compare the differences before and after the modification;

[0259] Standardized data format: ensure that the samples meet the input format requirements of the model;

[0260] Remove redundant or invalid data: clean up irrelevant or invalid information;

[0261] Feature extraction: Extract key features from the code so that the model can learn and optimize better.

[0262] It can be understood that the above preprocessing steps ensure that the incremental learning samples can provide accurate and structured information for the model, helping the model to better fine-tune and optimize; the corresponding processing methods in the preprocessing can adopt existing commonly used technical means to meet the needs of model fine-tuning.

[0263] It should be noted that in the process of fine-tuning or incremental learning, specific model layers usually include: 1) output layer, where the output layer is a network layer that outputs target source code optimization management information; 2) intermediate hidden layer, where the intermediate hidden layer is a layer responsible for context capture and semantic understanding; 3) word embedding layer: where the word embedding layer is a layer used to convert code symbols into vectors to help the model understand new inputs; 4) self-attention layer, where the self-attention layer is used to capture dependencies and contexts between codes; 5) feedforward neural network layer, where it is used to process complex features; 6) normalization layer, where the data is standardized to ensure model stability.

[0264] In specific implementation, when fine-tuning the model, one or more of the above-mentioned specific model layers may be selected to update parameters in a small range, wherein the process of updating parameters is mainly carried out through the following steps:

[0265] 1) Loss function calculation: measures the difference between the model output and the target value.

[0266] 2) Gradient calculation: The gradient is calculated through the back propagation algorithm.

[0267] 3) Parameter update: adjust the weights and biases of the model through gradient descent or other optimization algorithms, and update them at a certain learning rate.

[0268] 4) Selecting updated layers: Specific layers can be selectively updated while freezing other layers to reduce the amount of computation and retain the knowledge of the original model.

[0269] In one embodiment of the present invention, the loss function is calculated mainly based on the difference between the completion suggestion and the actual feedback, and is defined in the following ways:

[0270] Acceptance completion: Use cross entropy loss to measure the difference between the generated results and the results actually accepted by the developer;

[0271] Modification completion: The difference between the developer's modification and the model-generated suggestion is calculated through the edit distance or mean square error;

[0272] Refusal to complete: A penalty term can be introduced to increase the loss value of refusing to complete;

[0273] Contextual consistency: Ensure that the completed code is consistent with the code environment through contextual consistency loss.

[0274] Through the definition of these loss functions, the completion suggestions can be gradually optimized during fine-tuning and incremental learning, making them more in line with the developer's personalized needs. It should be noted that the types of loss functions and calculation methods mentioned above can be consistent with the existing technology and will not be repeated here. In addition, the specific implementation methods of the above-mentioned gradient calculation, parameter update, and selection of updated layers can all be consistent with the existing technology and will not be described in detail here.

[0275] Furthermore, when adjusting model parameters, the optimization algorithms used may include Adam, SGD, momentum gradient descent, etc. When verifying and testing the fine-tuning effect, a feasible verification and testing method may include:

[0276] 1. First, use automated verification tools to ensure that the model performs well enough on large-scale data to avoid overfitting or bias; the automated verification tools can be existing commonly used verification tools, and the type and method of the verification tools can be consistent with existing technologies.

[0277] 2. Then, through user feedback, capture the personalized performance of the model in the actual development scenario, and further fine-tune and optimize it according to the needs of developers, that is, use actual usage as feedback.

[0278] When the GPT-4 model or the Codex model builds an adaptive assisted management model, the adaptive assisted management model has online learning capabilities, and can continuously adapt to the developer's coding style and needs through online learning capabilities during use.

[0279] It is understandable that when updating the adaptive auxiliary management model through online learning, it can be related to the type of auxiliary management feedback information. For example, if the auxiliary management feedback information is that a certain completion suggestion has been modified multiple times, the generation strategy will be adjusted through the gradient descent algorithm to ensure that the subsequent completion suggestions in similar situations are more in line with the developer's habits. In addition, the feedback weight is calculated based on the auxiliary management feedback information. Specifically, different weights can be assigned based on the developer's feedback frequency and operation results. For example, the weight of frequently accepted completion suggestions will be increased so that the model will give priority to generating similar completions; if a certain section of completion suggestions is modified multiple times, the system will reduce the weight of the completion mode to avoid continuing to generate completions that do not meet the developer's needs.

[0280] In one embodiment of the present invention, when the adaptive auxiliary management model is dynamically adjusted, the dynamic adjustment method includes vocabulary, generation strategy, code snippet priority, naming style parameters, library and framework preferences, code formatting parameters and / or comment generation and use parameters; specifically, through dynamic adjustment to adapt to the needs of developers, the dynamically adjusted parameters can be personalized according to the actual usage, project requirements and development style of the developer, and the behavior of the adaptive auxiliary management model can be fine-tuned to generate code completion and optimization suggestions that are more in line with the developer's habits.

[0281] Specifically, the model's vocabulary and priority are dynamically adjusted according to the developer's naming habits and common words. At this time, when generating code, the adaptive auxiliary management model will be more inclined to use the variable names, function names, and class names commonly used by developers; if the developer prefers to use short variable names (such as i, n), the weight of these words in the model will be increased, so that these names will be recommended first during code completion.

[0282] Decoding Strategy, including strategies used during generation, such as greedy search, beam search, temperature parameters, etc. Different strategies will affect the diversity and certainty of code generation. For example, for developers who prefer diverse suggestions, you can increase the temperature parameter or use beam search to generate more candidate code snippets; for developers who prefer stable and consistent suggestions, you can use greedy search to generate the most likely completion. It should be noted that the generation strategy (such as greedy search, beam search, temperature parameters, etc.) is a function pre-set by LLM when generating content.

[0283] Token Prioritization: adjusts the priority of certain code snippets during the generation process based on the code structures or snippets commonly used by developers. This ensures that the adaptive auxiliary management model prioritizes the generation of code that conforms to the developer's commonly used style. For example, if developers often use specific code templates or design patterns (such as the singleton pattern), the system will increase the priority of these structures and recommend these patterns more frequently when providing code completion suggestions.

[0284] Identify the specific style of developers in naming variables, functions, classes, etc., and use it as a priority option when generating suggestions, that is, adjust the naming style parameters (Naming Style Preferences), for example, whether to use camelCase or underscore naming (snake_case). If the developer prefers to use underscore naming, the model will give priority to this style when generating variable or function names.

[0285] According to the libraries or frameworks commonly used by developers, the model's calling method and priority for these libraries are adjusted, that is, the library and framework preferences are adjusted. At this time, when completing suggestions, the adaptive auxiliary management model will give priority to providing code suggestions related to the libraries commonly used by developers. If developers frequently use the Pandas library to process data, the adaptive auxiliary management model will tend to recommend Pandas-related functions and methods rather than other less commonly used libraries.

[0286] According to the developer's code formatting habits, adjust the formatting style of the code generated by the adaptive auxiliary management model, such as indentation, line width, blank lines and comment style, that is, adjust the code formatting parameters (Code Formatting Preferences). For example, if the developer likes to add blank lines between code blocks or use a specific comment style, the model will generate code that conforms to these formats.

[0287] According to the developer's commenting habits, adjust how the adaptive auxiliary management model handles the comment content when generating code, that is, adjust the comment generation and usage parameters (Commenting Preferences), for example, whether to generate detailed document comments or simple inline comments. If developers often use detailed document comments in the code, the adaptive auxiliary management model will tend to generate comments of a similar style.

[0288] In one embodiment of the present invention, a personalized customization optimization module is further included for performing personalized processing on the target source code optimization management information, wherein:

[0289] The personalized customization optimization module optimizes the target source code optimization management information according to a preset coding style and / or coding habit, so as to generate personalized optimization management information of the target source code after optimization;

[0290] Return the target source code personalized optimization management information to the integrated development environment.

[0291] Specifically, through personalized customization of the optimization module, the definition of rules and / or templates can be realized, where defining rules means that developers can define rules for code completion and optimization, such as code style, function call order, variable naming conventions, etc.; defining templates means that developers can customize commonly used code snippets or patterns, and these templates can be automatically inserted when needed, such as code templates and comment templates.

[0292] Code rules and templates are based on the original output of the adaptive auxiliary management model and are implemented through personalized customization and optimization modules. They are mainly externally defined content and do not need to be directly integrated into the adaptive auxiliary management model. Instead, they are applied through the output results or generation process of the adaptive auxiliary management model to apply rules or insert templates to generate personalized code that meets the needs of developers.

[0293] In specific implementation, templates can be defined by using a template engine, where developers can write template files in a specific format through a template engine (IDE plug-in or third-party tool), and these templates will be read and applied to the code completion suggestion process. In addition, developers can define rules through configuration files, such as specifying code style and calling rules through files in JSON or YAML format.

[0294] In one embodiment of the present invention, the code completion optimization management model is integrated into the integrated development environment through an IDE integrated plug-in, wherein:

[0295] The IDE plug-in is a configurable plug-in. By configuring the function of the IDE plug-in, the code completion optimization management model is adapted to the integrated integrated development environment.

[0296] Figure 6 It is shown that the integrated development environment provides an integrated interface, which can be used in conjunction with the IDE integrated plug-in to integrate the code completion optimization management model into the integrated development environment through the IDE integrated plug-in. In order to improve adaptability, in one embodiment of the present invention, the IDE integrated plug-in should be applicable to plug-ins of different IDEs (such as Eclipse, VS Code, IntelliJ) to ensure the compatibility and ease of use of the plug-in.

[0297] In order to achieve functions and purposes different from those of existing plug-ins, the IDE integrated plug-in of the present invention mainly adapts to various development environments and provides personalized code completion and optimization functions through high configuration capabilities and wide compatibility; specifically:

[0298] Existing integrated plug-ins are generally developed for specific IDEs, with relatively fixed functions and lack of flexible configuration capabilities. The IDE integrated plug-in of the present invention is configurable, allowing users to configure the functions of the plug-in according to their needs, such as making the IDE integrated plug-in configurable through common file configuration methods such as JSON, YAML, XML, etc.; wherein, the IDE integrated plug-in of the present invention provides a configuration file or configuration interface, allowing users to set code completion strategies, optimization parameters, code styles, etc. according to project requirements or personal habits. For example, developers can set the priority rules for code completion, whether to display multiple completion suggestions, whether to automatically format the code after completion, etc. in the configuration file; personalized customization is achieved through functional configuration, and developers can adjust the behavior of the IDE integrated plug-in according to the IDE and programming style they use, increasing flexibility and practicality.

[0299] Many existing integrated plug-ins can only adapt to a specific IDE, such as Eclipse or VS Code, and have weak extensibility and compatibility. The IDE integrated plug-in of the present invention is designed to be compatible with a variety of different IDEs, so that it can work seamlessly in different environments. In one embodiment of the present invention, the plug-in interface (API) of the IDE is utilized: Most modern IDEs (such as Eclipse, VSCode, IntelliJ, etc.) provide plug-in development interfaces. By using these general interfaces, the IDE integrated plug-in can obtain and operate the content in the code editor, such as obtaining the current code context, triggering completion, formatting code, etc.

[0300] In specific implementation, when developing IDE integrated plug-ins, using a cross-platform framework or tool (such as Language Server Protocol (LSP)) can help IDE integrated plug-ins run in different IDEs. For example, IDEs such as VS Code and Eclipse support the LSP protocol, which can be used to achieve unified code completion and optimization management functions to improve the compatibility and extensibility of the IDE integrated plug-in of the present invention, ensure that the IDE integrated plug-in can be applied to multiple IDEs, and avoid developers losing the functional support of the plug-in due to changing IDEs.

[0301] Existing integrated plug-ins generally require complex configuration or rely on manual operation for adjustment, while the IDE integrated plug-in of the present invention emphasizes ease of use and minimizes the user's operating burden; in specific implementation, the IDE integrated plug-in can automatically set default completion and optimization rules according to the developer's IDE, programming language and project type, thereby reducing the initial configuration time; the IDE integrated plug-in displays completion suggestions in real time through a graphical interface, allowing developers to quickly accept, modify or reject suggestions, thereby optimizing the user experience.

[0302] In order to achieve compatibility with multiple programming languages, open source parser libraries (such as ANTLR, Tree-sitter) can be integrated into the IDE integrated plug-in to handle syntax parsing of different languages, or AST (abstract syntax tree) generation tools of each language can be used to accurately analyze the code.

[0303] From the above description, a code-assisted optimization system suitable for an integrated development environment can be obtained, specifically, including a terminal device installed with an integrated development environment, wherein the terminal device uses the above-mentioned code-assisted optimization method to perform code-assisted optimization on the target source code in the integrated development environment, so as to provide target source code optimization management information after the code-assisted optimization.

[0304] Specifically, the terminal device may be an existing commonly used computer device, and the terminal device should be able to install an integrated development environment and allow the code completion optimization management model to be integrated in the integrated development environment. Figure 7 In the present invention, a data storage module is generally required in the terminal device, and the data storage module can be a commonly used storage device. Figure 7 An embodiment of developing target source code on a terminal device is shown in the figure. In the figure, the developer writes code in an integrated development environment. During the code writing process, when the code completion optimization management model is triggered, the target code context information is obtained through the context perception module. The adaptive auxiliary management model generates target source code optimization management information based on the target code context model and returns it to the integrated development environment. In addition, Figure 7 It also shows the situation of adjusting and updating the code completion optimization management model through the brightening learning method.

[0305] In summary, the present invention performs context awareness on the target source code through a context awareness module, wherein, during context awareness, multi-level semantic analysis is performed on the target source code through real-time static analysis, dynamic analysis and natural language processing technology to generate instant context information. The adaptive auxiliary management model generates target source code optimization management information according to the target code context model, thereby effectively optimizing the code and improving development efficiency and code quality.

Claims

1. A code-assisted optimization method suitable for an integrated development environment, characterized in that: The code-assisted optimization method comprises: An integrated development environment is provided, and a code completion optimization management model is integrated in the integrated development environment, so as to use the integrated code completion optimization management model to assist in optimizing the target source code in the integrated development environment, wherein: For any target source code in the integrated development environment, when the development behavior for the target source code matches the preset code auxiliary management behavior, the code completion optimization management model is triggered to perform auxiliary optimization on the target source code; When assisting in optimizing the target source code, the code completion optimization management model obtains the code target context information corresponding to the target source code and the current development behavior; Based on the acquired code target context information, target source code optimization management information adapted to the current development behavior is generated, wherein the target source code optimization management information includes target source code completion information and / or target source code optimization suggestion information.

2. The code-assisted optimization method suitable for an integrated development environment according to claim 1, characterized in that: The code completion optimization management model includes a context-aware module and an adaptive auxiliary management model adapted to the context-aware module, wherein: When assisting in optimizing the target source code, the context-aware module is used to extract code target context information of the target source code, and the acquired code target context information is loaded into the adaptive assist management model; The adaptive auxiliary management model generates target source code optimization management information based on at least the code target context information, and returns the generated target source code optimization management information to the integrated development environment.

3. The code-assisted optimization method suitable for an integrated development environment according to claim 2, characterized in that: The context-aware module extracts the code target context information of the target source code, including: Obtain static context information, dynamic context information, and code semantic information of the target source code. Based on static context information, dynamic context information and code semantic information, the target context information of the generated code is extracted.

4. The code-assisted optimization method suitable for an integrated development environment according to claim 3, characterized in that: When extracting code target context information of the target source code by using the context awareness module, the target source code is firstly subjected to code optimization preprocessing to generate target source code preprocessing information after the code optimization preprocessing; Code optimization preprocessing of the target source code includes code parsing processing and / or behavior parsing processing, wherein: When performing code parsing processing on the target source code, extracting code body information of the target source code, wherein the code body information at least includes syntax information of the target source code and structure information of the target source code; When performing behavior analysis processing on the target source code, development interaction information in the integrated development environment is analyzed to generate code behavior information based on the analyzed development interaction information, wherein the code behavior information includes an interaction operation sequence and interaction context information; Based on the target source code preprocessing information, the context-aware module extracts the code target context information, where: Performing static analysis and capturing of code body information of the target source code to generate static context information after static analysis and capturing; Dynamic analysis is performed on code behavior information of the target source code to generate dynamic context information after dynamic analysis and capture.

5. The code-assisted optimization method suitable for an integrated development environment according to claim 2, characterized in that: The adaptive auxiliary management model is constructed based on a large language model. When building an adaptive auxiliary management model based on a large language model, it at least includes a model training step, wherein: When executing the management model training steps, including: Constructing a management model training data set, wherein the management model training data set includes a plurality of training samples; Constructing an adaptive auxiliary management basic model based on a large language model, and using the management module training data set to perform model training on the adaptive auxiliary management basic model; When the model training of the adaptive assisted management basic model reaches the target state, an adaptive assisted management model is formed based on the adaptive assisted management basic model.

6. The code-assisted optimization method suitable for an integrated development environment according to claim 5, characterized in that: After the code completion optimization management model is integrated into the integrated development environment, at least the adaptive auxiliary management model is dynamically adjusted based on the adaptive learning method, wherein: The adaptive learning method includes an incremental learning method and / or an online learning method; When dynamically adjusting the adaptive auxiliary management model based on the incremental learning method, it includes: In the integrated development environment, collecting auxiliary management feedback information, wherein the auxiliary management feedback information includes accepted operation information, modified operation information or rejected operation information; Fine-tuning training is performed on the adaptive assisted management model based on the assisted management feedback information, so as to dynamically adjust the adaptive assisted management model based on the fine-tuning training.

7. The code-assisted optimization method suitable for an integrated development environment according to claim 6, characterized in that: When the adaptive auxiliary management model is dynamically adjusted, the dynamic adjustment method includes vocabulary, generation strategy, code snippet priority, naming style parameters, library and framework preferences, code formatting parameters and / or comment generation and use parameters.

8. The code-assisted optimization method suitable for an integrated development environment according to claim 5, characterized in that: When building a model training dataset, include: Collecting training data, wherein any collected training data at least includes a training source code and source code interaction information corresponding to the training source code; Performing training data preprocessing on each of the training data collected above to generate preprocessed training data after the training data preprocessing; Context understanding and capture processing is performed on each of the pre-processed training data to generate training samples after the context understanding and capture processing, wherein the training samples include training source code context information.

9. The code-assisted optimization method suitable for an integrated development environment according to claim 2, characterized in that: It also includes a personalized customization optimization module for personalized processing of target source code optimization management information, wherein: The personalized customization optimization module optimizes the target source code optimization management information according to a preset coding style and / or coding habit, so as to generate personalized optimization management information of the target source code after optimization; Return the target source code personalized optimization management information to the integrated development environment.

10. A code-assisted optimization system suitable for an integrated development environment, characterized in that: It includes a terminal device installed with an integrated development environment, wherein the terminal device uses the code-assisted optimization method described in any one of claims 1 to 9 to perform code-assisted optimization on the target source code in the integrated development environment, so as to provide target source code optimization management information after the code-assisted optimization.

Citation Information

Cited By

  • Function Declaration-oriented code intelligent comparison and incremental updating method and system

    CN120491978A

  • Function Declaration-oriented code intelligent comparison and incremental update method and system

    CN120491978B