An artificial intelligence-based adaptive code processing method and device, and an agent

By measuring the overall and fragment similarity of candidate code, and selecting code with lower similarity for cross-mutation, the problem of balancing diversity and performance optimization in code generation and optimization is solved, thus improving code generation efficiency.

CN120909565BActive Publication Date: 2026-02-06BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511430817.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-09
Publication Date
2026-02-06
Estimated Expiration
2045-10-09

AI Technical Summary

Technical Problem

In existing technologies, balancing the diversity of evolution schemes with search performance optimization has become a key bottleneck in the code generation and optimization process, resulting in low code generation efficiency.

Method used

By using an AI-based adaptive code processing method, a candidate code set is obtained, the overall and fragment similarity of each candidate code is measured, and the code with lower similarity is selected for cross-mutation. This process is repeated multiple times to generate a target code set that meets the requirements.

Benefits of technology

While ensuring the diversity of code evolution, it significantly improves code generation efficiency and enhances the effectiveness of automatic code generation, optimization, and repair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120909565B_ABST
    Figure CN120909565B_ABST
Patent Text Reader

Abstract

The disclosure provides an artificial intelligence-based adaptive code processing method and device and an intelligent agent, and relates to the technical field of artificial intelligence, in particular to the technical fields of intelligent agents, coding agents, auxiliary programming, large language models, deep learning, retrieval-enhanced generation, and the like. The specific implementation scheme is as follows: a candidate code set is obtained, wherein the candidate code set includes multiple candidate codes, first description information corresponding to each candidate code, and second description information corresponding to each segment in the candidate code; the similarity between each two candidate codes in the candidate code set is determined according to the multiple first description information and the multiple second description information; two candidate codes corresponding to a similarity less than a first threshold are subjected to cross mutation to obtain a new candidate code set; based on the new candidate code set, the step of determining the similarity is returned to be executed until a target code set meeting the requirements is obtained. Thus, the generation efficiency of the code is improved while the diversity of evolution is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of artificial intelligence, in particular to the technical field of agents, encoding agents, auxiliary programming, large language models, deep learning, retrieval enhanced generation, and the like, and specifically relates to an adaptive code processing method and device based on artificial intelligence and an agent. BACKGROUND

[0002] The automatic generation and optimization of code play an important role in improving development efficiency, reducing technical threshold, and improving code quality. The evolution of program candidate solutions usually depends on the crossover and mutation of code segments. How to balance the diversity of evolution schemes and performance optimization in search has become a key bottleneck restricting the development of the technology. SUMMARY

[0003] The present disclosure aims to at least partially solve one of the technical problems in the related art.

[0004] To this end, the present disclosure aims to provide an adaptive code processing method and device based on artificial intelligence and an agent. By measuring the similarity of the entire code and the segments in the code, the candidate code programs with low similarity are crossed, thereby ensuring the diversity of evolution while improving the generation efficiency of the code.

[0005] According to a first aspect of the present disclosure, an adaptive processing method based on artificial intelligence is provided, comprising:

[0006] obtaining a candidate code set, wherein the candidate code set includes a plurality of candidate codes, first description information corresponding to each candidate code, and second description information corresponding to each segment in the candidate code;

[0007] determining the similarity between each two candidate codes in the candidate code set according to a plurality of first description information and a plurality of second description information;

[0008] crossing and mutating two candidate codes corresponding to a similarity less than a first threshold to obtain a new candidate code set;

[0009] based on the new candidate code set, returning to the step of determining the similarity until a target code set meeting the requirements is obtained.

[0010] According to a second aspect of the present disclosure, an adaptive code processing device based on artificial intelligence is provided, comprising:

[0011] a first obtaining module configured to obtain a candidate code set, wherein the candidate code set includes a plurality of candidate codes, first description information corresponding to each candidate code, and second description information corresponding to each segment in the candidate code;

[0012] a first determining module configured to determine the similarity between each two candidate codes in the candidate code set according to the plurality of first description information and the plurality of second description information;

[0013] a first processing module configured to perform cross mutation on two candidate codes corresponding to a similarity less than a first threshold value to obtain a new candidate code set;

[0014] a second processing module configured to return to the step of determining the similarity based on the new candidate code set until a target code set meeting the requirement is obtained.

[0015] According to a third aspect of the present disclosure, an agent is provided, comprising:

[0016] an input module configured to receive a code to be processed and / or a code processing instruction;

[0017] a processing module configured to invoke a large model to execute the AI-based adaptive code processing method according to the first aspect to obtain a target code set based on the code to be processed and / or the code processing instruction;

[0018] an output module configured to output the target code set.

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

[0020] at least one processor; and

[0021] a memory communicatively connected to the at least one processor; wherein

[0022] the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the AI-based adaptive code processing method according to the first aspect.

[0023] According to a fifth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, and the computer instructions are used to enable the computer to execute the AI-based adaptive code processing method according to the first aspect.

[0024] According to a sixth aspect of the present disclosure, a computer program product is provided, comprising computer instructions for implementing the steps of the AI-based adaptive code processing method according to the first aspect when executed by a processor.

[0025] The AI-based adaptive code processing method, device and agent provided by the present disclosure have the following beneficial effects:

[0026] In the present disclosure, the similarity between each two candidate codes is measured according to the overall description information and the segment description information of each candidate code in the candidate code set, and then two candidate codes with smaller similarity are selected for crossover mutation to obtain a new candidate code set and recalculate the similarity. After multiple iterations, a target code set meeting the requirements is obtained, which can provide data reference for code automatic generation, optimization or repair, thereby improving the generation efficiency of the code while ensuring the diversity of evolution.

