A large model driven programming method and device based on local code repository

Through the large-model-driven programming method based on local code warehouses, processing and inference code information is solved, and the traditional encoding method is time-consuming and labor-intensive and insufficient code completion accuracy is achieved, achieving more efficient and accurate programming assistance effects.

CN119396407BActive Publication Date: 2025-04-04ASIAINFO TECH CHINA INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510000728.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-02
Publication Date
2025-04-04
Estimated Expiration
2045-01-02

AI Technical Summary

Technical Problem

The traditional manual code writing and maintenance method is time-consuming and labor-intensive, prone to various errors, and the accuracy and efficiency of code completion technology still need to be improved.

Method used

The local code warehouse programming method driven by a large model is adopted. By obtaining pending code and task instructions, the entity relationship, syntax structure information and code summary are obtained, and the matching target community is found in the community, reference code is obtained, and reference code, pending code and task instructions are reasoned based on the target model.

Benefits of technology

It improves the accuracy and efficiency of handling programming problems, can more accurately understand the requirements and intentions of the pending code, obtain higher-quality target results, and help developers achieve programming goals quickly and accurately.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396407B_ABST
    Figure CN119396407B_ABST
Patent Text Reader

Abstract

The present application discloses a method and device for programming based on a local code repository driven by a large model, and relates to the field of computer technology. The method organizes the knowledge in the code base into multiple communities through hierarchical processing graphs, each of which contains communities with similarities, and the communities contain similar nodes. This hierarchical structure not only retains the grammatical relationship between codes, but also introduces similarities at the semantic level through the construction of communities and communities. By introducing similarities at the semantic level, the accuracy and coverage of retrieval can be improved, ensuring that the reference code can not only contain code fragments that are syntactically similar to the code to be processed, but also contain code that is semantically and functionally similar. On this basis, the target large model infers the reference code, the code to be processed, and the task instructions, and can more accurately understand the needs and intentions of the code to be processed, and obtain higher quality target results to assist developers in quickly and accurately achieving programming goals.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method and device for large model-driven local code repository-based programming. Background Art

[0002] With the rapid development of information technology, the scale of software projects continues to expand and the complexity is increasing. In this context, the traditional way of manually writing and maintaining code has gradually exposed many disadvantages. First, the manual coding process is time-consuming and labor-intensive, which greatly increases the development cycle and cost. Secondly, due to the intervention of human factors, various errors are prone to occur in the code writing process, such as syntax errors, logical errors, etc. These errors are not only difficult to detect, but once missed, they may cause more serious problems in the later software operation and maintenance.

[0003] In order to meet these challenges, code completion technology has emerged. Although code completion technology can improve coding efficiency to a certain extent by intelligently analyzing the developer's current programming context, predicting and recommending possible code snippets, the accuracy and efficiency of code completion still need to be improved. Summary of the invention

[0004] In view of the above problems, this application provides a method and device for programming based on a local code repository driven by a large model to achieve the purpose of improving the accuracy and efficiency of processing programming problems. The specific scheme is as follows:

[0005] The first aspect of the present application provides a large model-driven local code repository-based programming method, including:

[0006] In response to the request, obtaining the code to be processed and the task instruction in the request;

[0007] Processing the code to be processed to obtain entity relationships, grammatical structure information and code summaries;

[0008] Searching for a target community matching the to-be-processed code, entity relationship, grammatical structure information and code summary in at least one community; the at least one community is obtained by hierarchical processing of a graph, each community in the at least one community includes at least one community, at least one community in the community has similarity, each community in the at least one community includes at least one node in the graph, at least one node in the community has similarity; the graph is constructed based on code files in a local code repository and entity relationships, grammatical structure information and code summaries corresponding to the code files in the local code repository;

[0009] Obtaining reference codes according to the nodes and edges in the target community;

[0010] The reference code, the code to be processed and the task instruction are inferred based on the target large model to obtain a target result.

[0011] In a possible implementation, the processing of the code to be processed to obtain entity relationships, grammatical structure information and code summary includes:

[0012] Extracting a code summary from the code to be processed based on the target large model; the code summary includes: implementation logic and key information;

[0013] extracting entity relationships from the code summary based on the target big model;

[0014] Based on the abstract syntax tree analysis method, the syntax structure of the code to be processed is analyzed to obtain syntax structure information.

[0015] In a possible implementation, searching at least one community for a target community that matches the code to be processed, entity relationship, grammatical structure information, and code summary includes:

[0016] Obtaining a vectorized representation of each community in the at least one community; the vectorized representation of the community is obtained by vectorizing the community summary of the community;

[0017] Vectorizing the code to be processed, entity relationships, grammatical structure information, and code summary to obtain a vectorized representation to be matched;

[0018] The similarity between the vectorized representation to be matched and the vectorized representation of each community is calculated, and the community with the highest similarity is selected as the target community.

[0019] In one possible implementation, the graph is constructed in the following manner:

[0020] Split the code files in the local code repository to obtain multiple code snippets;

[0021] Based on the target macro model, each of the code snippets is respectively abstracted to obtain a code summary of each of the code snippets;

[0022] Extracting entity relationships from the code summary of each of the code snippets based on the target big model;

