API Task Requirement Processing and Access Method for Browser, Related Devices

By generating an abstract syntax tree and iteratively optimizing the API code output from the large language model, the errors in the API code and the lack of project-specific information are solved, and the logical accuracy and adaptability of the code are improved.

CN119045817BActive Publication Date: 2025-07-01SHENZHEN BEIANT MEDICAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411143371.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-20
Publication Date
2025-07-01
Estimated Expiration
2044-08-20

AI Technical Summary

Technical Problem

In the prior art, API code generated by large language models may contain errors or lack project-specific information, resulting in a low degree of adaptation to API task requirements.

Method used

Generate an abstract syntax tree through the parser, extract context information and establish hierarchical relationships, and iteratively optimize the API code file output by the large language model until the task needs are met.

Benefits of technology

It improves the adaptability of API code files and API task requirements and improves the logical accuracy of API code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119045817B_ABST
    Figure CN119045817B_ABST
Patent Text Reader

Abstract

The present application discloses an API task requirement processing and access method for a browser, and related devices. The method includes: inputting an API task requirement into a large language model to obtain an initial API code file output by the large language model; using a parser to generate a corresponding abstract syntax tree from the initial API code file; using the abstract syntax tree to extract context information and establish a hierarchical relationship; inputting the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model; when the target API code file meets the API task requirement, using the target API code file as the final API file corresponding to the API task requirement. Through the above method, the adaptation degree between the API code file and the API task requirement is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of API technology, and particularly to API task requirement processing, access methods for browsers, and related devices. Background Art

[0002] Large Language Models (LLMs) have made significant progress in automatic code generation. However, integrating LLM-based code generation into actual software projects poses challenges.

[0003] Because the generated code may contain errors in API usage, classes, data structures, or lack project-specific information. Summary of the Invention

[0004] The API task requirement processing, access methods for browsers, and related devices provided by this application can improve the adaptation degree between the API code file and the API task requirements, and enhance the logical accuracy of the API code within the API code file.

[0005] In a first aspect, this application provides an API task requirement processing method, which includes: inputting API task requirements into a large language model to obtain an initial API code file output by the large language model; using a parser to generate a corresponding abstract syntax tree from the initial API code file; using the abstract syntax tree to extract context information and establish a hierarchical relationship; inputting the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model; when the target API code file meets the API task requirements, taking the target API code file as the final API file corresponding to the API task requirements.

[0006] Among them, using the abstract syntax tree to extract context information and establish a hierarchical relationship includes: using the abstract syntax tree to extract context information and obtaining query vectors; calculating the cosine similarity between the query vector and each context information; using the cosine similarity to filter out the best context information from the context information; using the best context information to establish a hierarchical relationship.

[0007] Among them, when the target API code file meets the API task requirements, taking the target API code file as the final API file corresponding to the API task requirements includes: testing the target API code file, and when the test result meets the API task requirements, taking the target API code file as the final API file corresponding to the API task requirements.

[0008] Among them, testing the target API code file includes: determining a general API dependency graph based on the target API code file; monomorphizing the general API dependency graph to obtain an initial monomorphic API dependency graph; performing similarity pruning on the initial monomorphic API dependency graph to obtain a refined monomorphic API dependency graph; generating an API sequence based on the refined monomorphic API dependency; generating test cases using the API sequence; and testing the target API code file using the test cases.

[0009] Among them, monomorphizing the general API dependency graph to obtain an initial monomorphic API dependency graph includes: specifying the general API types in the general API dependency graph to obtain an initial typed API dependency graph; selecting a starting API from the initial typed API dependency graph, and searching for a path from the starting API to an ending API based on the starting API; and obtaining the initial monomorphic API dependency graph according to the path.

[0010] Among them, performing similarity pruning on the initial monomorphic API dependency graph to obtain a refined monomorphic API dependency graph includes: obtaining the API dependency relationships in the initial monomorphic API dependency graph; and removing similar and redundant API dependency relationships to obtain the refined monomorphic API dependency graph.