[0027] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the present disclosure, nor to limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS

[0028] The above described and / or additional aspects and advantages of the present disclosure will become apparent and easy to understand from the following description of the embodiments taken in conjunction with the following drawings, which serve to better understand the present scheme and do not constitute a limitation of the present disclosure, in which:

[0029] Figure 1 is a flow diagram of an adaptive code processing method based on artificial intelligence according to an embodiment of the present disclosure;

[0030] Figure 2 is a flow diagram of an adaptive code processing method based on artificial intelligence according to another embodiment of the present disclosure;

[0031] Figure 3 is a flow diagram of an adaptive code processing method based on artificial intelligence according to another embodiment of the present disclosure;

[0032] Figure 4 is a flow diagram of an adaptive code processing method based on artificial intelligence according to another embodiment of the present disclosure;

[0033] Figure 5 is a structural diagram of an adaptive code processing device based on artificial intelligence according to an embodiment of the present disclosure;

[0034] Figure 6 is a structural diagram of an intelligent agent according to an embodiment of the present disclosure;

[0035] Figure 7 shows a block diagram of an exemplary electronic device suitable for implementing the embodiments of the present disclosure. DETAILED DESCRIPTION

[0036] Exemplary embodiments of the present disclosure are described herein with reference to the accompanying drawings, which are included to provide a thorough understanding of embodiments of the present disclosure by individuals of ordinary skill in the art, and should not be construed as limiting the scope of the present disclosure. Accordingly, those of ordinary skill in the art will recognize various changes and modifications of the embodiments described herein, which do not depart from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted herein for clarity and conciseness.

[0037] Embodiments of the present disclosure relate to the field of artificial intelligence technologies such as agents, coding agents, programming assistance, large language models, deep learning, retrieval-augmented generation, etc.

[0038] Artificial Intelligence (AI) is a new technical science that studies and develops theories, methods, technologies, and application systems for simulating, extending, and expanding human intelligence. Artificial intelligence is a branch of computer science that aims to understand the essence of intelligence and produce a new intelligent machine that can react in a similar way to human intelligence.

[0039] An agent is a computer system or entity that can autonomously act, perceive the environment, make decisions, and interact with the environment. It usually has a large language model as the core decision and processing unit, and has the ability to independently think and call tools to gradually complete a given goal.

[0040] A coding agent is an artificial intelligence tool that can automatically perform programming tasks. It can understand natural language instructions and convert them into effective code snippets, thereby improving the efficiency of developers.

[0041] Programming assistance refers to a type of solution that provides support to developers at various stages of the software development life cycle through tools, techniques, or services, in order to reduce the difficulty of programming, reduce repetitive work, avoid errors, and improve development efficiency. It is not a complete replacement for manual programming, but rather a "collaborative partner" for developers, covering the entire process from code writing, debugging to maintenance, and is particularly suitable for solving repetitive tasks, syntax specifications, logic verification, etc.

[0042] A large language model (LLM) is a deep learning model trained on a large amount of text data, enabling the model to generate natural language text or understand the meaning of language text. These models can provide in-depth knowledge and language production on various topics by training on massive datasets. The core idea is to learn the patterns and structures of natural language through large-scale unsupervised training, to some extent, simulating the human language cognition and generation process.

[0043] Deep learning is the learning of the internal rules and representation levels of sample data, and the information obtained in the learning process is very helpful for the interpretation of data such as text, images and sound. The ultimate goal of deep learning is to enable machines to have analytical learning ability like humans, and to recognize text, images and sound data.

[0044] Retrieval-augmented Generation, or RAG for short. Retrieval-augmented generation models combine language models and information retrieval techniques. Specifically, when the model needs to generate text or answer questions, it will first retrieve relevant information from a large document set, and then use this retrieved information to guide the generation of text, thereby improving the quality and accuracy of predictions.

[0045] In the technical solutions of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the technical solutions comply with relevant laws and regulations and do not violate public order and good customs.

[0046] The AI-based adaptive code processing method, device and agent of the embodiments of the present disclosure are described below with reference to the accompanying drawings.

[0047] It should be noted that the execution subject of the AI-based adaptive code processing method of the present embodiment is an AI-based adaptive code processing device, which can be implemented by software and / or hardware. The device can be configured in an electronic device, which can include but is not limited to a terminal, a server, etc.

[0048] Figure 1 is a flowchart of the AI-based adaptive code processing method according to an embodiment of the present disclosure.

[0049] As shown in Figure 1 , the AI-based adaptive code processing method comprises:

[0050] S101: Obtain a candidate code set.

[0051] The candidate code set includes a plurality of candidate codes, first description information corresponding to each candidate code, and second description information corresponding to each segment in the candidate code.

[0052] The first description information can include any information describing the function, logic, and algorithm type of the code.

[0053] The second description information can include any information describing the algorithm, data structure, input data, and output data corresponding to the code segment.

[0054] In the embodiments of the present disclosure, the candidate code set can be obtained in different ways according to the needs of the user. For example, in the case of inputting a code for completion, optimization or repair, all solutions generated in the evolution process of the input code can be determined as candidate codes to obtain the candidate code set. Alternatively, the codes related to the user's needs can be queried from the historical code database as candidate codes to obtain the candidate set.