[0023] Based on the abstract syntax tree analysis method, the syntax structure of each code fragment is analyzed respectively to obtain the syntax structure information of each code fragment;

[0024] Constructing ontology;

[0025] The multiple code snippets, the code summary of each of the code snippets, the entity relationship and the grammatical structure information of each of the code snippets are entered into the ontology to obtain a graph.

[0026] In a possible implementation, the code files in the local code repository are split to obtain multiple code snippets, including:

[0027] Split the code files in the local code repository into multiple code units according to the set length;

[0028] The code units are marked according to a set mark list to obtain code snippets; the set mark list includes the following elements: project name, function, module, class, function and method.

[0029] In a possible implementation, the at least one community is obtained in the following manner:

[0030] Initialize each node in the graph into an independent community to obtain multiple communities;

[0031] The multiple communities are updated by selecting nodes from each node in the graph to move in a direction of increasing the first network modularity, thereby obtaining multiple new communities; the first network modularity indicates the quality of community division, and the larger the first network modularity, the closer the connection between nodes in the corresponding new community and the sparser the connection between new communities;

[0032] Communities are selected from the multiple new communities for merging in a direction of increasing the second network modularity to obtain at least one community; the second network modularity represents the quality of community division, and the larger the second network modularity, the tighter the connection between communities within the community and the sparser the connection between communities.

[0033] In a possible implementation, the first network modularity is determined in the following manner:

[0034] Based on the first relation , calculate the first network modularity; where, represents the first network modularity, represents the number of communities, Representing the community The sum of the weights of the internal edges, where the weight of the internal edge is a value obtained by normalizing the number of occurrences of the relationship between the two nodes connected by the internal edge, Representation and Community Half of the sum of the weights of all edges connecting the nodes in The weight of the edge connecting the nodes in is the value obtained by normalizing the number of occurrences of the relationship between the two nodes connected by the edge.

[0035] In a possible implementation, the second network modularity is determined in the following manner:

[0036] Based on the second relation , calculate the second network modularity; where, represents the second network modularity, represents the number of communities, Representing the community The sum of the weights of the internal edges, where the weight of the internal edge is the value obtained by normalizing the number of occurrences of the relationship between the two communities connected by the internal edge, Representation and community Half of the sum of the weights of all edges connecting the communities in The weight of the edge connecting the communities in is the value obtained by normalizing the number of occurrences of the relationship between the two communities connected by the edge.

[0037] In a possible implementation, the task instruction includes:

[0038] A task instruction for instructing to complete the code to be processed;

[0039] Or, a task instruction for asking questions about the code to be processed.

[0040] On the other hand, the present application provides a large model driven device based on local code repository programming, including:

[0041] A first obtaining module, configured to obtain, in response to a request, a code to be processed and a task instruction in the request;

[0042] A processing module, used for processing the code to be processed to obtain entity relationships, grammatical structure information and code summary;

[0043] A search module, used to search for a target community matching the to-be-processed code, entity relationship, grammatical structure information and code summary in at least one community; the at least one community is obtained by hierarchical processing of a graph, each community in the at least one community includes at least one community, at least one community in the community has similarity, each community in the at least one community includes at least one node in the graph, at least one node in the community has similarity; the graph is constructed based on the code files in the local code repository and the entity relationships, grammatical structure information and code summaries corresponding to the code files in the local code repository;

[0044] A second obtaining module is used to obtain a reference code according to the nodes and edges in the target community;

[0045] The reasoning module is used to reason the reference code, the code to be processed and the task instruction based on the target large model to obtain the target result.

[0046] In this application, the knowledge in the code base is organized into multiple communities by hierarchical processing graphs, each of which contains communities with similarities, and the communities contain similar nodes. This hierarchical structure not only retains the grammatical relationship between codes, but also introduces semantic similarity through the construction of communities and communities. By introducing semantic similarity, the accuracy and coverage of retrieval can be improved, ensuring that the reference code can not only contain code fragments that are syntactically similar to the code to be processed, but also contain semantically and functionally similar code. On this basis, the target large model reasons about the reference code, the code to be processed, and the task instructions, and can more accurately understand the needs and intentions of the code to be processed, and obtain higher quality target results to assist developers in quickly and accurately achieving programming goals. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0048] Figure 1 A flowchart of a large model-driven local code repository-based programming method provided in Example 1 of the present application;

[0049] Figure 2 A schematic diagram of a code file provided for this application;

[0050] Figure 3 A schematic diagram of code summary extraction provided for this application;

[0051] Figure 4 A schematic diagram of entity relationship extraction provided for this application;

[0052] Figure 5 A schematic diagram of a syntax tree structure provided for this application;

[0053] Figure 6 A schematic diagram of an entity provided for this application;

[0054] Figure 7 A schematic diagram of the relationship between entities in an ontology provided for this application;

[0055] Figure 8 A schematic diagram of code segmentation provided for this application;

[0056] Fig. 9 A schematic diagram of the structure of a large model-driven device based on local code repository programming provided in this application. DETAILED DESCRIPTION

[0057] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0058] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0059] The terms "first", "second" etc. in the specification of the application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable in appropriate circumstances, and this is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0060] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0061] Reference Figure 1 , which is a flow chart of a large model driven method based on local code repository programming provided in Example 1 of the present application, such as Figure 1 As shown, the method may include but is not limited to the following steps:

[0062] Step S101: In response to a request, obtain the code to be processed and the task instruction in the request.

[0063] Task instructions are used to instruct specific output to be generated based on the code to be processed. For example, task instructions can be used to instruct completion or optimization of the code to be processed.

[0064] Step S102: Process the code to be processed to obtain entity relationships, grammatical structure information and code summary.

[0065] In this embodiment, in the code to be processed, parameters, functions, classes, etc. can all be regarded as entities. Entity relationships can be understood as associations or interactions between these entities, which are used to reflect the logical structure and business logic of the code.

[0066] The grammatical structure information can be used to describe the grammatical structure of the code to be processed.

[0067] Code summary, which can be used to describe the function of the code to be processed, etc.

[0068] Step S103: searching for a target community in at least one community that matches the code to be processed, entity relationship, grammatical structure information, and code summary.

[0069] The at least one community is obtained by hierarchically processing the graph, each community in the at least one community includes at least one community, and at least one community in the community has similarities, for example, the nodes between the communities have similarities in function, implementation logic, code structure, etc.

[0070] Each community in the at least one community includes at least one node in the graph, and at least one node in the community has similarity, for example, similarity of entities represented by the nodes in terms of grammatical structure, function call mode, variable usage, etc.

[0071] The graph is constructed based on the code files in the local code repository and the entity relationships, grammatical structure information and code summaries corresponding to the code files in the local code repository.

[0072] Step S104: Obtain reference codes according to the nodes and edges in the target community.

[0073] In this embodiment, code snippets may be extracted from the target community according to the nodes and edges in the target community as reference codes.

[0074] Step S105: Reasoning the reference code, the code to be processed and the task instruction based on the target large model to obtain a target result.

[0075] The target big model can be built based on machine learning, deep learning or other artificial intelligence algorithms. For example, the target big model can include a language model with natural language processing capabilities and deep semantic understanding capabilities.

[0076] The target result may be a result that satisfies the requirements of the task instruction. For example, the target result may be a completed code or an optimized code.

[0077] In this embodiment, the knowledge in the code base is organized into multiple communities by hierarchical processing graphs, each of which contains similar communities, and the communities contain similar nodes. This hierarchical structure not only retains the grammatical relationship between codes, but also introduces semantic similarity through the construction of communities and communities. By introducing semantic similarity, the accuracy and coverage of retrieval can be improved, ensuring that the reference code can not only contain code fragments that are syntactically similar to the code to be processed, but also contain semantically and functionally similar code. On this basis, the target large model infers the reference code, the code to be processed, and the task instructions, and can more accurately understand the needs and intentions of the code to be processed, and obtain higher quality target results to assist developers in quickly and accurately achieving programming goals.

[0078] As another optional embodiment of the present application, a large model-driven local code repository-based programming method is provided in Embodiment 2 of the present application. This embodiment is mainly an implementation method of step S102 in Embodiment 1. Step S102 may include but is not limited to the following steps:

[0079] Step S1021: extracting a code summary from the code to be processed based on the target large model; the code summary includes: implementation logic and key information.

[0080] In this embodiment, the code to be processed and the prompt word "output the implementation logic and key information of this code" can be input into the target large model to obtain the code summary output by the target large model.

[0081] In this embodiment, the key information may include but is not limited to: class name, function name, method name, parameters, return value, code comments and other elements.

[0082] Step S1022: extract entity relationships from the code summary based on the target big model.

[0083] The target large model can analyze the text in the code summary, identify the entities therein, and try to understand the relationships between these entities.

[0084] Step S1023: Analyze the syntax structure of the code to be processed based on the abstract syntax tree analysis method to obtain syntax structure information.

[0085] The grammatical structure information may represent the hierarchical relationship and grammatical relationship between various elements in the code to be processed, for example, the composition of statements, the structure of expressions, the type of control structures, etc.

[0086] In this embodiment, the semantic understanding and context awareness capabilities of the target large model can be used to accurately extract code summaries and entity relationships. In addition, based on the abstract syntax tree analysis method, the hierarchical relationship and grammatical relationship between elements in the code to be processed can be clearly displayed.

[0087] As another optional embodiment of the present application, a large model-driven local code repository-based programming method is provided in Embodiment 3 of the present application. This embodiment is mainly an implementation method of step S103 in Embodiment 1. Step S103 may include but is not limited to the following steps:

[0088] Step S1031: obtaining a vectorized representation of each community in the at least one community; the vectorized representation of the community is obtained by vectorizing the community summary of the community.

[0089] The community summary can be understood as a summary of all nodes in the community.

[0090] In this embodiment, a pre-trained model can be used to convert the community summary into a vector in a high-dimensional space (ie, a vectorized representation of the community), wherein the direction and distance of the vector can reflect the deep semantics of the community summary.

[0091] Pre-trained models may include but are not limited to: BGE, M3E, and Text2vec, which have powerful language understanding and representation capabilities.

[0092] Step S1032: vectorize the code to be processed, entity relationship, grammatical structure information and code summary to obtain a vectorized representation to be matched.

