Code generation method

By building a project codebase and indexing it globally, and obtaining reference code for the background code, the problem of low code generation accuracy in existing technologies is solved, achieving more efficient and accurate code generation.

WO2026113790A1PCT designated stage Publication Date: 2026-06-04CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD +1

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD
Filing Date
2025-10-28
Publication Date
2026-06-04

Smart Images

  • Figure CN2025130702_04062026_PF_FP_ABST
    Figure CN2025130702_04062026_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the embodiments of the present disclosure is a code generation method. The method comprises: acquiring a project code repository corresponding to a target project, wherein the project code repository is constructed on the basis of at least one project file corresponding to the target project; acquiring a background code, and on the basis of the project code repository, determining at least one reference code corresponding to the background code; and using a code generation model to process each reference code and the background code, so as to generate a target code. A project code repository for a target project is constructed, global indexing is performed on project files in advance, and a background code is taken into account to retrieve similar reference codes from the code repository in real time, and thus the recall rate of similar codes can be effectively improved. Compared with a conventional method that only relies on recently opened files for retrieval, the problem of some similar codes being hidden in unopened files is solved, and thus the phenomenon of "hallucination" in generated codes is mitigated, thereby improving the accuracy and reliability of the generated codes.
Need to check novelty before this filing date? Find Prior Art

Description

Code generation method

[0001] This disclosure claims priority to Chinese Patent Application No. 202411717943.6, filed with the China Patent Office on November 27, 2024, entitled “Code Generation Method”, the entire contents of which are incorporated herein by reference. Technical Field

[0002] This disclosure relates to the field of computer technology, and in particular to a code generation method. Background Technology

[0003] With the development of code auto-completion technology, developers are increasingly relying on intelligent code generation tools when writing code. These tools can accelerate coding efficiency and reduce some repetitive tasks, resulting in a significant increase in productivity. Furthermore, developers not only focus on the code they are currently writing but also use these tools to search for similar code in previously opened files, thereby better understanding and referencing existing code structures.

[0004] Currently, commonly used code generation techniques can search for similar code snippets based on files recently opened by the developer, helping to solve some of the "illusion" code generation problems. However, these techniques can only handle recently opened files, and code highly similar to the current code snippet may be hidden in other files and not found. Therefore, this approach can only reduce the generation of some "illusion" code, and the accuracy of the generated code is still not high. To address these shortcomings, this paper proposes a code generation method. Summary of the Invention

[0005] In view of this, embodiments of this disclosure provide a code generation method and a code generation method applied to the cloud. One or more embodiments of this disclosure also relate to a code generation apparatus, a computing device, a computer-readable storage medium, and a computer program product, to address the technical deficiencies existing in the prior art.

[0006] According to a first aspect of the present disclosure, a code generation method is provided, comprising:

[0007] Obtain the project code repository corresponding to the target project, wherein the project code repository is constructed from at least one project file corresponding to the target project;

[0008] Obtain the background code, and determine at least one reference code corresponding to the background code based on the project codebase;

[0009] The reference code and the background code are processed using a code generation model to generate the target code.

[0010] According to a second aspect of the present disclosure, a code generation method is provided, applied to a cloud device, comprising:

[0011] The receiving end-side device sends a code generation instruction, wherein the code generation instruction includes at least one project file for the target project;

[0012] Obtain the project code repository corresponding to the target project, wherein the project code repository is constructed based on each project file;

[0013] Obtain the background code, and determine at least one reference code corresponding to the background code based on the project codebase;

[0014] The reference code and the background code are processed using a code generation model to generate target code, and the target code is sent to the end device.

[0015] According to a third aspect of the present disclosure, a code generation system is provided, the system including an edge device and a cloud device;

[0016] The edge device is configured to send code generation instructions to the cloud device, wherein the code generation instructions include at least one project file for the target project;

[0017] The cloud device is configured to receive code generation instructions sent by the edge device; obtain a project code library corresponding to the target project, wherein the project code library is constructed based on each project file; obtain background code, and determine at least one reference code corresponding to the background code based on the project code library; process each reference code and the background code using a code generation model to generate target code; and send the target code to the edge device.

[0018] The endpoint device is also configured to receive target code sent by the cloud device.

[0019] According to a fourth aspect of the present disclosure, a computing device is provided, comprising:

[0020] Memory and processor;

[0021] The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, they implement the steps of the above-described code generation method and the code generation method applied to cloud devices.

[0022] According to a fifth aspect of the present disclosure, a computer-readable storage medium is provided that stores computer-executable instructions, which, when executed by a processor, implement the steps of the above-described code generation method and the code generation method applied to a cloud device.

[0023] According to a sixth aspect of the present disclosure, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described code generation method and the code generation method applied to a cloud device.

[0024] By applying the solution of this disclosure, a project code library for the target project is constructed, and project files are globally indexed, enabling the early acquisition of valid code snippets across the entire project. While developers are coding, the system can not only retrieve the currently written code in real time but also find reference code similar to the background code from the global code library, thereby significantly improving the recall rate of similar code. Compared to the traditional method that relies solely on recently opened files for retrieval, this solves the problem that some similar code may be hidden in unopened files, preventing such code from being discovered and utilized in a timely manner. It effectively reduces the "illusion" phenomenon during code generation, thus greatly improving the accuracy and consistency of the generated code, contributing to increased development efficiency and ensuring code quality. Attached Figure Description

[0025] Figure 1 is a flowchart of a code generation method provided in an embodiment of this disclosure;

[0026] Figure 2 is a flowchart of a code generation method for cloud devices provided in an embodiment of this disclosure;

[0027] Figure 3 is an architecture diagram of a code generation system provided in an embodiment of this disclosure;

[0028] Figure 4 is a flowchart of a project development method provided in an embodiment of this disclosure;

[0029] Figure 5 is a schematic diagram of the structure of a code generation apparatus provided in an embodiment of this disclosure;

[0030] Figure 6 is a structural block diagram of a computing device provided in an embodiment of this disclosure. Detailed Implementation

[0031] Numerous specific details are set forth in the following description to provide a full understanding of this disclosure. However, this disclosure can be implemented in many other ways than those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this disclosure. Therefore, this disclosure is not limited to the specific implementations disclosed below.

[0032] The terminology used in one or more embodiments of this disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of this disclosure. The singular forms “a,” “the,” and “the” as used in one or more embodiments of this disclosure and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in one or more embodiments of this disclosure refers to and includes any or all possible combinations of one or more associated listed items.

[0033] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this disclosure, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this disclosure, and similarly, second may also be referred to as first. Depending on the context, the word “if” as used herein may be interpreted as “when”, “in response to a determination”, or “when…”.

[0034] Furthermore, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this disclosure are all information and data authorized by the user or fully authorized by all parties. Moreover, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0035] In one or more embodiments of this disclosure, a large model refers to a deep learning model with a large number of model parameters, typically containing hundreds of millions, tens of billions, hundreds of billions, trillions, or even tens of trillions of model parameters. A large model can also be called a foundation model. It is pre-trained using large-scale unlabeled corpora to produce a pre-trained model with hundreds of millions of parameters. Such models can adapt to a wide range of downstream tasks and have good generalization ability. Examples include Large Language Models (LLMs) and multi-modal pre-training models.

[0036] In practical applications, large models only require a small number of samples to fine-tune the pre-trained model before they can be applied to different tasks. Large models can be widely used in fields such as Natural Language Processing (NLP) and Computer Vision. Specifically, they can be applied to computer vision tasks such as Visual Question Answering (VQA), Image Captioning (IC), and Image Generation, as well as NLP tasks such as text-based sentiment classification, text summarization, and machine translation. The main application scenarios for large models include digital assistants, intelligent robots, search, online education, office software, e-commerce, and intelligent design.

