Code generation method and device, medium and equipment

By receiving user instructions and using large language models to generate target codes, the problem of insufficient knowledge reserves of code generation models in the astronomical field in the prior art is solved, and the code generation efficiency and accuracy are improved.

CN119847532AInactive Publication Date: 2025-04-18ZHEJIANG LAB
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510321770.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-18
Publication Date
2025-04-18
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

When existing code generation models deal with code generation requirements in the astronomical field, they lack knowledge reserves and are difficult to meet the actual programming needs of professional astronomers.

Method used

By receiving user instructions, the required target API is determined, and the API description information and user instructions are input into the large language model to generate target code for performing astronomy domain tasks.

Benefits of technology

It improves code generation efficiency, lowers the threshold for generating proprietary field code, and can more accurately meet the programming needs of astronomers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847532A_ABST
    Figure CN119847532A_ABST
Patent Text Reader

Abstract

The invention discloses a code generation method and device, a medium and equipment, and the method comprises the steps: determining each disassembly step for generating a code needed by a user based on a user instruction after receiving the user instruction containing information for describing the functions of a to-be-generated code in a set field; the method comprises the steps of obtaining a user instruction from a set domain API library, determining an API list of candidate APIs matched with the user instruction from the set domain API library on the basis of each disassembling step, inputting the APIs in the API list and the user instruction into a large language model to enable the large language model to generate codes, obtaining analyzed APIs through analyzing the generated codes, comparing the analyzed APIs with the APIs in the API library, updating the API list to iteratively generate the codes, and analyzing the analyzed APIs in the set domain API library. Error information appearing during code execution is fed back to the large language model, special retrieval is executed according to different error types so as to update the API list, the reliability and accuracy of field code generation are remarkably enhanced, and higher-quality programming support is provided for employees.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the fields of computer technology and astronomy, and in particular to a code generation method, device, medium and equipment. Background Art

[0002] Astronomers face many programming needs in their daily scientific research work, such as data retrieval, table generation and analysis, and drawing analysis according to actual needs. These needs can be solved by code generation technology. That is, the technology can automatically generate corresponding codes based on task instructions described in natural language.

[0003] Existing code generation models mainly focus on general code generation tasks. Compared with general code generation tasks, code generation requirements in the astronomical field usually involve specific astronomical knowledge and usually require a certain level of mastery of astronomy-related databases, such as Astropy and Astroquery.

[0004] However, due to the relative scarcity of relevant data on PowerPoint libraries (such as Astroquery) involving niche astronomical fields in natural corpora (such as open source platforms such as GitHub), the current code generation models have insufficient knowledge reserves when dealing with code generation needs in the astronomical field, and it is difficult to meet the actual programming needs of professional astronomers.

[0005] Therefore, how to provide astronomers with a reliable and efficient code generation method is a technical problem that needs to be solved urgently. Summary of the invention

[0006] The embodiments of the present application provide a code generation method, apparatus, medium and device to partially solve the above-mentioned problems existing in the prior art.

[0007] This application adopts the following technical solutions: The present application provides a code generation method, including: receiving a user instruction, wherein the user instruction includes information for describing a function that the code to be generated can implement in a set domain; According to the user instruction, determining each target API required for generating code from at least one pre-built application programming interface API library of the set domain; Determine the API description information corresponding to each target API, and input the API description information corresponding to each target API and the user instruction into a preset large language model, so as to generate a target code for executing the task required in the set field through the large language model.

[0008] Optionally, according to the user instruction, determining each target API required for generating the code from at least one pre-built application programming interface API library of the set domain specifically includes: Determine a feature representation vector corresponding to the user instruction through a preset feature expression model, and input API description information corresponding to each API included in the at least one API library into the feature expression model to determine each feature representation vector corresponding to each API included in the at least one API library; According to the similarity between the feature representation vector corresponding to the user instruction and the feature representation vector corresponding to each API included in the at least one API library, each target API required for generating the code is determined.

[0009] Optionally, determining the feature representation vector corresponding to the user instruction by using a preset feature expression model specifically includes: Inputting the user instruction into the large language model, so that the large language model determines, according to the user instruction, step description information of each disassembly step that needs to be performed when generating the code required by the set domain; The step description information of each disassembly step is input into the feature expression model to determine the feature representation vector corresponding to the user instruction.

