Code generation method and system
Patent Information
- Application Number
- CN202610780313.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-01
- Publication Date
- 2026-10-16
AI Technical Summary
但这类工具生成的代码与实际问题需求之间的匹配度不高,代码准确性不足
[0010]This specification provides a code generation method according to one embodiment, which, in response to a user's code editing operation, determines the problem information associated with the problematic code on the code editing page. It identifies the target project corresponding to the code editing page and queries the target project's project codebase and project knowledge base based on the problem information to obtain reference code documents corresponding to the project codebase and reference knowledge documents corresponding to the project knowledge base. It then queries the target project's project codebase and project knowledge base based on the problem information to retrieve reference knowledge documents related to the problem information, obtaining reference code documents and reference knowledge documents at the code and knowledge dimensions, respectively. The problematic code, problem information, reference knowledge documents, and reference code documents are input into the code generation model to generate target code associated with the problematic code. Finally, it generates target code associated with the problematic code based on the reference knowledge documents and reference code documents, achieving knowledge and code fusion, improving the matching degree between the target code and the problem information, improving the generation efficiency and accuracy of the target code, and ensuring the knowledge coverage of the target code.
Smart Images

Figure CN122924737A_ABST
Abstract
Description
Technical Field
[0001] The embodiments in this specification relate to the field of code generation technology, and in particular to code generation methods and systems. Background Technology
[0002] In software development, code editing and debugging are crucial aspects of a developer's daily work. When code contains logical flaws, syntax errors, or missing functionality, developers typically rely on their experience or existing code within the project to locate and fix the problem. However, as projects grow larger and logic becomes more complex, simply relying on human experience for code repair becomes inefficient and prone to overlooking crucial background knowledge or project-specific implementation standards. Existing development aids, such as code completion tools or general code generation models, can provide code suggestions in specific scenarios. However, the code generated by these tools often doesn't perfectly match the actual problem requirements, resulting in insufficient accuracy. Therefore, a more effective code generation method is urgently needed to address these issues. Summary of the Invention
[0003] In view of the above, embodiments of this specification provide a code generation method. One or more embodiments of this specification also relate to a code generation system, 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.
[0004] According to a first aspect of the embodiments of this specification, a code generation method is provided, comprising: In response to a user's code editing action, determine the issue information associated with the problematic code on the code editing page; Identify the target project corresponding to the code editing page, and query the project code library and project knowledge base of the target project based on the problem information to obtain the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base; The problem code, the problem information, the reference knowledge document, and the reference code document are input into the code generation model to generate the target code associated with the problem code.
[0005] According to a second aspect of the embodiments of this specification, a code generation system is provided, including a client and a server, comprising: The client is used to submit operation instructions to the server in response to the user's code editing operation; The server is configured to respond to the operation instruction to determine the problem information associated with the problem code; determine the target project corresponding to the code editing page, and query the project code library and project knowledge base of the target project based on the problem information to obtain the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base; input the problem code, the problem information, the reference knowledge document and the reference code document into the code generation model to generate the target code associated with the problem code, and send the target code to the client.
[0006] According to a third aspect of the embodiments of this specification, a code generation apparatus is provided, comprising: The determination module is configured to respond to user code editing actions and determine the issue information associated with the problematic code on the code editing page; The query module is configured to determine the target project corresponding to the code editing page, and query the project code library and project knowledge base of the target project based on the problem information to obtain the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base; The input module is configured to input the problem code, the problem information, the reference knowledge document, and the reference code document into the code generation model to generate target code associated with the problem code.
[0007] According to a fourth aspect of the embodiments of this specification, a computing device is provided, comprising: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions, which, when executed by the processor, implement the steps of the above-described code generation method.
[0008] According to a fifth aspect of the embodiments of this specification, a computer-readable storage medium is provided that stores computer-executable instructions that, when executed by a processor, implement the steps of the code generation method described above.
[0009] According to a sixth aspect of the embodiments of this specification, a computer program product is provided, including a computer program or instructions that, when executed by a processor, implement the steps of the code generation method described above.
[0010] This specification provides a code generation method according to one embodiment, which, in response to a user's code editing operation, determines the problem information associated with the problematic code on the code editing page. It identifies the target project corresponding to the code editing page and queries the target project's project codebase and project knowledge base based on the problem information to obtain reference code documents corresponding to the project codebase and reference knowledge documents corresponding to the project knowledge base. It then queries the target project's project codebase and project knowledge base based on the problem information to retrieve reference knowledge documents related to the problem information, obtaining reference code documents and reference knowledge documents at the code and knowledge dimensions, respectively. The problematic code, problem information, reference knowledge documents, and reference code documents are input into the code generation model to generate target code associated with the problematic code. Finally, it generates target code associated with the problematic code based on the reference knowledge documents and reference code documents, achieving knowledge and code fusion, improving the matching degree between the target code and the problem information, improving the generation efficiency and accuracy of the target code, and ensuring the knowledge coverage of the target code. Attached Figure Description
[0011] Figure 1 This is a flowchart illustrating a code generation method provided in one embodiment of this specification; Figure 2 This is a document structure diagram of a code generation method provided in one embodiment of this specification; Figure 3 This is a flowchart illustrating the processing steps of a code generation method provided in one embodiment of this specification. Figure 4 This is a flowchart illustrating a code generation method provided in one embodiment of this specification. Figure 5 This is a schematic diagram of the structure of a code generation system provided in one embodiment of this specification; Figure 6 This is an interactive schematic diagram of a code generation system provided in one embodiment of this specification; Figure 7 This is a schematic diagram of the structural flow of a code generation system provided in one embodiment of this specification; Figure 8 This is a schematic diagram of the structure of a code generation device provided in one embodiment of this specification; Figure 9 This is a structural block diagram of a computing device provided in one embodiment of this specification. Detailed Implementation
[0012] Many specific details are set forth in the following description to provide a full understanding of this specification. However, this specification 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 specification. Therefore, this specification is not limited to the specific implementations disclosed below.
[0013] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of this specification. The singular forms “a,” “described,” and “the” as used in one or more embodiments of this specification 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 specification refers to and includes any or all possible combinations of one or more associated listed items.
[0014] 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 specification, 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 specification, 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," "when," or "in response to a determination."
[0015] 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 specification 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.
[0016] The technical solutions provided in this application can employ deep learning models with relatively large parameter scales. However, this large model is merely an example; this application does not limit the number of model parameters supported by the deep learning model used, aiming to meet actual needs. The deep learning models involved in this application can be artificial intelligence-based language models (LM) or multimodal models (MM).
[0017] First, the terms and concepts used in one or more embodiments of this specification will be explained.
[0018] Frontend Framework: A software framework used to simplify web frontend development, providing basic capabilities such as structured code organization, component-based development, and state management.
[0019] Named Entity Recognition (NER), also known as proper name recognition or entity extraction, is a fundamental task in Natural Language Processing (NLP). Its core objective is to automatically identify entities with specific meanings from unstructured text and classify them into predefined categories.
[0020] Abstract Syntax Tree (AST): A tree-like abstract representation of source code used for code analysis and transformation.
[0021] MCP (Model Context Protocol): A standardized protocol used for communication between AI IDEs and external services.
[0022] Vector Search: A technique that converts text into vectors and retrieves data by calculating vector similarity.
[0023] Extension Point: An extensible interface reserved in the framework that allows third parties to inject custom logic.
[0024] Webhook: A user-defined HTTP callback that, when a specific event occurs, the source application (Git server) proactively sends an HTTP request to a configured URL to notify the target application (such as a CI / CD system) to take appropriate action.
[0025] An SDK (Software Development Kit) is a collection of software development tools used to help developers build applications on a specific platform, framework, or hardware.
[0026] An API (Application Programming Interface) is a predefined set of functions, protocols, and tools used to build software applications. It defines how different software components interact, allowing developers to invoke functions from external systems or services without needing to understand their internal implementation details.
[0027] Agent (Intelligent Agent): In computer science and artificial intelligence, an agent refers to an entity capable of perceiving its environment, making autonomous decisions, and executing actions. It possesses a certain degree of autonomy and can move towards a predetermined goal without continuous human intervention.
[0028] This specification provides a code generation method, and also relates to a code generation system, 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.
[0029] See Figure 1 , Figure 1 A flowchart of a code generation method according to an embodiment of this specification is shown, which specifically includes the following steps.
[0030] Step 102: In response to the user's code editing operation, determine the problem information associated with the problem code on the code editing page.
[0031] Specifically, the code editing page can be a page used for code editing during the development or maintenance of an application project, or it can be the code editing page for an engineering project during software development. The code editing interface is the interface through which code can be edited during application development; it can also be the editing interface corresponding to any code file within an engineering project. Code editing operations allow users to edit the code on the code editing page, including but not limited to writing, selecting, and modifying code. Problem code can be a code segment or keyword selected by the user on the code editing page, and problem information is the natural language problem information generated by the user in response to the problem code. User-submitted problem information can be text-based or audio-based.
[0032] Therefore, if a user has questions about the code on the code editing page, they can trigger code editing or updates by interacting with the code. Code editing actions can be linked to the problematic code on the code editing page, allowing users to submit further questions about that code. Code editing actions can also trigger an intelligent agent to automatically inspect the edited code on the code editing page, detecting any errors.
[0033] Furthermore, considering that users may have questions about the edited code during the code editing process, a question input component can be provided based on the user's code editing actions to allow them to input questions about the problematic code. The specific implementation is as follows: In response to the code editing operation on the code editing page for the problematic code, a problem input component is displayed on the code editing page; in response to the triggering operation of the problem input component, the problem information associated with the problematic code is determined.
[0034] Specifically, the question input component can be a content input component located at the cursor position on the code editing page, providing users with an entry point for content input. Users can input question information through the question input component using text or voice input. Code editing operations on the question code can be touch operations such as clicking and selecting the question code, which trigger the display of the question input component. Code editing operations on the question code can also be code operations automatically triggered when the cursor is hovered over the question code. The triggering operation for the question input component can be a content input operation, or a content input operation combined with a content submission operation.
[0035] Based on this, during code editing on the code editing page, users can edit problematic code. They can also hover the cursor over problematic code; if the hover duration exceeds a threshold, code editing will be automatically triggered. In response to code editing of problematic code on the code editing page, a problem input component is displayed. This component can be displayed at the cursor position or at the location of the problematic code. Users can input and submit problem information through the problem input component, triggering an action on the component. In response to triggering the problem input component, the associated problem information is determined.
[0036] For example, in a front-end framework development and maintenance scenario, when a user is editing code on a code editing page, they can submit issue information for components within the page. These components are the code snippets being questioned. When the user selects a code snippet or hovers the cursor over it, a question input component is displayed, allowing the user to enter their question in natural language. The user can then use this component to input the question message, such as "Add an extension point to this component."
[0037] In summary, in response to the triggering operation of the question input component, the question information associated with the question code is determined, enabling the submission of question information through the question input component, and ensuring that users can submit code editing-related questions in real time based on the code editing page.
[0038] Step 104: Determine the target project corresponding to the code editing page, and query the project code library and project knowledge base of the target project based on the problem information to obtain the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base.
[0039] Specifically, after responding to the user's code editing operation and determining the issue information associated with the problematic code on the code editing page, the target project corresponding to the code editing page can be identified. Based on the issue information, the project's code repository and knowledge base are queried to obtain the corresponding reference code documents in the project code repository and the corresponding reference knowledge documents in the project knowledge base. The target project can be an application development project, a front-end framework project, or an engineering project in the software development process. The target project's code repository is a database built upon its code documents, storing structured code documents. The target project's knowledge base is a database built upon its knowledge documents, storing structured project development knowledge. Code documents can be the target project's source code documents, and knowledge documents can be manually written architecture design documents, evolution documents, and Q&A data documents from the target project's development process. Reference code documents are code documents retrieved from the project code repository that match the issue information, and reference knowledge documents are knowledge documents retrieved from the project knowledge base that match the issue information.
[0040] Based on this, after responding to the user's code editing operation and determining the issue information associated with the problematic code on the code editing page, the target project corresponding to the code editing page is identified, and the project's code repository and knowledge base are queried based on the issue information. The project's code repository is queried based on the issue information to obtain the corresponding reference code documentation, and the project's knowledge base is queried based on the issue information to obtain the corresponding reference knowledge documentation.
[0041] Furthermore, considering that the question information is natural language content input by the user, directly inputting the question information into the code generation model might affect the code generation by the stop words and other content in the question information. Therefore, after determining the question information, entity recognition and intent recognition can be performed on the question information, as specifically implemented as follows: The problem information is preprocessed to obtain target problem information; the target problem information is subjected to intent recognition to obtain intent information; and the target problem information is subjected to entity recognition to obtain entity information.
[0042] Specifically, preprocessing methods for question information include, but are not limited to, word segmentation and stop word removal. Intent recognition of the target question information can utilize classification models to identify intent information representing the intention to ask the question. Intent information types include, but are not limited to, API usage, plugin design, extension point triggering, performance optimization, and clarification intents. Entity recognition of the target question information can leverage Neural Entity Recognition (NER) to extract entities from the target question information. Entity information can include entity name and entity type.
[0043] Based on this, the question information undergoes preprocessing such as word segmentation and stop word removal to obtain the target question information. Intent recognition is then performed on the target question information to obtain intent information representing the intent to ask the question, and entity recognition is performed on the target question information to obtain entity information including entity name and entity type.
[0044] Continuing with the previous example, if the question information is determined to be "How to use timeService to get the current time?", we can perform word segmentation and stop word removal on the question information to obtain the target question information "how, use, timeService, get, current time". Performing intent recognition and entity extraction on the target question information yields the intent information "how to use timeService" and the entity information "Entity 1: "timeService" → Type: Service, ID: servos-core / time / TimeService".
[0045] In summary, by performing intent recognition on the target question information to obtain intent information, and by performing entity recognition on the target question information to obtain entity information, subsequent queries can be performed in the project code repository and project knowledge base based on the intent information and entity information, ensuring the accuracy of the reference knowledge documents and reference code documents obtained.
[0046] Furthermore, the target project's codebase needs to contain the relevant code for the target project. This can be achieved by structuring the code documents associated with the target project, as detailed below: Identify the code documents associated with the target project and construct the code syntax tree corresponding to the code documents; identify at least one code entity in the code syntax tree and determine the entity relationship information corresponding to the at least one code entity; generate structured code documents corresponding to the at least one code entity based on the at least one code entity and the entity relationship information, and construct the project code library based on the at least one structured code document.
[0047] Specifically, the code document associated with the target project can be at least one source code document related to the target project. The code syntax tree corresponding to the code document is an abstract syntax tree constructed by performing lexical and syntactic analysis on the code document. The types of code entities identified in the code syntax tree include, but are not limited to, modules, services, interfaces, types, functions, classes, and decorators. The entity relationship information corresponding to at least one code entity refers to the entity relationship between at least one code entity determined according to the code syntax tree. Entity relationships include, but are not limited to, dependency relationships, call relationships, inheritance relationships, implementation relationships, and extension relationships. The structured code document contains entities and the relationship graph corresponding to the entity relationship information, forming a network code knowledge structure.
[0048] Based on this, the code documents associated with the target project are identified, and lexical and syntactic analysis are performed on these documents. A code syntax tree is constructed based on the analysis results. At least one code entity is identified within the code syntax tree, and entity information for each entity is extracted, along with the corresponding entity relationship information. Based on the at least one code entity and its relationship information, a structured code document is generated for each entity. This structured code document contains a network of code knowledge based on the entity relationship information. Finally, a project codebase is built based on at least one structured code document.
[0049] Following the previous example, when determining the front-end framework source code documentation for a target project, this documentation can be used as the code documentation. Lexical and syntactic analysis is performed on the front-end framework source code, and an Automatic Syntax Tree (ATS) is constructed based on the analysis results. Within the ATS, entities of various types, such as modules, services, interfaces, types, functions, classes, and decorators, are identified based on criteria such as export statements, @Service decorators, interface keywords, type keywords, function / const arrow functions, class keywords, and @ symbols. The module entity's module path and exported content are extracted; the service entity's class name, method signature, and comments; the interface entity's interface name, attributes, and type; the type entity's type name and type definition; the function entity's function name, parameters, and return value; the class entity's class name, parent class, methods, and attributes; and the decorator entity's decorator name and parameters. The dependency, call, inheritance, implementation, and extension relationships between these code entities are determined, and a structured code document is constructed for each entity. A relationship graph is embedded in each structured code document, forming a structured code document like this: Figure 2 The diagram shows a network knowledge structure. This network knowledge structure includes entity nodes such as applications, extensions, extension points, time services, scheduled task modules, event buses, and state synchronization modules, as well as the relationships between these entity nodes.
[0050] In summary, a project codebase is built based on at least one structured code document, which is then converted into a structured code document and stored in the project codebase. Subsequently, the project codebase can be queried based on issue information to obtain highly accurate project code.
[0051] Furthermore, the project knowledge base of the target project needs to contain relevant knowledge about the target project. This can be achieved by structuring at least one knowledge document associated with the target project. The specific implementation is as follows: Identify at least one knowledge document associated with the target project, and preprocess the at least one knowledge document to obtain multiple target knowledge fragments; add knowledge tags to the multiple target knowledge fragments respectively, and construct the project knowledge base containing index information based on the multiple target knowledge fragments and the knowledge tags corresponding to the multiple target knowledge fragments respectively.
[0052] Specifically, at least one knowledge document associated with the target project can be a manually written architecture design document, evolution record, or Q&A document related to the target project. The knowledge document records the usage methods and SDK integration methods of the specific software corresponding to the target project, as well as the design ideas and usage methods of the software or SDK. Preprocessing of at least one knowledge document can involve format standardization, including but not limited to document format conversion, removal of noisy data, and extraction of core data. The target knowledge fragment is the knowledge content obtained from preprocessing each knowledge document. Knowledge tags can be category tags for the target knowledge fragment, and can be categorized according to knowledge modules. Index information is constructed based on each target knowledge fragment and is used to represent the directory of target knowledge fragments stored in the project knowledge base.
[0053] Based on this, at least one knowledge document associated with the target project is identified, and this document is preprocessed to convert it into a unified format. Noise is removed from each document, and core knowledge data is extracted to obtain multiple target knowledge fragments. Knowledge tags are added to each target knowledge fragment according to its knowledge module category. A project knowledge base containing index information is constructed based on the multiple target knowledge fragments and their corresponding knowledge tags. Structured knowledge documents are then constructed based on the multiple target knowledge fragments, their corresponding knowledge tags, and the relationships between them, and are stored in the project knowledge base.
[0054] Following the previous example, the target project's architecture design document, evolution record, and Q&A document are treated as knowledge documents. These documents are converted to Markdown format, and the core data of each is extracted. Specifically, core data such as order services and payment services are extracted from the architecture design document; core data such as order service splitting decisions are extracted from the evolution record; and core data such as question-and-answer data pairs are extracted from the Q&A document. This extracted core data is then used as target knowledge fragments. Knowledge type tags (knowledge tags) are added to each target knowledge fragment, and dependencies between them are established, constructing a project knowledge base containing index information for the target knowledge fragments. The project knowledge base records the identifier, title, core content, knowledge category, difficulty level, and modification time of each target knowledge fragment.
[0055] In summary, a project knowledge base containing index information is constructed based on multiple target knowledge fragments and their corresponding knowledge tags. Subsequently, the project knowledge base can be queried based on question information to obtain highly accurate project knowledge.
[0056] Furthermore, considering that the target project's code repository and knowledge base are two different types of databases, to ensure the accuracy of the subsequently generated target code, the project code repository and knowledge base can be queried separately based on the intent information and entity information of the question information. The specific implementation is as follows: Based on the intent information and entity information of the question information, multiple queries are performed in the project code library of the target project to obtain directly related documents and indirectly related documents, and these directly related documents and indirectly related documents are used as reference code documents corresponding to the project code library; based on the intent information and entity information of the question information, multiple queries are performed in the project knowledge base of the target project to obtain directly related documents and indirectly related documents, and these directly related documents and indirectly related documents are used as reference knowledge documents corresponding to the project knowledge base.
[0057] Specifically, queries can be performed in both the project code repository and the project knowledge base using vector retrieval. Multi-way queries in the project code repository include, but are not limited to, keyword search, semantic search, entity linking, and relationship graph retrieval. Directly related code documents are those with a direct relationship to entity and intent information, while indirectly related documents are those with an indirect dependency relationship. Multi-way queries in the project knowledge base include, but are not limited to, keyword search, semantic search, entity linking, and relationship graph retrieval. Directly related knowledge documents are those with a direct relationship to entity and intent information, while indirectly related knowledge documents are those with an indirect dependency relationship.
[0058] Based on this, multiple queries, including keyword retrieval, semantic retrieval, entity linking, and relationship graph retrieval, are performed in the target project's codebase using intent and entity information from the question information. This yields directly related documents that are directly associated with the entity and intent information, as well as indirectly related documents. These directly and indirectly related documents are then used as reference code documents in the corresponding project codebase. Similarly, multiple queries, including keyword retrieval, semantic retrieval, entity linking, and relationship graph retrieval, are performed in the target project's knowledge base using intent and entity information from the question information. This yields directly and indirectly related knowledge documents that are directly associated with the entity and intent information, as well as indirectly related documents. These directly and indirectly related knowledge documents are then used as reference knowledge documents in the corresponding project knowledge base.
[0059] Continuing with the previous example, based on the intent information "how to use timeService" and the entity information "Entity 1: "timeService" → Type: Service, ID: servos-core / time / TimeService", multi-path queries are performed in the target project's codebase, including keyword search, semantic search, entity linking, and relationship graph search. This yields API documentation directly related to the intent and entity information, as well as lifecycle documentation (dependent API documentation) that is indirectly related to the intent and entity information, and extension point documentation that is depended upon by the intent and entity information. The source code documentation in the project codebase provides accurate API references, type definitions, and call relationships. These directly and indirectly related documents are used as reference code documentation for the corresponding project codebase. Based on the intent information "how to use timeService" from the question information and the entity information "Entity 1: "timeService" → Type: Service, ID: servos-core / time / TimeService", multiple queries are performed in the target project's knowledge base, including keyword search, semantic search, entity link search, and relationship graph search. This yields component usage guides directly related to the intent and entity information, as well as knowledge documents that are indirectly related to or dependent on the intent and entity information. Human-generated knowledge documents can provide high-level design intents, practical data, and case studies. Directly and indirectly related knowledge documents are used as reference knowledge documents in the project knowledge base.
[0060] In summary, by querying the project code repository and project knowledge base based on the intent information and entity information of the question information respectively, a dual-source knowledge base query is achieved, ensuring the accuracy of the retrieved reference knowledge documents and reference code documents.
[0061] Step 106: Input the problem code, the problem information, the reference knowledge document, and the reference code document into the code generation model to generate the target code associated with the problem code.
[0062] Specifically, after identifying the target project corresponding to the code editing page and querying the project's code repository and knowledge base based on the problem information to obtain the corresponding reference code document and knowledge document, the problem code, problem information, reference knowledge document, and reference code document can be input into the code generation model to generate target code associated with the problem code. The code generation model can be a large language model, used to analyze the problem code, problem information, reference knowledge document, and reference code document to generate target code for answering the problem information. The target code can be used to replace the problem code, or it can be used to continue, expand, or add functionality to the target code. The target code can also be used to update the problem code.
[0063] Based on this, after determining the target project corresponding to the code editing page, and querying the project code library and project knowledge base of the target project based on the problem information, and obtaining the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base, the problem code, problem information, reference knowledge document and reference code document are input into the code generation model. The code generation model is then used to analyze the problem code, problem information, reference knowledge document and reference code document to generate the target code associated with the problem code.
[0064] In practical applications, prompts can be built based on the problem information. These prompts, along with the problem code, problem information, reference knowledge documents, and reference code documents, are input into the code generation model. The code generation model can then generate target code based on the prompts. The prompts include, but are not limited to, a problem summary, core concepts, implementation methods, code examples, parameter descriptions, precautions, and related documentation. The target code output by the code generation model includes, but is not limited to, code examples and code explanations.
[0065] Furthermore, after identifying the target code, to improve the user's Q&A experience, the target code can be directly added to the code editing page, enabling automatic updates of the question code on the code editing page. The specific implementation is as follows: The problem code in the code editing page is updated based on the target code to obtain the target problem code.
[0066] Specifically, updating the issue code in the code editing page based on the target code can involve inserting the target code into the position of the issue code to continue writing the issue code. Alternatively, it can involve modifying the issue code based on the target code to ensure the accuracy of the resulting target issue code. If the target code includes code snippets and code descriptions, the issue code can be updated based on the code snippets, and the code descriptions can be added as comments to the position of the target issue code.
[0067] Based on this, after determining the target code, the code snippets within the target code are identified. The problem code in the code editing page is then updated based on these code snippets to obtain the target problem code. The code description content from the target code can then be added to the location of the target problem code.
[0068] In summary, by updating the question code on the code editing page based on the target code, the target question code can be obtained. This allows for direct modification of the question code on the code editing page based on the target code, achieving a seamless connection between Q&A and code modification. It provides both knowledge Q&A functionality and code editing assistant functionality.
[0069] Furthermore, after updating the issue code on the code editing page based on the target code, it indicates that the project code of the target project has changed. Considering that the project code repository and project knowledge base will still be needed to implement Q&A during the development or maintenance of the target project, in order to ensure the accuracy of subsequent Q&A, the project code repository and project knowledge base can be updated based on the changed code, and the modification of the issue code can be synchronized to the project code repository and project knowledge base. The specific implementation is as follows: If it is determined that the problem code needs to be updated based on the target code, the change code is determined; the project codebase and the project knowledge base are updated based on the change code.
[0070] Specifically, modified code refers to the code and its accompanying documentation obtained after modifying or adding code to the problematic code based on the target code. The project codebase can be updated based on the modified code, and the project knowledge base can be updated based on the documentation within the modified code.
[0071] Based on this, after determining that the problematic code should be updated based on the target code, the changed code is identified. Documentation is then merged based on the changed code, and relevant code-related questions and answers are identified in the project codebase, while relevant knowledge documents are identified in the project knowledge base. The project codebase and project knowledge base are then updated based on the document updates for the changed code.
[0072] Continuing with the previous example, Git Webhooks can be used to detect code updates to the target project. Once it's confirmed that problematic code has been updated based on the target code and the changed code is obtained, the project codebase and project knowledge base can be updated accordingly. The details of the changes in the changed code should be analyzed, and the relevant documentation in the project codebase and project knowledge base should be adjusted based on these details. After updating the project codebase and project knowledge base, the updated versions can be tested to ensure successful updates.
[0073] In summary, updating the project codebase and project knowledge base based on code changes enables data synchronization between the two, achieving an automated data update loop from code to data.
[0074] Furthermore, considering that the usability and accuracy of the initial code generated by the code generation model may be low, after determining the initial code, it can be tested in at least one detection dimension. If the detection passes, the usable target code is determined. The specific implementation is as follows: The problem code, the problem information, the reference knowledge document, and the reference code document are input into the code generation model to obtain initial code associated with the problem code; if the initial code passes code detection in at least one detection dimension, the initial code is used as the target code.
[0075] Specifically, initial code refers to the code output by the code generation model based on the analysis of problem code, problem information, reference knowledge documents, and reference code documents. At least one detection dimension is required, including but not limited to API validation, syntax checking, and type checking. If the initial code passes the code validation across at least one of these dimensions, it means the initial code has been validated and can be used to update the problem code.
[0076] Based on this, the problem code, problem information, reference knowledge documents, and reference code documents are input into the code generation model to obtain the initial code associated with the problem code. The initial code is then tested and verified in at least one of the following dimensions: API validation, syntax checking, and type checking. If the initial code passes the code testing in at least one dimension, it is used as the target code.
[0077] In summary, if the initial code passes code detection in at least one detection dimension, the initial code is used as the target code. Multiple detection methods, such as API verification and syntax checking, are applied to the initial code to ensure the accuracy and usability of the target code.
[0078] This specification provides a code generation method according to one embodiment, which, in response to a user's code editing operation, determines the problem information associated with the problematic code on the code editing page. It identifies the target project corresponding to the code editing page and queries the target project's project codebase and project knowledge base based on the problem information to obtain reference code documents corresponding to the project codebase and reference knowledge documents corresponding to the project knowledge base. It then queries the target project's project codebase and project knowledge base based on the problem information to retrieve reference knowledge documents related to the problem information, obtaining reference code documents and reference knowledge documents at the code and knowledge dimensions, respectively. The problematic code, problem information, reference knowledge documents, and reference code documents are input into the code generation model to generate target code associated with the problematic code. Finally, it generates target code associated with the problematic code based on the reference knowledge documents and reference code documents, achieving knowledge and code fusion, improving the matching degree between the target code and the problem information, improving the generation efficiency and accuracy of the target code, and ensuring the knowledge coverage of the target code.
[0079] The following is in conjunction with the appendix Figure 3 Taking the code generation method provided in this specification as an example in code editing, the code generation method will be further explained. Figure 3 The flowchart of a code generation method according to an embodiment of this specification is shown, which specifically includes the following steps.
[0080] Step 302: In response to the user's code editing operation, determine the problem information associated with the problem code on the code editing page.
[0081] In code editing scenarios, users (developers) can use natural language dialogue to have AI modify code files, upgrading knowledge-based Q&A to a programming assistant, providing users with a development experience where chatting is coding.
[0082] In practical applications, users can edit problematic code on the code editing page. Problematic code can be code that users have questions about and need answers to, or code that needs further development, such as APIs. The problem information is the user's edited natural language question, such as: "How do I use this extension point?".
[0083] In practice, the user places the cursor on the problem code, and a problem input component is provided. The user can input the problem information by clicking or performing other touch operations on the problem input component, and then submit it to the programming assistant.
[0084] Step 304: Determine the target project corresponding to the code editing page, and determine the project code repository and project knowledge base of the target project.
[0085] The target project is the project from which the user raised the question. The target project can be any project that requires code editing, such as an application development project or a front-end framework project. The project code repository is a code documentation library built based on the source code documentation of the target project, while the project knowledge base is a project knowledge documentation library built based on human-generated knowledge documentation of the target project.
[0086] The target project's human-written knowledge documentation includes, but is not limited to, manually written project architecture design documents, evolution records, and Q&A documents. These documents, written by experienced engineers, explain specific software usage methods and SDK integration approaches to second- or third-party engineers. To ensure that inexperienced second- or third-party engineers can understand the content and effectively solve their own problems, these documents use detailed, rich, and even redundant text, introducing the software or SDK's design principles, usage methods, and practical data in a progressive manner. After standardizing the format and categorizing the human-written knowledge documentation, a project knowledge base is constructed; this project knowledge base is a structured human-written document knowledge base.
[0087] Lexical and syntactic analysis is performed on the source code documentation of the target project to generate an abstract syntax tree (AST). Entities of various types, such as modules, services, interfaces, types, functions, classes, and decorators, are identified from the AST. Relationships between these entities are analyzed, and a structured document is generated for each entity. A relationship graph is embedded within the structured document to form a network-like knowledge structure. A project code knowledge base is then built based on the structured documents corresponding to each entity.
[0088] Step 306: Based on the problem information, query the project code repository and project knowledge base of the target project to obtain the reference code documents corresponding to the project code repository and the reference knowledge documents corresponding to the project knowledge base.
[0089] Before querying the project codebase and project knowledge base based on question information, an intelligent question-answering agent can be used to identify and classify the question information to obtain intent and entity information. Utilizing a multi-path retrieval strategy (keyword retrieval, semantic retrieval, entity link retrieval, and relationship graph retrieval), the project codebase and project knowledge base are queried separately based on the intent and entity information. Reference code documents corresponding to the entity and intent information are retrieved from the project codebase, and reference knowledge documents corresponding to the entity and intent information are retrieved from the project knowledge base. The reference code documents include documents directly related to the entity and intent information, as well as code documents indirectly related (dependent on or depended upon) to the entity and intent information. Similarly, the reference knowledge documents include documents directly related to the entity and intent information, as well as knowledge documents indirectly related (dependent on or depended upon) to the entity and intent information.
[0090] Step 308: Input the problem code, problem information, reference knowledge document, and reference code document into the code generation model to obtain the initial code associated with the problem code.
[0091] The code generation model is also known as the large language model. It can build a prompt and integrate the problem code, problem information, reference knowledge documents, and reference code documents to generate the initial code corresponding to the problem information. The initial code includes code content and code description.
[0092] Step 310: If the initial code passes code detection in at least one detection dimension, use the initial code as the target code.
[0093] Before sending the initial code to the user, it can be checked and verified in terms of API, syntax, and types to ensure its accuracy and reliability. Once the initial code passes the checks, it can be sent to the user as the final target code.
[0094] Step 312: Update the problem code in the code editing page based on the target code to obtain the target problem code.
[0095] In practical applications, the issue code on the code editing page can be updated directly based on the target code, or it can be updated based on the target code after user confirmation to obtain the target issue code. Methods for updating the issue code include, but are not limited to, adding and modifying.
[0096] Step 314: If it is determined that the problem code should be updated based on the target code, identify the changed code and update the project codebase and project knowledge base based on the changed code.
[0097] In practical applications, changes can be detected in the code on the code editing page. If changes are detected in the code on the code editing page, incremental parsing of the changed code and updates to the project code repository and project knowledge base can be automatically triggered.
[0098] The code generation method provided in this embodiment combines manually written architecture documents with automatically generated API documentation from source code to construct a dual-source knowledge base. The manually written documentation provides high-level design intent, practical data, and case studies, while the source code documentation provides accurate API references, type definitions, and call relationships, thus integrating code with code writing knowledge. By analyzing the source code documentation through abstract syntax trees, entities and their relationships are automatically extracted, constructing a network-like knowledge structure. Dependencies, calls, and inheritance relationships between modules are preserved, supporting jumps from any module to related modules, enabling cross-module knowledge association and reasoning. Through the MCP protocol, knowledge question-and-answer capabilities are deeply integrated into the programming assistant, providing actionable coding suggestions (code snippets, parameter completion, refactoring suggestions) to achieve "question-and-answer as coding," deeply merging "question-and-answer" and "coding." Through code change detection, incremental parsing and knowledge base updates are automatically triggered, achieving an automated closed loop from code to knowledge. By combining keyword retrieval, semantic retrieval, entity link retrieval, and relationship graph retrieval, a multi-path recall strategy is adopted to improve the accuracy and coverage of knowledge retrieval. It not only returns directly related documents but also dependent and dependent documents, constructing a complete knowledge context that significantly improves the accuracy of knowledge retrieval. Structured answers are generated based on templates, and API validation, syntax checking, and type checking are used to ensure answer accuracy, significantly improving the credibility and usability of the answers.
[0099] In practical applications, such as Figure 4 As shown, the code generation method includes modules such as a protocol layer, an intelligent agent, user interaction, a knowledge base, and automated synchronization. In the user interaction layer, users can submit questions to the intelligent agent regarding problematic code, enabling developers to ask questions. In the protocol layer, the code processing component sends the question information and the problematic code to the intelligent agent. The intelligent agent performs intent and entity recognition on the question information, and based on the recognized intent and entity information, performs knowledge retrieval in a knowledge base composed of a human-generated document knowledge base and a source code generation document knowledge base, and generates an answer corresponding to the question information based on the detected knowledge documents. After verifying the answer, it provides feedback to the user with the answer and coding suggestions. The automated synchronization module performs real-time change detection on the user-edited code. When code changes are detected, it performs incremental parsing and document merging of the changed code, and synchronizes the updated content to the knowledge base.
[0100] Corresponding to the above method embodiments, this specification also provides code generation system embodiments. Figure 5 A schematic diagram of the structure of a code generation system provided in one embodiment of this specification is shown. For example... Figure 5As shown, the code generation system 500 includes a client 510 and a server 520. The client 510 is configured to submit an operation instruction to the server 520 in response to a user's code editing operation. The server 520 is configured to determine, in response to the operation instruction, issue information associated with the problematic code; determine the target project corresponding to the code editing page, and query the project code library and project knowledge base of the target project based on the issue information to obtain reference code documents corresponding to the project code library and reference knowledge documents corresponding to the project knowledge base; input the problematic code, the issue information, the reference knowledge documents, and the reference code documents into the code generation model to generate the target code associated with the problematic code, and send the target code to the client 510.
[0101] This specification provides a code generation system in one embodiment, comprising a client and a server. When a client user has code generation and code inspection needs, they can submit operation instructions to the server through the client's code editing page. The server responds to the operation instructions by determining the problem information associated with the problematic code. It identifies the target project corresponding to the code editing page and queries the target project's project codebase and project knowledge base based on the problem information to obtain reference code documents corresponding to the project codebase and reference knowledge documents corresponding to the project knowledge base. It then queries the target project's project codebase and project knowledge base based on the problem information to retrieve reference knowledge documents related to the problem information, obtaining reference code documents and reference knowledge documents at the code and knowledge dimensions, respectively. The problematic code, problem information, reference knowledge documents, and reference code documents are input into the code generation model to generate target code associated with the problematic code, which is then sent to the client. The generation of target code associated with the problematic code based on the reference knowledge documents and reference code documents achieves knowledge and code fusion, improves the matching degree between the target code and the problem information, improves the generation efficiency and accuracy of the target code, and ensures the knowledge coverage of the target code.
[0102] In practical applications, such as Figure 6As shown, during code editing, users can modify and edit code through the code assistant and code processing component. When a user needs an explanation of a target API in the code, they can position the cursor on the target API on the code editing page and edit the question information in natural language: "Ask a question, how to use this extension point," submitting an operation instruction to the server-side code assistant based on the question information. The server-side code assistant treats the target API as the question code and sends the question code and question information to the code processing component. The code processing component parses the question code and its related context, identifies the target API name, and retrieves API documentation, usage examples, and specific practices from the project code repository and project knowledge base in the database. It obtains relevant knowledge related to the question code and question information, such as reference code documentation and reference knowledge documentation, and feeds this knowledge back to the code processing component. The code processing component generates code snippets and code descriptions based on the reference code documentation, reference knowledge documentation, question information, and question code, and sends these to the code assistant. The code assistant constructs the answer and suggested code corresponding to the question information based on the code snippets and code descriptions. After the user clicks on the suggested code, the code can be inserted at the cursor position, achieving automatic editing of the target API's code. After generating suggested code, the code can be directly added to the cursor position, enabling automatic code editing and insertion based on natural language question answering. In specific implementation, such as... Figure 7 As shown, the code generation system comprises an application layer, an extension layer, and a service layer. The application layer includes application and lifecycle management. The extension layer is used to extend the application's code, components, and APIs, registering these extensions with extension points. The service layer provides time services, event services, account services, and context services; the time and event services are used by the application. The event module and the state synchronization module form a dependency relationship.
[0103] Corresponding to the above method embodiments, this specification also provides embodiments of a code generation apparatus. Figure 8 A schematic diagram of a code generation apparatus according to one embodiment of this specification is shown. Figure 8 As shown, the device includes: Module 802 is configured to respond to a user's code editing operation by determining the problem information associated with the problem code on the code editing page. The query module 804 is configured to determine the target project corresponding to the code editing page, and query the project code library and project knowledge base of the target project based on the problem information to obtain the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base; The input module 806 is configured to input the problem code, the problem information, the reference knowledge document, and the reference code document into the code generation model to generate target code associated with the problem code.
[0104] In one optional embodiment, the construction of the project codebase includes: Identify the code documents associated with the target project and construct the code syntax tree corresponding to the code documents; Identify at least one code entity in the code syntax tree and determine the entity relationship information corresponding to the at least one code entity; Based on the at least one code entity and the entity relationship information, generate structured code documents corresponding to the at least one code entity, and construct the project code library based on the at least one structured code document.
[0105] In one optional embodiment, the construction of the project knowledge base includes: Identify at least one knowledge document associated with the target project, and preprocess the at least one knowledge document to obtain multiple target knowledge fragments; A knowledge tag is added to each of the multiple target knowledge fragments, and a project knowledge base containing index information is constructed based on the multiple target knowledge fragments and the knowledge tags corresponding to each of the multiple target knowledge fragments.
[0106] In an optional embodiment, after determining the issue information associated with the issue code, the method further includes: The problem information is preprocessed to obtain the target problem information; The target question information is subjected to intent recognition to obtain intent information, and the target question information is subjected to entity recognition to obtain entity information.
[0107] In one optional embodiment, based on the problem information, the project code repository and project knowledge base of the target project are queried to obtain reference code documents corresponding to the project code repository and reference knowledge documents corresponding to the project knowledge base, including: Based on the intent information and entity information of the problem information, multiple queries are performed in the project code library of the target project to obtain directly related documents and indirectly related documents, and the directly related documents and indirectly related documents are used as reference code documents corresponding to the project code library; Based on the intent information and entity information of the question information, multiple queries are performed in the project knowledge base of the target project to obtain directly related documents and indirectly related documents, and the directly related documents and indirectly related documents are used as reference knowledge documents corresponding to the project knowledge base.
[0108] In one optional embodiment, in response to a user's code editing operation, problem information associated with the problematic code on the code editing page is determined, including: In response to the code editing operation on the code editing page for the problematic code, a problem input component is displayed on the code editing page; In response to a triggering operation on the question input component, the question information associated with the question code is determined.
[0109] In an optional embodiment, after inputting the problem code, the problem information, the reference knowledge document, and the reference code document into the code generation model to generate the target code associated with the problem code, the method further includes: The problem code in the code editing page is updated based on the target code to obtain the target problem code.
[0110] In an optional embodiment, after inputting the problem code, the problem information, the reference knowledge document, and the reference code document into the code generation model to generate the target code associated with the problem code, the method further includes: If it is determined that the problematic code needs to be updated based on the target code, then the code to be changed is determined; The project codebase and the project knowledge base are updated based on the changed code.
[0111] In one optional embodiment, the problem code, the problem information, the reference knowledge document, and the reference code document are input into a code generation model to generate target code associated with the problem code, including: The problem code, the problem information, the reference knowledge document, and the reference code document are input into the code generation model to obtain the initial code associated with the problem code; If the initial code passes code detection in at least one detection dimension, the initial code is used as the target code.
[0112] This specification provides a code generation method according to one embodiment, which, in response to a user's code editing operation, determines the problem information associated with the problematic code on the code editing page. It identifies the target project corresponding to the code editing page and queries the target project's project codebase and project knowledge base based on the problem information to obtain reference code documents corresponding to the project codebase and reference knowledge documents corresponding to the project knowledge base. It then queries the target project's project codebase and project knowledge base based on the problem information to retrieve reference knowledge documents related to the problem information, obtaining reference code documents and reference knowledge documents at the code and knowledge dimensions, respectively. The problematic code, problem information, reference knowledge documents, and reference code documents are input into the code generation model to generate target code associated with the problematic code. Finally, it generates target code associated with the problematic code based on the reference knowledge documents and reference code documents, achieving knowledge and code fusion, improving the matching degree between the target code and the problem information, improving the generation efficiency and accuracy of the target code, and ensuring the knowledge coverage of the target code.
[0113] 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.
[0114] Figure 9 A structural block diagram of a computing device 900 according to one embodiment of this specification is shown. The components of the computing device 900 include, but are not limited to, a memory 910 and a processor 920. The processor 920 is connected to the memory 910 via a bus 930, and a database 950 is used to store data.
[0115] The computing device 900 also includes an access device 940, which enables the computing device 900 to communicate via one or more networks 960. 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 940 may include one or more of any type of wired or wireless network interface (e.g., a network interface card (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.
[0116] In one embodiment of this specification, the aforementioned components of the computing device 900 and Figure 9 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 9 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0117] The computing device 900 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 900 can also be a mobile or stationary server.
[0118] The processor 920 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.
[0119] 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 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 computing device, please refer to the description of the technical solution of the code generation method described above.
[0120] An embodiment of this specification also provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the steps of the code generation method described above.
[0121] 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 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 storage medium, please refer to the description of the technical solution of the code generation method described above.
[0122] An embodiment of this specification also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the code generation method described above.
[0123] The above is an illustrative scheme of a computer program product according to this embodiment. It should be noted that the technical solution of this computer program product 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 computer program product, please refer to the description of the technical solution of the code generation method described above.
[0124] The foregoing has described specific embodiments of this specification. 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 result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0125] 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.
[0126] 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 in this specification are not limited to the described order of actions, because according to the embodiments in this specification, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments in this specification.
[0127] 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.
[0128] The preferred embodiments disclosed above are merely illustrative of this specification. 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 described herein. These embodiments are selected and specifically described in this specification to better explain the principles and practical applications of the embodiments, thereby enabling those skilled in the art to better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.
Claims
1. A code generation method, comprising: In response to a user's code editing action, determine the issue information associated with the problematic code on the code editing page; Identify the target project corresponding to the code editing page, and query the project code library and project knowledge base of the target project based on the problem information to obtain the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base; The problem code, the problem information, the reference knowledge document, and the reference code document are input into the code generation model to generate the target code associated with the problem code.
2. The code generation method according to claim 1, wherein the construction of the project code repository includes: Identify the code documents associated with the target project and construct the code syntax tree corresponding to the code documents; Identify at least one code entity in the code syntax tree and determine the entity relationship information corresponding to the at least one code entity; Based on the at least one code entity and the entity relationship information, generate structured code documents corresponding to the at least one code entity, and construct the project code library based on the at least one structured code document.
3. The code generation method according to claim 1, wherein the construction of the project knowledge base includes: Identify at least one knowledge document associated with the target project, and preprocess the at least one knowledge document to obtain multiple target knowledge fragments; A knowledge tag is added to each of the multiple target knowledge fragments, and a project knowledge base containing index information is constructed based on the multiple target knowledge fragments and the knowledge tags corresponding to each of the multiple target knowledge fragments.
4. The code generation method according to claim 1, after determining the problem information associated with the problem code, further includes: The problem information is preprocessed to obtain the target problem information; The target question information is subjected to intent recognition to obtain intent information, and the target question information is subjected to entity recognition to obtain entity information.
5. The code generation method according to claim 4, wherein querying the project code library and project knowledge base of the target project based on the problem information to obtain the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base includes: Based on the intent information and entity information of the problem information, multiple queries are performed in the project code library of the target project to obtain directly related documents and indirectly related documents, and the directly related documents and indirectly related documents are used as reference code documents corresponding to the project code library; Based on the intent information and entity information of the question information, multiple queries are performed in the project knowledge base of the target project to obtain directly related documents and indirectly related documents, and the directly related documents and indirectly related documents are used as reference knowledge documents corresponding to the project knowledge base.
6. The code generation method according to claim 1, wherein determining the problem information associated with the problematic code in the code editing page in response to the user's code editing operation includes: In response to the code editing operation on the code editing page for the problematic code, a problem input component is displayed on the code editing page; In response to a triggering operation on the question input component, the question information associated with the question code is determined.
7. The code generation method according to claim 1, after inputting the problem code, the problem information, the reference knowledge document, and the reference code document into the code generation model to generate the target code associated with the problem code, further includes: The problem code in the code editing page is updated based on the target code to obtain the target problem code.
8. The code generation method according to claim 7, after inputting the problem code, the problem information, the reference knowledge document, and the reference code document into the code generation model to generate the target code associated with the problem code, further includes: If it is determined that the problematic code needs to be updated based on the target code, then the code to be changed is determined; The project codebase and the project knowledge base are updated based on the changed code.
9. The code generation method according to claim 1, wherein inputting the problem code, the problem information, the reference knowledge document, and the reference code document into the code generation model to generate the target code associated with the problem code includes: The problem code, the problem information, the reference knowledge document, and the reference code document are input into the code generation model to generate the initial code associated with the problem code; If the initial code passes code detection in at least one detection dimension, the initial code is used as the target code.
10. A code generation system, comprising a client and a server, including: The client is used to submit operation instructions to the server in response to the user's code editing operation; The server is used to determine the problem information associated with the problem code in response to the operation instruction; Identify the target project corresponding to the code editing page, and query the project code library and project knowledge base of the target project based on the problem information to obtain the reference code document corresponding to the project code library and the reference knowledge document corresponding to the project knowledge base; The problem code, the problem information, the reference knowledge document, and the reference code document are input into the code generation model to generate target code associated with the problem code, and the target code is sent to the client.
11. A computing device, comprising: Memory and processor; The memory is used to store computer programs or instructions, and the processor is used to execute the computer programs or instructions, which, when executed by the processor, implement the steps of the code generation method according to any one of claims 1 to 9.
12. A computer-readable storage medium storing a computer program or instructions that, when executed by a processor, implement the steps of the code generation method according to any one of claims 1 to 9.
13. A computer program product comprising a computer program or instructions which, when executed by a processor, implement the steps of the code generation method according to any one of claims 1 to 9.