[0055] In the embodiments of the present disclosure, each candidate code can be represented as a plurality of code slices, and each slice can correspond to a solution to a sub-problem. Therefore, the second description information corresponding to the slice can be determined according to the algorithm, data structure, input data and output data of the sub-problem.

[0056] S102: Determine the similarity between any two candidate codes in the candidate code set according to the plurality of first description information and the plurality of second description information.

[0057] In the embodiments of the present disclosure, the first description information of any two candidate codes in the candidate code set can be used to measure the closeness between the two candidate codes in terms of functional objectives and overall strategies to determine the overall similarity. The second description information of the two candidate codes can be used to measure the local differences between the slices of the two candidate codes in terms of methods, data structures, input and output to determine the local similarity. Then, the similarities in the two aspects can be fused, such as addition or weighted summation, to obtain the similarity between the two candidate codes, so as to determine the similarity between any two candidate codes in the candidate code set.

[0058] S103: Cross and mutate the two candidate codes corresponding to the similarity less than the first threshold value to obtain a new candidate code set.

[0059] The first threshold value can be a threshold value dynamically set according to experience or actual needs. The first threshold value is small, and is used to screen the candidate codes with small similarity in the candidate code set.

[0060] In the embodiments of the present disclosure, after determining the similarity between any two candidate codes in the candidate code set, each similarity obtained is compared with the first threshold value. In the case that the similarity corresponding to the two candidate codes is less than the first threshold value, the two candidate codes are quite different in terms of function, logic and algorithm type. By cross-mutating the two candidate codes, such as recombining the code slices, a new code structure can be generated to obtain a new candidate code, which avoids being limited to a local optimal solution too early during processing. The set of new candidate codes obtained by cross-mutating the two candidate codes corresponding to the similarity less than the first threshold value is the new candidate code set.

[0061] In the embodiments of the present disclosure, the two candidate codes with small similarity are cross-mutated, which can expand the structural diversity of new candidate solutions and ensure the diversity of code processing.

[0062] In S104, based on the new candidate code set, the step of determining the similarity is returned to be executed until the target code set meeting the requirements is obtained.

[0063] In the embodiments of the present disclosure, after obtaining the new candidate code set, the candidate code set can be evaluated to determine whether the current candidate code set meets the requirements. For example, the quality of the candidate code set can be scored by using an evaluation tool. In a case where the quality score of the candidate code set is higher than a score threshold set by a user, the candidate code set is determined as the target code set meeting the requirements. Alternatively, other conditions for determining whether the candidate code set is the target code set can be set according to actual needs, and the present disclosure is not limited in this regard.

[0064] In the embodiments of the present disclosure, in a case where the new candidate code set obtained does not meet the requirements, the similarity between each two candidate codes in the candidate code set is recalculated, and then two candidate codes with a similarity less than a first threshold are selected for cross-mutation to obtain a new candidate code set. The iteration can be performed multiple times. In a case where the new candidate code set obtained in one iteration meets the requirements, the iteration is stopped, and the candidate code set is determined as the target code set.

[0065] In the embodiments of the present disclosure, after obtaining the target code set, the codes in the target code set can be used for code generation, code completion or optimization based on the task needs of a user, so that the efficiency and effect of code generation and optimization can be significantly improved.

[0066] In the embodiments, the similarity between each two candidate codes in the candidate code set is measured according to the overall description information and the segment description information of each candidate code, and then two candidate codes with small similarity are selected for cross-mutation to obtain a new candidate code set and recalculate the similarity. After multiple iterations, the target code set meeting the requirements is obtained. The target code set can provide data reference for code automatic generation, optimization or repair, so that the generation efficiency of the code can be improved while the diversity of evolution is ensured.

[0067] The adaptive code processing method based on artificial intelligence provided in the present disclosure can be applied to scenarios such as programming assistance, code automatic completion, code debugging and optimization, and automatic vulnerability repair and test case generation. For example, a developer can input part of a program in an integrated development environment (IDE), and obtain a target code set by using the code processing method, and recommend the target code set to the developer; or the user can input a code segment containing defects, obtain a target code functionally equivalent to the code segment but safer or more robust, and automatically replace or generate a repaired version to improve system security.

[0068] Figure 2 is a flowchart of the adaptive code processing method based on artificial intelligence provided in another embodiment of the present disclosure.

[0069] As shown in Figure 2 , the adaptive code processing method based on artificial intelligence comprises:

[0070] S201: Obtain a candidate code set.

[0071] The description of S201 can be specifically referred to the above embodiments, which will not be repeated here.

[0072] S202: Determine the global similarity between two candidate codes corresponding to each two first description information.

[0073] It should be noted that in the present disclosure, the global similarity measures the closeness of the candidate codes in the functional target and the overall strategy, which can also be referred to as overall similarity, semantic similarity, etc.

[0074] In the embodiments of the present disclosure, the global similarity between the candidate codes can be obtained by converting the first description information into a semantic vector and then calculating the cosine similarity, or by matching the keywords in the first description information and determining the global similarity between the candidate codes according to the matching ratio, or by using other calculation methods to determine the global similarity between the two candidate codes, etc. The present disclosure does not limit the comparison.

[0075] S203: Determine the local similarity between each two candidate codes based on the second description information corresponding to each segment in each two candidate codes.