[0010] Optionally, according to the user instruction, determining each target API required for generating the code from at least one pre-built application programming interface API library of the set domain specifically includes: According to the user instruction, determining a candidate API list required for code generation from at least one pre-built application programming interface API library of the set domain; Inputting API description information corresponding to each candidate API included in the candidate API list and the user instruction into the large language model, so as to obtain an initial code generated based on the user instruction through the large language model; Parsing the initial code to determine an API included in the initial code as an API to be confirmed; Comparing the API to be confirmed with each API included in the at least one API library to obtain a comparison result; According to the comparison result, the API to be confirmed hit in the at least one API library is determined, and according to the API to be confirmed hit in the at least one API library, the candidate API list is updated to determine the target API through the updated candidate API list.

[0011] Optionally, the large language model is used to generate target code for performing tasks required in the set domain, specifically including: Generate a code to be verified by using the large language model; Calling a preset compiler to execute the code to be verified and obtain an execution result; If it is determined according to the execution result that an error occurs during the execution of the code to be verified, then error information corresponding to the error that occurs is determined; The target code is generated by using the large language model according to the error information.

[0012] Optionally, generating the target code by using the large language model according to the error information specifically includes: The error information is input into the large language model, so that the large language model adjusts the code to be verified according to the error information to generate the target code.

[0013] Optionally, generating the target code by using the large language model according to the error information specifically includes: Determine, according to the error information, at least one error category corresponding to the error that occurred; For each error category, an API search instruction for searching an error corresponding to the error category is generated as a search instruction corresponding to the error category; According to the search instructions corresponding to each error category, the API that triggers the error corresponding to each error category is retrieved as the error reporting API; According to the error reporting API, API adjustment strategy information is determined, so as to generate the target code based on the API adjustment strategy information and through the large language model.

[0014] The present application provides a code generation device, including: A receiving module, used for receiving a user instruction, wherein the user instruction includes information for describing a function that can be realized by the code to be generated in a set domain; a determination module, configured to determine, according to the user instruction, each target API required for generating code from at least one pre-built application programming interface API library of the set domain; A generation module is used to determine the API description information corresponding to each target API, and input the API description information corresponding to each target API and the user instruction into a preset large language model, so as to generate a target code for executing the task required in the set field through the large language model.

[0015] An embodiment of the present application provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned code generation method is implemented.

[0016] An embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements a code generation method when executing the program.

[0017] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects: The code generation method provided in the embodiment of the present application, after receiving a user instruction containing information for describing the functions that can be implemented by the code to be generated in a set domain, can determine, according to the user instruction, each target API required for generating the code from at least one API library of the set domain that is pre-built, and then determine the API description information corresponding to each target API, and input the API description information corresponding to each target API and the user instruction into a preset large language model, so as to generate the target code for executing the tasks required in the set domain through the large language model.

[0018] It can be seen from the above method that, based on user instructions, matching target APIs can be quickly searched from the API library of the set domain, and the API description information of these target APIs can be input into the large language model. With the help of the powerful semantic analysis ability of the large language model, the corresponding target code can be generated based on the API description information of these target APIs and user instructions. This can not only greatly improve the efficiency of target code generation, but also effectively lower the threshold for generating proprietary domain code. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The drawings described herein are used to provide a further understanding of the present specification and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present specification and do not constitute an improper limitation on the present application. In the drawings: Figure 1 A flowchart of a code generation method provided in an embodiment of the present application; Figure 2 A schematic diagram of the entire serial connection process of a code generation provided in an embodiment of the present application; Figure 3 A schematic diagram of a code generation device provided in an embodiment of the present application; Figure 4 A method corresponding to the embodiment of the present application is provided Figure 1 Schematic diagram of the structure of an electronic device. DETAILED DESCRIPTION

[0020] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions of this specification will be clearly and completely described below in combination with the specific embodiments of this application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0021] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.

[0022] Figure 1 A flowchart of a code generation method provided in an embodiment of the present application includes the following steps: S101: receiving a user instruction, wherein the user instruction includes information for describing a function that can be implemented by a code to be generated in a set domain.

[0023] In an embodiment of the present application, in order to generate a target code used in a set field, a user may input a user instruction on the terminal device used, so that the terminal device executes a process of generating the target code based on the received user instruction.