[0011] Among them, generating test cases using the API sequence includes: using a fuzz driver to execute the API sequence to generate test cases for fuzz testing.

[0012] In a second aspect, the present application provides an access method for a browser, the method including: a local Web server receiving an access request from the browser to a local external device; the local Web server providing a transit API corresponding to the local external device to the browser based on the access request, so that the browser accesses the local external device through the transit API.

[0013] Among them, the transit API is obtained by the method provided in the first aspect.

[0014] In a third aspect, the present application provides an electronic device, the electronic device including a processor and a memory connected to the processor; the memory is used for storing a computer program, and when the computer program is executed by the processor, it is used to implement the method provided in the first aspect or the second aspect.

[0015] In a fourth aspect, the present application provides a computer-readable storage medium, the computer-readable storage medium is used for storing a computer program, and when the computer program is executed by the processor, it is used to implement the method provided in the first aspect or the second aspect.

[0016] The beneficial effects of this application are as follows: Different from the prior art, the API task requirement processing method, the access method for browsers, and related devices provided by this application, when the large language model outputs an initial API code file corresponding to the API task requirements, use a parser to generate an abstract syntax tree from the initial API code file; extract context information using the abstract syntax tree and establish a hierarchical relationship; input the hierarchical relationship into the large language model again to obtain the target API code file output by the large language model; when the target API code file meets the API task requirements, use the target API code file as the final API file corresponding to the API task requirements, thereby iteratively repairing the logical errors in the API code file output by the large language model through the hierarchical relationship, improving the adaptation degree between the API code file and the API task requirements, and enhancing the logical accuracy of the API code within the API code file. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings. Among them:

[0018] Figure 1 is a flowchart of an embodiment of the API task requirement processing method provided by this application;

[0019] Figure 2 is a flowchart of another embodiment of the API task requirement processing method provided by this application;

[0020] Figure 3 is a flowchart of another embodiment of the API task requirement processing method provided by this application;

[0021] Figure 4 is Figure 3 a flowchart of an embodiment of step 35 in

[0022] Figure 5 is Figure 4 a flowchart of an embodiment of step 352 in

[0023] Figure 6 is Figure 3 a flowchart of an embodiment of step 353 in

[0024] Figure 7 is a flowchart of an embodiment of the method for browser access provided by this application;

[0025] Figure 8It is a schematic structural diagram of an embodiment of an electronic device provided by this application;

[0026] Figure 9 It is a schematic structural diagram of an embodiment of a computer-readable storage medium provided by this application. Detailed implementation manners

[0027] Next, the technical solutions in the embodiments of this application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of this application. It can be understood that the specific embodiments described herein are only used to explain this application, rather than limiting this application. Additionally, it should be noted that for the sake of description, only parts related to this application rather than all structures are shown in the drawings. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of this application.

[0028] Referring to "embodiment" herein means that the specific features, structures, or characteristics described in conjunction with the embodiment may be included in at least one embodiment of this application. The phrase appears in various positions in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0029] Large language models (LLMs) have made significant progress in automatic code generation. However, integrating LLM-based code generation into actual software projects poses challenges.

[0030] Because the generated code may contain errors in API usage, classes, data structures, or lack project-specific information.

[0031] Based on this, this application proposes that when the large language model outputs an initial API code file corresponding to the API task requirements, a parser is used to generate a corresponding abstract syntax tree from the initial API code file; the abstract syntax tree is used to extract context information and establish a hierarchical relationship; the hierarchical relationship is input into the large language model again to obtain the target API code file output by the large language model; when the target API code file meets the API task requirements, the target API code file is used as the final API file corresponding to the API task requirements, thereby iteratively repairing the logical errors in the API code file output by the large language model through the hierarchical relationship, improving the adaptation degree between the API code file and the API task requirements, and enhancing the logical accuracy of the API code in the API code file. Specifically, refer to any of the following embodiments or a combination of any embodiments.

[0032] Refer to Figure 1 , Figure 1It is a schematic flowchart of an embodiment of the API task requirement processing method provided by this application. The method includes:

