Code generation method and related device

By perceiving and extracting project-level contexts from multiple dimensions and as input to the intelligent programming assistant, the problem of poor code generation effect of intelligent programming assistant in real application scenarios is solved, and the quality and acceptance rate of code generation are improved.

WO2025097689A1PCT designated stage expired Publication Date: 2025-05-15HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD

Patent Information

Application Number
PCT/CN2024/092018
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-03-13
Filing Date
2024-05-09
Publication Date
2025-05-15

AI Technical Summary

Technical Problem

In code development projects for real application scenarios, intelligent programming assistants have poor code generation effects and low code acceptance rate, making it difficult to meet business needs.

Method used

By starting from multiple dimensions such as the project's static structure, developer behavior, code repository evolution history, etc., we perceive and extract the in-file context and cross-file context in the project related to the code generation task, and use these multi-dimensional project-level contexts together with user input as input to the code generation model.

Benefits of technology

Improve the ability of the code generation model to utilize cross-file contexts in the code generation process, improve the code generation effect in actual development scenarios, and improve the quality and acceptance rate of code generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024092018_15052025_PF_FP_ABST
    Figure CN2024092018_15052025_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in the present application is a code generation method. The method comprises: a code development platform receiving input information from a user for a first code file in a project; acquiring in-file context and first cross-file context on the basis of a static structure of the project; acquiring second cross-file context on the basis of behavior characteristics of the user when developing the project; acquiring third cross-file context on the basis of the degree of evolution coupling between at least one second code file in a code warehouse of the project and the first code file; generating prompt information on the basis of the input information, the in-file context, the first cross-file context, the second cross-file context and the third cross-file context; inputting the prompt information into a code generation model for reasoning, so as to obtain at least one group of generated codes; and presenting to the user the at least one group of generated codes in parallel. The method takes multi-dimensional project-level context and a user input as inputs of a code generation model, thereby improving the capability of the code generation model using cross-file context during code generation, and improving the code generation performance.
Need to check novelty before this filing date? Find Prior Art

Description

A code generation method and related device

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on November 7, 2023, with application number 202311473710.1 and invention name “A code generation method and related equipment”, and claims priority to the Chinese patent application filed with the State Intellectual Property Office on March 13, 2024, with application number 202410291045.2 and invention name “A code generation method and related equipment”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of artificial intelligence (AI) technology, and in particular to a code generation method, a code development platform, a computing device cluster, a computer-readable storage medium, and a computer program product. Background Art

[0003] As software scale and complexity increase, more and more developers are exploring the use of code generation technology for software development. Code generation technology aims to reduce developers' manual programming workload and improve code development efficiency, and has attracted widespread attention from both academia and industry in software engineering (SE). In recent years, thanks to advances in artificial intelligence (AI) research in natural language processing and breakthroughs in large language models, the results of large language model-related research have enabled code generation technology to gradually move from academic research to practical application, resulting in the emergence of various intelligent programming assistant products based on large language models.

[0004] The intelligent programming assistant product mainly focuses on the text-to-code conversion (Text2Code) scenario, which is used to generate code that implements the above requirements based on the requirements described by the developer in natural language. Specifically, the developer completes the writing of code function annotations during the code writing process and triggers code generation. Then, the intelligent programming assistant product can use the generative pre-trained transformer (GPT) model to generate code snippets that implement the functions described in the annotations based on the annotations and related information provided by the developer. The intelligent programming assistant product can present the code snippets to the developer in the form of recommendations, allowing the developer to decide whether to accept or reject the recommendation, or accept it and then make further modifications.

[0005] However, in code development projects targeting real application scenarios, the code generation effect of intelligent programming assistants is poor, the code acceptance rate is low, and it is difficult to meet business needs.

[0006] Summary of the Invention

[0007] This application provides a code generation method that perceives and extracts the in-file context and cross-file context related to the code generation task in the project from multiple dimensions such as the static structure of the project, developer behavior, and the evolution history of the code repository. The method uses the above multi-dimensional project-level context together with user input (such as task description information and input code in natural language form) as the input of the code generation model, improves the code generation model's ability to utilize cross-file context during the code generation process, and enhances the code generation effect in actual development scenarios. This application also provides a code development platform, computing device cluster, computer-readable storage medium, and computer program product corresponding to the above method.

[0008] In the first aspect, the present application provides a code generation method. The method can be performed by a code development platform. The code development platform can be software, which can be independently running software, or integrated into other software, such as a functional module within an integrated development environment (IDE) or a plug-in integrated into an IDE, or a code editor. The software can be deployed on a computing device cluster, which executes the program code of the software system, thereby executing the code generation method of the present application. In some possible implementations, the code development platform can also be hardware, such as a computing device cluster that provides code generation capabilities, which executes the code generation method of the present application when the computing device cluster is running.

[0009] Specifically, the code development platform receives the user's input information for the first code file in the project, where the input information includes at least one of the task description information of the code generation task or the input code. The code development platform then obtains the in-file context and the first cross-file context based on the static structure of the project, obtains the second cross-file context based on the user's behavioral characteristics in the development project, and obtains the third cross-file context based on the evolutionary coupling degree between at least one second code file and the first code file in the project's code repository. The in-file context is the context within the first code file, and the cross-file context is the context within the code files other than the first code file in the project. The code development platform can then generate prompt information based on the input information, the in-file context, the first cross-file context, the second cross-file context, and the third cross-file context. The code development platform inputs the prompt information into the code generation model for reasoning to obtain at least one set of generated code. The code development platform can display at least one set of generated code to the user.

[0010] This method starts from multiple dimensions such as the static structure of the project, developer behavior, and the evolution history of the code repository, and perceives and extracts the intra-file context and cross-file context related to the code generation task in the project. The above multi-dimensional project-level context is used together with user input (such as task description information and input code in natural language form) as the input of the code generation model, improving the code generation model's ability to utilize cross-file context during the code generation process and enhancing the code generation effect in actual development scenarios.

[0011] In some possible implementations, the code development platform may obtain a second cross-file context based on at least one of the metadata of an opened code file, the editing popularity of a code file in a project, or a user's search history in a development project, where the metadata of the opened code file includes at least one of the relative positional relationship of a class, member, method in the opened code file, or an editor of the opened code file.

[0012] This method perceives the user's focus in the development process (or programming process) by analyzing behavioral characteristics such as opened code files, editing heat, and search history. It can thus extract context that is helpful for code generation from the user behavior dimension and improve the quality of code generation.

[0013] In some possible implementations, the code development platform can obtain the behavioral characteristics of users in the development project through the behavior perception interface. This can enable analysis of user behavior during the development process and provide assistance for subsequent code generation.

[0014] In some possible implementations, the code development platform can also obtain commit records from the code repository. Based on the commit records, the code development platform can perform an evolutionary coupling analysis on at least one second code file and a first code file in the project's code repository to obtain the degree of evolutionary coupling between the at least one second code file and the first code file. The evolutionary coupling degree represents the degree of evolutionary coupling or evolutionary correlation, and can be quantified by the probability that the first code file and the second code file were simultaneously modified and committed throughout the entire commit history.

[0015] For code files with high evolutionary coupling, the context within the code file can provide a reference for code generation in the current code file, helping to improve the quality of code generation in the current code file.

[0016] In some possible implementations, the code development platform can construct a project structure diagram based on the static structure of the project. The static structure includes the project's hierarchical structure, which includes the hierarchical relationships among modules, packages, classes, or code blocks within the project. The project structure diagram includes hierarchical relationships and dependency information. The code development platform can obtain the subgraph corresponding to the code generation task based on its position in the project structure diagram, and obtain the intra-file context and the first cross-file context based on the subgraph corresponding to the code generation task.

[0017] In this method, by combining the static structure of the project to obtain the subgraph corresponding to the code generation task, the scope of determining the intra-file context and cross-file context can be narrowed. Based on the subgraph, the intra-file context and the first cross-file context can be accurately extracted to avoid interference from other contexts on code generation and improve the quality of code generation.

[0018] In some possible implementations, the code development platform can obtain the project's internal import statements and in-file context based on the subgraph corresponding to the code generation task, where the in-file context includes at least one of the library file import statement, the class to which the code generation task belongs, the context above the first code file, or the context below the first code file. The code development platform can obtain the dependent class of the class based on the project's internal import statement, and obtain a first cross-file context based on the dependent class, where the first cross-file context includes at least one of the member variable name, method signature, constant, and access control keyword in the dependent class.

[0019] This method uses subgraphs to identify the project's internal import statements, library file import statements, the class to which the code generation task belongs, and the context of the first code file. Based on the above internal import statements, the dependent class of the class can be identified, and then the member variable names, method signatures, constants, access control keywords and other contexts of the dependent class can be identified, providing rich reference information for code generation.

[0020] In some possible implementations, the code development platform may abstract at least one of the intra-file context, the first cross-file context, the second cross-file context, or the third cross-file context into a grammatically correct interface declaration, and then generate prompt information through a prompt project based on the input information and the interface declaration.

[0021] This method, by abstracting the context into an interface declaration, can compress context information. It also reuses the programming language grammar knowledge learned by the model during unsupervised pre-training by abstracting the context code into a grammatically correct interface declaration.

[0022] In some possible implementations, the code development platform can further sort the cross-file contexts based on at least one of access rights, topological distance, edit popularity, semantic similarity, or evolutionary coupling. Accordingly, the code development platform can assemble prompt information based on the input information, the context within the file, the first cross-file context, the second cross-file context, and the third cross-file context, combined with the sorting results of the cross-file contexts.

[0023] Considering that the overall length of the context may be too long, the context is sorted so that relatively important contexts can be input as prompt information without being truncated, thus ensuring the quality of code generation.