[0076] It should be noted that in the present disclosure, the local similarity measures the local difference of the segments of the candidate codes in the method, data structure, input and output, such as the matching degree of the abstract syntax tree or the control flow graph, which can also be referred to as substructure similarity, etc.

[0077] In the embodiments of the present disclosure, the similarity between the two candidate codes can be obtained by converting the second description information into a semantic vector, then calculating the similarity between the segments by cosine similarity, and then fusing the similarity of all segments to obtain the local similarity between the two candidate codes, or other calculation methods can also be used to obtain the local similarity between the two candidate codes. The present disclosure does not limit the comparison.

[0078] S204: Fuse the global similarity and the local similarity to obtain the similarity between each two candidate codes.

[0079] In the embodiments of the present disclosure, the fusion manner of the global similarity and the local similarity can be direct addition or weighted summation according to certain weights.

[0080] For example, when the global similarity and the local similarity are weighted summed according to certain weights, the similarity between the two candidate codes can be represented by the following formula (1):

[0081] (1)

[0082] Wherein, denotes the similarity between the candidate code A and the candidate code B, denotes the local similarity between the candidate code A and the candidate code B, denotes the global similarity between the candidate code A and the candidate code B, is a weight proportion coefficient of the local similarity in the similarity, which can be self-defined according to experience or actual needs.

[0083] Optionally, when the similarity between any two candidate codes is greater than or equal to the first threshold value, and the local similarity between part of the segments in any two candidate codes is less than the second threshold value, the part of the segments in any two candidate codes is crossed and mutated to obtain new candidate codes.

[0084] Wherein, the second threshold value can be a threshold value dynamically set according to experience or actual needs. The second threshold value is smaller in value and is used to screen the segments with smaller similarity in the candidate codes. The second threshold value and the first threshold value are used to screen different targets. One candidate code, one segment of the candidate code, therefore, no specific size relationship is set between the second threshold value and the first threshold value.

[0085] In the embodiments of the present disclosure, when the similarity between any two candidate codes is greater than or equal to the first threshold value, it can be determined that the functions, logics, etc. of the two candidate codes as a whole are relatively similar. At this time, the segments with relatively low similarity in the candidate codes can be further determined. By crossing and mutating the segments, moderate differences can be introduced to avoid falling into local optimization.

[0086] It should be noted that in the embodiments of the present disclosure, the two candidate codes corresponding to the similarity less than the first threshold value can be cross-mutated, and the two candidate codes with the similarity greater than or equal to the first threshold value and the local similarity between the partial segments less than the second threshold value can be cross-mutated.

[0087] Alternatively, the candidate code set can be updated for a certain number of rounds after the two candidate codes corresponding to the similarity less than the first threshold value are cross-mutated, and the segment cross between the candidate codes is performed again when the similarity between all the candidate codes is greater than the first threshold value.

[0088] In the embodiments, by cross-mutating the segments with low local similarity between the two candidate codes in the case of high global similarity, new candidate codes can be obtained, moderate differences can be introduced, local optimization can be avoided, the diversity of the candidate codes can be maintained while ensuring rapid convergence, homogeneous codes can be avoided, and thus better solutions can be explored in complex problems.

[0089] S205: Cross-mutate the two candidate codes corresponding to the similarity less than the first threshold value to obtain a new candidate code set.

[0090] S206: Based on the new candidate code set, return to perform the step of determining the similarity until a target code set meeting the requirements is obtained.

[0091] The description of S205 and S206 can be specifically referred to the above embodiments, which will not be repeated here.

[0092] In the embodiments, by measuring the similarity between the candidate codes from the global and local perspectives, the target code determined based on the similarity not only guarantees the reliability of the syntax level, but also can match the user's requirements in the function and performance levels.

[0093] Figure 3 is a flowchart of an adaptive code processing method based on artificial intelligence according to another embodiment of the present disclosure.

[0094] As shown in Figure 3 , the adaptive code processing method based on artificial intelligence comprises:

[0095] S301: Obtain a candidate code set.

[0096] Optionally, the code generated in the evolution process of the received code to be processed can be determined as a candidate code.

[0097] The code to be processed refers to the code provided by the user and needs to be optimized or completed.

[0098] In the embodiments of the present disclosure, the to-be-processed code can be modified, optimized, extended, refactored, etc. during evolution, and all code versions generated by all operations can be determined as candidate codes, so that the candidate codes can reflect the context logic, problem solution, etc. in the historical evolution, thereby facilitating improvement of code quality.

[0099] Alternatively, the candidate code associated with the received code processing instruction can also be obtained from the reference code library.

[0100] The reference code library can be a database storing historical codes.

[0101] In the embodiments of the present disclosure, each reference code in the reference code library can correspond to different functions or algorithm types, etc. The user can send the code processing quality to explicitly express the demand (such as what function code is needed, what use is, etc.), so that at least one candidate code associated with the received code processing instruction can be obtained from the reference code library, and a candidate code set is obtained.

[0102] In the embodiments, the candidate code can be obtained in multiple ways, which can be suitable for different task scenarios and improve the adaptability of code processing.

[0103] S302: Determine the similarity between each two candidate codes in the candidate code set according to the plurality of first description information and the plurality of second description information.

[0104] The description of S301 and S302 can be specifically referred to the above embodiments, which will not be repeated here.

[0105] S303: Cross mutation of the two candidate codes corresponding to the similarity less than the first threshold value is performed to obtain a new candidate code.

