Code generation method and related device

By linking the main plugin and the extended plugins, the problem of low user acceptance and code usability of the LLM intelligent programming assistant product in real development scenarios has been solved, enabling flexible expansion and customized code generation, and improving the code generation effect and adaptability.

WO2025251618A1PCT designated stage Publication Date: 2025-12-11HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD

Patent Information

Application Number
PCT/CN2025/070416
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-08-09
Filing Date
2025-01-03
Publication Date
2025-12-11

AI Technical Summary

Technical Problem

Existing LLM-based intelligent programming assistant products have low user acceptance and code usability rates in real-world development scenarios, and targeted optimization is costly, making process management and code branch maintenance difficult.

Method used

By introducing a linkage mechanism between a main plugin and multiple extension plugins into the code development platform, the main plugin provides basic variables, while the extension plugins provide additional suggestions from the perspectives of programming language, scenario, or development framework. This supports hot-swapping and on-demand combination, enabling flexible expansion and customization, and improving code generation efficiency.

Benefits of technology

It achieves a balance between versatility and customization, reduces the difficulty of process management and version maintenance, improves the accuracy and flexibility of code generation, and adapts to diverse code generation tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025070416_11122025_PF_FP_ABST
    Figure CN2025070416_11122025_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in the present application is a code generation method, which is applied to a code development platform. The code development platform comprises a main plug-in and a plurality of extension plug-ins, wherein the main plug-in is used for providing an actual value of a basic variable of a prompt, and the plurality of extension plug-ins are used for extending the prompt in terms of a programming language, scenario or development framework. The method comprises: a main plug-in receiving a code generation instruction, and then determining, in response to the code generation instruction, at least one extension plug-in corresponding to the code generation instruction from among a plurality of extension plug-ins; the main plug-in receiving a prompt returned by the at least one extension plug-in, wherein the prompt is obtained by means of the at least one extension plug-in extracting an actual value of an extension variable on the basis of extraction logic and replacing an extension variable in a prompt template with the actual value of the extension variable; the main plug-in performing inference by means of a language model and on the basis of the prompt, so as to obtain a second code segment. In the method, a prompt of a specific code generation task and the implementation of prompt engineering is entrusted to corresponding extension plug-ins, thereby realizing flexible extension of prompts.
Need to check novelty before this filing date? Find Prior Art

Description

Code generation method and related device

[0001] The present application claims priority to the Chinese Patent Application No. 202410733816.9, filed on June 6, 2024, entitled “A Code Generation Method and Related Device”, and to the Chinese Patent Application No. 202411098736.7, filed on August 9, 2024, entitled “A Code Generation Method and Related Device”, both of which are incorporated herein by reference in their entirety. TECHNICAL FIELD

[0002] The present application relates to the field of artificial intelligence (AI), 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

[0003] With the increase of software size and complexity, more and more developers try to use artificial intelligence (AI) technology to assist software development, so as to reduce the amount of manual programming work of developers and improve the efficiency of code research and development. In recent years, thanks to the progress of artificial intelligence (AI) research in natural language processing and the breakthrough in large language model (LLM), LLM related achievements have promoted the code generation technology from the academic research stage to the practical application stage, and various intelligent programming assistant products based on LLM have emerged in an endless stream.

[0004] The main functions provided by the intelligent programming assistant products based on LLM include code generation or natural language text to code (Text2Code). Among them, code generation can include the following multiple application scenarios: generating code that can achieve the requirements according to the requirements described by the developer in natural language; generating new code according to the existing code of the developer, or context to code (code2code). The existing code of the developer is the code fragment written by the developer or the example code fragment provided by the developer. Generating new code according to the written code fragment is also called code completion.

[0005] Currently, the LLM-based intelligent programming assistant product usually adopts prompt engineering to expand the knowledge and capability boundaries of the LLM, so as to optimize the code generation effect of the intelligent programming assistant product in the code development project of a real application scenario. For example, in the line-level code generation scenario, the intelligent programming assistant product can add the context such as the subsequent content and the content of the adjacent tab page in the prompt, so as to significantly improve the code generation effect.

[0006] In order to exert the gain of the prompt engineering, it is usually necessary to analyze and develop in specific scenarios. However, the development cost of targeted optimization is high, and the process management and code branch maintenance are extremely difficult. SUMMARY

[0007] The present application provides a code generation method, which delegates the prompt of the code generation task with customized requirements and the implementation of prompt engineering to the corresponding extension plug-in, and makes the main plug-in and the extension plug-in achieve synergistic cooperation through a multi-plug-in linkage mechanism, so as to realize flexible expansion of the prompt and balance between universality and customization. The present application also provides a code development platform, a computing device cluster, a computer readable storage medium and a computer program product corresponding to the above-mentioned method.

[0008] In the first aspect, the present application provides a code generation method. The method is applied to a code development platform. The code development platform includes a main plug-in and a plurality of extension plug-ins. The main plug-in is used to provide actual values of basic variables of the prompt, and the basic variables include at least one of a programming language, a current file path and a current file context. The plurality of extension plug-ins are used to extend the prompt from the dimensions of the programming language, the scenario or the development framework.

[0009] In specific implementation, the main plug-in receives a code generation instruction, and in response to the code generation instruction, determines at least one extension plug-in corresponding to the code generation instruction from the plurality of extension plug-ins. The code generation instruction is used to generate a second code segment according to a natural language description or a first code segment. The code generation instruction can be different according to the type of the code generation task. The at least one extension plug-in corresponding to the code generation instruction provides a prompt template corresponding to the code generation instruction and extraction logic of an extension variable in the prompt template. Then the main plug-in receives the prompt returned by the at least one extension plug-in, the prompt is obtained by the at least one extension plug-in according to the extraction logic to extract the actual value of the extension variable, and the extension variable in the prompt template is replaced by the actual value of the extension variable. Next, the main plug-in performs reasoning through a language model according to the prompt to obtain the second code segment.

[0010] The method determines the extension plug-in corresponding to the code generation instruction, and delegates the prompt of the code generation task with customization requirements (for example, for a specific code generation scenario) and the implementation of the prompt project to the corresponding extension plug-in for implementation. The main plug-in implements the basic functions, and the main plug-in and the extension plug-in achieve collaborative cooperation through the multi-plug-in linkage mechanism, thereby realizing flexible extension of the prompt, targeted optimization for specific code generation scenarios, and improving the code generation effect. Among them, the extension plug-in of the present application supports hot plugging, and the hot pluggable extension plug-in and the main plug-in linkage can realize flexible control of the prompt of the language model, establish a modular, hot plugging, on-demand combination extension mechanism, thereby making the intelligent programming assistant product such as the code development platform have high customizability and extensibility, and achieving a balance between generality and customization.

[0011] In some possible implementation manners, the main plug-in extracts a task feature of the code generation task according to the code generation instruction, the task feature includes at least one of a user dimension feature or a project dimension feature, the user dimension feature includes at least one of a department to which a user belongs, a project group to which the user belongs, or a user identifier, and the project dimension feature includes at least one of a programming language, a development framework, or an application field. The main plug-in determines at least one extension plug-in corresponding to the code generation instruction from a plurality of extension plug-ins according to the task feature.

[0012] The method extracts the task feature of the code generation task, such as the user dimension feature of the department to which the user belongs, the project group to which the user belongs, or the user identifier, or the project dimension feature of the programming language, the development framework, or the application field, and automatically determines the extension plug-in that cooperates with the main plug-in based on the above features, to realize on-demand combination of the plug-in for flexible extension of the prompt.

[0013] In some possible implementation manners, the main plug-in can present a plurality of extension plug-ins to the user in response to the code generation instruction. Then the main plug-in determines at least one extension plug-in corresponding to the code generation instruction in response to the selection operation of the user. Among them, the main plug-in can directly present a plurality of extension plug-ins to the user for selection, or present the extension plug-in determined based on the task feature to the user for selection after determining at least one extension plug-in based on the task feature.

[0014] The method realizes human-computer interaction by the user actively selecting the extension plug-in that cooperates with the main plug-in. The extension plug-in actively selected by the user can more guarantee the accuracy of the extension and improve the code generation effect.

[0015] In some possible implementation manners, the actual value of the extension variable is extracted by the extension plug-in from a project file, a project index, or a knowledge base. The method supports extracting the actual value of the extension variable from different data sources, thereby providing more rich information for the language model and improving the code generation effect.

[0016] In some possible implementation manners, the main plug-in is provided with a registration interface. The main plug-in receives a registration request generated by calling the registration interface by the plurality of extension plug-ins, and the registration request includes at least one of a plug-in identifier, a plug-in version, a plug-in applicable scenario or a plug-in capability. The main plug-in stores registration information of at least one extension plug-in, and the registration information includes at least one of the plug-in identifier, the plug-in version, the plug-in applicable scenario or the plug-in capability. The registration information is used to determine at least one extension plug-in corresponding to the code generation instruction.