[0037] First, the terms and concepts involved in one or more embodiments of this disclosure will be explained.

[0038] Hallucination refers to a phenomenon in generative models where the model generates content that is unrealistic or unfounded due to a lack of sufficient context or data. This phenomenon commonly occurs in text and code generation, especially when the model attempts to fill in missing information. Hallucinations cause the generated content to deviate from the original intent, thus affecting the quality of the generated results.

[0039] Abstract Syntax Tree (AST): A tree-like data structure used to represent the structure of code, where each node represents a syntactic element in the source code. Using the AST, compilers or interpreters can parse and analyze code, identify its syntactic structure, and perform code optimization, transformation, and error checking. The AST is a crucial step in the code compilation and parsing process.

[0040] Reciprocal Rank Fusion (RRF) is a ranking-based fusion method that calculates a fusion score by considering the relative rank of each code snippet in different sorted lists.

[0041] Condorcet Fusion is a ranking fusion method based on a voting mechanism. It determines the ranking of each code snippet by comparing its relative order across different ranking lists. The core idea is the "majority principle," meaning that if a code snippet ranks higher in multiple lists, it should also rank higher in the overall ranking. This fusion method is suitable for retrieval tasks that require balancing multiple ranking sources.

[0042] The CombSUM fusion method is a fusion algorithm that calculates a score by simply adding the scores from different retrieval methods. CombSUM considers the results of each retrieval method, summing the scores of each code snippet across different methods into a single total score. This method is suitable for the direct fusion of multiple scoring methods, effectively integrating the advantages of multiple retrieval algorithms and simplifying the sorting process.

[0043] CombMNZ fusion method: It is an improved version based on CombSUM. It not only adds up the scores of each code snippet, but also makes weighted adjustments based on the number of times the code snippet appears in different search methods.

[0044] This disclosure provides a code generation method and a code generation method applied to the cloud. One or more embodiments of this disclosure also relate to a code generation apparatus, a computing device, a computer-readable storage medium, and a computer program product, which will be described in detail in the following embodiments.

[0045] In their daily coding practice, developers not only focus on the code they are currently writing but also on other similar code existing throughout the project. However, current industry products only focus on the code file being written and recently opened code, which often leads to the generation of "illusion" code in the overall model. This type of code is not adopted by developers and can be disruptive.

[0046] Currently, the commonly used code generation methods in the industry record the code files that developers have opened in the code editor. When a developer is writing code, the system finds files related to the language type of the current file from the historical files opened, obtains the last N lines of code at the current cursor position, performs similarity calculations with the relevant files found, and provides code snippets with high similarity to the large model.

[0047] The methods described above can solve some of the code generation "illusion" problems, but they are limited by many factors. For example, it requires the developer to have recently opened historical files, and the opened files need to have a high degree of similarity to the current code. However, in real-world applications, similar code blocks are often hidden in files of other functional modules and will not have been opened recently, thus only solving part of the "illusion" problem.

[0048] Referring to Figure 1, Figure 1 shows a flowchart of a code generation method provided according to an embodiment of the present disclosure, which specifically includes the following steps.

[0049] Step 102: Obtain the project code repository corresponding to the target project, wherein the project code repository is constructed from at least one project file corresponding to the target project.

[0050] In practical applications, the target project is the specific software development task that the developer is currently undertaking, the project files are the code files or resource files that make up the project, and the project code repository is a collection that stores and manages the project code, providing global analysis and retrieval capabilities for the project files.

[0051] A target project can be understood as the collective term for a specific software development task or application that a developer is currently undertaking. A target project typically includes multiple functional modules, involving various aspects such as code writing, testing, and debugging. For example, a mobile application development project can be a target project, containing multiple functional parts such as the user interface and backend logic.

[0052] Project files can be understood as the foundational code and resource files that make up the target project. These files typically include source code files (such as .java, .py, etc.), configuration files, documentation files, etc. For example, when developing a web application, source code files, configuration files, and related database scripts are all considered project files, and together they form the basis of the web application project.

[0053] A project code repository can be understood as a system used to manage and store code files within a target project. It includes not only the source code but also provides features such as version control, retrieval, and indexing of these files. For example, during development, the code repository helps developers track changes to project files and performs structured analysis of the files using a code parser, making it easier for developers to retrieve and call similar code snippets.

[0054] It's important to note that building a project codebase based on at least one project file corresponding to the target project can be understood as indexing and parsing the project files to facilitate subsequent retrieval and code generation. This step of building the project codebase corresponding to the target project based on at least one project file is the fundamental step in the entire code generation process, and its core lies in the global indexing and organization of the project files. This process not only helps improve the retrieval of various code snippets within the project but also provides necessary data support for subsequent code generation.

[0055] The purpose of this step is that target projects typically contain a large number of files, and manually searching or analyzing these files is extremely inefficient and error-prone. Building the project codebase provides a searchable index for the entire project, allowing developers or models to easily find code snippets relevant to the current task. This not only improves the accuracy of the code generation process but also avoids the risk of missing critical code. Simultaneously, this process lays a solid foundation for subsequent operations to retrieve reference and background code, ensuring that the generated code is consistent with the overall project structure.

[0056] Furthermore, the project codebase is constructed in the following manner:

[0057] At least one target code index is obtained based on each project file, wherein the target code index is structured data used to retrieve code snippets;

[0058] Obtain the key index information corresponding to the index information of each target code;

[0059] The project code library is constructed based on the index information of each target code and the corresponding key index information.

[0060] In practical applications, target code index information is structured data used for quick retrieval of code snippets, while index key information consists of specific important features in the code snippets used to improve retrieval accuracy.

[0061] Target code index information can be understood as the index information corresponding to code snippets in project files, along with their respective file paths. This information is used for efficient retrieval within the project codebase. The file path, as supplementary information for the code snippets, helps to quickly locate their physical location during retrieval. For example, a code snippet for a specific function will generate index information, which includes not only the specific content and characteristics of the code snippet but also the file path where the function is located, so that its original file can be quickly located after the relevant code snippet is retrieved. This enables the system to quickly locate and match relevant code snippets in complex code, improving the accuracy and speed of code retrieval.

[0062] Key indexing information can be understood as crucial features in code that indicate its function or behavior, including function names, variable names, class definitions, and external interfaces called. For example, when a retrieval system finds a code segment that matches a function or variable name in the background code, these key features will be prioritized, thereby improving the relevance and accuracy of the search. By tagging this key information, the retrieval engine can quickly filter out code snippets that match the current background code requirements, further improving the efficiency of code generation and reuse.

[0063] It should be noted that obtaining at least one target code index based on each project file, and obtaining the corresponding index key information for each target code index, can be understood as extracting structured information from the code to facilitate subsequent retrieval. Specifically, this can be achieved by parsing the project files, generating a corresponding syntax tree, and extracting code fragments and their features; or by using a recursive character splitting algorithm to divide the code file into small blocks and generate index information for each block; or by scanning key identifiers such as functions, classes, and variables in the code file and combining them with the code context to generate index key information, etc. This disclosure does not impose any restrictions on these methods.

[0064] By constructing a project codebase using various code indexes and their corresponding key information, the efficiency and accuracy of code retrieval can be effectively improved, ensuring the rapid location of code snippets relevant to the current task across the entire project. This method comprehensively analyzes and organizes code, avoiding the omission of any important code blocks, thus providing a reliable data foundation for subsequent code generation, optimization, or reuse, ensuring code consistency and project maintainability.

[0065] Furthermore, based on each project file, at least one target code index information is obtained, including:

