Code adoption situation determination method and apparatus, electronic device, and storage medium
By generating code vectors and combining them with large language models for deep semantic analysis, the problem of being unable to accurately evaluate the adoption of AI-generated code is solved, and rapid and accurate adoption judgment and tool optimization are achieved.
Patent Information
- Application Number
- CN202511008993.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-22
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-07-22
AI Technical Summary
Existing techniques cannot accurately assess user adoption of AI-generated code.
By extracting the semantic information of the code, a code vector in a preset format is generated, similarity retrieval is performed using the vector database, and deep semantic analysis is performed in combination with a large language model to determine the code adoption status.
It improves the accuracy and reliability of identifying code adoption, realizes the quantification of the capabilities of AI-assisted programming tools, and facilitates the optimization of tool performance.
Smart Images

Figure CN120508837B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of computers, and in particular, to a code adoption situation determination method and device, electronic equipment, computer readable storage medium, and computer program product. BACKGROUND
[0002] With the rapid development of artificial intelligence technology, especially the breakthrough in the field of natural language processing and machine learning, large language models (LLM) are increasingly widely used in software development. Artificial intelligence (AI) assisted programming of large language models can generate new code snippets according to natural language descriptions or existing code, significantly improving development efficiency and innovation capability.
[0003] However, the adoption situation of AI-generated code by users cannot be accurately evaluated in the related art. SUMMARY
[0004] The present application provides a code adoption situation determination method and device, electronic equipment, computer readable storage medium, and computer program product to at least solve the problem that the adoption situation of AI-generated code by users submitted code cannot be accurately evaluated in the related art.
[0005] The present application provides a code adoption situation determination method, comprising: in the case where a first code submitted by a target object is obtained, extracting semantic information in the first code, and generating a first code vector in a preset format corresponding to the first code based on the semantic information; based on the first code vector, performing retrieval in a pre-constructed vector database to determine at least one candidate code vector in the vector database that meets the similarity of the first code vector, wherein the vector database comprises code vectors corresponding to each code in a preset artificial intelligence code library; based on the at least one candidate code vector, extracting at least one second code pointed to by the at least one candidate code vector in the artificial intelligence code library; inputting the first code and the at least one second code into a large language model, and determining the adoption situation of the first code for the at least one second code based on the output result of the large language model, wherein the large language model is used for semantic understanding of the code to determine the similarity of the code.
[0006] The application further provides a code adoption condition determination apparatus, comprising: a vector conversion module configured to, in a case where a first code submitted by a target object is acquired, extract semantic information in the first code, and generate a first code vector in a preset format corresponding to the first code based on the semantic information; a retrieval module configured to perform retrieval in a vector database constructed in advance based on the first code vector, to determine at least one candidate code vector in the vector database that meets a similarity criterion with the first code vector, wherein the vector database comprises code vectors corresponding to respective codes in a preset artificial intelligence code library; an extraction module configured to extract at least one second code pointed to by the at least one candidate code vector in the artificial intelligence code library based on the at least one candidate code vector; and an adoption determination module configured to input the first code and the at least one second code into a large language model, and determine an adoption condition of the first code for the at least one second code based on an output result of the large language model, wherein the large language model is configured to perform semantic understanding on the codes to determine the similarity of the codes.
[0007] The application further provides an electronic device, comprising: a memory configured to store a computer program; and a processor configured to implement the steps of the code adoption condition determination method when executing the computer program.
[0008] The application further provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the code adoption condition determination method.
[0009] The application further provides a computer program product, comprising a computer program, and the computer program is executed by a processor to implement the steps of the code adoption condition determination method.
[0010] Through the present application, since the semantic features of the code are extracted by the deep learning model, combined with efficient vector retrieval and deep semantic comparison, the accuracy and reliability of identifying the adoption situation are significantly improved. Based on the candidate code vectors retrieved by the first code vector, the system can accurately locate the source of each candidate code vector in the artificial intelligence code library, and then preliminarily search for the real second code through vector retrieval, greatly reducing the search range. Then based on the understanding ability of the large language model, the first code and at least one second code are deeply analyzed and contextually perceived, and the adoption situation between the first code and at least one second code is accurately judged, so that through two levels of code identification, the adoption situation between the first code and at least one second code is quickly and accurately judged. Based on the adoption situation, the actual value and influence of the AI-assisted programming tool can be accurately evaluated. The ability of the AI-assisted programming tool is accurately quantified, which facilitates the targeted optimization of the ability of the AI-assisted programming tool. Therefore, the technical problem that the adoption situation of the code submitted by the user to the AI-generated code cannot be accurately evaluated can be solved, and the technical effect that the adoption situation between the first code and at least one second code is quickly and accurately judged can be achieved. BRIEF DESCRIPTION OF DRAWINGS
[0011] In order to more clearly illustrate the embodiments of the present application, the drawings needed in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0012] Figure 1 is a hardware structure block diagram of a server device of a code adoption situation determination method according to an embodiment of the present application;
[0013] Figure 2 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0014] Figure 3 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0015] Figure 4 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0016] Figure 5 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0017] Figure 6 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0018] Figure 7 FIG. 6 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0019] Figure 8 FIG. 7 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0020] Figure 9 FIG. 8 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0021] Figure 10 FIG. 9 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0022] Figure 11 FIG. 10 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0023] Figure 12 FIG. 11 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0024] Figure 13 FIG. 12 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0025] Figure 14 FIG. 13 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0026] Figure 15 FIG. 14 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0027] Figure 16 FIG. 15 is a flowchart of a code adoption situation determination method according to an embodiment of the present application;
[0028] Figure 17 FIG. 16 is a structural block diagram of a code adoption situation determination apparatus according to an embodiment of the present application. DETAILED DESCRIPTION
[0029] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, any other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0030] It should be noted that, in the description of the present application, the term "comprising" or "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or further includes elements inherent to such a process, method, article or device. The terms "first", "second" and the like in the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence.
[0031] In order for those skilled in the art to better understand the present application, the present application will be further described in detail below in combination with the accompanying drawings and specific embodiments.
[0032] In combination with the specific application environment architecture or the specific hardware architecture on which the code adoption determination method is executed, the specific application environment architecture or the specific hardware architecture is described here.
[0033] The code adoption determination method provided in the embodiments of the present application can be executed in a server device or a similar computing device. Taking the case of running on a server device, Figure 1 is a hardware structure block diagram of a server device of a code adoption determination method according to an embodiment of the present application. As Figure 1 shown, the server device can include one or more (only one is shown in Figure 1 ) processor 102 (the processor 102 can include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned server device can further include a transmission device 106 for communication function and an input and output device 108. Those skilled in the art can understand that Figure 1 the structure shown is only schematic, which does not limit the structure of the above-mentioned server device. For example, the server device can further include more or less components than those shown in Figure 1 , or have a different configuration from Figure 1 .
[0034] The memory 104 can be used to store computer programs, such as software programs of application software and modules, such as a computer program corresponding to the code adoption situation determination method in the embodiments of the present application. The processor 102 performs various functional applications and data processing by running the computer programs stored in the memory 104, that is, implements the above method. The memory 104 can include a high-speed random access memory, and can also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 104 can further include a memory remotely arranged with respect to the processor 102, which can be connected to a server device through a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0035] The transmission device 106 is used to receive or send data via a network. Specific examples of the above network can include a wireless network provided by a communication provider of the server device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC) which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, RF) module used for wireless communication with the Internet.
[0036] The embodiments of the present application provide a code adoption situation determination method applied to the above server device. The method will be described in detail in combination with the execution process of the code adoption situation determination method. As shown in Figure 2 The method includes the following steps S200-S230:
[0037] Step S200, in the case of obtaining a first code submitted by a target object, extracting semantic information in the first code, and generating a first code vector in a preset format corresponding to the first code based on the semantic information.
[0038] Specifically, when the system receives the code snippet (first code) submitted by the target object, the first task is to perform deep semantic extraction on these codes, rather than just staying on the surface of text matching. This step aims to capture the function, logical structure and potential meaning of the code, and provide more abundant information for subsequent similarity comparison. Then, the system can use a pre-trained code embedding model to convert the extracted semantic information into a fixed-dimensional vector representation, i.e., the first code vector. This vectorization processing can more concisely represent the semantic features of the code, facilitating subsequent processing and storage.
[0039] Step S210, based on the first code vector, search in the pre-constructed vector database to determine at least one candidate code vector in the vector database that meets the similarity standard with the first code vector.
[0040] Wherein, the vector database includes code vectors corresponding to each code in the preset artificial intelligence code library.
[0041] Specifically, the system uses the first code vector to perform similarity search in a pre-constructed vector database that contains vector representations (referred to as second code vectors) of various code snippets generated by artificial intelligence code generators (such as large language models) in the past. The goal of the search is to find candidate code vectors that have high semantic similarity with the first code vector, in order to further identify whether code adoption behavior has occurred. Meeting the similarity standard means that the similarity between the candidate code vector and the first code vector exceeds a preset threshold, which is usually achieved by calculating the cosine similarity or Euclidean distance between the vectors.
[0042] Step S220, based on at least one candidate code vector, extract at least one second code pointed to by the at least one candidate code vector in the artificial intelligence code library.
[0043] Specifically, after determining the candidate code vectors, the system needs to locate the original code snippets (second codes) corresponding to these vectors in the artificial intelligence code library.
[0044] Illustratively, code positioning: use the metadata in the candidate code vector (such as code identifier (Identifier, ID), generation time, model version, etc.) to find and extract the corresponding second code in the artificial intelligence code library.
[0045] Step S230, input the first code and at least one second code into the large language model, and determine the adoption of the first code to the at least one second code based on the output result of the large language model.
[0046] Wherein, the large language model is used for semantic understanding of the code to determine the similarity of the code.
[0047] Specifically, in order to verify the semantic similarity between the first code and the second code, that is, to judge whether the first code substantially adopts or is significantly inspired by the second code, the system inputs the two sets of codes into a pre-trained large language model. The large language model uses its deep understanding ability to perform high-level semantic comparison of the code pairs, and judges whether there is substantial similarity between them and whether this similarity meets the adoption standard.
[0048] Exemplarily, a structured prompt is built for each code pair, containing code snippets, metadata (such as generation time, file path, etc.), and explicit requirements for inquiries about code similarity and adoption. A large language model is called, and the judgment result and reason returned by the model are parsed to determine the adoption relationship. The model can return a similarity score and a classification label (such as adoption, partial adoption, inspired, irrelevant).
[0049] In this embodiment, the semantic features of the code are extracted by a deep learning model, and then combined with efficient vector retrieval and deep semantic comparison, the accuracy and reliability of identifying the adoption situation are significantly improved. Based on the candidate code vectors retrieved by the first code vector, the system can accurately locate the source code of each candidate code vector in the artificial intelligence code library, and then preliminarily search for the real second code through vector retrieval, greatly reducing the search range. Then based on the understanding ability of the large language model, the first code and at least one second code are deeply analyzed and contextually perceived to accurately determine the adoption situation between the first code and at least one second code, so as to quickly and accurately determine the adoption situation between the first code and at least one second code through two-level code recognition. Based on the adoption situation, the actual value and influence of the AI-assisted programming tool can be accurately evaluated. The ability of the AI-assisted programming tool is accurately quantified, which facilitates targeted optimization of the ability of the AI-assisted programming tool.
[0050] In one embodiment, as shown in Figure 3 Step S210, based on the first code vector, the vector database is retrieved to determine at least one candidate code vector in the vector database that meets the similarity of the first code vector. Including steps S300-S320:
[0051] Step S300, according to the content of the first code vector and the metadata corresponding to the first code, a first vector index corresponding to the first code vector is constructed.
[0052] Specifically, after obtaining the first code vector, the system needs to combine the metadata related to the first code (such as code generation time, version of the generated AI model, file path, etc.) to establish an index for the first code vector in the vector database. This index aims to store and organize vector information and related metadata, so that the system can efficiently retrieve similar code vectors to the first code vector.
[0053] Exemplarily, a database system supporting vector storage and retrieval can be selected, such as Milvus or a relational database + vector extension plug-in (Postgre Structured Query Language + pgvector, PostgreSQL + pgvector). The database is configured to support efficient data storage and retrieval. Ensure that the first code vector is stored in the database with its related metadata saved together for subsequent retrieval and analysis. Build efficient indexes on the vector field, such as Hierarchical Navigable Small World (HNSW) or Inverted File with Asymmetric Distance Computation (IVFADC), to improve the speed and accuracy of similarity search.
[0054] Step S310, according to the first vector index in the vector database for retrieval, to determine the plurality of code vectors with the first vector index matching degree standard.
[0055] Among them, the matching degree of the plurality of code vectors with the first vector index is used to indicate the similarity of the plurality of code vectors with the first code vector.
[0056] Specifically, based on the constructed first vector index, the system performs similarity retrieval in the vector database. The purpose of retrieval is to find out a plurality of code vectors with semantic similarity to the first code vector reaching or exceeding a preset matching degree threshold.
[0057] Exemplarily, a matching degree threshold (for example, cosine similarity > 0.7) can be set using cosine similarity, Euclidean distance or other suitable metrics for vector similarity evaluation. Using the constructed vector index, perform Approximate Nearest Neighbor (ANN) search to quickly find a plurality of code vectors with matching degree to the first code vector. The retrieval results are sorted by matching degree, and the plurality of code vectors with matching degree higher than the preset threshold are retained for further verification.
[0058] Step S320, the code vector in the plurality of code vectors with similarity to the first code vector greater than the first similarity threshold is taken as a candidate code vector.
[0059] Specifically, among the plurality of code vectors retrieved, further filter out those code vectors with similarity to the first code vector exceeding the first similarity threshold as candidates for subsequent adoption verification. This step aims to refine the search results and ensure that the candidate code vectors have substantial similarity to the first code vector, in order to improve the efficiency and accuracy of adoption verification.
[0060] Exemplarily, a higher similarity threshold (such as cosine similarity > 0.85) is set to ensure that the candidate code vector and the first code vector have significant semantic similarity. From the search results, all code vectors with a similarity exceeding the first similarity threshold are selected to construct a candidate code vector set for subsequent deep semantic verification.
[0061] In this embodiment, by constructing a first vector index and an efficient retrieval mechanism, the system can quickly find similar code snippets in a large-scale code library, significantly improving the speed of code retrieval. At the same time, by setting a matching degree threshold, the semantic relevance of the search results is ensured, and the accuracy is improved. The setting of the first similarity threshold can effectively filter out code vectors with large semantic differences from the target code, avoiding unnecessary deep verification of low similarity codes, saving computing resources and time costs. The determination of the candidate code vector lays a foundation for subsequent deep semantic verification, enabling the system to analyze the code adoption situation in detail, including direct adoption, partial adoption, and AI code inspiration, which enhances the accurate evaluation and tracing ability of code adoption.
[0062] In one embodiment, as shown in Figure 4 Step S200, in the case where a first code submitted by a target object is obtained, semantic information in the first code is extracted, and a first code vector in a preset format corresponding to the first code is generated based on the semantic information. It includes steps S400-S420:
[0063] Step S400, the first code is segmented to divide the first code into multiple code snippets.
[0064] Specifically, the obtained original code (first code) is decomposed into smaller and more manageable units, i.e. multiple code snippets. This segmentation is based on the structure and logic of the code, ensuring that each code snippet contains relatively independent semantic information, creating conditions for subsequent semantic analysis and vectorization.
[0065] Exemplarily, it can be based on an abstract syntax tree (Approximate Nearest Neighbor, AST) segmentation, using a syntax parser to construct an abstract syntax tree (AST) of the first code, and dividing the code into multiple logical units such as functions, classes or important control flow blocks according to the structure of the AST.
[0066] Step S410, a preset semantic analysis model is used to perform semantic analysis on the multiple code snippets respectively to generate semantic vectors of a preset dimension corresponding to the multiple code snippets respectively.
[0067] The semantic parsing model is used to capture the syntax structure in the code snippet and parse the semantic information of the code snippet based on the syntax structure.
[0068] Specifically, the code snippets obtained by the above segmentation are subjected to deep semantic parsing, and a pre-trained semantic parsing model is used to generate a fixed-length semantic vector matched with each code snippet. These semantic vectors not only reflect the syntax structure of the code, but more importantly, express the deep semantics and functional characteristics of the code.
[0069] By way of example, a pre-trained semantic parsing model optimized for code is selected and loaded into memory. Each code snippet is converted into the input format required by the model, which can include tokenization, padding, or truncation of sequences to achieve a preset length. The preprocessed code snippet is input into the semantic parsing model, and the output is a fixed-dimension semantic vector. Each code snippet will have its own semantic vector representation, reflecting its unique semantic characteristics.
[0070] At step S420, a first code vector is generated by combining the preset-dimension semantic vectors corresponding to the plurality of code snippets.
[0071] Specifically, after obtaining the semantic vectors of the plurality of code snippets, these vectors are combined into an overall representation, i.e., the first code vector. This step integrates the semantic features of individual code snippets through certain mathematical operations or algorithms, enabling the first code vector to comprehensively reflect the semantic structure and functional characteristics of the entire code snippet.
[0072] By way of example, a vector integration strategy is selected, such as average pooling (averaging multiple semantic vectors), weighted summation (assigning different weights according to the importance of different code snippets), max pooling (selecting the highest value), or attention mechanism (more finely considering the importance of different snippets). The selected integration strategy is applied to the semantic vectors of the plurality of code snippets to generate the final first code vector. The generated first code vector can also be standardized to ensure its comparability and stability in subsequent similarity matching.
[0073] In this embodiment, by structurally segmenting the first code and performing semantic parsing and vectorization on each code snippet, the system can gain a deeper understanding of the code's semantic structure, going beyond superficial textual matching. This significantly improves the depth and accuracy of code understanding and comparison. Each code snippet is converted into a fixed-dimensional semantic vector. This vectorization enables the system to represent the code's semantic features from multiple perspectives, such as grammatical structure, function calls, and variable usage, enhancing the richness of code representation. The generation of the first code vector provides a unified basis for subsequent similarity comparisons with vectors of historical AI-generated code. Inter-vector comparisons (such as cosine similarity) are more efficient than textual matching, reducing comparison time in large code bases and improving system performance. The generation of the first code vector makes it possible to accurately assess which portions of the developer-submitted code actually adopted the AI-generated code. By comparing the vectors with historical AI-generated code, adoption patterns can be more accurately identified, avoiding false positives and missed detections, and improving the accuracy and reliability of code adoption analysis.
[0074] In one embodiment, Figure 5 As shown, step S400 is to segment the first code to segment the first code into multiple code segments. It includes steps S500-S520:
[0075] Step S500: determining the programming language used by the first code according to feature information of the first code.
[0076] Specifically, before processing the first code, the system needs to accurately identify the programming language used in the code. This is achieved based on the programming language's unique syntax, keywords, and structure, laying the foundation for subsequent code segmentation and normalization. Accurate programming language identification ensures the applicability and efficiency of subsequent processing steps.
[0077] Step S510 : segmenting the first code using a corresponding segmentation strategy according to the programming language used by the first code to generate a plurality of code segments.
[0078] Specifically, based on the programming language determined in the previous step, the system uses a corresponding code segmentation strategy to decompose the first code into multiple code fragments, each of which contains relatively independent semantic information. This step facilitates subsequent code standardization and semantic vectorization, as smaller code fragments are easier to manage and analyze. The segmentation granularity can be set according to actual needs, such as function level or statement block level, to meet the needs of different scenarios.
[0079] Step S520 : performing normalization processing on the plurality of code snippets to eliminate non-semantic information in the plurality of code snippets and converting the plurality of code snippets into a preset standard format.
[0080] Specifically, through normalization processing, unnecessary information that does not affect the semantics of the code snippet, such as comments and whitespace, is eliminated, and the code snippet is converted into a unified standard format to facilitate subsequent vectorization and similarity comparison.
[0081] In this embodiment, the accurate identification of the programming language ensures the correct application of the subsequent code segmentation strategy, avoids inconsistent processing due to language recognition errors, and improves the accuracy and efficiency of code processing. Code segmentation helps to decompose the first code into logically independent and more manageable code fragments, each of which carries specific semantic information, which is convenient for subsequent normalization processing and semantic analysis. Through normalization processing, non-essential factors that do not reflect semantics in code differences are eliminated, the accuracy of code text comparison is improved, and mismatches caused by different formats are reduced. Converting code fragments into a preset standard format unifies the coding style, simplifies the subsequent vectorization, storage and similarity comparison processes, and improves the processing speed of the overall system and the convenience of data management. It can significantly optimize the processing flow of the code submitted by developers, improve the accuracy and efficiency of code understanding and adoption analysis, and reduce the consumption of computing resources.
[0082] In one embodiment, Figure 6 As shown, step S510, according to the programming language used by the first code, the first code is segmented using a corresponding segmentation strategy to generate multiple code fragments. It includes: steps S600-S640:
[0083] Step S600: Loading a corresponding parser according to the programming language used by the first code.
[0084] Specifically, before processing the code, the system first needs to identify the programming language used in the first code. This step involves automatic language detection based on code features (such as keywords and grammatical structure). Once the programming language is identified, the system will load a parser that matches the language. A parser is a tool that understands the grammatical structure of a specific programming language, providing the foundation for subsequent code analysis and segmentation.
[0085] Step S610: parse the first code using a parser to generate an abstract syntax tree corresponding to the first code.
[0086] Specifically, an Abstract Syntax Tree (AST) is a tree-like data structure used to represent the structure of source code. By generating an AST for the first code segment, the system can understand the logical structure and grammatical features of the code, which serves as the basis for subsequent segmentation. The AST provides a structured representation of the grammatical structure of the code, enabling the system to more accurately identify logical units such as functions, classes, and methods within the code.
[0087] Step S620, based on the logical structure of the first code indicated by the abstract syntax tree, determine the semantic logic range of the first code.
[0088] Specifically, based on the AST, the system further analyzes the logical structure of the first code and determines the range with independent semantic logic in the code. These ranges can be functions, classes, methods or control flow blocks, which constitute the logical units of the code and are the basic units of subsequent code segment division.
[0089] Illustratively, by traversing the AST, logical units such as functions, class definitions, loops, etc. are identified, and their location information in the code (such as starting line, ending line) is recorded. A range is defined for each logical unit, which contains its complete code implementation, ensuring the integrity of the logic.
[0090] Step S630, based on the semantic logic range, the first code is segmented to divide the first code into multiple code segments.
[0091] Each code segment includes a complete semantic logic range.
[0092] Specifically, the system divides the first code into multiple code segments based on the determined semantic logic range, each code segment containing a complete semantic logic unit. This helps to accurately analyze the semantic information of the code segment, and also facilitates subsequent normalization processing and vectorization.
[0093] Illustratively, according to the logical unit range defined in the AST, the corresponding code segments are cut out from the first code, ensuring the integrity and independence of each segment. Each code segment is stored, along with metadata such as the starting position, ending position, and logical unit type of the segment.
[0094] Step S640, based on the metadata of each code segment, establish the association relationship between each code segment and the first code.
[0095] The association relationship includes the location information of the code segment in the first code.
[0096] Specifically, in order to track and understand the relationship between the code segment and the original code, the system establishes an association relationship for each code segment, which contains the exact location of the code segment in the first code. This step ensures that even if the code is divided into multiple segments, the original position of each segment can be tracked, facilitating subsequent code adoption analysis and audit.
[0097] Exemplarily, metadata is recorded for each code snippet, including the starting line, ending line of the code snippet in the first code, the file path it belongs to, and possibly the function or class name. While storing each code snippet, an association database or data structure is established to record the association of the snippet with the first code, facilitating subsequent retrieval and analysis.
[0098] In the present embodiment, by loading the parser specific to the programming language and generating the AST, the system is able to understand the logical structure of the code more deeply, laying a solid foundation for subsequent code snippet segmentation, thereby improving the depth of code understanding and analysis. Based on the logical structure indicated by the AST, the system determines the semantic logical range in the code, ensuring that each code snippet contains complete semantic information rather than arbitrary code snippets, which improves the accuracy and effectiveness of subsequent code processing. By establishing the association of each code snippet with the first code, the system is able to trace the original location of the code snippet, which is crucial for code adoption analysis, ensuring accurate identification and complete tracing of adoption, avoiding misjudgment and omissions in code adoption analysis. Thus, the depth and efficiency of code understanding and processing are improved, and the accuracy and tracing ability of code adoption analysis are significantly enhanced.
[0099] In one embodiment, as shown in FIG. 7, after the first code is parsed by the parser to generate an abstract syntax tree corresponding to the first code in step S610, the method further includes steps S700-S720: Figure 7
[0100] Step S700, in the case where it is determined that the parser fails to parse the first code, the location of the blank line in the first code is determined.
[0101] Specifically, when the standard code parser fails to correctly parse the first code, it indicates that the code may have syntax errors or format abnormalities. In order to avoid completely giving up the analysis of this part of the code, the system changes to find and use the location of the blank line in the code as the segmentation point. The reason for this is that in most programming languages, blank lines are usually used to separate different logical parts of the code, and using them as segmentation points can help the system to restore the logical structure of the code as much as possible, even in the case of syntax errors or format chaos.
[0102] Exemplarily, the location of the blank line in the code can be detected using regular expressions or string operation functions. Then all the found blank line locations are recorded as reference points for subsequent code segmentation.
[0103] Step S710, the location of the blank line in the first code is used as a segmentation position to segment the first code into multiple code snippets.
[0104] Specifically, once the empty line positions in the first code are determined, the system will split the first code into multiple smaller code segments according to these positions. Each segment is a relatively independent block of code that retains partial semantic information, although it may contain syntax errors or formatting disorders, for subsequent processing.
[0105] Illustratively, based on the recorded empty line positions, multiple code segments are generated using string slicing functions. These code segments are stored, along with the starting and ending positions of each segment and possible context information, to prepare for subsequent analysis.
[0106] Alternatively, in step S720, in the case where the parser fails to parse the first code, the first code is split into multiple code segments using a sliding window approach with a preset number of lines, and each code segment has a number of lines less than or equal to the preset number of lines.
[0107] Specifically, as an alternative strategy, when the parser fails to parse the first code and cannot reliably use empty line positions for splitting, the system will use a fixed number of lines as a window for sliding code splitting. This method ensures that even in the case of complex code structure or a large number of continuous logic, it can generate code segments suitable for processing, although it may result in discontinuity of logic between segments, but in the case where more accurate splitting cannot be performed, it is an effective means to ensure data availability.
[0108] Illustratively, a reasonable line threshold, such as 50 lines, is preset as the size of the sliding window. Starting from the first line of the first code, code segments are generated according to the preset line threshold, and then the window is moved to continue generating subsequent segments until the entire code is covered.
[0109] In this embodiment, by identifying and utilizing empty lines as splitting points, the system can still decompose the code and generate relatively independent code segments when encountering syntax errors or complex formatting of the first code, increasing the stability and robustness of the code processing flow. The sliding window splitting strategy provides a flexible way to generate processable code segments even when the code has no obvious logical separation, ensuring the system's data processing ability in various situations. After the parser fails to parse the first code, the above two alternative strategies are adopted to minimize the impact of parsing failure on the overall code processing flow, ensuring maximum utilization of data. Thus, when the standard code parsing method encounters obstacles, the system can still effectively process the first code through alternative code splitting strategies to generate code segments for subsequent analysis, not only improving the robustness and flexibility of the code processing flow, but also ensuring the comprehensiveness and accuracy of code adoption analysis, achieving more effective tracking and evaluation of code adoption in the software development process.
[0110] In one embodiment, the step S520 of normalizing the plurality of code snippets comprises:
[0111] removing comment information in the plurality of code snippets.
[0112] Specifically, although the comment information is helpful for understanding the intention of the code, it does not directly reflect the function or structure of the code in the code similarity comparison and semantic analysis. Therefore, the system removes the comment information in the code snippets, aiming to eliminate non-semantic differences and focus on the logical and structural features of the code.
[0113] and / or, removing leading and trailing white spaces of each line of code in the plurality of code snippets.
[0114] Specifically, white spaces (including spaces and tabs) are used for formatting and readability in the code, but do not participate in the function implementation of the code. Removing the leading and trailing white spaces of each line of code is to standardize the code format and avoid code similarity misjudgment caused by format differences.
[0115] and / or, replacing consecutive multiple space symbols in the plurality of code snippets with a single space symbol.
[0116] Specifically, in the code, consecutive multiple space symbols are usually used for alignment or formatting, but these are unnecessary in semantic analysis. Replacing consecutive spaces with a single space symbol can further standardize the code format and reduce the impact of format differences on similarity comparison.
[0117] and / or, replacing local variable names in the plurality of code snippets with preset format identifiers.
[0118] Specifically, the selection of local variable names may be influenced by the personal style of the developer, and has low correlation with the semantic information of the code. Replacing these variable names with uniform preset format identifiers can focus on the structure and algorithm logic of the code, improve the accuracy of code comparison, especially in the case of high code snippet similarity but different variable naming.
[0119] and / or, unifying the case format of letters in the plurality of code snippets.
[0120] Specifically, although in some programming languages, the case of keywords and function names has an impact on the function of the code, in most cases, the difference in case does not change the semantics of the code. Unifying the case format of letters can reduce unnecessary code differences and enhance the accuracy and efficiency of code comparison.
[0121] After the code snippet is normalized, an association between the code snippet before normalization and the code snippet after normalization is established.
[0122] Specifically, to ensure that subsequent analysis can trace back to the original code, the system needs to establish an association between the code snippet before normalization and the normalized code snippet after processing. This relationship records the changes of the code snippet during the normalization process, facilitating the restoration of the original state of the code in the adoption analysis, so as to accurately assess the adoption situation.
[0123] Exemplarily, the metadata of each code snippet can be recorded, including the original code text, the normalized code text, the variable name replacement record, the case conversion record, etc. In the code snippet database, an association entry is established for each normalized code snippet, containing the information of the original code snippet and the specific changes of the normalization processing, ensuring that the original code state can be accurately traced back in subsequent analysis.
[0124] In this embodiment, the standardization processing of removing comments and white spaces, and the unification of variable names and case, reduces the differences in code text format, enhances the similarity comparison between code snippets, and improves the accuracy of adoption analysis. The normalized code snippets are easier to process and vectorize, as they eliminate unnecessary format differences, simplify the input of the vectorization model, and improve the efficiency and quality of vectorization. Even in the case of inconsistent code formats, the system can ensure data consistency through normalization processing, enhancing the processing capability of complex or insufficiently formatted code snippets. By recording the code snippets before and after normalization and their changes, the system can accurately trace back to the original state of the code, which is crucial for fine-grained analysis and auditing of code adoption.
[0125] In one embodiment, as shown in Figure 8 Step S220, based on at least one candidate code vector, at least one second code pointed to by the at least one candidate code vector is extracted from the artificial intelligence code library. It includes steps S800-S820:
[0126] Step S800, the at least one candidate code vector is parsed to determine the metadata and code content corresponding to the at least one candidate code vector.
[0127] Specifically, after the similarity search, the system needs to decode the candidate code vector to restore the code snippet represented by these vectors and their accompanying metadata. This is to further analyze whether the code snippet is truly associated with the target code, and to provide detailed information for subsequent semantic similarity verification.
[0128] For example, candidate code vectors can be read from a vector database. Using the key stored in the database, metadata associated with the vector (such as programming language, file path, code generation time, user identifier (ID), etc.) and code text can be retrieved. The retrieved metadata and code text are reassembled to restore the original state and context of each candidate code snippet, ensuring the accuracy of subsequent analysis.
[0129] Step S810: Based on the metadata and code content, locate the code fragment pointed to by at least one candidate code vector in the artificial intelligence code library.
[0130] Specifically, using the metadata of the candidate code vector (e.g., file path, code ID), the system can accurately locate the corresponding code snippet in the AI code library. This step is the cornerstone for ensuring that subsequent analysis can compare with the correct code snippet.
[0131] Step S820: Construct at least one second code pointed to by at least one candidate code vector according to the code segment pointed to by at least one candidate code vector.
[0132] Specifically, the system needs to reorganize the located code snippets into a second code for the next step of semantic similarity verification. The second code should contain the complete content of all code snippets parsed from the candidate code vectors, so as to perform a comprehensive comparative analysis with the target code.
[0133] For example, based on the location information (e.g., line number, paragraph identifier) and code content of the located code snippets, they are reassembled according to the original code structure to generate secondary code. This ensures that the reassembled secondary code retains its original context in the source code repository, including file name, code generation time, and possible comments, to maintain code integrity and traceability.
[0134] In this embodiment, by parsing candidate code vectors and locating specific code snippets, the system can accurately compare code based on metadata and code content, avoiding the false positives and false negatives that can occur with simple matching methods based on text similarity. Leveraging code metadata, the system can trace the origins of each candidate code snippet, clarifying its relevance to the target code and its adoption path, enabling precise code tracing. Locating and constructing a secondary code prepares for subsequent in-depth semantic analysis.
[0135] In one embodiment, Figure 9 As shown, in step S230, before inputting the first code and at least one second code into the large language model and determining the adoption of the first code for the at least one second code based on the output result of the large language model, the method further includes steps S900-S920:
[0136] Step S900, classifying the at least one second code according to a preset similarity threshold.
[0137] wherein the second code with a similarity to the first code greater than a first threshold belongs to a first class, the second code with a similarity to the first code less than or equal to the first threshold and greater than or equal to a second threshold belongs to a second class, and the second code with a similarity to the first code less than the second threshold belongs to a third class.
[0138] Specifically, the system classifies the second codes into three classes based on the similarity between the first code and the second codes, through a preset similarity threshold. Through the classification, the system can filter out the highly similar, moderately similar and dissimilar second codes, and provide a basis for subsequent matching decisions.
[0139] Exemplarily, the similarity score between the first code and the second code is calculated using cosine similarity or code-specific similarity metrics, such as metrics based on edit distance. Two thresholds are defined, with the first threshold being higher than the second threshold. For example, the first threshold is set to 0.8 and the second threshold is set to 0.3, indicating the boundary between highly similar and moderately similar. The second code with a similarity greater than the first threshold is classified into the first class (highly similar); the second code with a similarity less than or equal to the first threshold and greater than or equal to the second threshold is classified into the second class (moderately similar); and the second code with a similarity less than the second threshold is classified into the third class (dissimilar).
[0140] Step S910, in the case where the at least one second code belongs to the first class, determining that the first code adopts the at least one second code.
[0141] Specifically, when the similarity score of the second code exceeds the first threshold, the system automatically considers these code fragments as adopted by the first code, i.e., the first code obviously contains the logic or structure of the second code. This step is a preliminary judgment of the adoption decision, providing a candidate set for subsequent in-depth verification.
[0142] Exemplarily, if the similarity score of the second code is higher than the preset first threshold, the system automatically marks that the first code adopts the second code, records the adoption relationship and prepares for subsequent in-depth verification. The code adoption relationship database is updated, and the adoption relationship of the second code belonging to the first class with the first code is recorded in detail, including the adopted code fragment, the similarity score, etc.
[0143] Step S920, in the case where the at least one second code belongs to the third class, determining that the first code does not adopt the at least one second code.
[0144] Specifically, for second codes belonging to the third category, i.e., code snippets with a similarity score below the second threshold, the system determines that the first code does not adopt these second codes. This helps filter out code snippets that are irrelevant to the logical structure of the first code, avoiding unnecessary in-depth verification and analysis later.
[0145] For example, if the similarity score of the second code is lower than the second threshold, the system regards this part of the code fragment as not adopted and does not perform further in-depth verification.
[0146] In this embodiment, by classifying the second code according to a preset similarity threshold, the system can quickly eliminate code fragments that are irrelevant to the first code and focus on highly similar and moderately similar codes, thereby improving the efficiency and accuracy of adoption decisions. The classification mechanism effectively filters out a large number of dissimilar second codes, reduces the candidate set for deep verification, avoids unnecessary consumption of computing resources, and improves the overall operating efficiency of the system. Dividing the similarity into three categories can not only quickly mark obvious adoption situations, but also retain moderately similar second codes for further deep verification, support refined analysis of the degree of code adoption, and increase the depth and breadth of adoption analysis. Through preliminary classification, the system can allocate computing resources more reasonably and avoid wasting resources on irrelevant code fragments. This is especially important when processing large-scale code bases and helps improve the overall performance and resource utilization of the system.
[0147] In one embodiment, Figure 10 As shown, in step S230, the first code and at least one second code are input into the large language model, and the adoption of the first code for the at least one second code is determined based on the output result of the large language model. It includes: steps S1000-S1010:
[0148] Step S1000: When at least one second code belongs to the second category, the second code belonging to the second category is input into the large language model, and structured prompt words are used to instruct the large language model to perform semantic understanding of the first code and the second code to obtain the output result of the large language model.
[0149] Specifically, for secondary codes that have a moderate level of similarity to the primary code, the system leverages a large language model for in-depth semantic understanding and comparison. This is because traditional similarity calculations may not fully capture the logical and functional relationships between codes, especially after the secondary code has been modified, reorganized, or variables renamed. By providing structured prompts to the large language model, the system guides the model to understand the potential connections between the two code segments, resulting in more accurate adoption decisions.
[0150] Exemplarily, a specific prompt template can be designed for the large language model, which should contain the content of the first code and the second code, and possible metadata (such as the generation time of the code, the programming language, etc.), requiring the model to evaluate the semantic similarity and adoption possibility of the two pieces of code. The large language model is called, and the structured prompt is passed to the model; the model will return the evaluation results of the similarity and adoption of the two pieces of code, including the probability score of adoption or the explicit adoption or non-adoption judgment, and the logical analysis supporting the judgment.
[0151] In step S1010, in the case where the output result of the large language model is that the first code adopts at least one second code, it is determined that the first code adopts at least one second code.
[0152] Specifically, based on the output of the large language model, if the model judges that the first code adopts the second code, the system will formally confirm this adoption relationship. This step is the decisive link of the adoption analysis, which relies on the deep understanding and high-level reasoning ability of the large model, and can accurately judge whether the modified code substantially adopts the AI-generated code logic.
[0153] Exemplarily, the system analyzes the output result of the large language model, and if the model's judgment shows that adoption occurs, the system will record the adoption relationship as part of the final analysis. Update the adoption relationship database to record the adoption event, including the adopted second code segment, the evidence of adoption (such as the analysis text output by the model), the similarity score of the two pieces of code, etc.
[0154] In this embodiment, the introduction of the large language model significantly improves the system's understanding and judgment ability of the code adoption situation, especially for those code segments that have been modified, reorganized or variable renamed by developers, the adoption relationship with the first code can be more accurately evaluated. Through the deep semantic understanding of the large model, the system can not only recognize the surface similarity of the code, but also deeply analyze the adoption situation at the logic and function level, increasing the depth and breadth of the adoption analysis. In the adoption judgment of the second type of code segment, the output result of the large model becomes the basis for scientific decision-making, avoiding the possible misjudgment or omission of judgment by relying only on similarity calculation, and improving the rationality and credibility of the adoption decision. Although the calling of the large model may increase the computational overhead, since the second code of the second type has been screened once through similarity classification, the number of second codes is smaller, and the system can effectively control the scale of deep analysis to avoid excessive resource consumption, so as to ensure the analysis accuracy while not sacrificing the system running efficiency too much. The deep adoption analysis of the medium similarity code segments belonging to the second type is realized, so that the large language model is used for secondary judgment for the code segments with intermediate similarity and uncertain adoption relationship, balancing the calculation resources and the judgment effect.
[0155] In one embodiment, as shown in FIG. 1, the method further comprises steps S1100-S1140: Figure 11
[0156] Step S1100, collecting interaction data between the target object and the large language model.
[0157] The interaction data includes the artificial intelligence code generated by the large language model and the context content related to the artificial intelligence code.
[0158] Specifically, the system actively captures all interaction information between the target object (e.g., software developer) and the large language model. This includes but is not limited to code snippets generated by the large model based on the target object's request, the model's response text, and metadata related to each interaction, such as timestamps, context information, question content, etc. The purpose of collecting this information is to build a comprehensive and traceable artificial intelligence code library, ensuring that future analysis of code adoption can be based on detailed data.
[0159] Illustratively, by listening to the interaction interface (such as Application Programming Interface Invocation (API invocation), Integrated Development Environment Plug-in (IDE plug-in) communication records, etc.) between the target object and the large model, the code snippets and natural language descriptions generated by each interaction are collected in real time or periodically. During the collection process, ensure that each request (question text) and the corresponding response (including the generated code snippets and the model's additional explanation information) are bound with their interaction metadata (such as timestamp, user ID, dialogue turn), for later analysis.
[0160] Step S1110, parsing the interaction data to separate the artificial intelligence code and the natural language description in the interaction data.
[0161] Specifically, the system further processes the collected interaction data to separate the specific code snippets and accompanying natural language descriptions, laying the foundation for subsequent code analysis and metadata association. The separation process needs to identify the boundaries between code and text description, ensuring the integrity and accuracy of the information.
[0162] Illustratively, regular expressions or specialized code parsing libraries are used to identify code snippets and natural language descriptions in response text. The identified code snippets and natural language descriptions are separated and stored separately, while saving their relative positions in the original interaction text so that context information can be restored when needed later.
[0163] Step S1120, an association between the artificial intelligence code and the metadata corresponding to the interaction data is established.
[0164] The metadata corresponding to the interaction data at least includes identification information of the target object, a timestamp, a dialogue round, and a question text.
[0165] Specifically, for each piece of separated artificial intelligence code, the system records and associates the generated context metadata, including but not limited to the generator of the code (the identity of the target object), the time of code generation, and the specific text of the question. This is to track the generation background of each piece of code in subsequent code adoption analysis, ensuring the depth and accuracy of the analysis.
[0166] Illustratively, a unique identifier is generated for each piece of artificial intelligence code, and the relevant metadata (including question text, user ID, timestamp, dialogue round, etc.) is associated with the identifier. A metadata dictionary or database record is constructed, in which the identifier of each code segment corresponds to all its context information, facilitating later query and analysis.
[0167] Step S1130, the artificial intelligence code and the metadata corresponding to the interaction data are combined into a preset structured data.
[0168] Specifically, in order to facilitate management and analysis, the system integrates the artificial intelligence code and its metadata into a structured data format, such as using JavaScript Object Notation Object (JSON) representation or specific database records. This structured data format can be easily read and parsed by subsequent processing programs, ensuring data consistency and ease of use.
[0169] Illustratively, the artificial intelligence code and the corresponding metadata are encapsulated into a structured data structure, such as a JSON object, according to a preset rule. Ensure that each item of metadata has a corresponding key (Key) and value (Value), which is convenient for subsequent program access. The structured data is stored persistently, for example, written into a database, to ensure data security and long-term availability.
[0170] Step S1140, an artificial intelligence code library is constructed based on the structured data.
[0171] Specifically, the system constructs an artificial intelligence code library according to the processed and integrated structured data. This code library not only contains code segments, but also detailed metadata, providing a comprehensive data set for subsequent code adoption metrics and in-depth analysis.
[0172] Exemplarily, a database system suitable for storing structured data, such as a relational database, is designed or selected. The structured data is inserted into the code base in batches, ensuring that each code snippet and its metadata are stored correctly. At the same time, indexes or other data structures are established to optimize query performance, ensuring that the required code snippets and metadata can be quickly retrieved.
[0173] In this embodiment, by recording the context of each code generation in detail, including the question text, timestamp and dialogue round, the system can conduct in-depth analysis on the code adoption based on accurate background information, avoiding false positives or false negatives caused by relying solely on code text similarity calculation, greatly improving the accuracy and reliability of the analysis. The artificial intelligence code library constructed not only contains code snippets, but also integrates detailed metadata, establishing a clear record of the generation context for each code. This provides a valuable traceability path for code adoption analysis, helping to understand the evolution history and adoption mode of the code snippet. By integrating the code and metadata generated by the large language model into a structured data format, the system greatly simplifies the subsequent code adoption analysis process, making code search, comparison and correlation query more efficient and intuitive, reducing the complexity of data processing. Storing code and metadata in a structured data format not only facilitates data management and query, but also supports compatibility with various data processing and analysis tools, enhancing the scalability and adaptability of the system to the future. The artificial intelligence code library constructed provides a data basis for the system to evaluate the accuracy and performance of the adoption analysis algorithm. By regularly analyzing the adoption rate trends and algorithm performance, the system can continuously optimize parameters and strategies, forming a closed-loop optimization mechanism to continuously improve the efficiency and quality of adoption analysis.
[0174] In one embodiment, as shown in Figure 12 Step S1110, the interaction data is parsed to separate the artificial intelligence code and the natural language description in the interaction data. This includes steps S1200-S1220:
[0175] Step S1200, the interaction data is parsed to determine the multi-round dialogue between the target object and the large language model.
[0176] Specifically, the multi-round dialogue record between the target object and the large language model is identified and separated from the collected interaction data. This is because the interaction between the developer and the AI model is often not a single inquiry and response, but includes multiple exchanges, including questions, AI responses, further clarification or modification requests, etc. By parsing the multi-round dialogue, the system can more comprehensively understand the context and dynamic evolution process of each code generation task, which is crucial for subsequent code adoption measurement.
[0177] Exemplarily, using session tracking algorithms or time series analysis, the system identifies the conversation records that belong to different rounds of the same session. For example, if two consecutive questions and answers occur within a short period of time and involve the same or related issues, the system marks them as part of the same session. Based on the session ID, each group of conversation records is separated, and each session contains all relevant questions and answers, including the artificial intelligence code generated by the large language model.
[0178] Step S1210, information extraction is performed on the text content in the multi-round conversation to determine the metadata in the interaction data.
[0179] Specifically, metadata refers to data about data. For each group of interactions in the multi-round conversation, the system needs to extract relevant metadata, including but not limited to question time, answer time, questioner information, session ID, conversation round, etc. These metadata play a key role in tracing the context of code generation and understanding the generation background and change history of code snippets, and are important basis for subsequent code adoption analysis.
[0180] Exemplarily, regular expressions or other text analysis tools are used to extract key information from the conversation records. For example, by matching the timestamp format string, the sending time of each message is determined. Metadata tags such as question time, answer time, questioner ID, session ID, conversation round, etc. are attached to each group of conversation records to ensure that these information can be clearly recorded and traced.
[0181] Step S1220, code recognition is performed on the text content in the multi-round conversation to extract the large language model generated artificial intelligence code in the interaction data.
[0182] Specifically, in the text content of the multi-round conversation, the system needs to identify and extract code snippets generated by the large language model. This is the core output of the AI-based code generation function, which is crucial for subsequent code adoption metrics, code library construction, and code similarity analysis. Code recognition needs to accurately distinguish the boundary between code and natural language description, so as to facilitate independent processing and analysis of the code.
[0183] Exemplarily, using code block matching algorithms or regular expressions, the system identifies text blocks in the form of code from the conversation records, which are usually used as code examples or suggestions in the response. The identified code snippets are extracted from the text and formatted, such as removing unnecessary white spaces, comments, etc. to ensure the cleanliness and consistency of the code snippets, so as to facilitate subsequent semantic comparison and vectorization processing.
[0184] In this embodiment, through the recognition of multi-round dialogue and the extraction of metadata, the system can more meticulously analyze the dynamic changes in the code adoption process, understand the context before and after the generation of code snippets, and more accurately assess the actual adoption degree of AI code. Accurate recognition and extraction of artificial intelligence code from interaction data can ensure that the construction of the code library is comprehensive and efficient, and each code snippet can be accurately indexed, facilitating subsequent retrieval and analysis. The analysis of multi-round dialogue and detailed metadata records provide a solid foundation for code tracing, helping to trace the generation history of code snippets, understand the modifications and optimizations in the adoption process, and increase the transparency and credibility of code adoption metrics. The separation of code recognition and metadata extraction ensures the purity of code snippets and the richness of metadata, providing a clear data structure for subsequent code adoption metrics and similarity comparison, avoiding interference from non-code elements, and improving analysis accuracy and efficiency.
[0185] In one embodiment, as shown in FIG. 13, the method further includes steps S1300-S1340: Figure 13
[0186] Step S1300, configure the access credentials and access path of the target code repository.
[0187] The target code repository stores all the code managed by the version control system of the target server. The code repository is a place where project source code, documents, scripts, and version history are stored, usually hosted by a version control system (Global Information Tracker, Git). The code repository can include source code files, configuration files (requirements.txt, pom.xml, Docker file, etc.), test cases and scripts, documents (README, API documentation, design specifications), version history (commit records, branches, tags), and the like.
[0188] Specifically, the system administrator or automated tool needs to configure the relevant access information of the target code repository, including access credentials (such as username, password, API key, etc.) and access path, so that subsequent access and retrieval of all code data stored in the code repository can be achieved. This step is the basis for subsequent code submission record access and new code recognition, ensuring that the system can legally and smoothly access the information of the target code repository.
[0189] Exemplarily, the login credentials of the target code repository, including but not limited to the username and password, or the API key and authentication token, are input in the configuration file of the system to ensure that the system can access the code repository through authentication. The access path of the target code repository is set, which can be the uniform resource locator (URL) address of the repository or the network path of the repository in the internal deployment environment, to ensure that the system can accurately locate the target repository.
[0190] In step S1310, in response to the analysis request of the target object, the target code repository is accessed along the access path using the access credentials, and the commit records of the code of the version control system within the target time range are called.
[0191] The analysis request carries the target time range.
[0192] Specifically, when the target object initiates the analysis request, the system uses the previously configured access credentials and path to connect to the target code repository and call the commit records of the version control system (Git) within the specified time range. This operation ensures that the system can obtain the history information of all related code commits of the target object within the target time, which is the key to determining the new code and building the incremental code library subsequently.
[0193] Exemplarily, the system receives and parses the analysis request of the target object and identifies the target time range carried in the request. The code repository is logged in using the access credentials, and all commit records within the target time range are obtained by calling the version control system API. This can include submitter information, commit time, commit description, modified file list, and other metadata, as well as specific code change information.
[0194] In step S1320, according to the commit records of the code of the version control system within the target time range, a plurality of codes submitted by the target object within the target time range are determined.
[0195] Specifically, based on the obtained commit records, the system further analyzes the specific code submission of the target object within the target time range. This includes identifying all code files and code changes submitted by the target object, preparing data for further code similarity analysis.
[0196] Exemplarily, the commits initiated by the target object (or its team members) are filtered out from the commit records to ensure that only the code changes related to the target object are focused on. The specific code changes of each commit, including added, deleted, and modified code lines, are parsed from the commit records using the functions provided by the version control system, such as the git show or git diff commands of Git.
[0197] Step S1330, determine new code in the plurality of codes that has a similarity to the code stored in the target code repository that is below a predetermined degree.
[0198] Specifically, the system needs to identify and filter out those "new codes" that are submitted within the target time range and have a low similarity to the previously stored codes in the repository. This is to enable more accurate analysis of which codes are likely to be AI-generated or significantly influenced by AI in the future, as only new codes have a higher probability of matching AI-generated code snippets.
[0199] Illustratively, use code similarity algorithms (such as edit distance calculation based on Levenshtein distance, vector-based semantic similarity calculation) to compare the submitted code within the target time range with the existing code in the repository to determine the similarity. Set a threshold, for example, if the similarity score of a piece of code is below a certain preset value (such as 70%), it can be considered as "new code" and meet the subsequent analysis conditions.
[0200] Step S1340, build an incremental code base based on the new code and the metadata corresponding to the new code.
[0201] Among them, the first code is obtained from the incremental code base.
[0202] Specifically, the system constructs an incremental code base from the filtered new codes and their corresponding metadata (such as submitter, submission time, code change description, etc.). This library is the main data source for subsequent code adoption analysis. The first code, as the target code for analysis, will be selected from this incremental code base to evaluate its adoption relationship with AI-generated code.
[0203] Illustratively, design the data structure and storage format of the incremental code base to ensure efficient storage and retrieval of code snippets and their metadata. This can be a table database, a document database, or a customized data storage system. Store the new code and its metadata in the incremental code base according to the designed data structure, ensuring that each piece of code has its complete context information.
[0204] In this embodiment, by configuring access credentials and paths, the system can quickly connect to the target code repository, retrieve the submission records within the specified time range, avoid the tedious process of manually searching and screening the code, significantly improve the data acquisition speed, and lay a fast and accurate foundation for subsequent analysis. The screened new code (i.e., code with a similarity lower than the preset value compared with the existing code) is more likely to be a potential adopter of AI-generated code, which narrows the scope of subsequent analysis, improves the pertinence and accuracy of analysis, and reduces the possibility of misjudgment or omission. The constructed incremental code library not only contains new code but also integrates detailed metadata, providing rich contextual information for subsequent code adoption analysis, which helps to trace the evolution and adoption process of the code and increases the transparency and credibility of code adoption metrics. The construction of the incremental code library realizes the centralized management and efficient retrieval of new code, avoids repeated processing of all codes in the repository, reduces data processing time and computing resource consumption, and makes the code adoption analysis process more smooth and efficient. By configuring access credentials and paths, automatically obtaining the submission records within the target time range, screening new code and constructing an incremental code library, the system not only improves the efficiency and accuracy of code adoption analysis, but also enhances the code tracing capability and process optimization, ensuring data security and compliance.
[0205] In one embodiment, as shown in FIG. 13B, step S1330, determining new code in the plurality of codes with a similarity lower than a preset degree compared with the code stored in the target code repository. Includes steps S1400-S1430: Figure 14
[0206] Step S1400, analyzing the plurality of codes to determine the newly added code lines in the plurality of codes compared with the code stored in the target code repository.
[0207] Specifically, the system needs to analyze all the codes submitted by the target object and identify those completely new code lines compared with the previous code version in the target code repository. These newly added code lines are more likely to be the adopted part of the AI-generated code and are the focus of subsequent in-depth analysis. Mark these newly added code lines as "new code" for the next step.
[0208] For example, use a code difference analysis tool such as the git diff command of Git to compare the newly submitted code of the target object with the latest version of the same file in the target code repository to find the newly added lines. From the difference analysis results, all newly added lines are screened out, which do not appear in the previous code version and are considered as "new code".
[0209] Step S1410, taking the newly added code lines as new code.
[0210] Step S1420, analyze the plurality of codes to determine the modification degree of each of the plurality of codes compared to the stored codes in the target code repository.
[0211] Step S1430, the code in the plurality of codes with a modification degree greater than the preset degree is regarded as new code.
[0212] Specifically, in addition to identifying newly added code lines, the system also needs to evaluate the degree of code modification, especially those code segments that have undergone significant changes. This is because, although the code lines already exist in the repository, if the modification is large enough to significantly change the logic and function of the code, these code segments may also be affected by the AI-generated code. By setting a modification degree threshold, the system can filter out those code segments with high modification degree as "new code" for subsequent adoption metrics.
[0213] For example, the edit distance, Jaccard index, or more complex syntax tree difference metrics such as the change rate based on abstract syntax tree AST can be used to quantify the degree of code modification. A preset degree threshold is set, for example, if a code segment is modified by more than 30%, it is considered to have a large modification degree, which may involve the introduction of new concepts or functions. For those code segments with a modification degree exceeding the threshold, the system regards them as "new code", even if some parts of these segments are already recorded in the repository. Such a strategy can ensure that even if the code is significantly modified based on the original, it can be included in the analysis range of adoption metrics.
[0214] In this embodiment, by explicitly distinguishing between newly added code lines and code segments with large modification degrees, the system can more finely divide the objects of code adoption analysis, avoiding treating all modified code as "new code". This not only focuses on the true adoption part, but also avoids resource waste, improving the relevance and efficiency of adoption metrics. The quantitative evaluation of modification degree can help the system identify code segments that may introduce new logic or functions on the surface, ensuring the comprehensiveness and depth of subsequent adoption metric analysis, and improving the accuracy of analysis. By setting a preset threshold for modification degree, the system can flexibly adjust the analysis strategy according to different project requirements or code properties, such as in a project with frequent code refactoring, the modification degree threshold can be appropriately relaxed to cover more "new code", thereby supporting diverse adoption metric requirements. Finally, the parts marked as "new code" are more likely to represent the actual adoption of AI-generated code, as they are either completely new or have undergone significant changes, and can serve as more reliable and practical metric indicators, helping to evaluate the effectiveness of AI-assisted programming tools.
[0215] In one embodiment, as shown in Figure 15 The method further includes steps S1500-S1530:
[0216] Step S1500, in the case where it is determined that the first code has an adoption relationship with at least one second code, determining a third code in the at least one second code that has the highest similarity to the first code.
[0217] Specifically, when the system has confirmed that there is an adoption relationship between the first code and at least one second code (i.e., AI-generated code), the next task is to find the second code that has the highest similarity to the first code, and mark it as the third code. The purpose of this operation is to accurately locate the specific content of the adoption, which helps subsequent calculation of the adoption amount and analysis of the adoption degree.
[0218] Illustratively, all second codes that are confirmed to have an adoption relationship can be sorted according to the similarity score calculated by the similarity. The second code that is selected as the third code is the one that is ranked first after sorting, which means that this second code has the highest semantic similarity to the first code. From the sorted results, the second code fragment that has the highest similarity to the first code is extracted as the third code for subsequent adoption amount calculation.
[0219] Step S1510, determining the adoption amount of the first code to the third code generated by artificial intelligence according to the similarity between the first code and the third code.
[0220] Specifically, after the third code is determined, the system needs to calculate the amount of the first code adopting the third code according to the specific similarity between the first code and the third code. The adoption amount here can refer to the number of lines, characters, or logical units of the adopted code, depending on the granularity and requirements of the analysis.
[0221] Illustratively, based on the similarity between the third code and the first code, the adoption amount can be calculated in various ways. For example, if the similarity is based on the number of code lines, then the adoption amount is the number of lines in the first code that match the third code. A more advanced calculation method can be based on the logical unit matching of the abstract syntax tree (AST), which calculates which function, class, or method fragment is adopted, and this calculation method can better reflect the adoption degree at the code logic level.
[0222] Step S1520, counting the total amount of new code in the incremental code base within a preset analysis period and the total adoption amount of the new code to the code generated by artificial intelligence.
[0223] Specifically, the system needs to count all new code (i.e., newly added code or significantly modified code in the incremental code base) within the entire preset analysis period, while calculating the total amount of AI-generated code adopted by these new codes, which provides the necessary data basis for subsequent adoption rate calculation.
[0224] Illustratively, a preset analysis period is set, which can be one day, one week, one month, or any custom time period. Traverse the incremental code base to count the total amount of all new code within the analysis period, and the total number of lines or logical units of AI code adopted in these new codes.
[0225] Step S1530, according to the total amount of new code and the total amount of AI-generated code adopted by new code, determine the adoption rate of new code for AI-generated code.
[0226] Specifically, based on the data counted in the first three steps, the adoption rate is calculated, which is a key metric reflecting how much proportion of the total new code is directly adopted or significantly affected by AI code.
[0227] Illustratively, the basic formula for calculating the adoption rate is (total adoption amount / total new code amount) * 100%. The total adoption amount and the total new code amount counted in step S1520 are brought into the formula, and the adoption rate is obtained.
[0228] Adoption rate output: after the system calculates the adoption rate, the result is output, which may be displayed in the form of a graphical report, or called by other systems through API, to facilitate the management team to intuitively understand the contribution of AI-generated code in software development.
[0229] In this embodiment, the system can accurately locate the specific content of the adoption by identifying the highest similarity code fragment in the adoption relationship, and further calculate the adoption rate based on the statistics of the total amount and the amount of adoption. This method based on deep comparison and quantitative statistics significantly improves the accuracy of analysis and the scientificity of results. The system not only can calculate the total number of lines or characters of adoption, but also can calculate the amount of adoption based on logical units (such as functions, classes), which provides a more detailed adoption measurement perspective. Through automated statistics and adoption rate calculation, the system avoids the tediousness of manual analysis, reduces errors in the analysis process, and makes the evaluation of code adoption degree more efficient and standardized. As a key metric, the adoption rate can provide a visual and quantitative AI code contribution for software development teams and management, which helps decision-making, such as evaluating the return on investment of AI-assisted programming tools, or optimizing the workflow of developers.
[0230] In one embodiment, as Figure 16As shown, the method further comprises steps S1600-S1620:
[0231] Step S1600, in the case where it is determined that the first code has an adoption relationship with at least one second code according to the adoption of the first code by the at least one second code, the first code is determined to be an adoption code.
[0232] Specifically, after analyzing and comparing the first code (the developer's submitted code snippet) and the second code (the AI-generated code snippet), if it is determined that the first code has obviously adopted part or all of the content of the second code, the system will mark the first code as an "adoption code". This is a sign of adoption relationship confirmation, meaning that part of the first code comes from or is significantly influenced by the second code.
[0233] Illustratively, based on the code similarity calculation result and the semantic verification of the large language model, if the similarity between the first code and the second code is higher than the preset threshold, and the model judges that there is an adoption relationship, the first code is marked as an adoption code at this time. The identification information of the adoption code is recorded in the adoption relationship library, including but not limited to the file name, the code snippet position, the version control submission ID, etc., so as to facilitate subsequent query and analysis.
[0234] Step S1610, querying the metadata of the first code as the adoption code in the incremental code library to obtain the provenance information of the first code as the adoption code.
[0235] The metadata of the first code includes the submission time of generating the first code and the identification information of the submitter.
[0236] Specifically, for the first code marked as an adoption code, the system needs to query its metadata from the incremental code library to obtain the submission time of the developer, the identification information of the submitter, etc., as the provenance head information of the adoption behavior. This helps to understand and track the adoption history of the code and confirm the time point and responsible subject of the adoption behavior.
[0237] Illustratively, through the database query function of the incremental code library, the identification information (such as file path, code snippet position) of the adoption code is used as the query key to obtain the corresponding metadata such as submission time and submitter ID. The queried metadata is integrated into the provenance information record of the adoption code to ensure that each adoption record is attached with complete context information.
[0238] Step S1620, querying the metadata of the second code adopted by the adoption code in the artificial intelligence code library to obtain the provenance information of the first code as the adoption code.
[0239] The metadata of the second code includes the dialogue text for generating the second code and the generation time.
[0240] Specifically, the system needs to query the metadata of the second code (adopted AI-generated code) from the artificial intelligence code library, including the text content of the generated dialogue, the generation time, etc., to further enrich the provenance information of the adopted code and ensure tracking to the original source of the AI-generated code.
[0241] Illustratively, the artificial intelligence code library is queried using the identification information of the second code (such as the corresponding inquiry ID or model response ID when the code is generated) to obtain the dialogue text, generation time, etc. The metadata of the second code is associated with the provenance information of the first code to form a complete adoption chain, including the time of the developer submitting the code, the submitter information, and the generation dialogue and generation time of the AI code.
[0242] In this embodiment, the system can provide detailed provenance information for each adoption behavior by explicitly marking the adopted code and extracting relevant metadata, including the generation time and generation background of the code snippet, the developer submission time and submitter information, etc., which greatly improves the transparency of adoption analysis and facilitates auditing or review by team members and management. The system not only relies on code similarity calculation, but also combines deep semantic verification of large language models to more accurately identify adoption behavior, avoiding false positives or false negatives that may occur with simple comparison, ensuring the accuracy of adoption analysis. By directly querying and integrating metadata after determining the adoption relationship, the system simplifies the adoption analysis process, avoids redundant queries and data processing, and improves analysis efficiency. The integrated provenance information not only includes the source of the code, but also covers the dialogue background of the generated code and the submission details of the developer, which helps to understand the generation process and adoption motivation of the adopted code. In summary, the method of this embodiment improves the transparency and accuracy of code adoption analysis, optimizes the analysis process, and strengthens the understanding and tracking ability of the adopted code.
[0243] In one embodiment, to ensure the continuous effectiveness and accuracy of the system, a set of evaluation and optimization methods can also be provided. Specifically, they include:
[0244] A gold standard verification dataset containing "first code (Git submission code) - second code (AI-generated code)" matching relationship (positive example) and non-matching relationship (negative example) is constructed through manual sampling annotation.
[0245] The dataset is updated and expanded regularly to cover more scenarios and edge cases.
[0246] The above method of the embodiment is used to determine the adoption on the verification data set, and the key performance indicators are calculated: precision: the proportion of the truly adopted AI code in the code determined by the system as adopted. Recall: the proportion of the truly adopted AI code identified by the system. F1 score: the harmonic mean of precision and recall.
[0247] The system can also periodically or randomly extract a part of the matching results (especially the results inconsistent with the LLM judgment result and the vector retrieval result (for example, the retrieval result is that the first code and the second code have an adoption relationship, but the LLM model output result is that the first code and the second code do not have an adoption relationship), or the similarity is in the fuzzy interval), which can be submitted to human auditors for review. Then collect the feedback of the auditors, and analyze the reasons for false positives (False Positives) and false negatives (False Negatives).
[0248] According to the evaluation results and human feedback, the key parameters in the system are adjusted, for example, including: code segmentation strategy and granularity. Similarity threshold of vector retrieval.
[0249] Then the prompt words of the LLM can be adjusted, and it can be evaluated whether the code embedding model and the LLM model need to be replaced or fine-tuned. Difficult cases or error cases are accumulated for improving the model or rules, and a closed loop of continuous optimization is formed.
[0250] In the embodiment, a system evaluation and model iterative optimization scheme is provided, which can evaluate the performance (accuracy, efficiency, etc.) of the system based on the analysis results of the system, and optimize the system based on the evaluation results to improve the accuracy of the adoption situation judgment.
[0251] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and the necessary general hardware platform, of course, it can also be realized by hardware, but in many cases the former is a better embodiment.
[0252] The embodiment of the present application also provides a code adoption situation determination device, Figure 17 is a structural block diagram of a code adoption situation determination device according to an embodiment of the present application, which comprises:
[0253] The vector conversion module 1701 is configured to, in the case where the first code submitted by the target object is acquired, extract semantic information in the first code, and generate a first code vector in a preset format corresponding to the first code based on the semantic information.
[0254] The retrieval module 1702 is configured to search in a pre-constructed vector database based on the first code vector to determine at least one candidate code vector in the vector database that meets a similarity threshold with the first code vector, where the vector database includes code vectors corresponding to respective codes in a preset artificial intelligence code library.
[0255] The extraction module 1703 is configured to extract, based on the at least one candidate code vector, at least one second code pointed to by the at least one candidate code vector from the artificial intelligence code library.
[0256] The adoption determination module 1704 is configured to input the first code and the at least one second code into a large language model, and determine, based on an output result of the large language model, an adoption of the first code with respect to the at least one second code, where the large language model is configured to perform semantic understanding on the codes to determine a similarity of the codes.
[0257] In an example embodiment, the retrieval module 1702 is further configured to construct a first vector index corresponding to the first code vector according to content of the first code vector and metadata corresponding to the first code. The retrieval is performed in the vector database according to the first vector index to determine a plurality of code vectors that meet a matching threshold with the first vector index, where the matching threshold between the plurality of code vectors and the first vector index is used to indicate a similarity between the plurality of code vectors and the first code vector. The code vectors in the plurality of code vectors that have a similarity greater than a first similarity threshold with the first code vector are taken as the candidate code vectors.
[0258] In an example embodiment, the vector conversion module 1701 is further configured to perform segmentation processing on the first code to segment the first code into a plurality of code segments. A preset semantic parsing model is used to perform semantic parsing on the plurality of code segments respectively to generate semantic vectors of a preset dimension corresponding to the plurality of code segments respectively, where the semantic parsing model is configured to capture a syntax structure in the code segments and parse semantic information of the code segments based on the syntax structure. The first code vector is generated by combining the semantic vectors of the preset dimension corresponding to the plurality of code segments respectively.
[0259] In an example embodiment, the vector conversion module 1701 is further configured to determine a programming language used by the first code according to feature information of the first code. The first code is segmented according to a corresponding segmentation strategy based on the programming language used by the first code to generate the plurality of code segments. The plurality of code segments are normalized to eliminate non-semantic information in the plurality of code segments and convert the plurality of code segments into a preset standard format.
[0260] In an example embodiment, the vector conversion module 1701 is further configured to load a corresponding parser according to a programming language used by the first code. The first code is parsed by the parser to generate an abstract syntax tree corresponding to the first code. Based on a logical structure of the first code indicated by the abstract syntax tree, a semantic logical range of the first code is determined. The first code is segmented based on the semantic logical range to divide the first code into a plurality of code segments, wherein each code segment includes a complete semantic logical range. An association relationship between each code segment and the first code is established based on metadata of each code segment respectively, wherein the association relationship includes position information of the code segment in the first code.
[0261] In an example embodiment, the apparatus further comprises:
[0262] The empty line determination module is configured to determine a position of an empty line in the first code in a case where the parser fails to parse the first code.
[0263] The first segmentation module is configured to take the position of the empty line in the first code as a segmentation position to segment the first code into a plurality of code segments.
[0264] The second segmentation module is configured to segment the first code into a plurality of code segments according to a preset number of lines in a case where the parser fails to parse the first code, wherein each code segment has a number of lines less than or equal to the preset number of lines.
[0265] In an example embodiment, the vector conversion module 1701 is further configured to remove comment information in the plurality of code segments. And / or, remove leading and trailing white spaces of each line of code in the plurality of code segments. And / or, replace a plurality of consecutive space symbols in the plurality of code segments with a single space symbol. And / or, replace local variable names in the plurality of code segments with identifiers in a preset format. And / or, unify the case format of letters in the plurality of code segments. Wherein, an association relationship between the code segment before the normalization processing and the code segment after the normalization processing is established after the code segment is normalized.
[0266] In an example embodiment, the extraction module 1703 is further configured to parse the at least one candidate code vector to determine metadata and code content corresponding to the at least one candidate code vector. Based on the metadata and the code content, a code segment pointed to by the at least one candidate code vector is located in the artificial intelligence code library. At least one second code pointed to by the at least one candidate code vector is constructed according to the code segment pointed to by the at least one candidate code vector.
[0267] In an example embodiment, the apparatus further comprises:
[0268] The classification module is configured to classify the at least one second code according to a preset similarity threshold, wherein the second code with a similarity to the first code greater than a first threshold belongs to a first category, the second code with a similarity to the first code less than or equal to the first threshold and greater than or equal to a second threshold belongs to a second category, and the second code with a similarity to the first code less than the second threshold belongs to a third category.
[0269] The adoption determination module is configured to determine that the first code adopts the at least one second code when the at least one second code belongs to the first category.
[0270] The non-adoption determination module is configured to determine that the first code does not adopt the at least one second code when the at least one second code belongs to the third category.
[0271] In an example embodiment, the adoption determination module 1704 is further configured to, when the at least one second code belongs to the second category, input the second code belonging to the second category into the large language model, instruct the large language model to perform semantic understanding on the first code and the second code by using a structured prompt word, and obtain an output result of the large language model. When the output result of the large language model is that the first code adopts the at least one second code, it is determined that the first code adopts the at least one second code.
[0272] In an example embodiment, the apparatus further comprises:
[0273] The data collection module is configured to collect interaction data between the target object and the large language model, wherein the interaction data includes artificial intelligence code generated by the large language model and context content related to the artificial intelligence code.
[0274] The data analysis module is configured to analyze the interaction data to separate the artificial intelligence code and the natural language description in the interaction data.
[0275] The relationship establishment module is configured to establish an association relationship between the artificial intelligence code and metadata corresponding to the interaction data, wherein the metadata corresponding to the interaction data at least includes identification information of the target object, a timestamp, a dialogue round, and a question text.
[0276] The combination module is configured to combine the artificial intelligence code and the metadata corresponding to the interaction data into preset structured data.
[0277] The first construction module is configured to construct an artificial intelligence code library based on the structured data.
[0278] In an example embodiment, the data parsing module is further configured to parse the interaction data to determine a multi-turn conversation between the target object and the large language model. Information extraction is performed on text content in the multi-turn conversation to determine metadata in the interaction data. Code recognition is performed on the text content in the multi-turn conversation to extract artificial intelligence code generated by the large language model in the interaction data.
[0279] In an example embodiment, the apparatus further comprises:
[0280] The configuration module is configured to configure access credentials and an access path of a target code repository, wherein the target code repository stores all codes managed by a version control system of a target server.
[0281] The access module is configured to, in response to an analysis request of the target object, access the target code repository along the access path using the access credentials, and call submission records of the codes of the version control system within a target time range, wherein the analysis request carries the target time range.
[0282] The range searching module is configured to determine, according to the submission records of the codes of the version control system within the target time range, a plurality of codes submitted by the target object within the target time range.
[0283] The code determining module is configured to determine, from the plurality of codes, new codes having a similarity lower than a preset degree to the codes already stored in the target code repository.
[0284] The second building module is configured to build an incremental code library based on the new codes and metadata corresponding to the new codes, wherein the first code is obtained from the incremental code library.
[0285] In an example embodiment, the code determining module is further configured to analyze the plurality of codes to determine new code lines in the plurality of codes compared to the codes already stored in the target code repository, and take the new code lines as the new codes. The plurality of codes are analyzed to determine modification degrees of the plurality of codes compared to the codes already stored in the target code repository, and take codes having a modification degree greater than a preset degree from the plurality of codes as the new codes.
[0286] In an example embodiment, the apparatus further comprises:
[0287] The similar code determining module is configured to, in a case where it is determined that the first code has an adoption relationship with at least one second code, determine a third code in the at least one second code having the highest similarity to the first code.
[0288] The adoption amount determining module is configured to determine, according to the similarity between the first code and the third code, an adoption amount of the first code to the third code generated by the artificial intelligence.
[0289] An adoption total amount determining module is configured to count a total amount of new codes in the incremental code base in a preset analysis period and an adoption total amount of the new codes for the AI-generated code.
[0290] An adoption rate determining module is configured to determine an adoption rate of the new codes for the AI-generated code according to the total amount of the new codes and the adoption total amount of the new codes for the AI-generated code.
[0291] In an example embodiment, the apparatus further includes:
[0292] An adoption code determining module is configured to determine the first code as an adoption code in a case where it is determined that the first code has an adoption relationship with the at least one second code according to the adoption of the first code for the at least one second code.
[0293] A first traceability module is configured to query metadata of the first code as the adoption code in the incremental code base to obtain traceability information of the first code as the adoption code, wherein the metadata of the first code includes a submission time of generating the first code and identification information of a submitter.
[0294] The first traceability module is configured to query metadata of the second code adopted by the adoption code in the AI code base to obtain the traceability information of the first code as the adoption code, wherein the metadata of the second code includes dialogue text of generating the second code and a generation time.
[0295] The features of the embodiments of the determination apparatus of the code adoption situation can be referred to the related descriptions of the embodiments of the determination method of the code adoption situation, which will not be repeated here.
[0296] Embodiments of the present application also provide an electronic device including a memory and a processor, the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any of the above-mentioned embodiments of the determination method of the code adoption situation.
[0297] Embodiments of the present application also provide a computer readable storage medium, which stores a computer program, wherein the computer program is configured to perform the steps in any of the above-mentioned embodiments of the determination method of the code adoption situation when running.
[0298] In an example embodiment, the above-mentioned computer readable storage medium can include but is not limited to: a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store computer programs.
[0299] The embodiment of the present application further provides a computer program product, the computer program product comprising a computer program, the computer program being executed by a processor to implement the steps in the code adoption condition determination method embodiment.
[0300] The embodiment of the present application further provides another computer program product, comprising a non-volatile computer readable storage medium, the non-volatile computer readable storage medium storing a computer program, the computer program being executed by a processor to implement the steps in the code adoption condition determination method embodiment.
[0301] Those skilled in the art can further understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized in electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been described in the above description in general terms. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0302] The above provides a code adoption condition determination method, device, electronic equipment, computer readable storage medium and computer program product. The principles and implementation modes of the present application are described in this paper. The above description of the embodiments is only used to help understand the method and its core idea. It should be pointed out that for those skilled in the art, without departing from the principles of the present application, some improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.
Claims
1. A method for determining code adoption, characterized in that: The method comprises: When a first code submitted by a target object is obtained, extracting semantic information from the first code, and generating a first code vector in a preset format corresponding to the first code based on the semantic information; Searching a pre-built vector database based on the first code vector to determine at least one candidate code vector in the vector database that meets a requirement for similarity to the first code vector, wherein the vector database includes code vectors corresponding to respective codes in a preset artificial intelligence code library; Based on the at least one candidate code vector, extracting at least one second code pointed to by the at least one candidate code vector in the artificial intelligence code library; classifying the at least one second code according to a preset similarity threshold, wherein a second code having a similarity with the first code less than or equal to the first threshold and greater than or equal to the second threshold belongs to the second category; The first code and at least one second code are input into a large language model, and the adoption of the at least one second code by the first code is determined based on the output of the large language model, wherein the large language model is used to perform semantic understanding of the codes to determine code similarity. If the at least one second code belongs to the second category, the second code belonging to the second category is input into the large language model, and a structured prompt word is used to instruct the large language model to perform semantic understanding of the first code and the second code to obtain the output of the large language model. If the output of the large language model is that the first code adopts the at least one second code, it is determined that the first code adopts the at least one second code.
2. The method for determining code adoption according to claim 1, wherein: The searching a pre-built vector database based on the first code vector to determine at least one candidate code vector in the vector database that meets a standard similarity with the first code vector includes: constructing a first vector index corresponding to the first code vector according to the content of the first code vector and metadata corresponding to the first code; Searching the vector database according to the first vector index to determine a plurality of code vectors that meet a matching degree requirement with the first vector index, wherein the matching degrees of the plurality of code vectors with the first vector index indicate similarities between the plurality of code vectors and the first code vector; A code vector among the multiple code vectors whose similarity to the first code vector is greater than a first similarity threshold is used as the candidate code vector.
3. The method for determining code adoption according to claim 1, wherein: The method of extracting semantic information from the first code submitted by the target object and generating a first code vector in a preset format corresponding to the first code based on the semantic information includes: performing segmentation processing on the first code to segment the first code into multiple code segments; Performing semantic parsing on the multiple code snippets respectively using a preset semantic parsing model to generate semantic vectors of preset dimensions corresponding to the multiple code snippets, wherein the semantic parsing model is used to capture the grammatical structure in the code snippets and parse the semantic information of the code snippets based on the grammatical structure; The first code vector is generated by combining semantic vectors of preset dimensions corresponding to the multiple code fragments.
4. The method for determining code adoption according to claim 3, wherein: The segmenting of the first code into a plurality of code segments includes: determining a programming language used by the first code according to feature information of the first code; Splitting the first code using a corresponding segmentation strategy according to the programming language used by the first code to generate multiple code fragments; Normalization is performed on the multiple code snippets to eliminate non-semantic information in the multiple code snippets and convert the multiple code snippets into a preset standard format.
5. The method for determining code adoption according to claim 4, wherein: The step of segmenting the first code using a corresponding segmentation strategy according to the programming language used by the first code to generate a plurality of code fragments includes: Loading a corresponding parser according to the programming language used by the first code; Parsing the first code using the parser to generate an abstract syntax tree corresponding to the first code; Determining multiple segments of semantic logic scope of the first code based on the logical structure of the first code indicated by the abstract syntax tree; Segmenting the first code based on the semantic logical scope to divide the first code into multiple code segments, wherein each of the code segments includes a complete semantic logical scope; Based on the metadata of each code snippet, an association relationship between each code snippet and the first code is established, wherein the association relationship includes location information of the code snippet in the first code.
6. The method for determining code adoption according to claim 5, wherein: After parsing the first code using the parser to generate an abstract syntax tree corresponding to the first code, the method further includes: If it is determined that the parser fails to parse the first code, determining a position of a blank line in the first code; Using blank line positions in the first code as segmentation positions to segment the first code into the multiple code segments; Alternatively, when it is determined that the parser fails to parse the first code, the first code is segmented in a sliding window manner according to a preset number of lines to segment the first code into multiple code fragments, and the number of lines of each code fragment is less than or equal to the preset number of lines.
7. The method for determining code adoption according to claim 3, wherein: The normalizing process of the plurality of code snippets includes: Removing comment information from the plurality of code snippets; and / or, removing leading and trailing whitespace characters from each line of code in the plurality of code snippets; and / or, replacing multiple consecutive space characters in the multiple code snippets with a single space character; and / or, replacing local variable names in the plurality of code snippets with identifiers in a preset format; and / or, unifying the uppercase and lowercase letters in the plurality of code snippets; After the code snippet is normalized, an association relationship is established between the code snippet before normalization and the code snippet after normalization.
8. The method for determining code adoption according to any one of claims 1 to 7, characterized in that: The extracting, from the artificial intelligence code library, at least one second code pointed to by the at least one candidate code vector based on the at least one candidate code vector includes: parsing the at least one candidate code vector to determine metadata and code content corresponding to the at least one candidate code vector; Locating, in the artificial intelligence code library, a code snippet pointed to by the at least one candidate code vector based on the metadata and the code content; At least one second code pointed to by the at least one candidate code vector is constructed according to the code segment pointed to by the at least one candidate code vector.
9. The method for determining code adoption according to any one of claims 1 to 7, characterized in that: Before inputting the first code and the at least one second code into the large language model and determining, based on an output result of the large language model, whether the first code is adopted for the at least one second code, the method further includes: classifying the at least one second code according to a preset similarity threshold, wherein a second code having a similarity with the first code greater than a first threshold belongs to a first category, and a second code having a similarity with the first code less than a second threshold belongs to a third category; In a case where the at least one second code belongs to the first category, determining that the first code adopts the at least one second code; In a case where the at least one second code belongs to the third category, it is determined that the first code does not adopt the at least one second code.
10. The method for determining code adoption according to any one of claims 1 to 7, characterized in that: The method further comprises: Collecting interaction data between the target object and the large language model, wherein the interaction data includes artificial intelligence code generated by the large language model and contextual content related to the artificial intelligence code; Parsing the interaction data to separate artificial intelligence code and natural language description in the interaction data; Establishing an association relationship between the artificial intelligence code and metadata corresponding to the interaction data, wherein the metadata corresponding to the interaction data includes at least identification information of the target object, a timestamp, a conversation turn, and a question text; Combining the artificial intelligence code and metadata corresponding to the interaction data into preset structured data; The artificial intelligence code library is constructed based on the structured data.
11. The method for determining code adoption according to claim 10, wherein: The parsing of the interaction data to separate the artificial intelligence code and the natural language description in the interaction data includes: Parsing the interaction data to determine multiple rounds of dialogue between the target object and the large language model; Extracting information from text content in the multiple rounds of conversations to determine metadata in the interaction data; Code recognition is performed on the text content in the multiple rounds of conversations to extract the artificial intelligence code generated by the large language model in the interaction data.
12. The method for determining code adoption according to any one of claims 1 to 7, characterized in that: The method further comprises: Configure access credentials and access paths for a target code repository, where the target code repository stores all code managed by the target server's version control system; In response to an analysis request for the target object, access the target code repository along the access path using the access credential, and call commit records of code in the version control system within a target time range, wherein the analysis request carries the target time range; Determining, based on the code submission records of the version control system within the target time range, multiple codes submitted by the target object within the target time range; Determining a new code among the plurality of codes whose similarity to the codes stored in the target code repository is lower than a preset level; An incremental code library is constructed based on the new code and metadata corresponding to the new code, wherein the first code is obtained from the incremental code library.
13. The method for determining code adoption according to claim 12, wherein: The determining of a new code among the plurality of codes whose similarity to the code stored in the target code repository is lower than a preset level includes: Analyzing the plurality of codes to determine new code lines in the plurality of codes compared to codes already stored in the target code repository; Using the newly added code line as the new code; Analyzing the plurality of codes to determine a modification degree of each of the plurality of codes compared to a code stored in the target code repository; The code whose modification degree is greater than a preset degree among the multiple codes is used as the new code.
14. The method for determining code adoption according to claim 12, wherein: The method further comprises: If it is determined that the first code has an adoption relationship with the at least one second code, determining a third code in the at least one second code that has the highest similarity to the first code; determining, based on a similarity between the first code and the third code, an adoption rate of the first code for the third code generated by artificial intelligence; Counting the total amount of new code in the incremental code base within a preset analysis period and the total amount of adoption of the new code for the AI-generated code; An adoption rate of the new code for the artificial intelligence-generated code is determined based on the total amount of the new code and the total amount of adoption of the new code for the artificial intelligence-generated code.
15. The method for determining code adoption according to claim 12, wherein: The method further comprises: If it is determined that the first code has an adoption relationship with the at least one second code according to the adoption status of the first code for the at least one second code, determining the first code as an adopted code; Querying metadata of the first code as the adopted code in the incremental code repository to obtain traceability information of the first code as the adopted code, wherein the metadata of the first code includes a submission time when the first code was generated and identification information of a submitter; The metadata of the second code adopted by the adopted code is queried in the artificial intelligence code library to obtain traceability information of the first code as the adopted code, wherein the metadata of the second code includes the dialogue text and generation time of generating the second code.
16. A device for determining code adoption, characterized in that: include: a vector conversion module, configured to, upon obtaining a first code submitted by a target object, extract semantic information from the first code and generate a first code vector in a preset format corresponding to the first code based on the semantic information; a retrieval module, configured to search a pre-built vector database based on the first code vector to determine at least one candidate code vector in the vector database that meets a requirement for similarity to the first code vector, wherein the vector database includes code vectors corresponding to respective codes in a preset artificial intelligence code library; an extraction module, configured to extract, from the artificial intelligence code library, at least one second code pointed to by the at least one candidate code vector based on the at least one candidate code vector; a classification module, configured to classify the at least one second code according to a preset similarity threshold, wherein a second code having a similarity with the first code that is less than or equal to the first threshold and greater than or equal to the second threshold belongs to the second category; An adoption determination module is configured to input the first code and at least one second code into a large language model, and determine, based on an output result of the large language model, whether the first code adopts the at least one second code. The large language model is configured to perform semantic understanding of the codes to determine code similarity. If the at least one second code belongs to the second category, the second code belonging to the second category is input into the large language model, and a structured prompt word is used to instruct the large language model to perform semantic understanding of the first and second codes to obtain an output result of the large language model. If the output result of the large language model indicates that the first code adopts the at least one second code, the module determines that the first code adopts the at least one second code.
17. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method according to any one of claims 1 to 15 when executing the computer program.
18. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method according to any one of claims 1 to 15 when executed by a processor.
19. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 15 are implemented.
Citation Information
Patent Citations
Document plagiarism judgment method and system based on semantic vector library and large language model
CN120234420A