[0017] In the method, the main plug-in supports the registration of the extension plug-in on the side of the main plug-in by providing the registration interface. In this way, the main plug-in can match the extension plug-in corresponding to the task characteristics according to the registration information, so as to meet the customization requirement.

[0018] In some possible implementation manners, the main plug-in can assemble the prompt and the actual value of the basic variable to obtain an assembled prompt. The main plug-in inputs the assembled prompt into the language model to obtain the second code segment. In this way, the actual value of the basic variable extracted by the main plug-in and the actual value of the extension variable extracted by the extension plug-in are assembled to obtain a complete prompt, so that the quality of the prompt can be improved, and the accuracy can be improved.

[0019] In a second aspect, the present application provides a code development platform. The code development platform includes a main plug-in and a plurality of extension plug-ins. The main plug-in is used to provide an actual value of a basic variable of a prompt, and the basic variable includes at least one of a programming language, a current file path or a current file context. The plurality of extension plug-ins are used to extend the prompt from the programming language, the scene or the development framework dimension.

[0020] The main plug-in is configured to receive a code generation instruction, the code generation instruction is used to generate a second code segment according to a natural language description or a first code segment, and at least one extension plug-in corresponding to the code generation instruction is determined from the plurality of extension plug-ins in response to the code generation instruction. The at least one extension plug-in provides a prompt template corresponding to the code generation instruction and extraction logic of an extension variable in the prompt template.

[0021] The main plug-in is further configured to receive a prompt returned by the at least one extension plug-in. The prompt is obtained by the at least one extension plug-in according to the extraction logic of the actual value of the extension variable, and the extension variable in the prompt template is replaced by the actual value of the extension variable. Then, according to the prompt, the language model is inferred to obtain the second code segment.

[0022] In some possible implementation manners, the main plug-in is specifically configured to:

[0023] According to the code generation instruction, a task feature of a code generation task is extracted, the task feature including at least one of a user dimension feature or a project dimension feature, the user dimension feature including at least one of a department to which a user belongs, a project group to which the user belongs, or a user identifier, and the project dimension feature including at least one of a programming language, a development framework, or an application field.

[0024] According to the task feature, at least one extension plug-in corresponding to the code generation instruction is determined from the plurality of extension plug-ins.

[0025] In some possible implementation manners, the main plug-in is specifically configured to:

[0026] In response to the code generation instruction, a plurality of extension plug-ins are presented to a user;

[0027] In response to a selection operation of the user, at least one extension plug-in corresponding to the code generation instruction is determined.

[0028] In some possible implementation manners, an actual value of the extension variable is extracted by the extension plug-in from a project file, a project index, or a knowledge base.

[0029] In some possible implementation manners, the main plug-in is provided with a registration interface, and the main plug-in is further configured to:

[0030] A registration request generated by the plurality of extension plug-ins by calling the registration interface is received, the registration request including at least one of a plug-in identifier, a plug-in version, a plug-in applicable scenario, or a plug-in capability;

[0031] Registration information of the at least one extension plug-in is stored, the registration information including at least one of the plug-in identifier, the plug-in version, the plug-in applicable scenario, or the plug-in capability, and the registration information being used to determine at least one extension plug-in corresponding to the code generation instruction.

[0032] In some possible implementation manners, the main plug-in is specifically configured to:

[0033] The prompt and the actual value of the base variable are assembled to obtain an assembled prompt;

[0034] The assembled prompt is input into a language model for inference to obtain the second code snippet.

[0035] In a third aspect, the present application provides a computing device cluster. The computing device cluster comprises at least one computing device, and the at least one computing device comprises at least one processor and at least one memory. The at least one processor and the at least one memory are in communication 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 the computing device cluster performs the code generation method according to the first aspect or any implementation manner of the first aspect.

[0036] In a fourth aspect, the present application provides a computer-readable storage medium, and the computer-readable storage medium stores instructions for instructing a computing device or a computing device cluster to perform the code generation method according to the first aspect or any implementation manner of the first aspect.

[0037] In a fifth aspect, the present application provides a computer program product comprising instructions for causing a computing device or a computing device cluster to perform the code generation method according to the first aspect or any implementation manner of the first aspect when the computer program product is executed on the computing device or the computing device cluster.

[0038] On the basis of the implementation manners of the aspects described above, the present application can be further combined to provide more implementation manners. BRIEF DESCRIPTION OF DRAWINGS

[0039] In order to more clearly illustrate the technical method of the present application, the drawings required for use will be briefly introduced as follows.

[0040] FIG. 1 is a schematic diagram of an architecture of a code development platform according to the present application;

[0041] FIG. 2 is a flowchart of a code generation method according to the present application;

[0042] FIG. 3 is a schematic diagram of code generation scene recognition according to the present application;

[0043] FIG. 4 is a schematic diagram of a code generation method according to the present application;

[0044] FIG. 5 is an example diagram of a prompt template according to the present application;

[0045] FIG. 6 is a flowchart of plug-in linkage in a code generation method according to the present application;

[0046] FIG. 7 is an interface diagram after an extension plug-in is installed according to the present application;

[0047] FIG. 8 is a structural schematic diagram of a computing device according to the present application;

[0048] FIG. 9 is a structural schematic diagram of a computing device cluster according to the present application;

[0049] FIG. 10 is a structural diagram of another computing device cluster provided by the present application;

[0050] FIG. 11 is a structural diagram of still another computing device cluster provided by the present application. DETAILED DESCRIPTION

[0051] The terms “first”, “second” in the embodiments of the present application are only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the technical features indicated. Therefore, the features defined with “first”, “second” can explicitly or implicitly include one or more of the features.

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

[0053] Code Generation refers to automatically generating code to make the code complete or implement the function described in the natural language description according to the input information of the user, such as incomplete code or natural language description, through automated tools or technologies. The automated tools or technologies can include but are not limited to artificial intelligence (AI) tools or technologies. AI technologies include but are not limited to natural language processing (NLP) and deep learning (DL). According to the granularity of the generated code, code generation can include line-level code generation, method-level code (or function-level code) generation, and class-level code generation.

[0054] Large Language Model (LLM) is a language model composed of artificial neural networks with many parameters (usually tens of billions of weights or more), which is trained on a large amount of unlabeled text using self-supervised learning or semi-supervised learning. According to the model architecture, large language models can be divided into different types. The large language models widely used in the field of code generation include Generative Pre-trained Transformer (GPT).

[0055] The intelligent programming assistant product based on a large language model such as GPT is usually a plug-in software (also referred to as a plug-in for short) relying on a code editor or an integrated development environment (IDE). For developers, one of the main functions provided by the intelligent programming assistant product is code generation. The code generation can include natural language text to code (Text2Code) or context to code (Code2Code). The natural language text to code can be to generate code that can achieve the requirements according to the requirements described by the developer in natural language; the context to code can be to generate new code according to the existing code of the developer (such as code completion).

[0056] Among them, the plug-in form of the intelligent programming assistant product can capture the requirements of the developer through a man-machine dialogue mode, and generate corresponding code. Specifically, the developer completes the writing of the code function comment (or simply referred to as the comment) in the process of writing the code, for example, can complete the writing of the code function comment through natural language, and triggers the code generation operation; then, the plug-in can generate a code segment that implements the function described in the comment according to the code function comment and related information (such as context) provided by the developer using the generative pre-training language model GPT; finally, the plug-in presents the code segment to the developer in the form of recommendation, so that the developer decides to accept or reject the recommendation, or accepts it and then further modifies it. Related data shows that the above plug-in can effectively reduce the cost caused by the frequent switching between the actual code writing and the activities of searching for knowledge, consulting documents, and finding reusable components, thereby improving the efficiency of software development.

[0057] Although the basic programming capability of the intelligent programming assistant product based on LLM improves rapidly, when applied to real development scenarios, the user acceptance rate and code availability of such intelligent programming assistant products in actual projects are still low. The effect and benefit of LLM in real development scenarios still have a large gap with the expected effect and benefit.

[0058] Taking the widely used code generation benchmark test set HumanEval as an example, the single generation pass rate of LLM has increased from about 10% in 2021 to nearly 80%, but the data feedback from multiple intelligent programming assistant products (assisted programming tools) shows that the actual user acceptance rate is generally 20-40%, which is much lower than the performance on the benchmark test set. The inventors found through research that the benchmark test set is only composed of 164 simplest and basic self-contained programming tasks, and the self-contained programming task is usually a task that can be implemented through a single function containing at most a dozen lines of code, and the self-contained programming task does not need to rely on third-party libraries or external code. The performance or effect of LLM on the benchmark test set cannot fully reflect the actual programming capability of LLM.

