AI code generation optimization method and system

By obtaining microservice path prefixes and API group list data, combined with noise reduction hash algorithms and code feature dictionaries, method names are automatically generated and AI code configuration details are generated. This solves the problems of low code generation efficiency and poor accuracy in existing technologies, and achieves efficient and accurate code generation and quality assurance.

CN120508296BActive Publication Date: 2025-09-16JIANGSU LINGHAO NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510984871.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-17
Publication Date
2025-09-16
Estimated Expiration
2045-07-17

AI Technical Summary

Technical Problem

Existing code generation methods lack flexibility and are difficult to customize according to the specific needs of users. Especially when processing API calls, traditional methods rely on manual writing, which is inefficient and error-prone. It is difficult to generate corresponding code quickly and accurately, and the consistency and standardization of the code are difficult to guarantee.

Method used

By obtaining microservice path prefixes and API group list data, combined with code feature verbiage and noise reduction hash comparison, the system identifies artificial code and automatically generates method names based on the user's selected API group. It then obtains interface details, generates a code snippet mapping table and abstract syntax tree, performs node replacement, and generates AI code configuration details. Finally, it adds annotations, parameter validation, business logic, and return result processing code to complete the AI ​​code, and adds exception handling logic.

Benefits of technology

It improves the efficiency and quality of code generation, reduces the workload of manual code writing, ensures that the generated code meets business requirements and code specifications, improves the accuracy and consistency of code generation, reduces the probability of errors, and enhances the robustness and stability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120508296B_ABST
    Figure CN120508296B_ABST
Patent Text Reader

Abstract

The present invention discloses an AI code generation optimization method and system, which belongs to the field of software development technology, and specifically includes: obtaining microservice path prefix and API group list data, combining code feature words to determine artificial code through noise reduction hash comparison, and automatically generating method names according to user selection and comments; obtaining interface details for the API group corresponding to each method name, generating API access path, sorting interface details to generate a code snippet mapping table, and automatically analyzing interface performance in combination with embedded point data; generating an abstract syntax tree according to the mapping table, traversing and replacing qualified nodes, and generating AI code configuration details; adding annotations to the method according to the configuration details to generate API code, adding parameter verification, business logic and return result processing code, and integrating them to form a complete AI code; adding exception handling logic to the complete AI code and writing it to a file; improving code generation efficiency and quality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of software development technology, and specifically relates to an AI code generation optimization method and system. Background Art

[0002] In the software development process, code generation is an important means to improve development efficiency. However, existing code generation methods often lack flexibility and are difficult to customize according to the specific needs of users. Especially when processing API calls, traditional API code writing relies on manual writing, which is inefficient and prone to errors. When it comes to a large number of API group selections and code generation, the disadvantages of manual operation are more obvious. For example, it is difficult to quickly and accurately generate corresponding code according to different needs, and the consistency and standardization of the code are difficult to guarantee. It is also impossible to effectively group and manage APIs, and it is difficult to generate high-quality code that conforms to specific business logic. Therefore, there is a need for a method and system that can perform batch selection based on API groups input by the user and optimize code generation in combination with AI technology. Summary of the Invention

[0003] In response to the shortcomings of the existing technology, the present invention proposes an AI code generation optimization method and system, which obtains microservice path prefix and API group list data, determines the artificial code through noise reduction hash comparison based on code feature words, and automatically generates method names based on user selection and comments; obtains interface details for the API group corresponding to each method name, generates API access path, organizes interface details to generate a code snippet mapping table, and automatically analyzes interface performance based on embedded data; generates an abstract syntax tree based on the mapping table, traverses and replaces qualified nodes, and generates AI code configuration details; adds annotations to the method based on the configuration details to generate API code, adds parameter verification, business logic and return result processing code, and integrates them to form a complete AI code; adds exception handling logic to the complete AI code and writes it to a file; improves code generation efficiency and quality.

[0004] To achieve the above object, the present invention provides the following technical solutions:

[0005] AI code generation optimization methods include:

[0006] Step S1: Obtain the microservice path prefix and the corresponding API group list data, combine the code feature words, determine the artificial code through noise reduction hash comparison, and automatically generate the method name based on the user-selected API group and the annotation;

[0007] Step S2: For each API group corresponding to the generated method name, obtain interface details, combine them with the microservice path prefix, generate the API access path, organize the obtained interface details, generate a code snippet mapping table, and automatically analyze the interface performance in combination with the embedded data;

[0008] Step S3: Generate an abstract syntax tree based on the code snippet mapping table, and traverse the generated abstract syntax tree to check and analyze each node and branch in the code structure. At the same time, during the traversal process, replace the nodes that meet the conditions, and generate AI code configuration details based on the replaced abstract syntax tree;

[0009] Step S4: Add annotations to the generated method names based on the AI ​​code configuration details, generate API code, add parameter validation logic to the generated API code, generate corresponding business logic code, and process the interface return value to generate the corresponding return result processing code, thus forming a complete AI code through integration;

[0010] Step S5: adding exception handling logic to the generated complete AI code, and writing the complete AI code with the added exception handling logic into a file.

[0011] Specifically, the specific steps of step S1 include:

[0012] S1.1: Obtain the microservice path prefix through user input or system configuration, and use the obtained microservice path prefix to obtain the corresponding API group list data from the configuration file;

[0013] S1.2: Initialize a traversal pointer, starting from the starting position of the API group list data, and check whether all microservice path prefixes and corresponding API group list data have been traversed;

[0014] If the traversal is completed, the configuration file content selected by the user is read;

[0015] If the traversal is not complete, the API path and interface type are obtained from the current traversal position, and a list of generated method names is maintained to determine whether the method name corresponding to the API path and interface type has been generated;

[0016] If the method name is not generated, the existing code is compared using a denoising hash to distinguish between plugin-generated code and manually written code. If the code is not generated by the plugin, the method name is automatically generated based on the user-selected API group and the annotation information in the API group. The generated method name is added to the list of generated method names and the traversal pointer is moved back one position.

[0017] If the method name has been generated, the corresponding method name is returned directly from the list of generated method names, and the traversal pointer is moved back one position.

[0018] Specifically, the specific steps of step S2 include:

[0019] S2.1: Obtain all generated method names from step S1, and match each obtained generated method name with the specified ID using string comparison;

