CN119045817B - API task demand processing and access method and related device for browser - Google Patents
API task demand processing and access method and related device for browser Download PDFInfo
- Publication number
- CN119045817B CN119045817B CN202411143371.5A CN202411143371A CN119045817B CN 119045817 B CN119045817 B CN 119045817B CN 202411143371 A CN202411143371 A CN 202411143371A CN 119045817 B CN119045817 B CN 119045817B
- Authority
- CN
- China
- Prior art keywords
- api
- code file
- dependency graph
- initial
- target
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/38—Creation or generation of source code for implementing user interfaces
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/957—Browsing optimisation, e.g. caching or content distillation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/30—Semantic analysis
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/33—Intelligent editors
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/35—Creation or generation of source code model driven
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/36—Software reuse
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N20/00—Machine learning
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Artificial Intelligence (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Medical Informatics (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Evolutionary Computation (AREA)
- Health & Medical Sciences (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Human Computer Interaction (AREA)
- Stored Programmes (AREA)
Abstract
The application discloses an API task demand processing method and an access method and related devices for a browser. The method comprises the steps of inputting the API task requirements into a large language model to obtain initial API code files output by the large language model, utilizing a parser to generate corresponding abstract syntax trees from the initial API code files, utilizing the abstract syntax trees to extract context information, establishing a hierarchical relationship, inputting the hierarchical relationship into the large language model again to obtain target API code files output by the large language model, and taking the target API code files as final API files corresponding to the API task requirements when the target API code files meet the API task requirements. By the method, the adaptation degree between the API code file and the API task requirement is improved.
Description
Technical Field
The application relates to the technical field of APIs, in particular to an API task demand processing method and an access method for a browser and a related device.
Background
Large Language Models (LLMs) have made significant progress in automatic code generation. However, integrating LLM-based code generation into an actual software project presents challenges.
Because the generated code may contain errors in API usage, class, data structure, or lack project specific information.
Disclosure of Invention
The API task demand processing method, the access method for the browser and the related device can improve the adaptation degree between the API code file and the API task demand and improve the logic accuracy of the API codes in the API code file.
The method comprises the steps of inputting API task requirements into a large language model to obtain initial API code files output by the large language model, generating corresponding abstract syntax trees by utilizing an analyzer, extracting context information by utilizing the abstract syntax trees to establish a hierarchical relationship, inputting the hierarchical relationship into the large language model again to obtain target API code files output by the large language model, and taking the target API code files as final API files corresponding to the API task requirements when the target API code files meet the API task requirements.
The method comprises the steps of extracting context information by using an abstract syntax tree, obtaining a query vector, calculating cosine similarity between the query vector and each context information, screening out optimal context information from the context information by using the cosine similarity, and establishing a hierarchical relationship by using the optimal context information.
When the target API code file meets the API task requirement, the target API code file is used as a final API file corresponding to the API task requirement, and the method comprises the steps of testing the target API code file, 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.
The method comprises the steps of determining a general API dependency graph based on an object API code file, carrying out uniqueness on the general API dependency graph to obtain an initial uniqueness API dependency graph, carrying out similarity pruning on the initial uniqueness API dependency graph to obtain a refined uniqueness API dependency graph, generating an API sequence according to the refined uniqueness API dependency, generating a test case by using the API sequence, and testing the object API code file by using the test case.
The method comprises the steps of carrying out unimodal on a general API dependency graph to obtain an initial unimodal API dependency graph, wherein the method comprises the steps of carrying out materialization on general API types 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, searching a path reaching an ending point API from the starting point API according to the starting point API, and obtaining the initial unimodal API dependency graph according to the path.
The method comprises the steps of carrying out similarity pruning on an initial single-state API dependency graph to obtain a refined single-state API dependency graph, wherein the step of obtaining the API dependency relationship in the initial single-state API dependency graph, and the step of removing the similar and redundant API dependency relationship to obtain the refined single-state API dependency graph.
The method for generating the test cases by using the API sequence comprises the steps of executing the API sequence by using a fuzzy driver to generate the test cases for fuzzy test.
The application provides a method for accessing a browser, which comprises the steps that a local Web server receives an access request of the browser to local external equipment, and provides a transfer API corresponding to the local external equipment for the browser based on the access request so that the browser accesses the local external equipment through the transfer API;
Wherein the staging API is obtained by a method as provided in the first aspect.
In a third aspect, the application provides an electronic device comprising a processor and a memory coupled to the processor, the memory for storing a computer program for implementing a method as provided in the first or second aspect when the computer program is executed by the processor.
In a fourth aspect, the present application provides a computer readable storage medium for storing a computer program for implementing a method as provided in the first or second aspect when the computer program is executed by a processor.
The method and the device for processing the API task requirements and accessing the browser have the advantages that the method and the device are different from the situation of the prior art, when an initial API code file corresponding to the API task requirements is output by a large language model, the initial API code file is generated into a corresponding abstract syntax tree by using a parser, context information is extracted by using the abstract syntax tree, a hierarchical relationship is built, the hierarchical relationship is input into the large language model again, a target API code file output by the large language model is obtained, when the target API code file meets the API task requirements, the target API code file is used as a final API file corresponding to the API task requirements, so that logic errors in the API code file output by the large language model are repaired through the iterative hierarchical relationship, the adaptation degree between the API code file and the API task requirements is improved, and the logic accuracy of the API codes in the API code file is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. Wherein:
FIG. 1 is a flow chart of an embodiment of a method for processing API task requirements according to the present application;
FIG. 2 is a flowchart of another embodiment of an API task demand processing method provided by the present application;
FIG. 3 is a flowchart illustrating another embodiment of an API task demand processing method according to the present application;
FIG. 4 is a flow chart of an embodiment of step 35 in FIG. 3;
FIG. 5 is a flow chart of an embodiment of step 352 of FIG. 4;
FIG. 6 is a flow chart illustrating an embodiment of step 353 in FIG. 3;
FIG. 7 is a flow chart of an embodiment of a method for browser access provided by the present application;
FIG. 8 is a schematic structural diagram of an embodiment of an electronic device according to the present application;
Fig. 9 is a schematic structural diagram of an embodiment of a computer readable storage medium provided by the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. It is to be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present application are shown in the drawings. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
Large Language Models (LLMs) have made significant progress in automatic code generation. However, integrating LLM-based code generation into an actual software project presents challenges.
Because the generated code may contain errors in API usage, class, data structure, or lack project specific information.
Based on the method, when the large language model outputs an initial API code file corresponding to the API task demand, a parser is utilized to generate a corresponding abstract syntax tree, context information is extracted by utilizing the abstract syntax tree, a hierarchical relationship is built, the hierarchical relationship is input 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 demand, the target API code file is used as a final API file corresponding to the API task demand, so that logic errors in the API code file output by the large language model are repaired through the iterative hierarchical relationship, the adaptation degree between the API code file and the API task demand is improved, and the logic accuracy of the API codes in the API code file is improved. Reference is made in detail to any one or combination of the following embodiments.
Referring to fig. 1, fig. 1 is a flowchart of an embodiment of an API task demand processing method according to the present application. The method comprises the following steps:
And step 11, inputting the API task requirements into the large language model to obtain an initial API code file output by the large language model.
In some embodiments, the large language model can automatically generate API codes according to API task requirements, thereby obtaining an initial API code file output by the large language model.
And step 12, generating a corresponding abstract syntax tree from the initial API code file by utilizing a parser.
It will be appreciated that there may be corresponding problems with the initial API code file. For example, merely entering a task requirement may cause the LLM to ignore item specific APIs, classes, data structures, or type information specific to the software item repository, potentially missing basic logic during code generation.
And 13, extracting context information by using the abstract syntax tree, and establishing a hierarchical relationship.
In some embodiments, the initial API code file is passed through a parser to generate an abstract syntax tree for representing the tree-like data structure of 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 brackets and semicolons, but focuses on the logical structure of the code. Each node in the tree represents a syntax element (e.g., operator, variable, function, etc.), and edges represent relationships between the nodes. The source code file is first broken down into tokens (tokens), such as keys, identifiers, operators, etc. And converting the symbol sequence into an abstract syntax tree according to the semantic search syntax rules. Abstract syntax trees are widely used in compiler and interpreter designs for operations such as syntax analysis, code generation, optimization, etc. If the fruit tree node is a child node of another node (e.g., function get_handle and class AsyncBolt), then an edge is created from the parent node to the child node, establishing a hierarchical relationship.
And 14, inputting the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model.
And inputting the hierarchical relationship into the large language model again for iteration, so as to obtain the target API code file output by the large language model. In the iterative process, the API codes are automatically generated again according to the hierarchical relationship and the API task requirements, and then the target API code file output by the large language model is obtained. If the target API code file meets the API task requirement, step 15 is executed. And if the target API code file does not meet the API task requirement, continuing iteration. After the large language model outputs the API code file, steps 12 to 14 are performed.
The number of specific iterations is set according to the actual requirements.
And step 15, when the target API code file meets the API task requirement, taking the target API code file as a final API file corresponding to the API task requirement.
In the embodiment, when the large language model outputs an initial API code file corresponding to the API task demand, a parser is utilized to generate a corresponding abstract syntax tree, context information is extracted by utilizing the abstract syntax tree, a hierarchical relationship is built, the hierarchical relationship is input 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 demand, the target API code file is used as a final API file corresponding to the API task demand, so that logic errors in the API code file output by the large language model are repaired through the iterative hierarchical relationship, the adaptation degree between the API code file and the API task demand is improved, and the logic accuracy of the API codes in the API code file is improved.
Referring to fig. 2, fig. 2 is a flowchart of another embodiment of an API task demand processing method according to the present application. The method comprises the following steps:
and step 21, inputting the API task requirements into the large language model to obtain an initial API code file output by the large language model.
And step 22, generating a corresponding abstract syntax tree from the initial API code file by utilizing a parser.
And 23, extracting context information by using the abstract syntax tree and acquiring a query vector.
And step 24, calculating cosine similarity between the query vector and each piece of context information.
And step 25, screening out the best context information from the context information by utilizing cosine similarity.
Semantic searching relies on techniques such as vector searching and machine learning. Vector search encodes searchable information into fields (vectors) of related terms or items, and then compares the vectors to determine the most similar content. Context cues are then used to determine the meaning of the words and return results 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 that is relevant to the actual meaning of the query.
Cosine similarity between the query vector and each context entry embedding vector is calculated and used to retrieve the most similar entry:
Generating a query vector, namely firstly, converting the query into an embedded vector and marking the embedded vector as hq;
The cosine similarity is calculated and then the cosine similarity between the query vector hq and each context entry embedding vector hc is calculated. Specifically, the cosine similarity is calculated by adopting the following formula:
where hq.hc represents the dot product of the vector, and |hq|| and |hc| represent the modular length of the vector, respectively.
Retrieving the most similar items, namely retrieving the first n items which are most similar to the query according to the calculated similarity.
And 26, establishing a hierarchical relationship by utilizing the optimal context information, extracting the context information by utilizing an abstract syntax tree, and establishing the hierarchical relationship.
And step 27, inputting the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model.
And 28, when the target API code file meets the API task requirement, taking the target API code file as a final API file corresponding to the API task requirement.
In the embodiment, when the large language model outputs an initial API code file corresponding to the API task demand, a parser is utilized to generate a corresponding abstract syntax tree, context information is extracted by utilizing the abstract syntax tree, a hierarchical relationship is built, the hierarchical relationship is input 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 demand, the target API code file is used as a final API file corresponding to the API task demand, so that logic errors in the API code file output by the large language model are repaired through the iterative hierarchical relationship, the adaptation degree between the API code file and the API task demand is improved, and the logic accuracy of the API codes in the API code file is improved.
Further, the cosine similarity between the query vector and each context entry embedded vector is calculated, and the similarity is used for searching the most similar entry, so that the context entry with higher similarity is selected, and the accuracy of the subsequent hierarchical relationship is improved.
Referring to fig. 3, fig. 3 is a flowchart illustrating another embodiment of an API task demand processing method according to the present application. The method comprises the following steps:
and step 31, inputting the API task requirements into the large language model to obtain an initial API code file output by the large language model.
And step 32, generating a corresponding abstract syntax tree from the initial API code file by utilizing a parser.
And step 33, extracting context information by using the abstract syntax tree, and establishing a hierarchical relationship.
And step 34, inputting the hierarchical relationship into the large language model again to obtain a target API code file output by the large language model.
Steps 31 to 34 have the same or similar technical schemes as any embodiment of the present application, and are not described here.
And 35, testing the target API code file, and taking the target API code file as a final API file corresponding to the API task requirement when the test result meets the API task requirement.
In some embodiments, referring to fig. 4, step 35 may be the following procedure:
step 351, determining the general API dependency graph based on the target API code file.
The generic API dependency graph is defined as a directed graph.
Step 352, the universal API dependency graph is unionized to obtain an initial unionized API dependency graph.
Wherein, the unistate API dependency graph has the following technical effects:
simplifying analysis and testing, namely reducing complexity caused by generalization through materializing types and APIs, so that analysis and testing are more direct and efficient.
And the coverage rate is improved, namely, in the testing process of fuzzy testing and the like, the single-state API dependency graph can help to generate more representative testing cases, and the test coverage rate is improved.
Redundancy is reduced, namely redundant information in the dependency graph is reduced through similarity pruning, so that the dependency relationship is clearer.
The specific application scene is as follows:
fuzzy test in the fuzzy test, a single-state API dependency graph is used for generating specific test cases, so that each case of the generic code can be ensured to be covered by the test.
Static analysis in a static analysis tool, the unimodal API dependency graph can help the analyzer to better understand code dependencies and identify potential errors and security vulnerabilities.
Performance optimization through unimodal, the compiler can generate more efficient codes, which is helpful for performance optimization.
In some embodiments, referring to fig. 5, step 352 may be the following procedure:
And step 51, materializing the general API types in the general API dependency graph to obtain an initial type API dependency graph.
Step 52, selecting an origin API from the initial type API dependency graph, and searching a path reaching the end API from the origin API according to the origin API.
An API is said to be reachable if each input in the API sequence satisfies any of the following conditions:
The type of this input is private.
The type of input is non-generic and there is a producer side to this input from any previous API in the API sequence.
The input type is generic, there is one specific type t, 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.
And step 53, obtaining an initial unistate API dependent graph according to the path.
In an application scenario, step 352 may be the following steps:
Constructing a unimodal API dependency graph, namely materializing the generic API and the type to generate a dependency graph containing all concrete type instances and APIs.
The starting point is determined by selecting one or more starting points, which may be a particular API, type instance, or entry point (e.g., main function) of the program.
Searching reachable nodes, namely starting from a starting point, and finding all reachable API nodes and type examples by traversing the dependency graph. This step may include Depth First Search (DFS), breadth First Search (BFS), etc. algorithms.
Processing constraints-during the search, type constraints and function constraints need to be processed to ensure that only eligible paths are considered.
The technical effect is that the reachable single-state API search has the following technical effects:
identifying call chains-which API and type instances are explicitly reachable after materialization-helps understand the call chains and execution paths of the program.
Auxiliary test-in the test process, test cases can be generated by using the reachable APIs, so that the test coverage to all practical possible code paths is ensured.
Optimizing code by identifying which APIs are actually reachable, code optimization can be performed, eliminating redundant or unlikely to be invoked code.
The specific application scene is as follows:
security analysis identifying reachable APIs helps to discover potential security vulnerabilities and attack paths when performing security analysis.
Performance analysis by analyzing reachable APIs and call chains, performance bottlenecks and optimization points can be found.
And in the automatic test generation tool, a reachable single-state API search result is utilized to generate representative test cases, so that the test coverage rate is improved.
And 353, performing similarity pruning on the initial unistate API dependency graph to obtain a refined unistate API dependency graph.
In some embodiments, referring to fig. 6, step 353 may be the following procedure:
Step 61, acquiring the API dependency relationship in the initial singlet API dependency graph.
And 62, removing similar and redundant API dependency relationships to obtain a refined singlet API dependency graph.
In an application scenario, similarity pruning is achieved by:
identifying similar nodes and edges by analyzing the attributes, labels and connection relations of the nodes and edges, and identifying parts with similar or same functions in the graph.
Merging or deleting similar parts, namely merging or deleting the nodes and edges with high similarity or redundancy, so as to simplify the structure of the graph. This may include the following operations:
And merging the nodes with similar functions into one node, and updating the connection relation of the related edges.
Redundant edges are deleted, duplicate or unnecessary edges are removed, and critical paths are reserved.
Updating the dependency relationship, namely recalculating and updating the dependency relationship in the graph after trimming, and ensuring the integrity and accuracy of the graph.
The similarity pruning has the following technical effects:
the structure of the graph is simplified, the number of nodes and edges is reduced, and the dependency graph is more concise and easy to understand.
The processing efficiency is improved, the complexity of analysis and calculation is reduced, and the calculation resources and time are saved.
And the readability of the result is enhanced, namely, the analysis result is clearer by removing redundant information, and the interpretation and the application are convenient.
And in the specific application scene, API dependency analysis, namely when analyzing the API dependency relationship, removing similar and redundant dependency paths, simplifying the dependency graph and helping a developer to better understand the relationship among the APIs.
And (3) automatic test generation, namely, when the test case is generated, the redundant test is reduced and the test efficiency is improved by trimming similar test paths.
Code optimization, namely identifying and eliminating redundant codes through similarity pruning when optimizing the code structure, and improving the code quality and performance.
Refining the singlet API dependency graph has the following technical effects:
Simplifying the graph structure, removing redundant and similar nodes and edges, so that the dependency graph is more concise and easy to understand.
The analysis efficiency is improved, the complexity of the graph is reduced, the consumption of computing resources and time is reduced, and the analysis and processing efficiency is improved.
And the readability of the result is enhanced, the dependency graph is clearer through refining, and the analysis result is easier to read and apply.
And in the specific application scenario, API dependency analysis, namely when analyzing API dependency relationship, a developer is helped to better understand the relationship and the dependency path between APIs by refining the dependency graph.
And (3) automatic test generation, namely, when the test case is generated, the redundant test is reduced by refining the dependency graph, and the test efficiency and the coverage rate are improved.
Code optimization, namely identifying and eliminating redundant codes by refining the dependency graph when optimizing the code structure, and improving the code quality and performance.
Step 354, generating an API sequence from the refined singlet API dependencies.
Step 355, generating test cases by using the API sequence.
And executing the API sequence by using the fuzzy driver to generate the test case for the fuzzy test.
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 sequence may be used to test the functionality, performance, and security of the system.
Detailed explanation
Input information including type information of the API, dependencies and interface documents.
The generation method comprises the following steps:
Model-based methods a model (e.g., a dependency graph, state machine, etc.) is used to generate possible API call sequences.
Based on a random method, an API call sequence is randomly generated, so that different call paths are ensured to be covered.
Heuristic method-generating API call sequence according to existing test experience and heuristic rule.
And (3) covering targets, namely ensuring that the generated API sequence can cover as many code paths and function points as possible so as to improve the comprehensiveness and effectiveness of the test.
The method has the technical effects that a large number of test cases can be automatically generated through API sequence generation, a wide code path and function points are covered, errors and holes in a system are effectively found, and the test efficiency and quality are improved.
Further, the API call sequence is tested by synthesizing and generating a fuzzy test library through a fuzzy driver.
Step 356, testing the target API code file with the test case.
In some embodiments, fuzzy driver synthesis refers to automatically generating a driver for performing a fuzzy test (fuzzing). Fuzzy testing is an automated testing technique that discovers vulnerabilities and errors in a system by inputting large amounts of random or semi-random data into the system.
Specifically, the input information includes API documents, dependencies, type information, and the like.
The generation method comprises a template method and an automation tool.
The template method uses predefined templates to generate fuzzy drivers, and the templates comprise common API calling modes and data input modes.
The automation tool automatically generates the fuzzy driver by using a special tool (such as AFL, libFuzzer).
The execution mode is that the fuzzy driver executes the generated API sequence and inputs random or semi-random data to test the robustness and safety of the system.
The method has the technical effects that the driver program for fuzzy test can be automatically generated through fuzzy driver synthesis, the robustness and the safety of the system are effectively tested, and potential loopholes and errors are found.
In practice, API sequence generation and fuzzy driver synthesis are often used in combination to maximize test coverage and the ability to find potential problems.
Generating an API call sequence, firstly, generating a call sequence which widely covers an API call path and interaction through an API sequence generation technology.
Synthesizing fuzzy drivers, then generating drivers for executing the API call sequences by fuzzy driver synthesis technology, and inputting random or semi-random data.
And finally, executing the generated API call sequence by using the synthesized fuzzy driver, and automatically testing the robustness and the safety of the system to find potential loopholes and errors.
In the embodiment, when the large language model outputs an initial API code file corresponding to the API task demand, a parser is utilized to generate a corresponding abstract syntax tree, context information is extracted by utilizing the abstract syntax tree, a hierarchical relationship is built, the hierarchical relationship is input 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 demand, the target API code file is used as a final API file corresponding to the API task demand, so that logic errors in the API code file output by the large language model are repaired through the iterative hierarchical relationship, the adaptation degree between the API code file and the API task demand is improved, and the logic accuracy of the API codes in the API code file is improved.
Further, a general API dependency graph is determined based on the target API code file, the general API dependency graph is unionized to obtain an initial unistate API dependency graph, similarity pruning is conducted on the initial unistate API dependency graph to obtain a refined unistate API dependency graph, an API sequence is generated according to the refined unistate API dependency, a test case is generated by the API sequence, the target API code file is tested by the test case, when the test result meets the API task requirement, the target API code file is used as a final API file corresponding to the API task requirement, and logic accuracy of the API code in the API code file and the degree of adaptation between the API code and the API task requirement are improved.
Referring to fig. 7, fig. 7 is a flowchart of an embodiment of a method for browser access provided by the present application. The method comprises the following steps:
And step 71, the local Web server receives an access request of the browser to the local external equipment.
And step 72, the local Web server provides the transit API corresponding to the local external equipment for the browser based on the access request, so that the browser accesses the local external equipment through the transit API.
Wherein the transfer API is obtained by a method as provided in any of the above embodiments.
In an application scenario, a local external device, such as a microscope, is connected. The Web service is run locally. And opening the browser to access a website, wherein a program in the website uses a transfer API provided by a Web service program, so that the magnification of a microscope and the like can be set through the browser. For example, in a remote diagnosis assisting process, a hospital needs to use a browser to share the view under the microscope so that a remote expert can perform diagnosis, and then needs to use the browser to access the local microscope.
In this embodiment, the transfer API is obtained by using the method provided in any one of the embodiments, so that the degree of adaptation between the transfer API and the local Web server and browser can be improved, and the logic accuracy of the API code in the transfer API can be improved.
Further, a Web server program is provided locally, by running the program, there is a Web server locally, and then the browser accesses the local Web server, and since the local Web server is a local program and the local program is capable of accessing any local external device, a relay API is provided through the local Web server, thereby realizing that the browser can access the local device.
Referring to fig. 8, fig. 8 is a schematic structural diagram of an embodiment of an electronic device according to the present application. The electronic device comprises a processor and a memory connected with the processor, wherein the memory is used for storing a computer program which is used for realizing the following method when being executed by the processor:
Inputting the API task requirements into a large language model to obtain an initial API code file output by the large language model, generating a corresponding abstract syntax tree by utilizing a parser, extracting context information by utilizing the abstract syntax tree, establishing 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, and taking the target API code file as a final API file corresponding to the API task requirements when the target API code file meets the API task requirements;
Or the local Web server receives an access request of the browser to the local external equipment, and provides a transfer API corresponding to the local external equipment for the browser based on the access request so that the browser accesses the local external equipment through the transfer API.
It will be appreciated that the computer program, when executed by a processor, is also operative to implement the method of any of the embodiments described above.
Referring to fig. 9, fig. 9 is a schematic structural diagram of an embodiment of a computer readable storage medium according to the present application. The computer readable storage medium is for storing a computer program which, when executed by a processor, is for implementing the method of:
Inputting the API task requirements into a large language model to obtain an initial API code file output by the large language model, generating a corresponding abstract syntax tree by utilizing a parser, extracting context information by utilizing the abstract syntax tree, establishing 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, and taking the target API code file as a final API file corresponding to the API task requirements when the target API code file meets the API task requirements;
Or the local Web server receives an access request of the browser to the local external equipment, and provides a transfer API corresponding to the local external equipment for the browser based on the access request so that the browser accesses the local external equipment through the transfer API.
It will be appreciated that the computer program, when executed by a processor, is also operative to implement the method of any of the embodiments described above.
In summary, the method and the related device for processing the API task requirements and accessing the browser provided by the application are characterized in that when the large language model outputs an initial API code file corresponding to the API task requirements, a parser is utilized to generate a corresponding abstract syntax tree from the initial API code file, context information is extracted by utilizing the abstract syntax tree, a hierarchical relationship is established, the hierarchical relationship is input 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, the target API code file is used as a final API file corresponding to the API task requirements, so that logic errors in the API code file output by the large language model are repaired through the iterative hierarchical relationship, the adaptation degree between the API code file and the API task requirements is improved, and the logic accuracy of the API codes in the API code file is improved.
Further, a Web server program is provided locally, by running the program, there is a Web server locally, and then the browser accesses the local Web server, and since the local Web server is a local program and the local program is capable of accessing any local external device, a relay API is provided through the local Web server, thereby realizing that the browser can access the local device.
In the several embodiments provided in the present application, it should be understood that the disclosed method and apparatus may be implemented in other manners. For example, the above-described device embodiments are merely illustrative, e.g., the division of the modules or units is merely a logical functional division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed.
The integrated units of the other embodiments described above may be stored in a computer readable storage medium if implemented in the form of software functional units and sold or used as stand alone products. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to execute all or part of the steps of the method according to the embodiments of the present application. The storage medium includes various media capable of storing program codes, such as a U disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, randomAccess Memory), a magnetic disk, or an optical disk.
The foregoing description is only of embodiments of the present application, and is not intended to limit the scope of the application, and all equivalent structures or equivalent processes using the descriptions and the drawings of the present application or directly or indirectly applied to other related technical fields are included in the scope of the present application.
Claims (9)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202411143371.5A CN119045817B (en) | 2024-08-20 | 2024-08-20 | API task demand processing and access method and related device for browser |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202411143371.5A CN119045817B (en) | 2024-08-20 | 2024-08-20 | API task demand processing and access method and related device for browser |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN119045817A CN119045817A (en) | 2024-11-29 |
| CN119045817B true CN119045817B (en) | 2025-07-01 |
Family
ID=93570792
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202411143371.5A Active CN119045817B (en) | 2024-08-20 | 2024-08-20 | API task demand processing and access method and related device for browser |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN119045817B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN120256281A (en) * | 2025-05-24 | 2025-07-04 | 江西师范大学 | API code optimization method, device and electronic device based on large language model |
Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN118034670A (en) * | 2024-02-26 | 2024-05-14 | 北京奇艺世纪科技有限公司 | Software code generation method, device, electronic device and storage medium |
| CN118503125A (en) * | 2024-05-30 | 2024-08-16 | 浙江大学 | Automatic unit test generation method and device based on thought chain prompt |
Family Cites Families (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JPH09160915A (en) * | 1995-12-07 | 1997-06-20 | Meidensha Corp | Contextual processing system for natural language |
| US10019285B2 (en) * | 2016-02-12 | 2018-07-10 | International Business Machines Corporation | Natural language conversation-based programming |
| US11893385B2 (en) * | 2021-02-17 | 2024-02-06 | Open Weaver Inc. | Methods and systems for automated software natural language documentation |
| US11656851B2 (en) * | 2021-10-22 | 2023-05-23 | Microsoft Technology Licensing, Llc. | Long-range modeling of source code files by syntax hierarchy |
| US11934801B2 (en) * | 2021-12-07 | 2024-03-19 | Microsoft Technology Licensing, Llc | Multi-modal program inference |
| US12197895B2 (en) * | 2021-12-16 | 2025-01-14 | International Business Machines Corporation | Dialogue- and machine learning-facilitated code development |
| CN115016793A (en) * | 2022-04-25 | 2022-09-06 | 中国平安人寿保险股份有限公司 | Syntax tree-based code generation method and device, electronic device, and storage medium |
| US20240126624A1 (en) * | 2022-10-14 | 2024-04-18 | International Business Machines Corporation | Automatically generating application programming interfaces |
| CN117608656A (en) * | 2023-11-13 | 2024-02-27 | 浙江大学 | A hybrid front-end framework migration method based on AST and LLM |
| CN118295640A (en) * | 2024-04-11 | 2024-07-05 | 河南旭方科技有限公司 | Software development management method based on artificial intelligence |
-
2024
- 2024-08-20 CN CN202411143371.5A patent/CN119045817B/en active Active
Patent Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN118034670A (en) * | 2024-02-26 | 2024-05-14 | 北京奇艺世纪科技有限公司 | Software code generation method, device, electronic device and storage medium |
| CN118503125A (en) * | 2024-05-30 | 2024-08-16 | 浙江大学 | Automatic unit test generation method and device based on thought chain prompt |
Also Published As
| Publication number | Publication date |
|---|---|
| CN119045817A (en) | 2024-11-29 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| Sager et al. | Detecting similar Java classes using tree algorithms | |
| US8566789B2 (en) | Semantic-based query techniques for source code | |
| Jiang et al. | An unsupervised approach for discovering relevant tutorial fragments for APIs | |
| US8533680B2 (en) | Approximating finite domains in symbolic state exploration | |
| CN111400724B (en) | Operating system vulnerability detection method, system and media based on code similarity analysis | |
| CN114692600B (en) | Method and system for formal language processing using subroutine graph | |
| JP7507564B2 (en) | Automatically finding the location of translated text in localized applications | |
| CN114969819A (en) | Data asset risk discovery method and device | |
| US11573790B2 (en) | Generation of knowledge graphs based on repositories of code | |
| Liu et al. | Parametric regular path queries | |
| Negrini et al. | Twinning automata and regular expressions for string static analysis | |
| Philippe et al. | Towards transparent combination of model management execution strategies for low-code development platforms | |
| CN119045817B (en) | API task demand processing and access method and related device for browser | |
| CN118094561A (en) | Code vulnerability detection method based on code attribute graph learning | |
| CN114003234A (en) | Small program partial compilation method, apparatus, device and computer-readable storage medium | |
| van Deursen et al. | Rapid system understanding: Two COBOL case studies | |
| Sowinski et al. | Ontology reuse: the real test of ontological design | |
| Bettini et al. | Supporting safe metamodel evolution with edelta | |
| CN117493169A (en) | A method, device, equipment and medium for detecting API behavior incompatibility between Java dependency library versions | |
| CN112445468A (en) | Typescript type file generation method, device, equipment and computer readable storage medium | |
| CN116541071A (en) | Application programming interface migration method based on prompt learning | |
| WO2022047623A1 (en) | Software information organization method and device, and computer-readable medium | |
| CN119621587A (en) | Generation method, test method, electronic device, storage medium and program product | |
| CN119179467A (en) | Artificial intelligence aided programming construction method | |
| Wang et al. | WheaCha: A method for explaining the predictions of models of code |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |