API structure generation method and device based on artificial intelligence, storage medium and program product
By generating API structures using an AI-based method, the problem of high labor costs caused by manually entering API structures in existing technologies is solved, achieving efficient and accurate API structure generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2026-03-13
AI Technical Summary
Existing API management platforms rely on users to manually enter API structures, resulting in high labor costs.
By employing an artificial intelligence-based approach, the API structure information is generated using a fine-tuned AI model after obtaining the call address and call data of the target API, thereby reducing reliance on manual operation.
It enables efficient and accurate generation of API structures, reducing the manpower costs of API management.
Smart Images

Figure CN121658104A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an API structure generation method, device, storage medium and program product based on artificial intelligence. Background Technology
[0002] With the continuous development of internet technology, APIs (Application Programming Interfaces) have become an indispensable part of modern software development. API management has become increasingly important during the development process. The emergence of API management platforms has made API management more convenient and efficient. Typically, API management platforms require users to manually input API structures according to the Open API Specification (OAS). However, existing API management platforms rely on users manually inputting API structures according to the OAS. This manual input method incurs high labor costs. Therefore, a new solution is needed. Summary of the Invention
[0003] This application provides several aspects of an AI-based API structure generation method, device, storage medium, and program product to reduce the human cost of API structure generation.
[0004] This application provides an AI-based API structure generation method, comprising: responding to a structure creation event of a target API and obtaining the call address of the target API; obtaining first call data when the target API is called based on the call address; and calling a target model to generate API structure information corresponding to the target API based on the first call data; wherein the target model is an AI model fine-tuned on a training dataset formed by API call data samples and API structure information samples.
[0005] Optionally, it further includes: outputting call prompt information corresponding to the target API, wherein the call prompt information is used to prompt the target API to be called according to different parameter information of the target API.
[0006] Optionally, obtaining the first call data when the target API is called based on the call address includes: calling an API gateway to detect the call operation of the target API based on the call address; and, when the call operation of the target API is detected, obtaining the request data and response data corresponding to the call operation; and obtaining the first call data based on the request data and the response data.
[0007] Optionally, based on the first call data, the target model is invoked to generate API structure information corresponding to the target API, including: generating a first prompt word based on the request data, the response data, and the API documentation specification; and inputting the first prompt word into the target model so that the target model outputs API structure information conforming to the API documentation standard based on the request data and the response data.
[0008] Optionally, after generating the API structure information corresponding to the target API by calling the target model, the method further includes: obtaining second call data when the target API is called based on the call address; if the second call data is different from the first call data, then updating the API structure information corresponding to the target API based on the second call data.
[0009] Optionally, updating the API structure information corresponding to the target API based on the second call data includes: determining whether the data structure corresponding to the second call data matches the data structure in the API structure information corresponding to the target API; if they do not match, generating a second prompt word based on the second call data; and inputting the second prompt word into the target model so that the target model modifies the API structure information corresponding to the target API based on the second call data.
[0010] Optionally, in the API structure information corresponding to the target API, the response status code and the response structure are recorded accordingly; updating the API structure information corresponding to the target API based on the second call data includes: extracting the response status code from the second call data; determining whether the API structure information corresponding to the target API contains the response structure corresponding to the response status code; if not, generating a third prompt word based on the second call data; and inputting the third prompt word into the target model so that the target model expands the response structure corresponding to the response status code in the API structure information corresponding to the target API based on the second call data.
[0011] Optionally, the API structure information corresponding to the target API includes: the API structure corresponding to the target API and the descriptive information associated with the API structure; wherein, the API structure information sample used to train the target model includes the descriptive information associated with the API structure information sample, so as to enable the artificial intelligence model to learn the knowledge of generating the API structure information sample and the descriptive information associated with the API structure information sample based on the API call data sample during the fine-tuning process.
[0012] This application embodiment also provides an AI-based API structure generation system, including: an API management device and a target model, wherein the target model is an AI model fine-tuned on a training dataset formed by API call data samples and API structure information samples; wherein, the API management device is used to: respond to a structure creation event of a target API and obtain the call address of the target API; obtain first call data when the target API is called according to the call address; and send a first call request to the target model according to the first call data; the target model is used to: respond to the first call request and generate API structure information corresponding to the target API.
[0013] Optionally, the system further includes: an API gateway; when the API management device obtains the first call data when the target API is called according to the call address, it is specifically configured to: send a second call request to the API gateway according to the call address; the API gateway is configured to: respond to the second call request, detect the call operation of the target API according to the call address; and, when the call operation of the target API is detected, obtain the request data and response data corresponding to the call operation; and return the request data and the response data as the first call data to the API management device.
[0014] This application also provides an electronic device, including: a memory and a processor; the memory is used to store one or more computer instructions; the processor is used to execute the one or more computer instructions to perform the steps in the method provided in this application.
[0015] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can implement the steps in the method provided in this application.
[0016] This application also provides a computer program product, including: a computer program / instructions, which, when executed by a processor, can implement the steps in the method provided in this application.
[0017] In the AI-based API structure generation method provided in this application embodiment, in response to the structure creation event of the target API, the call address of the target API can be obtained, and based on the call address, the first call data when the target API is called can be obtained. Based on the first call data, the target model can be invoked to generate the API structure information corresponding to the target API. The target model is an AI model fine-tuned on a training dataset formed by API call data samples and API structure information samples. Therefore, the target model has strong processing performance for API structure generation tasks, enabling it to accurately and efficiently generate API structures based on the input call data. Furthermore, in API management scenarios, the reliance on manual operations for entering API structures is reduced, effectively lowering the labor costs required for API management. Attached Figure Description
[0018] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0019] Figure 1 A flowchart illustrating an AI-based API structure generation method provided for an exemplary embodiment of this application;
[0020] Figure 2 A schematic diagram of an API management interface provided for an exemplary embodiment of this application;
[0021] Figure 3 A schematic diagram of an API structure generation system including an API management device and an API gateway, provided for an exemplary embodiment of this application;
[0022] Figure 4 A schematic diagram of the structure of an electronic device provided for an exemplary embodiment of this application. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0024] The terminology used in the embodiments of this invention is for the purpose of describing particular embodiments only and is not intended to limit the invention. The singular forms “a,” “the,” and “the” used in the embodiments of this invention and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. “Multiple” generally includes at least two, but does not exclude the inclusion of at least one.
[0025] It should be understood that the term "and / or" used in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.
[0026] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a product or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a product or system. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the product or system that includes said element.
[0027] In the process of generating OAS documents, schema generation is a crucial step. A schema is a way to define data structures used in API requests and responses, specifying the data format used. Schemas use JSON (JavaScript Object Notation) or XML (eXtensible Markup Language) to describe the structure and constraints of data objects, including data types (such as strings, integers, booleans), object properties, arrays, enumeration values, and rules regarding required fields. Through schemas, the specific shape and validation rules of data in API interactions can be precisely defined, ensuring data consistency in API calls and the readability of OAS documents.
[0028] In API management scenarios, some API management platforms rely on users to manually enter API structures according to open API specifications and then generate schemas based on these manually entered API structures. This approach requires the API management platform to provide robust and complex data structure definition capabilities, enabling users to meticulously define various request and response data structures within the API structure, thereby generating OAS documents. This method places high demands on the API management platform's development, and the diversity of API structures necessitates tedious and complex manual work to enter different APIs, resulting in high labor costs.
[0029] Some API structure generation schemes use hard coding to analyze the response structure and generate the data structure in the schema based on the analysis results. However, this method is inflexible; when the API response structure changes, the code needs to be manually updated to adapt to these changes, making this method still labor-intensive.
[0030] To address the aforementioned technical problems, a solution is provided in some embodiments of this application. The technical solutions provided by each embodiment of this application are described in detail below with reference to the accompanying drawings.
[0031] Figure 1 This is a flowchart illustrating an exemplary embodiment of an AI-based API structure generation method provided in this application. The method may include, for example: Figure 1 The steps shown are as follows:
[0032] Step 101: Respond to the structure creation event of the target API and obtain the call address of the target API.
[0033] Step 102: Obtain the first call data when the target API is called based on the call address.
[0034] Step 103: Based on the first call data, call the target model to generate the API structure information corresponding to the target API; the target model is an artificial intelligence model fine-tuned on the training dataset formed by the API call data samples and the API structure information samples.
[0035] This embodiment can be executed by an API management device, which can run on a terminal device or a server, or a portion of the API management device can not run on a terminal device while another portion runs on a server; this embodiment does not impose any restrictions. The server can be a conventional server, a cloud server, a virtual machine, a cloud computing instance, etc.; this embodiment does not impose any restrictions.
[0036] In step 101, the target API refers to any API of the structure to be created. This API is a set of rules, protocols, and tools that define how software components interact, specifying how to request API services, transmit data formats, and respond to requests, enabling different software components or services to communicate and collaborate. API services typically refer to backend services running on a server, providing specific functions or data and exposing them through the API for clients or other services to call.
[0037] The target API's structure creation event can be a user event or a system event. A user event is an event directly triggered by a user's interaction. User interactions can be initiated through a human-machine interface provided by the API management device. This human-machine interface can include at least one of the following: command-line interface (CLI), graphical user interface (GUI), text user interface (TUI), voice user interface (VUI), touch user interface (TUI), gesture user interface (Gestural UI), keyboard and mouse interface, natural language processing (NLP) interface, sensors, and hardware controllers.
[0038] In some alternative embodiments, the API management device may display an API management interface through an API console and provide users with an interface for creating API structures through the API management interface. Figure 2 The API management interface displayed in the API console is illustrated below, such as... Figure 2 As shown, the API management interface can display API name input controls, API protocol selection controls, and call address (Base Path) input controls, so as to obtain the name of the target API, the protocol type used, and the call address based on the above controls.
[0039] System events refer to events automatically generated by the operating system or other software components. System events may include, but are not limited to: timer expiration events, events of receiving specific communication messages from other processes / applications, API management interface call events provided by API management devices, etc., and will not be listed in detail here.
[0040] In step 101, the API call address refers to the URL (Uniform Resource Locator) used by the API caller (e.g., a client) when requesting API services over the network. This URL points to the service or resource provided by the API. Typically, the call address consists of a protocol, a domain name or IP (Internet Protocol) address, a port, a path, and query parameters. The protocol specifies the communication protocol between the API caller and the server providing the API service; for example, it could be HTTP (Hypertext Transfer Protocol) or HTTPS (Hypertext Transfer Protocol Secure). The domain name or IP address specifies the address of the server providing the API service. The port specifies the port number on the server that listens for connections; for example, port 80 for HTTP and port 443 for HTTPS. The path specifies the specific resource or service requested. Query parameters are an optional component of the API, used to provide additional information to the API.
[0041] In step 101, the call address of the target API obtained by the API management device can be input by the user or obtained by the API management device based on the name or identifier of the target API. For example, in some embodiments, the API management device can respond to the structure creation event of the target API, obtain the identifier of the target API, and obtain the call address of the target API from a specified database based on the identifier of the target API. Optionally, the specified database is used to store the correspondence between API identifiers and call addresses of different APIs. The specified database can be located on the device where the API management device is located, or it can be located on a remote device (e.g., a cloud server) corresponding to the API management device. This embodiment does not impose any restrictions.
[0042] After obtaining the call address of the target API, in step 102, the API management device can obtain the first call data when the target API is called based on the call address.
[0043] In some optional embodiments, the API management device may further output call prompt information corresponding to the target API, which is used to prompt the target API to be called according to different parameter information of the target API.
[0044] Optionally, the call prompt information can be output through the API management interface. In this implementation, after obtaining the API call address, the API management device can access the call address to obtain the API input parameters, and can then, based on the API input parameters, [further details about the API's input parameters are needed]. Figure 2 The illustrated API management interface displays prompts, such as: "Please call the target API using as many input parameters as possible." This implementation prompts users to use different input parameters to call the target API, ensuring that the API calls cover real-world scenarios as comprehensively as possible. This facilitates obtaining more accurate call data and ultimately generates a more accurate API structure.
[0045] In some optional embodiments, when the API management device obtains the first call data when the target API is called based on the call address, it may employ an API gateway. This gateway detects the call operation of the target API based on the call address and, upon detecting the call operation, obtains the request data and response data corresponding to that call operation. The API management device can then obtain the first call data based on the request data and the response data.
[0046] Figure 3 An illustration of an API structure generation system, including an API management device and an API gateway, is provided, such as... Figure 3 As shown, an API gateway is an intermediary layer located between the API caller and the API service, serving as a single entry point for handling requests to the API service. Figure 3 As shown, the API gateway can receive API call requests for API services from API callers, route the request data corresponding to the call request to the corresponding API service, and return the response data returned by the API service to the API caller.
[0047] like Figure 3 As shown, after obtaining the call address of the target API, the API management device can provide the call address to the API gateway. Upon receiving the call address, if the API gateway receives a call request from the API caller for the API service corresponding to that call address, the API gateway can record the request data when the API service is called. If it receives response data from the API service corresponding to that call address in response to the call request, the API gateway can record that response data. The API gateway can use the request data and response data corresponding to the call request as the first call data and provide the first call data to the API management device. The term "first" is used here to define the call data, solely for ease of description and to distinguish it from other call data mentioned later; it is not intended to limit the quantity or order of receiving call data.
[0048] The request data typically includes information required for the API call, such as the HTTP method (GET, POST, PUT, DELETE, etc.), URL, header information (e.g., authentication token, content type), and body (request body, used for POST, PUT, etc.). The response data typically includes a response header and a response body. The response header contains metadata, such as the response status code, date, and server type, while the response body contains the actual data or message.
[0049] The API structure defines the API's functionality and interaction methods, while request and response data are the specific content that implements these functionalities. Therefore, in this embodiment, using the request and response data generated when the API is invoked as the first invocation data to generate the API structure helps to obtain more complete API structure information.
[0050] Furthermore, in this implementation, based on the API gateway, the call data corresponding to the target API can be obtained without intruding on the API service corresponding to the target API or the API caller that initiated the API call, thereby reducing the impact on the API service and the API caller.
[0051] It should be noted that, in addition to the API gateway, the API management device can also utilize a lightweight API agent to obtain the first call data when the target API is invoked based on the call address of the target API. This embodiment does not impose any limitations. The API agent can be used to intercept HTTP / HTTPS requests and responses to the target API and obtain the first call data based on the intercepted requests and responses.
[0052] Of course, in addition to API gateways and API proxies, middleware or logging components can also be configured on the server where the API service is located to record the request and response data when the target API is called.
[0053] After obtaining the first call data based on the above implementation method, in step 103, the target model can be invoked to generate the API structure information corresponding to the target API based on the first call data. The API structure information corresponding to the target API can be recorded in a document (e.g., an OAS document) for later reading or use.
[0054] In this embodiment, the target model is an artificial intelligence model fine-tuned on a training dataset formed by API call data samples and API structure information samples. This artificial intelligence model can be a Large Language Model (LLM).
[0055] Large language models (MLMs) are naturally language processing (NLP) models trained on massive scales. Typically built on deep learning techniques and trained on large training datasets, they exhibit powerful performance in NLP tasks. The number of parameters in a large MLM exceeds a predetermined threshold, usually in the millions or billions. Before fine-tuning, the MLM is pre-trained on a large pre-training dataset, learning rich and general feature representations and content generation knowledge. Fine-tuning the pre-trained MLM using a training dataset composed of API call data samples and API structure information samples allows the prior knowledge and generalization ability learned during pre-training to be transferred to the API structure information generation task. This enables the fine-tuned MLM to accurately generate API structure information based on API call data.
[0056] It should be noted that the API structure information samples in the training dataset used for fine-tuning the artificial intelligence model are API structure information samples that conform to the defined API documentation specifications. These samples are used to enable the artificial intelligence model to learn and generate API structure information that conforms to the defined API documentation specifications during the fine-tuning process. The API documentation specifications may include: OAS specifications, API Blueprints, or AsyncAPI standards, etc., and this embodiment does not impose any limitations.
[0057] Accordingly, in some optional embodiments, when the API management device calls the target model to generate the API structure information corresponding to the target API based on the first call data, it generates a first prompt based on the request data, the response data, and the API documentation specification. The API documentation specification can be an OAS specification, an API Blueprint, or an AsyncAPI. For example, the first prompt could be: "Please refer to the following request data and response data to write an API structure that conforms to the OAS specification. Request data = {xxx}, Response data = {xxx}." This first prompt is input into the target model so that the target model outputs the API structure information corresponding to the target API based on the request data and response data.
[0058] In this implementation, the API management device can complete the task of generating API structure information by constructing the first prompt word and calling the target model, which reduces the reliance on manually writing API structure information and the need for manually writing API parsing logic, thereby reducing development costs and time costs.
[0059] In this embodiment, in response to the target API's structure creation event, the call address of the target API can be obtained, and based on this call address, the first call data when the target API is called can be obtained. Based on the first call data, the target model can be invoked to generate the API structure information corresponding to the target API. The target model is an artificial intelligence model fine-tuned on a training dataset formed by API call data samples and API structure information samples. Therefore, this target model has strong processing performance for API structure generation tasks, enabling it to accurately and efficiently generate API structures based on the input call data. Furthermore, in API management scenarios, the reliance on manual operations for entering API structures is reduced, effectively lowering the labor costs required for API management.
[0060] In some optional embodiments, the API management device can continuously record the call data of the target API and continuously update the API structure information. Optionally, after the target model generates the API structure information corresponding to the target API, the API management device can obtain the second call data when the target API is called based on the call address. If the second call data is different from the first call data, the API structure information corresponding to the target API can be updated based on the second call data. The second call data refers to the incremental call data generated by the call operation on the target API after obtaining the first call data. The second call data can be used to supplement or modify the first call data.
[0061] Accordingly, updating the API structure information corresponding to the target API may include modifying the API structure information or expanding the API information. The following will provide specific explanations based on different implementation methods.
[0062] In some optional Example A In this process, when the API management device updates the API structure information corresponding to the target API based on the second call data, it can determine whether the data structure corresponding to the second call data matches the data structure in the API structure information corresponding to the target API. The data structure may include variable types, variable organization methods, etc. Specifically, the API management device can compare the variable types and variable organization methods in the second call data with those in the API structure information corresponding to the target API. If the comparison results for variable types are inconsistent and / or the variable organization methods are inconsistent, it is determined that the data structure corresponding to the second call data does not match the data structure in the structure information corresponding to the target API. If the comparison results for variable types are consistent and the variable organization methods are consistent, it is determined that the data structure corresponding to the second call data matches the data structure in the structure information corresponding to the target API.
[0063] If there is a mismatch, the API management device can update the API structure information corresponding to the target API based on the second call data.
[0064] In some optional Example A1 In this system, the API management device can update the API structure information corresponding to the target API through human-computer interaction. Specifically, the API management device can generate a comparison result between the data structure in the second call data and the data structure in the API structure information corresponding to the target API, and output the comparison result. Optionally, the comparison result can be displayed on the user interface provided by the API management device, allowing the user to modify the data structure in the API structure information corresponding to the target API based on the comparison result. If a user's modification operation on the data structure in the API structure information corresponding to the target API is detected, the modification result can be obtained, and the API structure information corresponding to the target API can be updated based on the modification result.
[0065] In some other options Example A2 In this process, the API management device can call the target model to update the API structure information corresponding to the target API. Specifically, the API management device can generate a second prompt word based on the second call data and input the second prompt word into the target model, so that the target model can modify the API structure information corresponding to the target API based on the second call data. For example, the second prompt word could be: Please modify the API structure information corresponding to the target API based on the second call data.
[0066] Based on this implementation method, the API structure information of the new version can be obtained in a timely manner when the API changes, thereby improving the timeliness of API structure information during API iteration or updates.
[0067] In some optional Example B In the process, when the API management device updates the API structure information corresponding to the target API based on the second call data, it can expand the response structure corresponding to the response status code in the API structure information corresponding to the target API. This will be explained in detail below.
[0068] In the API structure information corresponding to the target API, response status codes and response structures are recorded in a corresponding manner. The response status code is part of the HTTP protocol and is used to indicate the result of a client request. Response status codes are typically three-digit codes, divided into different categories, each representing a different response type. For example, response status codes in the format "1xx" are informational status codes, indicating that the request has been received by the server, but further action is required to complete the request. Response status codes in the format "2xx" are success status codes, indicating that the request has been successfully received, understood, and accepted by the server; for example, the response status code 200 OK indicates that the request has been successfully processed. Response status codes in the format "3xx" are redirection status codes, indicating that further action is required from the client to complete the request, usually involving redirection. For example, the response status code 301 Moved Permanently indicates that the requested resource has been permanently moved to a new location. In addition to the above formats, response status codes in the formats "4xx" and "5xx" may also be included, but will not be listed here.
[0069] In OAS, responses are described using the `responses` keyword. Each response status code has a corresponding key-value pair, where the key is the HTTP response status code (e.g., 200 OK), and the value is a response object describing the response behavior under that status code. This response object may include at least one of the following fields: a `description` field to describe the response information under that status code, a `content` field to describe the response's data structure, a `headers` field to define the response headers, a `links` field to describe the links between the response and other operations, and an `examples` field to provide examples of the response, etc.
[0070] Different HTTP response status codes typically represent different processing logic or error conditions. Therefore, in the OAS specification, different response status codes may have different response structures. Based on this, when the target model generates API structure information corresponding to the target API based on the first call data, it can identify the response status code from the response data in the first call data, generate the response structure based on the response data, and output the corresponding response status code and response structure. For example, the API structure information of the target API may include: {first request structure; first response status code: first response structure; second response status code: second response structure}.
[0071] Accordingly, when updating the API structure information corresponding to the target API based on the second call data, the API management device can extract the response status code from the second call data and determine whether the API structure information corresponding to the target API contains the response structure corresponding to the response status code. Optionally, if the API structure information corresponding to the target API contains the response structure corresponding to the response status code, then there is no need to perform the operation of updating the API structure information based on the second call data. If it does not contain it, a third prompt word can be generated based on the second call data, and the third prompt word can be input into the target model so that the target model can expand the response structure corresponding to the response status code in the API structure information corresponding to the target API based on the second call data.
[0072] For example, the response status code in the second call data is the third response status code, and the response structure corresponding to the third response status code is not recorded in the API structure information of the target API. After generating a third prompt based on the second call data and inputting this third prompt into the target model, the target model can output the following expanded API structure information: {First request structure; First response status code: First response structure; Second response status code: Second response structure; Third response status code: Third response structure}.
[0073] Based on this implementation method, the API structure information can be expanded in a timely manner according to the incremental call data during the process of the target API being called, which facilitates the continuous improvement of the API structure information.
[0074] The foregoing embodiments describe an implementation method in which an API management device can call a target model to generate API structure information. It is worth noting that in some optional embodiments, the API structure information generated by the target model may further include: descriptive information associated with the API structure, which is used to improve the readability and usability of the API structure information. Exemplary examples will be provided below.
[0075] In some optional embodiments, during the process of fine-tuning the artificial intelligence model on the training dataset to obtain the target model, when constructing API structure information samples in the training dataset, descriptive information associated with the API structure information samples can be added to the API structure information samples.
[0076] The description information may include at least one of the following: a general description of the API, a path-level description, a request body description, a response description, error handling methods, and authentication and authorization information. The general API description may include: a brief introduction to the API, the current API version number, the license agreement used by the API, and definitions of specific terms used in the API. The path-level description may include: a brief description of the endpoint functionality, the HTTP methods supported by the path (e.g., GET, POST, etc.), descriptions of path parameters, parameters in the URL query string and their meanings, etc. The request body description may include: the data format of the request body (e.g., JSON, XML, etc.), parameters in the request body and their instance values, etc. The response description may include: the data format of the response, possible HTTP status codes and their meanings, fields in the response body and their meanings, etc. Error handling methods may include: definitions of error codes, examples of error responses, etc. Authorization information may include: the authentication methods used by the API, the scope of permissions required to access the API, examples of authentication requests, etc., and will not be listed exhaustively.
[0077] Optionally, descriptive information associated with the API structure information sample can be added to the API structure information sample through human-computer interaction. Specifically, the API structure information sample can be provided to relevant technical personnel, who can then add the aforementioned descriptive information as comments to the API structure information.
[0078] Based on the aforementioned API structure information sample, during the fine-tuning of the artificial intelligence model, the model can learn to generate the API structure information sample and the associated descriptive information based on the API call data sample. Furthermore, after inputting the first prompt word corresponding to the first call data into the target model, the API structure information output by the target model can include: the API structure corresponding to the target API and the associated descriptive information.
[0079] In this implementation, when constructing API structure information samples, descriptive information associated with the API structure is added to the samples. This allows the target model to automatically generate API structure information with descriptive information, thereby improving the readability of the API structure information. When the generated API structure information is used to generate API documentation, the descriptive information in the API structure information can be directly reused, reducing the technical and time costs required to annotate the API structure information and greatly improving the usability of the API structure information.
[0080] It's also worth noting that during the fine-tuning of the AI model on the training dataset to obtain the target model, the collected API structure information samples can be optimized according to the target API structure practices when constructing the API structure information samples in the training dataset. The target API structure practices refer to a set of best practices and guidelines followed when designing APIs to improve their usability, consistency, and maintainability. For example, taking the RESTful (Representational State Transfer) style of API design as an example, this style requires APIs to have a consistent URL structure, clear naming conventions, semantic HTTP status codes, and backward compatibility.
[0081] In some optional embodiments, when optimizing the collected API structure information samples according to the target practice style of API structure, a human-computer interaction method can be used to provide the design requirements of the target practice style of API structure and the API structure information samples to relevant technical personnel, who can then optimize the API structure information samples according to the design requirements of the target practice style. This will not be elaborated further.
[0082] In some alternative embodiments, when optimizing the collected API structure information samples according to the target practice style of the API structure, sample optimization prompts can be constructed based on the design requirements of the target practice style of the API structure and the API structure information samples, and these prompts can be input into the large language model. The large language model can then perform the task of optimizing the API structure information samples according to the design requirements of the target practice style based on the sample optimization prompts, and output the optimized API structure information samples. Subsequently, the large language model can be fine-tuned using sample pairs formed by the API call data samples and the optimized API structure information samples.
[0083] Based on this implementation method, by optimizing the API structure information samples, the target model can generate a higher quality API structure, thereby further improving the reliability, ease of understanding and integration of the API structure information.
[0084] Of course, in some alternative embodiments, instead of training the AI model to generate API structure information that conforms to the target practice style by optimizing API structure information samples, the fine-tuned target model can generate API structure information that conforms to the target practice style by adding prompts corresponding to the target practice style to the first prompt. That is, the first prompt can be: Please refer to the request data and response data to write an API structure that conforms to the OAS specification and RESTful style.
[0085] Based on this implementation method, the target model can intelligently complete missing information or optimize the description of API structure information according to the learned knowledge and the prompts of the target practice style, thereby improving the quality of OAS documents.
[0086] In addition to the aforementioned method embodiments, this application also provides an artificial intelligence-based API structure generation system, which may include: an API management device and a target model.
[0087] The API management device may run on a terminal device or on a server, or part of the API management device may not run on a terminal device while another part runs on a server; this embodiment does not impose any restrictions. The server may be a conventional server, a cloud server, a virtual machine, a cloud computing instance, etc.; this embodiment does not impose any restrictions.
[0088] The target model is an artificial intelligence model fine-tuned on a training dataset composed of API call data samples and API structure information samples. The target model can run on the device where the API management device is located, or on a remote server, which can be a cloud server.
[0089] In this system, the API management device is used to: respond to the structure creation event of the target API, obtain the call address of the target API, and obtain the first call data when the target API is called based on the call address. Based on the first call data, a first call request can be sent to the target model. The target model is used to: respond to the first call request and generate the API structure information corresponding to the target API.
[0090] Optionally, the system also includes: an API gateway, which is an intermediary layer located between the API caller and the API service, such as... Figure 3 As shown. Accordingly, when the API management device obtains the first call data when the target API is called based on the call address of the target API, it can send a second call request to the API gateway based on the call address. The API gateway is used to: respond to the second call request, detect the call operation of the target API based on the call address; and, when the call operation of the target API is detected, obtain the request data and response data corresponding to the call operation, and return the request data and response data as the first call data to the API management device.
[0091] Based on this system, the API management device can accurately and efficiently generate API structures using the target model. Furthermore, in API management scenarios, it reduces the reliance on manual input of API structures, effectively lowering the labor costs required for API management.
[0092] It should be noted that the execution subject of each step of the method provided in the above embodiments can be the same device, or the method can be executed by different devices. For example, the execution subject of steps 101 to 104 can be device A; or the execution subject of steps 101 and 102 can be device A, and the execution subject of step 103 can be device B; and so on.
[0093] Furthermore, some processes described in the above embodiments and accompanying drawings include multiple operations appearing in a specific order. However, it should be clearly understood that these operations may not be executed in the order they appear herein, or they may be executed in parallel. The operation numbers, such as 101, 102, etc., are merely used to distinguish different operations and do not represent any execution order. Additionally, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel. It should be noted that the descriptions such as "first" and "second" in this document are used to distinguish different messages, devices, modules, etc., and do not represent a sequential order, nor do they limit "first" and "second" to different types.
[0094] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0095] Figure 4 This application illustrates a schematic diagram of the structure of an electronic device provided in an exemplary embodiment, as shown below. Figure 4 As shown, the electronic device includes: a memory 401, a processor 402, and a communication component 403.
[0096] Memory 401 is used to store computer programs and can be configured to store various other data to support operation on the electronic device. Examples of this data include instructions for any application or method used to operate on the electronic device.
[0097] The processor 402, coupled to the memory 401, is used to execute a computer program in the memory 401 for: responding to a structure creation event of a target API and obtaining the call address of the target API; obtaining first call data when the target API is called based on the call address; and calling a target model to generate API structure information corresponding to the target API based on the first call data; wherein the target model is an artificial intelligence model fine-tuned on a training dataset formed by API call data samples and API structure information samples.
[0098] Optionally, the processor 402 is further configured to: output call prompt information corresponding to the target API, the call prompt information being used to prompt the target API to be called according to different parameter information of the target API.
[0099] Optionally, when the processor 402 obtains the first call data when the target API is called based on the call address, it is specifically configured to: call the API gateway to detect the call operation of the target API based on the call address; and, when the call operation of the target API is detected, obtain the request data and response data corresponding to the call operation; and obtain the first call data based on the request data and the response data.
[0100] Optionally, when the processor 402 calls the target model to generate API structure information corresponding to the target API based on the first call data, it is specifically used to: generate a first prompt word based on the request data, the response data, and the API documentation specification; and input the first prompt word into the target model so that the target model outputs API structure information that conforms to the API documentation standard based on the request data and the response data.
[0101] Optionally, after the processor 402 generates the API structure information corresponding to the target API by calling the target model, it is further configured to: obtain the second call data when the target API is called according to the call address; if the second call data is different from the first call data, update the API structure information corresponding to the target API according to the second call data.
[0102] Optionally, when the processor 402 updates the API structure information corresponding to the target API based on the second call data, it specifically performs the following steps: determining whether the data structure corresponding to the second call data matches the data structure in the API structure information corresponding to the target API; if they do not match, generating a second prompt word based on the second call data; and inputting the second prompt word into the target model so that the target model modifies the API structure information corresponding to the target API based on the second call data.
[0103] Optionally, in the API structure information corresponding to the target API, the response status code and the response structure are recorded accordingly; when the processor 402 updates the API structure information corresponding to the target API based on the second call data, it is specifically used to: extract the response status code from the second call data; determine whether the API structure information corresponding to the target API contains the response structure corresponding to the response status code; if not, generate a third prompt word based on the second call data; input the third prompt word into the target model, so that the target model expands the response structure corresponding to the response status code in the API structure information corresponding to the target API based on the second call data.
[0104] Optionally, the API structure information corresponding to the target API includes: the API structure corresponding to the target API and the descriptive information associated with the API structure; wherein, the API structure information sample used to train the target model includes the descriptive information associated with the API structure information sample, so as to enable the artificial intelligence model to learn the knowledge of generating the API structure information sample and the descriptive information associated with the API structure information sample based on the API call data sample during the fine-tuning process.
[0105] Furthermore, such as Figure 4 As shown, the electronic device also includes other components such as a power supply component 404, a display component 405, and an audio component 406. Figure 4 The diagram only shows some components and does not mean that the electronic device includes only these components. Figure 4 The components shown. Figure 4 In this embodiment, the components within the dashed boxes are optional, not mandatory, and their specific requirements depend on the product form of the electronic device. The electronic device in this embodiment can be a terminal device such as a desktop computer, laptop computer, smartphone, or IoT device, or a server-side device such as a conventional server, cloud server, or server array. If the electronic device in this embodiment is a terminal device such as a desktop computer, laptop computer, or smartphone, it may include... Figure 4 The components within the dashed box; if the electronic device in this embodiment is implemented as a conventional server, cloud server, or server array, etc., it may be omitted. Figure 4 The component within the dashed box.
[0106] The memory 401 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random-access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.
[0107] The communication component 403 is configured to facilitate wired or wireless communication between the device containing the communication component and other devices. The device containing the communication component can access wireless networks based on communication standards, such as Wi-Fi, 2G (e.g., Global System for Mobile Communications (GSM)), 3G (e.g., Wideband Code Division Multiple Access (WCDMA), 4G (e.g., Long Term Evolution (LTE)), 4G+ (e.g., LTE-Advanced (LTE-A)), or 5G (5th Generation Mobile Communication Technology), or combinations thereof. In one exemplary embodiment, the communication component receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, the communication component may be implemented based on Near Field Communication (NFC), Radio Frequency Identification (RFID), Infrared Data Association (IrDA), Ultra Wide Band (UWB), Bluetooth (BT), and other technologies.
[0108] The power supply component 404 is used to provide power to various components of the device in which the power supply component is located. The power supply component may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which the power supply component is located.
[0109] The display component includes a screen, which may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touchscreen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation.
[0110] An audio component may be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC) configured to receive external audio signals when the device containing the audio component is in an operating mode, such as call mode, recording mode, or voice recognition mode. The received audio signals may be further stored in memory or transmitted via a communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals.
[0111] In this embodiment, in response to the target API's structure creation event, the call address of the target API can be obtained, and based on this call address, the first call data when the target API is called can be obtained. Based on the first call data, the target model can be invoked to generate the API structure information corresponding to the target API. The target model is an artificial intelligence model fine-tuned on a training dataset formed by API call data samples and API structure information samples. Therefore, this target model has strong processing performance for API structure generation tasks, enabling it to accurately and efficiently generate the API structure based on the input call data. Furthermore, in API management scenarios, the reliance on manual operations for entering API structures is reduced, effectively lowering the labor costs required for API management.
[0112] Accordingly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed, can implement the steps that can be performed by an electronic device in the above method embodiments.
[0113] This application also provides a computer program product, including: a computer program / instructions, which, when executed by a processor, can implement the steps in the method provided in this application.
[0114] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM (Compact Disc Read-Only Memory), optical storage, etc.) containing computer-usable program code.
[0115] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0116] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0117] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0118] In a typical configuration, a computing device includes one or more processors (Central Processing Unit, CPU), input / output interfaces, network interfaces, and memory.
[0119] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0120] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, Digital Video Disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0121] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, product, or apparatus that includes said element.
[0122] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. An API structure generation method based on artificial intelligence, characterized in that, include: Respond to the structure creation event of the target API and obtain the call address of the target API; Based on the call address, obtain the first call data when the target API is called; Based on the first call data, the target model is invoked to generate the API structure information corresponding to the target API; The target model is an artificial intelligence model fine-tuned on a training dataset formed by API call data samples and API structure information samples.
2. The method according to claim 1, characterized in that, Also includes: Output the call prompt information corresponding to the target API. The call prompt information is used to prompt the target API to be called according to different parameter information of the target API.
3. The method according to claim 1, characterized in that, Based on the call address, obtain the first call data when the target API is called, including: The API gateway is invoked to detect the call operation of the target API based on the call address; and when the call operation of the target API is detected, the request data and response data corresponding to the call operation are obtained. Based on the request data and the response data, the first call data is obtained.
4. The method according to claim 3, characterized in that, Based on the first call data, the target model is invoked to generate the API structure information corresponding to the target API, including: Based on the request data, the response data, and the API documentation specifications, generate a first prompt word; The first prompt word is input into the target model so that the target model outputs API structure information that conforms to the API documentation standard based on the request data and the response data.
5. The method according to claim 1, characterized in that, After calling the target model to generate the API structure information corresponding to the target API, the process also includes: Based on the call address, obtain the second call data when the target API is called; If the second call data is different from the first call data, the API structure information corresponding to the target API is updated according to the second call data.
6. The method according to claim 5, characterized in that, Based on the second call data, the API structure information corresponding to the target API is updated, including: Determine whether the data structure corresponding to the second call data matches the data structure in the API structure information corresponding to the target API; If there is no match, a second prompt word is generated based on the second call data; The second prompt word is input into the target model so that the target model modifies the API structure information corresponding to the target API based on the second call data.
7. The method according to claim 5, characterized in that, In the API structure information corresponding to the target API, the response status code and response structure are recorded accordingly; Based on the second call data, the API structure information corresponding to the target API is updated, including: Extract the response status code from the second call data; Determine whether the API structure information corresponding to the target API contains the response structure corresponding to the response status code; If not included, a third prompt word is generated based on the second call data; The third prompt word is input into the target model so that the target model expands the response structure corresponding to the response status code in the API structure information corresponding to the target API based on the second call data.
8. The method according to any one of claims 1-7, characterized in that, The API structure information corresponding to the target API includes: the API structure corresponding to the target API and the descriptive information associated with the API structure; wherein, the API structure information sample used to train the target model includes the descriptive information associated with the API structure information sample, so as to enable the artificial intelligence model to learn the knowledge of generating the API structure information sample and the descriptive information associated with the API structure information sample based on the API call data sample during the fine-tuning process.
9. An API structure generation system based on artificial intelligence, characterized in that, include: API management device and target model, wherein the target model is an artificial intelligence model fine-tuned on a training dataset formed by API call data samples and API structure information samples; The API management device is configured to: respond to a structure creation event of a target API and obtain the call address of the target API; obtain first call data when the target API is called based on the call address; and send a first call request to the target model based on the first call data. The target model is used to: respond to the first call request and generate API structure information corresponding to the target API.
10. The system according to claim 9, characterized in that, The system also includes: an API gateway; When the API management device obtains the first call data when the target API is called based on the call address, it is specifically used to: send a second call request to the API gateway based on the call address; The API gateway is configured to: respond to the second call request, detect the call operation of the target API based on the call address; and, when the call operation of the target API is detected, obtain the request data and response data corresponding to the call operation; and return the request data and the response data as the first call data to the API management device.
11. An electronic device, characterized in that, include: Memory and processor; The memory is used to store one or more computer instructions; The processor is configured to execute one or more computer instructions for performing the steps of the method according to any one of claims 1-8.
12. A computer-readable storage medium storing a computer program, characterized in that, When a computer program is executed by a processor, it is able to perform the steps of the method described in any one of claims 1-8.
13. A computer program product, characterized in that, include: A computer program / instruction that, when executed by a processor, enables the implementation of the steps in the method described in any one of claims 1-8.