[0033] Step 11: Input the API task requirement into the large language model to obtain an initial API code file output by the large language model.

[0034] In some embodiments, the large language model can automatically generate API code according to the API task requirement, and then obtain an initial API code file output by the large language model.

[0035] Step 12: Use a parser to generate a corresponding abstract syntax tree from the initial API code file.

[0036] It can be understood that there may be corresponding problems with the initial API code file. For example, only inputting the task requirements may cause the LLM to ignore project-specific APIs, classes, data structures, or type information specific to the software project repository, which may potentially miss basic logic during the code generation process.

[0037] Step 13: Use the abstract syntax tree to extract context information and establish a hierarchical relationship.

[0038] In some embodiments, the initial API code file is used to generate an abstract syntax tree through a parser, which is a tree-like data structure representing the source code structure. Each node represents a syntax structure in the source code. The abstract syntax tree does not show all the syntax details, such as parentheses and semicolons, but focuses on the logical structure of the code. Each node in the tree represents a syntax element (such as an operator, variable, function, etc.), and the edges represent the relationships between the nodes. First, the source code file is decomposed into tokens, such as keywords, identifiers, operators, etc. According to the semantic search grammar rules, the token sequence is transformed into an abstract syntax tree. The abstract syntax tree is widely used in compiler and interpreter design for operations such as syntax analysis, code generation, and optimization. If a tree node is a child node of another node (for example, the function get_handler and the class AsyncBolt), an edge is created from the parent node to the child node to establish a hierarchical relationship.

[0039] Step 14: Input the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model.

[0040] Input the hierarchical relationship into the large language model again for iteration to obtain the target API code file output by the large language model. During the iteration process, generate API code automatically again according to the hierarchical relationship and API task requirements, and then obtain the target API code file output by the large language model. If the target API code file meets the API task requirements, execute step 15. If the target API code file does not meet the API task requirements, continue the iteration. After the large language model outputs the API code file, execute steps 12 to 14.

[0041] The specific number of iterations is set according to actual requirements.

[0042] Step 15: When the target API code file meets the API task requirements, use the target API code file as the final API file corresponding to the API task requirements.

[0043] In this embodiment, when the large language model outputs the initial API code file corresponding to the API task requirements, use a parser to generate the corresponding abstract syntax tree from the initial API code file; use the abstract syntax tree to extract context information and establish a hierarchical relationship; input the hierarchical relationship into the large language model again to obtain the target API code file output by the large language model; when the target API code file meets the API task requirements, use the target API code file as the final API file corresponding to the API task requirements, so as to repair the logical errors in the API code file output by the large language model by iterating the hierarchical relationship, improve the adaptation degree between the API code file and the API task requirements, and enhance the logical accuracy of the API code in the API code file.

[0044] Refer to Figure 2 , Figure 2 is a schematic flowchart of another embodiment of the API task requirement processing method provided by this application. The method includes:

[0045] Step 21: Input the API task requirements into the large language model to obtain the initial API code file output by the large language model.

[0046] Step 22: Use a parser to generate the corresponding abstract syntax tree from the initial API code file.

[0047] Step 23: Use the abstract syntax tree to extract context information and obtain query vectors.

[0048] Step 24: Calculate the cosine similarity between the query vector and each context information.

[0049] Step 25: Use the cosine similarity to screen out the best context information from the context information.

[0050] Semantic search relies on technologies such as vector search and machine learning. Vector search encodes searchable information into fields (vectors) of related terms or items, and then compares these vectors to determine the most similar content. Then, context clues are used to determine the meaning of words, and results are returned based on the semantic relevance of the query. This means that the search results are not just content that contains the query terms, but content related to the actual meaning of the query.

[0051] Calculate the cosine similarity between the query vector and the embedding vector of each context entry, and use this similarity to retrieve the most similar entries:

[0052] Generate the query vector: First, convert the query into an embedding vector, denoted as hq;