[0066] Identify the target project file and obtain at least one initial code index information based on the target project file, wherein the target project file is any one of the project files;

[0067] Determine reference code index information, and obtain at least one target code index information based on the reference code index information, wherein the reference code index information is any one of the initial code index information.

[0068] In practical applications, the overall code information is a description of the complete code structure and content contained in each file of the project, while the code index information is structured data obtained by splitting the overall code information into multiple sub-code chunks for efficient retrieval.

[0069] Overall code information can be understood as a complete representation of the code content extracted from project files. It includes the syntactic structure of the source code, as well as key components such as functions, classes, and variables. For example, in a Python project, overall code information would include defined functions, class structures, and called external modules. By parsing this information, the functionality and logic of the file can be fully understood. Overall code information provides the foundation for building a project codebase, ensuring that the important content of each project file is incorporated into the system for analysis and processing.

[0070] The initial code index information can be understood as including the code fragment identifiers generated after parsing the target file through code parsing, which contain complete content such as class methods, module functions, and tag elements in the code.

[0071] It should be noted that obtaining at least one initial code index information based on the target project file can be understood as extracting index data related to each code segment by analyzing the target project file. Specifically, this can be done by directly parsing the file content, such as scanning comments or tags in the code file to extract index information; it can also be based on syntax parsing technology to perform syntax tree analysis on the code file and extract function definitions, variable declarations, etc. as initial indexes; or it can utilize file structure analysis methods, such as generating index information based on directory hierarchy and file naming rules, etc. This disclosure does not impose any restrictions on this.

[0072] Obtaining at least one target code index based on the reference code index information can be understood as splitting the complete reference (initial) code index information into sub-code blocks using various strategies to improve the flexibility and efficiency of retrieval. For example, the code can be directly split according to a fixed character length, a fixed number of statements, or a fixed number of lines, or it can be split using overlapping sub-code blocks through sliding window technology, allowing the current block to share some content with the previous block, thereby improving recall. These sub-code blocks are stored as searchable units, and the content of each sub-code block includes not only code fragments but also relevant contextual information, enabling the system to quickly locate and match relevant code fragments in complex code, improving the accuracy and speed of code retrieval.

[0073] Considering the significant impact of code index length on code matching efficiency, splitting the complete reference (initial) code index into target code indexes using various strategies can effectively improve retrieval flexibility and matching accuracy. By using splitting methods such as fixed character length, fixed number of statements, or sliding windows, the size and range of code fragments can be flexibly adjusted, ensuring sufficient contextual information while avoiding inefficient retrieval due to excessively large fragments. Simultaneously, overlapping splitting methods can improve the recall rate of similar code, helping the system quickly find more relevant code fragments in complex projects, thereby significantly improving the speed and accuracy of code generation and matching.

[0074] Furthermore, the target project file is identified, and at least one initial code index information is obtained based on the target project file, including:

[0075] Determine the file type corresponding to the target project file;

[0076] Determine the code parsing rules corresponding to the target project file based on the file type;

[0077] The target project file is parsed according to the code parsing rules to obtain at least one initial code index information.

[0078] In practical applications, file type refers to the category or format to which the project file belongs, and code parsing rules are specific parsing methods used for different file types to extract code information from the file.

[0079] File type can be understood as the specific format or language of a project file, determining its structure and content processing methods. For example, a file type can be a programming language file (such as Java or Python files), a markup language file (such as HTML or XML), or even a file in other unrecognized languages. In a complex project, file types are diverse, and each type may have different syntax and structure. Therefore, identifying the file type is a crucial step in subsequent processing, as different file types require different parsing methods and tools.

[0080] Code parsing rules can be understood as specific parsing methods determined based on file type, used to accurately understand and process the code structure within a file. Each file type has its own specific syntax rules, therefore the parsing rules are adjusted according to the file type.

[0081] It should be noted that obtaining at least one initial code index by parsing the target project file according to code parsing rules can be understood as performing detailed parsing of the project file to generate searchable code snippets. Specifically, this can be achieved by using AST to parse programming language files, extracting structural information of various methods and functions to generate initial code index information; alternatively, it can be achieved by using parsing rules based on tags and nested structures to process markup language files, extracting tag elements and their attribute information as initial indexes; or, for unrecognized languages, using a recursive symbol splitting algorithm to progressively split the code into smaller blocks according to specific delimiters, ensuring that all code snippets can be recognized and indexed, etc. This disclosure does not impose any limitations in this regard.

[0082] It is important to note that for unrecognized language, a recursive delimiter algorithm is used for splitting. This can be understood as recursively trying different sized delimiters to gradually break the text into smaller blocks. Specifically, a predefined list of delimiters can be used to split the text sequentially from largest to smallest (e.g., from paragraph to character). Alternatively, block size control parameters can be set to limit the number of characters in each block. Block overlap parameters can also be set to ensure some overlap between blocks to maintain contextual coherence. Furthermore, a custom delimiter list can be defined to adapt to different document structures. By splitting according to meaningful delimiters, the semantic integrity of the text can be maintained to a certain extent. This is particularly suitable for processing structured or semi-structured text, such as Markdown or code. If none of the delimiters can meet the size limit, forced text truncation can also be selected, etc. This disclosure does not impose any restrictions on this.

[0083] By setting different syntax rules for different file types, it can be ensured that the code can be effectively parsed and processed.

[0084] Considering that the project files corresponding to the target project include invalid files, the following are also included when determining the project files used to generate the code repository:

[0085] Identify at least one invalid file in each project file;

[0086] Remove invalid files from each project file and build the project codebase based on at least one of the removed project files.

[0087] In practical applications, invalid files are those that cannot provide valid information for code retrieval or generation during the project codebase building process.

[0088] Invalid files can be understood as files that do not contain critical code information when building a project's codebase and cannot provide effective support for code indexing, retrieval, or generation. For example, binary files, log files, excessively long files, and files specified in .gitignore are generally considered invalid. They may occupy storage space but do not contain parsable source code information; therefore, these files are removed during the code parsing and indexing phases to avoid impacting the efficiency of codebase builds and the accuracy of retrieval.

[0089] Step 104: Obtain the background code and determine at least one reference code corresponding to the background code based on the project code library.

[0090] In practical applications, background code is the code snippet that the developer is currently writing or processing, while reference code is a code snippet in the project codebase that is similar to or related to the background code. It is obtained through retrieval and matching and is used to assist in code generation or optimization.

[0091] Background code can be understood as the code snippets that a developer is currently working on during the coding process. This code is usually closely related to the current task or functional module and forms the basis for generating new code. For example, when a developer writes a function, a portion of the function's code is considered background code, providing contextual information to the system and helping it retrieve and match similar code.

[0092] Reference code can be understood as code snippets that, through searching or matching within the project's codebase, have a certain similarity or relevance to the background code. Reference code provides contextual supplementation to the background code, helping to generate code that better conforms to project specifications or logic. For example, when the system finds a function or module in the project's codebase with a structure similar to the background code, that function can be considered reference code and used to improve the current code or generate new code.

[0093] The core of the process of acquiring background code and determining at least one reference code corresponding to the background code based on the project codebase lies in obtaining the local code (i.e., background code) before and after the current cursor position by analyzing the code snippet being written by the developer in real time. Background code provides the context of the developer's current work and is key to understanding and generating new code.

[0094] In implementation, the first step is to retrieve code snippets similar to the background code from the project's codebase. These snippets serve as reference code, providing additional support for generating the target code. The selection of reference code can be achieved through various methods, including keyword matching and semantic vector retrieval, and this disclosure places no restrictions on this approach. This process helps ensure that the generated code not only maintains logical consistency with the current background code but also fully utilizes existing code snippets within the project, improving the accuracy and efficiency of code generation.