[0059] To improve the effect of the LLM-based intelligent programming assistant product in real development scenarios, some optimization schemes are proposed in the industry, including but not limited to model fine-tuning, retrieval augmented generation (RAG), iteration, or contextual prompt engineering. Among them, model fine-tuning can be supervised fine-tuning of LLM using vertical domain (or vertical domain) data, thereby injecting additional knowledge, task form, specific requirements, etc. RAG can be to retrieve public knowledge bases or vertical domain knowledge bases to introduce reference code, thereby enhancing generated code. Iteration can be a multi-round dialogue-based generation method, providing better results through multiple generation-inspection trial and error, modification. Contextual prompt engineering (Contextual Prompt Engineering), also known as prompt engineering, specifically supplements, enhances, and refines the context required to solve problems, providing accurate inputs for LLM during training and inference.

[0060] Among them, contextual prompt engineering can effectively alleviate the problem that LLM-based intelligent programming assistant products require sufficient context as input, rely on programming frameworks and design patterns used in software development, and generate requirements that are strongly related to specific scenarios. It has the advantages of significant effect, convenient experiment, high certainty, and strong interpretability.

[0061] However, contextual prompt engineering usually needs to focus on certain specific scenarios for customized development, such as targeted optimization for specific languages and frameworks, which results in insufficient generality, portability, and flexibility of code generation functions. When supporting more and more scenarios, process management and code branch maintenance become extremely difficult, and costs also increase.

[0062] Therefore, the present application provides a code generation method. The method can be applied to a code development platform. The code development platform includes a main plug-in and a plurality of extension plug-ins. The main plug-in is used to provide actual values of prompted base variables, thereby providing basic functions. The base variables include at least one of a programming language, a current file path, and a current file context. The plurality of extension plug-ins are used to extend the prompt from the dimensions of the programming language, the scene, or the development framework.

[0063] In a specific implementation, the main plug-in can receive a code generation instruction, the code generation instruction being used to generate a second code segment according to a natural language description or a first code segment. Then the main plug-in determines at least one extension plug-in corresponding to the code generation instruction from a plurality of extension plug-ins in response to the code generation instruction. The at least one extension plug-in provides a prompt template corresponding to the code generation instruction, and extraction logic of an extension variable in the prompt template. The main plug-in receives a prompt returned by the at least one extension plug-in, the prompt being obtained by the at least one extension plug-in by extracting an actual value of the extension variable according to the extraction logic and replacing the extension variable in the prompt template with the actual value, and then the main plug-in can infer according to the prompt through a language model to obtain the second code segment.

[0064] The method can delegate the implementation of the prompt and the implementation of the prompt engineering in the code generation task with customization requirements (for example, for a specific code generation scenario) to the corresponding extension plug-in by determining the extension plug-in corresponding to the code generation instruction, the main plug-in implements the basic function, and the main plug-in and the extension plug-in achieve synergistic cooperation through the multi-plug-in linkage mechanism, thereby realizing flexible extension of the prompt, targeted optimization for the specific code generation scenario, and improving the code generation effect. The extension plug-in of the present application supports hot plugging, and the hot pluggable extension plug-in and the main plug-in linkage can realize flexible control of the prompt of the language model, establish a modular, hot plugging, and on-demand combination extension mechanism, thereby making the intelligent programming assistant product such as the code development platform have high customizability and extensibility, and achieving a balance between generality and customization.

[0065] Moreover, for the case where different versions (for example, internal versions, product line customized versions, external commercial versions, and concept verification versions) need to be developed and maintained, the main plug-in can select the corresponding extension plug-in to generate the corresponding prompt according to the requirements of different versions, thereby reducing the difficulty of process management and version maintenance and reducing the cost. In addition, even if the specific requirements, delivery rhythm, and delivery time of each code generation scenario are inconsistent, the migration and reuse of the corresponding extension plug-in and other modules can be realized, without repeated development for the same function, thereby avoiding the problems of increased workload and conflicts caused by repeated development.

[0066] For ease of understanding, the system architecture of the code development platform of the present application is introduced below with reference to the accompanying drawings.

[0067] Referring to a schematic diagram of an architecture of a code development platform shown in FIG. 1, the code development platform 10 includes a main plug-in 100 and a plurality of extension plug-ins 200. The main plug-in 100 is configured to provide actual values of prompted base variables, the base variables including at least one of a programming language, a current file path, and a current file context. The current file context can be content before and after a cursor in the current file. The plurality of extension plug-ins 200 are configured to extend the prompt from a programming language, a scenario, or a development framework dimension. The plurality of extension plug-ins 200 can include an extension plug-in for a programming language, an extension plug-in for a scenario, or an extension plug-in for a development framework. Each type of extension plug-in can include one or more extension plug-ins. Different types of extension plug-ins are described below.

[0068] The extension plug-in for a programming language is configured to optimize a programming language that is not supported by the main plug-in 100 or a programming language that is not well supported. For example, the extension plug-in for a programming language can include, but is not limited to, an extension plug-in for Ruby, an extension plug-in for Scala, or an extension plug-in for a structured query language (SQL). The extension plug-in for Ruby is denoted as Extension-Ruby, the extension plug-in for Scala is denoted as Extension-Scala, and the extension plug-in for SQL is denoted as Extension-SQL. The extension plug-in for a scenario is configured to optimize a specific code generation scenario (such as a specific vertical field).

[0069] The extension plug-in for a scenario can include, but is not limited to, an extension plug-in for a website development scenario, an extension plug-in for an artificial intelligence development scenario, or an extension plug-in for a specific organization. The extension plug-in for a website development scenario can be denoted as Extension-Web, the extension plug-in for an artificial intelligence development scenario can be denoted as Extension-AI, and the extension plug-in for a specific organization can be an extension plug-in for a specific company, an extension plug-in for a specific enterprise or institution, such as an extension plug-in for xx school or an extension plug-in for yy bank.

[0070] The extension plug-in for a development framework is configured to optimize a project development that follows a specific programming framework. The extension plug-in for a development framework can include, but is not limited to, an extension plug-in for a Spring framework, an extension plug-in for a Vue framework, or an extension plug-in for a Pytorch framework. The extension plug-in for a Spring framework is denoted as Extension-Spring, the extension plug-in for a Vue framework is denoted as Extension-Vue, and the extension plug-in for a Pytorch framework is denoted as Extension-Pytorch.

[0071] Unlike GPT, the code generation task faced by the code development platform 10 based on LLM has high complexity and dynamics due to diversified code engineering projects and time-varying code generation intentions. Accordingly, the complex and dynamically changing code generation task puts extensive and comprehensive requirements on the context content extraction capability of the code development platform 10. On the one hand, the context content includes not only static information, but also dynamic information that needs to be obtained in real time, such as context related to code generation location, knowledge base related data, results returned by tool calls, etc. The acquisition of the above information needs to rely on tools outside the code development platform 10 capability boundary such as program analysis, integrated development environment application programming interface (IDE API), search algorithm, execution environment, etc. On the other hand, in actual application scenarios, the context extraction capability required by different code generation tasks is usually special rather than general, and the strong binding of the context extraction capability with the code generation capability itself is not conducive to the independent evolution of the above special capability.

[0072] Therefore, the present application decouples the context extraction capability from the general capability of the code development platform 10. Specifically, the present application follows the open-closed principle and the separation of concerns principle in architecture design, places the general logic and hints in the main plug-in 100 of the code development platform 10 for implementation, and delegates the implementation of the hints (context hints) and hint engineering that focus on code generation tasks with customization needs (such as specific code generation scenarios) to different extension plug-ins 200 for implementation. The main plug-in 100 is equivalent to an IDE, which provides general basic functions and APIs that can be called by extension plug-ins, and the extension plug-in 200 is equivalent to various plug-ins with rich functions on the plug-in market. Users can download and install as needed to expand the functions not covered by the main plug-in 100 itself. The main plug-in 100 can be associated with a specific extension plug-in 200 through automatic identification of code generation tasks (such as automatic identification of code generation scenarios) or user selection, thereby realizing flexible extension of hints for different code generation tasks.

[0073] The functions of the main plug-in 100 and the extension plug-in 200 will be described in detail below.

[0074] The main plug-in 100 is responsible for implementing the main process of the code generation task, including providing basic variables for hints, which can include at least one of programming language, current file path, and current file context (such as current file content). In this way, the default hints and context can be specified. The main plug-in 100 is also responsible for calling the extension plug-in 200 and communicating with the background service.

[0075] The extension plug-in 200 is responsible for expanding the prompt from the perspective of programming language, scene or development framework. For example, the extension plug-in 200 can specify the prompt template optimized for the scene, the expansion variable in the prompt template that needs to extract the actual value, and the code implementation of the extraction logic. The extension plug-in 200 usually needs to follow the API provided by the main plug-in 100 to register and communicate with the main plug-in 100, and the main plug-in 100 calls and returns the complete prompt with the expansion variable replaced by the actual value of the expansion variable in the agreed format.