[0106] In the embodiments of the present disclosure, after determining the similarity between each two candidate codes in the candidate code set, each obtained similarity can be compared with the first threshold value. In the case that the similarity corresponding to the two candidate codes is less than the first threshold value, the two candidate codes are quite different in function, logic, and algorithm type, etc. By cross mutation of the two candidate codes, such as recombination of code segments, a brand new code structure can be generated, and a new candidate code is obtained.

[0107] S304: Determine the update strategy of the candidate code set according to the type of the code processing instruction and / or the first parameter in the code processing instruction.

[0108] The update strategy is used to indicate the proportion, number, and / or screening condition of parent codes included in the new candidate code set. The parent code is a code used to generate a new candidate code by cross mutation.

[0109] In the embodiments of the present disclosure, since the final obtained code has different effects due to different types of code processing instructions, different update strategies can be adopted. For example, if the target of the code processing instruction is to generate a brand-new logic code, the parent code can be discarded in the update strategy. However, if the target is to generate more optimized code on the basis of the existing framework, the parent code can be retained in the update strategy. Alternatively, if the code processing instruction is to optimize the code, part of the parent code can be retained to avoid losing excellent solutions in the parent code.

[0110] It should be noted that in the embodiments of the present disclosure, the user can also directly input the number or proportion of the parent code to be retained during the update of the candidate code set during use.

[0111] In the embodiments of the present disclosure, the user can also directly input the number or proportion of the parent code to be retained during the update of the candidate code set during use, that is, the first parameter in the code processing instruction. Thus, the update strategy of the candidate code set can be determined according to the first parameter in the code processing instruction.

[0112] In the present disclosure, the type of the code processing instruction and the first parameter in the code processing instruction can be combined to determine the update strategy of the candidate code set.

[0113] S305: Obtaining the target parent code from the candidate code set based on the update strategy.

[0114] In the embodiments of the present disclosure, the target parent code can be determined from the plurality of candidate codes for cross variation according to the proportion or number of the parent code indicated in the update strategy and / or the screening condition of the parent code.

[0115] S306: Determining the new candidate code and the target parent code as a new candidate code set.

[0116] In the embodiments of the present disclosure, by putting the parent code into the new set when generating the new code set through cross variation, the stability and diversity in the code evolution process can be maintained, the optimal solution can be retained, and valuable information can be avoided from being lost due to excessive intergenerational replacement.

[0117] S307: Based on the new candidate code set, returning to the step of determining the similarity until the target code set meeting the requirement is obtained.

[0118] The description of S307 can be specifically referred to the above embodiments, and will not be described here.

[0119] Figure 4 is a flowchart of an adaptive code processing method based on artificial intelligence according to another embodiment of the present disclosure.

[0120] AsFigure 4 The AI-based adaptive code processing method shown includes:

[0121] S401: In the case where the evaluation service in the system is in the selected state, or in the case where the received code processing instruction indicates to call the evaluation service, the evaluation service is called based on the new candidate code set to obtain the evaluation result output by the evaluation service.

[0122] The evaluation result includes the evaluation value of the candidate code and / or the to-be-updated segment in the candidate code.

[0123] In the embodiments of the present disclosure, in the case where the evaluation service in the system is in the selected state, or in the case where the received code processing instruction indicates to call the evaluation service, the evaluation service can be called to utilize the expert knowledge in the evaluation service to provide feedback from the global and local aspects to obtain the evaluation result.

[0124] In the embodiments of the present disclosure, the evaluation service can score each candidate code to obtain the evaluation value, thereby evaluating the overall optimization potential of the new candidate code set, which is used to filter the candidate codes that can be retained or eliminated in the candidate code set, for example, the corresponding candidate code is retained if the evaluation value is high, and the candidate code is deleted from the candidate code set if the evaluation value is lower than a certain value. Alternatively, the evaluation service can also evaluate the segments in each candidate code to accurately locate the segments that need to be replaced or adjusted, and determine the to-be-updated segments in the candidate code. Moreover, the evaluation value of each candidate code can also be obtained, and the to-be-updated segments therein can also be determined.

[0125] S402: Update the new candidate code set based on the evaluation result.

[0126] In the embodiments of the present disclosure, after obtaining the evaluation result, each candidate code can be deleted or retained, and the segments in the candidate code can be replaced or adjusted based on the evaluation result, so as to complete the update of the new candidate code set.

[0127] In the embodiments, by utilizing the feedback of the evaluation service to drive the adaptive editing strategy, the redundant candidate solutions caused by blind search can be significantly reduced, the convergence speed can be accelerated, and the response efficiency of the product and the user experience can be improved.

[0128] Optionally, when updating the new candidate code set, at least one of the following can be included: deleting the candidate code in the new candidate code set whose evaluation value is less than an evaluation threshold; updating the to-be-updated segment in the candidate code to obtain a new candidate code.

[0129] The evaluation threshold can also be a value set according to experience or actual demand, which is not limited in the present disclosure.

[0130] In the embodiments of the present disclosure, the candidate code set is updated from the overall and local two angles, which can improve the accuracy of code processing and improve the quality of code generation.

[0131] Optionally, when updating the to-be-updated segment in the candidate code, the similarity between the second description information of the to-be-updated segment and the third description information of each code segment in the gene pool can be determined, and then the target segment or the target parent code containing the target segment can be obtained from the gene pool based on the similarity. Then, the to-be-updated segment can be updated by using the target segment or the target parent code to obtain a new candidate code.

