Method for determining code, device, medium, and program product
By generating contextual information for the code, the problem of language models being unable to handle large volumes of code is solved, enabling efficient code understanding and adjustment for large-scale software projects.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- BEIJING ZITIAO NETWORK TECH CO LTD
- Filing Date
- 2024-12-05
- Publication Date
- 2026-06-11
AI Technical Summary
In existing technologies, language models cannot effectively handle large volumes of code, making it impossible to understand and adapt the code of large-scale software projects.
By analyzing the syntax tree of the original code to generate contextual information, the code size is compressed while retaining necessary information, and the language model is used to process or update the code.
This greatly extends the capabilities of language models, enabling them to understand and process large-scale code, and improving the efficiency and accuracy of code adjustments.
Smart Images

Figure CN2024137242_11062026_PF_FP_ABST
Abstract
Description
Methods, devices, media, and program products used to determine code. Technical Field
[0001] This disclosure relates generally to the field of computers, and more specifically to methods for determining code, electronic devices, computer-readable storage media, and computer program products. Background Technology
[0002] Using language models to determine code is a cutting-edge technology in artificial intelligence for software development. Through deep learning, these models can understand and generate high-quality programming code. They can not only perform simple code completion tasks, but also automatically generate functional interfaces and modify variables based on requirements documents. With the help of language models, developers only need to describe the required functions or modify requirements in natural language, such as having the language model modify the value of a variable or add functional components to the interface. Subsequently, the language model will determine the code snippets that meet the requirements or directly adjust the original code. Summary of the Invention
[0003] According to exemplary embodiments of this disclosure, a method for determining code, an electronic device, a computer storage medium, and a computer program product are provided.
[0004] In a first aspect of this disclosure, a method for determining code is provided, the method comprising acquiring first code and user input, the user input indicating adjustments to the first code. The method further comprises generating context information of the first code based on a syntax tree of the first code. The method further comprises determining second code using a target model based on the first code, the context information, and the user input.
[0005] In a second aspect of this disclosure, an apparatus for determining code is provided. The apparatus includes a data acquisition module configured to acquire a first code and user input, the user input indicating adjustments to the first code. The apparatus also includes a context generation module configured to generate context information for the first code based on a syntax tree of the first code. Furthermore, the apparatus includes a code determination module configured to determine a second code using a target model based on the first code, the context information, and the user input.
[0006] In a third aspect of this disclosure, an electronic device is provided, comprising: at least one processing unit; and at least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions causing the electronic device to perform the method described in the first aspect of this disclosure when executed by the at least one processing unit.
[0007] In a fourth aspect of this disclosure, a computer-readable storage medium is provided having machine-executable instructions stored thereon, which, when executed by a device, cause the device to perform the method described in the first aspect of this disclosure.
[0008] In a fifth aspect of this disclosure, a computer program product is provided, including computer-executable instructions, wherein the computer-executable instructions, when executed by a processor, implement the method described in the first aspect of this disclosure.
[0009] The summary section is provided to introduce a series of concepts in a simplified form, which will be further described in the detailed description below. The summary section is not intended to identify key or essential features of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0010] Figure 1 shows a schematic diagram of an example environment in which embodiments of the present disclosure can be implemented;
[0011] Figure 2 shows a flowchart of a method for determining code according to an embodiment of the present disclosure;
[0012] Figure 3A illustrates a schematic diagram of the context information for generating source code according to an embodiment of the present disclosure;
[0013] Figure 3B illustrates a schematic diagram of the context information of the source code according to an embodiment of the present disclosure;
[0014] Figure 4A shows a schematic diagram of the code content of a module according to an embodiment of the present disclosure;
[0015] Figure 4B shows a schematic diagram of a syntax tree according to an embodiment of the present disclosure;
[0016] Figure 4C illustrates a schematic diagram of sub-context information according to an embodiment of the present disclosure;
[0017] Figure 5 illustrates a schematic diagram of the dependencies between modules according to an embodiment of the present disclosure;
[0018] Figure 6 illustrates a schematic diagram of the context information for generating source code according to an embodiment of the present disclosure;
[0019] Figures 7A-7B illustrate schematic diagrams of recall-related codes according to embodiments of the present disclosure;
[0020] Figure 8 illustrates a recall information diagram of associated modules according to an embodiment of the present disclosure;
[0021] Figure 9A shows a schematic diagram of target prompt word information according to an embodiment of the present disclosure;
[0022] Figure 9B shows a schematic diagram for determining code according to an embodiment of the present disclosure;
[0023] Figure 10 shows a schematic block diagram of an example apparatus according to some embodiments of the present disclosure;
[0024] Figure 11 shows a block diagram of an example device that can be used to implement embodiments of the present disclosure.
[0025] In all the accompanying figures, the same or similar reference numerals denote the same or similar elements. Detailed Implementation
[0026] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of these messages or information. It is understood that before using the technical solutions disclosed in the embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0027] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message. As an optional but non-limiting implementation, the prompt message can be sent to the user in the form of a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0028] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.
[0029] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0030] In the description of embodiments of this disclosure, the term "comprising" and similar terms should be understood as open-ended inclusion, i.e., "including but not limited to". The term "based on" should be understood as "at least partially based on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc., may refer to different or the same objects unless explicitly stated. Other explicit and implicit definitions may also be included below.
[0031] When using language models to determine (e.g., update) code, the size of the code that can be input is limited by the language model's reading capabilities. This limitation is particularly pronounced nowadays, with the maximum number of characters that can be input into a language model typically around 10,000. However, many software projects have codebases of hundreds of thousands or even millions of characters. This prevents technical personnel from using language models to understand such large amounts of source code, thus hindering their ability to adjust the source code using the language model.
[0032] To address this, this disclosure proposes a method for determining code. This method preprocesses the code to be adjusted by analyzing the syntax tree of the original code (i.e., the first code) to grasp its logical framework. This syntax tree is then used to generate contextual information for the original code. This contextual information significantly compresses the size of the original code while retaining the necessary information for the target model (such as a language model) to understand it. This allows the target model to understand, process, or update the original code with fewer characters, thus greatly extending the capabilities of the target model.
[0033] The embodiments of the present disclosure will now be described in further detail with reference to the accompanying drawings, wherein FIG1 shows a schematic diagram of an example environment 100 in which the embodiments of the present disclosure can be implemented. The example environment 100 includes a computing device 110 and a computing device 120. The computing device 110 may process data and deploy a target model (e.g., a language model) for providing response services to user devices (e.g., computing device 120) accessing the computing device 110. In some embodiments, the computing device 120 communicates with the computing device 110 via a network 130. The network 130 may include a wired network, a wireless network, or a combination thereof, for providing communication between the computing device 120 and the computing device 110. In some embodiments, the computing device 120 may be connected to the computing device 110 via a data cable; the present disclosure does not limit the connection method between the computing device 110 and the computing device 120.
[0034] The computing device 120 may have an application (e.g., a client program) or a browser capable of calling the language model installed. Taking system 100 in Figure 1 as an example, the computing device 120 can communicate with the computing device 110 via network 130, sending source code (i.e., first code) 112 and user input "Please add a functional component to improve brightness for the code I submitted" to the computing device 110. The computing device 110 receives the first code and user input from the computing device 120 via network 130, with the user input indicating adjustments to the first code. This embodiment does not limit the programming language used in the source code; for example, the source code can be written in programming languages such as C, C++, Python, and Java.
[0035] The computing device 110 can generate context information 114 of the source code 112 based on the syntax tree 113. Through the syntax tree 113, the computing device 110 can analyze the source code 112 to obtain multiple nodes, each representing a keyword of a syntactic structure. During this process, the computing device 110 can deploy syntax tree parsing tools. For different programming languages, corresponding syntax tree parsing tools can be used; these tools are specifically designed and optimized for the characteristics of different programming languages. After generating the context information 114, the computing device 110 can save it locally because it is a summary of the source code, belonging to compressed source code, and therefore occupies less space.
[0036] The computing device 110 can use a language model to determine the code (i.e., the second code) 116 to respond, based on the original code 112, context information 114, and user input. In this operation, the input to the language model is not the original code 112, but a portion of the original code 112 determined based on the context information 114.
[0037] According to the method of embodiments of this disclosure, computing device 110 can preprocess the code to be adjusted. By analyzing the syntax tree of the original code (i.e., the first code), the logical framework of the original code can be grasped, thereby generating contextual information of the original code with the help of the syntax tree. Because each node of the syntax tree indicates the main features of the syntactic structure of the original code, this contextual information can greatly compress the size of the original code while retaining the information necessary for the language model to understand the original code. This allows the language model to understand, process, or update the original code by reading fewer characters, which can greatly extend the capability boundaries of the language model.
[0038] As shown in Figure 1, in environment 100, network 130 can be used to transmit data between computing device 110 and computing device 120. Network 130 has a theoretical bandwidth, which refers to the maximum transmission speed supported by network 130. It represents the maximum amount of data that network 130 can transmit under ideal conditions, usually measured in bits per second (bps). For example, if the theoretical bandwidth of network 130 is 100 Mbps, it means that under ideal conditions it can transmit 100 megabits of data per second. However, in reality, due to other factors that may exist in the network (e.g., signal interference, bandwidth sharing, transmission delay, etc.), the actual transmission speed may not reach 100 Mbps.
[0039] As understood by those skilled in the art, instances of computing device 110 can be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers 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, CDN, and big data and artificial intelligence platforms. Servers can be connected directly or indirectly via wired or wireless communication, and this application does not impose any limitations on this.
[0040] The computing device 120 can be any type of mobile computing device, including mobile computers (e.g., personal digital assistants (PDAs), laptops, notebook computers, tablet computers, netbooks, etc.), mobile phones (e.g., cellular phones, smartphones, etc.), wearable computing devices (e.g., smartwatches, head-mounted devices, including smart glasses, etc.) or other types of mobile devices. In some embodiments, the computing device 120 can also be a fixed computing device, such as a desktop computer, game console, smart TV, etc.
[0041] It should be understood that the architecture and functionality in example environment 100 are described for illustrative purposes only and do not imply any limitation on the scope of this disclosure. Embodiments of this disclosure can also be applied to other environments with different structures and / or functionalities.
[0042] The processes according to embodiments of this disclosure will be described in detail below with reference to other accompanying drawings. For ease of understanding, the specific data mentioned in the following description are exemplary and not intended to limit the scope of this disclosure. It will be understood that the embodiments described below may also include additional actions not shown and / or actions shown may be omitted, and the scope of this disclosure is not limited in this respect.
[0043] Figure 2 illustrates a flowchart of a method 200 for determining code according to certain embodiments of the present disclosure. In this embodiment, the method may be executed by a computing device 110. In block 202, a first code and user input are obtained, the user input indicating adjustments to the first code. The source code 112 can be code written in any programming language, and can cover any function, any purpose, and any technical framework. That is, the present disclosure does not limit the form and content of the source code. The user input can be an instruction entered by the user after launching a language model application in the computing device 120. For example, the user input could be "Please add a functional component to improve brightness for the code I submitted."
[0044] In box 204, context information of the first code is generated based on the syntax tree of the first code. A syntax tree, also known as an abstract syntax tree (AST), is an abstract representation of the syntactic structure of code. It represents the syntactic structure of a programming language in a tree-like form, where each node in the tree represents a syntactic node in the code. In some embodiments, the AST can be transformed through lexical analysis, syntax analysis, and other operations. There are various strategies for generating the syntax tree, and a suitable generation strategy can be selected based on the code characteristics; this disclosure does not limit this approach. The computing device 110 can analyze the syntax tree of the original code 112 to obtain multiple nodes of the original code 112, each node representing a keyword of a syntactic structure. The computing device 110 can quickly and accurately determine the logical framework of the original code based on the syntax tree, identifying the key nodes constituting the logic of the original code. The computing device 110 can utilize the content included in certain nodes of the syntax tree to generate context information that summarizes the original code, achieving compression and rapid understanding of the original code.
[0045] In box 206, the second code is determined using the target model based on the first code, context information, and user input. The target model can be a language model, such as a Large Language Model (LLM). A LLM is a deep learning model trained on large amounts of text data that can generate natural language text or understand the meaning of language text. The language model can understand the entire source code based on context information 114, and thus can process the source code based on its understanding of user input, such as updating the source code or outputting the target code snippet the user wants to find.
[0046] According to the method of the embodiments of this disclosure, the code to be adjusted can be preprocessed. By analyzing the syntax tree of the original code, the logical framework of the original code can be grasped, thereby generating context information of the original code with the help of the syntax tree. Since each node of the syntax tree indicates the main features of the syntax structure of the original code, the context information can greatly compress the size of the original code while retaining the information necessary for the language model to understand the original code. This allows the language model to understand, process or update the original code by reading fewer characters, which can greatly extend the capability boundary of the language model.
[0047] For large amounts of source code, it typically includes multiple modules, each usually represented as a separate code file, used to implement a specific task or function. In this embodiment, multiple sub-context information of multiple modules is determined based on multiple syntax trees of multiple modules. Each module includes a piece of code content, and a syntax tree for that module can be generated based on that code content. A one-to-one correspondence can exist between modules and syntax trees, and therefore a one-to-one correspondence can also exist between modules and sub-context information. In this embodiment, context information for the first code is generated based on the multiple sub-context information of multiple modules. Integrating the multiple sub-context information of the multiple modules included in the source code yields the context information for the entire source code.
[0048] Figure 3A illustrates a schematic diagram of the context information for generating source code according to an embodiment of the present disclosure. In this embodiment, the source code includes three modules: module 1 302, module 2 304, and module 3 306. These three modules can be three independent files containing specific code content. When generating the context information for the source code, the computing device 110 can determine the syntax trees of these three modules respectively using a syntax tree analysis tool, obtaining syntax trees 308-312. These three syntax trees can have multiple levels, and each level can have multiple nodes. Each node represents specific syntax content; for example, a node can represent a for loop statement, and a node can represent an if conditional statement. Furthermore, it should be noted that because modules can call each other, it is permissible for the syntax tree of module 1 302 to contain nodes that represent syntactic structures such as variables, functions, and methods defined in other modules (e.g., module 2 304 or module 3 306).
[0049] Based on the three syntax trees 308-312 of these three modules 302-306, three sub-context information pieces 314, 316, and 318 are determined. Similar to the syntax trees, these sub-context information pieces are allowed to contain both identical and different content. For example, sub-context information 314 and sub-context information 316 may both involve calls to function 'a'. However, the definition of function 'a' can appear in sub-context information 318. Finally, these three sub-context information pieces 314-318 can be integrated into a single context information piece 320, which serves as the context information for the original code.
[0050] Figure 3B illustrates a schematic diagram of the context information of the source code according to an embodiment of the present disclosure. As shown in Figure 3, the source code includes two modules, namely module 1 and module 2. After calculation, the sub-context information of module 1 is "Import: Import function-a and function-b from file1. Export: formatData and processArray. Function call: None." The sub-context information of module 2 is "Import: Import formatData from file2. Export: None. Function call: Call the formatData method with the parameter zzz." Here, file2 is the name of module 1. Arranging the sub-context information of module 1 and module 2 in the order of call or function yields the sub-context information 330 of the source code.
[0051] Regarding how to determine the sub-context information of each module based on the syntax trees of multiple modules, and ultimately synthesize the context information of the entire project, in this embodiment, the computing device 110 can determine multiple target nodes of multiple syntax trees. In operation, the computing device 110 first needs to parse the code content of each module and construct its abstract syntax tree. This step is accomplished using a syntax analysis tool specific to the programming language. Target nodes refer to those nodes that are significant in the syntax tree; they typically represent key program structures such as function definitions, class declarations, and variable assignment statements. These nodes are selected based on their ability to provide important information about the module's functionality and structure. For example, in a data processing module, nodes related to data reading, processing, and output might be selected as target nodes. The target node indicates the logical understanding of the corresponding module's code content, such as which functions or variables from other modules the target node's module references, and which modules reference the target node's module, etc.
[0052] To determine target nodes, nodes containing specific content can be pre-specified as target nodes. For example, multiple import nodes, export nodes, and function call nodes can be determined based on multiple syntax trees, and these can be further defined as target nodes. An import node can be a node containing the "import" code and its corresponding child nodes, whose child nodes include the specific objects being imported, such as which modules are imported. An export node can be a node containing the "export" code and its corresponding child nodes, whose child nodes include the variable names of the exported variables, etc. A function call node can be a node containing the "function" code and its corresponding child nodes, whose child nodes include the specific name of the function being called.
[0053] In this embodiment, multiple target codes corresponding to multiple target nodes are determined based on multiple modules. Once the target nodes in each module are determined, the next step is to extract the actual code snippets represented by these target nodes. This means retrieving the raw code text corresponding to the selected node from the syntax tree. For example, if a target node is a function call, the corresponding code snippet will be the complete expression of that function call. These code snippets are labeled "target code" because they directly reflect the parts that the user wants to adjust or optimize. In this way, the system can focus on the code areas that truly require attention in the project, rather than the entire content of the module.
[0054] In this embodiment, multiple target codes are serialized to generate multiple sub-context information for multiple modules. Serialization refers to the process of converting the extracted target code into a standardized format, which facilitates subsequent data processing and model training. In some embodiments, it can be serialized into natural language, as language models typically understand natural language easily. The sub-context information shown in Figure 3 is the serialized sub-context information, represented as strings of natural language. The purpose of serialization is to reduce data redundancy and improve processing efficiency. Specifically, each target code fragment can be converted into a series of feature vectors or string representations, which retain the core meaning of the original code but remove unnecessary details. For example, function names, parameter lists, and other elements can be converted into specific identifiers, forming a concise and effective representation. Furthermore, in some cases, natural language processing techniques, such as word embedding, can be applied to map code fragments to vectors in a high-dimensional space, facilitating understanding and processing by machine learning algorithms.
[0055] Figure 4A shows a schematic diagram of the code content of a module according to an embodiment of the present disclosure. Code content 402 in Figure 4A is the code content of module 1. Code content 402 includes import, export, and function information. "source" indicates which module is imported. In this example, the file1 module is imported. "specifiers" specifies which functions or methods are specifically imported from the file1 module. Here, functions function-a and function-b are imported. This means that in module 1, functions function-a and function-b from the file1 module can be used to process data.
[0056] The "exports" section defines the interfaces provided by module 1. In this example, module 1 provides a function named `processArray` to other modules. Other modules can use the `processArray` function by importing module 1. The `formatData` function, named `formatData`, takes `data` as its parameter and calls functions `function-a` and `function-b` (both from the `file1` module). Assuming the `formatData` function formats the input dataset, function-a can be used to transform each element, and function-b can be used to filter elements that meet the specified conditions.
[0057] The `processArray` function, named `processArray`, takes an array as its parameter and calls the `formatData` function. `processArray` accepts an array as an argument and calls `formatData` to process it. `formatData` can perform some form of transformation or filtering on the array, and `processArray` returns the processed result. Therefore, this code imports the functions `function-a` and `function-b` from the `file1` module. It defines two internal functions: `formatData` and `processArray`. The `formatData` function uses `function-a` and `function-b` to process the data. The `processArray` function calls `formatData` to process the passed array. Module 1 exposes the `processArray` function, which other modules can import and use.
[0058] Figure 4B shows a schematic diagram of a syntax tree according to an embodiment of the present disclosure. Based on the code content of module 1 shown in Figure 4A, computing device 110 can generate syntax tree 404. In syntax tree 404, the topmost `type` indicates that the type of module 1 is `Program`, indicating that this is a program node and the root node of the entire AST. `body` indicates the statements and declarations in the program body. In `body`, `type` is "ImportDeclaration", indicating that this is an import declaration. `source` indicates the source of the import, here it is module "file1". `specifiers` indicates the specific import items, where the first import item is function-a and the second import item is function-b.
[0059] For the `formatData` function, its `type` is `FunctionDeclaration`, indicating that it is a function declaration. `id` indicates the function name, here "formatData". `params` indicates the parameter list of the `formatData` function, here only one parameter is "data". `body` indicates the function body, containing two calling expressions, the first calling function-a and the second calling function-b. For the `processArray` function, its `type` is "ExportNamedDeclaration", indicating that it is an exported named declaration. `declaration` is the exported declaration, which is a function declaration. `Type` is `FunctionDeclaration`, indicating that it is a function declaration. `id` indicates the function name, here "processArray". `params` indicates the parameter list of the `formatData` function, here only one parameter is "arr". `body` indicates the function body, containing a calling expression, that is, calling the `formatData` function.
[0060] As can be seen from syntax tree 404, module 1 is a program node. The import declaration indicates that module 1 imports functions -a and -b from module file1. The formatData function accepts a parameter data and calls functions -a and -b within its function body. The processArray function accepts a parameter arr and calls the formatData function within its function body. This function is exported for use by other modules.
[0061] Figure 4C illustrates a schematic diagram of sub-context information according to an embodiment of the present disclosure. Based on the syntax tree 404 shown in Figure 4B, the computing device 110 can identify target nodes from the syntax tree 404, namely the contents of the import declaration "ImportDeclaration", the export declaration "ExportNamedDeclaration", and the function call "callExpression". The computing device 110 can generate sub-context information 406 based on the target nodes. The sub-context information 406 includes three parts: import information "import", export information "export", and function call information "function". The import information indicating module 1 depends on the file1 module and uses the function-a and function-b functions therein. The export information indicating module 1 provides a function named processArray. Other modules can use the processArray function by importing this module. The function call information includes the formatData function, which accepts a data parameter and calls the function-a and function-b functions within its function body. The function call information also includes the processArray function, which accepts an arr parameter and calls the formatData function within its function body. In the sub-context information 406, the function call information includes not only the functions called from other modules, but also the main characteristics of the functions defined within this module. The specific implementation of the function does not need to be considered. Therefore, this embodiment can compress the original code and achieve a quick understanding of the original code.
[0062] To further compress the source code, multiple contexts of the various modules included in the source code can be pruned. In this embodiment, an entry module is determined from multiple modules. The entry module indicates the initial operation on the source code, the first batch of instructions executed when the program starts. This may include loading configuration files, initializing database connections, starting the server, etc. An entry module typically has a specific identifier to explicitly indicate that it is the entry point of the source code. This identifier can be a special comment, a predefined variable name, a specific filename, or other form of marker. The computing device 110 determines the entry module by searching for modules with a specific entry identifier. For example, this can be done by scanning all module files for files containing specific comments or naming conventions. This allows the computing device 110 to automatically identify the entry module without requiring manual specification. This improves the system's flexibility and automation, and reduces the possibility of human error.
[0063] In this embodiment, based on the entry module, modules that depend on the entry module are identified as valid modules. After determining the entry module, the next step is to identify all other modules that depend on it. These dependent modules constitute the core functional part of the program. Valid modules are those modules that are actually called and executed during the execution of the source code.
[0064] In this embodiment, context information for the first code is generated based on the sub-context information of the entry module and the sub-context information of the valid modules. This operation ensures that the generated context information includes not only the key information of the entry module but also information about all associated valid modules. The sub-context information of the entry module (such as imported libraries, defined functions, etc.) is integrated with the sub-context information of other valid modules (such as their respective functions and calling relationships) to form a comprehensive project context view. The sub-context information of the valid modules is integrated as the context information of the original code. Since the sub-context information of non-valid modules is not integrated, non-valid modules are pruned, thereby further simplifying the context information of the original code and reducing interfering information irrelevant to understanding the original code.
[0065] Furthermore, pruning can be achieved by fully utilizing the sub-context information of each module in the embodiments of this disclosure. In an embodiment, the computing device 110 can determine the sub-context information of an entry module from multiple sub-context information of multiple modules based on the entry module. Since the entry module is typically identified, the sub-context information of the entry module can be obtained based on the identifier.
[0066] In this embodiment, the computing device 110 can determine, based on the import and export information of the sub-context information of other modules in a plurality of modules, modules that directly depend on the entry module and modules that indirectly depend on the entry module as valid modules. Modules indirectly dependent on the entry module have multiple dependencies on the entry module. The sub-context information of each module includes its import information, export information, and function call information. The dependencies between modules can be directly obtained or inferred from this information. Direct dependencies refer to modules that are explicitly imported or called in the entry module. For example, if the entry module imports module 1, then module 1 is directly dependent on the entry module. Indirect dependencies refer to modules that are not directly imported or called by the entry module, but are indirectly dependent on the entry module through other modules. For example, if module 1 imports module 2, then module 2 is indirectly dependent on the entry module. In this embodiment, the sub-context information of modules is organically combined with pruning operations, achieving efficient pruning of the context information of the original code, thereby further compressing the original code and making it easier to understand. Finally, the computing device 110 considers both directly and indirectly dependent modules as valid modules. These modules are the parts that the source code actually needs when it runs.
[0067] Figure 5 illustrates a schematic diagram of inter-module dependencies according to an embodiment of the present disclosure. First, at 502, the sub-context information of the entry module can be determined. Then, this sub-context information is analyzed; for example, the export information of the sub-context information may indicate that it exports function 1. The computing device 110 can analyze the sub-context information of other modules to detect which module's import information indicates that the entry module has been imported, or which module's function call information indicates that function 1 of the entry module has been called. Since it is detected that module 1 has imported the entry module or called function 1 of the entry module, at 504, it can be determined that module 1 depends on the entry module.
[0068] The computing device 110 can analyze the sub-context information of module 1, such as the export information of the sub-context information indicating that it exports function 2. The computing device 110 can analyze the sub-context information of other modules to detect which module's import information indicates that module 1 has been imported, or which module's function call information indicates that function 2 of module 1 has been called. Here, it is detected that module 2 imports module 1 or calls function 2 of module 1. Therefore, at 506, it can be determined that module 2 directly depends on module 1 and indirectly depends on the entry module.
[0069] The computing device 110 can analyze the sub-context information of module 2, such as the export information of the sub-context information indicating that it exports variable 3. The computing device 110 can analyze the sub-context information of other modules to detect which module's import information indicates that module 2 has been imported, or which module's function call information indicates that module 2's variable 3 has been called. Here, it is detected that module 3 has imported module 2 or called module 2's variable 3. Therefore, at 508, it can be determined that module 3 directly depends on module 2 and indirectly depends on the entry module and module 1.
[0070] Suppose the original code also includes modules 4 and 5. However, the import information for module 4 does not involve any valid modules, including the entry module, and the function call information does not indicate that any function in a valid module was called. Therefore, at point 510, module 4 can be considered an invalid module. If module 4 only depends on module 5, and module 5 does not involve importing other modules or calling functions or variables from other modules, then at point 512, module 5 can also be considered an invalid module. This embodiment provides a simple and effective pruning method, which can improve the processing efficiency of the determined code and further extend the capability boundaries of the language model.
[0071] Figure 6 illustrates a schematic diagram of the context information for generating source code according to an embodiment of the present disclosure. First, sub-context information for each module is obtained, including obtaining sub-context information for module 1 (602), module 2 (604), and module 3 (606). Then, at 608, based on this sub-context information, it is analyzed which modules are valid; for example, it can be confirmed that modules 1 and 2 are valid modules, while module 3 is an invalid module. At 610, the sub-context information of the source code is pruned by discarding module 3, thereby preserving the sub-context information of module 1 and module 2. At 612, the sub-context information of module 1 and module 2 is integrated to obtain the context information of the source code. According to this embodiment, the context information of the source code can be further compressed, i.e., the source code is compressed, and interfering information that hinders understanding the source code is eliminated.
[0072] After generating the context information of the source code, the computing device 110 can perform further preprocessing using a language model. In this embodiment, the language model is used to determine associated modules based on the context information of the first code. Associated modules indicate the modules in the source code that are involved in processing or updating the source code based on user input. By analyzing the context information of the source code, the language model can determine which modules are related to the current task (i.e., the user intent identified based on user input). These modules may be those directly involved in the update or those providing auxiliary functions.
[0073] As an example, a language model can analyze individual valid modules to determine associated modules, thereby improving processing efficiency. As another example, a language model can be used to determine associated sub-context information from multiple sub-contexts of multiple modules, and to determine associated modules based on associated sub-context information. The language model analyzes this sub-context information to identify the sub-context information relevant to updating the first code based on user input. This identification process can be performed in various ways. For example, after recognizing the user's intent, the language model can extract key features from the sub-context information of each module, such as function names, variable names, imported libraries, etc., to determine the associated module's sub-context information. The language model can also calculate the correlation between these features and user input, and so on.
[0074] In this embodiment, a language model is used to determine the second code based on associated modules, the first code, and user input. The code content corresponding to these modules can be obtained from the first code based on the associated modules. This code content and the user input can then be submitted to the language model for updating. The determined new code snippets can be updates to the associated modules or code snippets of the original code expected in the user input. Replacing the old associated modules with these updated ones forms the complete second code. The language model can perform post-processing after updating the modules, such as formatting the code and adding comments, to improve code readability and maintainability. In this embodiment, by using the language model to determine modules related to the user intent identified in the user input based on the sub-context information of each module, the volume of code content that needs to be input into the language model when processing or updating the original code can be further compressed, thereby further extending the capabilities of the language model.
[0075] Figures 7A-7B illustrate schematic diagrams of recall-related code according to embodiments of the present disclosure. Figure 7A shows source code 702 applying the method. Source code 702 demonstrates three different functions, defined in three modules: callccc.ts, callddd.ts, and callleee.ts. Each function has a specific function and works together to complete a task. The ccc function in the callccc.ts module is the entry point of the entire source code 702, responsible for calling the large language model, updating the UI state of the page, and updating database records; therefore, the callccc.ts module is the entry module of source code 702. In the ccc function of the callccc.ts module, await fetchLLM() is used to asynchronously call the fetchLLM function to obtain the response from the large language model. The await keyword indicates that this is an asynchronous operation; the function will wait for fetchLLM to complete before continuing execution. In the ccc function of the callccc.ts module, ddd() is called to update the state of the page. The specific implementation details of this function are in the callddd.ts file. The `ccc` function in the `callccc.ts` module calls the `eee` function to update the records in the database. The specific implementation details of this function are in the `calleee.ts` file.
[0076] Figure 7B illustrates the process of recalling associated modules based on source code 702. If the user input 704 in the language model call interface is "Give me a detailed explanation of how calling ccc to generate code works?", then according to the embodiment described above, the modules callccc.ts 708, calldddd.ts 710, and callleee.ts 712 in source code 702 will be processed to obtain three sub-context information. These three sub-contextual information pieces, along with user input, are fed into the language model. The language model identifies the user intent based on the user input and analyzes the three sub-contextual information to determine the modules that need to be recalled. First, it can be determined that module callccc.ts 708 is the associated module. The implementation of module callccc.ts 708 requires calling the ddd and eee functions defined in modules callddd.ts 710 and callleee.ts 712. Therefore, modules callddd.ts 710 and callleee.ts 712 can be recalled based on the sub-contextual information of module callccc.ts 708. After recalling the associated modules, the code content corresponding to associated modules 708-712 can be obtained from the original code 702. Then, this code content and user input are fed back into the language model to update the original code 702.
[0077] Figure 8 illustrates a recall information diagram of associated modules according to an embodiment of the present disclosure. In this embodiment, "file" in recall information 802 indicates the name of the associated module, including a module named "file2". "symbols" in recall information 804 indicates the names of functions to be used, including a function named "formatData" and a function named "processArray".
[0078] After obtaining the associated module, the associated module and user input can be encapsulated. In an embodiment, an associated code can be determined based on the associated module and the first code, and target prompt information can be generated based on the associated code and user input. This target prompt information can help the language model understand the task and determine the required response. In an embodiment, a second code is determined using the language model based on the target prompt information. Figure 9A shows a schematic diagram of target prompt information according to an embodiment of the present disclosure. The target prompt information 902 includes two parts: the upper part is the associated code corresponding to the recalled associated module. For simplicity, the specific code is not shown in the figure, but is described in general terms. The lower part is the user input, which can be the original text entered by the user.
[0079] Figure 9B illustrates a schematic diagram for determining code according to an embodiment of the present disclosure. At 904, computing device 110 acquires user input and a first code submitted by the user. This first code is the original code that needs to be updated. At 906, multiple modules of the first code are processed separately to obtain sub-context information corresponding to each module. This sub-context information compresses the code content of the corresponding module, retaining only the necessary information. At 908, the multiple sub-context information corresponding to these multiple modules, along with the user input, are input into a language model. The language model performs intent recognition on the user input to determine which sub-context information is associated with the user intent. After determining the associated sub-context information, the associated code content can be obtained. At 910, the associated code content, along with the user input, is input into a language model, which updates it to generate a code fragment for response. This code fragment for response is combined with the code content of other models to obtain the second code, i.e., the code for response.
[0080] The method for determining (e.g., updating) code according to embodiments of this disclosure can provide numerous benefits. For a given open-source source code, which includes 250 files in a first format, each containing 3506 spaces, 2204 comments, and 22823 code words; 47 files in a second format, each containing 1378 code words; 10 files in a third format, each containing 24 spaces, 44 comments, and 399 code words; 5 files in a fourth format, each containing 46 spaces and 81 code words; and 1 file in a fifth format, wherein the fifth format... The first format file includes 11 spaces, 23 comments, and 61 code words. The second format file includes two sixth format files, each containing 3 spaces and 29 code words. The third format file includes one seventh format file, each containing 3 spaces and 25 code words. The fourth format file includes one eighth format file, each containing 3 spaces and 25 code words. The fifth format file includes three ninth format files, each containing 3 spaces and 15 code words. The sixth format file includes one tenth format file, each containing 5 code words.
[0081] The original code was a massive 176,947 characters long, while the processed code's context information consisted of only 24,682 characters, achieving a compression rate of 13.9%, thus significantly reducing the original code's size. Furthermore, generating the context information for the original code took only 782 milliseconds, so it had virtually no impact on the speed of updating the original code.
[0082] Figure 10 shows a schematic block diagram of an example device 1000 according to some embodiments of the present disclosure. The device 1000 can be implemented by software, hardware, or a combination of both. As shown in Figure 10, the device 1000 includes a data acquisition module 1010, a context information generation module 1020, and a code determination module 1030.
[0083] In some embodiments, the data acquisition module 1010 can be configured to acquire a first code and user input, whereby the user input indicates adjustments to the first code. The context generation information module 1020 can be configured to generate context information for the first code based on the syntax tree of the first code. The code determination module 1030 can be configured to determine a second code using a target model based on the first code, the context information, and the user input.
[0084] In some embodiments, the first code includes multiple modules, and the context information generation module 1020 includes a sub-context information determination module configured to determine multiple sub-context information of the multiple modules based on multiple syntax trees of the multiple modules. The context information generation module 1020 also includes a first generation module configured to generate context information of the first code based on the multiple sub-context information of the multiple modules.
[0085] In some embodiments, based on multiple syntax trees of multiple modules, the subcontext information determination module includes a target node determination module configured to determine multiple target nodes of the multiple syntax trees. The subcontext information determination module also includes a target code determination module configured to determine multiple target codes corresponding to the multiple target nodes based on the multiple modules. The subcontext information determination module further includes a serialization processing module configured to perform serialization processing on the multiple target codes to generate multiple subcontext information for the multiple modules.
[0086] In some embodiments, the target node determination module includes a first node determination module configured to determine multiple import nodes, multiple export nodes, and multiple function call nodes based on multiple syntax trees. The target node determination module also includes a second node determination module configured to determine the multiple import nodes, multiple export nodes, and multiple function call nodes as multiple target nodes.
[0087] In some embodiments, the first generation module includes a first entry module determination module configured to determine an entry module from a plurality of modules, wherein the entry module indicates an initial operation for the first code. The first generation module also includes a pruning module configured to determine, based on the entry module, modules from the plurality of modules that depend on the entry module as valid modules. The first generation module further includes an integration module configured to generate context information for the first code based on sub-context information of the entry module and sub-context information of the valid modules.
[0088] In some embodiments, the first entry module has an entry identifier, and the entry module determining module includes a second entry module determining module configured to determine an entry module from a plurality of modules based on the entry identifier.
[0089] In some embodiments, the pruning module includes a first determining module configured to determine the sub-context information of the entry module from multiple sub-context information of multiple modules based on the entry module. The pruning module also includes a dependency analysis module configured to determine, based on import and export information of the sub-context information of other modules in the multiple modules, modules that directly depend on the entry module and modules that indirectly depend on the entry module as valid modules, wherein multiple dependencies exist between the modules that indirectly depend on the entry module and the entry module.
[0090] In some embodiments, the code determination module 1030 includes an association module determination module configured to determine an association module using a target model based on context information of the first code. The code determination module 1030 also includes a second determination module configured to determine a second code using the target model, the association module, the first code, and user input.
[0091] In some embodiments, the associated module determining module includes an associated context determining module configured to use a target model to determine associated sub-context information from multiple sub-context information of multiple modules. The associated module determining module also includes a third determining module configured to determine the associated module based on the associated sub-context information.
[0092] In some embodiments, the second determining module includes a fourth determining module configured to determine an associated code based on the associated module and the first code. The second determining module also includes a prompt word generation module configured to generate target prompt word information based on the associated code and user input. The second determining module further includes a fifth determining module configured to determine a second code using a target model based on the target prompt word information.
[0093] The division of modules or units in the embodiments of this disclosure is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods. Furthermore, the functional units in the disclosed embodiments may be integrated into one unit, exist as separate physical entities, or two or more units may be integrated into one unit. The integrated unit described above can be implemented in hardware or as a software functional unit.
[0094] Figure 11 shows a block diagram of an example device 1100 that can be used to implement embodiments of the present disclosure. It should be understood that the device 1100 shown in Figure 11 is merely exemplary and should not be construed as limiting the functionality and scope of the implementations described herein. For example, device 1100 can be used to correspond to computing device 120 described herein in conjunction with Figure 1 and can be used to perform the processes described above for Figures 1 through 9B.
[0095] As shown in Figure 11, device 1100 is in the form of a general-purpose computing device. Components of computing device 1100 may include, but are not limited to, one or more processors or processing units 1110, memory 1120, storage device 1130, one or more communication units 1140, one or more input devices 1150, and one or more output devices 1160. Processing unit 1110 may be a physical or virtual processor and is capable of performing various processes according to programs stored in memory 1120. In a multiprocessor system, multiple processing units execute computer-executable instructions in parallel to improve the parallel processing capability of computing device 1100.
[0096] Computing device 1100 typically includes multiple computer storage media. Such media can be any available media accessible to computing device 1100, including but not limited to volatile and non-volatile media, removable and non-removable media. Memory 1120 can be volatile memory (e.g., registers, cache, random access memory (RAM)), non-volatile memory (e.g., read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory), or some combination thereof). Storage device 1130 can be removable or non-removable media and may include machine-readable media, such as flash drives, disks, or any other media capable of storing information and / or data (e.g., training data for training) and accessible within computing device 1100.
[0097] The computing device 1100 may further include additional removable / non-removable, volatile / non-volatile storage media. Although not shown in FIG11, disk drives for reading or writing from removable, non-volatile disks (e.g., "floppy disks") and optical disk drives for reading or writing from removable, non-volatile optical disks may be provided. In these cases, each drive may be connected to a bus (not shown) via one or more data media interfaces. The memory 1120 may include a computer program product 1125 having one or more program modules configured to perform various methods or actions of various implementations of this disclosure.
[0098] The communication unit 1140 enables communication with other computing devices via a communication medium. Additionally, the components of the computing device 1100 can function as a single computing cluster or multiple computing machines capable of communicating via communication connections. Therefore, the computing device 1100 can operate in a networked environment using logical connections to one or more other servers, network personal computers (PCs), or another network node.
[0099] Input device 1150 can be one or more input devices, such as a mouse, keyboard, trackball, etc. Output device 1160 can be one or more output devices, such as a monitor, speaker, printer, etc. Computing device 1100 can also communicate as needed with one or more external devices (not shown) via communication unit 1140. These external devices include storage devices, display devices, etc., and can communicate with one or more devices that enable user interaction with computing device 1100, or with any device (e.g., network card, modem, etc.) that enables computing device 1100 to communicate with one or more other computing devices. Such communication can be performed via an input / output (I / O) interface (not shown).
[0100] According to an exemplary implementation of this disclosure, a computer-readable storage medium is provided that stores computer-executable instructions thereon, wherein the computer-executable instructions are executed by a processor to implement the methods described above. According to an exemplary implementation of this disclosure, a computer program product is also provided, which is tangibly stored on a non-transitory computer-readable medium and includes computer-executable instructions, which are executed by a processor to implement the methods described above. According to an exemplary implementation of this disclosure, a computer program product is provided that stores a computer program thereon, which, when executed by a processor, implements the methods described above.
[0101] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatuses, devices, and computer program products implemented according to this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.
[0102] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processing unit of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner. Thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.
[0103] Computer-readable program instructions can be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions that execute on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.
[0104] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction, which contains one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0105] Various implementations of this disclosure have been described above. The foregoing description is exemplary and not exhaustive, nor is it limited to the disclosed implementations. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described implementations. The terminology used herein is chosen to best explain the principles, practical applications, or improvements to technology in the market, or to enable others skilled in the art to understand the various implementations disclosed herein.
Claims
1. A method for determining code, comprising: Obtain a first code and user input, wherein the user input indicates an adjustment to the first code; Generate context information for the first code based on the syntax tree of the first code; as well as The second code is determined using the target model based on the first code, the context information, and the user input.
2. The method according to claim 1, wherein the first code comprises multiple modules, and generating context information of the first code based on the syntax tree of the first code includes: Based on the multiple syntax trees of the multiple modules, determine multiple sub-context information of the multiple modules; as well as The context information of the first code is generated based on the multiple sub-context information of the multiple modules.
3. The method according to claim 2, wherein determining multiple sub-context information of the multiple modules based on multiple syntax trees of the multiple modules includes: Determine multiple target nodes of the multiple syntax trees; Based on the aforementioned modules, multiple target codes corresponding to the multiple target nodes are determined; as well as The multiple target codes are serialized to generate multiple sub-context information for the multiple modules.
4. The method of claim 3, wherein determining the plurality of target nodes of the plurality of syntax trees includes: Based on the multiple syntax trees, multiple import nodes, multiple export nodes, and multiple function call nodes are determined; as well as The plurality of import nodes, the plurality of export nodes, and the plurality of function call nodes are identified as the plurality of target nodes.
5. The method according to claim 2, wherein generating the context information of the first code based on the multiple sub-context information of the plurality of modules includes: An entry module is determined from the plurality of modules, wherein the entry module indicates an initial operation for the first code; Based on the entry module, the modules among the plurality of modules that depend on the entry module are identified as valid modules; as well as The context information of the first code is generated based on the sub-context information of the entry module and the sub-context information of the effective module.
6. The method of claim 5, wherein the entry module has an entry identifier, and determining the entry module from the plurality of modules includes: The entry module is determined from the plurality of modules based on the entry identifier.
7. The method according to claim 5, wherein determining, based on the entry module, the modules among the plurality of modules that depend on the entry module as valid modules includes: Based on the entry module, the sub-context information of the entry module is determined from the multiple sub-context information of the multiple modules; as well as Based on the import and export information of the sub-context information of other modules in the plurality of modules, the modules that directly depend on the entry module and the modules that indirectly depend on the entry module are determined as the valid modules, wherein the modules that indirectly depend on the entry module have multiple dependencies on the entry module.
8. The method of claim 2, wherein determining the second code using a target model based on the first code, the context information, and the user input comprises: Based on the context information of the first code, the associated module is determined using the target model; as well as Using the target model, the second code is determined based on the associated module, the first code, and the user input.
9. The method of claim 8, wherein determining the associated module using the target model based on the context information of the first code includes: Using the target model, the associated sub-context information is determined from the multiple sub-context information of the multiple modules; as well as The associated module is determined based on the associated sub-context information.
10. The method of claim 8, wherein determining the second code using the target model based on the association module, the first code, and the user input comprises: The associated code is determined based on the associated module and the first code; Target prompt word information is generated based on the association code and the user input; as well as Based on the target prompt word information, the second code is determined using the target model.
11. An apparatus for determining a code, comprising: The data acquisition module is configured to acquire a first code and user input, wherein the user input indicates an adjustment to the first code; The context information generation module is configured to generate context information of the first code based on the syntax tree of the first code; as well as The code determination module is configured to determine the second code using a target model based on the first code, the context information, and the user input.
12. An electronic device, comprising: At least one processing unit; At least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions causing the electronic device to perform the method according to any one of claims 1 to 10 when executed by the at least one processing unit.
13. A computer program product having a computer program stored thereon, which, when executed by a processor, implements the method according to any one of claims 1 to 10.