[0076] Specifically, the main plug-in 100 is configured to receive a code generation instruction, the code generation instruction being used to generate a second code snippet according to a natural language description or a first code snippet. When the code generation instruction includes the natural language description, the code generation task is a Text2Code task, and when the code generation instruction includes the first code snippet, the code generation task is a Code2Code task. The main plug-in 100 is further configured to determine, in response to the code generation instruction, at least one extension plug-in 200 corresponding to the code generation instruction from a plurality of extension plug-ins 200. The at least one extension plug-in 200 provides a prompt template corresponding to the code generation instruction and extraction logic of an expansion variable in the prompt template. The extension plug-in 200 is configured to extract an actual value of the expansion variable according to the extraction logic and replace the expansion variable in the prompt template with the actual value of the expansion variable to obtain a prompt.

[0077] The main plug-in 100 is further configured to receive the prompt returned by the at least one extension plug-in 200, and infer through a language model according to the prompt to obtain the second code snippet. The language model can be a model for natural language processing, for example, a large language model LLM.

[0078] Based on FIG. 1, the code development platform 10 of the present application constructs a series of extension plug-ins 200 around the main plug-in 100, which is used to improve the effect in a specific scene or cover the unsupported cases. The user can select and install one or more extension plug-ins according to the code generation scene to achieve the effect of 1+N.

[0079] Based on the code development platform 10 of FIG. 1, the present application further provides a code generation method. The code generation method of the present application will be introduced below in combination with specific embodiments.

[0080] Referring to the flowchart of a code generation method shown in FIG. 2, the method can be executed by the code development platform 10 shown in FIG. 1, the code development platform 10 including a main plug-in 100 and a plurality of extension plug-ins 200. The method includes the following steps:

[0081] S202, the main plug-in 100 receives a code generation instruction.

[0082] The code generation instruction is used to generate a second code segment according to a natural language description or a first code segment. The natural language description can be a requirement described in natural language, which can be a function of the code to be generated. Among them, the natural language description can be input in the form of a comment, so that the compiler can not compile the above natural language description, avoiding compilation errors. The first code segment can be a partial code segment of a code block, and the code generation instruction is used to complete the remaining code segment according to the code segment. For example, the code block can be a function, and the first code segment can be a function declaration, and the code generation instruction is used to complete the function body according to the function declaration. Or the first code segment can be an example code segment, and the code generation instruction is used to generate a new code segment according to the example code segment. For ease of description, the code to be generated is collectively referred to as the second code segment.

[0083] In a specific implementation, the host plug-in 100 can receive the code generation instruction through human-computer interaction. For example, the host plug-in 100 can present a code editing interface to the user. The code editing interface can be a native editing interface of a code editor or an IDE, or an interactive interface of a language model such as an LLM. The interactive interface can be a dialogue interface, also known as a question and answer interface. The code editing interface includes but is not limited to a graphical user interface (GUI) or a command user interface (CUI). The graphical user interface can provide a code generation control, and the user can trigger the code generation instruction by clicking or touching the code generation control, so that the host plug-in 100 can receive the code generation instruction through the graphical user interface. In some examples, the user can input the code generation instruction in the command user interface, and the host plug-in 100 receives the code generation instruction input by the user through the command user interface. In addition, the host plug-in 100 also supports code generation instructions in the form of shortcut keys or voice. For example, the user can input a natural language description in the graphical user interface, and then click a shortcut key to trigger the code generation instruction.

[0084] S204, the host plug-in 100 determines at least one extension plug-in 200 corresponding to the code generation instruction from the plurality of extension plug-ins 200 in response to the code generation instruction.

[0085] The at least one extension plug-in 200 corresponding to the code generation instruction can be an extension plug-in 200 covering the capabilities not supported by the main plug-in 100. For example, the main plug-in 100 does not support the Ruby language, and the extension plug-in 200 can include Extension-Ruby. The main plug-in 100 can automatically perform code generation task identification in response to the code generation instruction, and then determine the at least one extension plug-in 200 corresponding to the code generation instruction according to the task identification result. Alternatively, the main plug-in 100 can determine the at least one extension plug-in 200 corresponding to the code generation instruction through human-computer interaction in response to the code generation instruction. The at least one extension plug-in 200 provides a prompt template corresponding to the code generation instruction and extraction logic of an extension variable in the prompt template. The extension variable is used to carry an extended context. The extended context can be a context related to the code generation task, including a dependent library of the project, a development framework used by the project, a cross-file context, or a search result in a knowledge base.

[0086] The following describes multiple implementation manners of determining the at least one extension plug-in 200 corresponding to the code generation instruction.

[0087] In some possible implementation manners, the main plug-in 100 can extract task features of the code generation task according to the code generation instruction. The task features are used to represent the characteristics of the code generation task. As shown in FIG. 3, the task features include at least one of user dimension features or project dimension features. The user dimension features can include at least one of a department to which a user belongs, a project group to which the user belongs, or a user identifier, and the user identifier can be a user name, an employee number, or the like. The project dimension features include at least one of a programming language, a development framework, or an application field. The application field refers to the field to which the project is applied, for example, a financial field, an educational field, or the like. Then the main plug-in 100 determines the at least one extension plug-in 200 corresponding to the code generation instruction from multiple extension plug-ins 200 according to the task features. The extension plug-in 200 can be an extension plug-in matching the task features. For example, when the task features include a Ruby programming language, the extension plug-in 200 corresponding to the code generation instruction can be Extension-Ruby.

[0088] Specifically, the main plug-in 100 is provided with a registration interface (such as a registration API), which is used to support the extension plug-in 200 to register at the side of the main plug-in 100. For example, after installation, the extension plug-in 200 can call the registration interface (such as the registration API) to declare the plug-in identifier (ID), the plug-in version, the plug-in applicable scenario, or the plug-in capability. The plug-in ID can include the plug-in name or the plug-in number. The plug-in applicable scenario refers to the scenario in which the plug-in can be used. The plug-in capability includes the function or capability provided by the plug-in. For example, the extension plug-in 200 can pass the plug-in ID, the plug-in version, the plug-in applicable scenario, or the plug-in capability as an interface parameter into the registration interface, generate a registration request through the registration interface, and send the registration request to the main plug-in 100, where the registration request includes at least one of the plug-in identifier, the plug-in version, the plug-in applicable scenario, or the plug-in capability. The main plug-in 100 stores the registration information of at least one extension plug-in, where the registration information includes at least one of the plug-in identifier, the plug-in version, the plug-in applicable scenario, or the plug-in capability, and the registration information is used to determine the at least one extension plug-in 200 corresponding to the code generation instruction. Based on this, the main plug-in 100 can determine the extension plug-in 200 whose registration information matches the task characteristics successfully according to the task characteristics and the registration information of the at least one extension plug-in 200, so as to obtain the at least one extension plug-in 200 corresponding to the code generation instruction. The at least one extension plug-in 200 corresponding to the code generation instruction can be the above-mentioned extension plug-in 200 whose matching is successful.

[0089] In some possible implementation manners, the main plug-in 100 can present a plurality of extension plug-ins 200 to the user. The plurality of extension plug-ins 200 can be installed extension plug-ins or extension plug-ins related to the project. The user can select the extension plug-in 200 matching the current code generation task from the plurality of extension plug-ins 200. The main plug-in 100 can determine the at least one extension plug-in 200 corresponding to the code generation instruction in response to the selection operation of the user.

[0090] Referring to FIG. 4, an example of a code generation method is shown. In this example, when the user triggers the code generation instruction, the main plug-in 100 of the code development platform 10 presents a configuration interface 400 to the user. The configuration interface 400 can display a plurality of extension plug-ins 200, which can be extension plug-ins related to the project, including but not limited to installed extension plug-ins, updatable extension plug-ins, and uninstalled extension plug-ins. Further, the configuration interface 400 can also display the currently used intelligent agent. The intelligent agent can be an intelligent entity constructed based on a language model such as LLM, and is usually presented in the form of an intelligent agent (AI agent). The user can select at least one extension plug-in 200 corresponding to the code generation instruction from the plurality of extension plug-ins 200 displayed according to the currently used intelligent agent. When the user clicks the optimization input control of the configuration interface 400, the main plug-in 100 can call the at least one extension plug-in 200 corresponding to the code generation instruction to optimize the prompt of the input language model. When the optimization is completed, the user can also trigger a sending operation, and the main plug-in 100 can respond to the sending operation by sending the operation to the determined extension plug-in 200, requesting the extension plug-in 200 to generate the prompt of the code generation task in the agreed format.

