Data generation method and device, computer device, readable storage medium and program product
By obtaining structured prompting framework information from a generative large language model and retrieving data from the target knowledge base, and then using a data generation model for analysis and processing, target prompts and code are generated. This solves the problem of code generation accuracy caused by developer subjectivity and achieves highly accurate code generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TSINGHUA UNIVERSITY
- Filing Date
- 2025-01-09
- Publication Date
- 2026-04-28
AI Technical Summary
In traditional generative large language models, the accuracy of task prompts and generated target code is poor due to the subjectivity of developers in constructing business prompts.
By acquiring structured prompt framework information, relevant data is retrieved from the target knowledge base. The first component of the data generation model is used for analysis and processing to generate target prompts. The second component is used for in-depth analysis and code generation to ensure that the generated code meets the requirements of the prompt framework and integrates professional domain knowledge.
It improves the accuracy and reliability of generated code, ensuring that the generated code not only meets the requirements of the prompting framework, but also incorporates professional domain knowledge, achieving precise contextual guidance and code generation.
Smart Images

Figure CN120144116B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a data generation method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Technology
[0002] With the development of artificial intelligence technology, generative artificial intelligence technology has emerged, which can realize operations such as code generation and code completion through generative artificial intelligence models.
[0003] In traditional technologies, generative large language models are used to analyze and process task prompts constructed by developers according to business requirements, determine the task objectives corresponding to the task prompts, and generate target code corresponding to the business requirements based on the task objectives. The target code is then used to build an application that implements the business requirements.
[0004] However, in traditional technologies, the subjectivity of developers in constructing business prompts leads to poor accuracy of task prompts, which in turn results in poor accuracy of target code generated from generative large language models. Summary of the Invention
[0005] Therefore, it is necessary to provide a data generation method, apparatus, computer equipment, computer-readable storage medium, and computer program product to address the aforementioned technical problems.
[0006] Firstly, this application provides a data generation method, including:
[0007] Obtain the prompting framework information, and retrieve the target knowledge base data in the target knowledge base based on the prompting framework information;
[0008] The first component of the data generation model is used to analyze and process the prompting framework information and the target knowledge base data to obtain the target prompt message;
[0009] The target prompt is analyzed and processed based on the target prompt and the second component of the data generation model to obtain generated code; the generated code is used to build the target application.
[0010] In one embodiment, retrieving target knowledge base data from the target knowledge base based on the prompting framework information includes:
[0011] The prompt frame information is vectorized and encoded according to the text embedding model to obtain the first query vector corresponding to the prompt frame information;
[0012] Based on the similarity between the first query vector and the second query vector corresponding to each candidate knowledge base data in the target knowledge base, the candidate knowledge base data are sorted to obtain the sorting result.
[0013] The target second query vector is determined based on the sorting result, and the target second query vector is used as the target knowledge base data.
[0014] In one embodiment, before obtaining the prompting frame information and retrieving target knowledge base data from the target knowledge base based on the prompting frame information, the method further includes:
[0015] Obtain initial material, and then segment the initial material into paragraphs to obtain target material;
[0016] The target material is vectorized and encoded according to the text embedding model to obtain the second query vector and the number corresponding to the second query vector.
[0017] Construct a target knowledge base based on the second query vector and the number.
[0018] In one embodiment, the first component includes a prompt generation structure and an encoding structure, wherein the target knowledge base data is the target second query vector corresponding to the prompt framework information;
[0019] The step of analyzing and processing the prompt framework information and the target knowledge base data according to the first component of the data generation model to obtain the target prompt includes:
[0020] The prompt frame information is vectorized according to the encoding structure in the data generation model to obtain the encoding vector corresponding to the prompt frame information;
[0021] The encoded vector and the target second query vector are concatenated to obtain the target vector;
[0022] The target vector is analyzed and processed according to the prompt generation structure to obtain the target prompt.
[0023] In one embodiment, after the second component of the data generation model analyzes and processes the target prompt and obtains the generated code, the method further includes:
[0024] The generated code is compiled using the target compiler to obtain the compilation result.
[0025] If the compilation result is a compilation failure, obtain the error information fed back by the target compiler, add the error information to the target prompt, and obtain a new target prompt;
[0026] The second component, based on the target prompt and the data generation model, is executed to analyze and process the target prompt to obtain generated code, until the compilation result is successful, thus obtaining the target application.
[0027] In one embodiment, after compiling the generated code according to the target compiler to obtain the compilation result, the method further includes:
[0028] If the compilation result is successful, the target application is obtained, and the test data is processed based on the target application to obtain the test calculation result;
[0029] The error result of the target application is determined based on the test calculation results and the standard calculation results corresponding to the test data;
[0030] If the error result is greater than a preset error threshold, the test result of the target application is determined to be a test failure, and the error result is added to the target prompt message;
[0031] The second component, based on the target prompt and the data generation model, analyzes and processes the target prompt to generate code, until the test result of the target application is successful, thus obtaining the target application.
[0032] Secondly, this application also provides a data generation apparatus, comprising:
[0033] The first acquisition module is used to acquire prompting framework information and retrieve target knowledge base data in the target knowledge base based on the prompting framework information.
[0034] The first generation module is used to analyze and process the prompt framework information and the target knowledge base data according to the first component of the data generation model to obtain the target prompt message;
[0035] The second generation module is used to analyze and process the target prompt based on the target prompt and the second component of the data generation model to obtain generated code; the generated code is used to build the target application.
[0036] In one embodiment, the first acquisition module is specifically used to perform vectorized encoding on the prompt frame information according to the text embedding model to obtain the first query vector corresponding to the prompt frame information;
[0037] Based on the similarity between the first query vector and the second query vector corresponding to each candidate knowledge base data in the target knowledge base, the candidate knowledge base data are sorted to obtain the sorting result.
[0038] The target second query vector is determined based on the sorting result, and the target second query vector is used as the target knowledge base data.
[0039] In one embodiment, the device further includes:
[0040] The second acquisition module is used to acquire initial material, perform paragraph segmentation on the initial material, and obtain target material.
[0041] The encoding module is used to vectorize the target material according to the text embedding model to obtain a second query vector and the number corresponding to the second query vector.
[0042] A construction module is used to construct a target knowledge base based on the second query vector and the number.
[0043] In one embodiment, the first component includes a prompt generation structure and an encoding structure, wherein the target knowledge base data is the target second query vector corresponding to the prompt framework information;
[0044] The first generation module is specifically used to vectorize the prompt frame information according to the encoding structure in the data generation model to obtain the encoding vector corresponding to the prompt frame information;
[0045] The encoded vector and the target second query vector are concatenated to obtain the target vector;
[0046] The target vector is analyzed and processed according to the prompt generation structure to obtain the target prompt.
[0047] In one embodiment, the device further includes:
[0048] The first compilation module is used to compile the generated code according to the target compiler to obtain the compilation result;
[0049] The first update module is used to obtain the error information fed back by the target compiler if the compilation result is a compilation failure, and add the error information to the target prompt to obtain a new target prompt;
[0050] The second compilation module is used to execute the second component based on the target prompt and the data generation model to analyze and process the target prompt and obtain the generated code, until the compilation result is successful and the target application is obtained.
[0051] In one embodiment, the device further includes:
[0052] The testing module is used to obtain the target application and calculate and process the test data based on the target application if the compilation result is successful, so as to obtain the test calculation result.
[0053] An error calculation module is used to determine the error result of the target application based on the test calculation result and the standard calculation result corresponding to the test data;
[0054] The second update module is used to determine the test result of the target application as a test failure if the error result is greater than a preset error threshold, and to add the error result to the target prompt message;
[0055] The third generation module is used to execute the second component based on the target prompt and the data generation model to analyze and process the target prompt and obtain the generated code, until the test result of the target application is successful, and the target application is obtained.
[0056] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0057] Obtain the prompting framework information, and retrieve the target knowledge base data in the target knowledge base based on the prompting framework information;
[0058] The first component of the data generation model is used to analyze and process the prompting framework information and the target knowledge base data to obtain the target prompt message;
[0059] The target prompt is analyzed and processed based on the target prompt and the second component of the data generation model to obtain generated code; the generated code is used to build the target application.
[0060] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0061] Obtain the prompting framework information, and retrieve the target knowledge base data in the target knowledge base based on the prompting framework information;
[0062] The first component of the data generation model is used to analyze and process the prompting framework information and the target knowledge base data to obtain the target prompt message;
[0063] The target prompt is analyzed and processed based on the target prompt and the second component of the data generation model to obtain generated code; the generated code is used to build the target application.
[0064] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0065] Obtain the prompting framework information, and retrieve the target knowledge base data in the target knowledge base based on the prompting framework information;
[0066] The first component of the data generation model is used to analyze and process the prompting framework information and the target knowledge base data to obtain the target prompt message;
[0067] The target prompt is analyzed and processed based on the target prompt and the second component of the data generation model to obtain generated code; the generated code is used to build the target application.
[0068] The aforementioned data generation method, apparatus, computer equipment, computer-readable storage medium, and computer program product acquire prompt framework information and retrieve target knowledge base data based on the prompt framework information. The first component of the data generation model analyzes and processes the prompt framework information and target knowledge base data to obtain a target prompt. Based on the target prompt and the second component of the data generation model, the target prompt is analyzed and processed to obtain generated code. The generated code is used to build the target application. This method, by acquiring structured prompt framework information, firstly provides a clear goal and guidance for code generation. Then, by retrieving relevant target knowledge base data, it supplements the code with rich background knowledge and example references. The first component of the data generation model comprehensively analyzes the prompt framework information and knowledge base data to generate the target prompt, achieving precise contextual guidance for code generation through semantic understanding and knowledge integration. Finally, based on the target prompt, the second component of the data generation model performs in-depth analysis and code generation, ensuring that the generated code not only meets the prompt framework requirements but also integrates professional domain knowledge, thereby effectively improving the accuracy of the generated code. Attached Figure Description
[0069] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0070] Figure 1 This is a diagram illustrating the application environment of a data generation method in one embodiment;
[0071] Figure 2 This is a schematic diagram of the prompt frame information in one embodiment;
[0072] Figure 3 This is a schematic diagram of the process for obtaining target knowledge base data in one embodiment;
[0073] Figure 4 This is a flowchart illustrating the process of constructing a target knowledge base in one embodiment;
[0074] Figure 5 This is a flowchart illustrating the process of generating a target prompt in one embodiment;
[0075] Figure 6 This is a schematic diagram of the process of iteratively optimizing and generating code based on the feedback mechanism of compilation results in one embodiment;
[0076] Figure 7 This is a flowchart illustrating the process of testing a target application in one embodiment;
[0077] Figure 8 This is a flowchart illustrating an example of a data generation method in one embodiment;
[0078] Figure 9 This is a structural block diagram of a data generation device in one embodiment;
[0079] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0080] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0081] In one embodiment, such as Figure 1 As shown, a data generation method is provided. This embodiment illustrates the method applied to a terminal. It is understood that this method can also be applied to a server, and further to a system including both a terminal and a server, and is implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0082] Step 102: Obtain the prompting framework information and retrieve the target knowledge base data based on the prompting framework information.
[0083] In this embodiment, the prompting framework information can be obtained by developers planning the code generation order according to the software requirements document, and filtering, extracting, and integrating information such as top-level prompts and unit prompts according to business requirements, thereby enabling the terminal to obtain the prompting framework information input by the user. Simultaneously, the terminal searches and filters the pre-built target knowledge base based on the similarity between the prompting framework information and the knowledge data in the target knowledge base, obtaining target knowledge base data related to the content involved in the prompting framework information. The prompting framework information includes, for example, [details omitted]. Figure 2 As shown, it can contain top-level prompts and multiple unit prompts. The target knowledge base data includes professional domain knowledge materials such as fuel system principles, modeling methods, and prompt construction techniques.
[0084] In an optional embodiment, the prompting framework information can also be retrieved and extracted from the software requirements document based on the business requirements input by the developer using an LLM (Large Language Model) model. For example, the software requirements document may contain development content such as a working fluid property class used to calculate the characteristics of the fluid during simulation. This module constructs a regression expression based on the fluid's temperature and pressure values to calculate the fluid's density, viscosity, and specific heat. Specifically, the terminal performs text cleaning on the software requirements document using the LLM model, removing irrelevant characters and formatting the content. Then, the cleaned software requirements document is divided into smaller paragraphs or sentences. Named Entity Recognition (NER) technology is used to identify key entities in the software requirements document, such as class names, function names, and variable names. Relationship extraction technology is then used to determine the relationships between these entities, such as the relationship between classes and functions, and the relationship between functions and variables.
[0085] Furthermore, the terminal can perform further code generation order analysis on the aforementioned fluid properties based on the LLM model, analyze the dependencies between entities, determine which classes or functions need to be defined first and which can be defined later, and then obtain the code generation order through the LLM model. Alternatively, the terminal can pre-store the code generation order corresponding to various types of development content. For example, the code generation order corresponding to "constructing a regression expression based on the fluid's temperature and pressure values to calculate the fluid's density, viscosity, and specific heat" would be defined as defining the working fluid property class, reading the file member function, and calculating the fluid density, fluid viscosity, and three fluid property member functions. Finally, the terminal further extracts or generates relevant information of top-level prompts and unit prompts from the software requirements document using the LLM model, as data support for the subsequent generation of target prompts.
[0086] Step 104: Analyze and process the prompt framework information and target knowledge base data according to the first component of the data generation model to obtain the target prompt.
[0087] In this embodiment, the data generation model can be an LLM model, such as the Github Copilot large model. The first component is responsible for understanding and processing the prompt framework information and the target knowledge base data to generate the target prompt. The first component includes functions such as natural language understanding, knowledge extraction, and information integration, which aim to transform the input prompt framework information and knowledge base data into specific and detailed target prompts to guide the subsequent code generation process.
[0088] The terminal uses a data generation model to understand the target knowledge base data, simplifies and refines the prompt framework information, and integrates the content in the prompt framework information according to the structure of the target prompt to obtain the target prompt.
[0089] In one specific embodiment, the terminal inputs a prompt framework and target knowledge base data into the data generation model. The top-level goal of the prompt framework is to implement a working fluid property class for calculating the characteristics of the fluid during the simulation process. The organizational structure includes defining the working fluid property class, file reading member functions, and member functions for calculating fluid density, viscosity, and other fluid properties. The top-level constraint is to adhere to coding standards to ensure consistent code style. The target knowledge base data includes fluid property calculation methods and file reading techniques. The data generation model performs correlation analysis and refinement on the input prompt framework and target knowledge base data, understanding the key elements and relationships within the prompt framework. It integrates the prompt framework and target knowledge base data to provide richer and more accurate information support for generating the target prompt. Furthermore, the data generation model analyzes the prompt framework, extracts core content, removes redundant information, and supplements and refines the prompt framework based on the target knowledge base data to ensure the accuracy and professionalism of the prompt. Finally, according to preset structural requirements, the processed information is organized and sorted to form a clear and logically distinct target prompt.
[0090] Step 106: The target prompt is analyzed and processed based on the second component of the target prompt and the data generation model to obtain the generated code.
[0091] The generated code is used to build the target application.
[0092] In this embodiment, after the terminal generates a target prompt through the first component of the data generation model, it passes the target prompt to the second component. The second component understands the target prompt, generates a code block based on the class name, function name, and variable name in the target prompt, and adjusts the code block according to the constraints and requirements of the target prompt to obtain the final generated code.
[0093] In the aforementioned data generation method, by acquiring structured prompt framework information, a clear goal and guidance are first provided for code generation. Then, by retrieving relevant target knowledge base data, rich background knowledge and example references are supplemented. The first component of the data generation model comprehensively analyzes the prompt framework information and knowledge base data to generate target prompts, achieving precise contextual guidance for code generation through semantic understanding and knowledge integration. Finally, based on the target prompts, the second component of the data generation model performs in-depth analysis and code generation, ensuring that the generated code not only meets the prompt framework requirements but also integrates professional domain knowledge, thereby effectively improving the accuracy of the generated code.
[0094] In one exemplary embodiment, such as Figure 3 As shown, step 102 includes steps 302 to 306. Wherein:
[0095] Step 302: Vectorize the prompt frame information according to the text embedding model to obtain the first query vector corresponding to the prompt frame information.
[0096] In this embodiment, the text embedding model can be a pre-trained BERT model or a text2vec model. The terminal inputs the prompt frame information into the text embedding model. The text embedding model maps the class names, function names, variable names, and calculation processes of related working fluid properties contained in the prompt frame information into a continuous vector space, capturing the semantic information of the text and obtaining a first query vector in high-dimensional vector form. For example, the text data "calculate the density of the fluid based on temperature and pressure" in the prompt frame information is converted into a 128-dimensional first query vector.
[0097] Step 304: Sort the candidate knowledge base data according to the similarity between the first query vector and the second query vector corresponding to each candidate knowledge base data in the target knowledge base, and obtain the sorting result.
[0098] In this embodiment, the candidate knowledge base data is stored in the target knowledge base in vector form, that is, the target knowledge base stores the second query vector corresponding to each candidate knowledge base data. Then, the terminal uses a similarity measurement method (e.g., cosine similarity, dot product, etc.) to calculate the similarity between the first query vector and each second query vector. For example, the cosine similarity calculation method is shown in the following formula:
[0099]
[0100] in, This is the first query vector. This is the second query vector corresponding to the candidate knowledge base data in the target knowledge base. The number of the second query vector is stored in the target knowledge base.
[0101] The terminal sorts the candidate knowledge base data according to the similarity between the first query vector and each of the second query vectors, obtaining the sorted results. By calculating vector similarity, the semantic relevance between the prompt frame information and the knowledge base data can be measured. The sorting process ensures that the most relevant knowledge base data is selected first, thereby improving the accuracy of subsequent processing.
[0102] Step 306: Determine the target second query vector based on the sorting result, and use the target second query vector as the target knowledge base data.
[0103] In this embodiment, the terminal selects the second query vector with the highest similarity from the sorting results as the target second vector, or selects the top k second query vectors with the highest similarity as the target second vector. The target second vector serves as supplementary content to the prompt frame information and is input into the data generation model together with the prompt frame information.
[0104] In this embodiment, by converting the prompt frame information into vector form and using the vector similarity calculation method to find the most relevant target knowledge base data in the target knowledge base, accurate matching and supplementation of the prompt frame information are achieved, thereby improving the accuracy of the generated code.
[0105] In one exemplary embodiment, such as Figure 4 As shown, before step 102, the method further includes steps 402 to 406. Wherein:
[0106] Step 402: Obtain initial material, segment the initial material into paragraphs, and obtain target material.
[0107] In this embodiment, the terminal uses knowledge of fuel system principles, modeling methods, and prompt construction techniques as initial material in its professional domain. It then uses a pre-trained text embedding model (e.g., BERT text segmentation model) to segment this initial material into shorter paragraphs, thus obtaining the target material. For example, the terminal uses a text segmentation model to divide a long article about fuel system theory into multiple independent paragraphs, which serve as the target material. Each paragraph describes different aspects of the fuel system, including fuel supply, injection system, and ignition system.
[0108] Step 404: Vectorize the target material according to the text embedding model to obtain the second query vector and the number corresponding to the second query vector.
[0109] In this embodiment, the terminal uses a pre-trained text embedding model to vectorize each target material, converting the target material into a high-dimensional vector form of a second query vector. Then, the terminal assigns a unique number to each second query vector to correspond to the original initial material. By vectorizing the target material, the text-based target material is converted into a numerical vector form of a second query vector, facilitating terminal processing and similarity calculation.
[0110] Step 406: Construct the target knowledge base based on the second query vector and the number.
[0111] In this embodiment, the target knowledge base is a vectorized knowledge set, where each vector represents the semantic information of a target material. The vectorized second query vector can be efficiently retrieved and matched based on vector similarity. The terminal calls a vector database tool (e.g., Chormá, Malvus, etc.) to create a data structure to store the second query vector and its corresponding number, thus obtaining the target knowledge base. The completed target knowledge base is then saved to a storage device using a serialized data structure for subsequent querying and use.
[0112] In this embodiment, initial materials of professional domain knowledge are obtained, and a pre-trained text segmentation model is used to segment them into independent paragraphs to form target materials. These paragraphs are then encoded into second query vectors in high-dimensional vector form using a text embedding model, and each vector is assigned a unique number to correspond with the original materials. This achieves vectorized representation and efficient storage of target materials, laying the foundation for efficient retrieval and semantic matching of the target knowledge base, and significantly improving the accuracy of obtaining generated samples in subsequent processing.
[0113] In an exemplary embodiment, the first component includes a prompt generation structure and an encoding structure, and the target knowledge base data is the target second query vector corresponding to the prompt framework information; such as Figure 5 As shown, step 104 includes steps 502 to 506. Wherein:
[0114] Step 502: Vectorize the prompt frame information according to the encoding structure in the data generation model to obtain the encoding vector corresponding to the prompt frame information.
[0115] In this embodiment, the terminal inputs the prompt frame information into the data generation model. The encoding structure of the data generation model performs preprocessing operations such as word segmentation, word embedding, and position encoding on the input text. It encodes each word or the entire sentence through a multi-layer Transformer structure (or other model structure) to obtain a high-dimensional vector that represents the semantic features of the prompt frame information.
[0116] Step 504: Concatenate the encoded vector and the target second query vector to obtain the target vector.
[0117] In this embodiment, the target second query vector is a vector extracted from the target knowledge base, representing target knowledge base data highly relevant to the prompting framework information. The terminal concatenates the encoded vector and the target second query vector into a longer vector. For example, the terminal can directly connect the target second query vector to the encoded vector to obtain the target vector. Alternatively, the terminal can determine the first weight of the encoded vector and the second weight of the target second query vector respectively, and then concatenate the encoded vector and the target second query vector according to the first weight and the second weight to obtain the target vector.
[0118] Step 506: Analyze and process the target vector according to the prompt generation structure to obtain the target prompt.
[0119] In this embodiment, the prompt generation structure can be a decoder or a generation model part, used to generate natural language text based on the input vector. The terminal inputs the concatenated target vector into the prompt generation structure. The prompt generation structure first decodes the target vector, parsing its different components, such as class names, function names, variable names, and implementation steps. Then, according to the predefined prompt word structure, it fills the parsed information into the reserved positions in the prompt word structure accordingly, thereby generating a complete and grammatically correct target prompt.
[0120] The target prompts output by the prompt generation structure include development requirements specified by the developers, such as working fluid property classes, including calculating the fluid's density, viscosity, and specific heat using regression expressions based on the fluid's temperature and pressure values. The target prompts also include the development sequence, top-level prompts, and unit prompts defined in the software requirements document. The top-level prompts include top-level goals, used to concisely and clearly state the project's objectives; organizational structure, describing the constituent units of the code to be generated and their functions; and top-level constraints, defining the constraints during the development process. Unit prompts include unit descriptions, specifying the concrete development goals and constraints for each unit; unit structure, detailing the class's member variables and member functions, or function parameters and return values; and implementation steps, describing the unit's implementation logic and steps. For example, for top-level prompts, the organizational structure includes the classes and functions required throughout the development process, as well as the naming and functionality of each unit; top-level constraints can be specified coding styles, such as pre-defined naming conventions, comments, and code structures; for unit descriptions of unit prompts, the unit description can be the function Func1 used for operations on a certain variable, the specific operation method involved (i.e., the development goal), and the specific variable should be named VarA (constraint); the member variables of the class in the unit structure can be "This class has three member variables, namely VarA (integer), VarB (character), and VarC (real)", and the function of the member function can be "This class contains two member functions, namely Func1 and Func2". If the unit structure is a function, then the unit description can be "The function outputs VarA (integer); outputs VarB (character); and returns VarC (real)". The implementation steps of the unit prompts include a description of the internal operation logic and implementation steps of the unit, for example, step 1: define variables VarA and VarB. Step 2: calculate variable VarC using formula 1. Step 3: Calculate the variable VarD using Formula 2. The unit prompt can also include auxiliary information and error warnings. Auxiliary information can be reference information related to the generated code within the unit, including parameter tables, program examples, etc.; error warnings can provide explanations of error handling and abnormal situations. For example, if the initially generated code contains errors, examples of errors to avoid and solutions can be provided when re-editing the prompt, so that the data generation model avoids the same errors when generating code again.
[0121] In this embodiment, the prompt framework information is vectorized using the encoding structure of the data generation model to generate an encoded vector. Simultaneously, a target second query vector related to the prompt framework information is obtained from the target knowledge base. Then, the encoded vector and the target second query vector are concatenated to form a target vector. Next, the prompt generation structure analyzes and processes the target vector to generate a target prompt. This target prompt includes not only the developer's requirements but also the development sequence, top-level prompts, and unit prompts defined in the software requirements document. The top-level prompts concisely and clearly state the project goals, describing the code's organizational structure and constraints; the unit prompts detail the specific development goals, structure, and implementation steps of each code unit. Furthermore, unit prompts can also include auxiliary information and error warnings to improve the accuracy and reliability of the generated code. This achieves efficient conversion from prompt framework information to specific prompts, providing precise guidance for automatic code generation and thus improving the accuracy of the generated code.
[0122] In one exemplary embodiment, such as Figure 6 As shown, after step 106, the method further includes steps 602 to 606. Wherein:
[0123] Step 602: Compile the generated code according to the target compiler to obtain the compilation result.
[0124] In this embodiment, after obtaining the generated code based on the data generation model, the terminal determines the target compiler based on the code type of the generated code. For example, if the code type of the generated code is Python code, the generated code is input into the Python compiler. The terminal compiles the generated code according to the target compiler that matches the generated code, thereby obtaining the compilation result of the target compiler.
[0125] Step 604: If the compilation result is a compilation failure, obtain the error information fed back by the target compiler, add the error information to the target prompt, and obtain a new target prompt.
[0126] In this embodiment, if the generated code is error-free, the compilation result is successful, and the terminal obtains the compiled target application. If there is a logical error in the generated code, the target compiler will report an error, and the terminal will receive the error information from the target compiler. Then, the terminal adds the error information from the target compiler to the target prompt, as the error warning information part of the unit prompt in the target prompt, thus obtaining the reconstructed target prompt.
[0127] Step 606: Execute the second component based on the target prompt and data generation model to analyze and process the target prompt and generate code until the compilation result is successful, thus obtaining the target application.
[0128] In this embodiment, the terminal repeatedly analyzes and processes the reconstructed target prompt based on the data generation model, regenerates code based on the new target prompt, and compiles the new generated code according to the target compiler until the compilation result of the target compiler is successful. This indicates that the generated code does not contain logical errors. Therefore, compiling the correct generated code can yield the target application that meets the business requirements.
[0129] In this embodiment, a matching target compiler is first selected based on the type of generated code, and the generated code is compiled to obtain a compilation result. If compilation fails, the terminal obtains the error information fed back by the target compiler and adds the error information to the target prompt, forming a new target prompt. Subsequently, the terminal regenerates the code through the data generation model based on the new target prompt and compiles it again until the compilation result is successful, indicating that there are no more logical errors in the generated code. Finally, a target application that meets business requirements is obtained. Through the above feedback mechanism and iterative optimization, the accuracy and reliability of the generated code are ensured.
[0130] In one exemplary embodiment, such as Figure 7 As shown, after step 602, the method further includes steps 702 to 708. Wherein:
[0131] Step 702: If the compilation result is successful, the target application is obtained, and the test data is calculated and processed according to the target application to obtain the test calculation result.
[0132] In this embodiment of the application, if the compilation result is successful, the terminal can obtain the target application after the generated code is compiled by the target compiler. Then, the terminal selects a set of pre-set test data covering various boundary conditions and typical scenarios, and inputs the test data into the target application to run the target application. The target application calculates the test data to obtain the test calculation result corresponding to the current test data, which is used to evaluate the result of the target application compiled by the generated code.
[0133] Step 704: Determine the error result of the target application based on the test calculation results and the standard calculation results corresponding to the test data.
[0134] In this embodiment, the standard calculation result corresponding to the test data can be the standard parameter result calculated by physical modeling software for the same test data. The terminal traverses the test data, compares the test calculation result of each test data with the standard calculation result, obtains the relative error between each test data and the standard calculation result, and uses this relative error as the error result.
[0135] Step 706: If the error result is greater than the preset error threshold, the test result of the target application is determined as a test failure, and the error result is added to the target prompt.
[0136] In this embodiment, the terminal has a preset error threshold. The error result of the target application is compared and analyzed with the preset error threshold. If the error result is less than the preset error threshold, the test result of the target application is considered successful. If the error result is greater than the preset error threshold, the test result of the target application is considered a failure. In this case, the terminal directly adds the error result to the target prompt as the error warning information part of the target prompt, resulting in a reconstructed target prompt. Optionally, the terminal can also input test data, test calculation results, and standard calculation results into the LLM model. The LLM model analyzes the relative error of the target application to obtain the error result analysis, and the error result analysis output by the LLM model is added together with the actual error result to the target prompt.
[0137] For example, the relative errors between the test data and the standard calculation results are shown in Table 1 below. The results show that the relative errors in the calculation of density, specific heat and absolute viscosity of the three working fluids are all less than 1%, which is in line with the development expectations.
[0138] Table 1
[0139]
[0140] Step 708: Execute the second component based on the target prompt and data generation model to analyze and process the target prompt and obtain the generated code, until the test result of the target application is successful, and the target application is obtained.
[0141] In this embodiment of the application, the terminal analyzes the newly generated target prompt text repeatedly according to the same principle as step 106 to obtain the generated code. After the target compiler successfully compiles the generated code, the newly generated target application is tested using test data until the test result of the target application is successful, indicating that the error result of the target application is less than the preset error threshold. At this time, the target application that meets the development expectations is obtained.
[0142] In this embodiment, after the generated code successfully compiles and the target application is obtained, the terminal uses pre-set test data to perform calculations on the target application and obtain test calculation results. Subsequently, the test calculation results are compared with standard calculation results to calculate the error result. If the error result exceeds a preset error threshold, the error result is added to the target prompt, and the code is regenerated using the data generation model, then compiled and tested again until the error result meets expectations, i.e., the test result is considered successful, and finally, the target application that meets the development expectations is obtained. Through feedback mechanisms and iterative optimization, the calculation accuracy of the generated code is ensured, and through verification with test data, the quality and reliability of the target application are improved.
[0143] In one embodiment, such as Figure 8 As shown, an example of a data generation method is provided, including:
[0144] Step 801: Obtain the prompting framework information and target knowledge base data.
[0145] Step 802: Generate module prompts using LLM.
[0146] Step 803: Generate unit code using LLM.
[0147] Step 804: Determine whether all code generation is complete. If not all code has been generated, proceed to step 803; if all code has been generated, proceed to step 805.
[0148] Step 805: Determine whether the target compiler compiles and runs and generates the correct result. If the correct result is generated, the target application is obtained. If the target compiler fails to compile and run or the generated result does not meet the business requirements, add the compiler feedback information or error analysis results to the prompt framework information and re-execute step 802.
[0149] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0150] Based on the same inventive concept, this application also provides a data generation apparatus for implementing the data generation method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more data generation apparatus embodiments provided below can be found in the limitations of the data generation method described above, and will not be repeated here.
[0151] In one exemplary embodiment, such as Figure 9 As shown, a data generation device 900 is provided, including: a first acquisition module 901, a first generation module 902, and a second generation module 903, wherein:
[0152] The first acquisition module 901 is used to acquire the prompting framework information and retrieve target knowledge base data in the target knowledge base based on the prompting framework information;
[0153] The first generation module 902 is used to analyze and process the prompt framework information and target knowledge base data according to the first component of the data generation model to obtain the target prompt message;
[0154] The second generation module 903 is used to analyze and process the target prompt based on the target prompt and the second component of the data generation model to obtain the generated code; the generated code is used to build the target application.
[0155] In one embodiment, the first acquisition module 901 is specifically used to perform vectorized encoding of the prompt frame information according to the text embedding model to obtain the first query vector corresponding to the prompt frame information;
[0156] Based on the similarity between the first query vector and the second query vector corresponding to each candidate knowledge base data in the target knowledge base, the candidate knowledge base data are sorted to obtain the sorting result;
[0157] The target second query vector is determined based on the ranking results, and the target second query vector is used as the target knowledge base data.
[0158] In one embodiment, the device 900 further includes:
[0159] The second acquisition module is used to acquire initial materials, segment the initial materials into paragraphs, and obtain target materials.
[0160] The encoding module is used to vectorize the target material according to the text embedding model to obtain the second query vector and the number corresponding to the second query vector.
[0161] The building module is used to construct the target knowledge base based on the second query vector and the number.
[0162] In one embodiment, the first component includes a prompt generation structure and an encoding structure, and the target knowledge base data is the target second query vector corresponding to the prompt frame information;
[0163] The first generation module 902 is specifically used to vectorize the prompt frame information according to the encoding structure in the data generation model to obtain the encoding vector corresponding to the prompt frame information.
[0164] The encoded vector and the target second query vector are concatenated to obtain the target vector;
[0165] The target vector is analyzed and processed based on the prompt generation structure to obtain the target prompt.
[0166] In one embodiment, the device 900 further includes:
[0167] The first compilation module is used to compile the generated code according to the target compiler and obtain the compilation result;
[0168] The first update module is used to obtain the error information fed back by the target compiler if the compilation result is a compilation failure, add the error information to the target prompt, and obtain a new target prompt;
[0169] The second compilation module is used to execute the second component based on the target prompt and the data generation model to analyze and process the target prompt, obtain the generated code, and continue until the compilation result is successful, thus obtaining the target application.
[0170] In one embodiment, the device 900 further includes:
[0171] The test module is used to obtain the target application if the compilation result is successful, and to calculate and process the test data based on the target application to obtain the test calculation result;
[0172] The error calculation module is used to determine the error result of the target application based on the test calculation results and the standard calculation results corresponding to the test data.
[0173] The second update module is used to determine the test result of the target application as a test failure if the error result is greater than the preset error threshold, and to add the error result to the target prompt message.
[0174] The third generation module is used to execute the second component based on the target prompt and the data generation model to analyze and process the target prompt and obtain the generated code, until the test result of the target application is successful, and the target application is obtained.
[0175] Each module in the aforementioned data generation device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0176] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 10 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores a target knowledge base. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a data generation method.
[0177] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0178] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0179] Obtain the hint framework information, and retrieve the target knowledge base data based on the hint framework information;
[0180] The first component of the data generation model analyzes and processes the prompt framework information and target knowledge base data to obtain the target prompt message;
[0181] The second component, based on the target prompt and the data generation model, analyzes and processes the target prompt to obtain generated code; the generated code is used to build the target application.
[0182] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0183] The prompt frame information is vectorized based on the text embedding model to obtain the first query vector corresponding to the prompt frame information;
[0184] Based on the similarity between the first query vector and the second query vector corresponding to each candidate knowledge base data in the target knowledge base, the candidate knowledge base data are sorted to obtain the sorting result;
[0185] The target second query vector is determined based on the ranking results, and the target second query vector is used as the target knowledge base data.
[0186] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0187] Obtain initial materials, segment the initial materials into paragraphs, and obtain the target materials;
[0188] The target material is vectorized and encoded using a text embedding model to obtain the second query vector and the corresponding number.
[0189] Construct the target knowledge base based on the second query vector and the number.
[0190] In one embodiment, the first component includes a prompt generation structure and an encoding structure, and the target knowledge base data is the target second query vector corresponding to the prompt framework information; when the processor executes the computer program, it also implements the following steps:
[0191] The prompt frame information is vectorized according to the coding structure in the data generation model to obtain the coding vector corresponding to the prompt frame information.
[0192] The encoded vector and the target second query vector are concatenated to obtain the target vector;
[0193] The target vector is analyzed and processed based on the prompt generation structure to obtain the target prompt.
[0194] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0195] The generated code is compiled by the target compiler to obtain the compilation result;
[0196] If the compilation result is a compilation failure, obtain the error information fed back by the target compiler, add the error information to the target prompt, and obtain a new target prompt;
[0197] The second component, based on the target prompt and data generation model, analyzes and processes the target prompt to generate code, until the compilation result is successful, thus obtaining the target application.
[0198] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0199] If the compilation result is successful, the target application is obtained, and the test data is processed based on the target application to obtain the test calculation result;
[0200] The error result of the target application is determined based on the test calculation results and the standard calculation results corresponding to the test data;
[0201] If the error result is greater than the preset error threshold, the test result of the target application will be determined as a test failure, and the error result will be added to the target prompt message;
[0202] The second component, based on the target prompt and data generation model, analyzes and processes the target prompt to generate code, until the test result of the target application is successful, thus obtaining the target application.
[0203] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0204] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0205] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0206] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0207] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0208] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A data generation method, characterized in that, The method includes: Obtain the prompting framework information, and retrieve the target knowledge base data in the target knowledge base based on the prompting framework information; the prompting framework information is obtained by cleaning the software requirements document with text and recognizing named entities through a large language model to obtain class names, function names, and variable names, determining the relationships between entities through relation extraction technology, obtaining the code generation order, and constructing according to the code generation order; The first component of the data generation model analyzes and processes the prompting framework information and the target knowledge base data to obtain the target prompt; the target prompt also includes a top-level prompt and unit prompts. The top-level prompt includes a top-level goal, an organizational structure, and top-level constraints. The top-level goal is used to describe the project's goal, the organizational structure is used to describe the constituent units and functions of the code to be generated, and the top-level constraints are used to define the constraints in the development process. The unit prompt includes a unit description, unit structure, and implementation steps. The unit description includes the development goals and constraints corresponding to each unit; the unit structure includes class member variables and member functions, or function parameters and return values; the implementation steps describe the implementation logic and steps of the unit. The target prompt is analyzed and processed based on the target prompt and the second component of the data generation model to obtain generated code; the generated code is used to build the target application.
2. The method according to claim 1, characterized in that, The step of retrieving target knowledge base data from the target knowledge base based on the prompting framework information includes: The prompt frame information is vectorized and encoded according to the text embedding model to obtain the first query vector corresponding to the prompt frame information; Based on the similarity between the first query vector and the second query vector corresponding to each candidate knowledge base data in the target knowledge base, the candidate knowledge base data are sorted to obtain the sorting result. The target second query vector is determined based on the sorting result, and the target second query vector is used as the target knowledge base data.
3. The method according to claim 1, characterized in that, Before obtaining the prompting frame information and retrieving target knowledge base data from the target knowledge base based on the prompting frame information, the method further includes: Obtain initial material, and then segment the initial material into paragraphs to obtain target material; The target material is vectorized and encoded according to the text embedding model to obtain the second query vector and the number corresponding to the second query vector. Construct a target knowledge base based on the second query vector and the number.
4. The method according to claim 1, characterized in that, The first component includes a prompt generation structure and an encoding structure, and the target knowledge base data is the target second query vector corresponding to the prompt framework information; The step of analyzing and processing the prompt framework information and the target knowledge base data according to the first component of the data generation model to obtain the target prompt includes: The prompt frame information is vectorized according to the encoding structure in the data generation model to obtain the encoding vector corresponding to the prompt frame information; The encoded vector and the target second query vector are concatenated to obtain the target vector; The target vector is analyzed and processed according to the prompt generation structure to obtain the target prompt.
5. The method according to claim 1, characterized in that, After the second component of the data generation model analyzes and processes the target prompt and obtains the generated code, the method further includes: The generated code is compiled using the target compiler to obtain the compilation result. If the compilation result is a compilation failure, obtain the error information fed back by the target compiler, add the error information to the target prompt, and obtain a new target prompt; The second component, based on the target prompt and the data generation model, is executed to analyze and process the target prompt to obtain generated code, until the compilation result is successful, thus obtaining the target application.
6. The method according to claim 5, characterized in that, After compiling the generated code according to the target compiler to obtain the compilation result, the method further includes: If the compilation result is successful, the target application is obtained, and the test data is processed based on the target application to obtain the test calculation result; The error result of the target application is determined based on the test calculation results and the standard calculation results corresponding to the test data; If the error result is greater than a preset error threshold, the test result of the target application is determined to be a test failure, and the error result is added to the target prompt message; The second component, based on the target prompt and the data generation model, analyzes and processes the target prompt to generate code, until the test result of the target application is successful, thus obtaining the target application.
7. A data generation apparatus, characterized in that, The device includes: The first acquisition module is used to acquire the prompting framework information and retrieve target knowledge base data in the target knowledge base according to the prompting framework information; the prompting framework information is obtained by cleaning the software requirement document with text and recognizing named entities through a large language model to obtain class names, function names, and variable names, determining the relationship between entities through relation extraction technology, obtaining the code generation order, and constructing according to the code generation order; The first generation module is used to analyze and process the prompt framework information and the target knowledge base data according to the first component of the data generation model to obtain the target prompt; the target prompt also includes a top-level prompt and a unit prompt. The top-level prompt includes a top-level goal, an organizational structure and a top-level constraint. The top-level goal is used to describe the goal of the project. The organizational structure is used to describe the constituent units and functions of the code to be generated. The top-level constraint is used to define the constraints in the development process. The unit prompt includes a unit description, unit structure, and implementation steps. The unit description includes the development goals and constraints corresponding to each unit; the unit structure includes class member variables and member functions, or function parameters and return values; the implementation steps describe the implementation logic and steps of the unit. The second generation module is used to analyze and process the target prompt based on the target prompt and the second component of the data generation model to obtain generated code; the generated code is used to build the target application.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Intelligent question and answer method, system and device, computer equipment and readable storage medium
CN118377881A
Application program generation method and device and electronic equipment
CN119088355A