[0093] In this embodiment, a pre-trained model can be used to convert the code to be processed, entity relationships, grammatical structure information and code summary into a vector in a high-dimensional space (i.e., a vectorized representation to be matched), wherein the direction and distance of the vector can reflect the deep semantics of the code to be processed, entity relationships, grammatical structure information and code summary.

[0094] Pre-trained models may include but are not limited to: BGE, M3E, and Text2vec, which have powerful language understanding and representation capabilities.

[0095] Step S1033: Calculate the similarity between the vectorized representation to be matched and the vectorized representation of each community, and select the community with the highest similarity as the target community.

[0096] In this embodiment, a similarity measurement method (such as cosine similarity, Euclidean distance, etc.) can be used to calculate the similarity between the vectorized representation to be matched and the vectorized representation of each community. According to the similarity calculation result, the community with the highest similarity can be selected as the target community.

[0097] The content in the target community is closest or most relevant to the content of the code to be processed.

[0098] In this embodiment, by obtaining the vectorized representation of each community in the at least one community, and vectorizing the code to be processed, entity relationship, grammatical structure information and code summary, the vectorized representation to be matched is obtained, and the deep semantic features of the community and the code to be processed can be obtained. On this basis, the similarity between the vectorized representation to be matched and the vectorized representation of each community is calculated, and the community with the highest similarity is selected as the target community, which can improve the accuracy and effectiveness of the target community.

[0099] As another optional embodiment of the present application, a large model-driven method based on local code repository programming is provided in Embodiment 4 of the present application. This embodiment is mainly an implementation method for constructing the graph in Embodiment 1. The graph can be constructed in the following manner:

[0100] Step S11: split the code files in the local code repository to obtain multiple code snippets.

[0101] Step S12: extracting a summary of each code snippet based on the target macro model to obtain a code summary of each code snippet.

[0102] In this embodiment, the code snippet and the prompt "output the implementation logic and key information of this code" can be input into the target macro model to obtain the code summary of the code snippet output by the target macro model.

[0103] In this embodiment, the key information may include but is not limited to: class name, function name, method name, parameters, return value, code comments and other elements.

[0104] For example, in Figure 2 In the my_project project, after the code files of the module1 module of the my_project function are split, you can Figure 3 The code snippet "#['my_project',..." and the prompt "Output the implementation logic and key information of this code" shown in part (a) are input into the target large model, and the target large model outputs the following Figure 3 The implementation logic and key information are shown in part (b).

[0105] Step S13: extracting entity relationships from the code summary of each code snippet based on the target macro model.

[0106] In this embodiment, prompt words for extracting entity relationships can be designed, and the prompt words and the code summary of each code snippet are input into the target large model to ensure that entities and their relationships can be extracted from the code summary efficiently and accurately.

[0107] In this embodiment, prompt words can be designed based on the input format of the target big model, the identification of key entities, and the determination of the association between entities to maximize the potential of the target big model, so as to achieve accurate data extraction and in-depth relationship analysis, thereby improving the intelligence level of the entire code summary understanding process.

[0108] For example, Figure 4 As shown in part (a), the code summary of one of the code snippets and the prompt "output the triple information of this paragraph" can be input into the target large model to obtain the triple information output by the target large model, such as Figure 4 As shown in part (b), in the triple information ['add_numbers', 'parameter', 'a'], add_numbers and a are both entities, and the relationship between add_numbers and a is that a is a parameter of add_numbers.

[0109] Step S14: Based on the abstract syntax tree analysis method, the syntax structure of each of the code snippets is analyzed respectively to obtain syntax structure information of each of the code snippets.

[0110] In this embodiment, the abstract syntax tree analysis method can be an AST package integrated in the programming tool, which can easily implement the structured analysis of the code. Figure 5 As shown, the grammatical structure information of the code snippet may be a grammatical tree structure.

[0111] By using the AST package integrated in the programming tool, the grammatical structure of each code snippet is analyzed separately to obtain the grammatical structure information of each code snippet, which can not only simplify the workflow of code analysis, but also improve the accuracy and efficiency of code parsing.

[0112] Step S15: construct the ontology.

[0113] As a formal knowledge representation method, ontology is used to define a set of concepts and the relationships between these concepts. In the process of ontology construction, it can be understood as a detailed modeling and characterization of concepts in the programming field and their complex and intertwined relationships. For example, Figure 6As shown in the figure, the constructed ontology can not only reveal the hierarchical structure between entities (such as 'class', 'package', 'method', 'function', 'parameter', 'variable', 'comment', 'exception', 'code snippet', 'code summary'), but also show the various relationships between them, thus providing a structured framework for understanding and analyzing knowledge in the programming field. Through the construction of the ontology, programming domain knowledge can be transformed into a form that is easy to understand and process, providing a solid foundation for further knowledge extraction, reasoning and decision-making.

[0114] The entities in the ontology not only represent the basic units in the code structure, but also contain the semantic information of the code. In the ontology, these concepts do not exist in isolation, but are interconnected through a series of relationships to form a close knowledge network. Figure 7 As shown in Figure 1, the relationships between concepts include but are not limited to the following: inheritance and derivation, such as inheritance between classes; inclusion and inclusion, such as the affiliation between packages and methods; calling and being called, such as the interaction between methods and functions. The establishment of these relationships provides rich semantic information for understanding and analyzing the structure and function of the code, making ontology a powerful knowledge representation tool.

