Code generation method and device, electronic equipment, storage medium and program product
By parsing natural language descriptions to obtain key parameters and querying code parameters from private databases or knowledge bases, code that meets user needs is generated. This solves the problem that existing tools cannot access the enterprise's internal private code, and improves the efficiency and accuracy of code generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INNER MONGOLIA NEW VISION GROUP CO LTD
- Filing Date
- 2026-01-05
- Publication Date
- 2026-06-05
AI Technical Summary
Existing code generation tools cannot access a company's internal proprietary code, forcing developers to manually memorize a large number of internal coding rules, increasing their workload and making them prone to coding errors.
By parsing the natural language description of the target user to obtain key parameters, and querying the corresponding code parameters from a private database or private knowledge base, code that meets the user's needs is generated.
It improves the efficiency and accuracy of code generation, solves the problem that general tools cannot access private code within an enterprise, and reduces the workload of developers and coding errors.
Smart Images

Figure CN122152283A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code generation method, apparatus, electronic device, storage medium, and program product. Background Technology
[0002] With the continuous development of Large Language Models (LLMs), code generation tools developed using LLMs can generate corresponding code based on natural language descriptions, helping developers improve coding efficiency.
[0003] However, currently available code generation tools can only access publicly available code and cannot access proprietary code within an enterprise. When developers within an enterprise need to access proprietary code to complete specific development tasks, these code generation tools cannot obtain the correspondence between specific industry terminology and the enterprise's internal code, resulting in the inability to obtain the correct code.
[0004] Therefore, in the process of generating code involving the enterprise's internal professional fields, developers still need to manually memorize a large number of internal coding rules. This not only increases the workload of developers, but also easily leads to coding errors due to memory bias, resulting in reduced coding efficiency. Summary of the Invention
[0005] This application provides a code generation method, apparatus, electronic device, storage medium, and program product, which can improve code generation efficiency.
[0006] In a first aspect, embodiments of this application provide a code generation method, comprising: obtaining a natural language description of a target user, the natural language description being used to characterize the target user's code generation requirements; parsing the natural language description to obtain key parameters; and querying code parameters corresponding to the key parameters from a private database or private knowledge base based on the key parameters, so as to generate a first target code based on the code parameters.
[0007] Optionally, based on the key parameters, the code parameters corresponding to the key parameters are queried from a private database or private knowledge base to generate the first target code based on the code parameters. This includes: generating a query statement based on the key parameters, and querying the first code parameters corresponding to the key parameters from the private database based on the query statement; when the first code parameters are found, generating the first target code based on the first code parameters.
[0008] Optionally, based on the key parameters, the code parameters corresponding to the key parameters are queried from a private database or private knowledge base to generate the first target code. The method also includes: when the first code parameter is not found, based on the key parameters, the second code parameter corresponding to the key parameters is queried from the private knowledge base to generate the first target code.
[0009] Optionally, based on the key parameters, the second code parameters corresponding to the key parameters are queried from the private knowledge base, including: vectorizing the key parameters to obtain parameter vectors, and vectorizing the fragments in the private knowledge base to obtain fragment vectors; calculating the similarity between the parameter vectors and fragment vectors, and filtering out target fragments with similarity greater than the similarity threshold to obtain the second code parameters corresponding to the target fragments, wherein the target fragments are one or more fragments in the private knowledge base.
[0010] Optionally, the natural language description is parsed to obtain key parameters, including: performing intent recognition on the natural language description to obtain intent recognition results, and extracting user intent and key parameters from the intent recognition results.
[0011] Optionally, generating the first target code based on code parameters includes: determining a code template based on user intent and filling the code parameters into the code template to generate the first target code.
[0012] Optionally, after generating the first target code based on the code parameters, the method further includes: retrieving the analysis steps corresponding to the user intent from the private knowledge base and querying the analysis code corresponding to the analysis steps; merging the analysis code with the first target code to obtain the second target code.
[0013] Optionally, based on the key parameter, query the code parameter corresponding to the key parameter from a private database or private knowledge base to generate the first target code based on the code parameter, including: when a key parameter corresponds to at least two code parameters, in response to the target user's selection operation, determine the target code parameter that uniquely corresponds to the key parameter; generate the first target code based on the target code parameter, where the selection operation is the operation of the target user selecting one of the at least two code parameters as the target code parameter.
[0014] Secondly, embodiments of this application provide a code generation apparatus, comprising: an acquisition module for acquiring a natural language description of a target user, the natural language description being used to characterize the target user's code generation requirements; a parsing module for parsing the natural language description to obtain key parameters; and a query module for querying code parameters corresponding to the key parameters from a private database or private knowledge base, based on the key parameters, to generate a first target code based on the code parameters.
[0015] Thirdly, embodiments of this application provide an electronic device, including a processor and a memory storing program instructions, wherein the processor is configured to execute the code generation method described above when running the program instructions.
[0016] Fourthly, embodiments of this application provide a storage medium storing program instructions, wherein the program instructions, when executed, perform the code generation method described above.
[0017] Fifthly, embodiments of this application provide a computer program product, including a computer program, which, when executed by a processor, implements the code generation method described above.
[0018] The code generation method provided in this application parses the natural language description of the target user to obtain key parameters, and then queries the corresponding code parameters from a private database or private knowledge base based on the key parameters. Finally, it generates code that meets the user's needs based on the code parameters. This approach parses the target user's requirement to generate private code, obtains the key parameters needed for code generation, and then fully utilizes the private code resources in the private database and private knowledge base to query the code parameters corresponding to the key parameters. This generates executable code that can run within the enterprise, effectively solving the problem that general code generation tools cannot access the enterprise's internal private code and improving code writing efficiency. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart of a code generation method provided in an embodiment of this application; Figure 2 This is a schematic diagram of an embodiment of the code generation method provided in this application; Figure 3 This is a schematic diagram of a code generation apparatus provided in an embodiment of this application; Figure 4 This is a schematic diagram of the electronic device provided in the embodiments of this application. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0022] It should be understood that the described embodiments are merely some, not all, of the embodiments in this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.
[0023] In the following description, when referring to the accompanying drawings, the same numbers in different drawings denote the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0024] In the description of this application, it should be understood that the terms "first," "second," "third," etc., are used only to distinguish similar objects and are not necessarily used to describe a specific order or sequence, nor should they be construed as indicating or implying relative importance. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances. Furthermore, in the description of this application, unless otherwise stated, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0025] In related technologies, code generation tools developed using large language models, such as Microsoft's Copilot and iFlytek's iFlytek Lingma, can assist users in writing code based on publicly available code resources. However, when dealing with users' internal code generation needs, these tools cannot directly access or parse the enterprise's private database table structure and coding rules. Therefore, when internal developers use general-purpose code generation tools to generate private code, these tools cannot obtain the correspondence between specific industry terminology and the enterprise's internal code, thus failing to generate correct code that meets the enterprise's actual needs.
[0026] Taking the wind power sector as an example, wind power data analysis relies on internal private data sources. These private data sources include SCADA (Supervisory Control and Data Acquisition) systems that collect wind turbine data in real time, and wind farm information tables that record details for each wind farm. Within these private data sources, standardized variable names are defined for wind power-related technical terms such as "wind speed" and "blade angle," for example, using "WTG_WindSpeed" to represent "wind speed." However, general-purpose code generation tools cannot access these private data sources. Therefore, when developers input the requirement "Analyze the wind speed data of XX wind farm," the code generation tool cannot recognize that the internal variable name corresponding to "wind speed" is "WTG_WindSpeed," and thus cannot correctly generate private code specific to the wind power sector.
[0027] Because the correct proprietary code cannot be directly obtained, developers need to spend a lot of time and effort manually searching for and memorizing a large number of API parameters. For example, when a developer needs to write code to "query the average wind speed of wind field XX", the developer needs to memorize the ID of each wind field. This not only increases the workload of developers, but also easily leads to coding errors due to memory bias, thereby reducing coding efficiency.
[0028] Based on this, embodiments of this application provide a code generation method, apparatus, electronic device, storage medium, and program product. By parsing the natural language description of the target user to obtain key parameters, and then querying corresponding code parameters from a private database or private knowledge base based on these key parameters, code that meets the user's needs is ultimately generated. This effectively solves the problem that general-purpose coding tools cannot access internal enterprise private code, thus improving coding efficiency.
[0029] The subject of this application is an electronic device, such as a server, laptop, desktop computer, mobile phone, tablet computer, etc., and the embodiments of this application are not limited thereto.
[0030] The code generation method of this application embodiment will now be described in detail. For example, please refer to... Figure 1 , Figure 1 This is a flowchart illustrating a code generation method provided in an embodiment of this application. This embodiment includes: S101: Obtain the natural language description of the target user, which is used to characterize the target user's code generation requirements.
[0031] In this embodiment, a user (i.e., the target user) inputs a natural language description that expresses their code generation needs into the electronic device. This natural language description can be in text or speech form. If it is in speech form, the electronic device can first use speech recognition technology to convert it into text form for subsequent parsing.
[0032] For example, if a target user wants to generate code to query wind speed data for wind farm A in 2024, their input in natural language could be "Generate code to query wind speed data for wind farm A in 2024" or "I want to query wind speed data for wind farm A in 2024". Similarly, if a target user wants to generate code to download power data for wind turbine #2 in wind farm A in 2025, their input in natural language could be "Generate code to download power data for wind turbine #2 in wind farm A in 2025" or "Download power data for wind turbine #2 in wind farm A in 2025".
[0033] S102: Parse the natural language description to obtain key parameters.
[0034] In this embodiment, after receiving the natural language description input by the target user, the electronic device parses it using a natural language processing model, such as large language models or entity recognition, to extract key parameters from the natural language description. For example, in the wind power field, the extracted key parameters may include the wind farm name, wind turbine number, time range, data type, etc.
[0035] For example, taking the natural language description input by the target user "Download wind speed data for wind turbine No. 1 of Shanghai Wind Farm in 2024" as an example, the key parameters extracted include: Shanghai Wind Farm, wind turbine No. 1, 2024-1-1, 2024-12-30, wind speed, etc. Taking the natural language description input by the target user "Plot fault data for wind turbine No. 1 of Shanghai Wind Farm in 2024" as another example, the key parameters extracted include: Shanghai Wind Farm, wind turbine No. 1, 2024-1-1, 2024-12-30, fault, etc.
[0036] S103: Based on the key parameters, query the code parameters corresponding to the key parameters from the private database or private knowledge base, so as to generate the first target code based on the code parameters.
[0037] In this embodiment, a private database refers to a database used internally by an enterprise or organization and not publicly disclosed, typically a relational database such as MySQL. The private database is primarily used to store structured internal business data. A private knowledge base refers to a knowledge base used internally by an enterprise or organization and not publicly disclosed, used to store unstructured / semi-structured knowledge, such as terminology within a specific field or company, and proprietary code. After the electronic device extracts key parameters from the natural language description, it queries the private database or private knowledge base based on these key parameters to find code parameters that match them. Once the code parameters are obtained, the electronic device generates code that meets the target user's needs based on these parameters.
[0038] Specifically, after obtaining the key parameters, the electronic device first performs a precise query in the private database. This involves finding the corresponding code parameter based on the mapping relationship between database entities and code parameters within the private database. For example, if the key parameter is "Weihai No. 1 Wind Farm," the corresponding code parameter in the private database is "farm-001." If no code parameter matching the key parameter is found in the private database, a fuzzy query is then performed in the private knowledge base, searching for knowledge base fragments similar to the key parameter. For instance, if the identified key parameter is "Guangling Wind Farm," and the private knowledge base stores a knowledge base fragment for "Shanxi Guangling," the electronic device can use algorithms such as semantic similarity to determine their similarity and thus obtain the code parameter related to "Shanxi Guangling."
[0039] The code generation method provided in this application parses the natural language description of the target user to obtain key parameters, and then queries the corresponding code parameters from a private database or private knowledge base based on the key parameters. Finally, it generates code that meets the user's needs based on the code parameters. This approach parses the target user's requirement to generate private code, obtains the key parameters related to private data sources needed for code generation, and then fully utilizes private code resources in the private database and private knowledge base to query the code parameters corresponding to the key parameters. This generates executable code that can run within the enterprise, effectively solving the problem that general code generation tools cannot access internal enterprise private code and improving code writing efficiency.
[0040] Optionally, in the above embodiments, during the process of generating the first target code based on the code parameters by querying the code parameters corresponding to the key parameters from a private database or private knowledge base according to the key parameters, the electronic device generates a query statement based on the key parameters and queries the first code parameters corresponding to the key parameters from the private database according to the query statement. When the first code parameters are found, the first target code is generated according to the first code parameters.
[0041] In this embodiment, refer to Figure 2 The above, Figure 2 This is a schematic diagram of an embodiment of the code generation method provided in this application. After obtaining the key parameters, the electronic device uses the NL2SQL (Natural Language to SQL) model to generate a query statement, such as an SQL query statement, based on the key parameters. This query statement is used to query the code parameter corresponding to the key parameters in a private database. By executing the query statement in the private database, a first code parameter that precisely matches the key parameters can be obtained. For example, if the key parameter is "Weihai No. 1 Wind Farm", then by querying the private database, the code parameter "farm-001" corresponding to the database entity "Weihai No. 1 Wind Farm" is found, which is the first code parameter corresponding to the key parameter.
[0042] This approach utilizes the NL2SQL model to quickly generate query statements based on key parameters, which can then be used to perform precise queries in a private database, efficiently retrieving the code parameters corresponding to the key parameters.
[0043] Optionally, in the above embodiments, during the process of generating the first target code by querying the code parameters corresponding to the key parameters from a private database or private knowledge base based on the key parameters, if the first code parameters are not found, the electronic device queries the second code parameters corresponding to the key parameters from the private knowledge base based on the key parameters, so as to generate the first target code based on the second code parameters.
[0044] In this embodiment, the private knowledge base stores a large amount of domain knowledge, terminology explanations, and proper noun fragments, etc., and continues to refer to... Figure 2 When the electronic device fails to find a first code parameter that precisely matches the key parameter in the private database, it further searches the private knowledge base using the key parameter. During this process, the electronic device searches for segments similar to the key parameter based on the semantic similarity between the key parameter and segments in the knowledge base, thereby obtaining the second code parameter corresponding to that segment.
[0045] Specifically, during the process of querying the second code parameter corresponding to the key parameter from the private knowledge base based on the key parameter, the electronic device vectorizes the key parameter to obtain a parameter vector, and vectorizes the fragments in the private knowledge base to obtain fragment vectors. Then, the electronic device calculates the similarity between the parameter vector and the fragment vector, and filters out target fragments with a similarity greater than a similarity threshold to obtain the second code parameter corresponding to the target fragment. The target fragments are one or more fragments from the private knowledge base.
[0046] In this embodiment, a vectorization model can be used to vectorize the key parameters and various fragments in the private knowledge base, converting text data into vectors, ultimately yielding parameter vectors and fragment vectors. The electronic device then calculates the similarity between the parameter vectors and each fragment vector, using methods such as cosine similarity or Euclidean distance, and pre-sets a similarity threshold, selecting fragments with similarity greater than the threshold as target fragments. The higher the similarity between a fragment and the key parameter, the closer the fragment's semantics are to the key parameter. Furthermore, the electronic device can find proper nouns or terms semantically similar to the key parameter and further obtain their corresponding code parameters, i.e., the second code parameters.
[0047] This approach allows for the identification of semantically similar segments when the private database fails to find a first code parameter that precisely matches the key parameter. By employing this method, a fuzzy search in the private knowledge base can be used to find segments that are semantically similar to the key parameter, thereby obtaining the corresponding second code parameter. This effectively expands the ways to obtain code parameters and improves the success rate and accuracy of code generation.
[0048] Optionally, in the above embodiments, during the process of generating target code based on key parameters by querying code parameters corresponding to key parameters from a private database or private knowledge base, when a key parameter corresponds to at least two code parameters, in response to the target user's selection operation, the target code parameter uniquely corresponding to the key parameter is determined, and then the first target code is generated based on the target code parameter. The selection operation is the operation by which the target user selects one of the at least two code parameters as the target code parameter.
[0049] In this embodiment, when querying code parameters in a private database or private knowledge base, there may be a situation where a single key parameter query yields multiple code parameters. In one scenario, during the process of querying the first code parameter corresponding to a key parameter from a private database, there may be a situation where one key parameter corresponds to multiple first code parameters. For example, if the key parameter is "Weihai No. 1 Wind Farm," due to different naming conventions in different regions, the private database may store multiple database entities for "Weihai No. 1 Wind Farm," each corresponding to a different first code parameter. When a key parameter is found to correspond to at least two first code parameters, the electronic device responds to the target user's selection operation and determines the target code parameter uniquely corresponding to that key parameter. This selection operation involves the target user choosing one of the at least two first code parameters as the target code parameter.
[0050] In another scenario, during the process of querying the second code parameter corresponding to a key parameter from a private knowledge base, segments with a similarity greater than a similarity threshold are selected as target segments. There may be multiple segments with a similarity greater than the threshold. For example, if the key parameter is "Guangling wind farm," the selected segments with a similarity greater than the threshold include "Shanxi Guangling," "Guangling wind farm," and "Guangling wind power station," each corresponding to a second code parameter. This means there may be a situation where one key parameter corresponds to multiple second code parameters. When a key parameter corresponds to at least two second code parameters, the electronic device responds to the target user's selection operation and determines the target code parameter uniquely corresponding to that key parameter. This selection operation involves the target user choosing one of the at least two second code parameters as the target code parameter.
[0051] In this embodiment, to address the scenario where a single key parameter may correspond to multiple code parameters (the code parameter refers to either the first code parameter or the second code parameter), the electronic device, after retrieving at least two code parameters, displays these multiple code parameters to the target user through an interactive interface. The target user then selects one of the multiple code parameters as the target code parameter based on their actual needs. After the target user completes their selection, the electronic device responds by determining the code parameter uniquely corresponding to the key parameter as the target code parameter, and generates target code based on this target code parameter.
[0052] By adopting this approach, when a key parameter corresponds to multiple code parameters, allowing the target user to make a selection ensures that the final generated target code accurately matches the target user's actual needs. This avoids the problem of generating incorrect code due to a key parameter corresponding to multiple code parameters, thus improving the accuracy of code generation.
[0053] Optionally, in the above embodiments, during the process of parsing the natural language description to obtain key parameters, the electronic device performs intent recognition on the natural language description to obtain intent recognition results, and extracts the user intent and the key parameters from the intent recognition results.
[0054] In this embodiment, after receiving a natural language description from a target user, the electronic device uses a natural language processing model to perform intent recognition, obtaining intent recognition results to clarify the target user's code generation needs. The user intent and key parameters are then extracted from the intent recognition results. The user intent indicates what purpose the target user wants to achieve by generating code, such as data downloading, data analysis, or chart drawing. For example, taking the target user's input natural language description, "Help me generate a piece of code to draw a statistical chart of fault data for Wind Turbine No. 1 of Weihai Wind Farm in 2024," the intent recognition result obtained is: "Draw a statistical chart of fault data for Wind Turbine No. 1 of Weihai Wind Farm in 2024." The extracted user intent includes: "Download fault data" and "Draw a statistical chart." The extracted key parameters include: Weihai Wind Farm, Wind Turbine No. 1, 2024-1-1, 2024-12-30, and fault. For example, taking the natural language description input by the target user, "Help me generate a code to query the wind speed data of wind farm A in 2024", the intent recognition result obtained through intent recognition is: "Query the wind speed data of wind farm A in 2024". The user intent extracted from this is "Query wind speed data", and the key parameters extracted include: wind farm A, 2024-1-1, 2024-12-30, wind speed, etc.
[0055] This approach, by performing intent recognition on natural language descriptions, can accurately grasp the code generation needs of target users and precisely extract user intent and key parameters from complex descriptions, providing a clear direction for subsequent code generation.
[0056] Optionally, in the above embodiments, during the process of generating the first target code based on the code parameters, the electronic device determines the code template according to the user's intention and fills the code parameters into the code template to generate the first target code.
[0057] In this embodiment, the electronic device pre-stores code templates that match different user intents. These templates can be quickly used to generate usable code by filling in code parameters. When the electronic device receives a user intent, it searches for a code template that matches it and fills in the code parameters corresponding to the found key parameters. For example, if the user intent is "query wind speed data," the electronic device will select a code template related to querying wind speed data and fill in the code parameters corresponding to the required key parameters, such as the wind field name, to generate the first target code for querying wind speed data.
[0058] This approach, which determines the code template based on user intent and generates code by filling in code parameters, can improve the efficiency and accuracy of code generation while reducing its complexity.
[0059] It's worth noting that for some commonly used code with fixed requirements, code can be generated by filling code parameters into a code template. Alternatively, a fixed code template can be avoided, allowing for open-ended code generation based on user intent and key parameters. For example, a large model can be used to generate code that meets the requirements based on user intent and key parameters. This open-ended code generation method offers a high degree of freedom and can meet more diverse code generation needs.
[0060] Optionally, in the above embodiments, after the electronic device generates the first target code according to the code parameters, the electronic device retrieves the analysis steps corresponding to the user intent from the private knowledge base, queries the analysis code corresponding to the analysis steps, and then merges the analysis code with the first target code to obtain the second target code.
[0061] In this embodiment, when the user's intent includes not only downloading or querying data but also data analysis, after generating the first target code, the electronic device further searches its private knowledge base to find the analysis steps corresponding to the user's intent, in order to make the generated code more complete and applicable to more complex business scenarios. These analysis steps are stored in text form in the historical analysis library of the private knowledge base. The historical analysis library stores the analysis steps used in past data analysis, recording how data analysis was performed after data acquisition. For example, if the user's intent includes "downloading wind speed data" and "drawing a wind rose diagram," the electronic device selects a code template related to downloading wind speed data, fills in the required code parameters into the code template, and generates the first target code for downloading wind speed data. Then, the electronic device searches the historical analysis library for analysis steps related to drawing a wind rose diagram, such as data cleaning, data grouping, data aggregation, and chart drawing.
[0062] After retrieving the analysis step corresponding to the user intent, the electronic device further queries the private knowledge base for the corresponding code (i.e., analysis code). Once the electronic device obtains the analysis code, it merges it with the previously generated first target code to obtain the final executable code (i.e., second target code). For example, after generating the first target code for downloading wind speed data, the electronic device determines the corresponding analysis step based on the user intent of "drawing a wind rose diagram," retrieves the analysis code corresponding to that step, and merges it with the first target code to obtain the final second target code that can be used to draw a wind rose diagram. In summary, the merged second target code not only contains the basic code for data downloading or querying but also the code for further data analysis.
[0063] This approach, by further merging and analyzing the generated first target code, can generate a second target code with more comprehensive functions, effectively meeting users' code generation needs in complex business scenarios.
[0064] Optionally, in the above embodiments, during the process of the electronic device retrieving the analysis steps corresponding to the user intent from the private knowledge base, the electronic device first vectorizes the user intent and each analysis step in the historical analysis database. Then, it calculates the similarity between the vectors of the user intent and each analysis step, and selects the target analysis step as the analysis step corresponding to the user intent based on the similarity. Specifically, the analysis step with the highest similarity can be directly selected as the target analysis step, or multiple analysis steps with similarity greater than a preset threshold can be selected first, and then the target analysis step can be selected from the multiple analysis steps.
[0065] It is worth noting that, since there may be some discrepancy between the analysis steps retrieved from the historical analysis database and the actual needs of the target user, optionally, to ensure the accuracy of the analysis steps, after retrieving the analysis steps corresponding to the user's intent, the electronic device inputs the target user's natural language description and the analysis steps into a large language model. The large language model then optimizes the analysis steps based on the target user's specific needs to obtain optimized analysis steps. For example, if the retrieved analysis steps are based on hourly data, but the target user actually needs analysis steps for minute-level data, the large language model can be used to adjust the analysis steps to obtain analysis steps specifically for minute-level data, which better suits the target user's actual needs. Furthermore, the electronic device obtains the analysis code corresponding to the optimized analysis steps.
[0066] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0067] Figure 3 This is a schematic diagram of a code generation device provided in an embodiment of this application. The device 300 includes: an acquisition module 31, a parsing module 32, and a query module 33.
[0068] The acquisition module 31 is used to acquire the natural language description of the target user, which is used to characterize the target user's code generation requirements.
[0069] Parsing module 32 is used to parse the natural language description to obtain key parameters.
[0070] The query module 33 is used to query the code parameters corresponding to the key parameters from a private database or private knowledge base, so as to generate the first target code based on the code parameters.
[0071] In one feasible implementation, the query module 33 queries the code parameters corresponding to the key parameters from a private database or private knowledge base based on the key parameters. When generating the first target code based on the code parameters, it generates a query statement based on the key parameters and queries the first code parameters corresponding to the key parameters from the private database based on the query statement. When the first code parameters are found, the first target code is generated based on the first code parameters.
[0072] In one feasible implementation, when the query module 33 queries the code parameters corresponding to the key parameters from a private database or private knowledge base to generate the first target code based on the code parameters, it is also used to query the second code parameters corresponding to the key parameters from the private knowledge base to generate the first target code based on the second code parameters when the first code parameters are not found.
[0073] In one feasible implementation, when the query module 33 queries the second code parameter corresponding to the key parameter from the private knowledge base based on the key parameter, it is used to vectorize the key parameter to obtain a parameter vector, and to vectorize the fragment in the private knowledge base to obtain a fragment vector; calculate the similarity between the parameter vector and the fragment vector, and filter out the target fragment with a similarity greater than the similarity threshold to obtain the second code parameter corresponding to the target fragment, wherein the target fragment is one or more fragments in the private knowledge base.
[0074] In one feasible implementation, the parsing module 32 parses the natural language description and obtains key parameters, then performs intent recognition on the natural language description to obtain intent recognition results, and extracts user intent and key parameters from the intent recognition results.
[0075] In one feasible implementation, when the query module 33 generates the first target code based on the code parameters, it determines the code template according to the user's intent and fills the code parameters into the code template to generate the first target code.
[0076] In one feasible implementation, after the query module 33 generates the first target code based on the code parameters, it is further used to retrieve the analysis steps corresponding to the user intent from the private knowledge base and query the analysis code corresponding to the analysis steps; the analysis code is then merged with the first target code to obtain the second target code.
[0077] In one feasible implementation, the query module 33 queries the code parameters corresponding to the key parameters from a private database or private knowledge base based on the key parameters. When generating the first target code based on the code parameters, it is used to determine the target code parameter uniquely corresponding to the key parameter in response to the target user's selection operation when a key parameter corresponds to at least two code parameters. The first target code is generated based on the target code parameter. The selection operation is the operation of the target user selecting one of the at least two code parameters as the target code parameter.
[0078] The code generation apparatus provided in this application embodiment is used to execute the code generation method in the above embodiment. Its implementation principle and technical effect are similar, and will not be described again here.
[0079] Combination Figure 4 As shown, this application embodiment provides an electronic device 400, including a processor 401 and a memory 402. Optionally, the device may further include a communication interface 403 and a bus 404. The processor 401, memory 402, and communication interface 403 can communicate with each other via the bus 404. The communication interface 403 can be used for information transmission. The processor 401 can call logical instructions in the memory 402 to execute the code generation method described in the above embodiment.
[0080] Furthermore, the logical instructions in the aforementioned memory 402 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium.
[0081] The memory 402, as a computer-readable storage medium, can be used to store software programs and computer-executable programs, such as program instructions / modules corresponding to the methods in the embodiments of this application. The processor 401 executes functional applications and data processing by running the program instructions / modules stored in the memory 402, that is, it implements the code generation method in the above embodiments.
[0082] The memory 402 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the terminal device. Furthermore, the memory 402 may include high-speed random access memory and may also include non-volatile memory.
[0083] This application provides a storage medium storing computer-executable instructions, which are configured to execute the code generation method described in the above embodiments.
[0084] The aforementioned storage medium can be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0085] The technical solutions of this application embodiment can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes one or more instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in this application embodiment. The aforementioned storage medium can be a non-transitory storage medium, including: USB flash drive, portable hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk, and other media capable of storing program code; it can also be a transient storage medium.
[0086] This application provides a computer program product, including a computer program, which, when executed by a processor, implements the code generation method described in the above embodiments.
[0087] The foregoing description and accompanying drawings fully illustrate embodiments of this disclosure to enable those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, procedural, and other changes. The embodiments represent only possible variations. Individual components and functions are optional unless explicitly required, and the order of operation may vary. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. Moreover, the terminology used in this application is for describing embodiments only and is not intended to limit the claims. As used in the description of embodiments and claims, the singular forms “a,” “an,” and “the” are intended to equally include the plural forms unless the context clearly indicates otherwise. Similarly, the term “and / or” as used in this application means including one or more of the associated listed items and all possible combinations thereof. Additionally, when used in this application, the term "comprise" and its variations "comprises" and / or "comprising" refer to the presence of stated features, integrals, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof. Without further limitations, an element defined by the phrase "comprises a..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes said element. In this document, each embodiment may focus on the differences from other embodiments, and similar or identical parts between embodiments can be referred to mutually. For methods, products, etc., disclosed in the embodiments, if they correspond to the method section disclosed in the embodiments, the relevant parts can be referred to the description of the method section.
[0088] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0089] The methods and products (including but not limited to devices and equipment) disclosed in the embodiments herein can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For instance, the division of units may be merely a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to implement this embodiment according to actual needs. In addition, the functional units in the embodiments of this application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than that shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks may also occur in a different order than disclosed in the description; sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. Each block in a block diagram and / or flowchart, and combinations of blocks in a block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
Claims
1. A code generation method, characterized in that, include: Obtain a natural language description of the target user, which is used to characterize the target user's code generation requirements; The natural language description is parsed to obtain key parameters; Based on the key parameters, query the code parameters corresponding to the key parameters from a private database or private knowledge base, and generate the first target code based on the code parameters.
2. The method according to claim 1, characterized in that, The step of querying the code parameters corresponding to the key parameters from a private database or private knowledge base, and generating the first target code based on the code parameters, includes: A query statement is generated based on the key parameters, and the first code parameter corresponding to the key parameters is queried from the private database according to the query statement. When the first code parameter is found, the first target code is generated based on the first code parameter.
3. The method according to claim 2, characterized in that, The step of querying the code parameters corresponding to the key parameters from a private database or private knowledge base, and generating the first target code based on the code parameters, further includes: If the first code parameter is not found, the second code parameter corresponding to the key parameter is queried from the private knowledge base according to the key parameter, so as to generate the first target code according to the second code parameter.
4. The method according to claim 3, characterized in that, The step of querying the second code parameter corresponding to the key parameter from the private knowledge base based on the key parameter includes: The key parameters are vectorized to obtain parameter vectors, and the fragments in the private knowledge base are vectorized to obtain fragment vectors; Calculate the similarity between the parameter vector and the fragment vector, and filter out target fragments with a similarity greater than a similarity threshold to obtain the second code parameter corresponding to the target fragment. The target fragment is one or more fragments in the private knowledge base.
5. The method according to claim 1, characterized in that, The process of parsing the natural language description to obtain key parameters includes: The natural language description is subjected to intent recognition to obtain intent recognition results, and the user intent and key parameters are extracted from the intent recognition results.
6. The method according to claim 5, characterized in that, The step of generating the first target code based on the code parameters includes: A code template is determined based on the user's intent, and the code parameters are filled into the code template to generate the first target code.
7. The method according to claim 6, characterized in that, After generating the first target code based on the code parameters, the process further includes: Retrieve the analysis steps corresponding to the user intent from the private knowledge base, and query the analysis code corresponding to the analysis steps; The analysis code is merged with the first target code to obtain the second target code.
8. The method according to claim 1, characterized in that, The step of querying the code parameters corresponding to the key parameters from a private database or private knowledge base, and generating the first target code based on the code parameters, includes: When a key parameter corresponds to at least two code parameters, in response to the target user's selection operation, a target code parameter uniquely corresponding to the key parameter is determined. The first target code is generated based on the target code parameters, and the selection operation is the operation by which the target user selects one of the at least two code parameters as the target code parameter.
9. A code generation device, characterized in that, include: The acquisition module is used to acquire a natural language description of the target user, wherein the natural language description is used to characterize the code generation requirements of the target user. The parsing module is used to parse the natural language description to obtain key parameters; The query module is used to query the code parameters corresponding to the key parameters from a private database or private knowledge base, so as to generate the first target code based on the code parameters.
10. An electronic device comprising a processor and a memory storing program instructions, characterized in that, The processor is configured to perform the method as described in any one of claims 1 to 8 when executing the program instructions.
11. A storage medium storing program instructions, characterized in that, When the program instructions are executed, they perform the method as described in any one of claims 1 to 8.
12. A computer program product, characterized in that, Includes a computer program, which, when executed by a processor, implements the method as described in any one of claims 1 to 8.