[0091] As an extension function of the code editor or IDE, the front-end interface of the code development platform 10 is embodied as a code generation tool, a code completion tool, or an auxiliary coding tool embedded in the IDE. Unlike traditional code generation tools and code completion tools, the front-end interface of the code development platform 10 of the present application supports users to independently select intelligent agents for different code generation tasks (such as code generation tasks in different development scenarios).

[0092] Considering that automatic identification of task characteristics and determination of extension plug-ins 200 according to task characteristics may result in non-optimal matching results, multiple matching results that need to be selected, presentation of all available extension plug-ins, and the required extension plug-ins not being installed, the main plug-in 100 can also prompt the user to independently specify the extension plug-in or install the extension plug-in.

[0093] For example, when the host plug-in 100 determines the multiple extension plug-ins 200 corresponding to the code generation instruction according to the task feature, the host plug-in 100 can further present the multiple extension plug-ins 200 determined according to the task feature to the user. The user can select at least one extension plug-in 200 from the multiple extension plug-ins 200 determined according to the task feature, and the host plug-in 100 determines at least one extension plug-in 200 corresponding to the code generation instruction in response to the selection operation of the user, and generates the code in cooperation with the host plug-in 100. In this way, the accuracy of calling the extension plug-in 200 can be further improved. For another example, when the host plug-in 100 determines that the extension plug-in 200 corresponding to the code generation instruction according to the task feature includes an uninstalled extension plug-in 200, the host plug-in 100 can further present a list of the uninstalled extension plug-in 200 to the user, and the user can trigger an installation operation through an interactive interface such as a GUI or a CUI. The host plug-in 100 obtains an installation package of the above-mentioned extension plug-in 200 from the plug-in market in response to the installation operation triggered by the user, and runs the installation package, thereby achieving the installation of the above-mentioned extension plug-in 200.

[0094] In S206, the extension plug-in 200 extracts the actual value of the extension variable according to the extraction logic of the extension variable, replaces the extension variable in the prompt template with the actual value, and obtains the prompt.

[0095] The extension plug-in 200 can extract the actual value of the extension variable from the project file, the project index or the knowledge base according to the extraction logic of the extension variable, replace the extension variable in the prompt template with the actual value of the extension variable, and thus obtain the prompt. The project file can be an index code file in a project (such as a code project). The project index can be an IDE index, which includes the index of files and methods constructed by the language service in the IDE for the structure of the current code project. The index can include visible navigation bars and invisible relationships between code files. The knowledge base can include knowledge related to programming languages, scenarios or development frameworks. The extension plug-in 200 can search in the knowledge base through the RAG and obtain the search result in the knowledge base. The prompt template can include an extension variable placeholder, and the extension plug-in 200 can replace the extension variable with the actual value according to the extension variable placeholder. Optionally, the prompt template can further include a basic variable placeholder, which is used to replace the actual value of the basic variable.

[0096] For ease of understanding, an example of the prompt template is provided in the present application. FIG. 5 shows an example diagram of a prompt template, in which the part contained by {} is a variable placeholder, and the variable placeholder is divided into the following categories according to the variable type:

[0097] The base variable placeholder, denoted as core.xxx, can be replaced by an actual value of a base variable by the main plug-in. The base variable can include at least one of a programming language, a current file path, or a current file context. The actual value of the programming language can be a programming language supported by the main plug-in, such as a general and basic programming language, including but not limited to Java. The actual value of the programming language can also be a programming language not supported by the main plug-in, such as Ruby. Accordingly, an extension plug-in for Ruby can support Ruby to dynamically extend the hint.

[0098] The extension variable placeholder, denoted as ext.id.xxx, can be replaced by an actual value of an extension variable by an extension plug-in with an ID of "id". The extension variable can include at least one of a dependent library of a project, a development framework used by the project, a search result (knowledge) in a knowledge base, and a cross-file context.

[0099] In some possible implementation manners, the extraction logic can include extraction rules. For example, some languages have unique syntax rules, and the extension plug-in 200 can perform context extraction for the language. Taking the C language as an example, the C language defines a structure body, and many other high-level languages (such as Java and Python) do not have the structure body. The extension plug-in 200 can extract the structure body from the project file according to a rule related to the structure body, such as matching a statement defining the struct. The structure body can be an actual value of an extension variable.

[0100] S208. The main plug-in 100 receives the hint returned by the at least one extension plug-in.

[0101] The hint is obtained by replacing an extension variable in a hint template with an actual value. The hint template can be a hint template provided by the extension plug-in 200, and the hint template provided by the extension plug-in 200 is specifically optimized for a current code generation task (such as a code generation task in a current code generation scenario) compared with a general hint template (such as a hint template provided by the main plug-in 100). After the extension plug-in 200 replaces the extension variable in the hint template with the actual value to obtain the hint, the extension plug-in 200 can return the hint to the main plug-in 100.

[0102] S210. The main plug-in 100 performs reasoning through a language model according to the hint to obtain a second code snippet.

[0103] Specifically, the main plugin 100 can directly input the prompt into the language model inference to obtain the second code snippet. For example, when the main plugin 100 determines one extension plugin 200 corresponding to the code generation instruction from the plurality of extension plugins 200, the main plugin 100 can provide the actual value of the base variable extracted by the main plugin 100 to the extension plugin 200, and the extension plugin 200 replaces the base variable in the prompt template with the actual value of the base variable, similar to the extension variable, so that a complete prompt can be obtained. In this case, the main plugin 100 receives the prompt returned by the extension plugin, and can directly input the language model for inference to obtain the second code snippet without further assembling.

[0104] In some possible implementations, the main plugin 100 can also assemble the prompt and the actual value of the base variable to obtain an assembled prompt, and then the main plugin 100 inputs the assembled prompt into the language model for inference to obtain the second code snippet. In a specific implementation, the main plugin 100 can first check whether the prompt is complete, for example, whether the prompt includes an un-replaced variable placeholder (for example, a base variable placeholder), and if so, the main plugin 100 can fill in the actual value of the corresponding base variable to obtain a complete prompt, and then input the complete prompt into the language model for inference.

[0105] In this application, the language model can be a large language model LLM, including but not limited to GPT. In actual application, the language model can also be a small-scale language model, which is not limited in this application. The main plugin 100 can select a language model that meets the demand according to the business demand to generate code by inference.

[0106] As shown in FIG. 4, the main plugin 100 can send the prompt assembled with additional context (such as the actual value of the extension variable) to the background service of the code development platform 10, and the background service can request the language model such as LLM to perform inference according to the prompt to generate the second code snippet. It should be noted that FIG. 4 is only one specific implementation of inputting the prompt into the language model for inference to obtain the second code snippet, and when the code development platform 10 adopts other architectures, the code can also be generated by other ways, which is not limited in this application.

[0107] The embodiment shown in FIG. 2 introduces the code generation method of the present application from the perspective of interaction between the main plugin 100 and the extension plugin 200. Among them, the main plugin 100 executes the steps of S202, S204, S208 and S210, and the extension plugin 200 executes S206 to execute the code generation method. The code generation method of the present application can also be divided into a method on the side of the main plugin 100 and a method on the side of the extension plugin 200. The method on the side of the main plugin 100 includes the steps executed by the main plugin 100, for example, S202, S204, S208 and S210; the method on the side of the extension plugin 200 includes the steps executed by the extension plugin 200.

[0108] Based on the above description, the present application provides a code generation method. In the method, the main plug-in 100 determines the extension plug-in corresponding to the code generation instruction, and entrusts the prompt under the specific code generation task and the implementation of the prompt project to the corresponding extension plug-in 200 for implementation. Through the multi-plug-in linkage mechanism, the main plug-in and the extension plug-in achieve collaborative cooperation, thereby realizing flexible expansion of the prompt for the specific code generation task, targeted optimization for the specific code generation scene, and improvement of the code generation effect. Among them, the extension plug-in 200 of the present application supports hot plugging. The hot pluggable extension plug-in 200 and the main plug-in 100 linkage can realize flexible control of the prompt for the language model, establish a modular, hot plugging, on-demand combination extension mechanism, thereby making the intelligent programming assistant product such as the code development platform 10 have high customizability and extensibility, and achieving a balance between universality and customization.

[0109] Next, the plug-in linkage process in the code generation method of the present application will be introduced in combination with specific scenarios.

[0110] Referring to a flowchart of plug-in linkage in a code generation method shown in FIG. 6, in this example, the main plug-in 100 can include an IDE plug-in of an agent and a local kernel module (local Core-Module), and the kernel module is used to realize linkage with the extension plug-in 200. The extension plug-in 200 can include an extension plug-in relied on by the agent, specifically, an extension plug-in matched with the main plug-in. The method specifically includes the following steps:

[0111] S602, in response to the selection operation of the user on the agent A, the IDE plug-in of the agent A checks whether the matched extension plug-in is installed. When there is an uninstalled matched extension plug-in, S604 is executed.