[0132] In the embodiments of the present disclosure, the gene pool of the code segment can be constructed based on the vector database, and the high-quality segments and their feature indexes such as the third description information are stored. Therefore, the retrieval augmented generation (RAG) technology can be used to obtain the target segment or the target parent code in the gene pool, and the to-be-updated segment is cross-enhanced or mutation-enhanced to update the to-be-updated segment to obtain a new candidate code. The cross-enhancement can provide additional parent code or segment for the candidate code, and improve the diversity of cross. The mutation-enhancement can provide a target segment with similar function but better performance at the feedback-located segment position, and reduce the invalid search space.

[0133] In the embodiments of the present disclosure, when updating the to-be-updated segment, the to-be-updated segment can be directly replaced, or the to-be-updated segment can be crossed with the target segment or the target parent code, and the to-be-updated segment is replaced based on the cross result to obtain a new candidate code.

[0134] In the embodiments of the present disclosure, by obtaining high-quality segments in the gene pool and adding them to the evolution process of the candidate code, and eliminating low-quality or redundant segments, it is ensured that the updated candidate code is more representative and the code processing is more efficient.

[0135] Optionally, when obtaining the target parent code from the gene pool, the target segment or the target parent code containing the target segment can be obtained from the gene pool based on the control signal and the similarity in the case that the control signal is received. The control signal is used to indicate the retrieval logic and / or the number of retrieval results.

[0136] The retrieval logic can be semantic similarity retrieval, functional similarity retrieval, target algorithm retrieval, etc.

[0137] The number of retrieval results is used to indicate how many target segments or target parent codes containing the target segments are obtained to update the candidate code.

[0138] In the embodiments of the present disclosure, the logic for retrieving the gene pool and the data amount for updating the candidate code are dynamically adjusted by receiving the control signal, so that the user can autonomously adjust the updating process of the candidate code, and the code updating result can be ensured to be more in line with the user's demand, thereby optimizing the use experience.

[0139] Optionally, the index corresponding to the candidate code can also be determined according to the first description information and / or the second description information associated with the candidate code whose evaluation value is greater than the evaluation threshold. Then the candidate code and the index are associated and stored in the gene pool.

[0140] In the embodiments of the present disclosure, by using the dynamic updating mechanism for the gene pool, the system can continuously accumulate and screen high-quality fragments during the running process, form a continuous improvement positive feedback loop, and make the product more and more intelligent over time.

[0141] Figure 5 FIG. 1 is a structural schematic diagram of an adaptive code processing device based on artificial intelligence according to an embodiment of the present disclosure.

[0142] As shown in FIG. 1, the adaptive code processing device 50 based on artificial intelligence includes: Figure 5

[0143] The first obtaining module 501 is configured to obtain a candidate code set, wherein the candidate code set includes a plurality of candidate codes, first description information corresponding to each candidate code, and second description information corresponding to each fragment in the candidate code.

[0144] The first determining module 502 is configured to determine the similarity between each two candidate codes in the candidate code set according to the plurality of first description information and the plurality of second description information.

[0145] The first processing module 503 is configured to cross and mutate the two candidate codes corresponding to the similarity less than the first threshold value to obtain a new candidate code set.

[0146] The second processing module 504 is configured to return to the step of determining the similarity based on the new candidate code set until a target code set meeting the requirement is obtained.

[0147] Optionally, the first determining module 502 can be specifically configured to:

[0148] determine the global similarity between the two candidate codes corresponding to each two first description information;

[0149] determine the local similarity between each two candidate codes based on the second description information corresponding to each fragment in the two candidate codes;

[0150] fuse the global similarity and the local similarity to obtain the similarity between each two candidate codes.​

[0151] Optionally, the first processing module 503 can be further configured to:

[0152] If the similarity between any two candidate codes is greater than or equal to the first threshold value, and the local similarity between the partial fragments in any two candidate codes is less than the second threshold value, the partial fragments in any two candidate codes are crossed and mutated to obtain a new candidate code.

[0153] Optionally, the first obtaining module 501 can be further configured to at least one of:

[0154] The code generated in the evolution process of the received to-be-processed code is determined as a candidate code.

[0155] The candidate code associated with the received code processing instruction is obtained from the reference code library.

[0156] Optionally, the first processing module 503 can be specifically configured to:

[0157] The two candidate codes corresponding to the similarity less than the first threshold value are crossed and mutated to obtain a new candidate code.

[0158] According to the type of the code processing instruction and / or the first parameter in the code processing instruction, an update strategy of the candidate code set is determined, wherein the update strategy is used to indicate the proportion, number, and / or screening condition of the parent code included in the new candidate code set.

[0159] Based on the update strategy, a target parent code is obtained from the candidate code set.

[0160] The new candidate code and the target parent code are determined as a new candidate code set.

[0161] Optionally, the first processing module 503 can be further configured to:

[0162] In a case where the evaluation service in the system is in a selected state, or in a case where the received code processing instruction indicates to call the evaluation service, the evaluation service is called based on the new candidate code set to obtain an evaluation result output by the evaluation service, wherein the evaluation result includes an evaluation value of the candidate code and / or a to-be-updated fragment in the candidate code.

[0163] Based on the evaluation result, the new candidate code set is updated.

[0164] Optionally, the first processing module 503 can be further configured to at least one of:

[0165] The candidate code in the new candidate code set whose evaluation value is less than an evaluation threshold value is deleted.

[0166] Update the segments in the candidate code that are to be updated to obtain new candidate code.