[0020] If the match is successful, go to S2.3;

[0021] If the match is unsuccessful, the annotation corresponding to the method name is searched, and zero-width characters are extracted from the annotation. The extracted zero-width characters are mapped and converted into encoding information.

[0022] S2.2: Match the mapped zero-width character with the specified ID again;

[0023] If the match is successful, go to S2.3;

[0024] If the match is unsuccessful, the traversal pointer is returned to the initial position and the matching judgment of the generated method name is restarted.

[0025] Specifically, the specific steps of step S2 also include:

[0026] S2.3: Generate an API access path based on the API group corresponding to the successfully matched method name and the microservice path prefix obtained in step S1. Use the generated API access path to send a request to the corresponding interface to obtain interface details; the interface details include interface parameters and return value information;

[0027] S2.4: Check whether the operation of requesting interface details is successful by checking the response status code;

[0028] If the request is successful, save the interface details;

[0029] If the request is unsuccessful, the error interface details will be thrown;

[0030] S2.5: Organize the obtained interface details and generate a code snippet mapping table. At the same time, automatically analyze the interface performance in combination with the embedded data; the code snippet mapping table records the correspondence between interface parameters, return values ​​and code snippets; the interface performance includes the response time and call frequency of the interface.

[0031] Specifically, the specific steps of step S3 include:

[0032] S3.1: After traversing all microservice path prefixes and corresponding API group list data, read the selected file content;

[0033] S3.2: Use the code parsing tool to generate an abstract syntax tree based on the read file content, and use the traversal pointer to traverse the abstract syntax tree;

[0034] S3.3: Check whether all nodes of the abstract syntax tree have been traversed;

[0035] If all nodes of the abstract syntax tree have not been traversed, the function declaration node and identifier judgment and diff comparison are performed, and the abstract syntax tree node is replaced based on the judgment and comparison results;

[0036] If all nodes of the abstract syntax tree are traversed, check whether there is a node representing an import statement in the abstract syntax tree;

[0037] If there is an import statement, generate the corresponding import statement code and continue to traverse the remaining code mapping table. During the traversal process, replace the nodes that meet the replacement conditions;

[0038] If there is no import statement, directly traverse the remaining code mapping table and replace the nodes that meet the replacement conditions;

[0039] S3.4: Generate AI code configuration details based on the replaced abstract syntax tree.

[0040] Specifically, the specific process of determining the function declaration node and identifier and performing diff comparison in S3.3 includes:

[0041] S3.31: If all nodes of the abstract syntax tree have not been traversed, check whether the currently traversed node is a function declaration node;

[0042] If the node is not a function declaration node, return to S3.2 and continue traversing the next node;

[0043] If the node is a function declaration node, determine whether the node is an identifier;

[0044] If the node does not belong to the identifier, return to S3.2 and continue traversing the next node;

[0045] If the node belongs to an identifier, save the name of the identifier and determine whether the saved name of the identifier exists in the map of the code fragment;

[0046] If it does not exist in the mapping of the code snippet, return to S3.2 and continue traversing the next node;

[0047] If it exists in the code snippet's map, remove the annotation corresponding to the method name;

[0048] S3.32: Determine whether a diff comparison of the abstract syntax tree is required;

[0049] If a comparison is required, use abstract syntax tree difference analysis to compare the current abstract syntax tree with the previous version;

[0050] If no comparison is required, the latest abstract syntax tree is generated based on the existing code details;

[0051] S3.33: Based on the judgment and analysis results, replace the nodes in the traversal process and update the structure of the abstract syntax tree;

[0052] S3.34: Based on the syntax tree comparison results and the traversal node replacement results, delete the mapping items that are no longer needed or have been updated in the corresponding code mapping table.

[0053] Specifically, the specific steps of step S4 include:

[0054] S4.1: Extract configuration information from the generated AI code configuration details; the configuration information includes code style, naming conventions, and annotation rules;

[0055] S4.2: Add annotations to the generated method names according to the annotation rules in the AI ​​code configuration details; the annotations include the method name's function description, parameter description, return value description, and permission requirements;

[0056] S4.3: Generate annotated API code based on the annotated method name, microservice path prefix, and API access path, and define the API interface in combination with the programming language and framework;

[0057] S4.4: Analyze the parameter information of the API interface, add parameter verification logic to the annotated API code based on business requirements and data types, use the built-in verification mechanism to perform parameter verification, and generate the corresponding business logic code;

[0058] S4.5: Process the return result of the business logic code and generate the corresponding return result processing code based on the return value information in the interface details;

[0059] S4.6: Integrate the annotated API code, business logic code, and return result processing code to form a complete AI code, and check and correct the formed complete AI code.

[0060] Specifically, the specific steps of step S5 include:

[0061] S5.1: Based on the complete AI code, determine the exception type and capture range; the exception types include network request exceptions, database operation exceptions, parameter parsing exceptions, and business logic calculation exceptions;

[0062] S5.2: Use the exception catching syntax try-except-finally to add exception catching code and write processing logic code for different exception types. The processing logic includes recording exception logs, returning error information to the caller, and performing error recovery operations.

[0063] S5.3: Set exception throwing rules and write exception throwing code according to the exception throwing rules;

[0064] The exception throwing rule is that if there is an exception that cannot be handled by the current code block, the exception will be passed to the upper call chain;

[0065] S5.4: Integrate the added exception catching code, processing logic code, and exception throwing code with the complete AI code, and use the built-in open function to write them line by line to the specified file;

[0066] S5.5: After the code is written, check whether the file is generated successfully. If the writing fails, record the error information.

[0067] AI code generation and optimization system, including: method name generation module, interface detail processing module, configuration generation module, code generation and integration module, and exception handling module;

[0068] The method name generation module is used to obtain the microservice path prefix and API group list data required for system operation, and generate a method name based on the user's selection and API group annotation;

[0069] The interface details processing module is used to obtain interface details information for the API group corresponding to the generated method name, generate the API access path in combination with the microservice path prefix, and generate a code snippet mapping table by arranging the interface details;

[0070] The configuration generation module is used to generate an abstract syntax tree based on the code fragment mapping table, traverse, check and analyze the abstract syntax tree, replace nodes that meet the conditions, and generate AI code configuration details based on the replaced abstract syntax tree;

