Code generation method and device, equipment and medium
By combining a pre-trained code generation model with user identifiers and historical query codes, target query codes that conform to user coding habits are generated, solving the problem of low efficiency in traditional manual analysis and achieving efficient and accurate data querying.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-04
- Publication Date
- 2026-03-13
AI Technical Summary
Traditional manual review and analysis of unstructured or semi-structured log data is inefficient and makes it difficult to uncover deeper correlations, resulting in untimely fault location, difficulty in discovering security threats, and inaccurate business insights.
By using a pre-trained code generation model, combined with user identification and knowledge of writing historical query codes, target query codes are generated from a pre-set knowledge base. Multi-dimensional knowledge verification is used to ensure the accuracy and personalized adaptability of the code.
It improves the accuracy and efficiency of code generation, ensures that the generated code conforms to the user's specific coding habits, and enhances the efficiency and accuracy of data querying.
Smart Images

Figure CN121658503A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large language models, and more particularly to a code generation method, apparatus, device, and medium. Background Technology
[0002] Currently, various software systems and infrastructures generate massive amounts of unstructured or semi-structured log data daily. This data is a key carrier of system status, user behavior, and security incidents. However, faced with such a massive data volume, traditional manual review and analysis methods are extremely inefficient, slow to respond, and unable to uncover deep-seated correlations, leading to a series of problems such as untimely fault location, difficulty in discovering security threats, and inaccurate business insights.
[0003] Therefore, in order to improve the efficiency of data retrieval, the existing technology uses the method of writing query statements to locate key data content. However, manually writing query statements is inefficient and lacks accuracy. Summary of the Invention
[0004] This invention provides a code generation method, apparatus, device, and medium that can directly generate code adapted to user habits, thereby improving the accuracy and efficiency of code generation.
[0005] In a first aspect, embodiments of the present invention provide a code generation method, including:
[0006] The input text of the target user is input into a pre-trained code generation model, wherein the input text is used to generate the target query code;
[0007] Using the code generation model, target knowledge is determined from a preset knowledge base based on the input text and user identifier, wherein the preset knowledge base includes the writing knowledge of historical query codes for each user;
[0008] Using the code generation model, target query code is generated based on the target knowledge.
[0009] Secondly, embodiments of the present invention provide a code generation apparatus, comprising:
[0010] An input module is used to input the target user's input text into a pre-trained code generation model, wherein the input text is used to generate target query code;
[0011] The knowledge determination module is used to determine target knowledge from a preset knowledge base based on the input text and user identifier using the code generation model, wherein the preset knowledge base includes the writing knowledge of historical query codes for each user;
[0012] The generation module is used to generate target query code based on the target knowledge using the code generation model.
[0013] Thirdly, embodiments of the present invention provide an electronic device, the electronic device comprising:
[0014] At least one processor; and,
[0015] A memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the code generation method described in any one of the embodiments of the present invention.
[0017] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the code generation method described in any one of the embodiments of the present invention.
[0018] This invention provides a code generation method, apparatus, device, and medium. The method includes: inputting input text from a target user into a pre-trained code generation model, wherein the input text is used to generate target query code; using the code generation model, determining target knowledge from a preset knowledge base based on the input text and user identifier, wherein the preset knowledge base includes historical query code writing knowledge for each user; and using the code generation model to generate target query code based on the target knowledge. Specifically, the preset knowledge base stores historical query code writing knowledge for each user. By calling historical knowledge related to the target user, the model can be guided to generate target query code that conforms to its specific coding habits. Therefore, the technical solution of this invention effectively improves the accuracy of generated code and its adaptability to users. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention, 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 the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A flowchart of a code generation method provided in Embodiment 1 of the present invention;
[0021] Figure 2 This is a flowchart of a code generation method provided in Embodiment 2 of the present invention;
[0022] Figure 3 A schematic diagram illustrating a code generation method provided in an embodiment of the present invention;
[0023] Figure 4 This is a schematic diagram of knowledge base updating provided in an embodiment of the present invention;
[0024] Figure 5 This is a schematic diagram of the structure of a code generation device provided in Embodiment 3 of the present invention;
[0025] Figure 6 This is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0028] It should be noted that the collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0029] Example 1
[0030] Figure 1 The flowchart illustrates a code generation method provided in Embodiment 1 of the present invention. This method is specifically applicable to situations where query code conforming to user writing habits is generated through a code generation model. This method can be executed by a code generation device, which can be composed of software and / or hardware and configured in a computer or server.
[0031] like Figure 1 As shown, it includes:
[0032] Step 110: Input the target user's input text into the pre-trained code generation model, wherein the input text is used to generate the target query code.
[0033] Specifically, the input text is a natural language description entered by the target user to generate the target query code, which includes functional requirements, specifications, or other relevant limitations for the target query code. The target query code is the program code that the user expects to obtain. The code generation model is built on a large language model. While large language models possess basic question-answering and code generation capabilities, their strong generality often makes it difficult to directly meet the personalized code standards of specific projects or individual users. Therefore, the large language model needs to be specifically trained to ensure that the generated code conforms to the user's specific specifications and quality requirements.
[0034] Step 120: Using the code generation model, determine the target knowledge from the preset knowledge base based on the input text and user identifier, wherein the preset knowledge base includes the writing knowledge of historical query codes for each user.
[0035] The user identifier is a characteristic identifier of the target user, which can be the user's ID, name, account, etc. Target knowledge refers to the knowledge required to generate the target query code. The code generation model will reason based on the target knowledge to obtain the target query code required by the target user. Furthermore, target knowledge can include various types of knowledge, such as the syntax and specifications of programming languages, logical rules for specific business domains, functional templates for logical functions, code quality and standardization, and especially the knowledge of the user's historical query code writing, used to characterize the user's writing habits, such as function usage and parameter naming preferences. It should be noted that different users often have different coding habits even for the same target function. For example, when naming the "user" parameter, some users may prefer to use ID, while others may use user; in the implementation of the corresponding search function, some users may prefer to use filters or find, while others may choose loop structures such as for. The method provided in this embodiment of the invention, by analyzing the user's historical query code, can automatically identify and learn their personalized coding style and habits, thereby generating new code that better matches the user's individual writing preferences, improving code consistency and maintainability.
[0036] Step 130: Using the code generation model, generate target query code based on the target knowledge.
[0037] Specifically, the code generation model performs reasoning and verification based on the target knowledge to obtain the target query code.
[0038] Optionally, the code generation model is used to generate multiple candidate query codes based on the target knowledge;
[0039] Based on the verification results of the multiple candidate query codes, the target query code is determined.
[0040] Specifically, different reference weights can be preset for different types of target knowledge to determine the degree of emphasis the large language model places on various types of knowledge during the reasoning process, thereby generating multiple candidate query codes. It should be noted that, since the reasoning process itself has a certain degree of randomness, to ensure the accuracy of the generated codes, multiple candidate query codes can be verified through the code generation model, and the target query code that meets the requirements can be determined based on the verification results.
[0041] Optionally, the plurality of candidate query codes are subjected to syntax verification to determine multiple syntax verification results; candidate function description information of the plurality of candidate query codes is determined, and the similarity verification between the candidate function description information and the function description information corresponding to the input text is performed to obtain multiple function verification results; the plurality of candidate query codes are respectively input to a preset verification interface, and multiple interface verification results are determined according to multiple response identifiers returned by the preset verification interface; the target query code is determined according to the multiple syntax verification results, multiple function verification results and multiple interface verification results corresponding to the plurality of candidate query codes.
[0042] Specifically, the candidate query code can be subjected to syntax verification, functional verification, and interface verification, and then the target query code can be determined based on the results of the syntax verification, functional verification, and interface verification.
[0043] Syntax validation refers to verifying the parameter usage, function calls, and syntax structure of candidate query code, checking whether the candidate query code conforms to the basic specifications of the programming language, such as whether parentheses match, whether statements are complete, and whether keywords are used correctly.
[0044] Functional verification is used to determine whether candidate codes truly reflect user intent. Candidate query codes can be converted into corresponding natural language function descriptions (candidate function description information), and then semantic similarity comparisons can be performed between these descriptions and the needs expressed in the user's input text to determine whether the candidate query code can fully fulfill the user's functional requirements.
[0045] Interface verification evaluates the usability and correctness of candidate code at runtime by inputting it into a preset verification interface (such as a simulated execution environment and test framework) and evaluating the response indicators returned by the preset verification interface (such as execution success / failure, correctness of output results, etc.).
[0046] Finally, by combining the three types of verification results, each candidate code can be evaluated from multiple dimensions, and the code that performs best in terms of syntax correctness, functional accuracy, and execution reliability can be selected as the target query code.
[0047] This invention provides a code generation method, apparatus, device, and medium. The method includes: inputting input text from a target user into a pre-trained code generation model, wherein the input text is used to generate target query code; using the code generation model, determining target knowledge from a preset knowledge base based on the input text and user identifier, wherein the preset knowledge base includes historical query code writing knowledge for each user; and using the code generation model to generate target query code based on the target knowledge. Specifically, the preset knowledge base stores historical query code writing knowledge for each user. By calling historical knowledge related to the target user, the model can be guided to generate target query code that conforms to its specific coding habits. Therefore, the technical solution of this invention effectively improves the accuracy of generated code and its adaptability to users.
[0048] Example 2
[0049] Figure 2 This is a flowchart of a code generation method provided in Embodiment 2 of the present invention. This embodiment specifically defines a method for determining target knowledge from a preset knowledge base based on the input text and user identifier.
[0050] like Figure 2 As shown, it includes:
[0051] Step 210: Input the target user's input text into the pre-trained code generation model, wherein the input text is used to generate the target query code.
[0052] Step 220: Using the code generation model, based on the input text, determine the first type of knowledge and the second type of knowledge, wherein the first type of knowledge represents the writing specifications of each objective function required to generate the target query code, and the second type of knowledge is the code template of the target query code.
[0053] The target function is the function required to compose the target query code. The writing specifications are the syntax, parameter order and writing format specifications for code elements such as function statements. The code template is a preset template to implement the code function. For example, when querying a database, the code template can include templates for steps such as login, inputting search conditions and querying. Custom parameters in the template are replaced by placeholders.
[0054] Optionally, using the code generation model, based on the input text, a first type of knowledge is determined, including:
[0055] The input text is segmented to identify keywords; based on the keywords, a target function and its writing specifications are determined from the first knowledge base of the code generation model; the target function and its writing specifications are identified as the first type of knowledge.
[0056] Keywords are words extracted from the input text after word segmentation that represent the core intent of the input text. Based on the keywords, the function to be performed can be determined. For example, if the keyword is "search," the target function can be mapped to "find"; if it is "delete," it can be mapped to "delete." Subsequently, by utilizing the correspondence between target functions and writing specifications stored in the first knowledge base, the corresponding target function and its writing specifications can be matched according to the determined function, and this is treated as the first type of knowledge. By referring to the first type of knowledge, the code generation model can ensure that the writing of each target function is accurate when generating the target query code, thereby improving the accuracy of the code.
[0057] For example, the writing conventions for functions in the first knowledge base may include: function name, function description, parameter definition, usage examples and applicable scenarios, etc.
[0058] Optionally, using the code generation model, based on the input text, a second type of knowledge is determined, including:
[0059] The input text is subjected to semantic recognition and intent recognition to determine the semantic recognition result and intent recognition result; the functional description information of the input text is determined based on the semantic recognition result and intent recognition result; and the target code template is determined from the second knowledge base of the code generation model based on the functional description information.
[0060] Semantic recognition parses the input text to determine its vocabulary, grammatical structure, and literal meaning. Intent recognition determines the fundamental purpose of the user's input text, i.e., the core functionality required by the target query. The functional description information of the input text is natural language text representing the user's core code functionality requirements, determined by the results of semantic and intent recognition. The second knowledge base stores the mapping relationships between various functions and their corresponding implementation logic frameworks (i.e., code templates). Each code template includes multiple functions and parameter placeholders. By replacing the corresponding parameter placeholders in the template with the target parameters from the input text, the code template is filled to achieve the corresponding functionality.
[0061] For example, if the function description is "within a certain time window, an account logs in from multiple different geographical locations", the function template is: appname=auth user=$USER | stats dc(src_ip) as ip_count by user| where ip_count > $THRESHOLD. Parameters: $USER, $THRESHOLD, $TIME_WINDOW.
[0062] Step 230: Using the code generation model, based on the input text and user identifier, determine the third type of knowledge, wherein the third type of knowledge represents the target user's function usage preferences and parameter naming preferences.
[0063] Optionally, the preset knowledge base includes a third knowledge base, and the method for generating the third knowledge base includes:
[0064] Obtain the user's historical query codes and determine the natural language descriptions corresponding to the historical query codes; determine the target function and target parameters in the historical query codes; based on a preset structured template, generate structured knowledge according to the user's identifier, target function, target parameters, historical query codes, and the natural language descriptions corresponding to the historical query codes;
[0065] The structured knowledge of each user's historical query codes constitutes the third knowledge base.
[0066] Among them, the historical query code is an instance of the query code that the user has executed and completed in the past; the preset structured template is a preset data storage format used to store the information of the historical query code in various dimensions (user identifier, objective function, objective parameters, historical query code and the natural language description corresponding to the historical query code) in a structured manner, which can be efficiently processed and retrieved by the code generation model.
[0067] Specifically, when achieving the same target function, individual user habits can lead to personalized differences in function selection and parameter naming. To address this, a third type of knowledge can be constructed for each user: by analyzing their historical query code, their unique function usage preferences and parameter naming conventions can be recorded. Ultimately, the code generation model, referencing this third type of knowledge, can output target query code that conforms to the user's personalized habits, thus determining the third type of knowledge.
[0068] Optionally, the step of using the code generation model to determine the third type of knowledge based on the input text and user identifier includes:
[0069] Based on the user identifier, candidate natural language descriptions corresponding to the user identifier are determined from the third knowledge base; the input text is matched with the candidate natural language descriptions for similarity, and the target natural language description is determined based on the matching results; the structured knowledge corresponding to the target natural language description is determined as the third type of knowledge.
[0070] Specifically, user knowledge corresponding to the target user in the third knowledge base can be determined through user identification. Then, the input text is matched with each candidate natural language description for similarity, and the description with the highest similarity is identified as the target natural language description. The structured knowledge corresponding to the target natural language description is then identified as the third type of knowledge. Furthermore, the third type of knowledge includes the function and parameter naming conventions used by users when handling similar problems in the past. By using this third type of knowledge, the code generated by the code generation model can be more in line with user habits, improving code adaptability.
[0071] Step 240: Using the code generation model, generate target query code based on the target knowledge, wherein the target knowledge includes first type of knowledge, second type of knowledge and third type of knowledge.
[0072] For example, Figure 3 This diagram illustrates a code generation method provided by an embodiment of the present invention. Specifically, retrieval of a preset knowledge base can be achieved through RAG (Retrieval-Augmented Generation). The preset knowledge base may include a general function library (first type of knowledge base), a scenario library (second type of knowledge base), and a user habit library (third type of knowledge base). Relevant knowledge of the input text can be obtained from these three types of knowledge bases, ensuring multi-dimensional optimization of the generated code in terms of logical integrity, syntactic standardization, and personal habits. Furthermore, after preprocessing (word segmentation, semantic recognition, and intent recognition, etc.) of the user-input natural language query, RAG retrieval is performed. The retrieval results from the first, second, and third types of knowledge bases, along with the input text, are combined to construct a new Prompt. The code generation model then uses the Prompt to generate preliminary SPL statements (candidate query statements). The candidate query statements undergo syntax verification, interface verification, and semantic verification. If verification fails, the query is regenerated; if successful, it is returned to the user. It should be noted that the code generation model records query usage and user feedback, and regularly updates the knowledge base through methods such as manual review, thereby achieving continuous self-optimization and improving the accuracy of code generation. For example, Figure 4This is a schematic diagram of knowledge base updates provided in an embodiment of the present invention. Specifically, the update task can be triggered by three methods: timed, event-driven, or manual. After the update begins, the syntax, executability, and validity of the query statements are first verified, and invalid queries are discarded. Then, the similarity of each query statement is calculated, clustered, and representative SPL statements are selected to achieve deduplication. Then, the capabilities of the model itself are used to convert the SPL language into natural language descriptions and generate vector indexes. Finally, all query statements are manually reviewed, and only those that pass the review are officially written into the knowledge base, thereby ensuring the accuracy and usability of the knowledge base content.
[0073] This invention provides a code generation method. Specifically, the first type of knowledge specifies the writing standards for individual functions, ensuring the accuracy of basic function writing. The second type of knowledge provides standard code templates for implementing overall functionality, guaranteeing the integrity of code logic and function. The third type of knowledge records users' personal habits in function usage and parameter naming, making the generated code more in line with the user's personalized style. By comprehensively utilizing multi-dimensional knowledge, the generated target query code can ensure accuracy while adapting to individual user needs, thereby effectively improving the accuracy and personalization of code generation.
[0074] Example 3
[0075] Figure 5 This is a schematic diagram of a code generation device provided in Embodiment 3 of the present invention. Figure 5 As shown, the device includes:
[0076] Input module 310 is used to input the input text of the target user into a pre-trained code generation model, wherein the input text is used to generate target query code;
[0077] The knowledge determination module 320 is used to determine target knowledge from a preset knowledge base based on the input text and user identifier using the code generation model, wherein the preset knowledge base includes the writing knowledge of historical query codes of each user;
[0078] The generation module 330 is used to generate target query code based on the target knowledge using the code generation model.
[0079] This invention provides a code generation apparatus that: inputs input text from a target user into a pre-trained code generation model, wherein the input text is used to generate target query code; uses the code generation model to determine target knowledge from a preset knowledge base based on the input text and user identifier, wherein the preset knowledge base includes historical query code writing knowledge for each user; and uses the code generation model to generate target query code based on the target knowledge. Specifically, the preset knowledge base stores historical query code writing knowledge for each user. By calling historical knowledge related to the target user, the model can be guided to generate target query code that conforms to its specific coding habits. Therefore, the technical solution of this invention effectively improves the accuracy of generated code and its adaptability to users.
[0080] Optionally, the knowledge determination module 320 includes:
[0081] The first determining unit is used to determine a first type of knowledge and a second type of knowledge based on the input text using the code generation model, wherein the first type of knowledge represents the writing specifications of each objective function required to generate the target query code, and the second type of knowledge is the code template of the target query code;
[0082] The second determining unit is used to determine a third type of knowledge based on the input text and user identifier using the code generation model, wherein the third type of knowledge represents the target user's function usage preferences and parameter naming preferences.
[0083] Optionally, the first determining unit includes: a first type of knowledge determining subunit, including:
[0084] The word segmentation micro-unit is used to segment the input text into words and determine each keyword;
[0085] A matching micro-unit is used to determine, based on the keywords, the target function and the writing specifications of the target function that match the keywords from the first knowledge base of the code generation model;
[0086] The micro-unit is determined to classify the objective function and its writing conventions as first-class knowledge.
[0087] Optionally, the first determining unit includes: the second type of knowledge determining subunit, including:
[0088] The micro-unit is used to perform semantic recognition and intent recognition on the input text, and to determine the semantic recognition result and the intent recognition result.
[0089] The matching micro-unit is used to determine the functional description information of the input text based on the semantic recognition result and the intent recognition result, and to determine the target code template from the second knowledge base of the code generation model based on the functional description information.
[0090] Optionally, the knowledge determination module 320 may also include a third generation unit, including:
[0091] The acquisition subunit is used to acquire the user's historical query code and determine the natural language description corresponding to the historical query code;
[0092] Extract sub-units to determine the target function and target parameters in the historical query code;
[0093] The filling subunit is used to generate structured knowledge based on a preset structured template, according to the user's user identifier, target function, target parameters, historical query code, and the natural language description corresponding to the historical query code;
[0094] The generated sub-units are used to construct a third knowledge base from the structured knowledge of each user's historical query codes.
[0095] Optionally, the second determining unit includes:
[0096] The identifier determination subunit is used to determine each candidate natural language description corresponding to the user identifier from the third knowledge base based on the user identifier;
[0097] The matching subunit is used to perform similarity matching between the input text and each candidate natural language description, determine the target natural language description based on the matching results, and determine the structured knowledge corresponding to the target natural language description as the third type of knowledge.
[0098] Optionally, the generation module 330 includes:
[0099] A generation unit is used to generate multiple candidate query codes based on the target knowledge using the code generation model.
[0100] The verification unit is used to determine the target query code based on the verification results of the plurality of candidate query codes.
[0101] Optional, the verification unit includes:
[0102] The syntax verification subunit is used to perform syntax verification on the multiple candidate query codes and determine multiple syntax verification results.
[0103] The semantic verification subunit is used to determine the candidate function description information of the multiple candidate query codes, and to perform similarity verification between the candidate function description information and the function description information corresponding to the input text to obtain multiple function verification results.
[0104] An interface verification subunit is used to input the multiple candidate query codes into a preset verification interface, and determine multiple interface verification results based on the multiple response identifiers returned by the preset verification interface.
[0105] The evaluation subunit is used to determine the target query code based on multiple syntax verification results, multiple functional verification results, and multiple interface verification results corresponding to multiple candidate query codes.
[0106] The code generation apparatus provided in the embodiments of the present invention can execute the code generation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0107] Example 4
[0108] Figure 6 A schematic diagram of an electronic device 10, which can be used to implement embodiments of the present invention, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0109] like Figure 6 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0110] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0111] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as code generation methods.
[0112] In some embodiments, the code generation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the code generation method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the code generation method by any other suitable means (e.g., by means of firmware).
[0113] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0114] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0115] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0116] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0117] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0118] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0119] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0120] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A code generation method, characterized in that, include: The input text of the target user is input into a pre-trained code generation model, wherein the input text is used to generate the target query code; Using the code generation model, target knowledge is determined from a preset knowledge base based on the input text and user identifier, wherein the preset knowledge base includes the writing knowledge of historical query codes for each user; Using the code generation model, target query code is generated based on the target knowledge.
2. The method according to claim 1, characterized in that, The step of using the code generation model to determine target knowledge from a preset knowledge base based on the input text and user identifier includes: Using the code generation model, based on the input text, a first type of knowledge and a second type of knowledge are determined, wherein the first type of knowledge represents the writing specifications of each objective function required to generate the target query code, and the second type of knowledge is the code template of the target query code; Using the code generation model, a third type of knowledge is determined based on the input text and user identifier, wherein the third type of knowledge represents the target user's function usage preferences and parameter naming preferences.
3. The method according to claim 2, characterized in that, The step of using the code generation model to determine the first type of knowledge based on the input text includes: The input text is segmented into words to determine the keywords; Based on the keywords, the target function and the writing specifications of the target function that match the keywords are determined from the first knowledge base of the code generation model; The objective function and its writing conventions are classified as the first type of knowledge.
4. The method according to claim 2, characterized in that, Using the code generation model, based on the input text, a second type of knowledge is determined, including: Perform semantic recognition and intent recognition on the input text, and determine the semantic recognition result and intent recognition result; Based on the semantic recognition results and intent recognition results, the functional description information of the input text is determined, and the target code template is determined from the second knowledge base of the code generation model based on the functional description information.
5. The method according to claim 2, characterized in that, The preset knowledge base includes a third knowledge base, and the method for generating the third knowledge base includes: Obtain the user's historical query codes and determine the natural language descriptions corresponding to the historical query codes; Determine the target function and target parameters in the historical query code; Based on a preset structured template, structured knowledge is generated according to the user's identifier, objective function, objective parameters, historical query codes, and the natural language descriptions corresponding to the historical query codes. The structured knowledge of each user's historical query codes constitutes the third knowledge base.
6. The method according to claim 5, characterized in that, The method of using the code generation model to determine the third type of knowledge based on the input text and user identifier includes: Based on the user identifier, determine each candidate natural language description corresponding to the user identifier from the third knowledge base; The input text is matched with each candidate natural language description for similarity. The target natural language description is determined based on the matching results. The structured knowledge corresponding to the target natural language description is determined as the third type of knowledge.
7. The method according to claim 1, characterized in that, The step of using the code generation model to generate target query code based on the target knowledge includes: Using the code generation model, multiple candidate query codes are generated based on the target knowledge; Based on the verification results of the multiple candidate query codes, the target query code is determined.
8. The method according to claim 7, characterized in that, Determining the target query code based on the verification results of the multiple candidate query codes includes: Perform syntax validation on the multiple candidate query codes and determine multiple syntax validation results; Determine the candidate function description information of the multiple candidate query codes, and perform similarity verification between the candidate function description information and the function description information corresponding to the input text to obtain multiple function verification results; The candidate query codes are input into the preset verification interface, and the verification results of the multiple interfaces are determined according to the multiple response identifiers returned by the preset verification interface. The target query code is determined based on multiple syntax validation results, multiple function validation results, and multiple interface validation results corresponding to multiple candidate query codes.
9. A code generation device, characterized in that, include: An input module is used to input the target user's input text into a pre-trained code generation model, wherein the input text is used to generate target query code; The knowledge determination module is used to determine target knowledge from a preset knowledge base based on the input text and user identifier using the code generation model, wherein the preset knowledge base includes the writing knowledge of historical query codes for each user; The generation module is used to generate target query code based on the target knowledge using the code generation model.
10. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the code generation method according to any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that are used to cause a processor to execute the code generation method of any one of claims 1-8.