[0053] Calculate the cosine similarity: Then, calculate the cosine similarity between the query vector hq and the embedding vector hc of each context entry. The cosine similarity is calculated using the following formula:

[0054]

[0055] where hq·hc represents the dot product of the vectors, and ||hq|| and ||hc|| represent the magnitudes of the vectors respectively.

[0056] Retrieve the most similar entries: According to the calculated similarity, retrieve the top n entries that are most similar to the query.

[0057] Step 26: Establish a hierarchical relationship using the best context information Extract context information using the abstract syntax tree and establish a hierarchical relationship.

[0058] Step 27: Input the hierarchical relationship into the large language model again to obtain the target API code file output by the large language model.

[0059] Step 28: When the target API code file meets the API task requirements, use the target API code file as the final API file corresponding to the API task requirements.

[0060] In this embodiment, when the large language model outputs an initial API code file corresponding to the API task requirements, a parser is used to generate a corresponding abstract syntax tree from the initial API code file; the abstract syntax tree is used to extract context information and establish a hierarchical relationship; the hierarchical relationship is input into the large language model again to obtain the target API code file output by the large language model; when the target API code file meets the API task requirements, the target API code file is used as the final API file corresponding to the API task requirements, thereby iteratively repairing the logical errors in the API code file output by the large language model through the hierarchical relationship, improving the adaptation degree between the API code file and the API task requirements, and enhancing the logical accuracy of the API code in the API code file.

[0061] Further, calculate the cosine similarity between the query vector and each context entry embedding vector, and use this similarity to retrieve the most similar entry, thereby selecting context entries with higher similarity and improving the accuracy of the subsequent hierarchical relationship.

[0062] Refer to Figure 3 , Figure 3 FIG.

[0063] Step 31: Input the API task requirements into the large language model to obtain the initial API code file output by the large language model.

[0064] Step 32: Use a parser to generate a corresponding abstract syntax tree from the initial API code file.

[0065] Step 33: Use the abstract syntax tree to extract context information and establish a hierarchical relationship.

[0066] Step 34: Input the hierarchical relationship into the large language model again to obtain the target API code file output by the large language model.

[0067] Steps 31 to 34 have the same or similar technical solutions as any embodiment of the present application, and will not be elaborated here.

[0068] Step 35: Test the target API code file. When the test result meets the API task requirements, the target API code file is used as the final API file corresponding to the API task requirements.

[0069] In some embodiments, refer to Figure 4 , step 35 may be the following process:

[0070] Step 351: Determine a general API dependency graph based on the target API code file.

[0071] The general API dependency graph is defined as a directed graph.

[0072] Step 352: Monomorphize the general API dependency graph to obtain an initial monomorphic API dependency graph.

[0073] Among them, the monomorphic API dependency graph has the following technical effects:

[0074] Simplify analysis and testing: By concretizing types and APIs, the complexity brought by generics is reduced, making analysis and testing more straightforward and efficient.

[0075] Improve coverage: During testing processes such as fuzz testing, the monomorphic API dependency graph can help generate more representative test cases and improve test coverage.

[0076] Reduce redundancy: Through similarity pruning, redundant information in the dependency graph is reduced, making the dependency relationship clearer.

[0077] Specific application scenarios:

[0078] Fuzz testing: In fuzz testing, the monomorphic API dependency graph is used to generate specific test cases to ensure that all instances of generic code can be covered by testing.

[0079] Static analysis: In static analysis tools, the monomorphic API dependency graph can help the analyzer better understand the code dependency relationship and identify potential errors and security vulnerabilities.

[0080] Performance optimization: Through monomorphization, the compiler can generate more efficient code, which helps with performance optimization.

[0081] In some embodiments, referring to Figure 5 , step 352 may be the following process:

[0082] Step 51: Concretize the general API types in the general API dependency graph to obtain an initial typed API dependency graph.

[0083] Step 52: Select a starting API from the initial typed API dependency graph, and search for paths from the starting API to the ending API based on the starting API.