[0024] Among them, the terminal device mentioned here can refer to electronic devices such as desktop computers, laptops, etc., or mobile electronic devices such as tablet computers. As for the generation process of the entire target code, it can also be executed by a server. Then, after the above-mentioned user enters a user instruction in the terminal device, the terminal device can send the user instruction to the server, and the server executes the subsequent target code generation process. Of course, the generation process of the entire target code can also be completed by a client installed in the terminal device. For the convenience of description, the following only takes the terminal device as the execution subject to describe the detailed process of a code generation method provided by an embodiment of the present application.

[0025] In an embodiment of the present application, the terminal device may display an information input interface to the user, in which the user may edit the user instruction and perform a confirmation operation based on his / her own needs, and the terminal device may receive the user instruction after responding to the confirmation operation. The user instruction mentioned here may include information for describing the functions that the code to be generated can achieve in the set field. For example, the user instruction may be a description statement that describes the functions that the code to be generated should have.

[0026] Of course, the user instruction may also refer to converting the above-mentioned description statement into instruction information executable by the terminal device. Therefore, after responding to the confirmation operation performed by the user in the above-mentioned information input interface, the terminal device can parse the information input by the user in the information input interface to generate the user instruction.

[0027] Furthermore, the above-mentioned setting field may refer to the astronomical field. Then, the target code generated by the method provided in the embodiment of the present application may refer to the code for performing tasks in the astronomical field. The target code can be used to perform tasks such as data statistics, data analysis, and celestial body identification in the astronomical field. Of course, the code generation method provided in the embodiment of the present application is actually a general method, and can also be applied to code generation in other fields (such as unmanned driving, medicine, financial management, etc.). For the sake of convenience, the following only takes the astronomical field as an example to describe the subsequent code generation process.

[0028] S102: According to the user instruction, determine each target API required for generating code from at least one pre-built application programming interface API library of the set domain.

[0029] After receiving the user instruction, the terminal device can parse it and generate a corresponding search instruction. Then, the terminal device executes the search instruction to determine the target APIs for generating the code required for the set field from at least one API library of a pre-built set field (i.e., the astronomical field).

[0030] At present, there are some data packages in the field of astronomy, such as Astropy and Astroquery, which contain APIs specially written for the field of astronomy. Therefore, the terminal device can first obtain these data packages through the above search instructions, and then extract these data packages to obtain various APIs, and build at least one API library in the field of astronomy.

[0031] For the process of determining the target API, the terminal device can extract the annotations of each API and obtain the description information of the API through methods such as regularization, and then input the API description information corresponding to each API contained in at least one API library into a preset feature expression model to perform feature extraction on the API description information corresponding to each API respectively to generate a feature representation vector corresponding to each API. At the same time, the terminal device can input user instructions into the feature expression model so that the feature expression model performs feature extraction on the user instructions to output a feature representation vector corresponding to the user instructions. The terminal device can then calculate the similarity between the feature representation vector corresponding to the user instruction and the feature representation vector corresponding to each API, so as to determine the target API required for generating code based on the calculated similarity between the feature representation vector corresponding to the user instruction and the feature representation vector corresponding to each API.

[0032] Among them, the feature expression model mentioned above is mainly used to convert the input information into a corresponding feature representation vector and output it. The feature expression model can be obtained by training with preset samples and labels alone, or by joint training with other models. The embodiment of the present application does not further limit the feature expression model, and it is mainly capable of realizing the feature extraction function and outputting the extracted feature representation vector.

[0033] Furthermore, since the API description information corresponding to each API may not necessarily be able to intuitively reflect the functions that the target code that the user needs to generate should have, if the feature representation vector corresponding to the user instruction is directly matched with the feature representation vector directly converted from the API description information of each candidate API, the matching result may not be able to accurately obtain the target API required for generating the code.

[0034] To this end, in an embodiment of the present application, the terminal device may first input the user instruction into a preset large language model, and the large language model may first determine, based on the user instruction, the step description information of each disassembly step that needs to be executed when generating the code required in the above-mentioned astronomical field. Afterwards, the large language model may output the determined step description information of each disassembly step, and then the terminal device may input the step description information of each disassembly step into the above-mentioned feature expression model, and determine the feature representation vector corresponding to the user instruction by determining the feature representation vector corresponding to the step description information of each disassembly step.