[0024] In some possible implementations, the code development platform may also add start marks to different types of information in the input information, the in-file context, the first cross-file context, the second cross-file context, and the third cross-file context to generate prompt information.

[0025] This can display information related to the code generation task, improve the code generation model's ability to utilize cross-file context during the code generation process, and enhance the code generation effect in actual development scenarios.

[0026] In some possible implementations, the code generation model is obtained as follows:

[0027] Obtain training data that includes cross-file context;

[0028] Based on the training data, the base model is directly pre-trained, multi-stage pre-trained, or fine-tuned to obtain a code generation model.

[0029] Compared to adding cross-file context only during the inference phase, this application also supports aligning training tasks with inference tasks, thereby focusing on improving the code generation model's ability to perceive and utilize context, achieving better results and experience in actual use.

[0030] In a second aspect, the present application provides a code development platform. The code development platform includes:

[0031] An interaction module is configured to receive input information of a first code file in a project from a user, the input information including at least one of task description information of a code generation task or input code;

[0032] A context extraction module is configured to obtain an intra-file context and a first cross-file context based on the static structure of the project, obtain a second cross-file context based on the behavioral characteristics of the user in developing the project, and obtain a third cross-file context based on the evolutionary coupling between at least one second code file and the first code file in the project's code repository, where the intra-file context is the context within the first code file, and the cross-file context is the context within code files in the project other than the first code file;

[0033] A prompt module, configured to generate prompt information according to input information, an intra-file context, a first cross-file context, a second cross-file context, and a third cross-file context;

[0034] A generation module, configured to input the prompt information into a code generation model for reasoning to obtain at least one set of generated codes;

[0035] The interactive module is further configured to display at least one set of generated codes to the user.

[0036] In some possible implementations, the context extraction module is specifically configured to:

[0037] A second cross-file context is obtained based on at least one of the metadata of an opened code file, the editing popularity of a code file in a project, or a user's search history in a development project. The metadata of the opened code file includes at least one of a relative position relationship of a class, a member, a method in the opened code file, or an editor of the opened code file.

[0038] In some possible implementations, the context extraction module is further configured to:

[0039] Obtain the user's behavioral characteristics in the development project through the behavior perception interface.

[0040] In some possible implementations, the context extraction module is further configured to:

[0041] Get the commit record of the code repository;

[0042] According to the commit record of the code repository, an evolutionary coupling analysis is performed on at least one second code file and a first code file in the code repository of the project to obtain an evolutionary coupling degree between the at least one second code file and the first code file.

[0043] In some possible implementations, the context extraction module is specifically configured to:

[0044] Build a project structure diagram based on the static structure of the project. The static structure includes the hierarchical structure of the project. The hierarchical structure includes the hierarchical relationship of modules, packages, classes or code blocks in the project. The project structure diagram includes the hierarchical relationship and dependency information.

[0045] According to the position of the code generation task in the project structure diagram, obtain the subgraph corresponding to the code generation task;

[0046] According to the subgraph corresponding to the code generation task, obtain the intra-file context and the first cross-file context.

[0047] In some possible implementations, the context extraction module is specifically configured to:

[0048] Obtaining, according to the subgraph corresponding to the code generation task, an internal import statement and an intra-file context of the project, where the intra-file context includes at least one of a library file import statement, a category of the code generation task, a context above the first code file, or a context below the first code file;

[0049] According to the internal import statement of the project, the dependent class of the belonging class is obtained, and the first cross-file context is obtained according to the dependent class. The first cross-file context includes at least one of the member variable name, method signature, constant, and access control keyword in the dependent class.

[0050] In some possible implementations, the prompt module is specifically configured to:

[0051] Abstracting at least one of the intra-file context, the first cross-file context, the second cross-file context, or the third cross-file context into a grammatically correct interface declaration;

[0052] Generate prompt information through the prompt project based on input information and interface declaration.

[0053] In some possible implementations, the prompt module is further configured to:

[0054] sorting cross-file contexts according to at least one of access rights, topological distance, editing heat, semantic similarity, or evolutionary coupling;

[0055] The prompt module is specifically used for:

[0056] According to the input information, the context within the file, the first cross-file context, the second cross-file context and the third cross-file context, the prompt information is assembled in combination with the sorting results of the cross-file context.

[0057] In some possible implementations, the prompt module is specifically configured to:

[0058] Start marks are added to different types of information in input information, in-file context, first cross-file context, second cross-file context, and third cross-file context to generate prompt information.

[0059] In some possible implementations, the code development platform further includes:

[0060] The training module is used to obtain training data including cross-file context, and perform direct pre-training, multi-stage pre-training or fine-tuning on the base model based on the training data to obtain a code generation model.

[0061] In a third aspect, the present application provides a computing device cluster. The computing device cluster includes at least one computing device, wherein the at least one computing device includes at least one processor and at least one memory. The at least one processor and the at least one memory communicate with each other. The at least one processor is configured to execute instructions stored in the at least one memory, so that the computing device or computing device cluster performs the code generation method described in the first aspect or any implementation of the first aspect.

[0062] In a fourth aspect, the present application provides a computer-readable storage medium storing instructions, wherein the instructions instruct a computing device or a computing device cluster to execute the code generation method described in the first aspect or any implementation of the first aspect.

[0063] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a computing device or a computing device cluster, enables the computing device or computing device cluster to execute the code generation method described in the first aspect or any one of the implementations of the first aspect.

[0064] Based on the implementation methods provided in the above aspects, this application can also be further combined to provide more implementation methods. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] In order to more clearly illustrate the technical methods of the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments.

[0066] FIG1 is a schematic diagram of the architecture of a code development platform provided by this application;

[0067] FIG2 is a flow chart of a code generation method provided by the present application;

[0068] FIG3 is a schematic diagram of a code editing interface provided by the present application;

[0069] FIG4 is a schematic diagram of a flow chart of code generation in the reasoning phase provided by this application;

[0070] FIG5 is a schematic diagram of a code editing interface provided by the present application;

[0071] FIG6 is a flowchart of context processing in the reasoning phase provided by the present application;

[0072] FIG7 is a schematic diagram of a model architecture based on a transformer decoder provided in this application;

[0073] FIG8 is a schematic diagram of the structure of training data including file-level context provided by the present application;

[0074] FIG9 is a schematic diagram of the structure of training data including cross-file context provided by the present application;

[0075] FIG10 is a schematic diagram of a front-end interface of a code generation plug-in provided by the present application;

[0076] FIG11 is a schematic diagram of a front-end interface of a code generation plug-in provided by the present application;

[0077] FIG12 is a comparative diagram of a code generation result provided by this application;

[0078] FIG13 is a schematic diagram of triggering code generation through a human-computer interaction interface provided by the present application;

[0079] FIG14 is a schematic diagram of constructing prompt information and generating code based on the prompt information provided by the present application;

[0080] FIG15 is a schematic diagram of the structure of a code development platform provided by this application;

[0081] FIG16 is a schematic diagram of the structure of a computing device provided by the present application;

[0082] FIG17 is a schematic diagram of the structure of a computing device cluster provided by this application;

[0083] FIG18 is a schematic diagram of the structure of another computing device cluster provided by the present application;

[0084] FIG19 is a schematic diagram of the structure of another computing device cluster provided in this application. DETAILED DESCRIPTION

[0085] The terms "first" and "second" in the embodiments of this application are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the number of technical features indicated. Therefore, features specified as "first" or "second" may explicitly or implicitly include one or more of the features.

[0086] First, some technical terms involved in the embodiments of this application are introduced.

[0087] Code generation refers to the process of automatically generating code based on user input, such as incomplete code or natural language descriptions, using automated tools or techniques to complete the code or implement the functionality described in the natural language description. Depending on the granularity of the generated code, code generation can include line-level code generation and method-level (or function-level) code generation.

[0088] A large language model (LLM) is a language model composed of an artificial neural network with many parameters (typically billions of weights or more) that is trained on large amounts of unlabeled text using self-supervised or semi-supervised learning. Large language models can be categorized into different types based on their architecture. Generative Pre-trained Transformer (GPT) models are widely used in code generation.

[0089] Intelligent programming assistant products based on large language models such as GPT support the generation of code snippets that implement the functions described in the comments based on the comments and related information provided by developers. User feedback and large-scale survey results during the public beta phase show that the above-mentioned intelligent programming assistant products can effectively reduce the cost of developers frequently switching between actual code writing and searching for knowledge, consulting documents, and finding reusable components, thereby improving the efficiency of software development. However, in code development projects in real application scenarios, the business logic code generation effect is poor. Specifically, the generated code contains methods or variables that do not exist at all (usually referred to as hallucinations in the AI ​​field), or fails to make good use of the existing cross-file code in the project for code generation, resulting in repeated development and increased code complexity.

[0090] After research, the inventors discovered that the code generation models in intelligent programming assistant products are typically trained using LLMs such as GPT. The training and reasoning methods of the code generation models are derived from natural language processing (NLP) technology, and do not fully consider the logical structure of code projects and the common call relationships between code file contents. Specifically:

[0091] During model training, LLM processes training data sequentially using natural language, which is inconsistent with the logical conventions of actual code development. Furthermore, LLM's training is based on text-based file-level context, making it difficult to learn and utilize global information such as the project's static structure and code call relationships.

[0092] During model inference, the context scope of LLM is limited to the current code file. This makes it easy for the generated code to include calls to code that doesn't exist in the project, while failing to correctly call existing code. If the context scope is expanded and still in text format, private data in the user code can be easily leaked.