[0115] Step S16: Enter the multiple code snippets, the code summary of each code snippet, the entity relationship and the grammatical structure information of each code snippet into the ontology to obtain a graph.

[0116] In this embodiment, for each entity defined in the ontology (such as class, method, function, parameter, etc.), a corresponding node can be created. For example, for the entity "Dog", a node named "Dog" can be created.

[0117] For the relationship in the ontology, you can create an edge corresponding to the node. For example, for the relationship "Dog -- (definition / defined) -- init", you can create an edge from the "Dog" node to the "init" node and annotate the relationship of this edge as "definition / defined".

[0118] In addition to basic entities and relations, additional information (such as code snippets, code summaries, entity relations, grammatical structure information, etc.) can be added to the constructed nodes and / or edges. For example, for the function "add_numbers", an attribute can be added to its corresponding node, which contains the code snippet, code summary, entity relations, and grammatical structure information of the function.

[0119] The created nodes are connected through edges to obtain a graph.

[0120] For example, the information in the graph may include:

[0121] Dog -- (definition / defined) -- __init_;

[0122] Dog -- (defining / defined) -- display_info;

[0123] Dog -- (definition / defined) -- bark;

[0124] __init__ -- (contains / is included) -- name;

[0125] __init__ -- (contains / is contained by) -- age;

[0126] display_info -- (contains / is contained by) -- name;

[0127] display_info -- (contains / is contained by) -- age;

[0128] bark -- (contains / is contained by) -- name;

[0129] add_numbers -- (contains / is contained by) -- a;

[0130] add_numbers -- (contains / is contained by) -- b;

[0131] my_dog -- (caller / called) -- Dog;

[0132] add_numbers -- (property) -- def add_numbers(a, b): \n return a + b;

[0133] add_numbers -- (attributes) -- This code is a simple Python function definition.

[0134] In this embodiment, by splitting the code files in the local code repository into multiple code snippets, the complexity and difficulty of understanding the code can be reduced. In addition, building an ontology is the basis for building a knowledge graph. By entering multiple code snippets, code summaries, entity relationships, and grammatical structure information into the ontology, a graph containing rich code knowledge and information can be generated. This graph not only helps developers quickly understand the structure and function of the code base, but also provides strong support for applications such as intelligent search, recommendation, and completion of the code.

[0135] As another optional embodiment of the present application, a large model-driven local code repository-based programming method is provided in Embodiment 5 of the present application. This embodiment is mainly an implementation method of step S11 in Embodiment 4. Step S11 may include but is not limited to the following steps:

[0136] Step S111: cutting the code file in the local code repository into pieces of a set length to obtain a plurality of code units.

[0137] Setting the maximum number of tokens or characters in a code snippet to n (e.g., about 1k) as the basis for segmentation can ensure that each code unit is not too large while maintaining a certain degree of integrity. "Tokens" can include basic units in the code, such as keywords, variable names, operators, etc.

[0138] If the cut point is inside a class, function, or method, that is, when the class, function, or method is split into two fragments, you can choose a fragment with a length less than n to try to ensure the integrity of the class, function, or method. If the integrity of the class, function, or method cannot be maintained even if the value of n is reduced, a mapping relationship can be established.

[0139] Step S112: Mark the code unit according to the set mark list to obtain a code snippet; the set mark list includes the following elements: project name, function, module, class, function and method.

[0140] Each code snippet is marked with a segment <start> … <end>Mark the starting and ending positions.

[0141] For example, taking n=10 as an example, the code snippet is as follows Figure 8 As shown in the figure, #my_project-my_project-modele1, #['my_project', ' my_project',' modele1','','add_numbers',''], etc. are tags made according to the set tag list.

[0142] In this embodiment, the code units are marked according to a set mark list, and the marks provide context information for the code snippets, so that the target large model can understand the code snippets more quickly, thereby ensuring the accuracy and efficiency of summary extraction.

[0143] As another optional embodiment of the present application, a large model-driven local code repository-based programming method is provided in Embodiment 6 of the present application. This embodiment is mainly an implementation method for constructing at least one community in Embodiment 1. The at least one community can be obtained in the following manner:

[0144] Step S21: Initialize an independent community for each node in the graph to obtain multiple communities.

[0145] Step S22: Selecting a node from each node in the graph to move in a direction of increasing the first network modularity, and updating the multiple communities to obtain multiple new communities.

[0146] The first network modularity indicates the quality of community division. The larger the first network modularity is, the tighter the connection between nodes in the corresponding new community is and the sparser the connection between new communities is.