[0167] Optionally, the first processing module 503 may be used for:

[0168] Determine the similarity between the second description information of the fragment to be updated and the third description information of each code fragment in the gene pool;

[0169] Based on similarity, retrieve the target fragment or the target parent code containing the target fragment from the gene pool;

[0170] The target fragment or its parent code is used to update the fragment to be updated, resulting in new candidate code.

[0171] Optionally, the first processing module 503 may be used for:

[0172] Upon receiving a control signal, the target fragment or target parent code containing the target fragment is retrieved from the gene pool based on the control signal and similarity. The control signal is used to indicate the retrieval logic and / or the number of retrieval results.

[0173] Optionally, the first processing module 503 may also include at least one of the following:

[0174] The index corresponding to the candidate code is determined based on the first description information and / or the second description information associated with the candidate code whose evaluation value is greater than the evaluation threshold;

[0175] The candidate codes and their indexes are associated and stored in the gene pool.

[0176] It should be noted that the foregoing explanation of the AI-based adaptive code processing method also applies to the AI-based adaptive code processing device of this embodiment, and will not be repeated here.

[0177] In this embodiment, the similarity between any two candidate codes is measured based on the overall description information and fragment description information of each candidate code in the candidate code set. Then, two candidate codes with low similarity are selected for cross mutation to obtain a new candidate code set and the similarity is recalculated. After multiple iterations, a target code set that meets the requirements is obtained. The target code set can provide data reference for automatic code generation, optimization or repair, thereby improving the code generation efficiency while ensuring the diversity of evolution.

[0178] This disclosure also provides an intelligent agent. Figure 6 This is a schematic diagram of the structure of an intelligent agent proposed in an embodiment of this disclosure. Figure 6 As shown, the intelligent agent 60 may include an input module 601, a processing module 602, and an output module 603.

[0179] The input module 601 is used to receive the code to be processed and / or code processing instructions; the processing module 602 is used to call the large model to execute the artificial intelligence-based adaptive code processing method described in the above embodiments based on the code to be processed and / or code processing instructions received by the input module 601, so as to obtain the target code set; the output module 603 is used to output the target code set.

[0180] In this embodiment of the disclosure, the user invokes... Figure 5 The agent shown can obtain the target code set output by the agent by inputting only one of the information of the code to be processed and the code processing instructions. This provides data reference for automatic code generation, optimization or repair, assists users in programming, and improves work efficiency.

[0181] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0182] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0183] like Figure 7 As shown, device 700 includes a computing unit 701, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 702 or a computer program loaded into random access memory (RAM) 703 from storage unit 708. The RAM 703 may also store various programs and data required for the operation of device 700. The computing unit 701, ROM 702, and RAM 703 are interconnected via bus 704. Input / output (I / O) interface 705 is also connected to bus 704.

[0184] Multiple components in device 700 are connected to I / O interface 705, including: input unit 706, such as keyboard, mouse, etc.; output unit 707, such as various types of monitors, speakers, etc.; storage unit 708, such as disk, optical disk, etc.; and communication unit 709, such as network card, modem, wireless transceiver, etc. Communication unit 709 allows device 700 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0185] The computing unit 701 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as code processing methods. For example, in some embodiments, the code processing method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the code processing method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to execute code processing methods by any other suitable means (e.g., by means of firmware).

[0186] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0187] Program code for carrying out methods of the present disclosure can be written in any combination of one or more programming languages. The program code can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the program code, when executed by the processor or controller, produces the functions / operations specified in the flowcharts and / or block diagrams. The program code can be executed entirely on a machine, partially on a machine, partially on a machine as a stand-alone software package, partially on a machine and partially on a remote machine or entirely on a remote machine or server.

[0188] In the context of the present disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium will include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fibers, portable compact disc read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0189] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.

[0190] The systems and techniques described here can be implemented in a computing system that includes a back end component, e.g., as a data server, or that includes a middleware component, e.g., an application server, or that includes a front end component, e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here, or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication, e.g., a communication network. Examples of communication networks include a local area network (LAN), a wide area network (WAN), the Internet, and a blockchain network.

[0191] The computer system can include clients and servers. The clients and servers are generally remote from each other and typically interact through a communication network. The relationship of client and server can arise by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also known as cloud computing server or cloud host, which is a host product in the cloud computing service system, to solve the defects of large management difficulty and weak business scalability in traditional physical host and VPS service ("Virtual Private Server", or simply "VPS"). The server can also be a server of a distributed system, or a server combined with a blockchain.

[0192] It should be understood that various forms of flow shown above can be used with reordering, additions, or removals of steps. For example, steps recited in the disclosure can be executed in parallel, in serial, or in different orders, unless otherwise specifically noted in the disclosure, and are not limited herein.

[0193] In addition, the terms "first", "second", etc., are used herein only to describe various steps in a method, process, or algorithm, and are not construed as indicating or implying relative importance or a required order of steps. Thus, features defined with "first", "second", etc., can include at least one of the features, explicitly or implicitly. In the description of the disclosure, the meaning of "a plurality of" is at least two, for example, two, three, etc., unless otherwise specifically limited. In the description of the disclosure, the word "if" can be interpreted as "when" or "upon" or "in response to determining" or "in the case of".

[0194] The above detailed description does not limit the scope of the disclosure. Various modifications, combinations, sub-combinations and alternatives can be made to the detailed description. Any modification, equivalent replacement and improvement etc. made within the spirit and principle of the disclosure shall be included in the scope of the disclosure.