[0093] This shows that compared with other software development tools, intelligent programming assistant products based on LLM are still in their infancy. To this end, the industry has proposed a solution that uses project-level context as an input prefix to enhance the input of the code generation model during the reasoning phase to improve the code generation effect. This solution first proposes a series of rules to define project-level context, including the current class (Current), parent class (Parent Class), referenced class (Import Class), class in the same package (Sibling), class with the same name as the current class in the project (Similar Name), child class (Child Class), referenced class of the parent class (Import of Parent Class), referenced class in the class of the same package (Import of Sibling), etc. At the same time, to solve the problem of excessively long context, this solution also specifically classifies the context information in the code to select a context of appropriate length.

[0094] Based on the aforementioned rules, the solution designs a rule selector, such as a multi-label classifier, that uses a combination of different rules to select context at different levels and contents for input into the intelligent programming assistant product. The rule selector is then optimized based on a comparison of the generated code with the actual code labels. During the inference phase, the optimized rule selector extracts context at different levels for different code scenarios. This context is then proportionally combined with the code near the generation point, and then used as input for code generation tools such as the intelligent programming assistant product.

[0095] However, the aforementioned solution's considerations are relatively narrow, primarily focusing on the static dimensions of the project. This makes it difficult to precisely identify the context scope required for code generation tasks. Furthermore, given the flexibility of programming languages ​​and the unpredictability of project code, defining context scopes through predefined rules fails to cover the full range of actual development scenarios, easily leading to omissions or redundancies in context. Consequently, the aforementioned solution offers limited improvement or gains in code generation performance, and the acceptance rate of generated code still falls short of meeting business requirements.

[0096] In view of this, the present application provides a code generation method. This method aims to alleviate the limitations of current intelligent programming assistants in code generation from the perspective of context awareness, and proposes an intelligent perception and dynamic construction technology for project-level context (including intra-file context and cross-file context) in object-oriented code generation. A context that is conducive to code generation is constructed through multi-dimensional cross-file context perception and extraction technology. Furthermore, the project-level context perception and utilization capabilities of the code generation model are improved through the joint optimization of the model training and reasoning stages, thereby alleviating the problem of poor code generation effect caused by the above-mentioned deficiencies.

[0097] The code generation method can be performed by a code development platform. The code development platform can be software, which can be stand-alone software or integrated into other software, such as a functional module within an integrated development environment (IDE) or a plug-in integrated into an IDE, or a code editor. The software can be deployed on a computing device cluster, which executes the program code of the software system, thereby executing the code generation method of the present application. The software can be provided to users in the form of a software package, for example, the software can be provided to users as a new function of a client code editor or IDE with version updates, or as a new feature of a code generation plug-in based on a pre-trained language model, with version updates. Users can run the software package in a local data center or a private cloud to deploy the software. Alternatively, the software can be provided to users in the form of a cloud service, such as software as a service (SaaS). For example, the software can appear as an auxiliary coding function of a cloud code editor or development environment, and expose a functional interface to the outside in the form of a cloud service, such as an application programming interface (API), and other tools can use the above-mentioned code generation function or capability by calling the interface. In some possible implementations, the code development platform may also be hardware, such as a computing device cluster that provides code generation capabilities. When the computing device cluster is running, it executes the code generation method of the present application.

[0098] Specifically, the code development platform can receive input information from a user about a first code file in a project, where the input information includes at least one of the task description information or input code for the code generation task. The code development platform then obtains an intra-file context and a first cross-file context based on the static structure of the project, obtains a second cross-file context based on the user's behavioral characteristics in developing the project, and obtains a third cross-file context based on the degree of evolutionary coupling between at least one second code file and the first code file in the project's code repository. Based on the input information, the intra-file context, the first cross-file context, the second cross-file context, and the third cross-file context, the code development platform generates prompt information, inputs the prompt information into a code generation model for inference, obtains at least one set of generated code, and displays the at least one set of generated code to the user.

[0099] This method starts from multiple dimensions such as the static structure of the project, developer behavior, and the evolution history of the code repository, and perceives and extracts the intra-file context and cross-file context related to the code generation task in the project. The above multi-dimensional project-level context is used together with user input (such as task description information and input code in natural language form) as the input of the code generation model, improving the code generation model's ability to utilize cross-file context during the code generation process and enhancing the code generation effect in actual development scenarios.

[0100] Moreover, this method introduces the above-mentioned multi-dimensional cross-file context into training expectations, aligning the task form and data distribution in the training phase with the task form and data distribution in the reasoning phase, so as to enhance the code generation model's ability to perceive and utilize cross-file context, and further improve the code generation capability of the code generation model.

[0101] In order to make the technical solution of this application clearer and easier to understand, the system architecture of the code development platform of this application is first introduced below.

[0102] Referring to the schematic diagram of the architecture of a code development platform shown in FIG1 , code development platform 10 includes an inference platform 100 , which is used to perform inference based on a trained code generation model to generate code. Furthermore, code development platform 10 may also include a training platform 200 , which is used to train a base model based on a training corpus including multi-dimensional cross-file context to obtain a code generation model. The inference process is performed in the inference phase, and the training process is performed in the training phase.

[0103] The reasoning platform 100 is used to obtain multi-dimensional cross-file context from the project through multi-dimensional project-level cross-file context awareness technology for code generation tasks, and to extract intra-file context for code generation tasks through code generation key information extraction technology. The intra-file context is also referred to as the current file context. Specifically, the reasoning platform 100 can receive input information of the first code file in the project from the user, and the input information includes at least one of the task description information or input code of the code generation task, and then obtain the intra-file context and the first cross-file context according to the static structure of the project, obtain the second cross-file context according to the behavioral characteristics of the user in the development project, and obtain the third cross-file context according to the evolutionary coupling degree of at least one second code file and the first code file in the code repository of the project. The multi-dimensional cross-file context may include a combination of the above-mentioned first cross-file context, the second cross-file context and the third cross-file context. The reasoning platform 100 is used to generate prompt information based on the above-mentioned input information (such as the task description information and input code of the code generation task), the file context, and the multi-dimensional cross-file context (such as the first cross-file context, the second cross-file context, and the third cross-file context), input the prompt information into the code generation model for reasoning, and obtain at least one set of generated code. The generated code can be, for example, a generated line-level code snippet or a method-level code snippet. The reasoning platform 100 is used to display at least one set of generated code to the user.

[0104] In some possible implementations, the reasoning platform 100 is also used to sort the multi-dimensional cross-file context by context priority to obtain the cross-file context priority. Accordingly, the reasoning platform 100 is used to construct the input information (such as the task description information and input code of the code generation task), the context within the file, and the multi-dimensional cross-file context into prompt information in combination with the cross-file context priority, for example, a context-enhanced prompt is constructed through a context-aware prompt template. Among them, when constructing the prompt, the location of the code generation task is also combined, also known as the task point. It should be noted that the reasoning platform 100 takes into account the situation where the overall length of the context is too long and sorts the context so that the relatively important context can be input into the prompt without being truncated. In some cases, such as when the overall length of the context is within a controllable range, the reasoning platform 100 may not perform the above-mentioned sorting process.

[0105] The code generation model can be trained by a training platform 200. The training platform 200 is used to obtain training data including cross-file context, such as the aforementioned multi-dimensional cross-file context. Based on the training data, the base model is then directly pre-trained, pre-trained in multiple stages, or fine-tuned to obtain the code generation model. Figure 1 illustrates an example of fine-tuning instructions on the base model by the training platform 200.

[0106] In specific implementation, the training platform 200 is used to obtain code files of a large number of projects from a massive software code repository (also referred to as a code warehouse for short), and pre-process the code files of the projects, such as extraction, screening or deduplication, to form a code warehouse data set. The training platform 200 is used to perform multi-dimensional project-level cross-file context perception on the data in the code warehouse data set, thereby extracting the multi-dimensional project-level cross-file context for the function (or method), and constructing training data based on the multi-dimensional project-level cross-file context. Among them, the training platform 200 can perform word segmentation, encoding, and segmentation on the function's comments, declarations, and the function's in-file context, multi-dimensional project-level cross-file context, in-file context, and function body, and then form instructions (such as prompts in the form of instructions). The training platform 200 is used to fine-tune the instructions recorded as a model through the constructed instructions, so as to obtain a code generation model.

[0107] Based on the code development platform 10 shown in Figure 1, the present application provides a code generation method. The code generation method of the present application is described below with reference to the accompanying drawings.

[0108] Referring to the flowchart of a code generation method shown in FIG2 , the method includes the following steps:

[0109] S202 : The code development platform 10 receives user input information of a first code file in a project.

[0110] A project, short for software project, is a project file created by developers for the software they are developing. A project can include multiple code files, such as those used to implement different software functions or features. Code files within a project can be developed independently by a single user or collaboratively by multiple users. During development, users can use code generation capabilities to automatically generate code.

[0111] Taking the first code file as an example, the user's input information in the first code file may include at least one of the task description information or input code of the code generation task. The task description information may be a task description in natural language. For example, when the code generation task is used to generate code for a target method or target function, the task description information may be a description of the requirements for creating the target method or target function, and the task description information may typically be input in the form of comments. The input code may include a function declaration. The function declaration may include the function name and parameter names. Accordingly, the code generation task may be a code snippet that generates the function body.

[0112] Specifically, the code development platform 10 may present a code editing interface to the user, wherein the code editing interface may be a user interface of a code editor, and the code editing interface may be a graphical user interface (GUI) or a command user interface (CUI).

[0113] For ease of description, the present application is illustrated as a GUI example with a code editing interface. As shown in Figure 3, a code editing interface 300 can include an editing window 302 for a first code file. A user can input task description information 304 in the editing window 302. Task description information 304 is used to describe the code that needs to be generated. In this example, task description information 304 can be "Create a http sever instance and start it", as well as input method declaration 306, such as "public void init(){}". The user can trigger the code generation control 308 of the code editing interface 300, thereby triggering a code generation operation. Accordingly, the code development platform 10 can receive the task description information 304 and method declaration 306 (input code) input by the user, and then perform code generation based on the task description information 304 and method declaration 306.

