Code generation method and device based on large model, storage medium and equipment
By identifying the steps and logical relationships in the business logic process, combining computer program code and operator names defined in natural language, high-order programs are generated, and the accuracy and reliability problems of LLM when generating code in specific fields are solved, achieving more efficient code generation.
Patent Information
- Application Number
- CN202511041894.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-25
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2045-07-25
AI Technical Summary
When generating codes in specific domains, large language models (LLMs) are prone to problems such as lack of knowledge, errors in knowledge or expired knowledge due to the limitations of training data, resulting in reduced accuracy and reliability of generated codes.
By obtaining the business logic process described by natural language, using a pre-trained large language model (LLM) to identify each step and its logical relationship, generate a computer program code framework, and combine the operator names defined by natural language to generate knowledge higher-order programs to improve the accuracy and reliability of code generation.
Through clear logical relationships and operator names defined in natural language, the accuracy and reliability of LLM generated code is improved, the logical confusion caused by ambiguity and ambiguity of natural language descriptions is avoided, and the accuracy of code execution is ensured.
Smart Images

Figure CN120540645A_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of computer technology, and in particular to a code generation method, apparatus, storage medium, and device based on a large model. Background Art
[0002] With the development of artificial intelligence (AI) technology, large language models (LLMs) have been widely used in various fields. Using LLMs to generate code is one of the important applications of LLMs.
[0003] However, when LLMs are applied to generate code in specific domains, they often face numerous challenges. This is because specialized domains contain a vast amount of highly complex and constantly updated knowledge. LLMs can suffer from knowledge deficiencies, errors, or outdated knowledge due to limited training data. These issues can cause LLMs to "illusion" the generated code, reducing the accuracy and reliability of the generated code.
[0004] Therefore, how to generate accurate and reliable code based on LLM has become an urgent problem to be solved. Summary of the Invention
[0005] The embodiments of this specification provide a code generation method, device, storage medium and electronic device based on a large model to partially solve the problems existing in the above-mentioned prior art.
[0006] The embodiments of this specification adopt the following technical solutions: This specification provides a code generation method based on a large model, the method comprising: Obtain business logic processes described in natural language; Input the business logic process into a pre-trained large language model LLM; Identifying the steps in the business logic process and the logical relationships between the steps through the LLM; Based on the logical relationship, a computer program code of a preset type for representing the logical relationship between the steps is generated as a framework code; and for each step, based on the natural language used to describe the step in the business logic process and a preset knowledge base corresponding to the business logic process, at least one operator for executing the step is generated, wherein the computational logic of the operator is defined in the natural language, and the operator name of the operator conforms to the function name format of the computer program code of the preset type; A knowledge high-level program for executing the business logic process is generated according to the framework code and the operator name of the operator generated for each step.
[0007] This specification provides a code generation device based on a large model, the device comprising: An acquisition module is used to acquire the business logic process described in natural language; An input module, configured to input the business logic process into a pre-trained large language model LLM; An identification module, configured to identify, through the LLM, the steps included in the business logic process and the logical relationships between the steps; A generation module is used to generate a preset type of computer program code for representing the logical relationship between the steps according to the logical relationship as a framework code; and, for each step, based on the natural language used to describe the step in the business logic process and the preset knowledge base corresponding to the business logic process, generate at least one operator for executing the step, the calculation logic of the operator is defined by natural language, and the operator name of the operator conforms to the function name format of the preset type of computer program code; based on the framework code and the operator name of the operator generated for each step, generate a knowledge high-level program for executing the business logic process.
[0008] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the above-mentioned large model-based code generation method.
[0009] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the above-mentioned large model-based code generation method is implemented.
[0010] At least one of the above technical solutions adopted in the embodiments of this specification can achieve the following beneficial effects: The embodiments of this specification disclose a code generation method based on a large model, which inputs a business logic process described in natural language into a pre-trained LLM, and uses the LLM to identify the steps contained in the business logic process and the logical relationship between the steps. For the logical relationship, the LLM generates a preset type of computer program code representing the logical relationship as a framework code. For each step, the LLM generates at least one operator for executing the step. The calculation logic of the operator is defined by natural language, but the operator name still conforms to the function name format of the preset type of computer program code. Finally, based on the framework code and the operator name of the operator of each step, a knowledge high-level program for executing the business logic process is generated. This method improves the accuracy of LLM generated code by inputting the business logic process into LLM. Moreover, in order to avoid the logical confusion of each step in the business logic process caused by the ambiguity and vagueness of the business logic process itself described by natural language, this method LLM expresses the logical relationship between each step through computer program code, and uses the semantic accuracy of computer program code to express the main logic of the business logic process. For specific steps, they are expressed through operators defined by natural language, so as to express the specific knowledge required for the execution of the step through the advantage of natural language in expressing knowledge, thereby improving the accuracy and reliability of LLM generated code. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The exemplary embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation of this specification. In the drawings: Figure 1 A code generation flow chart based on a large model provided in the embodiments of this specification; Figure 2 A schematic diagram of a code generation device based on a large model provided in an embodiment of this specification; Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this specification. DETAILED DESCRIPTION
[0012] To make the objectives, technical solutions, and advantages of this specification more clear, the following will clearly and completely describe the technical solutions of this specification in conjunction with the specific embodiments of this specification and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of this specification.
[0013] The technical solutions provided by the various embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0014] Figure 1 The code generation flow chart based on the large model provided in the embodiment of this specification specifically includes the following steps: S100: Acquire a business logic process described in natural language.
[0015] In the embodiments of this specification, Figure 1 The device for generating codes using the method shown can be any electronic device, such as a computer, a server, or a server cluster consisting of multiple servers, etc. For ease of description, the following description will only take a server as an example.
[0016] In order to generate code for executing a certain business, the server can first obtain the business logic process of the business. Specifically, the business logic process described in this specification includes a standard operating procedure (SOP). The SOP is a standard operating procedure for the business described in natural language. It is a document that details the work, workflow, and steps in the business. It provides standard process specifications within the organization of the business for reference and operation by internal personnel of the organization. In addition to containing the standardized process of the business, the SOP also includes clear responsibilities and authorities of each role in the business, emergency measures, quality standards and assessments, document management, and other content.
[0017] In the embodiments of this specification, the code generation method provided in this specification is described below by taking the above-mentioned business as the risk control business as an example.
[0018] When the above-mentioned business is a risk control business based on the recorded risk log, the business logic process of the risk control business (that is, the risk control logic process) can be described in the following natural language: The first step is to analyze the cmd field to determine whether the file is granted executable permissions. If the cmd command line does not grant the file executable permissions, the conclusion is that no action is required. The second step is to determine whether the installation package is a commonly used software installation package. If it is a commonly used installation software, the conclusion is that no action is required; The third step is to determine whether the cmd field has been manually analyzed by security operations personnel within N days and determined to require no action. For example, if the chmod command line is determined to require no action, then no action is required for this risk log. The fourth step is to determine whether the risk log does not need to be handled or generates an attack alarm based on the results of the above three steps.
[0019] The risk log is a risk log of other businesses recorded by the user when performing other businesses, and the risk control business is a business that requires risk control of the other businesses based on the risk log.
[0020] S102: Input the business logic process into a pre-trained large language model LLM.
[0021] After the server obtains the business logic process described above, it can input the business logic process described in natural language into a pre-trained LLM. This LLM can be pre-deployed on the server, or it can be deployed on other devices. If deployed on other devices, the server can send the business logic process to the other devices, allowing them to input the received business logic process into the LLM. The following description uses the LLM deployed on the server as an example.
[0022] In order to avoid the LLM from generating "hallucinations" and code that is inconsistent with the actual business logic process, and to improve the accuracy and reliability of the LLM generated code, in the embodiment of this specification, the server directly outputs the actual business logic process obtained in step S100 to the LLM, so that the LLM generates code for executing the business based on the business logic process.
[0023] S104: Identify the steps included in the business logic process and the logical relationships between the steps through the LLM.
[0024] Generally, a business logic process consists of several steps arranged according to certain logical relationships. For example, in the example above, the first step is executed first. If the first step evaluates to "no," the result is output directly, indicating no action is required. If the result is "yes," the second step is executed. If the second step evaluates to "yes," the result is output directly, indicating no action is required. Otherwise, the third step is executed. If the third step evaluates to "yes," the result is output directly, indicating no action is required. Otherwise, an attack alert is generated. Therefore, the logical relationships between the different steps in a business logic process constitute the basic framework of the process. Specifically, the execution of each step requires the use of knowledge specific to the business logic process, including the concepts and attributes of the entities required in the process, as well as the relationships between them. For example, in the example above, the first step requires determining whether the "cmd" field grants executable permissions to a file. The knowledge required to execute this first step includes at least the concept of the "cmd" field, the concept of file executable permissions, and the relationship between the "cmd" field and file executable permissions (i.e., which "cmd" field indicates that the file has been granted executable permissions, and which "cmd" field indicates that the file has not been granted executable permissions).
[0025] It can be seen from this that a business logic process is essentially composed of the logical relationship between each step and the knowledge required to execute each step. Therefore, to generate code for executing the business logic process, LLM needs to identify the steps contained in the business logic process and the logical relationship between the steps based on the business logic process described in natural language.
[0026] Specifically, since identifying the steps and logical relationships between the steps in a business logic process may also require a knowledge base corresponding to the business logic process, in the embodiments of this specification, the knowledge base corresponding to the business logic process may be pre-injected into the pre-trained LLM. The knowledge base may include at least one of the following: The knowledge graph corresponding to the business logic process includes the concept description of each entity required in the business logic process (used to describe what the entity is, such as the concept of cmd command line in the above example), the attributes of each entity (used to describe all possible attributes of the entity in the business logic), and the relationship between each entity; The calling interface of the tool required in the business logic process includes API or SDK, etc. For example, in the second step of the above example, it is necessary to determine whether the installation package is an installation package of commonly used software. In this case, it is necessary to call the tool to obtain a list of installation packages of commonly used software. This requires calling the tool through the tool's calling interface.
[0027] After injecting the above-mentioned knowledge base containing the knowledge graph corresponding to the business logic process and / or the calling interface of the required tools into the pre-trained LLM, when the server inputs the business logic process described in natural language to the LLM, the LLM can identify the semantics of the business logic process described in the natural language based on its own reasoning ability, and map the concepts in the business logic process into entities in the knowledge graph. Then, based on the semantics, the entire business logic process is split into several steps, and finally the logical relationship between the steps is inferred.
[0028] S106: Based on the logical relationship, generate a preset type of computer program code for representing the logical relationship between the steps as a framework code.
[0029] Because natural language itself has a certain degree of ambiguity and ambiguity, which is an inherent defect of any natural language, directly using natural language to express the logical relationship between the steps in the business logic process is very likely to lead to logical confusion among the steps. In particular, when people other than the person who wrote the business logic process read the business logic process, the ambiguity and ambiguity of natural language may lead to inaccurate understanding, which will affect the business itself.
[0030] Computer programming language, as a formalized and precise language, has clear semantics and strict logical structure, and can effectively avoid the above-mentioned problems of natural language. Therefore, in the embodiment of this specification, for the logical relationship between each step in the business logic process, the server can generate a preset type of computer program code for representing the logical relationship between each step as a framework code through LLM based on the logical relationship between each step identified in step S104.
[0031] The preset type of computer program code may be any type of computer program code, including but not limited to Python code. The following description will only take Python code as an example.
[0032] S108: For each step, generate at least one operator for executing the step according to the natural language used to describe the step in the business logic process and a preset knowledge base corresponding to the business logic process.
[0033] In the embodiment of this specification, the execution order of step S106 and step S108 may not be particular. Specifically, the server may execute step S106 through the LLM while also executing step S108 through the LLM.
[0034] As for the knowledge required for each step in the business logic process, natural language is more natural and more understandable than computer programming language. Therefore, in the embodiments of this specification, an operator defined in natural language is used to represent a step.
[0035] The computational logic of the operators described in the embodiments of this specification is defined in natural language, but the operator names of these operators still conform to the function name format requirements of the aforementioned predefined type of computer program code. Therefore, the operators defined in natural language in this specification are essentially custom functions within the predefined type of computer program code, which are high-level abstract expressions of the logic that implements the steps.
[0036] Specifically, for each step identified in the business logic process, the LLM can determine the knowledge required to execute the step, such as one or more entities in the knowledge graph, one or more attributes of the entity, the relationship between the entity and other entities, and / or the calling interface of the tool required for the step, based on the semantics of the natural language used to describe the step in the identified business logic process and the knowledge base corresponding to the business logic process. After determining the knowledge required to execute the step, at least one operator for executing the step can be generated based on the knowledge. The operator is defined in natural language and its name conforms to the function name format requirements of the aforementioned preset type of computer program code.
[0037] Continuing with the previous example, the first step is to determine whether the cmd field grants the file executable permission. Therefore, LLM can generate an operator name hop_judge that meets the Python code function name requirements and define the operator hop_judge as follows: def hop_judge Determine whether {cmd} grants file executable permissions As can be seen from this, the definition of the operator hop_judge is completely defined using natural language "judge whether {cmd} grants executable permissions to the file", making the operator more understandable.
[0038] The above is just an example of expressing a step with one operator. Those skilled in the art should understand that in actual applications, for more complex steps, more operators (such as more than two operators) can be used to express the step.
[0039] S110: Generate a knowledge high-level program for executing the business logic process according to the framework code and the operator name of the operator generated for each step.
[0040] As explained above, a business logic process is essentially composed of the logical relationships between the steps and the knowledge required to execute each step. The logical relationships have been expressed using the generated framework code in step S106, and the knowledge required to execute each step has been expressed in step S108 using operators defined in natural language, whose operator names still conform to the preset type of computer program code function name format requirements. Therefore, LLM can combine the framework code and the operators corresponding to each step to generate a knowledge high-level program (HOP) for executing the business logic process.
[0041] Continuing with the above example, LLM combines the operators corresponding to each step into the framework code to generate the following HOP for executing the above risk control logic process: def evaluate(cmd): if hop_judge_a("Judge (cmd) whether to grant file executable permissions") #High-level judgment pkg = hop_get("Get the installation package used by (cmd)") if not pkg in hop_knowledge_retrieve("Common Installation Package") #High-level knowledge concept matching if not hop_judge_b("Check the history to see if (cmd) has been manually judged as not requiring action") return "Attack Alarm" return "No need to dispose" In the HOP above, the content enclosed by ("") is the natural language definition of the corresponding operator. These operators include hop_judge_a, hop_get, hop_knowledge_retrieve, and hop_judge_b. The framework code expressed in Python above shows the entire risk control logic process as follows: first, execute the hop_judge_a operator to determine whether (cmd) has file executable permissions. If so, execute the hop_get operator, obtain the installation package used by (cmd), and assign it to pkg. If not, directly output "No action required." After obtaining the installation package used by (cmd) and assigning it to pkg, execute the hop_knowledge_retrieve operator to obtain the commonly used installation package and determine whether pkg is not among the commonly used installation packages. If so, execute the hop_judge_b operator. If not, directly output "No action required." Execute the hop_judge_b operator to determine whether (cmd) has not been manually determined to require action in the past. If so, output "Attack Alarm"; otherwise, output "No action required."
[0042] As can be seen, the HOP, represented by Python code, is completely consistent with the original risk control logic process described in natural language. Therefore, even if personnel within the department executing the risk control work change, the HOP can be read by other personnel (besides the original author of the risk control logic process) without causing logical confusion between the various steps due to the inherent ambiguity and ambiguity of natural language. Furthermore, while the operators in the HOP code are defined in natural language, the operator names are still Python function names. Therefore, the HOP code itself consists of Python framework code referencing various Python-formatted operator names. Formally, it remains Python code. Therefore, the HOP code is not only human-readable but can also be directly executed in the Python execution environment to implement the risk control logic process. The specific execution method for the HOP, which is formally Python code but essentially contains operators defined in natural language, is described below.
[0043] In the embodiments of this specification, in order for the LLM to accurately convert the business logic process described in the input natural language into the above-mentioned HOP, it is not enough to simply inject the knowledge base corresponding to the business logic process into the LLM. The LLM also needs to be fine-tuned and trained in the business scenario corresponding to the business logic process in advance.
[0044] Specifically, when fine-tuning the LLM, you can first obtain a sample logical process described in natural language. This sample logical process also includes several steps, referred to as sample steps below. This sample logical process and the aforementioned business logic process are business logic processes in the same business scenario. That is, the knowledge base corresponding to the sample logical process is exactly the same as the knowledge base corresponding to the aforementioned business logic process.
[0045] After obtaining the sample logic process, you can also Figure 1 In the steps S102 to S110 shown, the sample logic process is input into the LLM to be trained, and the sample steps contained in the sample logic process and the logical relationship between the sample steps are identified by the LLM to be trained. According to the logical relationship between the sample steps, a preset type of computer program code for representing the logical relationship between the sample steps is generated as the framework code to be optimized. Moreover, for each sample step, according to the natural language used to describe the sample step in the sample logic process and the knowledge base corresponding to the preset sample logic process, at least one operator for executing the sample step is generated as the operator to be optimized. The calculation logic of the operator to be optimized is also defined in natural language, and the operator name of the operator to be optimized also conforms to the function name format of the above-mentioned preset type of computer program code. Finally, according to the framework code to be optimized and the operator name of the operator to be optimized generated for each sample step, a HOP to be optimized for executing the sample logic process is generated. This process is the same as Figure 1 Steps S102 to S110 are identical and will not be described again here.
[0046] After the LLM to be trained generates the HOP to be optimized, the optimized HOP after adjusting the HOP to be optimized can be determined. Among them, since the HOP to be optimized is also the above-mentioned preset type of computer program code (such as Python code) in form, the HOP to be optimized can be manually adjusted so that the logical relationship between the sample steps expressed by the framework code to be optimized is completely consistent with the original sample logical process, and the natural language corresponding to the operator to be optimized defined by natural language contained therein is more in line with the knowledge in the knowledge base corresponding to the sample logical process, and the calculation logic of the operator to be optimized expressed is clearer and more accurate. Of course, the HOP to be optimized can also be adjusted by other trained LLMs, and this embodiment of the specification does not limit this.
[0047] After obtaining the optimized HOP, the supervised fine-tuning training (SFT) of the LLM to be trained can be performed based on the optimized HOP, that is, the optimized HOP is used as the label corresponding to the sample logic process, and used as the supervision signal to adjust the model parameters of the LLM to be trained, so that the model parameters of the LLM to be trained are adjusted to make the LLM adapt to generate various business logic processes in the business scenario. Figure 1 The device used for code generation can be the same device or a different device. Furthermore, since the embodiments of this specification require that the original reasoning capabilities of the LLM be maintained as much as possible and adapted only to the business scenario, when performing SFT on the LLM, not all model parameters of the LLM are adjusted; instead, only some of the model parameters within the LLM are adjusted. The adjusted model parameters may only include the LoRA model parameters within the LLM.
[0048] After the LLM is obtained through the above SFT training, the server can Figure 1 The method shown generates a HOP corresponding to the business logic process in this business scenario. As explained above, the generated HOP is not only a user-readable document, but also a directly executable computer program code. Because the HOP contains not only the aforementioned pre-defined computer program code (such as Python) but also operators defined in natural language, the aforementioned LLM is also required to assist in the execution of the HOP.
[0049] Specifically, an operating environment for the preset type of computer program code can be run, and business data can be loaded. When the business scenario is a risk control business scenario, that is, the business logic process is a risk control logic process in a risk control business scenario, the loaded business data can be a pre-recorded risk log. The risk log is a risk log of other businesses recorded by the user when performing other businesses. The risk control business is the business that requires risk control of the other business based on the risk log.
[0050] After the operating environment of the preset type of computer program code is pulled up and the business data is loaded, the system can run the program through the operating environment based on the business data. Figure 1 Generated HOP.
[0051] When running to the operator defined by natural language in the HOP, the above-mentioned LLM needs to be called. Among them, since the framework of the HOP is still a preset type of computer program code, the operating environment using the preset type of computer program code can directly run the HOP. As for the operator defined by natural language contained in the HOP, since the operator is essentially a custom function in the preset type of computer program code, the HOP references the function name, which means executing the function corresponding to the function name, obtaining the execution result, and then continuing to execute the subsequent code according to the execution result. Therefore, when running to the operator name defined by natural language in the HOP, the pre-defined calculation logic of the operator needs to be called. When the calculation logic of the operator is parsed by the operating environment, if it is parsed that the calculation logic is defined by natural language, the operating environment can directly call the above-mentioned LLM.
[0052] After calling the above-mentioned LLM, the business data and / or the intermediate results obtained by currently running the HOP can be input into the LLM as the input parameters of the operator, so that the LLM executes the calculation logic of the operator according to the input parameters and the knowledge base corresponding to the above-mentioned business logic process to determine the execution result of the operator, and continues to execute the HOP according to the execution result of the operator until the execution of the HOP is completed.
[0053] Continuing with the above example, for the operator hop_judge_a in the above HOP, its natural language defined calculation logic is "Judge whether (cmd) grants file executable permissions." In this case, business data, that is, the pre-recorded risk log, can be used as the operator's input parameter. The operator's natural language defined calculation logic and the input parameter are both input into the LLM. Prompt information can also be input into the LLM. Under the guidance of the prompt information, the LLM first identifies the cmd command line in the input parameter (i.e., the entity in the knowledge graph) based on the knowledge base corresponding to the risk control logic process. Then, based on the knowledge base and the identified cmd command line, the LLM determines the attributes of the cmd command line in the input parameter (i.e., the attributes of the entity in the knowledge graph). Based on the attributes, the LLM determines whether the cmd command line grants file executable permissions (i.e., the relationship between different entities in the knowledge graph). The judgment result is used as the output parameter of the operator hop_judge_a and returned to the Python runtime environment, allowing the Python runtime environment to continue executing subsequent code in the HOP.
[0054] For another example, for the operator hop_knowledge_retrieve in the above HOP, the calculation logic defined in natural language is "common installation packages". The calculation logic defined in natural language of the operator can be input into LLM, and prompt information can be input to LLM, so that the LLM, under the guidance of the prompt information, first determines the tool for obtaining the list of commonly used installation packages based on the knowledge base corresponding to the risk control logic process, and then calls the tool through the calling interface of the tool to obtain the commonly used installation packages through the called tool. Finally, the obtained list of commonly used installation packages is used as the output parameter of the operator hop_knowledge_retrieve and returned to the Python runtime environment, so that the Python runtime environment continues to execute the subsequent code in the HOP to determine whether the intermediate result pkg of the current running of the HOP is not included in the list of commonly used installation packages.
[0055] The above devices used to run HOP need to deploy the same LLM that has been fine-tuned by SFT. The devices running HOP can be used with Figure 1 The devices for generating HOP in the method shown may be the same or different, and this specification does not impose any limitation on this.
[0056] Those skilled in the art will appreciate that the above description uses the risk control logic process as an example. In reality, the HOP generation methods provided in the embodiments of this specification can be used to generate and execute HOPs corresponding to business logic processes in any business scenario. Furthermore, the aforementioned preset computer program code is described using Python code as an example; the preset computer program code described in the embodiments of this specification can also be other types of computer program code.
[0057] The above is a code generation method based on a large model provided in an embodiment of this specification. Based on the same idea, this specification also provides corresponding devices, storage media and electronic devices.
[0058] Figure 2 A schematic diagram of a code generation device based on a large model provided in an embodiment of this specification, the device comprising: An acquisition module 201 is used to acquire a business logic process described in a natural language; An input module 202 is used to input the business logic process into a pre-trained large language model LLM; Identification module 203, used to identify the steps included in the business logic process and the logical relationship between the steps through the LLM; The generation module 204 is used to generate a preset type of computer program code for representing the logical relationship between the steps as a framework code based on the logical relationship; and, for each step, based on the natural language used to describe the step in the business logic process and the preset knowledge base corresponding to the business logic process, generate at least one operator for executing the step, the calculation logic of the operator is defined by natural language, and the operator name of the operator conforms to the function name format of the preset type of computer program code; based on the framework code and the operator name of the operator generated for each step, generate a knowledge high-level program for executing the business logic process.
[0059] Optionally, the input module 202 is further configured to inject a knowledge base corresponding to the business logic process into the pre-trained LLM before the identification module 203 identifies the steps included in the business logic process and the logical relationships between the steps through the LLM; The identification module 203 is specifically configured to identify the steps included in the business logic process and the logical relationships between the steps through the LLM according to the knowledge base corresponding to the business logic process.
[0060] Optionally, the device further comprises: The training module 205 is used to obtain a sample logical process described in natural language, wherein the sample logical process includes several sample steps; identify each sample step included in the sample logical process and the logical relationship between the sample steps through the LLM to be trained; generate a preset type of computer program code for representing the logical relationship between the sample steps based on the logical relationship between the sample steps, as a framework code to be optimized; and, for each sample step, generate at least one operator for executing the sample step based on the natural language used to describe the sample step in the sample logical process and a preset knowledge base corresponding to the sample logical process, as an operator to be optimized, wherein the calculation logic of the operator to be optimized is defined in natural language, and the operator name of the operator to be optimized conforms to the function name format of the preset type of computer program code; generate a knowledge high-level program to be optimized for executing the sample logical process based on the framework code to be optimized and the operator name of the operator to be optimized generated for each sample step; determine an optimized knowledge high-level program after adjusting the knowledge high-level program to be optimized; and perform supervised fine-tuning training on the LLM to be trained based on the optimized knowledge high-level program.
[0061] Optionally, the knowledge base corresponding to the sample logic process is the same as the knowledge base corresponding to the business logic process.
[0062] Optionally, the device further comprises: An operating module 206 is configured to operate an operating environment of the preset type of computer program code and load business data; and to operate the high-level knowledge program through the operating environment based on the business data; When the operator in the knowledge high-level program is run, the LLM is called; the business data and / or the intermediate results obtained by currently running the knowledge high-level program are input into the LLM as input parameters of the operator, so that the LLM executes the calculation logic of the operator according to the input parameters and the knowledge base corresponding to the business logic process to determine the execution result of the operator; the knowledge high-level program is continued to be executed according to the execution result of the operator until the execution of the knowledge high-level program is completed.
[0063] Optionally, the running module 206 is specifically used to call the calculation logic of the operator when running to the operator name of the operator in the knowledge high-level program; when parsing through the running environment that the calculation logic is defined by natural language, calling the LLM.
[0064] Optionally, the business logic process includes a risk control logic process; The business data includes a pre-recorded risk log; The preset type of computer program code includes Python.
[0065] This specification also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it can be used to execute the large model-based code generation method provided above.
[0066] based on Figure 1 The code generation method based on the large model shown in the embodiment of this specification also provides Figure 3 The structural diagram of the electronic device shown in FIG. Figure 3 At the hardware level, the electronic device includes a processor, an internal bus, a network interface, memory, and non-volatile storage, and may also include other hardware required for its operations. The processor reads the corresponding computer program from the non-volatile storage into the memory and then runs it, implementing the aforementioned large model-based code generation method.
[0067] The foregoing is merely an example of the present invention and is not intended to limit the present invention. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention are intended to be included within the scope of the claims of the present invention.
Claims
1. A code generation method based on a large model, the method comprising: Obtain business logic processes described in natural language; Input the business logic process into a pre-trained large language model LLM; Identifying the steps in the business logic process and the logical relationships between the steps through the LLM; generating, according to the logical relationship, a computer program code of a preset type for representing the logical relationship between the steps as a framework code; Furthermore, for each step, based on the natural language used to describe the step in the business logic process and a preset knowledge base corresponding to the business logic process, at least one operator for executing the step is generated, wherein the computational logic of the operator is defined in the natural language, and the operator name conforms to the function name format of the preset type of computer program code; A knowledge high-level program for executing the business logic process is generated according to the framework code and the operator name of the operator generated for each step.
2. The method according to claim 1, before identifying the steps in the business logic process and the logical relationships between the steps through the LLM, the method further comprises: Injecting the knowledge base corresponding to the business logic process into the pre-trained LLM; Identifying the steps in the business logic process and the logical relationships between the steps through the LLM specifically includes: Through the LLM, the steps included in the business logic process and the logical relationships between the steps are identified according to the knowledge base corresponding to the business logic process.
3. The method according to claim 1, wherein the LLM is pre-trained, specifically comprising: Acquire a sample logical process described in natural language, where the sample logical process includes several sample steps; Identifying, by the LLM to be trained, each sample step included in the sample logic process and the logical relationship between the sample steps; According to the logical relationship between each sample step, generating a computer program code of a preset type for representing the logical relationship between each sample step as the framework code to be optimized; Furthermore, for each sample step, based on the natural language used to describe the sample step in the sample logical process and a preset knowledge base corresponding to the sample logical process, at least one operator for executing the sample step is generated as the operator to be optimized, wherein the computational logic of the operator to be optimized is defined in natural language, and the operator name of the operator to be optimized conforms to the function name format of the preset type of computer program code; Generate a knowledge high-level program to be optimized for executing the sample logic process according to the framework code to be optimized and the operator name of the operator to be optimized generated for each sample step; Determining an optimized knowledge high-level program after adjusting the knowledge high-level program to be optimized; According to the optimized knowledge high-level program, supervised fine-tuning training is performed on the LLM to be trained.
4. The method according to claim 3, wherein the knowledge base corresponding to the sample logic process is the same as the knowledge base corresponding to the business logic process.
5. The method of claim 1, further comprising: Running the operating environment of the preset type of computer program code and loading business data; Based on the business data, running the knowledge high-level program through the operating environment; When the operator in the knowledge high-level program is executed, the LLM is called; Input the business data and / or the intermediate result obtained by currently running the knowledge high-level program as input parameters of the operator into the LLM, so that the LLM executes the calculation logic of the operator according to the input parameters and the knowledge base corresponding to the business logic process to determine the execution result of the operator; The high-level knowledge program is continued to be executed according to the execution result of the operator until the execution of the high-level knowledge program is completed.
6. The method according to claim 5, wherein when the operator in the knowledge high-level program is executed, the LLM is called, specifically comprising: When the operator name of the operator in the knowledge high-level program is reached, the calculation logic of the operator is called; When it is found through the operating environment that the computing logic is defined in a natural language, the LLM is called.
7. The method according to claim 5, wherein the business logic process includes a risk control logic process; The business data includes a pre-recorded risk log; The preset type of computer program code includes Python.
8. A code generation device based on a large model, the device comprising: An acquisition module is used to acquire the business logic process described in natural language; An input module, configured to input the business logic process into a pre-trained large language model LLM; An identification module, configured to identify, through the LLM, the steps included in the business logic process and the logical relationships between the steps; A generating module, configured to generate, based on the logical relationship, a computer program code of a preset type for representing the logical relationship between the steps, as a framework code; Furthermore, for each step, based on the natural language used to describe the step in the business logic process and the preset knowledge base corresponding to the business logic process, at least one operator for executing the step is generated, the calculation logic of the operator is defined through natural language, and the operator name of the operator conforms to the function name format of the preset type of computer program code; based on the framework code and the operator name of the operator generated for each step, a knowledge high-level program for executing the business logic process is generated.
9. A computer-readable storage medium storing a computer program, wherein the computer program implements the method according to any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.
Citation Information
Patent Citations
Model-based code generation method and device, storage medium and electronic equipment
CN117873453A
Code generation method and system based on large language model
CN118210489A
Structured common sense reasoning method based on code language
CN118396109A
Visual intelligent programming method based on large language model
CN119045806A
Pseudo-code-based source code generation method and device, computer equipment and readable storage medium
CN119248235A