[0095] The necessity of this step lies in the fact that the background code written by developers is usually only a small part of the current task. By combining it with similar code blocks in the project, the current task can be better understood and completed. Matching and retrieving reference code not only improves the quality of generated code but also reduces repetitive work, avoids generating irrelevant or erroneous code, and ensures that the generated code meets the overall requirements of the project.

[0096] Furthermore, obtain the background code, including:

[0097] Determine the cursor position in the code editing interface associated with the target project;

[0098] The background code is determined based on the cursor position.

[0099] In practical applications, the code editing interface associated with the target project is the interactive interface used by developers to edit the code of the target project, and the cursor position is the current input point or focus position of the developer when writing or modifying code in the editing interface.

[0100] The code editing interface associated with the target project can be understood as the workspace where developers write, modify, and debug code during the development process. This interface is typically used in conjunction with a development environment (IDE) or text editor, providing features such as code visualization, syntax highlighting, and error suggestions. For example, in a web development project, developers manipulate HTML, JavaScript, or CSS files through the editing interface, writing or modifying code in real time. The editing interface directly impacts developer productivity; therefore, its layout, functionality, and user experience are crucial to code writing.

[0101] The cursor position can be understood as the focus of the code the developer is currently editing; it's the specific location where code is entered and modified. During editing, the cursor position determines the context of code operations and is usually associated with the developer's input. For example, when a developer places the cursor inside a function and enters new code, the system analyzes the current context's code logic based on the cursor position and parses it according to the class, method, or variable at that location. The cursor position is a crucial reference point for code generation, helping the system understand the developer's intent in real time and provide corresponding code suggestions.

[0102] Considering that it is necessary to query multiple reference codes in the project code repository, and the reference codes are determined by the reference code information, the project code repository includes at least one project code information.

[0103] Furthermore, based on the project codebase, at least one reference code corresponding to the background code is determined, including:

[0104] Based on the background code, obtain the code reference weights corresponding to the code information of each project in the project code library;

[0105] At least one reference code is determined based on the code reference weight corresponding to the code information of each project.

[0106] At least one reference code is determined based on the information from each reference code.

[0107] In practical applications, project code information refers to the indexes and key information of each code snippet stored in the project code library, code reference weight is a metric for evaluating the relevance of project code information to background code, and reference code information refers to code snippets that are highly correlated with the background code, determined based on the code reference weight.

[0108] Project code information can be understood as structured data about a code snippet within a project's codebase, describing its content, function, and location. It typically includes the code's index and key index information. For example, in a large software project, project code information might contain the name, parameters, return value, and file path of a function within the project. By recording this information, the system can quickly locate code snippets related to specific functions when needed, thereby improving code retrieval efficiency.

[0109] Code reference weight can be understood as a numerical value used to measure the similarity or relevance between project code information and background code. It calculates the matching degree between project code information and background code by analyzing index key information and code index information in the project code information. For example, the system may determine the similarity between a code snippet and background code based on function names, variable types, or class definitions; a higher weight indicates a stronger association between the code snippet and the background code. Code reference weight is crucial in the code retrieval process because it helps the system filter out more relevant code snippets, optimizing the accuracy of code generation and completion.

[0110] Reference code information can be understood as code snippets from the project's codebase that are relevant to the background code, selected based on their reference weight. These snippets include not only the original code but also its context and functional description. Through reference code information, the system can provide developers with more precise code suggestions or completions. For example, when a developer calls a function in the background code, the reference code information will provide additional relevant implementation details or sample code for that function, helping the developer complete the task more quickly.

[0111] It should be noted that obtaining code reference weights corresponding to the code information of each project in the project code repository based on the background code can be understood as evaluating the matching degree by analyzing the relevance between the project code information and the background code. Specifically, this can be achieved by semantically matching the background code with index key information in the project code information, such as function names, variable names, or class names, to generate index key weights; alternatively, code execution path analysis can be used to evaluate the call relationships between the background code and other code segments in the project, generating code reference weights, and then generating index key weights based on the dependency degree between the background code and other code segments in the project; furthermore, code reference weights can be generated through historical code change records, and the historical evolution of code segments in the project can be analyzed to generate index key weights. Code segments with a higher sum of code reference weights and index key weights are likely to be more relevant to the background code, further improving the accuracy of reference code selection, etc. This disclosure does not impose any limitations in this regard.

[0112] By calculating the reference weights representing the relevance of project code information to background code, the system selects reference codes corresponding to the background code. This ensures that the system prioritizes code snippets more relevant to the current development context. This approach significantly improves the accuracy and efficiency of code retrieval, helping developers quickly find reference code highly matched to the current task, thereby reducing errors and unnecessary repetitive operations during code generation. Furthermore, by analyzing code index information and key index information, the system can dynamically adjust reference weights to ensure that each generated code meets actual needs and the current development environment, thus improving development speed and code quality.

[0113] Considering the code reference weights used to calculate the relevance of project code information to background code, project code information includes code index information and index key information.

[0114] Furthermore, based on the background code, the code reference weights corresponding to the code information of each project in the project code repository are obtained, including:

[0115] Based on the index key information in the project code information, obtain the index key weight between the background code and the project code; and / or,

[0116] Calculate the code index weight between the code index information in the code information of each project and the background code;

[0117] Based on the index key weights and / or code index weights corresponding to the code information of each project, determine the code reference weights corresponding to the code information of each project.

[0118] In practical applications, the index key weight is a weight value used to evaluate the similarity between the index key information in the project code information and the background code, while the code index weight is a metric used to measure the degree of association between the project code snippet and the background code.

[0119] Index key weights can be understood as weights calculated by analyzing the similarity between key features in the code (such as function names, class names, variable names, etc.) and the background code. For example, when a function name in a code snippet is the same as or similar to a function name in the background code, the system will assign that snippet a higher index key weight. This method allows the system to prioritize code snippets that have important features matching the background code, thereby improving retrieval accuracy.

[0120] Code index weight can be understood as a weight calculated based on the degree of matching between the overall content and structure of a code snippet and the background code. This includes not only variable and function names in the code, but also complex relationships such as code logic and execution order. For example, by analyzing the execution path or dependencies of a code snippet, the system can assess its overall similarity to the background code, thereby assigning it an appropriate code index weight. A higher code index weight indicates that the code snippet has a stronger functional and logical relevance to the background code, making it suitable for directly generating subsequent code or for using the code snippet as a reference to generate subsequent code.

[0121] It should be noted that in one or more embodiments provided in this disclosure, the index key weight or code index weight can be directly determined as the code reference weight, or the code reference weight corresponding to the code information of each project can be determined based on the index key weight and code index weight corresponding to the code information of each project.