Claims

1. An artificial intelligence-based adaptive code processing method, comprising: obtaining a candidate code set, wherein the candidate code set comprises a plurality of candidate codes, first description information corresponding to each of the candidate codes, and second description information corresponding to each segment in the candidate codes, the first description information being information for describing the function, logic and algorithm type of the candidate code, and the second description information being information for describing the algorithm, data structure, input data and output data corresponding to each segment in the candidate code; determining the global similarity between two candidate codes corresponding to each two first description information; determining the local similarity between each two candidate codes based on the second description information corresponding to each segment in each two candidate codes; fusing the global similarity and the local similarity to obtain the similarity between each two candidate codes; crossing and mutating two candidate codes corresponding to a similarity less than a first threshold to obtain a new candidate code set; based on the new candidate code set, returning to the step of determining the similarity until a target code set meeting the requirements is obtained.

2. The method of claim 1, wherein, After obtaining the similarity between each two candidate codes, further comprising: crossing and mutating part of the segments in any two candidate codes with a similarity greater than or equal to the first threshold and a local similarity less than a second threshold to obtain a new candidate code.

3. The method of claim 1, wherein, The obtaining of the candidate code set comprises at least one of the following: determining the code generated in the evolution process of the received code to be processed as the candidate code; obtaining the candidate code associated with the received code processing instruction from the reference code library.

4. The method of claim 3, wherein, The crossing and mutating of two candidate codes corresponding to a similarity less than a first threshold to obtain a new candidate code set comprises: crossing and mutating two candidate codes corresponding to a similarity less than a first threshold to obtain a new candidate code; determining an update strategy of the candidate code set according to the type of the code processing instruction and / or the first parameter in the code processing instruction, wherein the update strategy is used to indicate the proportion, number and / or screening condition of parent codes included in the new candidate code set; obtaining a target parent code from the candidate code set based on the update strategy; determining the new candidate code and the target parent code as the new candidate code set.

5. The method of any one of claims 1-4, wherein, After obtaining the new candidate code set, further comprising: in a case where the evaluation service in the system is in a selected state, or in a case where the received code processing instruction indicates calling the evaluation service, calling the evaluation service based on the new candidate code set to obtain an evaluation result output by the evaluation service, wherein the evaluation result comprises an evaluation value of the candidate code and / or a segment to be updated in the candidate code; updating the new candidate code set based on the evaluation result.

6. The method of claim 5, wherein, The updating of the new candidate code set based on the evaluation result comprises at least one of the following: delete the candidate code whose evaluation value in the new candidate code set is less than the evaluation threshold value; update the to-be-updated segment in the candidate code to obtain a new candidate code.

7. The method of claim 6, wherein, The updating the to-be-updated segment in the candidate code to obtain a new candidate code comprises: determining the similarity between the second description information of the to-be-updated segment and the third description information of each code segment in the gene pool, the third description information being information for describing the algorithm, data structure, input data and output data corresponding to each code segment in the gene pool; based on the similarity, obtaining a target segment or a target parent code containing the target segment from the gene pool; updating the to-be-updated segment using the target segment or the target parent code to obtain a new candidate code.

8. The method of claim 7, wherein, The method further comprises at least one of the following: determining the index corresponding to the candidate code according to the first description information and / or the second description information associated with the candidate code whose evaluation value is greater than the evaluation threshold value; 9. The method of claim 7, wherein, storing the candidate code and the index in the gene pool.

10. An artificial intelligence-based adaptive code processing apparatus, comprising: a first obtaining module configured to obtain a candidate code set, wherein the candidate code set comprises a plurality of candidate codes, first description information corresponding to each of the candidate codes, and second description information corresponding to each segment in the candidate codes, the first description information being information for describing the function, logic and algorithm type of the candidate code, and the second description information being information for describing the algorithm, data structure, input data and output data corresponding to each segment in the candidate code; a first determining module configured to determine the global similarity between two candidate codes corresponding to each two first description information, determine the local similarity between each two candidate codes based on the second description information corresponding to each segment in each two candidate codes, and fuse the global similarity and the local similarity to obtain the similarity between each two candidate codes; a first processing module configured to cross and mutate two candidate codes corresponding to a similarity less than a first threshold value to obtain a new candidate code set; a second processing module configured to return to the step of determining the similarity based on the new candidate code set until a target code set meeting the requirements is obtained.

11. An intelligent agent, comprising: an input module configured to receive a to-be-processed code and / or a code processing instruction; a processing module configured to call a large model to execute the method of any one of claims 1-9 based on the to-be-processed code and / or the code processing instruction to obtain a target code set; an output module configured to output the target code set. ​ ​ 12. An electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the artificial intelligence based adaptive code processing method of any one of claims 1-9.

13. A non-transitory computer-readable storage medium having stored thereon computer instructions, wherein the computer instructions, when executed by a processor, cause the processor to perform the method of any one of claims 1-12. wherein the computer instructions cause the computer to perform the artificial intelligence based adaptive code processing method of any one of claims 1-9.

14. A computer program product, characterised in that, a computer program that, when executed by a processor, implements the steps of the artificial intelligence based adaptive code processing method of any one of claims 1-9.

Citation Information

Patent Citations

  • Algorithm automatic matching and parameter optimization method and system

    CN118468061A

  • Code completion method and device, storage medium and computer equipment

    CN119225735A