[0147] Consider each node of the graph in turn, and try to move the node to the community where its neighboring nodes are located to increase the first network modularity. For each node, calculate the change in modularity when moving it to different communities, select the community with the largest increase to move, and repeat this step until no node movement can increase the first network modularity. For example, a graph containing 6 nodes A, B, C, D, E, F, in the initial stage, each node is regarded as an independent community. Therefore, {A}, {B}, {C}, {D}, {E}, {F} are the initial 6 communities. {A}, {B}, {C}, {D}, {E}, {F} will have a first network modularity of x1. Consider node A: A's neighbors are B and C. If A moves to the community {B} where B is located, the new community is {A, B}, {C}, {D}, {E}, {F}, and the first network modularity corresponding to {A, B}, {C}, {D}, {E}, {F} is x2. If x2 is greater than x1, {A,B}, {C}, {D}, {E}, {F} are retained; if A moves to the community {C} where C is located, the new community is {A, C}, {B}, {D}, {E}, {F}, and the first network modularity corresponding to {A, C}, {B}, {D}, {E}, {F} is x3. If x3 is greater than x2, {A,C}, {B}, {D}, {E}, {F} are retained; if x3 is smaller than x2, the original {A,B}, {C}, {D}, {E}, {F} are still retained.

[0148] Step S23: Selecting communities from the multiple new communities to merge in a direction of increasing the second network modularity to obtain at least one community.

[0149] In this embodiment, node movement and community merging may be repeated until a certain stop condition is reached, such as no node movement can increase the modularity, or a preset number of iterations is reached.

[0150] The second network modularity indicates the quality of community division. The larger the second network modularity is, the tighter the connection between communities within the community is and the sparser the connection between communities is.

[0151] Each community in at least one community may include at least one community, and each community in at least one community may include at least one node. For example, the graph contains nodes A, B, C, D, E, F, and the initial communities are {A}, {B}, {C}, {D}, {E}, {F}; after moving the nodes, three communities are obtained, namely {A,B,C}, {D,E}, {F}; the communities can be merged to obtain two communities, namely {A,B,C}, {{ D,E},F}.

[0152] In this embodiment, by moving nodes and merging communities in the direction of increasing modularity, a clearer and more intuitive community and group structure can be formed.

[0153] As another optional embodiment of the present application, a large model-driven method based on local code repository programming is provided in Embodiment 7 of the present application. This embodiment is mainly an implementation method for determining the first network modularity in Embodiment 6. The first network modularity can be determined in the following manner:

[0154] Based on the first relation , calculate the first network modularity; where, represents the first network modularity, represents the number of communities, Representing the community The sum of the weights of the internal edges, where the weight of the internal edge is a value obtained by normalizing the number of occurrences of the relationship between the two nodes connected by the internal edge, Representation and Community Half of the sum of the weights of all edges connecting the nodes in The weight of the edge connecting the nodes in is the value obtained by normalizing the number of occurrences of the relationship between the two nodes connected by the edge.

[0155] As another optional embodiment of the present application, a large model-driven method based on local code repository programming is provided in Embodiment 8 of the present application. This embodiment is mainly an implementation method for determining the second network modularity in Embodiment 6. The second network modularity can be determined in the following manner:

[0156] Based on the second relation , calculate the second network modularity; where, represents the second network modularity, represents the number of communities, Representing the community The sum of the weights of the internal edges, where the weight of the internal edge is the value obtained by normalizing the number of occurrences of the relationship between the two communities connected by the internal edge, Representation and community Half of the sum of the weights of all edges connecting the communities in The weight of the edge connecting the communities in is the value obtained by normalizing the number of occurrences of the relationship between the two communities connected by the edge.

[0157] As another optional embodiment of the present application, a large model-driven local code repository-based programming method is provided in Embodiment 9 of the present application. This embodiment is mainly an implementation method of the task instructions in Embodiment 1. The task instructions may include but are not limited to:

[0158] The task instruction for instructing to complete the code to be processed is used. Accordingly, reasoning the reference code, the code to be processed and the task instruction based on the target large model to obtain the target result may include:

[0159] Based on the target large model, the reference code, the code to be processed and the task instructions for instructing to complete the code to be processed can be inferred to obtain the target code.

[0160] The target code is the code after completing the code to be processed.

[0161] Alternatively, the task instruction may include: a task instruction for asking questions to the code to be processed. Accordingly, reasoning the reference code, the code to be processed and the task instruction based on the target big model to obtain the target result may include:

[0162] The reference code, the code to be processed, and the task instruction for asking questions about the code to be processed are inferred based on the target large model to obtain a target answer. For example, the task instruction for asking questions about the code to be processed includes: please analyze the performance bottleneck of the code to be processed and propose at least one optimization solution. The performance bottleneck of the code to be processed can be analyzed based on the target large model, and the analysis results and at least one optimization solution can be given.

[0163] Next, a large model-driven device based on local code warehouse programming provided in the present application is introduced. The large model-driven device based on local code warehouse programming introduced below and the large model-driven method based on local code warehouse programming introduced above can be referenced to each other.

[0164] Reference Fig. 9 The large model-driven device based on local code repository programming includes: a first acquisition module 100, a processing module 200, a search module 300, a second acquisition module 400 and a reasoning module 500.

[0165] The first obtaining module 100 is used to obtain the to-be-processed code and task instruction in the request in response to the request.

[0166] The processing module 200 is used to process the code to be processed to obtain entity relationships, grammatical structure information and code summary.

[0167] The search module 300 is used to search for a target community that matches the code to be processed, entity relationship, grammatical structure information and code summary in at least one community; the at least one community is obtained by hierarchical processing of the graph, each community in the at least one community includes at least one community, at least one community in the community has similarity, each community in the at least one community includes at least one node in the graph, and at least one node in the community has similarity; the graph is constructed based on the code files in the local code repository and the entity relationships, grammatical structure information and code summaries corresponding to the code files in the local code repository.