[0035] Among them, the various disassembly steps mentioned here are used to represent the various steps required to obtain the target code, such as generating a preparation environment, generating a basic code framework, generating the required kernel function, etc. The step description information of these disassembly steps can reflect the functions that the target code to be generated should have to a certain extent. On this basis, the above-mentioned feature expression model can respectively determine the feature representation vector corresponding to the step description information of each disassembly step, so that the terminal device can generate the feature representation vector corresponding to the user instruction based on the feature representation vector corresponding to the step description information of these disassembly steps.

[0036] In the embodiment of the present application, there are multiple ways to generate the feature representation vector corresponding to the user instruction. For example, the feature representation vectors corresponding to the step description information of the disassembly step can be spliced, and the feature representation vector obtained after splicing is used as the feature representation vector corresponding to the user instruction; for another example, the feature representation vectors corresponding to the step description information of the disassembly step can be averaged, and the feature representation vector obtained after averaging is used as the feature representation vector corresponding to the user instruction. Other methods are not described in detail here.

[0037] Since the feature representation vector corresponding to the user instruction determined based on the step description information of each disassembly step can further represent the contents of each step required to generate the target code, after matching the feature representation vector corresponding to the user instruction with the feature representation vector corresponding to each API contained in at least one API library, the accurate target API required to generate the target code can be obtained.

[0038] In order to further accurately screen out the target API required to generate the target code, the API determined by the terminal device from at least one API library in the above manner can actually be used as a candidate API, and the candidate API needs to be further verified to determine whether it is suitable as the target API required to generate the code.

[0039] Specifically, the terminal device can determine a candidate API list for generating the code required in the astronomy field from at least one pre-built API library in the astronomy field according to the user instruction, and the candidate API list records the API description information of each candidate API. Then, the terminal device can input the API description information corresponding to each candidate API included in the candidate API list and the user instruction into a preset large language model to obtain the initial code generated based on the user instruction through the large language model.

[0040] The terminal device may parse the initial code to determine the API contained in the initial code as the API to be confirmed. Then, the terminal device may compare the API to be confirmed with each API contained in at least one API library in the astronomy field, so as to determine the API to be confirmed that is hit in the at least one API library in the astronomy field according to the comparison result.

[0041] The terminal device can update the candidate API list according to the API to be confirmed hit in at least one API library in the astronomical field, and determine the target API for generating the code required in the astronomical field according to the updated candidate API list.

[0042] The above API comparison process can actually be regarded as a further recall of APIs in at least one API library in the field of astronomy. That is, after generating the initial code based on the candidate API, if the API parsed from the initial code belongs to the API contained in at least one API library in the field of astronomy, then it can be proved that the hit API belongs to the API that can realize the functions required by the target code.

[0043] In the above comparison process, the name of the API parsed from the initial code can be compared with the name of each API in at least one API library in the astronomical field to determine the API in the initial code that belongs to at least one API library as the hit API to be confirmed.

[0044] It should be emphasized that the above process is actually an iterative process, that is, the terminal device first generates the initial code according to the candidate API list, and then compares the API parsed from the initial code with the APIs contained in the at least one API in the astronomical field, and then updates the candidate API list, and then regenerates the code through the updated candidate API list, and then continues to parse the API from the regenerated code and continues to compare it with the APIs contained in the at least one API library in the astronomical field. The API contained in the API list obtained after multiple iterations can be used as the target API for generating the code required in the astronomical field.

[0045] There may be multiple conditions for terminating the iteration. For example, when the set iteration round is reached, the iteration termination condition may be considered satisfied. For another example, when the APIs hit from the API library in the previous and next iterations are the same, the iteration termination condition may be considered satisfied. Other iteration termination conditions are not described one by one here.

[0046] S103: Determine the API description information corresponding to each target API, and input the API description information corresponding to each target API and the user instruction into a preset large language model, so as to generate a target code for executing the task required in the set field through the large language model.

[0047] After determining the target API, the target code for executing the tasks required in the set field (i.e., the astronomy field) can be generated by the large language model. The large language model can directly generate and output the target code based on the user instructions and the target API.

[0048] In order to ensure that the target code finally generated can normally execute the tasks required in the astronomical field, in the embodiment of the present application, the terminal device can first generate the code to be verified according to the determined API, and then call the preset compiler to execute the code to be verified to obtain the execution result. Among them, the preset compiler needs to be pre-configured in the terminal device according to the programming language corresponding to the code to be verified.