[0122] Furthermore, based on the index key weights and code index weights corresponding to the code information of each project, the code reference weights corresponding to the code information of each project are determined. This can be understood as fusing the results of different retrieval methods. Specifically, this can be achieved through linear combination, summing the scores of each method according to their weights; or by dynamically adjusting the weights, flexibly adjusting the weights of each method based on the query type or context information; or by segmented fusion, using different fusion strategies for long-tail queries and popular queries; considering the diversity of results during the fusion process to avoid homogenization; performing post-processing optimization, such as re-ranking or filtering the fused results, such as deduplication and entity linking; or using RRF (Reciprocal Rank Fusion), which utilizes the ranking of documents in different sorting lists for fusion; or using Condorcet Fusion (Condorcet... Fusion (Condorcet fusion method) is based on majority voting based on the relative order of documents; CombSUM fusion method and CombMNZ fusion method are applied to simply add up the scores or combine the number of retrievals; fusion is based on a probability model to estimate the probability distribution of document relevance; machine learning algorithms can even be used to learn better fusion strategies, etc., and this disclosure does not impose any restrictions on this.

[0123] By obtaining the index key weights and / or code index weights corresponding to the code information of each project, and determining their corresponding code reference weights, the accuracy and relevance of search results can be effectively improved. By calculating the weights of various feature dimensions of the code, the system can ensure that it prioritizes code snippets that highly match the background code. This not only reduces interference from irrelevant code but also improves the quality and efficiency of code generation. Furthermore, combining multiple weight evaluation methods can integrate various search results, avoiding the limitations of over-reliance on a single feature, thereby providing developers with a more comprehensive code reference.

[0124] Furthermore, based on the index key information in the code information of each project, the index key weights between the code information of each project and the background code are obtained, including:

[0125] Obtain the activity file queue and determine the reference activity weight corresponding to the code information of each project based on the activity file queue, wherein the activity file queue is an ordered list that records the file information corresponding to the developer's recent operations in the target project;

[0126] Based on the index key information and reference activity weights in the code information of each project, the index key weights between the code information of each project and the background code are obtained.

[0127] In practical applications, the active file queue is an ordered list that records the file paths or contents that the developer has recently operated on in the project. The reference activity weight is a weight value that evaluates the relevance of code snippets to background code based on the frequency and order of file operations in the active file queue.

[0128] The active file queue can be understood as a dynamically updated record of file paths, containing the order and timing of files opened, edited, or closed by developers within a project. For example, during software development, developers may frequently manipulate files in certain modules, and the active file queue automatically records the paths and related information of these files. By analyzing this queue, the system can understand the scope of code the developer is currently focusing on and prioritize code snippets from these files during subsequent code retrieval, thereby improving the contextual relevance of code generation.

[0129] Reference activity weights can be understood as assigning a weight to each file based on factors such as operation frequency and the time of its most recent operation, according to the file records in the active file queue. A higher weight indicates a stronger relevance between the code snippet in that file and the developer's current task or background code. For example, if a file is opened and edited multiple times, its reference activity weight will increase, and the system will be more inclined to select relevant code snippets from these files during code retrieval, thereby improving the accuracy and real-time performance of the generated code.

[0130] It should be noted that determining the reference activity weights for each project's code information based on the active file queue can be understood as evaluating the relevance of these files by analyzing the file records recently operated on by developers. Specifically, this can be achieved by calculating the frequency of each file's operation, with higher frequencies resulting in greater weights; by recording the operation times of files, with files closer to the current time receiving higher weights; or by analyzing the mutual reference relationships between files, where a file associated with multiple high-weight files will have its reference activity weight increased accordingly, and so on. This disclosure does not impose any limitations on these methods.

[0131] By retrieving reference activity weights corresponding to project code information from the active file queue and updating their corresponding index key weights, more accurate code retrieval and generation can be achieved. This ensures that code snippets in files that developers have recently frequently manipulated or edited are given higher weights, thus prioritizing the retrieval of code highly relevant to the current task. This approach effectively incorporates the developer's actual operation history, making the generated code more consistent with the current development context, reducing interference from irrelevant code, and improving both system response speed and the quality of generated code.

[0132] Step 106: Process the reference code and the background code using the code generation model to generate the target code.

[0133] In practical applications, the code generation model is an algorithmic model used to generate new code that meets the project requirements based on the input background code and reference code. The target code is a new code snippet generated by the model that can be directly applied to the project.

[0134] A code generation model can be understood as a system based on artificial intelligence or machine learning algorithms, specifically designed to generate new code based on input background code and reference code. It can be a large, pre-trained model, or a deep learning model that learns from large amounts of code data and masters the syntax rules and logical structures of different programming languages ​​and development scenarios, etc. This disclosure makes no limitations on this.

[0135] Target code can be understood as new code generated by a code generation model. It is typically highly relevant to the developer's current task and can be directly used for project feature expansion or optimization. Target code is the output of the model generation, designed to reduce the developer's workload. For example, when a developer writes initial code for a specific function, the target code generated by the model might be a complete function implementation, which the developer can then modify slightly or use directly to improve development efficiency.

[0136] It should be noted that the specific methods for using a code generation model to process reference code and background code to generate target code can be understood as implementing code generation through different technologies. Specifically, these methods can involve obtaining code generation hints based on the reference and background code, inputting these hints into the code generation model to obtain the generated target code; alternatively, vectorized retrieval techniques can be used to embed the reference and background code, generating new code snippets based on semantic similarity; or context window techniques can be used, combining the contextual information of the current background code to generate code closely related to the project logic, etc. This disclosure does not impose any limitations on these methods.

[0137] The process of generating target code using a code generation model by processing reference and background code relies on the model's deep learning of large-scale data. Through analysis of numerous code snippets, the model can identify the grammatical rules and logical structures of different languages ​​and intelligently generate code by combining the context of the background and reference code. The background code provides the developer's current working environment and task context, while the reference code represents similar code implementations within the project. By processing these two types of input, the model generates target code that better meets the needs of the current project.

[0138] The process of generating target code significantly reduces repetitive work in development. Developers no longer need to manually search for or write similar code; instead, the model's automation capabilities generate accurate code snippets, improving development efficiency and reducing potential code "illusion" problems. Furthermore, the model ensures that the generated code remains consistent with the overall project logic based on the context of the background code and the historical implementation of the reference code, thereby improving code quality and maintainability. In the overall project development process, combining the capabilities of the code generation model can effectively reduce errors and ensure fast and accurate code generation.

[0139] Furthermore, the reference code and the background code are processed using a code generation model to generate target code, including:

[0140] Code generation prompts are obtained based on the reference code and the background code.

[0141] Input the code generation prompt information into the code generation model to obtain the target code generated by the code generation model.

[0142] In practical applications, code generation hints serve as input to guide the code generation model in generating the target code. These hints can be understood as a set of input information containing background code, reference code, and relevant context, providing the code generation model with the contextual basis for generating the target code. For example, when a developer writes a section of code within a function, the hints might include the function's definition, the variables involved, and similar function implementations in the reference code.

[0143] Code generation prompts enable code generation models to understand the developer's intent and generate highly relevant and accurate code completions or suggestions.

[0144] Considering that the project files were modified after the target code was generated, the method further includes, after processing the reference code and the background code using the code generation model to generate the target code:

[0145] The project file corresponding to the background code is determined to be the currently active file;

[0146] The current active file is updated based on the target code, and the active file queue is updated based on the updated current active file.

[0147] In practical applications, the currently active file is the file that the developer is currently operating on or editing in the project, and the active file queue is a list that records recently operated file paths, used to track the developer's file operation history.

[0148] The active file can be understood as the file that the developer is currently focusing on during code editing. This file might be the source code file that the developer is currently editing or modifying, or a project file that has just been opened for viewing. For example, when a developer is editing a Java class file, that file becomes the active file, and the system will prioritize related operations based on the context information of that file to provide functions such as code generation, completion, or suggestions. The active file is a dynamic element that changes frequently during project development, affecting the system's real-time responsiveness.

[0149] It should be noted that updating the active file queue based on the updated current active file can be understood as reflecting changes in the current active file by adjusting the order and / or content of the queue. Specifically, this can be done by placing the updated current active file at the head of the queue to prioritize the processing of the latest active file; or by inserting the updated current active file into a specific position in the queue; or by removing outdated files from the queue and adding the updated current active file to ensure that the queue is always up-to-date, etc. This disclosure does not impose any restrictions on this.

[0150] The active file queue can be understood as an in-memory recording structure that stores the paths of files manipulated in the order they were accessed by the developer. Therefore, when a developer opens, closes, or edits a file, the file path is added to the active file queue, ensuring the system can track the developer's operation history. For example, when a developer frequently switches between files, the active file queue records these file paths and arranges them in chronological order. Through this queue, the system can analyze which files the developer is currently focusing on and assign higher weights to code snippets within these files, providing more relevant content during code generation or suggestion. Furthermore, considering storage space limitations and the efficiency of subsequent code generation, earlier added file paths can be removed when the queue length exceeds a system-defined threshold, maintaining the queue's effectiveness.

[0151] By updating the active file queue in real time, the system can continuously track developers' operation history and prioritize files most relevant to their current tasks. This not only improves the accuracy of code retrieval and generation but also dynamically adjusts the system's response based on the developer's latest actions, providing more intelligent code suggestions. Furthermore, automatically removing outdated file paths from the queue effectively manages queue length, preventing irrelevant information from interfering with overall efficiency. This ensures that the code generation process always revolves around the developer's core needs, improving the continuity and efficiency of the development workflow.

[0152] By applying the scheme of this disclosure, a project code library is constructed based on project files, and overall code information is extracted using code parsing rules. This method can accurately identify valid code snippets and perform deep matching through indexing key information and index weights. Unlike traditional methods that rely solely on recently opened files, this technology achieves global analysis and retrieval of code across the entire project, effectively solving the problem of undiscovered similar code hidden in other files. By matching highly relevant reference code to background code, the generated prompts are made more context-sensitive, thereby significantly improving the accuracy of code generation.

[0153] Corresponding to the above method embodiments, this disclosure also provides an embodiment of a code generation method applied to cloud devices. Referring to FIG2, FIG2 shows a flowchart of a code generation method applied to cloud devices according to an embodiment of this disclosure, which specifically includes the following steps.

[0154] Step 202: Receive code generation instructions sent by the end-side device, wherein the code generation instructions include at least one project file for the target project.

[0155] Step 204: Obtain the project code library corresponding to the target project, wherein the project code library is constructed based on each project file.

[0156] Step 206: Obtain the background code and determine at least one reference code corresponding to the background code based on the project code library.

[0157] Step 208: Use the code generation model to process each reference code and the background code to generate target code, and send the target code to the end device.

[0158] In practical applications, cloud devices are remote servers that process and store large amounts of data, while edge devices are local computing devices that users directly operate, such as computers or mobile phones. Code generation instructions are requests sent by users to cloud devices through edge devices to trigger the code generation process.

[0159] Cloud devices can be understood as remote servers or computing clusters specifically designed for high-performance computing and large-scale data storage. They possess powerful processing capabilities, enabling efficient handling of complex tasks such as code generation and model training. Developers can offload computationally intensive tasks to cloud devices, eliminating the need to rely on local computing resources. For example, when developers are writing code locally, they can delegate complex code generation tasks to cloud devices, which will quickly generate the required code snippets.

[0160] Edge devices can be understood as the local computing devices developers use daily, such as personal computers, laptops, or mobile devices. Edge devices are typically used to interact directly with users and are responsible for sending requests to cloud devices. For example, when a developer is editing code on their computer, the edge device can capture relevant code information and send it to the cloud device for processing and code generation. Once completed, the cloud device returns the result to the edge device for the developer to use.

[0161] A code generation command can be understood as a request issued by the edge device to trigger the cloud device to generate code. This command typically includes key information such as project files and background code. After receiving this information, the cloud device processes it and generates the required code. For example, when a developer is editing code on the edge device, they issue a code generation command, and the cloud device analyzes the project files based on the command and returns the corresponding code generation result.

[0162] The above is an illustrative scheme of a code generation method applied to a cloud device according to this embodiment. It should be noted that the technical solution of the code generation method applied to the cloud device belongs to the same concept as the technical solution of the code generation method described above. For details not described in detail in the technical solution of the code generation method applied to the cloud device, please refer to the description of the technical solution of the code generation method described above.

[0163] By applying the solution of this disclosure, which transmits code generation instructions from the edge device to the cloud, this solution can fully utilize the computing and storage resources of the cloud to build a more comprehensive project codebase. This technology can not only perform global code analysis based on multiple project files, but also accurately obtain reference code corresponding to background code, thereby improving the depth and breadth of code matching. Compared to solutions that only perform code retrieval locally, cloud devices have more efficient data processing capabilities, enabling them to complete complex code generation tasks in a shorter time and return highly relevant target code through the generation model, ensuring the accuracy and consistency of the generated results and further optimizing the developer's workflow.

[0164] Referring to Figure 3, Figure 3 shows an architecture diagram of a code generation system provided in an embodiment of the present disclosure. The code generation system may include a client 100 and a server 200.

[0165] Client 100 is used to send code generation instructions to server 200, wherein the code generation instructions include at least one project file for the target project;

[0166] Server 200 is used to receive code generation instructions sent by client 100; obtain the project code library corresponding to the target project, wherein the project code library is constructed based on each project file; obtain background code, and determine at least one reference code corresponding to the background code based on the project code library; process each reference code and the background code using a code generation model to generate target code; and send the target code to client 100.

[0167] Client 100 is also used to receive target code sent by server 200.

[0168] By employing the scheme of this disclosure embodiment, and through collaborative work between the client and server, this system can fully utilize the server's computing power for code generation. The client is responsible for sending code generation instructions. Upon receiving the instructions, the server constructs a project code library based on multiple project files and accurately retrieves reference code related to the background code through a global search of the code library. Compared to traditional methods that only process code generation locally, the server uses its powerful processing capabilities to perform in-depth analysis and matching of project files, ensuring that the generated code has a high degree of contextual relevance. The generated target code is returned to the client, effectively improving the accuracy of code generation and development efficiency.

[0169] The code generation system may include multiple clients 100 and a server 200. Clients 100 can be referred to as edge devices, and server 200 can be referred to as cloud devices. Multiple clients 100 can establish communication connections through server 200. In the code generation scenario, server 200 is used to provide code generation services between multiple clients 100. Each client 100 can act as either a sender or a receiver, communicating through server 200.

[0170] Users can interact with server 200 through client 100 to receive data sent by other clients 100, or send data to other clients 100, etc. In a code generation scenario, users can publish data streams to server 200 through client 100, server 200 can generate target code based on the data stream, and push the target code to other clients that have established communication.

[0171] In this system, client 100 and server 200 establish a connection via a network. The network provides the medium for communication between client 100 and server 200. The network can include various connection types, such as wired or wireless communication links or fiber optic cables. Data transmitted by client 100 may need to undergo encoding, transcoding, compression, or other processing before being published to server 200.

[0172] Client 100 can be a browser, an app (application), a web application such as an H5 (HyperText Markup Language 5) application, a lightweight application (also known as a mini-program), or a cloud application. Client 100 can be developed based on the software development kit (SDK) of the corresponding service provided by server 200, such as a real-time communication (RTC) SDK. Client 100 can be deployed on electronic devices and depends on the device or certain apps on the device to run. Electronic devices may have displays and support information browsing, such as personal mobile terminals like mobile phones, tablets, and personal computers. Various other types of applications can also be configured on electronic devices, such as human-computer interaction applications, model training applications, text processing applications, web browser applications, shopping applications, search applications, instant messaging tools, email clients, and social media platform software.

[0173] Server 200 may include servers providing various services, such as servers providing communication services to multiple clients, servers supporting backend training of models used on clients, and servers processing data sent by clients. It should be noted that server 200 can be implemented as a distributed server cluster composed of multiple servers, or as a single server. The server can also be a server in a distributed system, or a server integrated with blockchain. The server can also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.

[0174] It is worth noting that the code generation method provided in this embodiment is generally executed by the server. However, in other embodiments of this disclosure, the client may also have similar functionality to the server, thereby executing the code generation method provided in this embodiment. In other embodiments, the code generation method provided in this embodiment may also be executed jointly by the client and the server.

[0175] The following description, in conjunction with Figure 4, uses the application of the code generation method provided in this disclosure in project development as an example to further illustrate the code generation method. Figure 4 shows a flowchart of the processing procedure of a project development method provided in an embodiment of this disclosure, specifically including the following steps.

[0176] Step 402: Obtain multiple project files for the target project.

[0177] Step 404: Filter out invalid files in each project file.

[0178] Step 406: Based on the file type, call the corresponding code parsing rules to split the code in the valid file, generate multiple code blocks, and store the code fragments in the local embedded search engine.

[0179] Step 408: When a developer opens or closes a file, or when the file content changes, the local file change interface is called to record the file path and add it to the active file queue. If the queue length exceeds the threshold, the earlier added file paths will be removed.

[0180] Step 410: When the developer starts coding, parse the code before the current cursor position to obtain the background code.

[0181] Step 412: Calculate the index key weights between the background code and each code block using the above-mentioned active file queue, and call the vector retrieval service to obtain the index key weights between the background code and each code block.

[0182] Step 414: Combine the above index key weights and index key weights to perform a fusion sort, and select the code block with the highest sort ranking as the reference code.

[0183] Step 416: Combine the above reference code with the background code in context to generate prompt information for model invocation.

[0184] Step 418: Pass the generated prompt information to the code generation model for invocation, generate code snippets, and return them to the developer.

[0185] Step 420: Combine the code snippets generated by the model with the background code to assist developers in completing the project.

[0186] By applying the solution of this disclosure, valid code snippets from project files are stored in a local embedded retrieval engine. Combined with the calculation of active file queues and index key weights, this method enables real-time retrieval of reference code related to the background code during the developer's coding process, significantly improving code recall and matching accuracy. Compared to traditional methods that rely solely on recently opened files for code retrieval, this technology ensures accurate matching of similar code globally by invoking vector retrieval services and fusion ranking algorithms. By combining the generated reference code with the context of the background code, more relevant hints are provided, reducing the generation of "illusion" code, optimizing the output of the code generation model, and further improving project development efficiency and code quality.

[0187] Corresponding to the above method embodiments, this disclosure also provides a code generation apparatus embodiment. Figure 5 shows a schematic diagram of the structure of a code generation apparatus provided in one embodiment of this disclosure. As shown in Figure 5, the apparatus includes:

[0188] The acquisition module 502 is configured to acquire the project code library corresponding to the target project, wherein the project code library is constructed from at least one project file corresponding to the target project;

[0189] The determination module 504 is configured to obtain background code and determine at least one reference code corresponding to the background code based on the project code library;

[0190] The generation module 506 is configured to process the reference code and the background code using a code generation model to generate target code.

[0191] Optionally, the code generation apparatus includes a construction module, further configured to:

[0192] At least one target code index is obtained based on each project file, wherein the target code index is structured data used to retrieve code snippets;

[0193] Obtain the key index information corresponding to the index information of each target code;

[0194] The project code library is constructed based on the index information of each target code and the corresponding key index information.

[0195] Optionally, the building module is further configured as follows:

[0196] Identify the target project file and obtain at least one initial code index information based on the target project file, wherein the target project file is any one of the project files;

[0197] Determine reference code index information, and obtain at least one target code index information based on the reference code index information, wherein the reference code index information is any one of the initial code index information.

[0198] Optionally, the building module is further configured as follows:

[0199] Determine the file type corresponding to the target project file;

[0200] Determine the code parsing rules corresponding to the target project file based on the file type;

[0201] The target project file is parsed according to the code parsing rules to obtain at least one initial code index information.

[0202] Optionally, the building module is further configured as follows:

[0203] Identify at least one invalid file in each project file;

[0204] Remove invalid files from each project file and build the project codebase based on at least one of the removed project files.

[0205] Optionally, the determining module 504 is further configured to:

[0206] Determine the cursor position in the code editing interface associated with the target project;

[0207] The background code is determined based on the cursor position.

[0208] Optionally, the project code repository includes at least one project code information;

[0209] The determining module 504 is further configured as follows:

[0210] Based on the background code, obtain the code reference weights corresponding to the code information of each project in the project code library;

[0211] At least one reference code is determined based on the code reference weight corresponding to the code information of each project.

[0212] At least one reference code is determined based on the information from each reference code.

[0213] Optionally, project code information includes code index information and index key information;

[0214] The determining module 504 is further configured as follows:

[0215] Based on the index key information in the project code information, obtain the index key weight between the background code and the project code; and / or,

[0216] Calculate the code index weight between the code index information in the code information of each project and the background code;

[0217] Based on the index key weights and / or code index weights corresponding to the code information of each project, determine the code reference weights corresponding to the code information of each project.

[0218] Optionally, the determining module 504 is further configured to:

[0219] Obtain the activity file queue and determine the reference activity weight corresponding to the code information of each project based on the activity file queue, wherein the activity file queue is an ordered list that records the file information corresponding to the developer's recent operations in the target project;

[0220] Based on the index key information and reference activity weights in the code information of each project, the index key weights between the code information of each project and the background code are obtained.

[0221] Optionally, the generation module 506 is further configured to:

[0222] Code generation prompts are obtained based on the reference code and the background code.

[0223] Input the code generation prompt information into the code generation model to obtain the target code generated by the code generation model.

[0224] Optionally, the code generation apparatus further includes an update module, which is configured to:

[0225] The project file corresponding to the background code is determined to be the currently active file;

[0226] The current active file is updated based on the target code, and the active file queue is updated based on the updated current active file.

[0227] By constructing a project code repository and comprehensively parsing and indexing each project file, the solution disclosed herein can accurately extract overall code information and key index information from the project files, ensuring that code fragments within the code repository are effectively stored and retrieved. Compared to traditional retrieval devices that rely solely on recently accessed files, this device not only supports global code analysis but also matches reference code by calculating key index weights, further improving the recall rate of similar code. Combined with the processing of the code generation model, this technology ensures that the generated target code is highly relevant to the background code, effectively reducing inaccurate code fragments during the generation process, improving development efficiency, and guaranteeing code quality.

[0228] The above is an illustrative scheme of a code generation device according to this embodiment. It should be noted that the technical solution of this code generation device and the technical solution of the code generation method described above belong to the same concept. For details not described in detail in the technical solution of the code generation device, please refer to the description of the technical solution of the code generation method described above.

[0229] Figure 6 shows a structural block diagram of a computing device 600 according to an embodiment of the present disclosure. The components of the computing device 600 include, but are not limited to, a memory 610 and a processor 620. The processor 620 is connected to the memory 610 via a bus 630, and a database 650 is used to store data.

[0230] The computing device 600 also includes an access device 640, which enables the computing device 600 to communicate via one or more networks 660. Examples of these networks include Public Switched Telephone Network (PSTN), Local Area Network (LAN), Wide Area Network (WAN), Personal Area Network (PAN), or combinations of communication networks such as the Internet. The access device 640 may include one or more of any type of wired or wireless network interface (e.g., a network interface controller (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) wireless interface, a Wi-MAX (Worldwide Interoperability for Microwave Access) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, or a Near Field Communication (NFC) interface.

[0231] In one embodiment of this disclosure, the aforementioned components of the computing device 600, as well as other components not shown in FIG. 6, may also be connected to each other, for example, via a bus. It should be understood that the computing device block diagram shown in FIG. 6 is merely for illustrative purposes and is not intended to limit the scope of this disclosure. Those skilled in the art can add or replace other components as needed.

[0232] The computing device 600 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or personal computers (PCs). The computing device 600 can also be a mobile or stationary server.

[0233] The processor 620 is used to execute the following computer-executable instructions, which, when executed by the processor, implement the steps of the above-described code generation method and the code generation method applied to cloud devices.

[0234] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device belongs to the same concept as the above-described code generation method and the code generation method applied to cloud devices. For details not described in detail in the technical solution of the computing device, please refer to the descriptions of the above-described code generation method and the code generation method applied to cloud devices.

[0235] An embodiment of this disclosure also provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the steps of the above-described code generation method and the code generation method applied to a cloud device.

[0236] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the code generation method and the code generation method applied to cloud devices described above. Details not described in detail in the technical solution of the storage medium can be found in the descriptions of the code generation method and the code generation method applied to cloud devices described above.

[0237] An embodiment of this disclosure also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described code generation method and the code generation method applied to a cloud device.

[0238] The above is an illustrative scheme of a computer program according to this embodiment. It should be noted that the technical solution of this computer program belongs to the same concept as the above-described code generation method and the code generation method applied to cloud devices. For details not described in detail in the technical solution of the computer program, please refer to the descriptions of the above-described code generation method and the code generation method applied to cloud devices.

[0239] The foregoing has described specific embodiments of this disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0240] The computer instructions include computer program code, which may be in the form of source code, object code, executable file, or certain intermediate forms. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately added or removed according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media may not include electrical carrier signals and telecommunication signals.

[0241] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this disclosure are not limited to the described order of actions, because according to the embodiments of this disclosure, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments of this disclosure.

[0242] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0243] The preferred embodiments disclosed above are merely illustrative of this disclosure. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the embodiments of this disclosure. These embodiments are selected and specifically described in this disclosure to better explain the principles and practical applications of the embodiments of this disclosure, thereby enabling those skilled in the art to better understand and utilize this disclosure. This disclosure is limited only by the claims and their full scope and equivalents.