[0084] An API is said to be reachable if each input in the API sequence satisfies any of the following conditions:

[0085] · The type of this input is primitive.

[0086] · The type of the input is non-generic, and there is a producer edge from any previous API in the API sequence to this input.

[0087] · The input type is generic. There exists a concrete type t such that there is a producer edge from any previous API in the API sequence to type t, and there is a matching edge from t to the input type.

[0088] Step 53: Obtain the initial monomorphic API dependency graph according to the path.

[0089] In an application scenario, step 352 can be the following steps:

[0090] Construct a monomorphic API dependency graph: Specify the generic APIs and types to generate a dependency graph that includes all concrete type instances and APIs.

[0091] Determine the starting point: Select one or more starting points, which can be specific APIs, type instances, or the entry point of the program (such as the main function).

[0092] Search for reachable nodes: Starting from the starting point, traverse the dependency graph to find all reachable API nodes and type instances. This step may include algorithms such as depth-first search (DFS) and breadth-first search (BFS).

[0093] Handle constraints: During the search process, type constraints and function constraints need to be handled to ensure that only eligible paths are considered.

[0094] Technical effects: The reachable monomorphic API search has the following technical effects:

[0095] Identify the call chain: It clarifies which APIs and type instances are reachable after specification, helping to understand the program's call chain and execution path.

[0096] Assist in testing: During the testing process, these reachable APIs can be used to generate test cases to ensure that all actual possible code paths are covered by the tests.

[0097] Optimize the code: By identifying which APIs are actually reachable, code optimization can be carried out to eliminate redundant or never-called code.

[0098] Specific application scenarios:

[0099] Security analysis: When conducting security analysis, identifying reachable APIs helps to discover potential security vulnerabilities and attack paths.

[0100] Performance analysis: By analyzing reachable APIs and the call chain, performance bottlenecks and optimization points can be discovered.

[0101] Test generation: In automated test generation tools, use the results of reachable monomorphic API search to generate representative test cases to improve test coverage.

[0102] Step 353: Perform similarity pruning on the initial monomorphic API dependency graph to obtain a refined monomorphic API dependency graph.

[0103] In some embodiments, referring to Figure 6 , step 353 may be the following process:

[0104] Step 61: Obtain the API dependency relationships in the initial monomorphic API dependency graph.

[0105] Step 62: Remove similar and redundant API dependency relationships to obtain a refined monomorphic API dependency graph.

[0106] In an application scenario, similarity pruning is achieved through the following steps:

[0107] Identify similar nodes and edges: By analyzing the attributes, labels, and connection relationships of nodes and edges, identify the functionally similar or identical parts in the graph.

[0108] Merge or delete similar parts: Merge or delete highly similar or redundant nodes and edges to simplify the graph structure. This may include the following operations:

[0109] Merge nodes: Merge functionally similar nodes into one node and update the connection relationships of the relevant edges.

[0110] Delete redundant edges: Remove duplicate or unnecessary edges and retain the critical path.

[0111] Update dependency relationships: After pruning, recalculate and update the dependency relationships in the graph to ensure the integrity and accuracy of the graph.

[0112] Technical effects: Similarity pruning has the following technical effects:

[0113] Simplify the graph structure: Reduce the number of nodes and edges, making the dependency graph more concise and easier to understand.

[0114] Improve processing efficiency: Reduce the complexity of analysis and calculation, saving computing resources and time.

[0115] Enhance the readability of results: By removing redundant information, make the analysis results clearer and easier to interpret and apply.

[0116] Specific application scenarios: API dependency analysis: When analyzing API dependency relationships, remove similar and redundant dependency paths to simplify the dependency graph and help developers better understand the relationships between APIs.

[0117] Automated test generation: When generating test cases, by pruning similar test paths, reduce redundant tests and improve test efficiency.

[0118] Code Optimization: When optimizing the code structure, redundant code is identified and eliminated through similarity pruning, improving code quality and performance.

[0119] Refining the monomorphic API dependency graph has the following technical effects:

[0120] Simplify the graph structure: Remove redundant and similar nodes and edges, making the dependency graph more concise and easier to understand.

[0121] Improve analysis efficiency: Reduce the complexity of the graph, lower the consumption of computing resources and time, and improve analysis and processing efficiency.

[0122] Enhance result readability: Through refinement, the dependency graph becomes clearer and the analysis results are easier to interpret and apply.

[0123] Specific application scenarios: API dependency analysis: When analyzing API dependencies, refining the dependency graph helps developers better understand the relationships and dependency paths between APIs.

[0124] Automated test generation: When generating test cases, refining the dependency graph reduces redundant tests and improves test efficiency and coverage.

[0125] Code Optimization: When optimizing the code structure, redundant code is identified and eliminated through refining the dependency graph, improving code quality and performance.

[0126] Step 354: Generate an API sequence based on the refined monomorphic API dependency.

[0127] Step 355: Generate test cases using the API sequence.

[0128] Execute the API sequence using a fuzz driver to generate test cases for fuzz testing.

[0129] In some embodiments, API sequence generation refers to automatically generating a series of API call sequences that cover all possible API call paths and interactions in the target system. The generated API sequences can be used to test the functionality, performance, and security of the system.

[0130] Detailed Explanation

[0131] Input information: Includes API type information, dependency relationships, and interface documentation.

[0132] Generation methods:

[0133] Model-based method: Use models (such as dependency graphs, state machines, etc.) to generate possible API call sequences.

[0134] Random-based method: Randomly generate API call sequences to ensure coverage of different call paths.

[0135] Heuristic method: Generate API call sequences based on existing test experience and heuristic rules.

[0136] Coverage objective: Ensure that the generated API sequences can cover as many code paths and function points as possible to improve the comprehensiveness and effectiveness of testing.

[0137] Technical effect: Through API sequence generation, a large number of test cases can be automatically generated, covering a wide range of code paths and function points, effectively discovering errors and vulnerabilities in the system, and improving testing efficiency and quality.

[0138] Furthermore, a fuzz testing library is generated through fuzz driver synthesis to test the API call sequences.

[0139] Step 356: Test the target API code file using test cases.

[0140] In some embodiments, fuzz driver synthesis refers to automatically generating a driver program for performing fuzz testing. Fuzz testing is an automated testing technique that discovers vulnerabilities and errors in a system by inputting a large amount of random or semi-random data into the system.

[0141] Specifically: The input information includes API documentation, dependency relationships, type information, etc.

[0142] The generation methods include template methods and automated tools.

[0143] Among them, the template method uses predefined templates to generate fuzz driver programs, and these templates contain common API call patterns and data input methods.

[0144] The automated tool is to automatically generate fuzz driver programs using special tools (such as AFL, LibFuzzer, etc.).

[0145] The execution method is that the fuzz driver program executes the generated API sequences and inputs random or semi-random data to test the robustness and security of the system.

[0146] Technical effect: Through fuzz driver synthesis, a driver program for fuzz testing can be automatically generated, effectively testing the robustness and security of the system and discovering potential vulnerabilities and errors.

[0147] Combined use: In practical applications, API sequence generation and fuzz driver synthesis are usually combined to maximize the test coverage rate and the ability to discover potential problems.

[0148] Generate API call sequences: First, generate call sequences that widely cover API call paths and interactions through API sequence generation technology.

[0149] Synthesize a fuzz driver: Then, generate a driver that executes these API call sequences through fuzz driver synthesis technology and input random or semi-random data.

[0150] Execute tests: Finally, use the synthesized fuzz driver to execute the generated API call sequences to automatically test the robustness and security of the system and discover potential vulnerabilities and errors.

[0151] In this embodiment, when the large language model outputs an initial API code file corresponding to the API task requirements, use a parser to generate a corresponding abstract syntax tree from the initial API code file; use the abstract syntax tree to extract context information and establish a hierarchical relationship; input the hierarchical relationship into the large language model again to obtain the target API code file output by the large language model; when the target API code file meets the API task requirements, use the target API code file as the final API file corresponding to the API task requirements, so as to repair the logical errors in the API code file output by the large language model by iterating the hierarchical relationship, improve the adaptation degree between the API code file and the API task requirements, and enhance the logical accuracy of the API code in the API code file.