[0049] Furthermore, if the terminal device determines, based on the execution result, that an error occurs during the execution of the code to be verified, it can determine error information corresponding to the error, and then generate the target code through a large language model based on the error information.

[0050] This process can be understood as adjusting the code generated by the large language model based on the error feedback mechanism or adjusting the determined target API, and then determining the final target code based on the adjustment results. This process can also be divided into two directions: one is to get the final target code by adjusting the API, and the other is to directly adjust the code to get the final target code.

[0051] For the method of directly adjusting the code, the terminal device can input the above error information into the large language model, so that the large language model adjusts the above code to be verified according to the error information to generate the target code.

[0052] That is, the large language model can analyze the specific problems in the code to be verified through the error information obtained, and then repair these problems through self-developed repair strategies to obtain the final target code.

[0053] As for the method of adjusting the API, the terminal device can determine at least one error category corresponding to the error that occurred based on the above error information, and then, for each error category, generate an API search instruction for retrieving the error corresponding to the error category as the search instruction corresponding to the error category. The terminal device can retrieve the API that causes the error corresponding to each error category based on the search instruction corresponding to each error category, as the error reporting API, and then determine the API adjustment strategy information based on the determined error reporting API, so as to generate the target code based on the API adjustment strategy information through the large language model.

[0054] The above-mentioned misalignment categories are used to reflect the types of API errors, such as import errors, value errors, attribute errors, etc. The terminal device retrieves the error APIs that cause each error category according to the search instructions generated for each error category as each error reporting API. Furthermore, the terminal device generates API adjustment strategy information for deleting or replacing these error reporting APIs based on these error reporting APIs, and generates target code through a large language model based on the API adjustment strategy information.

[0055] During this process, the terminal device can input the above API adjustment strategy information into the large language model, and the large language model adjusts the previously used API based on the adjustment strategy information, and generates the target code according to the adjusted API.

[0056] The terminal device can also adjust the candidate API list mentioned above according to the API adjustment policy information. After that, the terminal device can input the API description information and user instructions of the API included in the adjusted API list into the large language model to regenerate the target code through the large language model.

[0057] It should be noted that no matter which adjustment method is used, it may not be possible to obtain a target code without problems through one round of adjustment during the actual execution process, so multiple rounds of adjustments can be performed to obtain the final target code. Taking the first method as an example (i.e., the method of directly adjusting the code), after the terminal device obtains the error information, it can input the error information into the large language model. The large language model can adjust the code to be verified based on the error information, and re-run the adjusted code as the code to be verified. Then, the error information obtained by running the code to be verified is input into the large language model again, so that the large language model adjusts the code to be verified again based on the error information obtained. Through multiple rounds of adjustments, code that will not have problems running, that is, the target code, can be obtained.

[0058] It can be seen from the above method that, based on user instructions, matching target APIs can be quickly searched from the API library of the set domain, and the API description information of these target APIs can be input into the large language model. With the help of the powerful semantic analysis ability of the large language model, the corresponding target code can be generated based on the API description information of these target APIs and user instructions. This can not only greatly improve the efficiency of target code generation, but also effectively lower the threshold for generating proprietary domain code.

[0059] Moreover, whether in the process of determining the target API or the process of determining the target code, by executing multiple rounds of API comparison and error feedback mechanisms, the accurate target API can be iterated, as well as the target code that will run without problems. Therefore, through continuous iteration, not only the error correction capability of the large language model is improved, but also the smooth execution of subsequent tasks is further guaranteed.

[0060] It should be noted that, whether the terminal device runs the above-mentioned code to be verified or the terminal device runs the target code, if an operation error occurs, the terminal device can display the error information to the user so that the user can obtain the error information that occurs, as shown in the following table.

[0061] Table 1

[0062] In Table 1 above, the error category is used to reflect the type of error that occurs in the API, and the error type can be understood as a sub-classification of an error. The special search in Table 1 is used to prompt users how to find the API that has an error.

[0063] Based on the content shown in Table 1 above, the user can understand the problems in the generated code to be verified or the target code, and then enter corresponding prompt statements in the large language model (such as prompts about what errors exist in the generated code, based on what logic the API with the error should be located, etc.), so that the large language model can further adjust the generated code to obtain the final target code.

[0064] The above is the entire process of the code generation method provided in the embodiment of the present application. In order to further illustrate the execution process of the entire code generation, the code generation process will be described below with a series example of the entire process. Figure 2 shown.