[0114] It should be noted that FIG3 is only an example of the user's input information including task description information and input code. In other possible implementation methods of the embodiment of the present application, the user's input information may also include task description information, or include input code. For example, when the user is editing the code of some methods, the user can directly write the method without adding task description information in the form of comments. For another example, when the user is editing the code of some methods, the user can add task description information in the form of comments without entering the code. Among them, when entering the task description information 304 in the form of comments, the user can first enter the keyword of the comment, such as the " / * / " character, the @ character or the # character, and then enter the task description information. This can avoid executing the above-mentioned task description information 304 when executing the code file.

[0115] In addition, FIG3 is an example of a user triggering a code generation control 308 to trigger a code generation operation. In actual application, the code development platform 10 also supports triggering a code generation operation in other ways. For example, the code development platform 10 also supports a shortcut key or menu (such as a right-click menu) to trigger a code generation operation. Alternatively, referring to FIG4 , the user can also call a language model, such as LLM, when editing code in the first code file, and input the task description information and / or input code of the code generation task in an instruction / dialogue manner. In the example of FIG4 , the task description information can be “Based on the current project, add a course selection method for the Student class”, and the interactive interface of the LLM can also include a selection control. When the selection control is selected, the LLM can generate code with reference to the current project. The method of triggering code generation or inputting code generation task description information and inputting code in this application is not limited and can be selected according to actual conditions.

[0116] S204 : The code development platform 10 obtains the intra-file context and the first cross-file context according to the static structure of the project.

[0117] The static structure of a project can include its hierarchical structure. The hierarchical structure includes the hierarchical relationships among modules, packages, classes, or code blocks within the project. The hierarchical structure can be represented by a tree structure (referred to as a tree). Specifically, the tree is rooted at the project and has methods as leaf nodes. The tree is formed by expanding the modules, packages, classes, and code blocks within the project layer by layer.

[0118] The code development platform 10 can construct a project structure diagram based on the static structure of the project. The project structure diagram includes hierarchical relationships and dependency information. The dependency information can include dependency information between classes. The code development platform 10 can then obtain a subgraph corresponding to the code generation task based on its position in the project structure diagram, for example, the position of the class to which the code generation task belongs in the project structure diagram. The subgraph can be a partial graph of the project structure diagram related to the code generation task.

[0119] For a folder corresponding to a project / code repository, the code development platform 10 can construct a graph-formatted data structure through preprocessing, which is called a project structure diagram. The project structure diagram can be generated based on a project hierarchy tree, where the project hierarchy tree can be a tree that models the hierarchical structure of a project. Specifically, based on the project hierarchy tree, the code development platform 10 can convert the project hierarchy tree into a project structure diagram that models the hierarchical and reference relationships between classes within the project by analyzing the dependencies between classes and adding edges.

[0120] For a code generation task, the code development platform 10 can determine the code scope that the method has the authority to access or call based on the location of the code generation task in the project structure diagram, the access control permissions of the class (such as public / private / default, etc.), and the hierarchy and reference relationships involving the class, which is reflected as a sub-diagram of the project structure diagram.

[0121] The code development platform 10 can obtain the file context and the first cross-file context based on the subgraph corresponding to the code generation task. Among them, the file context refers to the context within the first code file. The context before the input information (or target method) is called the preceding context (also called the foreword), and the context after the target method is called the following context (also called the following context). The preceding context generally includes package statements and import statements, the signature of the belonging class (the class where the target method is located), partial declarations of the belonging class (such as member variables, constructors, partial methods), etc.; and the following context generally includes other method declarations of the belonging class. The first cross-file context refers to the context from other code files in the code warehouse obtained from the static structure dimension. In specific implementation, the code development platform 10 can obtain code snippets from other code files in the project used in the first code file based on the edges in the project structure diagram and the import statements of the first code file (current file). The first cross-file context may include code snippets from other code files in the project used in the first code file obtained based on the above-mentioned import statements and project structure diagram. As shown in Figure 4, the first cross-file context can include at least one of the imported cross-file classes, class members, or class methods within the project, where class methods can include constructors or other methods. The first cross-file context can also include code in the same package, parent class members, and parent class methods.

[0122] Among them, the code development platform 10 can obtain the first cross-file context such as cross-file classes and methods in the project that the current file depends on through analysis tools, or access the intermediate data obtained by the IDE analysis project through the API provided by the IDE, such as the Program Structure Interface (PSI), to obtain the first cross-file context.

[0123] S206 : The code development platform 10 obtains a second cross-file context according to the user's behavior characteristics in the development project.

[0124] Behavioral features refer to the characteristic representations of the opening of code files, editing of code files, or searching behaviors triggered during the development of a project. The behavioral features may include at least one of the metadata of an opened code file, the editing popularity of a code file in a project, or a user's search history in the development project. The metadata of an opened code file may include at least one of the relative positional relationships of a class, a member, a method, or an editor of an opened code file. The relative positional relationships of the editors of an opened code file may include the group in which the editor is located and the relative positions of each editor. The editing popularity of a code file may be characterized by the number of recently modified x files, the frequency of modification, or the amount of modification. The search history may be a search history of a user in the search box of the code development platform 10.

[0125] The code development platform 10 can perceive the user's focus in the development process (or programming process) based on the user's behavioral characteristics in the development project (such as real-time behavioral characteristics). The focus is the code file in the project that the user focuses on (for example, the code file other than the first code file in the project). The code development platform 10 can extract cross-file code from the code file in the project that the user focuses on, thereby obtaining a second cross-file context.

[0126] The code development platform 10 may provide a behavior-aware interface. For example, code development platforms such as IDEs provide APIs for perceiving user behavior. The code development platform 10 may obtain the user's behavior characteristics in the development project through the behavior-aware interface, thereby obtaining another dimension of cross-file context.

[0127] S208 : The code development platform 10 obtains a third cross-file context according to the evolution coupling degree between at least one second code file and the first code file in the code repository of the project.

[0128] Evolutionary coupling refers to the tendency of pairs of code entities (e.g., two code entities) to change together (covariate) throughout the software revision history. The evolutionary coupling relationship between code entities X and Y can be represented by X→Y: if code entity X changes, entity Y also tends to change. X and Y can be at the granularity of source files, classes, modules, methods, variables, and so on. The degree of evolutionary coupling indicates the degree of evolutionary coupling or evolutionary correlation.

[0129] Specifically, the code development platform 10 can analyze the evolutionary coupling between at least one second code file and the first code file (the file where the code generation task is located) in the project based on the evolutionary history of the code warehouse using an evolutionary correlation analysis method, and extract a third cross-file context from the file with a high degree of coupling. The second code file can be a code file other than the first code file in the project, and a high degree of coupling can mean that the coupling is higher than a set value, or is ranked in the top k when the coupling is sorted from high to low. In some examples, the third cross-file context can be a code snippet in a code file that has been modified simultaneously in the submission history.

[0130] Among them, the code development platform 10 can obtain the submission record of the code repository, such as the git submission record, and then the code development platform 10 can perform an evolutionary coupling analysis on at least one second code file and the first code file in the project's code repository based on the submission record of the code repository to obtain the evolutionary coupling degree of at least one second code file and the first code file.

[0131] Among them, the above S204, S206, and S208 can be executed in parallel, or executed successively according to a set order, and the embodiment of the present application does not limit this.

[0132] S210 : The code development platform 10 generates prompt information according to the input information, the intra-file context, the first cross-file context, the second cross-file context, and the third cross-file context.

[0133] Specifically, the code development platform 10 can fill the input information, the intra-file context, the first cross-file context, the second cross-file context and the third cross-file context into the corresponding positions of the prompt template respectively, thereby generating a prompt. As shown in Figure 4, the prompt template may include instruction filling indication information and context filling indication information. In the reasoning stage, the instruction filling indication information may indicate the filling of the user's input information, such as task description information and input code, and the context filling indication information may indicate the filling of the intra-file context, the first cross-file context, the second cross-file context and the third cross-file context. Furthermore, the context filling indication information can also be divided into intra-file context filling indication information and cross-file context filling indication information. Among them, the intra-file context filling indication information may include the following filling indication information and the above filling indication information.

[0134] In some possible implementations, the prompt template may also include a system prompt. For example, the system prompt in Figure 4 can be used to indicate that the task is a programming task based on project-level context. To align tasks between the inference and training phases, the training and inference phases can share a common prompt template. Based on this, the prompt template may also include generated code fill-in instructions, indicating the desired fill location for generated code.

[0135] Since the input length of the code generation model (usually a language model, such as LLM) has certain limitations (called window size, usually 1024 to 8192), when the input length is limited, the length of the project-level context may exceed the input length limit of the code generation model. Based on this, the present application can also support sorting cross-file contexts to reduce the probability of important contexts being deleted by truncation strategies when the input is too long. Among them, the code development platform 10 can sort cross-file contexts according to at least one of access rights, topological distance, editing heat, semantic similarity or evolutionary coupling (or referred to as evolutionary relevance, evolutionary relevance). Among them, topological distance is a probability relative to physical distance, and physical distance can be the distance between the target method and the context in the code file. Topological distance can be the distance between the target method and the context in the project structure diagram, and the distance can be characterized by the number of hops (or the number of nodes in the interval). Accordingly, the code development platform 10 can be assembled to obtain prompt information based on the input information, the upper and lower parts of the file, the first cross-file context, the second cross-file context and the third cross-file context, combined with the sorting results of the cross-file context. The code development platform 10 quantifies the importance of different cross-file contexts to the code generation task by comprehensively using indicators such as access rights, topological distance, editing heat, semantic similarity, and evolutionary correlation, and sorts the cross-file contexts according to their importance (importance) to avoid important cross-file contexts being truncated due to excessively long input.