[0168] The second obtaining module 400 is used to obtain a reference code according to the nodes and edges in the target community.

[0169] The reasoning module 500 is used to reason the reference code, the code to be processed and the task instruction based on the target large model to obtain a target result.

[0170] The processing module 200 may be specifically used for:

[0171] A code summary is extracted from the code to be processed based on the target large model; the code summary includes: implementation logic and key information.

[0172] Entity relationships are extracted from the code summary based on the target big model.

[0173] Based on the abstract syntax tree analysis method, the syntax structure of the code to be processed is analyzed to obtain syntax structure information.

[0174] The search module 300 may be specifically used for:

[0175] Obtaining a vectorized representation of each community in the at least one community; the vectorized representation of the community is obtained by vectorizing the community summary of the community;

[0176] Vectorizing the code to be processed, entity relationships, grammatical structure information, and code summary to obtain a vectorized representation to be matched;

[0177] The similarity between the vectorized representation to be matched and the vectorized representation of each community is calculated, and the community with the highest similarity is selected as the target community.

[0178] The large model-driven device based on local code repository programming may also include:

[0179] The first building block is used to:

[0180] Split the code files in the local code repository to obtain multiple code snippets;

[0181] Based on the target macro model, each of the code snippets is respectively abstracted to obtain a code summary of each of the code snippets;

[0182] Extracting entity relationships from the code summary of each of the code snippets based on the target big model;

[0183] Based on the abstract syntax tree analysis method, the syntax structure of each code fragment is analyzed respectively to obtain the syntax structure information of each code fragment;

[0184] Constructing ontology;

[0185] The multiple code snippets, the code summary of each of the code snippets, the entity relationship and the grammatical structure information of each of the code snippets are entered into the ontology to obtain a graph.

[0186] The first building module splits the code files in the local code repository to obtain multiple code fragments, which may specifically include:

[0187] Split the code files in the local code repository into multiple code units according to the set length;

[0188] The code units are marked according to a set mark list to obtain code snippets; the set mark list includes the following elements: project name, function, module, class, function and method.

[0189] The large model-driven device based on local code repository programming may also include:

[0190] The second building block is used to:

[0191] Initialize each node in the graph into an independent community to obtain multiple communities;

[0192] The multiple communities are updated by selecting nodes from each node in the graph to move in a direction of increasing the first network modularity, thereby obtaining multiple new communities; the first network modularity indicates the quality of community division, and the larger the first network modularity, the closer the connection between nodes in the corresponding new community and the sparser the connection between new communities;

[0193] Communities are selected from the multiple new communities for merging in a direction of increasing the second network modularity to obtain at least one community; the second network modularity represents the quality of community division, and the larger the second network modularity, the tighter the connection between communities within the community and the sparser the connection between communities.

[0194] The first network modularity can be determined in the following way:

[0195] Based on the first relation , calculate the first network modularity; where, represents the first network modularity, represents the number of communities, Representing the community The sum of the weights of the internal edges, where the weight of the internal edge is a value obtained by normalizing the number of occurrences of the relationship between the two nodes connected by the internal edge, Representation and Community Half of the sum of the weights of all edges connecting the nodes in The weight of the edge connecting the nodes in is the value obtained by normalizing the number of occurrences of the relationship between the two nodes connected by the edge.

[0196] The second network modularity can be determined in the following way:

[0197] Based on the second relation , calculate the second network modularity; where, represents the second network modularity, represents the number of communities, Representing the community The sum of the weights of the internal edges, where the weight of the internal edge is the value obtained by normalizing the number of occurrences of the relationship between the two communities connected by the internal edge, Representation and community Half of the sum of the weights of all edges connecting the communities in The weight of the edge connecting the communities in is the value obtained by normalizing the number of occurrences of the relationship between the two communities connected by the edge.

[0198] The task instructions may include:

[0199] A task instruction for instructing to complete the code to be processed;

[0200] Or, a task instruction for asking questions about the code to be processed.

[0201] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0202] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0203] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0204] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.< / end> < / start>

Claims

1. A large model driven local code repository programming method, characterized in that: include: In response to the request, obtaining the code to be processed and the task instruction in the request; Processing the code to be processed to obtain entity relationships, grammatical structure information and code summaries; Searching for a target community that matches the to-be-processed code, entity relationship, grammatical structure information, and code summary in at least one community; the at least one community is obtained by layering the graph, each community in the at least one community includes at least one community, at least one community in the community has similarity, each community in the at least one community includes at least one node in the graph, and at least one node in the community has similarity; The graph is constructed based on the code files in the local code repository and the entity relationships, grammatical structure information and code summaries corresponding to the code files in the local code repository; Obtaining reference codes according to the nodes and edges in the target community; Reasoning the reference code, the code to be processed and the task instruction based on the target big model to obtain a target result; The map is constructed in the following way: Split the code files in the local code repository to obtain multiple code snippets; Based on the target macro model, each of the code snippets is respectively abstracted to obtain a code summary of each of the code snippets; Extracting entity relationships from the code summary of each of the code snippets based on the target big model; Based on the abstract syntax tree analysis method, the syntax structure of each code fragment is analyzed respectively to obtain the syntax structure information of each code fragment; Constructing ontology; The multiple code snippets, the code summary of each of the code snippets, the entity relationship and the grammatical structure information of each of the code snippets are entered into the ontology to obtain a graph.