[0065] Figure 2 A schematic diagram of the entire serial connection process of a code generation provided in an embodiment of the present application.

[0066] During the code generation process, the user can input user instructions into the terminal device, and the terminal device can input the user instructions into the large language model to generate a search plan for retrieving the corresponding API. This search plan is the large language model determining the various decomposition steps required to generate the code required for the set domain according to the user instructions.

[0067] The terminal device may execute step S1: API retrieval to retrieve candidate APIs matching the user instruction from an API library of a set domain and obtain a candidate API list.

[0068] The terminal device can input the API description information corresponding to each candidate API and the user instructions into the large language model based on the candidate API recorded in the candidate API list, and the large language model can generate a code to be verified (or an initial code) based on the input information.

[0069] Among them, the terminal device can first parse the initial code output by the large language model, and execute S2: API comparison step, that is, compare the APIs contained in the parsed initial code with the APIs contained in the API library, and then update the candidate API list according to the comparison results. After that, according to the API description information of the candidate API contained in the updated candidate API list and the user instructions, the corresponding code is generated again through the large language model, and the generated code is parsed again.

[0070] When the set iteration round is reached or the candidate API recorded in the candidate API list is no longer updated, the code to be verified can be generated through the large language model, and the code to be verified can be executed through a preset compiler.

[0071] If it is detected that a problem occurs during the execution of the code to be verified, it can be determined that the code to be verified fails to be executed, and the code to be verified can be regenerated by step S3: feedback optimization, and / or step S4: error information feedback.

[0072] In step S3, the terminal device may input the error information obtained by executing the code to be verified into the large language model, and the large language model may adjust the previously generated code to be verified according to the received error information to regenerate the code to be verified that needs to be verified.

[0073] In step S4, the terminal device can determine the error category of the error that occurs during the execution of the code to be verified through the obtained error information, and generate a search instruction for each error category. By executing the search instruction, the corresponding error reporting API can be retrieved from the API library, and the candidate API list can be updated (or adjusted) through the retrieved error reporting API, so as to regenerate the code to be verified according to each candidate API recorded in the updated candidate API list and the user instruction.

[0074] If no problem occurs during the execution of the code to be verified, the execution is determined to be successful, and the code output by the large language model is used as the final target code.

[0075] It should be noted that the above steps S3 and S4 can actually be performed at the same time, that is, the large language model can regenerate the code to be verified from the perspective of adjusting the code itself and adjusting the API required for generating the code. After repeated iterations, the target code that meets the requirements can be obtained.

[0076] In addition, in actual applications, in addition to retrieving the corresponding error reporting API from the API library according to the above retrieval instruction, the terminal device can also directly determine the corresponding error reporting API from the previously determined candidate APIs.

[0077] It should also be noted that after obtaining the above error information, the large language model can adjust the above-determined disassembly steps based on the error information, and the terminal device can regenerate the feature representation vector corresponding to the user instruction through the above-mentioned feature expression model based on the adjusted disassembly steps, thereby completing the subsequent process. Of course, the large language model can also further refine the above-determined disassembly steps based on the error information to obtain more detailed disassembly steps. These detailed steps can further clarify the various functions required by the target code, so that the terminal device can determine the feature representation vector corresponding to the user instruction through the above-mentioned feature expression model based on these more detailed disassembly steps to complete the subsequent process.

[0078] When the error message is input into the large language model, a corresponding prompt statement can be input into the large language model, so that the large language model determines whether to perform an adjustment operation on the disassembly step or a refinement operation on the disassembly step according to the prompt statement. In other words, the prompt statements used to guide the large language model to perform an adjustment operation on the disassembly step and to guide the large language model to perform a refinement operation on the disassembly step are different. The specific prompt statement can be set by the user or triggered by a preset rule.

[0079] For example, if the number of error messages obtained does not exceed the preset number threshold, it means that the overall problem of the code to be verified is not serious, and then a prompt statement can be used to guide the large language model to perform adjustments to the disassembly steps; for another example, if the number of error messages obtained exceeds the preset number threshold, it means that the overall problem of the code to be verified is relatively serious, and it is necessary to further clarify the various detailed steps required in the entire code generation process. Therefore, a prompt statement can be used to guide the large language model to perform detailed operations on the disassembly steps.