Claims

1. A code generation method, comprising: Obtain the project code repository corresponding to the target project, wherein the project code repository is constructed from at least one project file corresponding to the target project; Obtain the background code, and determine at least one reference code corresponding to the background code based on the project codebase; The reference code and the background code are processed using a code generation model to generate the target code.

2. The method of claim 1, wherein the project codebase is constructed in the following manner: At least one target code index information is obtained based on each project file, where... The target code index information is structured data used to retrieve code snippets; Obtain the key index information corresponding to the index information of each target code; The project code library is constructed based on the index information of each target code and the corresponding key index information.

3. The method as described in claim 2, wherein obtaining at least one target code index information based on each project file includes: Identify the target project file and obtain at least one initial code index information based on the target project file, wherein the target project file is any one of the project files; Determine reference code index information, and obtain at least one target code index information based on the reference code index information, wherein the reference code index information is any one of the initial code index information.

4. The method as described in claim 2 or 3, wherein the target code index information further includes the file path of the corresponding code segment, the file path being used to determine the original storage location of the code segment.

5. The method of claim 3, wherein determining the target project file and obtaining at least one initial code index information based on the target project file, includes: Determine the file type corresponding to the target project file; Determine the code parsing rules corresponding to the target project file based on the file type; The target project file is parsed according to the code parsing rules to obtain at least one initial code index information.