[0136] Furthermore, if the original code is used directly as context, redundant information can be introduced, which limits the amount of context information available to the code generation model, thereby reducing the efficiency of context utilization. To this end, the code development platform 10 also supports direct context abstraction, for example, abstracting at least one of the file context, the first cross-file context, the second cross-file context or the third cross-file context into a grammatically correct interface declaration. Among them, the code development platform 10 can retain the hierarchical structure and identifier (ID) by removing at least one of the comments, variable assignments, and method bodies. The retained ID can include method names and parameter names. Accordingly, the code development platform 10 can generate prompt information through a prompt project based on the input information and interface declaration. Among them, the code development platform 10 can filter out the context (or interface declaration) related to the current method (such as the target method) in the abstracted context (such as the interface declaration) through identifier similarity, such as the part that is most likely to be related to the current method, thereby realizing context intelligent recommendation and filtering. Furthermore, the code development platform 10 can adjust the filtered context or interface declaration to the position before the user input (such as task description information), and organize the position of each context in the prompt in reverse order of context importance, thereby reducing the probability of important context being truncated and increasing the weight of important context for code generation (such as method body generation of the target method).

[0137] By abstracting the context into an interface declaration, the code development platform 10 can, on the one hand, compress context information. On the other hand, by abstracting the context code into a grammatically correct interface declaration, the code development platform 10 can reuse the programming language grammar knowledge learned by the model during unsupervised pre-training.

[0138] In some possible implementations, the code development platform 10 can add start markers to different types of information in the input information, the intra-file context, the first cross-file context, the second cross-file context, and the third cross-file context to generate prompt information. This can display information related to the code generation task, improve the code generation model's ability to utilize cross-file context during the code generation process, and enhance the code generation effect in actual development scenarios.

[0139] S212 , the code development platform 10 inputs the prompt information into the code generation model for reasoning to obtain at least one set of generated codes.

[0140] A code generation model is a language model used to generate code based on user input. Considering the effectiveness of code generation, this language model can be a causal language model based on the Transformer decoder architecture, such as an LLM based on the GPT architecture. This type of model accepts a code sequence as input, autoregressively predicts the next word (token) in the code as output, and uses this output as the next input (i.e., performing the Next Token Prediction task).

[0141] The code development platform 10 inputs the prompt information into the code generation model. The code generation model can combine the multi-dimensional project-level context in the prompt information to infer the subsequent code of the input code, thereby obtaining at least one set of generated code.

[0142] S214 : The code development platform 10 displays at least one set of generated codes to the user.

[0143] Specifically, the code development platform 10 can display at least one set of generated codes to the user in the code editing interface of the first code file. When the code development platform 10 infers multiple sets of generated codes for the code generation task, the code development platform 10 can display the generated codes in combination with probability.

[0144] In some possible implementations, the code development platform 10 can sort the generated codes according to probability, and the code development platform 10 can display the generated codes with high probability. When the user triggers the operation of viewing the next set of generated codes, the code development platform 10 displays the generated codes whose probability sorting results are after the current generated codes.

[0145] In some other possible implementations, the code development platform 10 may also display multiple sets of generated codes at once. Specifically, the code development platform 10 may sort the generated codes according to probability and display the top n generated codes at once according to the sorting result.

[0146] Furthermore, the code development platform 10 can also receive user feedback on the generated code, wherein the feedback can include acceptance, rejection, or revision of the generated code. If the user determines that the generated code is usable, the user can accept the second code snippet; if the user determines that the generated code is not usable, the user can reject the second code snippet; if the user determines that the generated code is partially usable, the user can revise the generated code.

[0147] As shown in FIG5 , the code development platform 10 can present a code editing interface 500 to the user. The code editing interface 500 includes generated code 502 and feedback controls corresponding to the generated code 502. The feedback controls can include an accept control 504, a reject control 506, and a revision control 508. The user can trigger different types of feedback controls to provide different types of feedback, such as accepting, rejecting, or revising the generated code 502. Furthermore, the code editing interface 500 can also include a coding process analysis 503 for the generated code 502. In this way, the user can determine whether the generated code 502 meets the requirements based on the coding process analysis 503 and then decide the type of feedback to be provided to the generated code 502.

[0148] In some possible implementations, when the feedback is rejection or revision, the code development platform 10 may also update the code generation model based on the user's feedback on the generated code 502. For example, the code development platform 10 may construct the revised code, along with related input information and context, as training data and update it into the training dataset for subsequent updates to the code generation model. This can improve the accuracy of the code generation model's reasoning and enhance output precision.

[0149] Compared with file-level context awareness, the code generation method of this application takes into account the diversity of project-level context scope and types, expands the context scope to the entire project, and is closer to the background knowledge range required by human developers in actual programming. Moreover, by extracting context from multiple dimensions for the entire project, it can accurately perceive and obtain project-level context that is helpful for the current code generation task for code generation, thereby improving the code generation effect of the code generation model in actual development scenarios, especially improving the generation ability of object-oriented programs and codes that rely on custom types / methods, and significantly improving the generation effect of object-oriented code.

[0150] Furthermore, compared to uploading the context in plain text form to the server and inputting it into the code generation model, this application supports preprocessing the context locally on the user, such as abstracting it into an interface declaration. On the one hand, this compresses the context length and allows a wider range of context to be included with the same length of input. On the other hand, it also reduces the risk of privacy data leakage in user code to a certain extent.

[0151] The embodiment of Figure 2 introduces the code generation method. The following describes the multi-dimensional project-level context perception and extraction, context importance quantification and intelligent recommendation, and context reorganization process in the code generation method with an example.

[0152] 6 shows a flowchart of context processing in the reasoning phase, which may include the following stages:

[0153] Phase 1: The code development platform 10 constructs a project structure diagram and determines a sub-diagram from the project structure diagram.

[0154] Specifically, for a project, the code development platform 10 (e.g., an IDE) typically provides a more powerful and accurate project-level analysis tool that can analyze the open project (e.g., the current project) as a whole. The analysis results can be utilized through the plug-in API as a source of context for the reasoning phase. The analysis results may include hierarchical and dependency information (e.g., reference relationships) between various types within the project. The code development platform 10 can use the above analysis results as a project index and cache them.

[0155] The code development platform 10 can obtain a project hierarchy tree (for example, the project structure in Figure 6), add edges to the project hierarchy tree based on the project index or cache, and thus convert the project hierarchy tree into a project structure diagram that models the hierarchy and reference relationships between various types within a project. For code generation tasks, the code development platform 10 can determine the code scope that the method has the authority to access or call based on the location of the code generation task (for example, the target method requested to be generated) in the project structure diagram, the access control permissions of the class (such as public / private / default, etc.), and the hierarchy and reference relationships involving the class. As shown in Figure 6, the code scope can be represented by a subgraph of the project structure diagram. Based on this, the subgraph can also be called a context scope diagram.

[0156] Compared with using a syntax tree parser, this application can effectively use the project index or cache provided by the IDE. On the one hand, it can provide more accurate and complete analysis results, thereby improving the accuracy of code generation. On the other hand, it will bring additional analysis costs (considering that code generation is usually an activity with high real-time requirements and the model itself requires time reasoning. This method uses project indexes, does not require additional analysis, shortens response time, and avoids the cost increase caused by additional analysis).

[0157] At this stage, the code development platform 10 can also obtain code submission records for subsequent evolutionary coupling analysis.

[0158] Phase 2: The code development platform 10 partitions the code within the file.

[0159] The code development platform 10 divides the source code file (e.g., the first code file) containing the code generation task into two parts: the part before the target method is called the context, and the part after the target method is called the context. The context generally includes package and import statements, the signature of the class, and some declarations of the class (e.g., member variables, constructors, and some methods); while the context generally includes other method declarations of the class.

[0160] Among them, the import statement can be further divided into the internal import statement of the project and the library file import statement. Among them, the internal import statement of the project is used to import other code files within the project. The library file import statement is used to import the standard library or the third-party library. Since the internal import statement of the project can be used to determine the cross-file context, the code development platform 10 can partition or divide the internal import statement of the project and the library file import statement. As shown in Figure 6, the code development platform 10 can partition the context, input information, and context in the first code file, wherein the context can also be divided into the partition of the package statement and the internal import statement of the project, the partition of the library file import statement, and the partial declaration partition of the class. Among them, different partitions can be distinguished by different styles, such as different fill colors.

[0161] In stage 3, the code development platform 10 can obtain multi-dimensional project-level context through multi-dimensional project-level context perception and extraction.

[0162] Specifically, the code development platform 10 can obtain the code content of other code files in the project used in the first file based on the edges in the project structure diagram and the import statements in the first code file, such as the internal import statements of the project, thereby obtaining the first cross-file context.

[0163] The code development platform 10 can obtain the internal import statements and file context of the project based on the subgraph corresponding to the code generation task. The file context includes at least one of the library file import statement, the class to which the code generation task belongs, the previous context of the first code file, or the following context of the first code file. The code development platform 10 then obtains the dependent class of the belonging class based on the internal import statement of the project, and obtains the first cross-file context based on the dependent class. The first cross-file context may include at least one of the member variable name, method signature, constant, and access control keyword in the dependent class.

[0164] The code development platform 10 can also rely on the IDE's API to detect the code files within the project that the developer is focusing on and extract the second cross-file context. Furthermore, the code development platform 10 can also extract the third cross-file context by analyzing the evolutionary correlation of the code files that are highly evolutionarily coupled with the file containing the current code generation task.

[0165] Phase 4: The code development platform 10 performs context screening and sorting.