[0080] The above is a code generation method provided by one or more embodiments of the present application. Based on the same idea, the present application also provides a corresponding code generation device, such as Figure 3 shown.

[0081] Figure 3 A schematic diagram of a code generation device provided in an embodiment of the present application specifically includes: A receiving module 301 is used to receive a user instruction, wherein the user instruction includes information for describing the function that the code to be generated can achieve in a set domain; A determination module 302, configured to determine, according to the user instruction, target APIs required for code generation from at least one pre-built application programming interface API library of the set domain; The generation module 303 is used to determine the API description information corresponding to each target API, and input the API description information corresponding to each target API and the user instruction into a preset large language model to generate a target code for executing the task required in the set field through the large language model.

[0082] Optionally, the determination module 302 is specifically used to determine the feature representation vector corresponding to the user instruction through a preset feature expression model, and input the API description information corresponding to each API contained in the at least one API library into the feature expression model to determine each feature representation vector corresponding to each API contained in the at least one API library; and determine each target API required for generating code based on the similarity between the feature representation vector corresponding to the user instruction and the feature representation vector corresponding to each API contained in the at least one API library.

[0083] Optionally, the determination module 302 is specifically used to input the user instruction into the large language model so that the large language model determines, based on the user instruction, step description information of each decomposition step that needs to be executed when generating the code required for the set domain; and input the step description information of each decomposition step into the feature expression model to determine the feature representation vector corresponding to the user instruction.

[0084] Optionally, the determination module 302 is specifically used to determine, according to the user instruction, a candidate API list required for generating code from at least one application programming interface API library pre-built for the set domain; input the API description information corresponding to each candidate API contained in the candidate API list and the user instruction into the large language model, so as to obtain the initial code generated based on the user instruction through the large language model; parse the initial code to determine the API contained in the initial code as the API to be confirmed; compare the API to be confirmed with each API contained in the at least one API library to obtain a comparison result; determine the API to be confirmed hit in the at least one API library according to the comparison result, and update the candidate API list according to the API to be confirmed hit in the at least one API library, so as to determine the target API through the updated candidate API list.

[0085] Optionally, the generation module 303 is specifically used to generate the code to be verified through the large language model; call a preset compiler to execute the code to be verified and obtain an execution result; if it is determined according to the execution result that an error occurs during the execution of the code to be verified, then determine the error information corresponding to the error; based on the error information, generate the target code through the large language model.

[0086] Optionally, the generating module 303 is specifically configured to input the error information into the large language model, so that the large language model adjusts the code to be verified according to the error information to generate the target code.

[0087] Optionally, the generation module 303 is specifically used to determine, based on the error information, at least one error category corresponding to the error that occurred; for each error category, generate an API retrieval instruction for retrieving an error corresponding to that error category as a retrieval instruction corresponding to that error category; according to the retrieval instruction corresponding to each error category, retrieve the API that triggers the error corresponding to each error category as an error reporting API; according to the error reporting API, determine API adjustment strategy information, so as to generate the target code based on the API adjustment strategy information through the large language model.

[0088] The present application also provides a computer-readable storage medium, which stores a computer program, which can be used to execute the above Figure 1 A code generation method is provided.

[0089] The present application also provides Figure 4 The schematic structure diagram of the electronic device shown in FIG. Figure 4 As shown, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 The code generation method described.

[0090] Of course, in addition to software implementation, this application does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the executor of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0091] In the 1990s, it was very clear whether the improvement of a technology was hardware improvement (for example, improvement of the circuit structure of diodes, transistors, switches, etc.) or software improvement (improvement of the method flow). However, with the development of technology, many improvements of the method flow today can be regarded as direct improvements of the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that the improvement of a method flow cannot be implemented with hardware entity modules. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask chip manufacturers to design and make dedicated integrated circuit chips. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one kind of HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages ​​and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.

[0092] The controller may be implemented in any suitable manner, for example, the controller may take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (e.g., software or firmware) executable by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, and the memory controller may also be implemented as part of the control logic of the memory. It is also known to those skilled in the art that, in addition to implementing the controller in a purely computer-readable program code manner, the controller may be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, such a controller may be considered as a hardware component, and the devices for implementing various functions included therein may also be considered as structures within the hardware component. Or even, the devices for implementing various functions may be considered as both software modules for implementing the method and structures within the hardware component.