[0071] The code generation and integration module is used to annotate the generated method names based on the AI ​​code configuration details, generate API code, and add parameter verification logic, business logic code, and return result processing code to finally integrate and form a complete AI code;

[0072] The exception handling module is used to add exception handling logic to the generated complete AI code, and write the complete AI code with the added exception handling logic into a file to complete the generation and storage of the AI ​​code.

[0073] An electronic device includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of an AI code generation optimization method when executing the computer program.

[0074] Compared with the prior art, the present invention has the following beneficial effects:

[0075] 1. The present invention proposes an AI code generation optimization system and optimizes and improves the architecture, operation steps and processes. The system has the advantages of simple process, low investment and operation costs, and low production work costs.

[0076] 2. The present invention proposes an AI code generation optimization method. In terms of code generation efficiency and accuracy, by obtaining the microservice path prefix and API group list data, combining noise reduction hashing to determine the manual code and automatically generate method names, the workload of manual code writing is reduced and repetitive work is avoided; based on the interface details, a code fragment mapping table and an abstract syntax tree are generated and node replacement is performed, etc., which can ensure that the generated code meets business requirements and code specifications, improve the accuracy and consistency of code generation, and reduce the probability of errors.

[0077] 3. The present invention proposes an AI code generation optimization method. In terms of code quality and performance optimization, it combines embedded data to analyze interface performance, performs anti-shake and throttling processing on the interface, and improves code operation efficiency from the source; adds complete logic such as parameter verification, business logic, return result processing, and exception handling, which enhances the robustness and stability of the code, enabling it to cope with complex and changing business scenarios and operating environments; in addition, generates AI code configuration details to unify code style and naming specifications, facilitates subsequent maintenance and collaborative development of the code, and improves the overall quality and maintainability of the code. BRIEF DESCRIPTION OF THE DRAWINGS

[0078] Figure 1 This is a schematic diagram of the AI ​​code generation optimization method of the present invention;

[0079] Figure 2 Implement a flowchart for AI code configuration details;

[0080] Figure 3 Form a flow chart for the complete AI code;

[0081] Figure 4 Implement a flowchart for AI code exception handling and writing process;

[0082] Figure 5This is a diagram of the AI ​​code generation optimization system architecture of the present invention. DETAILED DESCRIPTION

[0083] Example 1

[0084] See also Figure 1 , an embodiment provided by the present invention: an AI code generation optimization method, comprising the following steps:

[0085] Step S1: Obtain the microservice path prefix and the corresponding API group list data, combine the code feature words, determine the artificial code through noise reduction hash comparison, and automatically generate the method name based on the user-selected API group and the annotation;

[0086] Among them, the user can select at least one API group for batch processing.

[0087] Step S2: For each API group corresponding to the generated method name, obtain interface details, combine them with the microservice path prefix, generate the API access path, organize the obtained interface details, generate a code snippet mapping table, and automatically analyze the interface performance in combination with the embedded data;

[0088] Step S3: Generate an abstract syntax tree based on the code snippet mapping table, and traverse the generated abstract syntax tree to check and analyze each node and branch in the code structure. At the same time, during the traversal process, replace the nodes that meet the conditions, and generate AI code configuration details based on the replaced abstract syntax tree;

[0089] Step S4: Add annotations to the generated method names based on the AI ​​code configuration details, generate API code, add parameter validation logic to the generated API code, generate corresponding business logic code, and process the interface return value to generate the corresponding return result processing code, thus forming a complete AI code through integration;

[0090] Step S5: adding exception handling logic to the generated complete AI code, and writing the complete AI code with the added exception handling logic into a file.

[0091] The specific steps of step S1 include:

[0092] S1.1: Obtain the microservice path prefix through user input or system configuration, and use the obtained microservice path prefix to obtain the corresponding API group list data from the configuration file;

[0093] S1.2: Initialize a traversal pointer, starting from the starting position of the API group list data, and check whether all microservice path prefixes and corresponding API group list data have been traversed;

[0094] If the traversal is completed, the configuration file content selected by the user is read;

[0095] If the traversal is not complete, the API path and interface type are obtained from the current traversal position, and a list of generated method names is maintained to determine whether the method name corresponding to the API path and interface type has been generated;

[0096] The specific process of determining whether the corresponding method name has been generated includes:

[0097] (1) Extract the API path and interface type information from the API group item pointed to by the current traversal pointer;

[0098] (2) At the beginning of the program, initialize an empty list or dictionary to store the generated method names; the key of the list or dictionary is a unique identifier composed of the API path and interface type, and the value is the corresponding method name;

[0099] (3) Generate a unique identifier based on the currently obtained API path and interface type, for example, by connecting the API path and interface type with a separator;

[0100] (4) Check if this unique identifier exists in the list or dictionary of generated method names;

[0101] If it exists, it means that the method name corresponding to the API path and interface type has been generated, and the corresponding method name can be directly obtained from the list or dictionary;

[0102] If it does not exist, it means that the method name corresponding to the API path and interface type has not been generated yet, and subsequent method name generation operations are required.

[0103] If the method name is not generated, the existing code is compared using a denoising hash to distinguish between plugin-generated code and manually written code. If the code is not generated by the plugin, the method name is automatically generated based on the user-selected API group and the annotation information in the API group. The generated method name is added to the list of generated method names and the traversal pointer is moved back one position.

[0104] Furthermore, we use noise reduction hashing to compare existing code and distinguish between plugin-generated code and manually written code. If the code is not plugin-generated, we automatically generate method names based on the user-selected API grouping and the annotation information in the API grouping, including:

[0105] (1) Collect existing code files in the project from the local file system;

[0106] (2) Parse the collected existing code and extract code features, where the features include the code's grammatical structure, function call pattern, variable naming rules, and comment style. For example, use a code parsing library, such as Python's ast module, to extract function definitions and variable declaration information from the code;

[0107] (3) Use the denoising hash algorithm to process the extracted code features and calculate the denoising hash value of the code. The denoising hash algorithm in the present invention adopts the SimHash algorithm, whose core idea is to convert the code features into a binary vector of fixed length. The specific steps are as follows:

[0108] Segment the code features to obtain feature words;

[0109] Calculate a hash value for each feature word and convert it into a binary vector;

[0110] Assign a weight to each feature word according to its importance;