6. The method according to any one of claims 1-5, wherein obtaining the background code includes: Determine the cursor position in the code editing interface associated with the target project; The background code is determined based on the cursor position.

7. The method according to any one of claims 1-6, wherein the project code repository includes at least one project code information; Based on the project codebase, at least one reference code corresponding to the background code is determined, including: Based on the background code, obtain the code reference weights corresponding to the code information of each project in the project code library; At least one reference code is determined based on the code reference weight corresponding to the code information of each project. At least one reference code is determined based on the information from each reference code.

8. The method as described in claim 7, wherein the project code information includes code index information and index key information; Based on the background code, obtain the code reference weights corresponding to the code information of each project in the project code repository, including: Based on the index key information in the project code information, obtain the index key weight between the background code and the project code; and / or, Calculate the code index weight between the code index information in the code information of each project and the background code; Based on the index key weights and / or code index weights corresponding to the code information of each project, determine the code reference weights corresponding to the code information of each project.

9. The method as described in claim 8, wherein obtaining the index key weight between each project code information and the background code based on the index key information in each project code information includes: Obtain the activity file queue and determine the reference activity weight corresponding to the code information of each project based on the activity file queue, wherein the activity file queue is an ordered list that records the file information corresponding to the developer's recent operations in the target project; Based on the index key information and reference activity weights in the code information of each project, the index key weights between the code information of each project and the background code are obtained.