[0093] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0094] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0095] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0096] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0097] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0098] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0099] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0100] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0101] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0102] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0103] It should be understood by those skilled in the art that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0104] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0105] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0106] The above description is only an embodiment of the present specification and is not intended to limit the present specification. For those skilled in the art, the present specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification shall be included in the scope of the claims of the present specification.

Claims

1. A code generation method, characterized in that: include: receiving a user instruction, wherein the user instruction includes information for describing a function that the code to be generated can implement in a set domain; According to the user instruction, determining each target API required for generating code from at least one pre-built application programming interface API library of the set domain; Determine the API description information corresponding to each target API, and input the API description information corresponding to each target API and the user instruction into a preset large language model, so as to generate a target code for executing the task required in the set field through the large language model.

2. The method according to claim 1, characterized in that According to the user instruction, each target API required for generating code is determined from at least one application programming interface API library pre-built in the set domain, specifically including: Determine a feature representation vector corresponding to the user instruction through a preset feature expression model, and input API description information corresponding to each API included in the at least one API library into the feature expression model to determine each feature representation vector corresponding to each API included in the at least one API library; According to the similarity between the feature representation vector corresponding to the user instruction and the feature representation vector corresponding to each API included in the at least one API library, each target API required for generating the code is determined.

3. The method according to claim 2, characterized in that Determining a feature representation vector corresponding to the user instruction through a preset feature expression model specifically includes: Inputting the user instruction into the large language model, so that the large language model determines, according to the user instruction, step description information of each disassembly step that needs to be performed when generating the code required by the set domain; The step description information of each disassembly step is input into the feature expression model to determine the feature representation vector corresponding to the user instruction.

4. The method according to claim 1, characterized in that According to the user instruction, each target API required for generating code is determined from at least one application programming interface API library pre-built in the set domain, specifically including: According to the user instruction, determining a candidate API list required for code generation from at least one pre-built application programming interface API library of the set domain; Inputting API description information corresponding to each candidate API included in the candidate API list and the user instruction into the large language model, so as to obtain an initial code generated based on the user instruction through the large language model; Parsing the initial code to determine an API included in the initial code as an API to be confirmed; Comparing the API to be confirmed with each API included in the at least one API library to obtain a comparison result; According to the comparison result, the API to be confirmed hit in the at least one API library is determined, and according to the API to be confirmed hit in the at least one API library, the candidate API list is updated to determine the target API through the updated candidate API list.

5. The method according to claim 1, characterized in that Generate target code for executing tasks required in the set domain through the large language model, specifically including: Generate a code to be verified by using the large language model; Calling a preset compiler to execute the code to be verified and obtain an execution result; If it is determined according to the execution result that an error occurs during the execution of the code to be verified, then error information corresponding to the error that occurs is determined; The target code is generated by using the large language model according to the error information.

6. The method according to claim 5, characterized in that Generating the target code according to the error information by using the large language model specifically includes: The error information is input into the large language model, so that the large language model adjusts the code to be verified according to the error information to generate the target code.

7. The method according to claim 5, characterized in that Generating the target code according to the error information by using the large language model specifically includes: Determine, according to the error information, at least one error category corresponding to the error that occurred; For each error category, an API search instruction for searching an error corresponding to the error category is generated as a search instruction corresponding to the error category; According to the search instructions corresponding to each error category, the API that triggers the error corresponding to each error category is retrieved as the error reporting API; According to the error reporting API, API adjustment strategy information is determined, so as to generate the target code based on the API adjustment strategy information and through the large language model.

8. A code generating device, characterized in that: include: A receiving module, used for receiving a user instruction, wherein the user instruction includes information for describing a function that can be realized by the code to be generated in a set domain; a determination module, configured to determine, according to the user instruction, each target API required for generating code from at least one pre-built application programming interface API library of the set domain; A generation module is used to determine the API description information corresponding to each target API, and input the API description information corresponding to each target API and the user instruction into a preset large language model, so as to generate a target code for executing the task required in the set field through the large language model.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of claims 1 to 7 is implemented.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Model-based code generation method and device, storage medium and electronic equipment

    CN117873453A

  • Code generation method based on large language model, medium and equipment

    CN118363580A

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

    CN118778939A

  • Front-end API (Application Program Interface) service code generation method and device, equipment and storage medium

    CN119415100A

  • Generate custom client library samples based on a machine readable API description

    US8510762B1