[0111] Multiply the binary vector of each feature word by its weight, and then add all the vectors together;

[0112] The added vectors are binarized to obtain a final SimHash value. The binarization process is a prior art in this field and is not an inventive solution of the present application, so it will not be described in detail here.

[0113] (4) Collect known plug-in generated codes in advance, calculate their denoised hash values, and build a plug-in generated code hash library;

[0114] (5) Using a similarity measurement method, the calculated denoised hash value of the existing code is compared with the hash value in the plug-in generated code hash library. In the present invention, the similarity measurement method adopts the Hamming distance formula. The Hamming distance is the existing technical content in this field and is not the inventive solution of this application, so it will not be described in detail here;

[0115] If the hash value of the existing code is similar to the hash value in the plugin-generated code hash library to a value that exceeds a preset error threshold, the code is considered to be generated by the plugin; otherwise, it is considered to be manually written code;

[0116] If the code is manually written, the method name is automatically generated based on the API group selected by the user and the annotation information in the API group, using natural language processing technology and predefined naming rules, including:

[0117] 1) Parse the annotation information in the API group and extract key business terms and operation descriptions;

[0118] 2) Combine the extracted key information into a method name according to predefined naming rules, such as underscore naming;

[0119] 3) Check the legality of the generated method name to ensure that it complies with the naming conventions of the programming language.

[0120] If the method name has been generated, the corresponding method name is returned directly from the list of generated method names, and the traversal pointer is moved back one position.

[0121] Example 2

[0122] See also Figure 2 In this embodiment, the specific steps of step S2 include:

[0123] S2.1: Obtain all generated method names from step S1, and match each obtained generated method name with the specified ID using a string comparison method. The string comparison uses an exact match, which is known in the art and does not constitute an inventive solution of the present application, and is not further described here.

[0124] If the match is successful, go to S2.3;

[0125] If the match is unsuccessful, the annotation corresponding to the method name is searched, and zero-width characters are extracted from the annotation. The extracted zero-width characters are mapped and converted into encoding information.

[0126] It should be noted that the purpose of matching each generated method name obtained with the specified ID is to accurately find the method name related to specific needs, because step S1 generates multiple method names, and subsequent operations only need to further process the method name corresponding to the specific ID. For example, methods with specific functions need to be screened for targeted code generation, logical processing or other operations. By matching with the specified ID, the required method can be accurately located from the many generated method names, thereby ensuring that subsequent steps can process specific methods as expected, ensuring the accuracy and pertinence of the entire code generation process, avoiding unnecessary operations on irrelevant methods, and improving the efficiency and quality of code generation.

[0127] Furthermore, the annotation corresponding to the method name is searched, and zero-width characters are extracted from the annotation. The extracted zero-width characters are mapped and converted into encoding information, including:

[0128] (1) If the method name fails to match the specified ID, you need to first use the traversal pointer to determine the specific location of the method name in the code, traverse the code file, and find the comment content near the method definition line;

[0129] (2) After finding the annotation corresponding to the method name, use regular expressions to extract zero-width characters from the annotation, where zero-width characters are characters that are invisible in the text but have specific meanings, such as zero-width spaces and zero-width hyphens. Regular expressions are prior art in this field and are not the inventive solution of this application, so they will not be described in detail here;

[0130] (3) Establish a mapping table between zero-width characters and encoding information, and replace the zero-width characters with the corresponding encoding information according to the mapping table, including:

[0131] 1) Determine the zero-width character set based on the application scenario;

[0132] 2) Design corresponding encoding information for each zero-width character, where the encoding information can be numbers or letters. Its purpose is to convert the zero-width character into a form that is easy to recognize and process. For example, the zero-width space is assigned code 001 and the zero-width hyphen is assigned code 002;

[0133] 3) Use a dictionary to establish a mapping relationship between zero-width characters and encoding information. The key of the mapping table is the zero-width character and the value is the corresponding encoding information.

[0134] 4) Traverse the extracted zero-width character list, find the corresponding encoding information in the mapping table, and replace it with the original text.

[0135] It should be emphasized that, because when the direct match between the method name and the specified ID is unsuccessful, there will be some hidden associated information stored in the annotation. Due to its invisible nature, zero-width characters can hide some additional identification information without affecting the normal reading of the annotation. Therefore, by extracting and mapping these zero-width characters, the hidden information can be converted into recognizable encoding information, thereby providing a second chance to match the method name with the specified ID. This method can increase the flexibility and accuracy of the match, avoid missing the real matching method due to the superficial difference in the method name, and improve the reliability of the entire code processing flow.

[0136] S2.2: Match the mapped zero-width character with the specified ID again;

[0137] If the match is successful, go to S2.3;

[0138] If the match is unsuccessful, the traversal pointer is returned to the initial position and the matching judgment of the generated method name is restarted;

[0139] S2.3: Generate an API access path based on the API group corresponding to the successfully matched method name and the microservice path prefix obtained in step S1. Use the generated API access path to send a request to the corresponding interface to obtain interface details; the interface details include interface parameters and return value information;

[0140] Furthermore, the specific steps for generating the API access path include:

[0141] (1) Get the method name that successfully matches the specified ID;

[0142] (2) According to the successfully matched method name, the corresponding API group information is searched and obtained from the structure storing the API group list data, wherein the API group information includes the API path segment and interface type;

[0143] (3) Extract the microservice path prefix from the result obtained in step S1;

[0144] (4) Combine the obtained microservice path prefix and the path fragment in the API grouping information to generate a complete API access path. The combination needs to be spliced ​​according to specific rules, such as adding a separator " / " between the paths.

[0145] S2.4: Check whether the operation of requesting interface details is successful by checking the response status code;

[0146] If the request is successful, save the interface details;

[0147] If the request is unsuccessful, the error interface details will be thrown;

[0148] For example, the code implementation process of sending a request to the corresponding interface to obtain interface details is as follows:

[0149] import requests

[0150] # Assume this is the generated API access path

[0151] api_access_path = "https: / / example.com / api / some_endpoint"

[0152] try:

[0153] response = requests.get(api_access_path) # Send a GET request

[0154] if response.status_code == 200: # Check the response status code

[0155] interface_details = response.json() # Get interface details (JSON format)

[0156] print("Interface details:", interface_details)

[0157] else:

[0158] print(f"Request failed, status code: {response.status_code}")