[0166] The project-level context may exceed the context limit of the language model. Therefore, the code development platform 10 can also filter out the part of the project-level context that is most likely to be related to the current method based on the description, method name, return type, parameter type and other information of the method to be generated by identifier similarity. The code development platform 10 can sort the filtered contexts (for example, cross-file contexts with high relevance). Among them, the code development platform 10 can also uniformly adjust the filtered contexts to the position before the input information to reduce the probability of being truncated when entering the code generation model, and increase the weight of the filtered context on the method body generation by reducing the distance.

[0167] Phase 5: The code development platform 10 performs context reorganization.

[0168] The code development platform 10 abstracts the cross-file context of files. For example, it removes comments, variable assignments, method bodies, and other information from the cross-file code, retaining only the hierarchical structure and identifier information to compress the context information. Furthermore, the code development platform 10 abstracts the context code into a grammatically correct interface declaration form to reuse the programming language grammar knowledge learned by the model during unsupervised pre-training. The code development platform 10 then organizes the positions of the various contexts in the prompt in descending order of context importance.

[0169] Compared to adding cross-file context only in the inference phase, this solution also supports aligning training tasks with inference tasks, thereby focusing on improving the code generation model's ability to perceive and utilize context, and achieving better results and experience in actual use. Among them, the code development platform 10 can obtain training data including cross-file context, for example, training data including multi-dimensional cross-file context, and based on the training data, directly pre-train, multi-stage pre-train or fine-tune the base model to obtain a code generation model. The following describes the model training process in the training phase in conjunction with the embodiment.

[0170] During the training phase, this solution aims to provide a common training data processing solution and format across models. Therefore, it can be used to pre-train code generation models from random initialization, as well as to perform targeted tuning training on existing code generation models.

[0171] The core of this stage is multi-dimensional project-level context awareness. Unlike typical data processing methods that use source files as the basic unit, this application's solution uses projects as the basic unit and specifically includes the following steps:

[0172] Step 1: Analyze the project structure of the entire project and represent the project structure as a tree structure with functions / methods as leaf nodes;

[0173] Step 2: Filter out leaf nodes that meet the criteria.

[0174] Specifically, the project's methods are filtered to find complete methods that meet the specified conditions. These conditions may include, but are not limited to, a non-empty method body and non-special methods. Special methods can be configured by the user, such as get / set / constructor / toString / hashCode methods.

[0175] Step 3: For each method, determine the context scope and extract information from the context and perform desensitization processing.

[0176] Step 4: Take the project-level context, method annotation (if any), and method signature of each leaf node as input, and the method body code as the expected output to form a training data.

[0177] Step 5: After the above processing, the methods in multiple software code repositories together constitute a training dataset for model pre-training or tuning of existing models.

[0178] The following describes possible implementation solutions for this application in the training phase from the aspects of model architecture, training methods, data processing, etc.

[0179] Considering that the causal language model based on the Transformer decoder architecture has good results in the field of code generation, this solution uses the GPT model as the base model to perform model training and obtain a code generation model. Figure 7 shows a schematic diagram of a model architecture based on a transformer decoder. The model can include a transformer decoder and a token embedding layer and a position embedding layer. The decoder can include a feedforward neural network (FNN) and a masked multi-head attention layer. The training data can be encoded by the token embedding layer and the position embedding layer, and then input into the transformer decoder for decoding.

[0180] In order to adapt to the input format requirements of GPT, it is usually necessary to process the context information into a sequence form, while taking into account the characteristics of the language model and trying to conform to the grammatical rules of the programming language itself.

[0181] During the training phase, the current training method generally uses a single source code file as a unit, and generates training data / samples through a sliding window algorithm. FIG8 shows a structure of training data including file-level context, and the above data only contains context information within a certain range at the file level. In order to specifically improve the model's ability to perceive and utilize project-level context information, this solution processes the training data through the technology introduced above, expands the context range and compresses the context content. After the context extraction is completed, different types of information are spliced ​​in the order of project-level context, file-level context, class-level context, method comments, and method code snippets. Furthermore, the code generation platform 10 can use special tokens (such as <--xl_start-->, <comment> 、 <java>etc.) mark the starting position of different information, so that different loss update strategies can be formulated for different types of information during training. The format of a piece of training data after processing can be shown in Figure 9.

[0182] The process of converting training data into a computable tensor format is similar to other models. Specifically, a specially constructed tokenizer and vocab are used to convert each word (token) in the training data into its corresponding index in the vocab, forming a sequence of the corresponding index of each word in the data. The vector representation of the corresponding word in the word embedding model is then obtained through the index. The vector representations of multiple samples are combined into a word vector matrix and fed into the base model for training.

[0183] Code generation models generally use a pretrain-finetune paradigm for model training and optimization. During the pretraining phase, the model learns the language's syntax and patterns through unsupervised training on a large corpus of data. During the finetuning phase, data is processed specifically based on downstream task objectives, and targeted optimization is performed through supervised learning.

[0184] Depending on the optimization objectives, this solution can be applied to different stages:

[0185] Direct pretraining: Start training directly from a randomly initialized model.

[0186] Multi-stage pretraining: Based on a pretrained model, replace the data, modify the hyperparameters and continue training.

[0187] Fine-tuning: Based on a pre-trained model, fine-tune the model through training methods such as instruction tuning and prompt tuning.