2. The method for programming based on a local code repository driven by a large model according to claim 1, characterized in that: The processing of the code to be processed to obtain entity relationships, grammatical structure information and code summaries includes: Extracting a code summary from the code to be processed based on the target large model; the code summary includes: implementation logic and key information; extracting entity relationships from the code summary based on the target big model; Based on the abstract syntax tree analysis method, the syntax structure of the code to be processed is analyzed to obtain syntax structure information.

3. The method of large model driven programming based on local code repository according to claim 1, characterized in that: The step of searching for a target community in at least one community that matches the code to be processed, entity relationship, grammatical structure information, and code summary includes: Obtaining a vectorized representation of each community in the at least one community; the vectorized representation of the community is obtained by vectorizing the community summary of the community; Vectorizing the code to be processed, entity relationships, grammatical structure information, and code summary to obtain a vectorized representation to be matched; The similarity between the vectorized representation to be matched and the vectorized representation of each community is calculated, and the community with the highest similarity is selected as the target community.

4. The method of large model-driven local code repository programming according to claim 1, characterized in that: Split the code files in the local code repository to obtain multiple code snippets, including: Split the code files in the local code repository into multiple code units according to the set length; The code units are marked according to a set mark list to obtain code snippets; the set mark list includes the following elements: project name, function, module, class, function and method.

5. The method of large model driven programming based on local code repository according to claim 1, characterized in that: The at least one community is obtained by: Initialize each node in the graph into an independent community to obtain multiple communities; The multiple communities are updated by selecting nodes from each node in the graph to move in a direction of increasing the first network modularity, thereby obtaining multiple new communities; the first network modularity indicates the quality of community division, and the larger the first network modularity, the closer the connection between nodes in the corresponding new community and the sparser the connection between new communities; Communities are selected from the multiple new communities for merging in a direction of increasing the second network modularity to obtain at least one community; the second network modularity represents the quality of community division, and the larger the second network modularity, the tighter the connection between communities within the community and the sparser the connection between communities.

6. The method for programming based on a local code repository driven by a large model according to claim 5, characterized in that: The first network modularity is determined by: Based on the first relation , calculate the first network modularity; where, represents the first network modularity, represents the number of communities, Representing the community The sum of the weights of the internal edges, where the weight of the internal edge is a value obtained by normalizing the number of occurrences of the relationship between the two nodes connected by the internal edge, Representation and Community Half of the sum of the weights of all edges connecting the nodes in The weight of the edge connecting the nodes in is the value obtained by normalizing the number of occurrences of the relationship between the two nodes connected by the edge.

7. The method of large model driven programming based on local code repository according to claim 5, characterized in that: The second network modularity is determined by: Based on the second relation , calculate the second network modularity; where, represents the second network modularity, represents the number of communities, Representing the community The sum of the weights of the internal edges, where the weight of the internal edge is a value obtained by normalizing the number of occurrences of the relationship between the two communities connected by the internal edge, Representation and community Half of the sum of the weights of all edges connecting the communities in The weight of the edge connecting the communities in is the value obtained by normalizing the number of occurrences of the relationship between the two communities connected by the edge.

8. The method according to claim 1, characterized in that: The task instructions include: A task instruction for instructing to complete the code to be processed; Or, a task instruction for asking questions about the code to be processed.

9. A large model driven device based on local code repository programming, characterized in that: include: A first obtaining module, configured to obtain, in response to a request, a code to be processed and a task instruction in the request; A processing module, used for processing the code to be processed to obtain entity relationships, grammatical structure information and code summary; A search module, used to search for a target community matching the code to be processed, entity relationship, grammatical structure information and code summary in at least one community; The at least one community is obtained by layering the graph, each community in the at least one community includes at least one community, at least one community in the community has similarity, each community in the at least one community includes at least one node in the graph, and at least one node in the community has similarity; The graph is constructed based on the code files in the local code repository and the entity relationships, grammatical structure information and code summaries corresponding to the code files in the local code repository; wherein the graph is constructed in the following manner: the code files in the local code repository are split to obtain multiple code snippets; each of the code snippets is respectively summarized and refined based on the target big model to obtain the code summary of each of the code snippets; entity relationships are extracted from the code summary of each of the code snippets based on the target big model; the grammatical structure of each of the code snippets is respectively analyzed based on the abstract syntax tree analysis method to obtain the grammatical structure information of each of the code snippets; an ontology is constructed; the multiple code snippets, the code summary of each of the code snippets, the entity relationships and the grammatical structure information of each of the code snippets are entered into the ontology to obtain a graph; A second obtaining module is used to obtain a reference code according to the nodes and edges in the target community; The reasoning module is used to reason the reference code, the code to be processed and the task instruction based on the target large model to obtain the target result.

Citation Information

Patent Citations

  • Intelligent auxiliary method and platform for software development

    CN117369786A

  • Code processing method fusing multiple retrieval modes, model end and storage medium

    CN119002930A