[0159] except requests.RequestException as e:

[0160] print(f"Request error: {e}")

[0161] S2.5: Organize the obtained interface details and generate a code snippet mapping table. At the same time, automatically analyze the interface performance in combination with the embedded data; the code snippet mapping table records the correspondence between interface parameters, return values ​​and code snippets; the interface performance includes the response time and call frequency of the interface.

[0162] Furthermore, the specific steps of S2.5 include:

[0163] (1) Clean the obtained interface details data to remove invalid information, duplicate data, and data in the wrong format. For example, if the interface details contain HTML tags, they can be removed;

[0164] (2) Arrange the interface details according to a certain structure, such as classifying the interface's input parameters, output parameters, request methods, return status codes, and other information;

[0165] (3) Define the mapping rules between interface details and code snippets according to different programming languages ​​and development frameworks. For example, for a GET request interface, define its corresponding code snippet as the code for sending a GET request using the HTTP client library of that language;

[0166] (4) According to the mapping rules, the organized interface details are associated with the corresponding code snippets to generate a code snippet mapping table, wherein the code snippet mapping table contains the interface name, interface path, request method, and corresponding code snippet information;

[0167] (5) Collecting interface tracking data from the tracking system, such as the interface response time, number of calls, and error rate;

[0168] (6) Calculate the average response time of the interface based on the collected tracking data, and perform performance analysis based on the average response time of the interface. For example, if the average response time of the interface exceeds the preset response threshold, it may be that the business logic of the interface is complex or the database query efficiency is low. The average response time of the interface is obtained by calculating the ratio of the sum of the response time of each call to the interface to the number of calls to the interface;

[0169] It should be emphasized that since the interface details contain key information of the interface, such as the request method, request path, input and output parameters, this information can uniquely determine the function and usage of an interface, and the code snippet is the specific code that implements these interface functions, by defining reasonable mapping rules, the interface details and code snippets can be mapped one by one. For example, for an interface that uses Python's requests library to send a GET request, as long as the request path and request parameters of the interface are known, the corresponding code snippet can be generated.

[0170] Moreover, since interface details can only describe the definition and specifications of the interface, they cannot reflect the actual usage of the interface in operation. However, tracking data can record the number of interface calls, call time, caller and other information, and can promptly discover the performance bottlenecks and potential problems of the interface. Therefore, tracking data analysis is necessary.

[0171] The specific steps of step S3 include:

[0172] S3.1: After traversing all microservice path prefixes and corresponding API group list data, read the selected file content;

[0173] S3.2: Generate an abstract syntax tree based on the read file content using a code parsing tool, and traverse the abstract syntax tree using a traversal pointer. In the present invention, the code parsing tool uses Python's ast library.

[0174] S3.3: Check whether all nodes of the abstract syntax tree have been traversed;

[0175] If all nodes of the abstract syntax tree have not been traversed, the function declaration node and identifier judgment and diff comparison are performed, and the abstract syntax tree node is replaced based on the judgment and comparison results;

[0176] It should be noted that when traversing the abstract syntax tree, function declaration nodes are important structural elements in the code. Judging function declaration nodes can help understand which functions are defined in the code, the parameters of these functions, the return value type and other information. By analyzing function declaration nodes, the functional module division of the code can be determined and different functional units can be identified. This is very helpful for understanding the overall architecture and logic of the code. For example, when generating code based on API information, it is necessary to determine the name, parameter list and return value type of the generated function based on the function declaration node; and judging identifiers can help parse variables and function references in the code; because the code will be continuously modified and updated during the implementation process, by performing diff comparison, the changes in the code can be detected. For example, by comparing the abstract syntax trees of two versions of the code, it is possible to find out which function declarations have changed and which identifiers have been modified or deleted.

[0177] For example, suppose there are two versions of code, version A and version B. The two versions of the code are parsed into abstract syntax trees respectively, and then the two abstract syntax trees are diffed. If a new function declaration node is added in version B, the diff comparison will detect this new node and display it in the difference report. In this way, you can clearly understand what changes have occurred in the code from version A to version B.

[0178] If all nodes of the abstract syntax tree are traversed, check whether there is a node representing an import statement in the abstract syntax tree;

[0179] If there is an import statement, generate the corresponding import statement code and continue to traverse the remaining code mapping table. During the traversal process, replace the nodes that meet the replacement conditions;

[0180] If there is no import statement, directly traverse the remaining code mapping table and replace the nodes that meet the replacement conditions;

[0181] S3.4: Generate AI code configuration details based on the replaced abstract syntax tree.

[0182] The specific process of function declaration node and identifier judgment and diff comparison in S3.3 includes:

[0183] S3.31: If all nodes of the abstract syntax tree have not been traversed, check whether the currently traversed node is a function declaration node;

[0184] If the node is not a function declaration node, return to S3.2 and continue traversing the next node;

[0185] If the node is a function declaration node, determine whether the node is an identifier, such as a function name;

[0186] If the node does not belong to the identifier, return to S3.2 and continue traversing the next node;

[0187] If the node belongs to an identifier, save the name of the identifier and determine whether the saved name of the identifier exists in the map of the code fragment;

[0188] If it does not exist in the mapping of the code snippet, return to S3.2 and continue traversing the next node;

[0189] If it exists in the code snippet's map, remove the annotation corresponding to the method name;

[0190] S3.32: Determine whether a diff comparison of the abstract syntax tree is required;

[0191] If a comparison is required, use abstract syntax tree difference analysis to compare the current abstract syntax tree with the previous version;

[0192] Furthermore, the specific steps of using abstract syntax tree difference analysis to compare the current abstract syntax tree with the previous version include:

[0193] (1) Traverse the nodes of the two abstract syntax trees and use the tree edit distance algorithm to match and compare the nodes. For example, compare the node type, attributes, and child nodes. If the node matches successfully, continue to compare its child nodes; if not, record the difference information;

[0194] (2) During the comparison process, the difference information between the two abstract syntax trees is recorded, such as newly added nodes, deleted nodes, and modified node attributes, and stored in an empty list;

[0195] (3) Generate a difference report based on the recorded difference information, including the location, type and specific content of the difference.

[0196] If no comparison is required, the latest abstract syntax tree is generated based on the existing code details;