[0188] This solution trains the model by predicting the next word based on the existing word (Next Token Prediction), but only calculates the target code part to be predicted (for example, <java>The loss value of this part is used to update the model weights, thereby specifically optimizing the model's prediction ability for the code implementation part under the premise of known project-level context information and the current method function description.

[0189] Next, the solution of this application is introduced from the perspective of front-end interface and human-computer interaction.

[0190] Similar to similar code generation tools and intelligent programming assistants, this application is primarily implemented as an extension or plug-in for a code editor or IDE. Therefore, the front-end interface is a code generation, completion, or coding assistance tool embedded in the IDE. This example generates method-level code examples for a Java-specific IDE.

[0191] Figure 10 shows a schematic diagram of the front-end interface of a code generation plug-in. After a user enters comments and method declarations to trigger code generation, the plug-in executes the aforementioned code generation method to obtain generated code. This generated code can be the method body code. The front-end interface also includes controls for accepting, viewing the next set of generated code controls, and recommending more generated code controls. Users can trigger corresponding controls to implement corresponding functions.

[0192] It's important to note that most code generation tools offer the experience shown in Figure 10. Unlike these tools, this solution provides the following options, allowing users to explicitly select and control the cross-file contexts involved in code generation. As shown in Figure 11, the front-end interface allows users to explicitly select the cross-file contexts for code generation through a dialog.

[0193] How to make intelligent programming assistants cooperate with existing code development and management tools, how to make the human-computer interaction logic of programming assistants more in line with developers' development habits, and how to present code generation technology and the product form of programming assistants still need to be continuously explored in practice.

[0194] Next, we will give an example of human-computer interaction engineering.

[0195] As shown in Figure 12, current tools typically only send a text request to the backend model for inference based on the context within a certain range around the code generation point in the current file. For example, in the figure, the trigger position is after the signature of the init() method (i.e., the cursor is at line 19). If the backend model input window is 1024, the plugin will input a maximum of 1024 tokens before and after the cursor position into the model, including the init() method declaration, comments, member variable declarations above init(), class declarations, and import statements. Some models (such as Meta's InCoder) also allow other content below init() as input. With this input, since the information obtained is mostly the current file content, the model tends to generate code implementations that appear frequently in the training data, such as directly implementing from scratch using classes such as ServerSocket and ServerHandler. This result is too low-level and may include code from other projects and unimported dependencies, which does not meet user expectations.

[0196] Applying the project-level context-aware mechanism proposed in this solution, if configured as shown in Figure 7, the code generation plug-in (plug-in side) first analyzes the location of the current task point and then performs the following steps:

[0197] File context analysis: First, the current file content is segmented into the project's internal import statements, standard library import statements, third-party library import statements, the class containing the task point, and the current file's context. For the project's internal import statements, external file context analysis is used to expand and extract dependencies. For standard library and third-party library import statements, they are retained as part of the input. For the current file's context and context, they are retained as part of the input.

[0198] Out-of-file context analysis: Analyze other classes (or interfaces, enumeration types, etc.) in the project that the current class depends on through package and import statements, expand their contents, analyze the member variable names, method signatures, constants, and their access control keywords (such as public / private / default / friendly, etc.) defined therein, and remove specific assignment statements, initialization blocks, method bodies, etc., to achieve the purpose of code interface abstraction. For context filtering and sorting, first filter the information accessible to the generation point based on the relationship between the package where the generation task is located and the package where the current class is located; then sort the accessible information based on the similarity between the identifier and the method name / comment where the generation task is located.

[0199] For the example in Figure 12, after the above steps, the final context information obtained includes: (1) the createServer() method declaration in the util.Helper class; (2) the Java standard library imported by the current file; (3) the member variable ip declared in the current Server class; and (4) the start() method defined in the current Server class after the generation point. This context information will be attached to the prompt and input into the code generation model, making it easier for the code generation model to generate code implementations that are relevant to the current project context and reuse existing packages as much as possible, thereby better meeting user expectations.

[0200] As shown in Figure 13, users can trigger cross-file context extraction by right-clicking in the editing area to open the menu bar and selecting Cross-File Code Generation. The extracted cross-file context and input information, such as the code generation task description, are then combined into a prompt. This combined prompt is then fed into the code generation model for inference. The generated result is shown in Figure 14. If the user accepts the generated code, the code generation task is complete.

[0201] It should be noted that the core idea of ​​this application is to achieve a certain balance between the model's requirements for contextual information and the security of the user's local code / privacy data through selective perception of project-level context information, under the premise that the code generation model based on the causal language model has a limited acceptable input window, so as to help developers better utilize code generation tools to improve the efficiency of software development. With the recent rapid advancement of code generation tools based on large models in technology and business, more and more users have begun to pay attention to privacy and security issues during use. This application proposes a better solution to address privacy and security issues. It can not only be implemented as a capability or plug-in of a local IDE, but also as a function of a cloud IDE, deployed and used in the form of a cloud service.

[0202] Based on the aforementioned code generation method, the present application further provides a code development platform 10. As shown in FIG15 , the code development platform 10 includes:

[0203] Interaction module 1502, configured to receive user input information of a first code file in a project, the input information including at least one of task description information of a code generation task or input code;

[0204] Context extraction module 1504 is configured to obtain an intra-file context and a first cross-file context based on the static structure of the project, obtain a second cross-file context based on the behavioral characteristics of the user in developing the project, and obtain a third cross-file context based on the evolutionary coupling between at least one second code file and the first code file in the project's code repository, where the intra-file context is the context within the first code file, and the cross-file context is the context within code files in the project other than the first code file.

[0205] Prompt module 1506, configured to generate prompt information based on input information, intra-file context, first cross-file context, second cross-file context, and third cross-file context;

[0206] A generation module 1508 is configured to input the prompt information into a code generation model for reasoning to obtain at least one set of generated codes;

[0207] The interaction module 1502 is further configured to display at least one set of generated codes to the user.

[0208] The interaction module 1502, the context extraction module 1504, the prompt module 1506, and the generation module 1508 may be modules in the aforementioned reasoning platform 100. For example, the interaction module 1502, the context extraction module 1504, the prompt module 1506, and the generation module 1508 may be implemented by hardware or by software.

[0209] When implemented through software, the interaction module 1502, context extraction module 1504, prompt module 1506, and generation module 1508 can be applications running on a computing device, such as a computing engine. Applications can be virtualized through virtualization services and provided to users. Virtualization services can include virtual machine (VM) services, bare metal server (BMS) services, and container services. VM services can be services that use virtualization technology to create a virtual machine (VM) resource pool on multiple physical hosts to provide VMs for users to use on demand. BMS services are services that create a virtual BMS resource pool on multiple physical hosts to provide BMSs for users to use on demand. Container services are services that create a virtual container resource pool on multiple physical hosts to provide containers for users to use on demand. A VM is a simulated virtual computer, that is, a logical computer. BMS is a high-performance computing service that is elastically scalable and has computing performance no different from that of a traditional physical machine, with the characteristics of secure physical isolation. Containers are a kernel virtualization technology that provides lightweight virtualization to isolate user spaces, processes, and resources. It should be understood that the VM service, BMS service, and container service mentioned above are merely specific examples. In actual applications, virtualization services can also include other lightweight or heavyweight virtualization services, which are not specifically limited here.

[0210] When implemented through hardware, the interaction module 1502, the context extraction module 1504, the prompt module 1506, and the generation module 1508 may include at least one computing device, such as a server. Alternatively, the interaction module 1502, the context extraction module 1504, the prompt module 1506, and the generation module 1508 may be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0211] In some possible implementations, the context extraction module 1504 is specifically configured to:

[0212] A second cross-file context is obtained based on at least one of the metadata of an opened code file, the editing popularity of a code file in a project, or a user's search history in a development project. The metadata of the opened code file includes at least one of a relative position relationship of a class, a member, a method in the opened code file, or an editor of the opened code file.

[0213] In some possible implementations, the context extraction module 1504 is further configured to:

[0214] Obtain the user's behavioral characteristics in the development project through the behavior perception interface.

[0215] In some possible implementations, the context extraction module 1504 is further configured to:

[0216] Get the commit record of the code repository;

[0217] According to the commit record of the code repository, an evolutionary coupling analysis is performed on at least one second code file and a first code file in the code repository of the project to obtain an evolutionary coupling degree between the at least one second code file and the first code file.

[0218] In some possible implementations, the context extraction module 1504 is specifically configured to:

[0219] Build a project structure diagram based on the static structure of the project. The static structure includes the hierarchical structure of the project. The hierarchical structure includes the hierarchical relationship of modules, packages, classes or code blocks in the project. The project structure diagram includes the hierarchical relationship and dependency information.

[0220] According to the position of the code generation task in the project structure diagram, obtain the subgraph corresponding to the code generation task;

[0221] According to the subgraph corresponding to the code generation task, obtain the intra-file context and the first cross-file context.

[0222] In some possible implementations, the context extraction module 1504 is specifically configured to:

[0223] Obtaining, according to the subgraph corresponding to the code generation task, an internal import statement and an intra-file context of the project, where the intra-file context includes at least one of a library file import statement, a category of the code generation task, a context above the first code file, or a context below the first code file;

[0224] According to the internal import statement of the project, the dependent class of the belonging class is obtained, and the first cross-file context is obtained according to the dependent class. The first cross-file context includes at least one of the member variable name, method signature, constant, and access control keyword in the dependent class.

[0225] In some possible implementations, the prompt module 1506 is specifically configured to:

[0226] Abstracting at least one of the intra-file context, the first cross-file context, the second cross-file context, or the third cross-file context into a grammatically correct interface declaration;

[0227] Generate prompt information through the prompt project based on input information and interface declaration.

[0228] In some possible implementations, the prompt module 1506 is further configured to:

[0229] sorting cross-file contexts according to at least one of access rights, topological distance, editing heat, semantic similarity, or evolutionary coupling;

[0230] The prompt module 1506 is specifically used for:

[0231] According to the input information, the context within the file, the first cross-file context, the second cross-file context and the third cross-file context, the prompt information is assembled in combination with the sorting results of the cross-file context.

[0232] In some possible implementations, the prompt module 1506 is specifically configured to:

[0233] Start marks are added to different types of information in input information, in-file context, first cross-file context, second cross-file context, and third cross-file context to generate prompt information.

[0234] In some possible implementations, the code development platform 10 further includes:

[0235] The training module 1509 is used to obtain training data including cross-file context, and perform direct pre-training, multi-stage pre-training or fine-tuning on the base model based on the training data to obtain a code generation model.

[0236] The training module 1509 may be a module in the aforementioned training platform 200. For example, the training module 1509 may be implemented by hardware or software.

[0237] When implemented via software, training module 1509 can be an application running on a computing device, such as a VM service, a BMS service, or a container service. When implemented via hardware, training module 1509 can include at least one computing device, such as a server. Alternatively, training module 1509 can be implemented using an ASIC or a PLD.

[0238] This application also provides a computing device 1600. As shown in Figure 16, computing device 1600 includes a bus 1602, a processor 1604, a memory 1606, and a communication interface 1608. Processor 1604, memory 1606, and communication interface 1608 communicate with each other via bus 1602. Computing device 1600 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in computing device 1600.

[0239] Bus 1602 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, among others. Buses may be classified as address buses, data buses, control buses, and the like. For ease of illustration, FIG16 shows only one line, but this does not imply a single bus or type of bus. Bus 1602 may include a path for transmitting information between various components of computing device 1600 (e.g., memory 1606, processor 1604, and communication interface 1608).

[0240] The processor 1604 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0241] The memory 1606 may include a volatile memory, such as a random access memory (RAM). The memory 1606 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD). The memory 1606 stores an executable program code, and the processor 1604 executes the executable program code to implement the aforementioned code generation method. Specifically, the memory 1606 stores instructions for the code development platform 10 to execute the code generation method.

[0242] The communication interface 1608 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 1600 and other devices or a communication network.

[0243] Embodiments of the present application also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.

[0244] As shown in Figure 17, the computing device cluster includes at least one computing device 1600. The memory 1606 of one or more computing devices 1600 in the computing device cluster may store the same code development platform 10 for executing instructions of the code generation method.

[0245] In some possible implementations, one or more computing devices 1600 in the computing device cluster may also be used to execute some of the instructions for executing the code generation method on the code development platform 10. In other words, a combination of one or more computing devices 1600 may jointly execute the instructions for executing the code generation method on the code development platform 10.

[0246] It should be noted that the memory 1606 in different computing devices 1600 in the computing device cluster may store different instructions for executing part of the functions of the code development platform 10 .

[0247] FIG18 illustrates a possible implementation. As shown in FIG18 , two computing devices 1600A and 1600B are connected via a communication interface 1608. The memory in computing device 1600A stores instructions for executing the functions of interaction module 1502, context extraction module 1504, and prompt module 1506. The memory in computing device 1600B stores instructions for executing the functions of generation module 1508. Optionally, the memory in computing device 1600B also stores instructions for executing the functions of training module 1509. In other words, the memories 1606 of computing devices 1600A and 1600B jointly store instructions for the code development platform 10 to execute the code generation method.

[0248] The connection method between the computing device clusters shown in Figure 18 can be considered to consider that the code generation method provided in this application requires a lot of computing power for model reasoning. Therefore, it is considered to hand over the functions implemented by the generation module 1508 for model reasoning to the computing device 1600B.

[0249] It should be understood that the functionality of the computing device 1600A shown in FIG18 may also be implemented by multiple computing devices 1600. Similarly, the functionality of the computing device 1600B may also be implemented by multiple computing devices 1600.

[0250] In some possible implementations, one or more computing devices in a computing device cluster may be connected via a network. The network may be a wide area network (WAN) or a local area network (LAN), among others. FIG. 19 illustrates a possible implementation. As shown in FIG. 19 , two computing devices 1600C and 1600D are connected via a network. Specifically, the network is connected via a communication interface in each computing device. In this type of possible implementation, the memory 1606 in the computing device 1600C stores instructions for executing the functions of the interaction module 1502, the context extraction module 1504, and the prompt module 1506. Simultaneously, the memory 1606 in the computing device 1600D stores instructions for executing the functions of the generation module 1508.

[0251] The connection method between the computing device clusters shown in Figure 19 can be that considering that the code generation method provided in this application requires a lot of computing power to perform model reasoning to generate code, it is considered to entrust the functions implemented by the generation module 1508 to the computing device 1600D for execution.

[0252] It should be understood that the functionality of the computing device 1600C shown in FIG19 may also be implemented by multiple computing devices 1600. Similarly, the functionality of the computing device 1600D may also be implemented by multiple computing devices 1600.

[0253] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the above-mentioned code development platform 10 for executing the code generation method.

[0254] The present application also provides a computer program product comprising instructions. The computer program product may be software or a program product comprising instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the aforementioned code generation method.

[0255] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the protection scope of the technical solutions of the various embodiments of the present invention.< / java> < / java> < / comment>

Claims

1. A code generation method, characterized in that: The method comprises: The code development platform receives input information of a first code file in a project from a user, wherein the input information includes at least one of task description information of a code generation task or input code; The code development platform obtains an in-file context and a first cross-file context according to the static structure of the project, obtains a second cross-file context according to the behavioral characteristics of the user in developing the project, and obtains a third cross-file context according to the evolutionary coupling degree between at least one second code file in the code repository of the project and the first code file, wherein the in-file context is a context within the first code file, and the cross-file context is a context within a code file in the project other than the first code file; The code development platform generates prompt information according to the input information, the intra-file context, the first cross-file context, the second cross-file context and the third cross-file context; The code development platform inputs the prompt information into a code generation model for reasoning to obtain at least one set of generated codes; The code development platform displays the at least one set of generated codes to the user.

2. The method according to claim 1, characterized in that The acquiring a second cross-file context according to the behavior characteristics of the user in developing the project includes: The code development platform obtains a second cross-file context based on at least one of the metadata of an opened code file, the editing popularity of the code file in the project, or the search record of the user in developing the project, wherein the metadata of the opened code file includes at least one of the relative position relationship of the class, member, method in the opened code file, or the editor of the opened code file.

3. The method according to claim 2, characterized in that The method further comprises: The code development platform obtains the behavior characteristics of the user in developing the project through a behavior perception interface.

4. The method according to claim 1, characterized in that: The method further comprises: The code development platform obtains the submission record of the code repository; The code development platform performs an evolutionary coupling analysis on at least one second code file in the code repository of the project and the first code file according to the submission record of the code repository to obtain an evolutionary coupling degree between the at least one second code file and the first code file.

5. The method according to claim 1, characterized in that The code development platform obtains the intra-file context and the first cross-file context according to the static structure of the project, including: The code development platform constructs a project structure diagram according to the static structure of the project, wherein the static structure includes a hierarchical structure of the project, the hierarchical structure includes a hierarchical relationship among modules, packages, classes or code blocks in the project, and the project structure diagram includes the hierarchical relationship and dependency information; The code development platform obtains a subgraph corresponding to the code generation task according to the position of the code generation task in the project structure diagram; The code development platform obtains the intra-file context and the first cross-file context according to the subgraph corresponding to the code generation task.

6. The method according to claim 5, characterized in that The code development platform obtains the intra-file context and the first cross-file context according to the subgraph corresponding to the code generation task, including: The code development platform obtains, according to the subgraph corresponding to the code generation task, an internal import statement of the project and the in-file context, wherein the in-file context includes at least one of a library file import statement, a category of the code generation task, a context above the first code file, or a context below the first code file; The code development platform obtains the dependent class of the belonging class according to the internal import statement of the project, and obtains the first cross-file context according to the dependent class, wherein the first cross-file context includes at least one of the member variable name, method signature, constant, and access control keyword in the dependent class.

7. The method according to any one of claims 1 to 6, characterized in that: The code development platform generates prompt information according to the input information, the intra-file context, the first cross-file context, the second cross-file context, and the third cross-file context, including: Abstracting at least one of the in-file context, the first cross-file context, the second cross-file context, or the third cross-file context into a grammatically correct interface declaration; Prompt information is generated through a prompt project according to the input information and the interface declaration.

8. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: The code development platform sorts the cross-file context according to at least one of access rights, topological distance, editing heat, semantic similarity, or evolutionary coupling; The code development platform generates prompt information according to the input information, the intra-file context, the first cross-file context, the second cross-file context, and the third cross-file context, including: The code development platform assembles prompt information according to the input information, the context within the file, the first cross-file context, the second cross-file context and the third cross-file context in combination with the sorting result of the cross-file context.

9. The method according to any one of claims 1 to 8, characterized in that: The code development platform generates prompt information according to the input information, the intra-file context, the first cross-file context, the second cross-file context, and the third cross-file context, including: The code development platform adds a start mark to different types of information in the input information, the in-file context, the first cross-file context, the second cross-file context and the third cross-file context to generate prompt information.

10. The method according to any one of claims 1 to 9, characterized in that: The code generation model is obtained in the following way: Obtain training data including cross-file context; According to the training data, the base model is directly pre-trained, multi-stage pre-trained or fine-tuned to obtain the code generation model.

11. A code development platform, characterized in that: The code development platform includes: An interaction module, configured to receive input information of a first code file in a project from a user, wherein the input information includes at least one of task description information of a code generation task or input code; a context extraction module, configured to obtain an intra-file context and a first cross-file context according to a static structure of the project, obtain a second cross-file context according to a behavioral characteristic of the user in developing the project, and obtain a third cross-file context according to an evolutionary coupling degree between at least one second code file in a code repository of the project and the first code file, wherein the intra-file context is a context within the first code file, and the cross-file context is a context within a code file in the project other than the first code file; a prompt module, configured to generate prompt information according to the input information, the intra-file context, the first cross-file context, the second cross-file context and the third cross-file context; A generation module, used for inputting the prompt information into a code generation model for reasoning to obtain at least one set of generated codes; The interaction module is further used to display the at least one set of generated codes to the user.

12. The code development platform according to claim 11, characterized in that: The context extraction module is specifically used for: A second cross-file context is obtained based on at least one of metadata of an opened code file, editing popularity of the code file in the project, or a search record of the user in developing the project, wherein the metadata of the opened code file includes at least one of a relative position relationship of a class, a member, a method in the opened code file, or an editor of the opened code file.

13. The code development platform according to claim 12, characterized in that: The context extraction module is also used to: The behavior characteristics of the user in developing the project are obtained through a behavior perception interface.

14. The code development platform according to claim 11, characterized in that: The context extraction module is also used to: Obtain the submission record of the code repository; According to the submission record of the code repository, an evolutionary coupling analysis is performed on at least one second code file in the code repository of the project and the first code file to obtain an evolutionary coupling degree between the at least one second code file and the first code file.

15. The code development platform according to claim 11, characterized in that: The context extraction module is specifically used for: According to the static structure of the project, a project structure diagram is constructed, wherein the static structure includes a hierarchical structure of the project, the hierarchical structure includes a hierarchical relationship among modules, packages, classes or code blocks in the project, and the project structure diagram includes the hierarchical relationship and dependency information; According to the position of the code generation task in the project structure diagram, obtaining a subgraph corresponding to the code generation task; According to the subgraph corresponding to the code generation task, an intra-file context and a first cross-file context are obtained.

16. The code development platform according to claim 15, characterized in that: The context extraction module is specifically used for: According to the subgraph corresponding to the code generation task, the internal import statement of the project and the context in the file are obtained, wherein the context in the file includes the library file import statement, the category of the code generation task, the context of the first code file or the first code file. At least one of the following items in the document; According to the internal import statement of the project, the dependent class of the belonging class is obtained, and the first cross-file context is obtained according to the dependent class, wherein the first cross-file context includes at least one of the member variable name, method signature, constant, and access control keyword in the dependent class.

17. The code development platform according to any one of claims 11 to 16, characterized in that: The prompt module is specifically used for: Abstracting at least one of the in-file context, the first cross-file context, the second cross-file context, or the third cross-file context into a grammatically correct interface declaration; Prompt information is generated through a prompt project according to the input information and the interface declaration.

18. The code development platform according to any one of claims 11 to 17, characterized in that: The prompt module is also used for: sorting the cross-file contexts according to at least one of access rights, topological distance, editing heat, semantic similarity, or evolutionary coupling; The prompt module is specifically used for: Prompt information is obtained by assembling the input information, the context in the file, the first cross-file context, the second cross-file context and the third cross-file context in combination with the sorting result of the cross-file context.

19. The code development platform according to any one of claims 11 to 18, characterized in that: The prompt module is specifically used for: A start mark is added to different types of information in the input information, the in-file context, the first cross-file context, the second cross-file context, and the third cross-file context to generate prompt information.

20. The code development platform according to any one of claims 11 to 19, characterized in that: The code development platform also includes: The training module is used to obtain training data including cross-file contexts, and perform direct pre-training, multi-stage pre-training or fine-tuning on the base model according to the training data to obtain the code generation model.

21. A computing device cluster, characterized in that: The computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory, wherein the at least one memory stores computer-readable instructions; the at least one processor executes the computer-readable instructions so that the computing device cluster executes the code generation method according to any one of claims 1 to 10.

22. A computer-readable storage medium, characterized in that: The method comprises computer-readable instructions; the computer-readable instructions are used to implement the code generation method according to any one of claims 1 to 10.

23. A computer program product, characterized in that The method comprises computer-readable instructions; the computer-readable instructions are used to implement the code generation method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Code generation method and related equipment

    CN119960823A

  • A method and a device for automatically generating codes

    CN109634607A

  • Cross-project programming task context prediction method

    CN114115893A

  • System for generating functionality representation, indexing, searching, componentizing, and analyzing of source code in codebases and method thereof

    US20180373507A1

  • CN202311473710A

Cited By

  • Game function development system and method based on natural language instruction

    CN120560648A

  • Code adaptation method and related device for version upgrading of Android system

    CN120892088A

  • Code adoption rate determination method and device, medium, electronic equipment and product

    CN121050713A