[0112] Specifically, the IDE plug-in of the agent A can detect the installed extension plug-in, and obtain the plug-in information of the installed extension plug-in. The plug-in information can include plug-in identification (such as plug-in ID) and plug-in version (version). Then the IDE plug-in compares the plug-in information of the installed extension plug-in with the plug-in information of the matched extension plug-in. If the plug-in information of the installed plug-in includes the plug-in information of the matched extension plug-in, it indicates that the matched extension plug-in has been installed. Otherwise, it indicates that there is an uninstalled matched extension plug-in.

[0113] S604, the IDE plug-in performs installation operation on the uninstalled matched extension plug-in. When it is detected that the installation is successful, S606 is executed.

[0114] Specifically, the IDE plug-in can present a detection result to the user, the detection result including an uninstalled matched extension plug-in. The result display interface can further include an installation control of the extension plug-in, and when the user clicks the installation control, the IDE plug-in can obtain a path of an installation package of the extension plug-in, access the path to obtain the installation package, and run the installation package to implement installation of the matched extension plug-in.

[0115] In some possible implementation manners, the IDE plug-in can also search a plug-in market according to plug-in information of the uninstalled matched extension plug-in, obtain an installation package of the matched extension plug-in, and then run the installation package to implement installation of the matched extension plug-in.

[0116] S606, the IDE plug-in presents an installation success prompt to the user.

[0117] The installation success prompt is used to prompt that the matched extension plug-in is installed successfully, and in some examples, the installation success prompt can also prompt a plug-in application scenario of the extension plug-in and a matched main plug-in.

[0118] S608, the IDE plug-in receives a code generation instruction, and in response to the code generation instruction, collects context.

[0119] The context can include a current file path, a cursor position, and a current file context (such as code in the current file). The current file context can be determined according to the cursor position. For example, the current file context can be n lines before and after the cursor position in the current file, and n can be a positive integer, for example, n can be 10.

[0120] S610, the IDE plug-in sends the context to the kernel module.

[0121] S612, the kernel module determines whether to generate code according to the context. If yes, S614 is performed, and if no, S632 is performed.

[0122] For example, the current file path indicates that the current file is a readme file, and code generation is not performed, and the code generation process can be ended. For another example, the kernel module can identify whether the code generation instruction is a false trigger according to the context. For example, the user presses enter multiple times in a short time to trigger code generation when writing code, which indicates that there is a false trigger.

[0123] S614, the kernel module determines at least one extension plug-in 200 corresponding to the code generation instruction from a plurality of extension plug-ins 200.

[0124] In a specific implementation, the kernel module can identify the task according to the context, obtain the task feature, and then determine at least one extension plug-in corresponding to the code generation instruction according to the identified task feature. In some examples, the kernel module can also support determining at least one extension plug-in corresponding to the code generation instruction in a manner selected by a user.

[0125] In S616, the kernel module determines whether at least one extension plug-in corresponding to the code generation instruction has been installed. If yes, S618 is performed; if no, S620 is performed.

[0126] In S618, the kernel module sends the context to at least one extension plug-in corresponding to the code generation instruction. Then, S622 is performed.

[0127] In S620, the kernel module sends an indication to the IDE plug-in, where the indication is used to instruct a user to install at least one extension plug-in corresponding to the code generation instruction and retrigger code generation.

[0128] In S622, the extension plug-in extracts an actual value of an extension variable according to extraction logic of the extension variable in the prompt template based on the context sent by the kernel module.

[0129] In S624, the extension plug-in replaces the extension variable in the prompt template with the actual value of the extension variable to obtain a prompt, and returns the prompt to the kernel module.

[0130] In S626, the kernel module obtains an actual value of a basic variable, and assembles the actual value of the basic variable to the prompt.

[0131] In S628, the kernel module returns the assembled prompt to the IDE plug-in.

[0132] In S630, the IDE plug-in renders a code generation request according to the assembled prompt, and sends the code generation request to a background service.

[0133] In S632, the IDE plug-in ends code generation.

[0134] The linkage manner between the main plug-in and the extension plug-in can be determined according to the type of the IDE. For example, the plug-in linkage of some types of IDEs can be implemented by sharing a message queue. The shared message queue can adopt a topic (Topic) subscription and consumption mechanism. For another example, the plug-in linkage of some types of IDEs can be implemented by calling commands with each other, for example, command registration and calling.

[0135] Based on the above content description, when the user triggers the code generation instruction, the main plug-in automatically calls the communication interface (such as API) of the available extension plug-in according to the automatic matching result or user selection, and transmits the context related to the current code generation task as input (such as the current file path, cursor position, existing code context in the file, etc.). After the extension plug-in receives the above context related to the current code generation task, it can extract additional context according to its built-in extraction rules, such as cross-file context, search results in the knowledge base, and configuration files related to the development framework, and return them to the main plug-in. The main plug-in can request the language model to perform reasoning based on the optimized prompt according to the prompt optimized based on the additional context, thereby improving the code generation effect.

[0136] In order to make the technical solutions of the present application clearer and easier to understand, the possible implementation schemes of the code generation method of the present application in the reasoning stage will be described from the aspect of human-computer interaction.

[0137] In some possible implementation manners, referring to the schematic diagram of the configuration interface in the schematic diagram of the code generation method shown in FIG. 4, the user can independently select the required intelligent agent for different code generation scenarios, and then select and install the required extension plug-in. The user can input a natural language description or a first code fragment and trigger a code generation instruction. The main plug-in of the intelligent agent can automatically call the API of the extension plug-in to obtain the prompt obtained by replacing the extension variable with the actual value by the extension plug-in. The prompt can include cross-file context, search results in the knowledge base, and configuration files related to the development framework. Further, the main plug-in can also obtain the actual value of the basic variable, and assemble the actual value of the basic variable with the prompt returned by the extension plug-in to obtain the final prompt. The main plug-in can request the LLM to perform reasoning based on the final prompt to generate a second code fragment.

[0138] In other possible implementation manners, when the user does not select any extension plug-in, the main plug-in can automatically identify the code generation scenario through user dimension features and project dimension features when the user triggers the code generation instruction, and obtain scenario features. The main plug-in can recommend at least one extension plug-in to the user according to the scenario features. The user installs the above extension plug-in recommended by the main plug-in. FIG. 7 shows an interface diagram after installing the extension plug-in. The extension plug-in can extend the functions not covered by the main plug-in itself, improve the code generation effect, and thus improve the user experience.

[0139] It should be noted that the related content of FIGS. 1 to 7 is illustrated by taking the example of providing services through plug-ins. In other possible implementation manners of the present application, the code development platform can also expose a function interface in the form of a cloud service to the outside. Other tools can call the function interface to realize the functions of the present application.

[0140] In addition, the context engineering extensible solution is mainly exemplified by the code generation function of the intelligent programming assistant product, but the solution is not limited to the code generation task. For example, the context engineering extensible solution can also be completely extended to other functions, such as technical Q&A, code explanation, unit test generation, etc.

[0141] Based on the foregoing code generation method, the application further provides a code development platform 10. As shown in FIG. 1, the code development platform 10 includes a main plug-in 100 and a plurality of extension plug-ins 200. The main plug-in is used to provide actual values of prompted base variables, and the base variables include at least one of a programming language, a current file path, and a current file context. The plurality of extension plug-ins 200 are used to extend the prompt from the programming language, the scene, or the development framework dimension.

[0142] The main plug-in 100 is configured to receive a code generation instruction, the code generation instruction being used to generate a second code snippet according to a natural language description or a first code snippet, and in response to the code generation instruction, determine at least one extension plug-in 200 corresponding to the code generation instruction from the plurality of extension plug-ins 200, the at least one extension plug-in 200 providing a prompt template corresponding to the code generation instruction and extraction logic of an extension variable in the prompt template.

[0143] The main plug-in 100 is further configured to receive a prompt returned by the at least one extension plug-in 200, the prompt being obtained by the at least one extension plug-in 200 according to the extraction logic of the actual value of the extension variable, and replacing the extension variable in the prompt template with the actual value of the extension variable, and then according to the prompt, performing reasoning through a language model to obtain the second code snippet.

[0144] In some possible implementation manners, the main plug-in 100 is specifically configured to:

[0145] extract task features of the code generation task according to the code generation instruction, the task features including at least one of user dimension features or project dimension features, the user dimension features including at least one of a department to which a user belongs, a project group to which the user belongs, or a user identifier, and the project dimension features including at least one of a programming language, a development framework, or an application field;

[0146] determine the at least one extension plug-in 200 corresponding to the code generation instruction from the plurality of extension plug-ins according to the task features.

[0147] In some possible implementation manners, the main plug-in 100 is specifically configured to:

[0148] present the plurality of extension plug-ins 200 to the user in response to the code generation instruction;

[0149] determine the at least one extension plug-in 200 corresponding to the code generation instruction in response to a selection operation of the user.

[0150] In some possible implementation manners, an actual value of the extended variable is extracted by the extension plug-in 200 from a project file, a project index, or a knowledge base.

[0151] In some possible implementation manners, the main plug-in 100 is provided with a registration interface, and the main plug-in 100 is further configured to:

[0152] receive a registration request generated by the plurality of extension plug-ins 200 by calling the registration interface, the registration request including at least one of a plug-in identifier, a plug-in version, a plug-in applicable scenario, or a plug-in capability;

[0153] store registration information of at least one extension plug-in 200, the registration information including at least one of the plug-in identifier, the plug-in version, the plug-in applicable scenario, or the plug-in capability, and the registration information being used to determine at least one extension plug-in 200 corresponding to the code generation instruction.

[0154] In some possible implementation manners, the main plug-in 100 is specifically configured to:

[0155] assemble the prompt and the actual value of the basic variable to obtain an assembled prompt;

[0156] input the assembled prompt into the language model to perform reasoning, and obtain a second code snippet.

[0157] Exemplarily, the main plug-in 100 and the extension plug-in 200 can be implemented by software. When implemented by software, the main plug-in 100 and the extension plug-in 200 can be application programs running on a computer device. The application programs can also be virtualized to provide users with virtualized services. The virtualized services can include a virtual machine (VM) service, a bare metal server (BMS) service, or a container service. The VM service can be a service that provides a VM for users to use on demand by virtualizing a VM resource pool on multiple physical hosts through a virtualization technology. The BMS service is a service that provides a BMS for users to use on demand by virtualizing a BMS resource pool on multiple physical hosts. The container service is a service that provides a container for users to use on demand by virtualizing a container resource pool on multiple physical hosts. The VM is a virtual computer simulated, that is, a logical computer. The BMS is a high-performance computing service that can be elastically scaled, has no difference in computing performance from a traditional physical machine, and has the feature of secure physical isolation. The container is a kernel virtualization technology that can provide light virtualization to achieve the purpose of isolating user space, processes, and resources. It should be understood that the VM service, the BMS service, and the container service in the virtualized services are only specific examples. In actual applications, the virtualized services can also be other light or heavy virtualized services, which are not specifically limited here.

[0158] It should be noted that the main plug-in 100 and the extension plug-in 200 can be plug-ins of a client code editor or a development environment (such as an IDE), which provide services for developers by interacting with the client code editor or the development environment. The main plug-in 100 and the extension plug-in 200 can be provided to developers in the form of new functions as the version of the client code editor or the development environment is iterated. Alternatively, the main plug-in 100 and the extension plug-in 200 can be new features of a code generation tool based on LLM, which are provided to developers as the version is iterated. In addition, the main plug-in 100 and the extension plug-in 200 can also be auxiliary coding functions of a cloud code editor or a development environment (such as Codespace) provided to users. For example, the main plug-in 100 and the extension plug-in 200 can expose a functional interface in the form of a cloud service, and other tools can use the functions of the present application by calling the interface.

[0159] In some possible implementation manners, the main plug-in 100 is specifically configured to:

[0160] The task feature of the code generation task is extracted according to the code generation instruction, and the task feature includes at least one of a user dimension feature or a project dimension feature, the user dimension feature includes at least one of a department to which a user belongs, a project group to which the user belongs, or a user identifier, and the project dimension feature includes at least one of a programming language, a development framework, or an application field.

[0161] According to the task feature, at least one extension plug-in corresponding to the code generation instruction is determined.

[0162] In some possible implementation manners, the main plug-in 100 is specifically configured to:

[0163] In response to the code generation instruction, the user is presented with a plurality of extension plug-ins;

[0164] In response to the selection operation of the user, at least one extension plug-in corresponding to the code generation instruction is determined.

[0165] In some possible implementation manners, the actual value of the extension variable is extracted by the extension plug-in 200 from a project file, a project index, or a knowledge base.

[0166] In some possible implementation manners, the main plug-in 100 is provided with a registration interface, and the main plug-in 100 is further configured to:

[0167] Receive a registration request generated by the plurality of extension plug-ins 200 by calling the registration interface, and the registration request includes at least one of a plug-in identifier, a plug-in version, a plug-in applicable scenario, or a plug-in capability;

[0168] Store registration information of at least one extension plug-in 200, and the registration information includes at least one of a plug-in identifier, a plug-in version, a plug-in applicable scenario, or a plug-in capability, and the registration information is used to determine at least one extension plug-in corresponding to the code generation instruction.

[0169] In some possible implementation manners, the main plug-in 100 is specifically configured to:

[0170] The prompt and the actual value of the basic variable are assembled to obtain an assembled prompt;

[0171] The assembled prompt is input into the language model for reasoning to obtain a second code snippet.

[0172] The application also provides a computing device 800. As shown in FIG. 8, the computing device 800 includes a bus 802, a processor 804, a memory 806, and a communication interface 808. The processor 804, the memory 806, and the communication interface 808 communicate through the bus 802. The computing device 800 can be a server or a terminal device. It should be understood that the number of processors and memories in the computing device 800 is not limited in the application.

[0173] The bus 802 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, or the like. The bus can be divided into an address bus, a data bus, a control bus, or the like. For ease of representation, only one line is shown in FIG. 8, but it does not mean that there is only one bus or only one type of bus. The bus 802 can include a channel for transmitting information between various components (e.g., the memory 806, the processor 804, the communication interface 808) of the computing device 800.

[0174] The processor 804 can include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP), or the like.

[0175] The memory 806 can include a volatile memory (e.g., a random access memory (RAM)), and can also include a non-volatile memory (e.g., a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD)). The memory 806 stores executable program codes, and the processor 804 executes the executable program codes to implement the foregoing code generation method. Specifically, the memory 806 stores instructions of the code development platform 10 for implementing the code generation method. As shown in FIG. 8, the memory 806 can store instructions for implementing the functions of the main plug-in 100 and instructions for implementing the functions of the plurality of extension plug-ins 200.

[0176] The communication interface 808 uses a transceiver module such as, but not limited to, a network interface card, a transceiver, or the like, to implement communication between the computing device 800 and other devices or communication networks.

[0177] The embodiments of the present application also provide a computing device cluster. The computing device cluster comprises at least one computing device. The computing device can be a server, for example, 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 notebook computer, or a smart phone.

[0178] As shown in FIG. 9, the computing device cluster comprises at least one computing device 800. The same code development platform 10 for executing the instructions of the code generation method can be stored in the memory 806 of one or more computing devices 800 in the computing device cluster.

[0179] In some possible implementations, one or more computing devices 800 in the computing device cluster can also be used to execute part of the instructions of the code development platform 10 for executing the code generation method. In other words, the combination of one or more computing devices 800 can collectively execute the instructions of the code development platform 10 for executing the code generation method.

[0180] It should be noted that the memories 806 in different computing devices 800 in the computing device cluster can store different instructions for executing part of the functions of the code development platform 10. For example, the instructions for implementing the functions of the extension plug-in 200 can be stored in the memories 806 of different computing devices 800, and the computing device storing the instructions for implementing the functions of the main plug-in 100 can call the computing device storing the instructions for implementing the functions of the extension plug-in 200, so as to cooperatively execute the code generation method.

[0181] FIG. 10 shows a possible implementation. As shown in FIG. 10, two computing devices 800A and 800B are connected through the communication interface 808. The memory in the computing device 800A stores the instructions for executing the functions of the main plug-in 100. The memory in the computing device 800B stores the instructions for executing the functions of the extension plug-in 200. In other words, the memories 806 of the computing devices 800A and 800B collectively store the instructions of the code development platform 10 for executing the code generation method.

[0182] The connection mode between the computing devices in the computing device cluster shown in FIG. 10 can be that the code generation method provided in the present application needs to extract the actual values of the extension variables and replace the extension variables in the prompt template with the actual values of the extension variables. Therefore, it is considered that the functions implemented by the extension plug-in 200 are executed by independent computing devices. For example, the functions of the main plug-in 100 are executed by the computing device 800A, and the functions implemented by the extension plug-in 200 are executed by the computing device 800B.

[0183] It should be appreciated that the functions of the computing device 800A shown in FIG. 10 can also be performed by a plurality of computing devices 800. Likewise, the functions of the computing device 800B can also be performed by a plurality of computing devices 800.

[0184] In some possible implementations, one or more computing devices in the cluster of computing devices can be connected through a network. The network can be a wide area network, a local area network, or the like. FIG. 11 shows one possible implementation. As shown in FIG. 11, two computing devices 800C and 800D are connected through a network. Specifically, the computing devices are connected to the network through the communication interfaces in the computing devices. In this type of possible implementation, the memory 806 in the computing device 800C stores instructions for performing the functions of the host plug-in 100. Meanwhile, the memory 806 in the computing device 800D stores instructions for performing the functions of the extension plug-in 200.