10. The method of claim 9, wherein obtaining the index key weight between each project code information and the background code based on the index key information and reference activity weight in each project code information includes: The index key information in the code information of each project is weighted, wherein the weighting coefficient is the activity weight; Calculate the matching degree between the weighted index key information and the background code, and determine the matching degree as the index key weight.

11. The method according to any one of claims 1-10, wherein the reference code and the background code are processed using a code generation model to generate target code, comprising: Code generation prompts are obtained based on the reference code and the background code. Input the code generation prompt information into the code generation model to obtain the target code generated by the code generation model.

12. The method of claim 11, wherein obtaining code generation hint information based on each reference code and the background code includes: The reference codes and the background code are concatenated to obtain the concatenated code; A separator is inserted into the concatenated code. The separator is used to distinguish between the reference code and the background code, and the concatenated code after the inserted separator is determined as the code generation prompt information.

13. The method of any one of claims 1-12, wherein after processing the reference code and the background code using a code generation model to generate the target code, the method further comprises: The project file corresponding to the background code is determined to be the currently active file; The current active file is updated based on the target code, and the active file queue is updated based on the updated current active file.

14. The method of claim 13, wherein updating the active file queue based on the updated current active file comprises: The updated current active file is inserted at the head of the active file queue; If the length of the active file queue exceeds a preset threshold, the file path at the end of the active file queue is removed.

15. The method according to any one of claims 1-14, wherein the method further comprises: Invalid files are removed from each project file. The invalid files are those that cannot provide valid support for code indexing, retrieval, or generation. The project codebase is constructed based on the project files after removing the invalid files.

16. A code generation method, applied to a cloud device, comprising: The receiving end-side device sends a code generation instruction, wherein the code generation instruction includes at least one project file for the target project; Obtain the project code repository corresponding to the target project, wherein the project code repository is constructed based on each project file; Obtain the background code, and determine at least one reference code corresponding to the background code based on the project codebase; The reference code and the background code are processed using a code generation model to generate target code, and the target code is sent to the end device.

17. A code generation system, the system comprising an edge device and a cloud device; The endpoint device is configured to send code generation instructions to the cloud device, wherein, The code generation instructions include at least one project file for the target project; The cloud device is configured to receive code generation instructions sent by the end device; Obtain the project code library corresponding to the target project, wherein the project code library is constructed based on each project file; obtain background code, and determine at least one reference code corresponding to the background code based on the project code library; process each reference code and the background code using a code generation model to generate target code; send the target code to the end device; The endpoint device is also configured to receive target code sent by the cloud device.

18. A computing device, comprising: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions, which, when executed by the processor, implement the steps of the method according to any one of claims 1-16.

19. A computer-readable storage medium storing a computer program / instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1-16.

20. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1-16.