Code generation method and computing device
By using automated test cases and closed-loop iterative updates, the problem of logical errors in the code generated by the AI question-answering system was solved, enabling fast and accurate code generation and improving development efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XFUSION DIGITAL TECH CO LTD
- Filing Date
- 2025-08-06
- Publication Date
- 2026-06-16
AI Technical Summary
Existing AI question-answering systems generate code with logical errors or that deviates from the intended meaning of the requested information, requiring developers to manually correct them, which is inefficient.
By generating initial response information, automating test cases, and combining test results to determine target response information, we avoid initial code logic errors. We use abstract syntax trees to split code blocks, use template libraries to match test templates, and combine scenario description information to generate test parameters for closed-loop iterative updates.
It enables the rapid and accurate generation of code corresponding to request information, improving code generation efficiency and accuracy, reducing manual intervention, and ensuring the correctness of code logic.
Smart Images

Figure CN121166525B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computing technology, and in particular to a code generation method and a computing device. Background Technology
[0002] With the rapid advancement of Artificial Intelligence (AI) technology, AI question-answering systems have been widely applied in software development and technical support. For example, developers can submit requests (or "questions") to AI question-answering systems to assist in generating corresponding code. However, AI question-answering systems may generate partially erroneous code, which may deviate from the intended meaning of the request or contain logical errors.
[0003] In related technologies, users typically correct these erroneous codes manually, which leads to low efficiency in correcting these errors and consequently extends the development cycle.
[0004] Therefore, in AI question-answering systems, how to accurately generate the code corresponding to the request information has become an urgent problem to be solved. Summary of the Invention
[0005] This application provides a code generation method and computing device, which facilitates the rapid and accurate generation of code corresponding to request information.
[0006] In a first aspect, embodiments of this application provide a code generation method, the method comprising:
[0007] Obtain the request information sent by the terminal; the request information is used to request the generation of code.
[0008] Generate initial response information corresponding to the request information, which includes the initial code corresponding to the request information;
[0009] Based on the initial response information, test cases are determined, and the initial code is tested based on the test cases to obtain test results;
[0010] Based on the test results and the initial response information, the target response information corresponding to the request information is determined. The target response information includes the target code, which is determined based on the initial code.
[0011] Send the target response information to the terminal.
[0012] In the above technical solution, there is no need for manual testing of the initial code. Test cases are generated based on the initial response information, and the initial code is automatically tested using the test cases. The target response information is determined by combining the test results and the initial response information, so as to avoid logical errors or deviations from the original meaning of the request information in the initial code. This helps to ensure the accuracy of the target code in the target response information and improve the generation efficiency of the target code. As a result, the AI question answering system can quickly and accurately generate the code corresponding to the request information.
[0013] In one possible implementation, test cases are determined based on the initial response information, including:
[0014] The initial response information is parsed and processed to obtain the initial code and scenario description information corresponding to the request information;
[0015] Based on the syntax structure of the initial code, the initial code is split into multiple target code blocks;
[0016] Based on multiple target code blocks and / or scenario description information, determine the target test template corresponding to the initial code from multiple test templates in the template library;
[0017] Based on the scenario description information and multiple target code blocks, determine multiple test parameters corresponding to the initial code;
[0018] Based on multiple test parameters and the target test template, test cases are determined.
[0019] In the above technical solution, the initial response information can be parsed to obtain initial code and scenario description information. By splitting the initial code into multiple target code blocks in a standard format, the efficiency of test case generation can be improved. Furthermore, by combining the scenario description information and / or multiple target code blocks, the target test template corresponding to the initial code can be accurately matched in multiple test templates. In addition, by combining the scenario description information and multiple target code blocks, multiple test parameters can be determined more comprehensively. This makes the test cases generated based on multiple test parameters and target test templates more accurate and covers a more comprehensive test range. Consequently, the test results obtained based on the test cases are more accurate, ensuring that the AI question-answering system can quickly and accurately generate the code corresponding to the request information.
[0020] In one possible implementation, based on the syntactic structure of the initial code, the initial code is split into multiple target code blocks, including:
[0021] Generate an abstract syntax tree (AST) corresponding to the initial code, and perform syntax verification on the AST. The AST is used to represent the syntactic structure of the initial code.
[0022] If the syntax verification of the AST passes, the multiple target element types corresponding to the AST and the reference code blocks corresponding to each target element type are determined based on the code structure library. The code structure library includes multiple element types and the reference code blocks corresponding to each element type. The multiple element types include multiple target element types.
[0023] The AST is split into multiple target code blocks based on the reference code blocks corresponding to multiple target element types.
[0024] In the above technical solution, the initial code is converted into an AST, and after the syntax verification of the AST is passed, reference code blocks of multiple target element types corresponding to the AST are determined based on the code structure library. The AST is then split into multiple target code blocks of standard format based on these reference code blocks of multiple target element types. This allows the subsequent test generator to quickly generate test cases based on multiple target code blocks, thereby improving the efficiency of test case generation and thus improving the testing efficiency of the code in the response information.
[0025] In one possible implementation, the template library includes template information for multiple test templates, the template information including code type and template identifier; based on multiple target code blocks and / or scenario description information, the target test template corresponding to the initial code is determined from the multiple test templates in the template library, including:
[0026] Based on multiple target code blocks and / or scenario description information, determine the template indication information corresponding to the initial code. The template indication information includes the target code type and / or target template identifier.
[0027] Based on the template information and template instruction information of multiple test templates, the target test template is determined from among the multiple test templates.
[0028] In the above technical solution, the target code type is the code type corresponding to the target test template, and the target template identifier is the template identifier corresponding to the target test template. By combining multiple target code blocks and / or scenario description information, the template indication information corresponding to the initial code is determined, so as to accurately match the target test template corresponding to the initial code among multiple test templates, which helps to improve the accuracy of target test template matching. Furthermore, the template library includes test templates for various code types (programming language types and test framework types), which can flexibly adapt to the test template matching process in various test environments, with high flexibility, enabling it to generate richer test cases and more diverse test scenarios for the initial code.
[0029] In one possible implementation, based on scenario description information and multiple target code blocks, several test parameters corresponding to the initial code are determined, including:
[0030] Based on the scenario description information and multiple target code blocks, determine the test conditions for the initial code;
[0031] Based on the test conditions and multiple parameter generation rules, multiple test parameters are determined. The multiple parameter generation rules include at least one of the following: boundary value generation rules, outlier generation rules, and parameter type diversity input rules.
[0032] In the above technical solution, by combining scenario description information and multiple target code blocks, the test conditions corresponding to the initial code are determined to ensure that the test of the code covers the core test scenarios of user requirements (such as boundary conditions and functional correctness), and to ensure the comprehensiveness and accuracy of the test of the initial code.
[0033] In one possible implementation, the target response information corresponding to the request information is determined based on the test results and the initial response information, including:
[0034] If the test result is that the test passes, the initial response information will be determined as the target response information, and the target code in the target response information will be the initial code.
[0035] If the test result is that the test fails, the initial response information is updated based on the initial test process data to obtain the target response information. The initial test process data is generated during the testing of the initial code, and the target code in the target response information is obtained by updating the initial code.
[0036] In the above technical solution, if the test result is that the test fails, the initial response information can be updated by combining the initial test process data to generate more accurate target response information, which helps to ensure the accuracy of the target code in the generated target response information.
[0037] In one possible implementation, the initial response information is updated based on the initial test process data to obtain the target response information, including:
[0038] Based on the (i-1)th test process data, determine the i-th response information corresponding to the request information, and based on the i-th response information, determine the i-th test case. The (i-1)th test process data is generated during the testing of the i-1th code in the (i-1)th response information.
[0039] Based on the i-th test case, the i-th code in the i-th reply message is tested to obtain the i-th test result;
[0040] Where i takes the values 1, 2, ..., until the target response information is obtained based on the i-th test result. When i is 1, the i-1 test process data is the initial test process data, the i-1 response information is the initial response information, and the i-1 code is the initial code.
[0041] In the above technical solution, corresponding test cases can be generated based on the response information and executed automatically. This allows for automated testing of the response information's code. If the test fails, the (i-1)th response information can be automatically updated based on the (i-1)th test process data. This enables closed-loop iterative control of the response information corresponding to the request information, achieving automated correction of the response information (or code) to better reflect the correct response information required by the request information, thus improving the accuracy of the response information's code.
[0042] In one possible implementation, the target response information is obtained based on the i-th test result, including:
[0043] If the i-th test result is a pass, the i-th response information is determined as the target response information;
[0044] If the i-th test result is a failure, and if i is less than N and the i-th difference value is greater than or equal to the difference threshold, then based on the i-th test process data, determine the (i+1)-th response information corresponding to the request information, and obtain the target response information based on the (i+1)-th response information. The i-th test process data is generated during the testing of the i-th code. If i is greater than or equal to N, or the i-th difference value is less than the difference threshold, request the terminal to obtain update request information, and obtain the target response information based on the update request information. The update request information is obtained by updating the request information.
[0045] Where N is an integer greater than 1, the i-th difference value is the difference between the i-th code and the (i-1)-th code, and the i-th code is obtained by updating the (i-1)-th code.
[0046] In the above technical solution, if the i-th test result is a test failure, the maximum number of updates N and the difference threshold are set to avoid endlessly updating the response information corresponding to the request information in the event of logical errors in the request information, thereby reducing resource waste.
[0047] In one possible implementation, the i-th response information corresponding to the request information is determined based on the (i-1)-th test process data, including:
[0048] Based on the i-1 test process data, determine at least one error type corresponding to the i-1 code, as well as error detection data for each error type. The error detection data includes error description information and correction instruction information.
[0049] Based on the error detection data of at least one error type corresponding to the (i-1)th code, generate error feedback information corresponding to the (i-1)th code based on the error feedback template;
[0050] Based on the error feedback information corresponding to the (i-1)th code, the (i-1)th reply information is updated to obtain the i-th reply information.
[0051] In the above technical solution, standardized error feedback information corresponding to the i-1th code can be generated based on the i-1th test process data. The i-1th response information can be updated using this standardized error feedback information, thereby enabling closed-loop iterative control of the response information corresponding to the request information. This achieves automated correction and updating of the response information (or code) corresponding to the request information, making the response information closer to the correct response information required by the request information. This ensures that the AI question-answering system accurately generates the code corresponding to the request information.
[0052] Secondly, embodiments of this application provide a code generation apparatus, the apparatus comprising:
[0053] The transceiver module is used to obtain request information sent by the terminal, and the request information is used to request code generation.
[0054] The processing module is used to generate initial response information corresponding to the request information. The initial response information includes the initial code corresponding to the request information.
[0055] The processing module is also used to determine test cases based on the initial response information, and to test the initial code based on the test cases to obtain test results;
[0056] The processing module is also used to determine the target response information corresponding to the request information based on the test results and the initial response information. The target response information includes the target code, which is determined based on the initial code.
[0057] The transceiver module is also used to send target response information to the terminal.
[0058] The code generation apparatus provided in this application embodiment can execute the technical solutions described in any of the first aspects, and its beneficial effects are similar, so they will not be described again here.
[0059] In one possible implementation, the processing module is specifically used for:
[0060] The initial response information is parsed and processed to obtain the initial code and scenario description information corresponding to the request information;
[0061] Based on the syntax structure of the initial code, the initial code is split into multiple target code blocks;
[0062] Based on multiple target code blocks and / or scenario description information, determine the target test template corresponding to the initial code from multiple test templates in the template library;
[0063] Based on the scenario description information and multiple target code blocks, determine multiple test parameters corresponding to the initial code;
[0064] Based on multiple test parameters and the target test template, test cases are determined.
[0065] In one possible implementation, the processing module is further used for:
[0066] Generate an abstract syntax tree (AST) corresponding to the initial code, and perform syntax verification on the AST. The AST is used to represent the syntactic structure of the initial code.
[0067] If the syntax verification of the AST passes, the multiple target element types corresponding to the AST and the reference code blocks corresponding to each target element type are determined based on the code structure library. The code structure library includes multiple element types and the reference code blocks corresponding to each element type. The multiple element types include multiple target element types.
[0068] The AST is split into multiple target code blocks based on the reference code blocks corresponding to multiple target element types.
[0069] In one possible implementation, the template library includes template information for multiple test templates, the template information including code type and template identifier; the processing module is further used for:
[0070] Based on multiple target code blocks and / or scenario description information, determine the template indication information corresponding to the initial code. The template indication information includes the target code type and / or target template identifier.
[0071] Based on the template information and template instruction information of multiple test templates, the target test template is determined from among the multiple test templates.
[0072] In one possible implementation, the processing module is further used for:
[0073] Based on the scenario description information and multiple target code blocks, determine the test conditions for the initial code;
[0074] Based on the test conditions and multiple parameter generation rules, multiple test parameters are determined. The multiple parameter generation rules include at least one of the following: boundary value generation rules, outlier generation rules, and parameter type diversity input rules.
[0075] In one possible implementation, the processing module is further used for:
[0076] If the test result is that the test passes, the initial response information will be determined as the target response information, and the target code in the target response information will be the initial code.
[0077] If the test result is that the test fails, the initial response information is updated based on the initial test process data to obtain the target response information. The initial test process data is generated during the testing of the initial code, and the target code in the target response information is obtained by updating the initial code.
[0078] In one possible implementation, the processing module is further used for:
[0079] Based on the (i-1)th test process data, determine the i-th response information corresponding to the request information, and based on the i-th response information, determine the i-th test case. The (i-1)th test process data is generated during the testing of the i-1th code in the (i-1)th response information.
[0080] Based on the i-th test case, the i-th code in the i-th reply message is tested to obtain the i-th test result;
[0081] Where i takes the values 1, 2, ..., until the target response information is obtained based on the i-th test result. When i is 1, the i-1 test process data is the initial test process data, the i-1 response information is the initial response information, and the i-1 code is the initial code.
[0082] In one possible implementation, the processing module is further used for:
[0083] If the i-th test result is a pass, the i-th response information is determined as the target response information;
[0084] If the i-th test result is a failure, and if i is less than N and the i-th difference value is greater than or equal to the difference threshold, then based on the i-th test process data, determine the (i+1)-th response information corresponding to the request information, and obtain the target response information based on the (i+1)-th response information. The i-th test process data is generated during the testing of the i-th code. If i is greater than or equal to N, or the i-th difference value is less than the difference threshold, request the terminal to obtain update request information, and obtain the target response information based on the update request information. The update request information is obtained by updating the request information.
[0085] Where N is an integer greater than 1, the i-th difference value is the difference between the i-th code and the (i-1)-th code, and the i-th code is obtained by updating the (i-1)-th code.
[0086] In one possible implementation, the processing module is further used for:
[0087] Based on the i-1 test process data, determine at least one error type corresponding to the i-1 code, as well as error detection data for each error type. The error detection data includes error description information and correction instruction information.
[0088] Based on the error detection data of at least one error type corresponding to the (i-1)th code, generate error feedback information corresponding to the (i-1)th code based on the error feedback template;
[0089] Based on the error feedback information corresponding to the (i-1)th code, the (i-1)th reply information is updated to obtain the i-th reply information.
[0090] Thirdly, embodiments of this application provide a computing device, including: a processor and a memory; the processor and the memory are coupled;
[0091] Memory is used to store program instructions;
[0092] The processor is configured to execute program instructions to perform the method as described in any one of the first aspects.
[0093] The computing device provided in the embodiments of this application can execute the technical solutions described in any of the first aspects, and its beneficial effects are similar, so they will not be described again here.
[0094] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions that, when executed by a computer, implement the method as described in any one of the first aspects.
[0095] The computer-readable storage medium provided in the embodiments of this application can perform the technical solutions as described in any of the first aspects, and its beneficial effects are similar, so they will not be repeated here.
[0096] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the method described in any of the first aspects.
[0097] The computer program product provided in the embodiments of this application can execute the technical solutions described in any of the first aspects, and its beneficial effects are similar, so they will not be described again here.
[0098] The code generation method and computing device provided in this application embodiment can receive request information sent by a terminal and generate initial response information corresponding to the request information. After generating the initial response information, test cases can be generated based on the initial response information, and the initial code in the initial response information can be tested using the test cases. Furthermore, a target response information can be determined by combining the test results and the initial response information, and then sent to the terminal. The target response information may include target code, which can be determined based on the initial code. In this process, no manual testing and correction of the initial code is required. By testing the initial code in the response information, logical errors or deviations from the intended meaning of the request information in the initial code can be avoided, which is beneficial for quickly and accurately generating the code corresponding to the request information. Attached Figure Description
[0099] 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 or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0100] Figure 1A This is a schematic diagram of an application scenario provided by an embodiment of this application;
[0101] Figure 1B This is a schematic diagram of the structure of an AI question-answering system provided in an embodiment of this application;
[0102] Figure 2 One of the flowcharts illustrating the code generation method provided in this application embodiment;
[0103] Figure 3 A second schematic flowchart illustrating the code generation method provided in this application embodiment;
[0104] Figure 4 A schematic diagram illustrating the initial code splitting process provided in an embodiment of this application;
[0105] Figure 5 The third flowchart illustrating the code generation method provided in this application embodiment;
[0106] Figure 6 The fourth flowchart illustrating the code generation method provided in this application embodiment;
[0107] Figure 7 A schematic diagram illustrating error feedback information provided in an embodiment of this application;
[0108] Figure 8This is a schematic diagram of the structure of a code generation device provided in an embodiment of this application;
[0109] Figure 9 This is a schematic diagram of the hardware structure of a computing device provided in an embodiment of this application. Detailed Implementation
[0110] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with those of this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the embodiments of this application as detailed in the appended claims.
[0111] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of the technical solutions in the embodiments of this application. However, it does not mean that the applicant has used or necessarily used such solutions.
[0112] 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, stored data, displayed data, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0113] It should be noted that in the embodiments of this application, the term "at least one" refers to one or more, and "more than one" refers to two or more.
[0114] First, the terminology used in the embodiments of this application will be explained.
[0115] Automated test feedback refers to the process by which a system (e.g., an automated testing system) automatically collects and analyzes test results after executing test cases using automated tools, and then provides real-time feedback of key information from the test results (such as pass rate, reasons for failure, performance metrics, etc.) to the end user (e.g., the computer used by developers or testers). This allows users to make code corrections or optimize processes based on the key information provided by the system feedback, thus achieving closed-loop feedback control. The automated test feedback process mainly includes the following stages: automated test execution, result collection and analysis, and closed-loop feedback control. Its core objective is to shorten the feedback cycle, improve testing efficiency, and enhance software quality through iterative optimization.
[0116] A parser, typically a component of a compiler or interpreter, performs syntax checking and constructs a data structure (such as a hierarchical data structure like a parse tree or abstract syntax tree) from the input words. A parser usually uses a separate lexical analyzer to separate individual "words" from the input character stream, forming a word stream, which is then used as its input. In practice, parsers can be written manually by developers or generated (semi-)automatically using tools. The tasks of a parser can include: determining whether the input string (input text) can be derived from the start symbols of the grammar; and how to derive the input string (input text) from the start symbols of the grammar. Parsers can employ two main analysis methods:
[0117] Top-down parsing: According to formal grammar rules, in the top-down expansion of the parse tree, the parser searches for the leftmost possible derivation of the input string. During top-down parsing, words can be used sequentially from left to right.
[0118] Bottom-up parsing: The parser starts with the input string and attempts to rewrite it according to the given formal grammar rules to transform it into the starting symbols of the grammar.
[0119] Sandboxing, in the field of computer science, is a security mechanism used to isolate running programs. Its purpose is to restrict access permissions for untrusted processes or code. The name "sandbox" comes from sandbox games, where users can freely use their imagination to build a small, isolated world, just as a sandbox provides a virtual environment for a program to be executed. This virtual environment contains virtual hardware and software resources, such as file systems, networks, and operating systems, allowing applications or processes to run within it. Programs running in a sandbox can only access the resources loaded for them by the sandbox and will not affect external applications, systems, or platforms, preventing them from causing permanent changes to other programs or data on the computing device. In the field of network security, sandboxing can isolate dangerous files within the sandbox to identify unknown attacks.
[0120] AI-assisted coding refers to the use of artificial intelligence technologies (such as large language models and machine learning algorithms) to automatically complete or optimize coding tasks in software development, including code generation, completion, testing, and refactoring. AI-assisted coding aims to improve development efficiency, reduce repetitive work, and assist in code quality management. Its core is to achieve intelligent coding through deep learning of massive code repositories, development standards, and contextual information using algorithmic models.
[0121] Abstract Syntax Tree (AST): In computer science, an AST is an abstract representation of the syntactic structure of source code, often simply called a syntax tree. An AST represents the syntactic structure of a programming language in a tree-like format, where each node represents a structure within the source code. The syntax is described as "abstract" because it doesn't represent every detail of the actual syntax.
[0122] To facilitate understanding of the code generation method provided in the embodiments of this application, the application scenarios involved in the embodiments of this application will first be introduced.
[0123] Figure 1A This is a schematic diagram illustrating an application scenario provided by an embodiment of this application. Please refer to... Figure 1A AI question-answering scenarios include terminals and computing devices. The computing devices and terminals can communicate and interact. For example, the computing devices can be, but are not limited to, independent physical servers, server clusters composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The terminals can be, but are not limited to, smartphones, smartwatches, tablets, laptops, desktop computers, and portable laptops.
[0124] The computing device may run an AI question-answering system, which in some embodiments may also be referred to as an AI code question-answering tool.
[0125] The terminal can display the dialogue interface of the AI question-answering system. Users can input request information through the dialogue interface on the terminal, and the terminal can send the request information to the computing device. The request information can be used to request the generation of code.
[0126] The computing device (or AI question-answering system) can receive request information sent by the terminal and generate initial response information corresponding to the request information. This initial response information includes initial code corresponding to the request information. The computing device can also determine test cases based on the initial response information, test the initial code based on the test cases, obtain test results, and determine the target response information corresponding to the request information based on the test results and the initial response information, and send the target response information to the terminal. The target response information may include target code, which can be determined based on the initial code. In this process, no manual testing or correction of the initial code is required. After generating the initial response information corresponding to the request information, the computing device can generate test cases based on the initial response information and test the initial code using the test cases. It can also determine the target response information by combining the test results and the initial response information. This avoids logical errors or deviations from the original intent of the request information in the initial code, ensuring the accuracy of the target code in the target response information and improving the efficiency of target code generation. This allows the AI question-answering system to quickly and accurately generate the code corresponding to the request information.
[0127] In actual code development, developers can use the aforementioned AI question-and-answer system to generate code, thereby shortening the development cycle.
[0128] In some embodiments, the request information can be understood as a question raised by a user to the AI question-answering system through a terminal, and the target response information can be understood as the corresponding answer generated by the AI question-answering system based on the question.
[0129] The AI question-answering system provided in this application embodiment can receive request information sent by users through terminals, and generate test cases corresponding to the initial code based on the initial response information corresponding to the request information, so as to test the initial code through the test cases and avoid logical errors or deviations from the original intent of the request information in the initial code; the AI question-answering system can also verify whether the initial response information meets the requirements of the request information based on the test results of the initial code, and can correct the initial response information after the verification fails to obtain the response information that meets the requirements of the request information.
[0130] Figure 1B This is a schematic diagram of the structure of an AI question-answering system provided in an embodiment of this application. Please refer to [link / reference]. Figure 1B An AI question-answering system may include a code extraction module, a test generator, a secure execution engine, and a feedback optimizer, among which:
[0131] (1) Code extraction module
[0132] The code extraction module can be used to acquire request information sent by the terminal, generate corresponding response information through an AI model, and extract multiple target code blocks and scene description information from the response information. This provides structured input information for automated testing and feedback optimization of the code in the subsequent AI question-answering system. The code extraction module can perform code separation, syntax validation, and structured input processing on the response information generated by the AI model to achieve efficient conversion from response information to code.
[0133] It should be noted that this AI model can run on computing devices or other devices, and the code extraction module can call the AI model based on its API.
[0134] (2) Test Generator
[0135] The test generator can automatically create adapted test cases for the code in the response information based on multiple target code blocks and scenario description information, ensuring that the testing of the code covers the core test scenarios of user requirements (such as boundary conditions and functional correctness). The test optimizer can combine code analysis and rule engine to automatically generate test logic for test cases, quickly transforming the code in the response information into executable test cases.
[0136] (3) Safe Execution Engine
[0137] The secure execution engine can implement functions such as environment isolation, exception control, resource limiting, and logging for test cases.
[0138] The secure execution engine can be used to build a sandbox environment using Docker containers and Node.js subprocesses, which can then be used to automate the execution of test cases.
[0139] In some embodiments, if at least one test case exists, the secure execution engine can build a test execution environment using a Docker container and utilize the child process module of the Node.js child process to create test processes corresponding to each test case within the Docker container. In this process, a highly secure test execution environment can be built using the Docker container, isolating the test execution environment of the test cases from the execution environments of other processes on the computing device. Furthermore, by performing multi-layered exception handling and logging on the test cases (including the Docker container layer and the child process layer), code escape can be prevented, avoiding interference from abnormal conditions of the test cases (e.g., abnormal operations or abnormal code) on other execution processes on the computing device, ensuring the stability and traceability of the testing process. Creating test processes corresponding to each test case through Node.js child processes isolates the automated testing processes of each test case within the Docker container, preventing mutual interference between the automated testing processes of each test case and ensuring the smooth operation of the automated testing processes of each test case.
[0140] The secure execution engine can control the resources used by Docker containers to prevent them from consuming excessive computing resources and causing resource abuse. For example, the secure execution engine can limit the memory used by a Docker container to 512MB and restrict it to one CPU core.
[0141] The secure execution engine can send test process data generated during the automated testing of code to the feedback optimizer.
[0142] (4) Feedback Optimizer
[0143] Feedback optimizers can have functions such as dynamic correction, iterative improvement, and scenario adaptation.
[0144] The feedback optimizer can be used to obtain the test results of the code and, if the test result is a pass, send the target response information, which includes the target code, to the terminal. If the test result is a fail, based on the test process data, it determines the reason why the code in the response information failed the test, generates a corresponding error feedback information with a fixed structure, and passes this error feedback information to the code extraction module. The code extraction module then triggers the AI model to regenerate the response information (or the code in the response information). In this process, through closed-loop iterative control of the response information (or the code in the response information), automated correction and optimization of the response information (or the code in the response information) can be achieved, ensuring that the generated response information adapts to the scenario of the request information; that is, the response information is the correct response information expected by the user. The feedback optimizer can choose whether to trigger the code extraction module to correct the response information (or the code in the response information) based on the test results of the code in the response information. Through multiple rounds of interaction between the feedback optimizer and the code extraction module, the response information gradually approaches the correct response information corresponding to the request information.
[0145] The AI question-answering system provided in this application embodiment may include the following modules: a code extraction module, a test generator, a secure execution engine, and a feedback optimizer. The code extraction module can generate response information based on the request information sent by the terminal. The response information may include code. The code extraction module can identify and separate multiple target code blocks and scene description information corresponding to the code from the response information using a syntax analyzer. The test generator can generate test cases based on the multiple target code blocks and scene description information. The secure execution engine can build a sandbox environment using Docker containers and Node.js subprocesses and automatically execute test cases in the sandbox environment. The feedback optimizer can determine the test result of the initial code. If the test result is a pass, it sends the response information to the terminal; if the test fails, it generates error feedback information based on the test process data generated during the testing of the code and sends the error feedback information to the code extraction module, so that the code extraction module updates the response information (or the code in the response information) based on the error feedback information, thereby realizing intelligent feedback optimization of the code that failed the test. These modules in the AI question-answering system work together to achieve closed-loop iterative control of the response information (or the code in the response information), ensuring that the AI question-answering system can quickly and accurately generate the code corresponding to the request information, thus improving the accuracy of the response information generated by the AI question-answering system. The AI question-answering system does not require manual intervention in the process of correcting the response information, which helps to improve the efficiency of the AI question-answering system in correcting the response information. Furthermore, by building a sandbox environment to provide a secure execution environment for test cases, the automated test execution process of the test cases is isolated from other execution processes in the computing device, which helps to ensure the security and operational stability of the computing device.
[0146] The AI question-answering system and code generation method provided in this application can provide standardized and scalable intelligent support for software development, so as to realize an AI-driven, fully automated development process.
[0147] The technical solutions of the embodiments of this application will be described in detail below with specific examples. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0148] Figure 2 This is one of the flowcharts illustrating the code generation method provided in this application. Please refer to... Figure 2 The method may specifically include the following steps:
[0149] S201. The computing device obtains the request information sent by the terminal.
[0150] Accordingly, the terminal can send a request message to the computing device, which can be used to request the generation of code.
[0151] The request information can be text information described in natural language; or the request information can be voice information, which the computing device can convert into text information.
[0152] For example, the request information could be "Write a JavaScript function to calculate the nth term of the Fibonacci sequence, and return 5 when n=5 and 0 when n=0".
[0153] This step can be performed by a computing device, for example, by a code extraction module in the computing device, which can be used to communicate and interact with the terminal to obtain request information sent by the terminal.
[0154] S202. The computing device generates the initial response information corresponding to the request information.
[0155] The initial response information may include the initial code corresponding to the request information.
[0156] Optionally, the initial response information may also include a scenario description corresponding to the request information. For example, the scenario description information may include the question and expected result corresponding to the request information.
[0157] For example, the initial response information could be: "According to your requirements, we need to write a JavaScript function that outputs 5 when the input n is 5, and outputs 0 when the input n is 0. The following is the function that meets your requirements: Code 1." Here, the initial code can be "Code 1", the scenario description information can be: "According to your requirements, we need to write a JavaScript function that outputs 5 when the input n is 5, and outputs 0 when the input n is 0. The following is the function that meets your requirements:", the question can be: "According to your requirements, we need to write a JavaScript function", and the expected result can be: "Outputs 5 when the input n is 5; outputs 0 when the input n is 0".
[0158] This step can be performed by a computing device, for example, by a code extraction module within the computing device.
[0159] Alternatively, the computing device (or code extraction module) may generate the initial response information in the following two ways:
[0160] Method 1: The computing device can run an AI model. The computing device (or code extraction module) can input request information into the AI model, and the AI model can generate and output mixed text based on the request information. This "mixed text" is the "initial response information" mentioned above. The AI model can use AI-assisted coding technology to generate this initial response information.
[0161] Method 2: The AI model runs on a device other than the computing device. The computing device (or code extraction module) can call the AI model based on the AI model's calling interface to generate the initial response information corresponding to the request information through the AI model.
[0162] S203. The computing device determines test cases based on the initial response information, and tests the initial code based on the test cases to obtain test results.
[0163] Test cases may include, but are not limited to, the following information: function name, input parameters, expected output parameters, and description field. For example, the function name may be "fib", the input parameter may be "fib(5)", the expected output parameter may be "5", and the description field may be "n=5 should return 5".
[0164] The test result can be either "test passed" or "test failed" (or "test failed").
[0165] Optionally, at least one test case can be determined based on the initial response information, and the initial code can be tested based on the at least one test case to obtain test results.
[0166] This step can be performed by a computing device, for example, by a code extraction module, a test generator, a secure execution engine, and a feedback optimizer working together within the computing device. Specifically, the code extraction module and the test generator can cooperate to determine test cases based on the initial response information; the secure execution engine and the feedback optimizer can cooperate to test the initial code based on the test cases and obtain test results.
[0167] It should be noted that the process of determining test cases based on the initial response information will be... Figure 3 Detailed explanation is provided in the embodiments.
[0168] In some embodiments, after determining at least one test case, the security execution engine can add the at least one test case to a continuous integration (CI), continuous deployment (CD), or continuous delivery (CD) process to trigger automated test execution of at least one test case.
[0169] The secure execution engine can obtain the actual output parameters of each test case and compare the actual output parameters of the test case with the expected output parameters to obtain the execution result of the test case. The execution result can be either successful or unsuccessful (or "failed").
[0170] The secure execution engine can send the execution results of at least one test case to the feedback optimizer.
[0171] The feedback optimizer can determine the test results of the initial code based on the execution results of at least one test case.
[0172] For a test case, if the test case passes, the feedback optimizer can determine that the initial code has passed the test; if the test case fails, the feedback optimizer can determine that the initial code has failed the test.
[0173] If all test cases pass, the feedback optimizer determines that the initial code has passed the test; if at least one test case fails, the feedback optimizer determines that the initial code has failed the test.
[0174] S204. The computing device determines the target response information corresponding to the request information based on the test results and the initial response information.
[0175] The target response information may include a target code, which may be determined based on the initial code.
[0176] This step can be performed by a computing device, for example, by a feedback optimizer within the computing device.
[0177] In some embodiments, the computing device (or feedback optimizer) may determine the target response information in the following manner: if the test result is a pass, the initial response information can be determined as the target response information, and the target code in the target response information is the initial code; if the test result is a fail, the initial response information can be updated based on the initial test process data of the test case to obtain the target response information, where the initial test process data is generated during the testing of the initial code, and the target code in the target response information is obtained by updating the initial code.
[0178] Initial testing process data may include test execution logs and resource usage information obtained from testing the initial code based on test cases. The test execution logs can be data generated by the testing framework (e.g., Jest / Mocha) during the execution of test cases, and can be used to record the execution results and detailed information of the test cases. Resource usage information can be used to indicate the resource consumption of the runtime environment executing the test cases; for example, the runtime environment of the test cases can be a Docker container or a sandbox environment built based on Docker containers.
[0179] For example, test execution logs may include the execution results of test cases, error stacks, and test duration. Error stacks can be used to locate errors; for example, they can be used to identify test cases that failed and the reasons why those test cases failed.
[0180] For example, resource usage information may include CPU utilization, memory utilization, memory usage, and execution time information, and the execution time information may include at least one of the following: test start time, test end time, and test duration.
[0181] Optionally, the secure execution engine may acquire the initial test process data during the testing of the initial code based on test cases and send the initial test process data to the feedback optimizer. Alternatively, the feedback optimizer may request the initial test process data from the secure execution engine.
[0182] It should be noted that the process of updating the initial response information based on the initial test process data to obtain the target response information will be... Figure 5 Detailed explanation is provided in the embodiments.
[0183] S205. The computing device sends the target response information to the terminal.
[0184] Accordingly, the terminal can receive target response information sent by the computing device, which may include scenario description information and target code corresponding to the request information.
[0185] For example, the target response information could be: "According to your requirements, we need to write a JavaScript function that outputs 5 when the input n is 5, and outputs 0 when the input n is 0. This conforms to the definition of the Fibonacci sequence, where the first two terms of the Fibonacci sequence are 0 and 1, and each subsequent term is the sum of the first two terms. The following is the function that meets your requirements: Code 2." The scenario description information is: "According to your requirements, we need to write a JavaScript function that outputs 5 when the input n is 5, and outputs 0 when the input n is 0. This conforms to the definition of the Fibonacci sequence, where the first two terms of the Fibonacci sequence are 0 and 1, and each subsequent term is the sum of the first two terms. The following is the function that meets your requirements:", and the target code could be "Code 2".
[0186] Optionally, the scene description information in the target response information can be the same as the scene description information in the initial response information; or, the scene description information in the target response information can be different from the scene description information in the initial response information.
[0187] This step can be performed by the computing device, for example, by the feedback optimizer in the computing device, or it can be performed jointly by the feedback optimizer and the code extraction module.
[0188] The feedback optimizer can determine the response information as the target response information and send it to the terminal after at least one test case corresponding to the code of the response information has passed the test. Alternatively, the feedback optimizer can send the target response information to the code extraction module, which then sends it to the terminal.
[0189] The code generation method provided in this application embodiment can generate initial response information corresponding to the request information after receiving the request information, determine test cases based on the initial response information, test the initial code based on the test cases, and determine the target response information by combining the test results and the initial response information. This avoids logical errors or deviations from the original intent of the request information in the initial code, which helps to ensure the accuracy of the target code in the target response information and improve the generation efficiency of the target code, enabling the AI question-answering system to quickly and accurately generate the code corresponding to the request information.
[0190] Figure 3 This is a second flowchart illustrating the code generation method provided in this application's embodiments. Please refer to... Figure 3 The method may specifically include the following steps:
[0191] S301. Parse and process the initial response information to obtain the initial code and scenario description information corresponding to the request information.
[0192] This step S301 can be performed by a computing device, for example, by a code extraction module in the computing device.
[0193] In some embodiments, the computing device (or code extraction module) can parse the initial response information using a parser to separate the initial code and scene description information from the initial response information. For example, the parser can be an Esprima parser for JavaScript (which supports AST generation).
[0194] In some embodiments, the computing device (or code extraction module) can extract the initial code from the initial response information using regular expressions.
[0195] S302. Based on the syntax structure of the initial code, the initial code is split into multiple target code blocks.
[0196] This step S302 can be performed by a computing device, for example, by a code extraction module in the computing device.
[0197] In some embodiments, the computing device (or code extraction module) may perform steps one through three as follows via a parser to split the initial code into multiple code blocks:
[0198] Step 1: Generate the AST corresponding to the initial code and perform syntax verification on the AST.
[0199] An AST can be used to characterize the syntactic structure of the initial code.
[0200] For example, the initial code can be JavaScript code, and the computing device (or code extraction module) can call the parseScript function of the Esprima parser to parse the initial code into an AST and verify that the syntax of the generated AST is correct.
[0201] The syntax verification result of the AST can be either syntax verification passed or syntax verification failed. If the syntax verification of the AST is passed, the computing device (or code extraction module) can continue to execute step two. If the syntax verification of the AST is failed, the computing device (or code extraction module) can regenerate the code corresponding to the request information and repeat step one. If the syntax verification of the AST corresponding to the code generated after N repetitions is still failed, an error message is generated and sent to the terminal. The error message can be used to instruct the terminal to re-enter the request information, where N can be an integer greater than or equal to 1.
[0202] For example, in some scenarios, if there is a logical error in the request information, the AST of the initial code generated by the code extraction module based on the request information may always fail syntax validation. In this case, in order to avoid the code extraction module iterating and updating the generated code indefinitely, the user can set a maximum number of repetitions N (e.g., 5) to avoid the code extraction module working ineffectively and wasting resources.
[0203] Step 2: If the syntax verification of the AST passes, determine the multiple target element types corresponding to the AST and the reference code blocks corresponding to each target element type based on the code structure library.
[0204] The code structure library can include multiple element types and reference code blocks corresponding to each element type. Multiple element types can include multiple target element types.
[0205] Optionally, each element type may correspond to a reference code block of at least one programming language type. For example, the programming language type may include, but is not limited to, JavaScript and Java.
[0206] Before performing step two, users can analyze the syntax types (such as functions, variables, loops, etc.) and contextual relationships (such as function names, parameters, return value logic, etc.) of each element in the AST of multiple historical code sources to determine the multiple element types that may exist in the AST, as well as the reference code blocks corresponding to each element type. Based on these multiple element types and the reference code blocks corresponding to each element type, the user can construct the code structure library. For example, the code structure library can be shown in Table 1.
[0207] Table 1
[0208]
[0209] For example, if the programming language is JavaScript, its reference code block may include:
[0210] (1) The reference code block for the function declaration, including the function name and parameter list, such as function <name> ( <params>){...};
[0211] (2) The reference code block for conditional statements, including the condition, such as if( <condition>){...};
[0212] (3) The reference code block for the loop structure, including the loop condition, such as for(let i = 0; i... <n;i++){...};
[0213] (4) A reference code block for asynchronous operations, used to define asynchronous functions, such as async function fetchData(){...}.
[0214] Step 3: Based on the reference code blocks corresponding to multiple target element types, split the AST into multiple target code blocks.
[0215] For any target element type, the reference code block of the target element type can be matched with the AST to find at least one target code block corresponding to the reference code block in the AST, and the at least one target code block can be split from the AST.
[0216] Optionally, if the format of the target code block is different from that of the reference code block, the format of the target code block can be updated to the format of the reference code block.
[0217] Below, in conjunction with Figure 4 The process of splitting the initial code into target code blocks is explained. Figure 4 For a schematic diagram of the initial code splitting process provided in an embodiment of this application, please refer to [link / reference]. Figure 4 It can generate the AST corresponding to the initial code and split the AST into the following three target code blocks: the code block corresponding to the function declaration, such as "function fib(n)"; the code block corresponding to the boundary condition, such as "if(n<=1)return n"; and the code block corresponding to the recursive logic, such as "return fib(n-1)+fib(n-2)".
[0218] This method converts the initial code into an Abstract Syntax Tree (AST), and after the AST passes syntax verification, determines reference code blocks of multiple target element types corresponding to the AST based on the code structure library. Based on these reference code blocks of multiple target element types, the AST is split into multiple target code blocks in a standard format. This allows the subsequent test generator to quickly generate test cases based on multiple target code blocks, improving the efficiency of test case generation and thus improving the testing efficiency of the code in the response information.
[0219] S303. Based on multiple target code blocks and scenario description information, determine the target test template corresponding to the initial code from multiple test templates in the template library.
[0220] The template library can include template information corresponding to multiple test templates. This template information may include, but is not limited to, code type and template identifier. The template identifier may include the name and / or index of the test template; the code type may include the programming language type and / or test framework type corresponding to the test template.
[0221] Optionally, the template information may also include template examples.
[0222] Template libraries can be stored in the form of data tables, for example, as shown in Table 2.
[0223] Table 2
[0224]
[0225] For example, the programming language types in the template library may include, but are not limited to, JavaScript and Java. The JavaScript test framework type may include Jest, and the corresponding Jest template example may include a description, function name, input parameters, and expected output parameters, for example, "test('description', () => expect(function name(input)).toEqual(expected))". The Java test framework type may include JUnit, and the corresponding JUnit template example may include a function name, input parameters, and expected output parameters, for example, "@Test public void test function name(){assertEquals(expected, function name(input));}".
[0226] This step S303 can be performed by a computing device, for example, by a test generator in the computing device.
[0227] In some embodiments, the computing device (or test generator) may determine the target test template by performing the following steps: determining template indication information corresponding to the initial code based on multiple target code blocks and / or scenario description information, wherein the template indication information includes the target code type and / or target template identifier; and determining the target test template among multiple test templates based on the template information and template indication information corresponding to multiple test templates.
[0228] In some embodiments, if the scenario description information indicates a programming language type, the template indication information corresponding to the initial code can be determined based on the programming language type; if the scenario description information does not indicate a programming language type, the template indication information can be determined based on the programming language types of multiple target code blocks.
[0229] Optionally, the programming language type indicated in the scene description information or the programming language type of multiple target code blocks can be determined as the target code type.
[0230] Optionally, the test framework type corresponding to the programming language type can be further determined based on the programming language type, and the programming language type and / or test framework type can be determined as the target code type. The test framework type can be the default test framework type corresponding to the programming language type or the most frequently used test framework type.
[0231] Optionally, after determining the target code type, a target template identifier can be further determined based on the target code type. For example, if the target code type includes a programming language type, the template identifier corresponding to the default (or most frequently used) test framework type of that programming language type can be determined as the target template identifier; if the target code type includes both a programming language type and a test framework type, the template identifier corresponding to that test framework type can be determined as the target template identifier.
[0232] If the template indication information includes a target template identifier, the test template corresponding to the target template identifier in the template library can be identified as the target test template. For example, if the template indication information corresponding to the initial code includes the target template identifier A-1, the target test template can be identified as example A-1 according to the template library shown in Table 2.
[0233] When the template instruction information includes the target code type, there are two scenarios:
[0234] Scenario 1: If the target code type includes a programming language type, it may match one or more test templates corresponding to that programming language type.
[0235] In this case, if a test template is matched, it can be identified as the target test template; if multiple test templates are matched, the test template with the highest usage rate among the multiple test templates or the default test template corresponding to the programming language type can be identified as the target test template.
[0236] Case 2: If the target code type includes a test framework type, that is, the target code type includes a test framework type alone, or the target code type includes both a test framework type and a programming language type, the test template corresponding to the test framework type in the template library can be determined as the target test template.
[0237] This method combines multiple target code blocks and / or scenario description information to determine the template indication information corresponding to the initial code, thereby accurately matching the target test template corresponding to the initial code among multiple test templates, which helps improve the accuracy of target test template matching. Furthermore, the template library includes test templates for various programming languages and test frameworks, allowing it to flexibly adapt to the test template matching process in various testing environments, demonstrating high flexibility.
[0238] S304. Based on the scenario description information and multiple code blocks, determine multiple test parameters corresponding to the initial code.
[0239] This step S304 can be performed by a computing device, for example, by a test generator in the computing device.
[0240] In some embodiments, the computing device (or test generator) may determine multiple test parameters by performing the following steps: determining the test conditions corresponding to the initial code based on scenario description information and multiple target code blocks; and generating multiple test parameters based on the test conditions and multiple parameter generation rules.
[0241] Optionally, the test generator can parse the scenario description information to parse the test conditions set in the request information; the test generator can also parse the logical relationship between multiple target code blocks to identify the function parameters and test conditions of the initial code.
[0242] This method combines scenario description information and multiple target code blocks to determine the test conditions corresponding to the initial code, ensuring that the testing of the code covers the core test scenarios of user requirements (such as boundary conditions and functional correctness), and guaranteeing the comprehensiveness and accuracy of the testing of the initial code.
[0243] For example, if the scenario description is "According to your requirements, we need to write a JavaScript function that outputs 5 when the input n is 5 and 0 when the input n is 0. The following is the function that meets your requirements:", the test generator can parse and process the above scenario description and extract the following test conditions:
[0244] Test condition 1: When the input n is 5, the output is 5;
[0245] Test condition 2: When the input n is 0, the output is 0.
[0246] For example, the test generator can parse the code block "function fib(n)" to determine that the function is a Fibonacci sequence and the function parameter n is an integer; it can also parse the code block "if(n<=1)return n" to determine the boundary test conditions.
[0247] Optionally, the multiple parameter generation rules may include at least one of the following:
[0248] (1) Boundary value generation rules: For numerical parameters, generate minimum, maximum and critical values.
[0249] (2) Outlier generation rules: For numerical parameters, generate minimum, maximum and critical values.
[0250] (3) Input rules for parameter type diversity: Randomly generate test parameters of various parameter types. For example, the parameter type of the Fibonacci sequence function is numerical, and some non-numerical parameters such as strings and arrays can be randomly input.
[0251] In some embodiments, the test generator may store mapping relationships, which may include multiple test conditions and parameter generation rules corresponding to each test condition. The test generator can determine the parameter generation rules corresponding to the initial code based on the test conditions and mapping relationships corresponding to the initial code.
[0252] Multiple test parameters can include function name, input parameters, and expected output parameters. The input parameters and expected output parameters can form a parameter pair.
[0253] Optionally, the multiple test parameters may also include some feature parameters, such as timeout duration.
[0254] For example, based on the test conditions extracted from the scene description information, two sets of parameter pairs can be determined, namely: (fib(5), 5) and (fib(0), 0). Based on the code block, the function name can be determined as "fib". Based on the boundary test conditions (n<=1) determined by the code block, according to the boundary value generation rules and the boundary test conditions (n<=1), the following parameter pairs can be determined, namely: (fib(0), 0), (fib(1), 1), (fib(2), 2), (fib(5), 5), (fib(-1), outlier), (fib(1.5), outlier).
[0255] S305. Based on multiple test parameters and the target test template, determine the test cases.
[0256] The target test template may include multiple placeholders, which may include, but are not limited to: placeholders corresponding to function names, input parameters, expected output parameters, and description fields.
[0257] In some embodiments, the multiple placeholders may also include placeholders for some feature parameters, for example, the multiple placeholders may include placeholders for timeout duration.
[0258] This step S305 can be performed by a computing device, for example, by a test generator in the computing device.
[0259] In some embodiments, a computing device (or test generator) may determine test cases by performing the following steps: determining the correspondence between multiple test parameters and multiple placeholders in a target test template; and replacing the multiple placeholders in the target test template with multiple test parameters according to the correspondence to obtain test cases.
[0260] For example, the substitution logic between test parameters and placeholders may include:
[0261] 1. Replace the placeholders corresponding to function names in the target test template with the function names from the multiple test parameters. For example, if the placeholder for the function name in the target test template is "<%=functionName%>", and the function name in the multiple test parameters is "fib", you can replace "<%=functionName%>" with "fib" in the target test template.
[0262] 2. Replace the placeholders corresponding to the input parameters in the target test template with the input parameters from the multiple test parameters, and replace the placeholders corresponding to the expected output parameters with the expected output parameters from the multiple test parameters. For example, if the placeholders corresponding to the input parameters in the target test template can be "<%=input%>", and the placeholders corresponding to the expected output parameters can be "<%=expected%>", and the input parameters in the multiple test parameters are "fib(5)" and the expected output parameters can be "5", then you can replace "<%=input%>" with "fib(5)" and "<%=expected%>" with "5" in the target test template.
[0263] 3. Based on each parameter pair in the test parameters, a corresponding description field can be generated, and the placeholders corresponding to the description fields in the target test template can be replaced with these multiple description fields. For example, based on (fib(5), 5), the readable description field "n=5 should return 5" can be automatically generated. The placeholders corresponding to the description fields in the target test template can be "<%=description%>", and "<%=description%>" in the target test template can be replaced with "n=5 should return 5".
[0264] 4. Replace the placeholders corresponding to the feature parameters in the target test template with the feature parameters from the multiple test parameters.
[0265] For example, if there are 3 test cases corresponding to the initial code, the information of these 3 test cases can be as follows:
[0266] Test case 1: The function name is "fib"; the description field can be "n=5 should return 5", the input parameter is fib(5), and the expected output parameter is "5".
[0267] Test Case 2: The function name is "fib"; the description field can be "n=0 should return 0", the input parameter is fib(0), and the expected output parameter is "0".
[0268] Test Case 3: The function name is "fib"; the description field can be "n=40 should not time out", the input parameter is fib(40), the expected output parameter is "102334155", and the timeout is set to 10 seconds (10000 milliseconds). If fib(40) returns an error value, it means the test has failed; if the calculation time of fib(40) exceeds 10 seconds, it also means the test has timed out.
[0269] For example, if test case 1 passes but test case 3 times out (e.g., due to unoptimized recursion causing test case 3 to take too long to execute), in this case, the test process data of test case 3 can be obtained, and error feedback information can be generated based on the test process data of test case 3, so as to correct the initial code through the error feedback information.
[0270] The code generation method provided in this application can parse and process the initial response information to obtain initial code and scenario description information. By splitting the initial code into multiple target code blocks in a standard format, it is beneficial to improve the efficiency of test case generation. Furthermore, by combining the scenario description information and / or multiple target code blocks, the method can accurately match the target test template corresponding to the initial code in multiple test templates. In addition, by combining the scenario description information and multiple target code blocks, it can more comprehensively determine multiple test parameters. This allows the test cases generated based on multiple test parameters and target test templates to have higher accuracy and more comprehensive test coverage, thereby making the test results obtained based on the test cases more accurate.
[0271] Figure 5 This is the third flowchart illustrating the code generation method provided in this application's embodiments. Please refer to... Figure 5 The method may specifically include the following steps:
[0272] S501. Initialize i to 1.
[0273] S502. Based on the (i-1)th test process data, determine the i-th response information corresponding to the request information, and based on the i-th response information, determine the i-th test case.
[0274] Where i takes the values 1, 2, ... in sequence.
[0275] The (i-1)th test process data is generated during the testing of the (i-1)th code in the (i-1)th response information. The (i-1)th test process data may include test execution logs and resource monitoring data obtained from testing the (i-1)th code based on the (i-1)th test case. The test execution logs can be used to record the execution results and detailed information of the (i-1)th test case; the resource monitoring data can be used to indicate the resource consumption of the runtime environment used to execute the (i-1)th test case.
[0276] When i is 1, the (i-1)th test process data is the initial test process data, the (i-1)th reply information is the initial reply information, and the (i-1)th code is the initial code.
[0277] This step can be performed by a computing device, for example, by a secure execution engine, feedback optimizer, code extraction module, and test generator within the computing device. Specifically:
[0278] The secure execution engine can be used to generate i-1 test process data and send the i-1 test process data to the feedback optimizer during the automated testing of i-1 code based on i-1 test cases.
[0279] The feedback optimizer can be used to determine the error feedback information corresponding to the (i-1)th code based on the (i-1)th test process data when the test result for the (i-1)th code is a test failure; and send the error feedback information corresponding to the (i-1)th code to the code extraction module.
[0280] The code extraction module can be used to update the (i-1)th reply information based on the error feedback information corresponding to the (i-1)th code to obtain the i-th reply information; parse the i-th reply information to obtain the i-th code and the i-th scene description information corresponding to the request information; split the i-th code into multiple target code blocks based on the syntax structure of the i-th code; and send the multiple target code blocks corresponding to the i-th code and the i-th scene description information to the test generator.
[0281] The test generator can be used to: determine the target test template corresponding to the i-th code from multiple test templates in the template library based on multiple target code blocks corresponding to the i-th code and / or the i-th scenario description information; determine multiple test parameters corresponding to the i-th code based on the i-th scenario description information and the multiple target code blocks corresponding to the i-th code; and determine the i-th test case based on the multiple test parameters corresponding to the i-th code and the target test template corresponding to the i-th code.
[0282] It should be noted that the process of determining the i-th response information corresponding to the request information based on the (i-1)-th test process data will be... Figure 6 Detailed explanation is provided in the embodiments.
[0283] S503. Test the i-th code in the i-th response information based on the i-th test case to obtain the i-th test result.
[0284] This step can be performed by a computing device, for example, by a secure execution engine and a feedback optimizer within the computing device.
[0285] It should be noted that the process of obtaining the i-th test result in this step can refer to the process of testing the initial code based on the test cases to obtain the test results in step S203, and will not be repeated here.
[0286] S504. Determine whether the result of the i-th test is a successful test.
[0287] The result of the i-th test can be either a pass or a fail.
[0288] If so, that is, if the result of the i-th test is that the test is passed, then proceed to step S505;
[0289] If not, that is, if the result of the i-th test is that the test fails, then proceed to step S506.
[0290] S505. The i-th reply information is determined as the target reply information.
[0291] It is understandable that the i-th code in the i-th reply message is the target code.
[0292] S506. Determine whether i is less than N.
[0293] If so, that is, i is less than N, then proceed to step S507;
[0294] If not, that is, i is greater than or equal to N, then proceed to step S509.
[0295] Users can pre-configure the maximum number of updates N in the electronic device (or feedback optimizer) according to business needs; for example, N is 5.
[0296] In practical applications, if there is a logical error in the request information, the test result may still fail even after updating the corresponding response information multiple times. In this case, in order to update the corresponding response information indefinitely, the user can set a maximum number of repetitions N (e.g., 5) to reduce resource waste.
[0297] S507. Determine whether the i-th difference value is less than the difference threshold.
[0298] If so, that is, if the i-th difference value is less than the difference threshold, then proceed to step S509;
[0299] If not, that is, if the i-th difference value is greater than or equal to the difference threshold, then proceed to step S508.
[0300] The i-th difference value can be the difference between the i-th code and the (i-1)-th code, where the i-th code is obtained by updating the (i-1)-th code.
[0301] This method can achieve convergence detection by comparing the i-th difference value with the difference threshold. The convergence detection means that if the difference value of the code in two consecutively generated response messages is less than the difference threshold, then the code generation process in the response message is determined to be "stable" and the update process of the response message is terminated.
[0302] In practical applications, if the difference between the code in the response information generated by the code extraction module for a certain request is less than the difference threshold, it can be determined that the code in the response information generated by the code extraction module for that request is accurate. In this case, if the test result is that the test fails twice in a row, it can be determined that there may be a logical error in the request information, and the update process of the response information can be terminated to reduce resource waste.
[0303] Optionally, users can pre-configure this difference threshold based on their own business needs.
[0304] Steps S504 to S507 can be executed by a computing device. For example, steps S504 to S507 can be executed by a feedback optimizer in the computing device.
[0305] S508, Update i to i+1.
[0306] After completing step S508, return to step S502.
[0307] S509. Request update request information from the terminal and obtain the target response information based on the update request information.
[0308] The update request information is obtained by updating the request information.
[0309] In some embodiments, the computing device (or code extraction module) may send an error message to the terminal, which may be used to instruct the terminal to re-enter the request information.
[0310] It is understood that the process of obtaining the target response information based on the update request information in this step can refer to the process of obtaining the target response information based on the request information in the above embodiment, and will not be repeated here.
[0311] The code generation method provided in this application can generate corresponding test cases based on the response information, so as to automatically test the code of the response information through the test cases. If the test fails, the (i-1)th response information can be automatically updated based on the (i-1)th test process data. This allows for closed-loop iterative control of the response information corresponding to the request information, thereby achieving automated correction of the response information (or code) corresponding to the request information. This makes the response information closer to the correct response information required by the request information, which is beneficial to improving the accuracy of the response information code. By setting a maximum number of updates N and a difference threshold, the method avoids endless updates to the response information corresponding to the request information in the event of logical errors in the request information, thus reducing resource waste.
[0312] Figure 6 This is the fourth flowchart illustrating the code generation method provided in this application's embodiments. Please refer to... Figure 6 The method may specifically include the following steps:
[0313] S601. Based on the i-1th test process data, determine at least one error type corresponding to the i-1th code, and the error detection data for each error type.
[0314] Error detection data can include error description information and correction instructions.
[0315] Optionally, the error detection data may also include error location information.
[0316] In some embodiments, after obtaining the (i-1)th test process data, the (i-1)th test process data can be standardized.
[0317] Optionally, the i-1th test process data can be filled into a preset data presentation template to obtain standardized i-1th test process data.
[0318] For example, the data presentation template may include, but is not limited to, the following:
[0319] (1) The specific content of the test case (testCase), such as "n=5 should return 5";
[0320] (2) The execution status of the test case, which may include, but is not limited to, one of the following: failed, passed, error, timeout;
[0321] (3) Error details, which may include, but are not limited to, the following:
[0322] A. Error message, for example, "Expected 5 but received 3", means that the expected output parameter was 5, but the actual output parameter was 3.
[0323] B. Error location information may include code snippet information and line number information.
[0324] Code snippet information can be used to locate the code snippet of the test case where the error occurred. For example, codeSnippet can be used to indicate that the code snippet where the error occurred is the code snippet corresponding to fib(5).
[0325] The line number information (lineNumber) indicates the line number of the problematic code; for example, the line number could be 10.
[0326] (4) Resource usage information can be used to indicate the resource consumption during the execution of test cases. For example, the resource usage information may include CPU utilization (e.g., 85%) and memory usage (e.g., 200MB).
[0327] Error types may include, but are not limited to, at least one of the following: syntax error, logical defect, performance problem, or missing boundary condition.
[0328] Correction instructions may include analysis rules and correction strategies for the error type. The analysis rules can be used to indicate at least one possible cause of the error of that type; the feedback strategy can be used to indicate how to correct the error of that type.
[0329] This step can be performed by a computing device, for example, by a feedback optimizer within the computing device.
[0330] The computing device (or feedback optimizer) may contain a mapping relationship between error types and correction indication information. This mapping relationship may include multiple error types and the corresponding correction indication information for each error type. For example, this mapping relationship may be shown in Table 3.
[0331] Table 3
[0332]
[0333] S602. Based on the error detection data of at least one error type corresponding to the (i-1)th code, generate error feedback information corresponding to the (i-1)th code based on the error feedback template.
[0334] An error feedback template may include multiple fields, as well as a corresponding fill area or placeholder for each field. These fields can be used to indicate the error type (errorType), error description information (errorContext), and correction instruction information (suggestedAction). The correction instruction information may include a correction strategy.
[0335] Optionally, these fields can also be used to indicate error location information, which may include code snippet information.
[0336] This step can be performed by a computing device, for example, by a feedback optimizer within the computing device.
[0337] The computing device (or feedback optimizer) can perform the following steps to generate error feedback information corresponding to each error type: For each error type, the error detection data of each error type can be filled into the error feedback template to generate the error feedback information corresponding to that error type.
[0338] The error feedback information corresponding to the i-th code can include error feedback information corresponding to each error type in at least one error type.
[0339] Figure 7 This is a schematic diagram illustrating error feedback information provided in an embodiment of this application. Please refer to [link / reference]. Figure 7 In error feedback information A, the error type is "performance problem", the error description is "execution timeout when n=40", and the correction instruction is "optimize the algorithm to iterate or cache intermediate results".
[0340] In error feedback information B, the error type is "logic defect", the error description is "function fib(n) returns 3 when n=5, the expected output parameter is 5", the correction instruction is "check the recursion termination condition and calculation logic", and the error location information includes the code snippet "return fib(n-1)+fib(n-2)".
[0341] It should be noted that in some embodiments, the terms "code snippet" and "code block" can be used interchangeably.
[0342] S603. Based on the error feedback information corresponding to the (i-1)th code, update the (i-1)th reply information to obtain the i-th reply information.
[0343] This step can be performed by a computing device, for example, by a feedback optimizer and a code extraction module in the computing device.
[0344] The feedback optimizer can send a transfer request to the code extraction module, which may include error feedback information corresponding to the (i-1)th code. For example, this transfer request may be a Hypertext Transfer Protocol (HTTP) request.
[0345] In one example, the feedback optimizer can send an HTTP request to the AI model's interface via the code extraction module. This HTTP request includes error feedback information corresponding to the (i-1)th code. This allows the AI model to update the (i-1)th response information based on the error feedback information corresponding to the (i-1)th code, thereby avoiding errors corresponding to the (i-1)th code during the generation of the (i-1)th response information and improving the accuracy of the (i-1)th response information.
[0346] In some embodiments, the AI model can update the i-1th code in the i-1th response information to obtain the i-th response information; or, the AI model can update both the i-1th code and the i-1th scene description information in the i-1th response information to regenerate the i-th response information.
[0347] The feedback optimizer can convert the test result of the i-1th code in the i-1th response information into an operable update instruction and send the update instruction to the code extraction module. The code extraction module can then use the update instruction to call the AI model to update the i-1th response information (or the i-1th code within it), so that the response information generated by the AI model gradually approaches the correct response information desired by the request information.
[0348] For example, if the (i-1)th code generated by the AI model calculates the Fibonacci sequence using recursive calls, the recursive call method will repeatedly calculate the values of some parameters during the calculation process, resulting in a long test time and causing a timeout when n=40. In this case, the AI model can update the (i-1)th code to the ith code, which calculates the Fibonacci sequence using an iterative loop. This can avoid repeated calculations, reduce test time, and prevent the timeout when n=40.
[0349] The code generation method provided in this application embodiment can generate standardized error feedback information corresponding to the (i-1)th code based on the (i-1)th test process data. The (i-1)th response information can be updated using the standardized error feedback information corresponding to the (i-1)th code, thereby enabling closed-loop iterative control of the response information corresponding to the request information. This achieves automated correction and updating of the response information (or code) corresponding to the request information, making the response information closer to the correct response information required by the request information. This ensures that the AI question-answering system accurately generates the code corresponding to the request information.
[0350] In some embodiments, the AI question-answering system, code generation method, and computing device provided in this application can also realize intelligent code diagnosis and repair functions. For example, based on the automated testing of the code for the reply information, the computing device (AI question-answering system) adds an intelligent error diagnosis function to the code, which not only points out the errors in the code, but also provides suggestions for code repair, and even automatically repairs common errors in the code.
[0351] In some embodiments, the computing device provided in this application can also realize real-time monitoring and early warning functions for the AI question-answering system. For example, the computing device can detect the accuracy rate of the AI question-answering system in real time, and immediately issue an early warning and initiate a repair process when it is determined that the accuracy rate of the AI question-answering system has decreased or other abnormal problems have occurred in the AI question-answering system.
[0352] Figure 8 This is a schematic diagram of a code generation apparatus provided in an embodiment of this application. Please refer to... Figure 8 The code generation apparatus may include:
[0353] The transceiver module 11 is used to obtain request information sent by the terminal, and the request information is used to request code generation.
[0354] Processing module 12 is used to generate initial response information corresponding to the request information, and the initial response information includes the initial code corresponding to the request information;
[0355] The processing module 12 is also used to determine test cases based on the initial response information, and to test the initial code based on the test cases to obtain test results;
[0356] The processing module 12 is also used to determine the target response information corresponding to the request information based on the test results and the initial response information. The target response information includes the target code, which is determined based on the initial code.
[0357] The transceiver module is also used to send target response information to the terminal.
[0358] The code generation apparatus provided in this application embodiment can execute the technical solutions shown in the above method embodiments, and its beneficial effects are similar, so they will not be described again here. Figure 1B The code extraction module in the embodiment can be used to execute the content executed by the transceiver module 11, and the feedback optimizer can also be used to execute the "send target reply information to the terminal" executed by the transceiver module 11; Figure 1B In the embodiment, the code extraction module, test generator, secure execution engine, and feedback optimizer can work together to execute the content executed by the processing module 12.
[0359] In one possible implementation, the processing module 12 is specifically used for:
[0360] The initial response information is parsed and processed to obtain the initial code and scenario description information corresponding to the request information;
[0361] Based on the syntax structure of the initial code, the initial code is split into multiple target code blocks;
[0362] Based on multiple target code blocks and / or scenario description information, determine the target test template corresponding to the initial code from multiple test templates in the template library;
[0363] Based on the scenario description information and multiple target code blocks, determine multiple test parameters corresponding to the initial code;
[0364] Based on multiple test parameters and the target test template, test cases are determined.
[0365] In one possible implementation, the processing module 12 is further used for:
[0366] Generate an abstract syntax tree (AST) corresponding to the initial code, and perform syntax verification on the AST. The AST is used to represent the syntactic structure of the initial code.
[0367] If the syntax verification of the AST passes, the multiple target element types corresponding to the AST and the reference code blocks corresponding to each target element type are determined based on the code structure library. The code structure library includes multiple element types and the reference code blocks corresponding to each element type. The multiple element types include multiple target element types.
[0368] The AST is split into multiple target code blocks based on the reference code blocks corresponding to multiple target element types.
[0369] In one possible implementation, the template library includes template information for multiple test templates, the template information including code type and template identifier; the processing module 12 is further used for:
[0370] Based on multiple target code blocks and / or scenario description information, determine the template indication information corresponding to the initial code. The template indication information includes the target code type and / or target template identifier.
[0371] Based on the template information and template instruction information of multiple test templates, the target test template is determined from among the multiple test templates.
[0372] In one possible implementation, the processing module 12 is further used for:
[0373] Based on the scenario description information and multiple target code blocks, determine the test conditions for the initial code;
[0374] Based on the test conditions and multiple parameter generation rules, multiple test parameters are determined. The multiple parameter generation rules include at least one of the following: boundary value generation rules, outlier generation rules, and parameter type diversity input rules.
[0375] In one possible implementation, the processing module 12 is further used for:
[0376] If the test result is that the test passes, the initial response information will be determined as the target response information, and the target code in the target response information will be the initial code.
[0377] If the test result is that the test fails, the initial response information is updated based on the initial test process data to obtain the target response information. The initial test process data is generated during the testing of the initial code, and the target code in the target response information is obtained by updating the initial code.
[0378] In one possible implementation, the processing module 12 is further used for:
[0379] Based on the (i-1)th test process data, determine the i-th response information corresponding to the request information, and based on the i-th response information, determine the i-th test case. The (i-1)th test process data is generated during the testing of the i-1th code in the (i-1)th response information.
[0380] Based on the i-th test case, the i-th code in the i-th reply message is tested to obtain the i-th test result;
[0381] Where i takes the values 1, 2, ..., until the target response information is obtained based on the i-th test result. When i is 1, the i-1 test process data is the initial test process data, the i-1 response information is the initial response information, and the i-1 code is the initial code.
[0382] In one possible implementation, the processing module 12 is further used for:
[0383] If the i-th test result is a pass, the i-th response information is determined as the target response information;
[0384] If the i-th test result is a failure, and if i is less than N and the i-th difference value is greater than or equal to the difference threshold, then based on the i-th test process data, determine the (i+1)-th response information corresponding to the request information, and obtain the target response information based on the (i+1)-th response information. The i-th test process data is generated during the testing of the i-th code. If i is greater than or equal to N, or the i-th difference value is less than the difference threshold, request the terminal to obtain update request information, and obtain the target response information based on the update request information. The update request information is obtained by updating the request information.
[0385] Where N is an integer greater than 1, the i-th difference value is the difference between the i-th code and the (i-1)-th code, and the i-th code is obtained by updating the (i-1)-th code.
[0386] In one possible implementation, the processing module 12 is further used for:
[0387] Based on the i-1 test process data, determine at least one error type corresponding to the i-1 code, as well as error detection data for each error type. The error detection data includes error description information and correction instruction information.
[0388] Based on the error detection data of at least one error type corresponding to the (i-1)th code, generate error feedback information corresponding to the (i-1)th code based on the error feedback template;
[0389] Based on the error feedback information corresponding to the (i-1)th code, the (i-1)th reply information is updated to obtain the i-th reply information.
[0390] Figure 9 This is a schematic diagram of the hardware structure of a computing device provided in an embodiment of this application. Please refer to [link / reference]. Figure 9 The computing device 20 can be the computing device in the above method embodiments. The computing device 20 may include a processor 21 and a memory 22, which are coupled together. The processor 21 and the memory 22 can communicate; for example, the processor 21 and the memory 22 communicate via a communication bus 23.
[0391] Memory 22 is used to store program instructions;
[0392] The processor 21 is used to execute program instructions to perform the technical solution as shown in the above method embodiments.
[0393] Optionally, the computing device 20 may also include a communication interface, which may include a transmitter and / or a receiver.
[0394] Optionally, the aforementioned processor can be a CPU, or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0395] This application provides a computer-readable storage medium storing computer-executable instructions; when executed by a processor, the computer-executable instructions are used to implement the code generation method shown in the above embodiments.
[0396] This application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it causes the computer to perform the code generation method shown in the above embodiments.
[0397] All or part of the steps in the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a readable memory. When the program is executed, it performs the steps of the above-described method embodiments; and the aforementioned memory (storage medium) includes: read-only memory (ROM), RAM, flash memory, hard disk, solid-state drive, magnetic tape, floppy disk, optical disk, and any combination thereof.
[0398] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable device to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable device, create means for implementing the functions specified in one or more flowchart illustrations and / or one or more block diagrams.
[0399] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.
[0400] These computer program instructions may also be loaded onto a computer or other programmable device to cause a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable device, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.
[0401] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of this application, and are not intended to limit them. Although the embodiments of this application have been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.< / condition> < / params> < / name>
Claims
1. A code generation method, characterized in that, The method includes: Obtain request information sent by the terminal, the request information being used to request code generation; Generate initial response information corresponding to the request information, wherein the initial response information includes initial code corresponding to the request information; Based on the initial response information, test cases are determined, and the initial code is tested based on the test cases to obtain test results; Based on the test results and the initial response information, the target response information corresponding to the request information is determined. The target response information includes a target code, which is determined based on the initial code. Send the target response information to the terminal; Based on the test results and the initial response information, the target response information corresponding to the request information is determined, including: If the test result is that the test fails, the i-th response information corresponding to the request information is determined based on the i-1 test process data, and the i-th test case is determined based on the i-th response information. The i-1 test process data is generated during the testing of the i-1 code in the i-1 response information. If the i-th test result is a pass, the i-th response information is determined as the target response information; If the i-th test result is a failed test, and if i is less than N and the i-th difference value is greater than or equal to the difference threshold, then based on the i-th test process data, the (i+1)-th response information corresponding to the request information is determined, and the target response information is obtained based on the (i+1)-th response information. The i-th test process data is generated during the testing of the i-th code. If i is greater than or equal to N, or the i-th difference value is less than the difference threshold, an update request information is requested from the terminal, and the target response information is obtained based on the update request information. The update request information is obtained by updating the request information. Wherein, i takes the values 1, 2, ..., until the target response information is obtained based on the i-th test result. When i is 1, the (i-1)-th test process data is the initial test process data, the (i-1)-th response information is the initial response information, and the (i-1)-th code is the initial code. N is an integer greater than 1, the i-th difference value is the difference between the i-th code and the (i-1)-th code, and the i-th code is obtained by updating the (i-1)-th code.
2. The method according to claim 1, characterized in that, Based on the initial response information, test cases are determined, including: The initial response information is parsed to obtain the initial code and scene description information corresponding to the request information; Based on the syntax structure of the initial code, the initial code is split into multiple target code blocks; Based on the multiple target code blocks and / or the scenario description information, determine the target test template corresponding to the initial code from multiple test templates in the template library; Based on the scenario description information and the multiple target code blocks, determine multiple test parameters corresponding to the initial code; The test cases are determined based on the multiple test parameters and the target test template.
3. The method according to claim 2, characterized in that, Based on the syntax structure of the initial code, the initial code is split into multiple target code blocks, including: Generate an abstract syntax tree (AST) corresponding to the initial code, and perform syntax verification on the AST, wherein the AST is used to characterize the syntactic structure of the initial code; If the syntax verification of the AST passes, multiple target element types corresponding to the AST and reference code blocks corresponding to each target element type are determined based on the code structure library. The code structure library includes multiple element types and reference code blocks corresponding to each element type. The multiple element types include the multiple target element types. The AST is split into the multiple target code blocks based on the reference code blocks corresponding to the multiple target element types.
4. The method according to claim 2 or 3, characterized in that, The template library includes template information for the plurality of test templates, the template information including code type and template identifier; based on the plurality of target code blocks and / or the scenario description information, determining the target test template corresponding to the initial code from the plurality of test templates in the template library includes: Based on the plurality of target code blocks and / or the scene description information, determine the template indication information corresponding to the initial code, wherein the template indication information includes the target code type and / or the target template identifier; Based on the template information and template indication information of the plurality of test templates, the target test template is determined from the plurality of test templates.
5. The method according to any one of claims 2-4, characterized in that, Based on the scenario description information and the multiple target code blocks, determine multiple test parameters corresponding to the initial code, including: Based on the scenario description information and the multiple target code blocks, determine the test conditions for the initial code; Based on the test conditions and multiple parameter generation rules, the multiple test parameters are determined. The multiple parameter generation rules include at least one of the following: boundary value generation rules, outlier generation rules, and parameter type diversity input rules.
6. The method according to any one of claims 1-5, characterized in that, Determining the target response information corresponding to the request information based on the test results and the initial response information further includes: If the test result is a pass, the initial response information is determined as the target response information, and the target code in the target response information is the initial code.
7. The method according to claim 1, characterized in that, Based on the data from the (i-1)th test process, determine the i-th response information corresponding to the request information, including: Based on the i-1th test process data, at least one error type corresponding to the i-1th code is determined, as well as error detection data for each error type. The error detection data includes error description information and correction instruction information. Based on the error detection data of at least one error type corresponding to the (i-1)th code, generate error feedback information corresponding to the (i-1)th code based on the error feedback template; Based on the error feedback information corresponding to the (i-1)th code, the (i-1)th reply information is updated to obtain the i-th reply information.
8. A computing device, characterized in that, include: Processor and memory; The processor and the memory are coupled; The memory is used to store program instructions; The processor is used to execute the program instructions to implement the method as described in any one of claims 1 to 7.