[0197] S3.33: Based on the judgment and analysis results, replace the nodes in the traversal process and update the structure of the abstract syntax tree;

[0198] S3.34: Based on the syntax tree comparison results and the traversal node replacement results, delete the mapping items that are no longer needed or have been updated in the corresponding code mapping table.

[0199] Example 3

[0200] See also Figure 3 In this embodiment, the specific steps of step S4 include:

[0201] S4.1: Extract configuration information from the generated AI code configuration details; the configuration information includes code style, naming conventions, and annotation rules;

[0202] S4.2: Add annotations to the generated method names according to the annotation rules in the AI ​​code configuration details; the annotations include the method name's function description, parameter description, return value description, and permission requirements;

[0203] S4.3: Generate annotated API code based on the annotated method name, microservice path prefix, and API access path, and define the API interface in combination with the programming language and framework;

[0204] Furthermore, the specific steps of S4.3 include:

[0205] (1) Get the annotated method name, microservice path prefix, and API access path;

[0206] (2) Concatenate the microservice path prefix and the API access path to form a complete API path;

[0207] (3) Generate the annotation API code based on the selected programming language and framework, combined with the annotated method name. The programming language is Python, and the framework is Python's Flask. The specific operations are as follows:

[0208] 1) Import libraries and modules related to processing HTTP requests, annotations, etc. according to the requirements of the framework;

[0209] 2) Use the syntax and annotations provided by the framework to bind the annotated method name to the constructed API path to define the API interface;

[0210] 3) Implement the specific logic of the annotated method name into the API interface to ensure that the interface can correctly process requests and return responses;

[0211] (4) Format the generated annotation API code to make it conform to the code standards and style.

[0212] S4.4: Analyze the parameter information of the API interface, add parameter verification logic to the annotated API code based on business requirements and data types, use the built-in verification mechanism to perform parameter verification, and generate the corresponding business logic code;

[0213] Furthermore, the specific steps of S4.4 include:

[0214] (1) Obtain the parameter definition of the API interface from the annotated API code, including parameter name and data type;

[0215] (2) Design parameter verification logic, including:

[0216] Check whether the parameter meets the requirements of the parameter type according to its data type. For example, for integer type parameters, check whether it is a valid integer value; for string type parameters, check whether its length and format meet the requirements.

[0217] For parameters with value range restrictions, check whether the passed-in parameters are within the standard range;

[0218] Perform mandatory field verification: For required parameters, check whether the parameter is passed in. If not, return the corresponding error message;

[0219] (3) Depending on the programming language and framework used, use the annotations or configuration methods provided by Flask-WTF to apply the designed parameter verification logic to the parameters of the API interface. It should be noted that Python's Flask uses Flask-WTF for form validation;

[0220] (4) In the business logic code, process according to the result of parameter verification;

[0221] If the parameter verification passes, the normal business logic is executed;

[0222] If the verification fails, an error message is returned to the client.

[0223] S4.5: Process the return result of the business logic code and generate the corresponding return result processing code based on the return value information in the interface details;

[0224] S4.6: Integrate the annotated API code, business logic code, and return result processing code to form a complete AI code, and check and correct the formed complete AI code.

[0225] Example 4

[0226] See also Figure 4 In this embodiment, the specific steps of step S5 include:

[0227] S5.1: Based on the complete AI code, determine the exception type and capture range; the exception types include network request exceptions, database operation exceptions, parameter parsing exceptions, and business logic calculation exceptions;

[0228] S5.2: Use the exception catching syntax try-except-finally to add exception catching code and write processing logic code for different exception types; the processing logic includes recording exception logs, returning error information to the caller, and performing error recovery operations. The try-except-finally syntax is the prior art content in this field and is not the inventive solution of this application, so it is not described in detail here;

[0229] Among them, the code that may throw an exception is placed in the try block. When the code in the try block is executed, if an exception occurs, the program will immediately jump to the except block or catch block for exception handling.

[0230] S5.3: Set exception throwing rules and write exception throwing code according to the exception throwing rules;

[0231] The exception throwing rule is that if there is an exception that cannot be handled by the current code block, the exception will be passed to the upper call chain;

[0232] S5.4: Integrate the added exception catching code, processing logic code, and exception throwing code with the complete AI code, and use the built-in open function to write them line by line to the specified file;

[0233] S5.5: After the code is written, check whether the file is generated successfully. If the writing fails, record the error information.

[0234] Example 5

[0235] See also Figure 5 Another embodiment provided by the present invention is an AI code generation and optimization system, comprising:

[0236] Method name generation module, interface details processing module, configuration generation module, code generation and integration module, exception handling module;

[0237] The method name generation module is used to obtain the microservice path prefix and API group list data required for system operation, and generate method names based on user selections and API group annotations;

[0238] The interface details processing module is used to obtain interface details information, including interface parameters and return values, for the API group corresponding to the generated method name. At the same time, it combines the microservice path prefix to generate the API access path, generates a code snippet mapping table by sorting the interface details, and analyzes the interface performance to provide a basis for subsequent code generation and optimization;

[0239] The configuration generation module is used to generate an abstract syntax tree based on the code fragment mapping table, traverse, check, and analyze the abstract syntax tree, replace nodes that meet the conditions, and generate AI code configuration details based on the replaced abstract syntax tree;

[0240] The code generation and integration module is used to annotate the generated method names based on the AI ​​code configuration details, generate API code, and add parameter validation logic, business logic code, and return result processing code to finally integrate and form a complete AI code.

[0241] The exception handling module is used to add exception handling logic to the generated complete AI code to ensure that the code can reasonably handle various abnormal situations during operation. At the same time, the complete AI code with added exception handling logic is written to a file to complete the generation and storage of the code.

[0242] The method name generation module includes: information acquisition unit, code identification unit, and method name generation unit;

[0243] The information acquisition unit is used to obtain the microservice path prefix through user input or system configuration, and obtain the corresponding API group list data from data sources such as configuration files, databases or service registration centers based on the prefix;

[0244] The code identification unit is used to combine the code feature words and compare the existing code through noise reduction hashing to determine whether the code is generated by the plug-in, thereby determining whether the code is artificial;

[0245] The method name generation unit is used to automatically generate a method name based on the API grouping selected by the user and the annotation information in the API grouping.