[0152] Furthermore, determine a general API dependency graph based on the target API code file; monomorphize the general API dependency graph to obtain an initial monomorphic API dependency graph; perform similarity pruning on the initial monomorphic API dependency graph to obtain a refined monomorphic API dependency graph; generate an API sequence based on the refined monomorphic API dependency; generate test cases using the API sequence; use the test cases to test the target API code file, so that when the test results meet the API task requirements, use the target API code file as the final API file corresponding to the API task requirements, and enhance the logical accuracy of the API code in the API code file and the adaptation degree between the API code file and the API task requirements.

[0153] Refer to Figure 7 , Figure 7 is a schematic flowchart of an embodiment of a method for browser access provided by this application. The method includes:

[0154] Step 71: The local Web server receives an access request from the browser to the local external device.

[0155] Step 72: The local Web server provides a transit API corresponding to the local external device to the browser based on the access request, so that the browser can access the local external device through the transit API.

[0156] Among them, the transit API is obtained by the method provided in any of the above embodiments.

[0157] In an application scenario, local external devices such as microscopes are connected. A web service program is run locally. Then a browser is opened and a website is accessed. The program in the website uses the transfer API provided by the web service program, thereby enabling the magnification of the microscope to be set through the browser. For example, in the process of remote assisted diagnosis in a hospital, it is necessary to use the browser to share the microscopic field of view so that experts at the remote end can make a diagnosis. At this time, it is necessary to use the browser to access the local microscope.

[0158] In this embodiment, the transfer API is obtained by using the method provided in any of the above embodiments, which can improve the adaptation degree between the transfer API, the local web server, and the browser, and enhance the logical accuracy of the API code in the transfer API.

[0159] Furthermore, a web server program is provided locally. By running this program, there is a web server locally. Then the browser accesses the local web server. Since the local web server is a local program and a local program can access any local external device, the transfer API is provided through the local web server, thereby enabling the browser to access local devices.

[0160] Refer to Figure 8 , Figure 8 which is a schematic structural diagram of an embodiment of an electronic device provided by this application. The electronic device includes a processor and a memory connected to the processor; the memory is used to store a computer program, and when the computer program is executed by the processor, it is used to implement the following methods:

[0161] Input the API task requirements into the large language model to obtain the initial API code file output by the large language model; use a parser to generate the corresponding abstract syntax tree from the initial API code file; use the abstract syntax tree to extract context information and establish a hierarchical relationship; input the hierarchical relationship into the large language model again to obtain the target API code file output by the large language model; when the target API code file meets the API task requirements, use the target API code file as the final API file corresponding to the API task requirements;

[0162] Or, the local web server receives an access request from the browser to a local external device; the local web server provides the transfer API corresponding to the local external device to the browser based on the access request, so that the browser can access the local external device through the transfer API.

[0163] It can be understood that when the computer program is executed by the processor, it is also used to implement the methods in any of the above embodiments.

[0164] Refer to Figure 9 , Figure 9It is a schematic structural diagram of an embodiment of a computer-readable storage medium provided by this application. The computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, it is used to implement the following method:

[0165] Input the API task requirements into a large language model to obtain an initial API code file output by the large language model; use a parser to generate a corresponding abstract syntax tree from the initial API code file; use the abstract syntax tree to extract context information and establish a hierarchical relationship; input the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model; when the target API code file meets the API task requirements, use the target API code file as the final API file corresponding to the API task requirements;

[0166] Alternatively, a local Web server receives an access request from a browser to a local external device; based on the access request, the local Web server provides a transit API corresponding to the local external device to the browser, so that the browser can access the local external device through the transit API.

[0167] It can be understood that when the computer program is executed by a processor, it is also used to implement the method of any of the above embodiments.