[0185] The manner in which the cluster of computing devices shown in FIG. 11 are connected can be in consideration of the context, such as the cross-file context, in the dynamic expansion hint required by the code generation method provided in the present application. Therefore, it is considered that the functions implemented by the extension plug-in 200 are performed by independent computing devices.

[0186] It should be appreciated that the functions of the computing device 800C shown in FIG. 11 can also be performed by a plurality of computing devices 800. Likewise, the functions of the computing device 800D can also be performed by a plurality of computing devices 800.

[0187] The embodiments of the present application also provide a computer readable storage medium. The computer readable storage medium can be any available medium or data storage device that can be accessed by a computing device, such as a data center containing one or more available media. The available medium can be a magnetic medium, such as a floppy diskette, a hard disk drive, a magnetic tape, an optical medium, such as a DVD, or a semiconductor medium, such as a solid state hard drive, or the like. The computer readable storage medium includes instructions that instruct a computing device to perform the code generation method described above and applied to the code development platform 10.

[0188] The embodiments of the present application also provide a computer program product containing instructions. The computer program product can be software or a program product containing 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 is caused to perform the code generation method described above.

[0189] Finally, it should be noted that the above examples are only used to illustrate the technical solutions of the present application, and are not intended to limit the same; although the present application has been described in detail with reference to the foregoing examples, those of ordinary skill in the art should understand that the technical solutions recorded in the foregoing examples can still be modified, or some of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the protection scope of the technical solutions of the embodiments of the present application.

Claims

1. A code generation method characterized by, The method is applied to a code development platform, the code development platform comprises a main plug-in and a plurality of extension plug-ins, the main plug-in is used for providing actual values of prompted basic variables, the basic variables comprise at least one of a programming language, a current file path and a current file context, and the plurality of extension plug-ins are used for extending the prompt from the programming language, a scene or a development framework dimension, and the method comprises the following steps: The main plug-in receives a code generation instruction, the code generation instruction is used for generating a second code segment according to a natural language description or a first code segment; The main plug-in determines at least one extension plug-in corresponding to the code generation instruction from the plurality of extension plug-ins in response to the code generation instruction, the at least one extension plug-in provides a prompt template corresponding to the code generation instruction and extraction logic of an extension variable in the prompt template; The main plug-in receives a prompt returned by the at least one extension plug-in, the prompt is obtained by the at least one extension plug-in according to the extraction logic of the actual value of the extension variable and replacing the extension variable in the prompt template with the actual value of the extension variable; The main plug-in performs reasoning through a language model according to the prompt to obtain the second code segment.

2. The method of claim 1, wherein, The main plug-in determines at least one extension plug-in corresponding to the code generation instruction from the plurality of extension plug-ins in response to the code generation instruction, comprising: The main plug-in extracts task features of a code generation task according to the code generation instruction, the task features comprise at least one of user dimension features or project dimension features, the user dimension features comprise at least one of a department to which a user belongs, a project group to which the user belongs or a user identifier, and the project dimension features comprise at least one of a programming language, a development framework or an application field; The main plug-in determines at least one extension plug-in corresponding to the code generation instruction from the plurality of extension plug-ins according to the task features.

3. The method according to claim 1 or 2, characterized in that, The main plug-in determines at least one extension plug-in corresponding to the code generation instruction from the plurality of extension plug-ins in response to the code generation instruction, comprising: The main plug-in presents a plurality of extension plug-ins to a user in response to the code generation instruction; The main plug-in determines at least one extension plug-in corresponding to the code generation instruction in response to a selection operation of the user.

4. The method according to any one of claims 1 to 3, characterized in that, The actual value of the extension variable is extracted by the extension plug-in from a project file, a project index or a knowledge base.

5. The method according to any one of claims 1 to 4, characterized in that, The main plug-in is provided with a registration interface, and the method further comprises: The main plug-in receives a registration request generated by the plurality of extension plug-ins by calling the registration interface, the registration request comprises at least one of a plug-in identifier, a plug-in version, a plug-in applicable scene or a plug-in capability; The main plug-in stores registration information of the at least one extension plug-in, the registration information comprises at least one of the plug-in identifier, the plug-in version, the plug-in applicable scene or the plug-in capability, and the registration information is used for determining at least one extension plug-in corresponding to the code generation instruction.

6. The method according to any one of claims 1 to 5, characterized in that, The main plug-in obtains the second code segment by reasoning through a language model according to the prompt, and the method comprises the following steps of: The main plug-in assembles the prompt and the actual value of the basic variable to obtain an assembled prompt; The main plug-in inputs the assembled prompt into a language model to reason and obtain the second code segment.

7. A code development platform, characterized by, The code development platform comprises a main plug-in and a plurality of extension plug-ins, the main plug-in is used for providing an actual value of a basic variable of a prompt, the basic variable comprises at least one of a programming language, a current file path and a current file context, and the plurality of extension plug-ins are used for extending the prompt from the programming language, a scene or a development framework dimension; The main plug-in is used for receiving a code generation instruction, the code generation instruction is used for generating a second code segment according to a natural language description or a first code segment, and at least one extension plug-in corresponding to the code generation instruction is determined from the plurality of extension plug-ins in response to the code generation instruction, the at least one extension plug-in provides a prompt template corresponding to the code generation instruction and extraction logic of an extension variable in the prompt template; The main plug-in is further used for receiving a prompt returned by the at least one extension plug-in, the actual value of the extension variable is extracted from the extension variable according to the extraction logic by the at least one extension plug-in, the extension variable in the prompt template is replaced by the actual value of the extension variable to obtain the prompt, and then the second code segment is obtained by reasoning through a language model according to the prompt.

8. The code development platform of claim 7, wherein, The main plug-in is specifically used for: extracting task characteristics of a code generation task according to the code generation instruction, the task characteristics comprise at least one of user dimension characteristics or project dimension characteristics, the user dimension characteristics comprise at least one of a department to which a user belongs, a project group to which the user belongs or a user identifier, and the project dimension characteristics comprise at least one of a programming language, a development framework or an application field; determining at least one extension plug-in corresponding to the code generation instruction from the plurality of extension plug-ins according to the task characteristics.

9. The code development platform of claim 7 or 8, wherein, The main plug-in is specifically used for: presenting a plurality of extension plug-ins to a user in response to the code generation instruction; determining at least one extension plug-in corresponding to the code generation instruction in response to a selection operation of the user.

10. The code development platform of any of claims 7 to 9, wherein, The actual value of the extension variable is extracted from a project file, a project index or a knowledge base by the extension plug-in.

11. The code development platform of any of claims 7 to 10, wherein, The main plug-in is provided with a registration interface, and the main plug-in is further used for: receiving a registration request generated by the plurality of extension plug-ins by calling the registration interface, the registration request comprising at least one of a plug-in identifier, a plug-in version, a plug-in applicable scene or a plug-in capability; storing registration information of the at least one extension plug-in, the registration information comprising at least one of the plug-in identifier, the plug-in version, the plug-in applicable scene or the plug-in capability, and the registration information is used for determining at least one extension plug-in corresponding to the code generation instruction.

12. The code development platform of any one of claims 7 to 11, wherein, The main plug-in is specifically used for: assembling the prompt and the actual value of the basic variable to obtain an assembled prompt; The assembled prompt is input into a language model for inference, to obtain the second code snippet.

13. A cluster of computing devices, characterized in that, The computing device cluster comprises at least one computing device, the at least one computing device comprising at least one processor and at least one memory, and the at least one memory storing computer readable instructions; the at least one processor executes the computer readable instructions, so that the computing device cluster executes the code generation method in any one of claims 1 to 6.

14. A computer-readable storage medium, characterized in that, The computer readable instructions are used to implement the code generation method in any one of claims 1 to 6.

15. A computer program product, characterised in that, The computer readable instructions are used to implement the code generation method in any one of claims 1 to 6. The computer readable instructions are used to implement the code generation method in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Service grid expansion framework, service grid expansion method and system

    CN116483325A

  • Programming language extension method and system, computing device and storage medium

    CN116737273A

  • Plug-in framework, plug-in, data processing method and device and electronic equipment

    CN117289929A

  • Coding auxiliary plug-in development system based on large language model

    CN118069109A

  • Apparatus, Device, Method and Computer Program for Generating Code using an LLM

    US20240111498A1

Cited By

  • EDA tool chain dynamic arrangement method and device based on intention driving and storage medium

    CN121960310A

  • Code incremental injection method and device, electronic equipment and storage medium

    CN122086461A

  • A code increment injection method and device, electronic equipment and storage medium

    CN122086461B