[0246] The interface details processing module includes: an interface details acquisition unit, an access path generation unit, a code fragment mapping unit, and an interface performance analysis unit;

[0247] The interface details acquisition unit is used to obtain specific interface details, including interface parameters and return value information, by sending a request to the interface for the API group corresponding to each generated method name;

[0248] The access path generation unit is used to combine the microservice path prefix and interface details to generate the API access path for subsequent interface calls and code generation;

[0249] The code snippet mapping unit is used to organize the obtained interface details, generate a code snippet mapping table, and record the correspondence between interface parameters, return values ​​and code snippets to facilitate subsequent code generation and replacement;

[0250] The interface performance analysis unit is used to combine embedded data to analyze performance indicators such as the usage frequency and response time of similar interfaces in the past, automatically perform performance processing such as anti-shake and throttling on the interface, and optimize interface performance.

[0251] The configuration generation module includes: abstract syntax tree unit, traversal and processing unit, and code configuration generation unit;

[0252] Abstract syntax tree unit, used to generate abstract syntax tree using code fragment mapping table and professional code parsing tools, such as Python's ast library;

[0253] The traversal and processing unit is used to traverse the generated abstract syntax tree, check and analyze each node and branch in the code structure, and replace the nodes that meet the conditions according to the preset rules;

[0254] The code configuration generation unit is used to extract the code style and naming conventions based on the replaced abstract syntax tree and generate AI code configuration details.

[0255] The code generation and integration module includes: annotation adding unit, API code generation unit, verification logic adding unit, business logic code unit, return result processing unit, and code integration unit;

[0256] The annotation adding unit is used to add appropriate annotations to the generated method names according to the annotation rules in the AI ​​code configuration details, such as method function description, parameter description, and return value description;

[0257] The API code generation unit is used to combine the annotated method name with the microservice path prefix, API access path and other information to generate complete API code;

[0258] The parameter verification logic adding unit is used to analyze the parameter information of the API interface and add parameter verification logic to the API code according to business requirements and data types to ensure the legitimacy of the input parameters;

[0259] The business logic code unit is used to generate corresponding business logic code based on the functions and business requirements of the API interface, refer to the code snippet mapping table and interface details, and implement specific business operations;

[0260] The return result processing unit is used to process the return result of the business logic code, format, encrypt, and paginate the return result according to the return value information in the interface details, and generate the corresponding return result processing code;

[0261] The code integration unit is used to integrate the annotated API code, parameter verification logic, business logic code, and return result processing code to form a complete AI code.

[0262] The exception handling module includes: an exception type determination unit, an exception capture unit, an exception throwing rule unit, and a code writing unit;

[0263] The exception type determination unit is used to analyze the functions and operations of each part of the code based on the complete AI code, and determine the possible exception types, such as network request exceptions, database operation exceptions, parameter parsing exceptions, and business logic calculation exceptions;

[0264] The exception capture unit is used to add exception capture code to the corresponding code block using the exception capture syntax try-except-finally and to write specific processing logic, such as recording exception logs, returning error information to the caller, and performing error recovery operations;

[0265] Exception throwing rule unit, used to set exception throwing rules and write corresponding exception throwing codes;

[0266] The code writing unit is used to integrate the added exception capture code, processing logic code, exception throwing code with the complete AI code, and use the built-in file operation function open function to write the integrated code line by line into the specified file and check it.

[0267] Example 6

[0268] An electronic device includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of an AI code generation optimization method when executing the computer program. For details, please refer to the above method embodiment and will not be repeated here.

[0269] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific embodiments. The above-mentioned specific embodiments are merely illustrative and not restrictive. Under the guidance of the present invention, ordinary technicians in this field can also change, modify, replace and modify the above-mentioned embodiments without departing from the purpose and scope of protection of the present invention. These are all protected by the present invention.

Claims

1. AI code generation optimization method, characterized in that: include: Step S1: Obtain the microservice path prefix and the corresponding API group list data, combine the code feature words, determine the artificial code through noise reduction hash comparison, and automatically generate the method name based on the user-selected API group and the annotation; Step S2: For each API group corresponding to the generated method name, obtain interface details, combine them with the microservice path prefix, generate the API access path, organize the obtained interface details, generate a code snippet mapping table, and automatically analyze the interface performance in combination with the embedded data; Step S3: Generate an abstract syntax tree based on the code snippet mapping table, and traverse the generated abstract syntax tree to check and analyze each node and branch in the code structure. At the same time, during the traversal process, replace the nodes that meet the conditions, and generate AI code configuration details based on the replaced abstract syntax tree; Step S4: Add annotations to the generated method names based on the AI ​​code configuration details, generate API code, add parameter validation logic to the generated API code, generate corresponding business logic code, and process the interface return value to generate the corresponding return result processing code, thus forming a complete AI code through integration; Step S5: adding exception handling logic to the generated complete AI code, and writing the complete AI code with the added exception handling logic into a file.

2. The AI ​​code generation optimization method according to claim 1, wherein: The specific steps of step S1 include: S1.1: Obtain the microservice path prefix through user input or system configuration, and use the obtained microservice path prefix to obtain the corresponding API group list data from the configuration file; S1.2: Initialize a traversal pointer, starting from the starting position of the API group list data, and check whether all microservice path prefixes and corresponding API group list data have been traversed; If the traversal is completed, the configuration file content selected by the user is read; If the traversal is not complete, the API path and interface type are obtained from the current traversal position, and a list of generated method names is maintained to determine whether the method name corresponding to the API path and interface type has been generated; If the method name is not generated, the existing code is compared using a denoising hash to distinguish between plugin-generated code and manually written code. If the code is not generated by the plugin, the method name is automatically generated based on the user-selected API group and the annotation information in the API group. The generated method name is added to the list of generated method names and the traversal pointer is moved back one position. If the method name has been generated, the corresponding method name is returned directly from the list of generated method names, and the traversal pointer is moved back one position.

3. The AI ​​code generation optimization method according to claim 2, wherein: The specific steps of step S2 include: S2.1: Obtain all generated method names from step S1, and match each obtained generated method name with the specified ID using string comparison; If the match is successful, go to S2.3; If the match is unsuccessful, the annotation corresponding to the method name is searched, and zero-width characters are extracted from the annotation. The extracted zero-width characters are mapped and converted into encoding information. S2.2: Match the mapped zero-width character with the specified ID again; If the match is successful, go to S2.3; If the match is unsuccessful, the traversal pointer is returned to the initial position and the matching judgment of the generated method name is restarted.