[0168] In summary, for the API task requirement processing, access method for browser, and related device provided by this application, when the large language model outputs an initial API code file corresponding to the API task requirements, use a parser to generate a corresponding abstract syntax tree from the initial API code file; use the abstract syntax tree to extract context information and establish a hierarchical relationship; input the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model; when the target API code file meets the API task requirements, use the target API code file as the final API file corresponding to the API task requirements, thereby repairing logical errors in the API code file output by the large language model by iterating the hierarchical relationship, improving the adaptation degree between the API code file and the API task requirements, and enhancing the logical accuracy of the API code in the API code file.

[0169] Furthermore, provide a Web server program locally. By running this program, there is a Web server locally. Then the browser accesses the local Web server. Since the local Web server is a local program and a local program can access any local external device, a transit API is provided through the local Web server, thereby enabling the browser to access local devices.

[0170] In several embodiments provided by the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0171] If the integrated unit in the above-mentioned other embodiments is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods described in various embodiments of the present application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.

[0172] The above is only the embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present application.

Claims

1. A method for processing API task requirements, characterized in that: The method comprises: Inputting the API task requirements into the large language model to obtain an initial API code file output by the large language model; Using a parser to generate a corresponding abstract syntax tree from the initial API code file; Extracting context information using the abstract syntax tree to establish a hierarchical relationship; Inputting the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model; When the target API code file meets the API task requirement, the target API code file is used as the final API file corresponding to the API task requirement; The process of extracting context information by using the abstract syntax tree and establishing a hierarchical relationship includes: Extracting context information using the abstract syntax tree and obtaining a query vector; Calculating the cosine similarity between the query vector and each context information; Filtering out the best context information from the context information using the cosine similarity; A hierarchical relationship is established using the optimal context information.

2. The method according to claim 1, characterized in that When the target API code file meets the API task requirement, using the target API code file as the final API file corresponding to the API task requirement includes: The target API code file is tested, and when the test result meets the API task requirement, the target API code file is used as the final API file corresponding to the API task requirement.

3. The method according to claim 2, characterized in that The testing of the target API code file includes: Determine a general API dependency graph based on the target API code file; Monomorphizing the general API dependency graph to obtain an initial monomorphic API dependency graph; Performing similarity pruning on the initial singleton API dependency graph to obtain a refined singleton API dependency graph; Generate an API sequence according to the refined singleton API dependency; Generate test cases using the API sequence; The target API code file is tested using the test case.

4. The method according to claim 3, characterized in that The step of monomorphizing the general API dependency graph to obtain an initial monomorphic API dependency graph includes: Concretize the general API type in the general API dependency graph to obtain an initial type API dependency graph; Selecting a starting point API from the initial type API dependency graph, and searching for a path from the starting point API to the end point API according to the starting point API; The initial singleton API dependency graph is obtained according to the path.

5. The method according to claim 3, characterized in that: The similarity pruning of the initial singleton API dependency graph to obtain a refined singleton API dependency graph includes: Obtaining API dependency relationships in the initial singleton API dependency graph; Remove similar and redundant API dependencies to obtain a refined singleton API dependency graph.

6. The method according to claim 3, characterized in that: The generating of test cases by using the API sequence includes: The API sequence is executed using a fuzzy driver to generate a test case for fuzz testing.

7. A browser access method, characterized in that: The method comprises: The local Web server receives the access request of the browser to the local external device; The local Web server provides the browser with a transfer API corresponding to the local external device based on the access request, so that the browser accesses the local external device through the transfer API; Wherein, the transit API is obtained by the method described in any one of claims 1-6.

8. An electronic device, characterized in that: The electronic device comprises a processor and a memory connected to the processor; the memory is used to store a computer program, and when the computer program is executed by the processor, it is used to implement the method according to any one of claims 1 to 7.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, it is used to implement the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Software code generation method and device, electronic equipment and storage medium

    CN118034670A

  • Method and device for automatically generating unit test based on thinking chain prompt

    CN118503125A