4. The AI ​​code generation optimization method according to claim 3, wherein: The specific steps of step S2 also include: S2.3: Generate an API access path based on the API group corresponding to the successfully matched method name and the microservice path prefix obtained in step S1. Use the generated API access path to send a request to the corresponding interface to obtain interface details; the interface details include interface parameters and return value information; S2.4: Check whether the operation of requesting interface details is successful by checking the response status code; If the request is successful, save the interface details; If the request is unsuccessful, the error interface details will be thrown; S2.5: Organize the obtained interface details and generate a code snippet mapping table. At the same time, automatically analyze the interface performance in combination with the embedded data; the code snippet mapping table records the correspondence between interface parameters, return values ​​and code snippets; the interface performance includes the response time and call frequency of the interface.

5. The AI ​​code generation optimization method according to claim 4, wherein: The specific steps of step S3 include: S3.1: After traversing all microservice path prefixes and corresponding API group list data, read the selected file content; S3.2: Use the code parsing tool to generate an abstract syntax tree based on the read file content, and use the traversal pointer to traverse the abstract syntax tree; S3.3: Check whether all nodes of the abstract syntax tree have been traversed; If all nodes of the abstract syntax tree have not been traversed, the function declaration node and identifier judgment and diff comparison are performed, and the abstract syntax tree node is replaced based on the judgment and comparison results; If all nodes of the abstract syntax tree are traversed, check whether there is a node representing an import statement in the abstract syntax tree; If there is an import statement, generate the corresponding import statement code and continue to traverse the remaining code mapping table. During the traversal process, replace the nodes that meet the replacement conditions; If there is no import statement, directly traverse the remaining code mapping table and replace the nodes that meet the replacement conditions; S3.4: Generate AI code configuration details based on the replaced abstract syntax tree.

6. The AI ​​code generation optimization method according to claim 5, characterized in that: The specific process of function declaration node and identifier judgment and diff comparison in S3.3 includes: S3.31: If all nodes of the abstract syntax tree have not been traversed, check whether the currently traversed node is a function declaration node; If the node is not a function declaration node, return to S3.2 and continue traversing the next node; If the node is a function declaration node, determine whether the node is an identifier; If the node does not belong to the identifier, return to S3.2 and continue traversing the next node; If the node belongs to an identifier, save the name of the identifier and determine whether the saved name of the identifier exists in the map of the code fragment; If it does not exist in the mapping of the code snippet, return to S3.2 and continue traversing the next node; If it exists in the code snippet's map, remove the annotation corresponding to the method name; S3.32: Determine whether a diff comparison of the abstract syntax tree is required; If a comparison is required, use abstract syntax tree difference analysis to compare the current abstract syntax tree with the previous version; If no comparison is required, the latest abstract syntax tree is generated based on the existing code details; S3.33: Based on the judgment and analysis results, replace the nodes in the traversal process and update the structure of the abstract syntax tree; S3.34: Based on the syntax tree comparison results and the traversal node replacement results, delete the mapping items that are no longer needed or have been updated in the corresponding code mapping table.

7. The AI ​​code generation optimization method according to claim 6, wherein: The specific steps of step S4 include: S4.1: Extract configuration information from the generated AI code configuration details; the configuration information includes code style, naming conventions, and annotation rules; S4.2: Add annotations to the generated method names according to the annotation rules in the AI ​​code configuration details; the annotations include the method name's function description, parameter description, return value description, and permission requirements; S4.3: Generate annotated API code based on the annotated method name, microservice path prefix, and API access path, and define the API interface in combination with the programming language and framework; S4.4: Analyze the parameter information of the API interface, add parameter verification logic to the annotated API code based on business requirements and data types, use the built-in verification mechanism to perform parameter verification, and generate the corresponding business logic code; S4.5: Process the return result of the business logic code and generate the corresponding return result processing code based on the return value information in the interface details; S4.6: Integrate the annotated API code, business logic code, and return result processing code to form a complete AI code, and check and correct the formed complete AI code.

8. The AI ​​code generation optimization method according to claim 7, wherein: The specific steps of step S5 include: S5.1: Based on the complete AI code, determine the exception type and capture range; the exception types include network request exceptions, database operation exceptions, parameter parsing exceptions, and business logic calculation exceptions; S5.2: Use the exception catching syntax try-except-finally to add exception catching code and write processing logic code for different exception types. The processing logic includes recording exception logs, returning error information to the caller, and performing error recovery operations. S5.3: Set exception throwing rules and write exception throwing code according to the exception throwing rules; The exception throwing rule is that if there is an exception that cannot be handled by the current code block, the exception will be passed to the upper call chain; S5.4: Integrate the added exception catching code, processing logic code, and exception throwing code with the complete AI code, and use the built-in open function to write them line by line to the specified file; S5.5: After the code is written, check whether the file is generated successfully. If the writing fails, record the error information.

9. An AI code generation optimization system, which is used to implement the AI ​​code generation optimization method according to any one of claims 1 to 8, characterized in that: include: Method name generation module, interface details processing module, configuration generation module, code generation and integration module, exception handling module; The method name generation module is used to obtain the microservice path prefix and API group list data required for system operation, and generate a method name based on the user's selection and API group annotation; The interface details processing module is used to obtain interface details information for the API group corresponding to the generated method name, generate the API access path in combination with the microservice path prefix, and generate a code snippet mapping table by arranging the interface details; The configuration generation module is used to generate an abstract syntax tree based on the code fragment mapping table, traverse, check and analyze the abstract syntax tree, replace nodes that meet the conditions, and generate AI code configuration details based on the replaced abstract syntax tree; The code generation and integration module is used to annotate the generated method names based on the AI ​​code configuration details, generate API code, and add parameter verification logic, business logic code, and return result processing code to finally integrate and form a complete AI code; The exception handling module is used to add exception handling logic to the generated complete AI code, and write the complete AI code with the added exception handling logic into a file to complete the generation and storage of the AI ​​code.

10. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the AI ​​code generation optimization method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Application programming interface generation method and device

    CN108108162A

  • Inventory code generation method and device for GSCloud and medium

    CN120315694A