API code generation method and device, equipment, medium and program product

By inputting application scenarios and handling items names into large language models to generate API codes, the problems of low efficiency and poor adaptability of API code generation in the existing technology are solved, and automated API code generation and deployment are realized, improving efficiency and user experience.

CN119127152APending Publication Date: 2024-12-13ZHONGDIAN DATA IND CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411069327.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-06
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

Existing API code generation methods are inefficient and difficult to adapt to different user needs. They rely on predefined templates and rules, require manual participation, and are costly.

Method used

By obtaining the application scenario name and processing item name in the pending data, obtaining the corresponding target prompt word, and inputting it into the preset large language model, generating the corresponding API code, and realizing the automatic generation of API code without manual participation.

Benefits of technology

It improves the efficiency of API code generation, can directly adapt to different user needs, reduces the complexity and labor cost of API deployment, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127152A_ABST
    Figure CN119127152A_ABST
Patent Text Reader

Abstract

The invention relates to an API code generation method and device, equipment, a medium and a program product. The API code generation method comprises the steps of obtaining to-be-processed data; obtaining a target prompt word corresponding to an application scene name and / or a transaction item name in the to-be-processed data; and inputting the to-be-processed data and the target cue word into a preset large language model, generating an API code corresponding to the to-be-processed data by the preset large language model based on the to-be-processed data and the target cue word, and outputting the API code, so that the API code can be automatically generated based on the preset large language model, the generation efficiency of the API code is improved, and the user experience is improved. The to-be-processed data is directly input into the large language model, the API code matched with the application scene name and / or the transaction item name contained in the to-be-processed data can be obtained, and then the generated API code can adapt to different requirements of users.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of computer program development, and in particular to an API code generation method, apparatus, device, medium and program product. Background Art

[0002] An Application Programming Interface (API) is a set of predefined rules and protocols for interaction between different software applications. With the popularization of cloud computing and mobile applications, people's demand for APIs and their requirements for API development efficiency are also increasing.

[0003] In the process of API development, the existing API code generation methods mainly include: the first method is that developers manually define the API request parameters and response parameters, and write business logic and error code processing to generate usable API code; the second method is to define the API structure based on existing front-end development tools such as Swagger and OpenAPI, and then generate API code by filling in the parameters required for the API code in the predefined templates and rules compiled by humans.

[0004] However, among the existing API code generation methods, the first method requires users to manually write API codes, which has the problems of low efficiency and high labor costs; although the second method improves the efficiency of API code generation to a certain extent, the preparation of predefined templates and rules has high technical requirements for developers, and this method relies on predefined templates and rules, and is difficult to adapt to different user needs. Summary of the invention

[0005] In order to solve the above technical problems, the present disclosure provides an API code generation method, device, equipment, medium and program product.

[0006] A first aspect of an embodiment of the present disclosure provides an API code generation method, including:

[0007] Obtaining the data to be processed, which includes the application scenario name and / or the name of the item to be processed;

[0008] Obtain target prompt words corresponding to the application scenario name and / or the name of the task to be handled;

[0009] The data to be processed and the target prompt word are input into a preset large language model, and the preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code.

[0010] A second aspect of an embodiment of the present disclosure provides an API code generation device, including:

[0011] A first acquisition module is used to acquire data to be processed, where the data to be processed includes an application scenario name and / or a name of an item to be processed;

[0012] The second acquisition module is used to acquire the target prompt word corresponding to the application scenario name and / or the name of the task to be handled;

[0013] The code generation module is used to input the data to be processed and the target prompt word into a preset large language model, and the preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code.

[0014] A third aspect of the embodiments of the present disclosure provides an electronic device, including:

[0015] processor;

[0016] A memory for storing executable instructions;

[0017] The processor is used to read executable instructions from the memory and execute the executable instructions to implement the API code generation method provided in the first aspect above.

[0018] A fourth aspect of an embodiment of the present disclosure provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the processor implements the API code generation method provided by the first aspect above.

[0019] A fifth aspect of an embodiment of the present disclosure provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, the API code generation method of the first aspect described above is implemented.

[0020] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:

[0021] The API code generation method, apparatus, device, medium and program product provided by the embodiments of the present disclosure can obtain data to be processed, wherein the data to be processed includes an application scenario name and / or a name of an item to be handled, obtain a target prompt word corresponding to the application scenario name and / or the name of the item to be handled, input the data to be processed and the target prompt word into a preset large language model, and generate an API code corresponding to the data to be processed based on the data to be processed and the target prompt word by the preset large language model, and output the API code. Thus, the API code can be automatically generated based on the preset large language model without manual intervention, thereby improving the efficiency of API code generation. At the same time, the data to be processed can be directly input into the large language model to obtain an API code matching the application scenario name and / or the name of the item to be handled contained in the data to be processed, thereby enabling the generated API code to adapt to different needs of users. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0023] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0024] Figure 1 is a flow chart of an API code generation method provided by an embodiment of the present disclosure;

[0025] Figure 2 is a flowchart of another API code generation method provided by an embodiment of the present disclosure;

[0026] Figure 3 It is a structural schematic diagram of an API code generation device provided by an embodiment of the present disclosure;

[0027] Figure 4 It is a structural schematic diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0028] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.

[0029] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

[0030] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0031] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0032] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0033] Generally, the existing API code generation method relies on predefined templates and rules, and is difficult to adapt to different user needs. To address this problem, the present disclosure provides an API code generation method, which is described below in conjunction with a specific embodiment.

[0034] Figure 1 It is a flowchart of an API code generation method provided by an embodiment of the present disclosure. The method can be executed by an API code generation device. The API code generation device can be implemented in software and / or hardware. The API code generation device can be configured in an electronic device, such as a server or a terminal, wherein the terminal specifically includes a mobile phone, a computer or a tablet computer, etc.

[0035] In the embodiments disclosed herein, the API code generation method can be applied to the government field, as well as to the medical field, the education field, etc., without limitation herein.

[0036] like Figure 1As shown, the API code generation method provided in this embodiment includes the following steps.

[0037] S110, obtaining data to be processed, where the data to be processed includes an application scenario name and / or a task name.

[0038] In the embodiment of the present disclosure, after receiving the API code generation instruction, the electronic device obtains the data to be processed.

[0039] In the embodiments of the present disclosure, the data to be processed may be self-constructed virtual data, unpublished internal data, data in a preset database, web page data crawled by a web crawler on an open source website, etc., and no limitation is made here.

[0040] The data to be processed can be natural language text, which can be recognized and processed using a preset large language model without the need for additional parsing operations.

[0041] In the embodiments of the present disclosure, the application scenario name is the name of the scenario to which the generated API code is applied, which is used to describe the application scenario or function information of the API interface corresponding to the generated API code, or the application scenario name can be understood as the parameter name, that is, the name of what to do, and the application scenario name can be used to determine the API name. The name of the handling matter can be understood as the name of a specific handling matter under the application scenario.

[0042] For example, in the field of government affairs, the name of the application scenario can be the birth of a newborn, and the names of the matters corresponding to the application scenario can include birth certificate, newborn physical examination, newborn household registration, etc.; the name of the application scenario can be marriage, and the names of the matters corresponding to the application scenario can include marriage certificate, marriage registration, etc.

[0043] In some embodiments of the present disclosure, the API code generation instruction includes data to be processed. After receiving the API code generation instruction, the electronic device parses the API code generation instruction to obtain the data to be processed.

[0044] In some other embodiments of the present disclosure, after receiving the API code generation instruction, the electronic device obtains the first voice information of the user corresponding to the API code generation instruction based on a preset voice acquisition device, and when the first voice information contains a preset wake-up word, the first voice information is recognized and converted into a first voice text, and the first voice text is determined as the data to be processed; alternatively, the electronic device can perform multiple rounds of voice interaction with the user, and determine the data to be processed based on the multiple rounds of voice interaction information.

[0045] In some other embodiments of the present disclosure, the API code generation instruction includes target identification information. After receiving the API code generation instruction, the electronic device parses the API code generation instruction, obtains the target identification information, searches for data corresponding to the target identification information from a preset database or internal data for publication, and determines the data as data to be processed.

[0046] S120: Obtain a target prompt word corresponding to the application scenario name and / or the task name.

[0047] In the disclosed embodiment, after obtaining the pending items, the electronic device obtains the target prompt word corresponding to the application scenario name and / or the name of the item in the pending items.

[0048] Specifically, after obtaining the pending items, the electronic device can parse the pending items, obtain the application scenario names and / or the names of the items to be processed, and obtain the target prompt words corresponding to the application scenario names and / or the names of the items to be processed from a preset database.

[0049] In the embodiment of the present disclosure, the target prompt words include prompt information related to API code generation, such as identity description information, task description information, output format description information, and preset code examples.

[0050] The identity description information is the description information used to inform the identity to which the preset large language model belongs; and the task description information is the information used to describe the task to be performed by the preset large language model.

[0051] For example, the identity description information and task description information in the target prompt word can be "You are an API code-assisted construction robot. You can help users build business processes and provide interface documentation, code examples and other information. You can answer users' questions and help users understand each aspect of the business process. You will answer questions based on the following format."

[0052] The output format description information is descriptive information of the type or format used to execute the output. For example, the format definition may be marked using preset symbols and syntax to help convey the intent and make the output easier to parse.

[0053] Exemplarily, the output format description information in the target prompt word can be "Note: You only need to generate code, not any textual description!; Note: You must ensure that the content you generate is directly executable code!; Generate 5-8 parameters and a reasonable description of the matter (router description) according to the format of the script below (you can determine the input and output parameters yourself); Note: There should be no spaces between the generated input and output parameters; Note: The interface description needs to explain the interface function according to the parameters, and the description format of @onething_router.post() should not be unified; Note that it must include #Create a FastAPI application instance, #Add routes to the application instance, and #Run the application; Note: The port number can only be XXXX".

[0054] The code examples are pre-set code examples that conform to a preset API architecture, and are used for a preset large language model to perform contextual learning based on the code examples, and to generate API codes in a preset format strictly in accordance with the API architecture in the code examples based on the learning results.

[0055] Optionally, the code example in the target prompt word contains comment information to improve the readability of the code example and help the preset large language model to better understand and learn. The comment information is a detailed explanation used to describe the function and logic of the code.

[0056] In the disclosed embodiment, by adding code examples to the target prompt word, a usable API code conforming to a preset format can be generated by learning the code examples using a large language model without training the preset large language model.

[0057] S130: input the data to be processed and the target prompt word into a preset large language model, and the preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code.

[0058] In the embodiment of the present disclosure, after obtaining the target prompt word, the electronic device inputs the data to be processed and the target prompt word into a preset large language model, and the preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code.

[0059] In the disclosed embodiment, the preset large language model can be any existing chat model, such as Meta-Llama-3-70B-Instruc or moonshot-v1-8k model, or a large language model with a parameter amount greater than a preset parameter amount threshold (such as 70b), thereby ensuring the quality and practicality of the generated API code.

[0060] Specifically, after obtaining the target prompt word, the electronic device can call the preset large language model based on the preset function, and input the data to be processed and the target prompt word into the preset large language model. The preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code, thereby obtaining the API code corresponding to the data to be processed.

[0061] Among them, the preset function can be a function written using the OpenAI library for calling a preset large language model.

[0062] The number of data to be processed may be one or more. When the number of data to be processed is more than one, the electronic device may generate API codes corresponding to each data to be processed in batches based on a preset large language model.

[0063] In the disclosed embodiments, it is possible to obtain data to be processed, wherein the data to be processed includes an application scenario name and / or an item to be processed name, obtain a target prompt word corresponding to the application scenario name and / or the item to be processed name, input the data to be processed and the target prompt word into a preset large language model, and generate an API code corresponding to the data to be processed based on the data to be processed and the target prompt word by the preset large language model, and output the API code. Thus, the API code can be automatically generated based on the preset large language model without manual intervention, thereby improving the efficiency of API code generation. At the same time, the data to be processed can be directly input into the large language model to obtain an API code that matches the application scenario name and / or item to be processed name contained in the data to be processed, thereby enabling the generated API code to adapt to different needs of users.

[0064] Based on the above embodiments of the present disclosure, after outputting the API code, the API code generation method may further include: running the API code to perform API deployment and generate a Json file corresponding to the API.

[0065] Before running the API code, the API code is cleaned based on a preset regular expression to obtain the target API code after the data cleaning process; the target API code is format converted to obtain the target programming language code, and the target programming language code is stored in the target file.

[0066] Json file is a file format used to store and exchange data. Its full name is JavaScript Object Notation. It uses a text format that is completely independent of the programming language to store and represent data.

[0067] The target programming language code may be Python code, that is, code that can be directly run, and the target file may be a newly created Python file.

[0068] Specifically, after obtaining the API code, the electronic device uses a preset regular expression to perform data cleaning on the special symbols or redundant text in the API code, obtains the target API code after data cleaning, extracts the string in the target API code, saves the string in Excel format, and then converts the string in Excel format into Python code to obtain the target programming language code such as Python code, and stores the Python code in the newly created Python file. In the process of converting the string in Excel format into Python code, it is necessary to determine the progressive relationship between the class definition (class) and the function in Python, that is, to complete the processing of line breaks and space completion omitted in Excel.

[0069] Furthermore, running the API code to deploy the API may specifically include: running the target programming language code, namely Python, to deploy the API.

[0070] In the embodiments of the present disclosure, after obtaining the API code, the API code can be converted into Python code that can be run directly, and then the API code can be automatically deployed without manual deployment of the API, thereby improving the convenience of API deployment, reducing the complexity of API deployment, and improving user experience.

[0071] In an embodiment of the present disclosure, the target prompt word includes one or more port numbers, and running the target programming language code may specifically include: determining a target process corresponding to the one or more port numbers based on the one or more port numbers; and running the target programming language code based on the target process.

[0072] In some embodiments of the present disclosure, the target prompt word only includes one port number, and the number of generated API codes is one. At this time, based on the correspondence between the port number and the process, the target process corresponding to the port number is determined, and then the target programming language code such as Python code is run based on the target process to perform API deployment.

[0073] In other embodiments of the present disclosure, the target prompt word contains only one port number. When there are multiple API codes generated, each API code is run in sequence based on the target process corresponding to the port number, and then each API is deployed. In this way, it is possible to ensure that the operating environment of each API code is isolated from the main program, improve the stability and controllability of the system and the security of API deployment, and at the same time, ensure that a single API code error does not affect the operation of the entire system. By controlling the running time of the target process, memory and CPU resources can also be effectively managed.

[0074] In some other embodiments of the present disclosure, when the target prompt word contains multiple port numbers and the number of generated API codes is multiple, the target process corresponding to each port number is determined, and a corresponding process is assigned to each API code, so that each API code is assigned a corresponding process to run the API code, thereby improving the efficiency of API deployment.

[0075] In the embodiment of the present disclosure, after generating the Json file corresponding to the API, the API code generation method may further include: extracting target Json data in the Json file, formatting the Json file based on the target Json data, and saving it as a target Excel file.

[0076] The target Json data includes basic information and parameter information. The basic information includes the input data corresponding to the API, i.e., the data to be processed, the API generation timestamp, the API usage timestamp, the API user name, the API generation method, etc. The parameter information includes various parameters in the API code generated by the preset large language model.

[0077] Specifically, after obtaining the Json file, the Json file is parsed, the target Json data is extracted from the Json file, and converted into an Excel file format that is easy to read and manage, and stored in the Excel file, thereby facilitating users to view and manage data.

[0078] In some embodiments of the present disclosure, when some data is missing in a Json file and a corresponding Excel file cannot be generated, the Json file is directly skipped and the next Json file is processed.

[0079] In an embodiment of the present disclosure, when there are multiple API codes, there are also multiple Json files generated by running the API codes, and then there are multiple Excel files obtained after converting the Json files. At this time, the multiple Excel files are merged to form a total Excel file to facilitate the management of multiple APIs.

[0080] Specifically, the specific method of merging multiple Excel files is as follows: For each Excel file, a preset module is used. For example, a built-in module in Python for generating and processing universally unique identifiers (Universally Unique Identifier, referred to as UUID), namely the UUID module, generates a unique interface ID, and then reads the contents of each worksheet in the Excel file one by one. In the read worksheet data, the interface ID (that is, the ID of the API interface) is added as the first column to identify all data from the same API interface. The interface ID makes the data of the interface basic table and the interface parameter table (that is, the basic information and parameter information included in the target Json data) correspond one to one. The merge adopts the logic of continuation to check whether a worksheet with the same name already exists in the merged file. If it does, the maximum number of rows of the worksheet is obtained to determine the starting position for writing the new data. If it does not exist, set the first row of the writing starting position. The processed data is written to the interface basic table and interface parameter table of the total Excel file in the correct position and order.

[0081] In the disclosed embodiment, when there are multiple API codes, the number of target files obtained by format conversion of the multiple API codes is also multiple, such as generating multiple Python files. In this case, the multiple Python files are merged to facilitate the subsequent management of the API.

[0082] Specifically, the Python code in each Python file is extracted and merged into a main script according to preset rules, thereby providing convenience for subsequent R&D personnel to uniformly deploy and maintain the API.

[0083] In the disclosed embodiment, Python files, Json files generated based on Python, and Excel files converted from Json files can use the same naming prefix, which facilitates the association of related files of the same API interface, thereby improving work efficiency and convenience of file search.

[0084] Figure 2 is a flowchart of another API code generation method provided by an embodiment of the present disclosure, such as Figure 2 As shown, the API code generation method may specifically include the following steps:

[0085] S210: Obtain data to be processed, where the data to be processed includes an application scenario name and / or a task name.

[0086] S220: Obtain a target prompt word corresponding to the application scenario name and / or the task name.

[0087] S230: input the data to be processed and the target prompt word into a preset large language model, and the preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code.

[0088] S240. Run the API code to deploy the API and generate a Json file corresponding to the API.

[0089] S250, extracting target Json data from the Json file, formatting the Json file based on the target Json data, and saving the Json file as a target Excel file.

[0090] It should be noted that the specific implementation of steps S210-S250 is similar to the implementation of the relevant steps in the above-mentioned embodiment of the present disclosure, and will not be repeated here.

[0091] In the embodiments of the present disclosure, it is possible to obtain data to be processed, wherein the data to be processed includes an application scenario name and / or an item to be handled name, obtain a target prompt word corresponding to the application scenario name and / or the item to be handled name, input the data to be processed and the target prompt word into a preset large language model, and generate an API code corresponding to the data to be processed based on the data to be processed and the target prompt word by the preset large language model, and output the API code. After obtaining the API code, the API code is run to perform API deployment, and a Json file corresponding to the API is generated, target Json data in the Json file is extracted, and the Json file is formatted and saved as a target Excel file based on the target Json data. Thus, API code related to user needs can be automatically generated, and the API can be automatically deployed, thereby improving the efficiency and universality of API code generation, and improving the efficiency and convenience of API deployment. In addition, by converting the format of the Json file into an Excel file, subsequent file viewing and use are facilitated, thereby improving user experience.

[0092] Figure 3 It is a structural diagram of an API code generation device provided in an embodiment of the present disclosure.

[0093] In the embodiments of the present disclosure, the API code generation device can be set in an electronic device and is understood as a part of the functional modules in the above electronic device. Specifically, the electronic device can be a server or a terminal, wherein the terminal specifically includes a mobile phone, a computer or a tablet computer, etc., which is not limited here.

[0094] like Figure 3 As shown, the API code generating device 300 may include a first obtaining module 310 , a second obtaining module 320 and a code generating module 330 .

[0095] The first acquisition module 310 may be used to acquire data to be processed, where the data to be processed includes an application scenario name and / or a task name.

[0096] The second acquisition module 320 may be used to acquire a target prompt word corresponding to an application scenario name and / or a task name.

[0097] The code generation module 330 can be used to input the data to be processed and the target prompt word into a preset large language model, and the preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code.

[0098] In the disclosed embodiments, it is possible to obtain data to be processed, wherein the data to be processed includes an application scenario name and / or an item to be processed name, obtain a target prompt word corresponding to the application scenario name and / or the item to be processed name, input the data to be processed and the target prompt word into a preset large language model, and generate an API code corresponding to the data to be processed based on the data to be processed and the target prompt word by the preset large language model, and output the API code. Thus, the API code can be automatically generated based on the preset large language model without manual intervention, thereby improving the efficiency of API code generation. At the same time, the data to be processed can be directly input into the large language model to obtain an API code that matches the application scenario name and / or item to be processed name contained in the data to be processed, thereby enabling the generated API code to adapt to different needs of users.

[0099] In some embodiments of the present disclosure, the target prompt word includes identity description information, task description information, output format description information and preset code examples.

[0100] In some embodiments of the present disclosure, the API code generation device 300 may further include an API deployment module.

[0101] The API deployment module can be used to run the API code after outputting the API code to deploy the API and generate the Json file corresponding to the API.

[0102] In some embodiments of the present disclosure, the API code generating device 300 may further include a data processing module.

[0103] The data processing module can be used to perform data cleaning on the API code based on a preset regular expression before running the API code, and obtain the target API code after data cleaning; perform format conversion on the target API code to obtain the target programming language code, and store the target programming language code in the target file.

[0104] The API deployment module can be specifically used to run the target programming language code to deploy the API.

[0105] In some embodiments of the present disclosure, the target prompt word includes one or more port numbers.

[0106] The API deployment module can be specifically used to determine a target process corresponding to one or more port numbers based on the one or more port numbers; and run a target programming language code based on the target process.

[0107] In some embodiments of the present disclosure, the API code generating device 300 may further include a format conversion module.

[0108] The format conversion module can be used to extract target Json data from the Json file after generating the Json file corresponding to the API, format the Json file based on the target Json data, and save it as a target Excel file.

[0109] It should be noted that Figure 3 The API code generating device 300 shown can execute each step in the above method embodiment and realize each process and effect in the above method embodiment, which will not be described in detail here.

[0110] Figure 4 It is a structural schematic diagram of an electronic device provided by an embodiment of the present disclosure.

[0111] In the disclosed embodiment, Figure 4 The electronic device shown may be a server or a terminal, wherein the terminal specifically includes a mobile phone, a computer or a tablet computer, etc., which is not limited here.

[0112] like Figure 4 As shown, the electronic device may include a processor 410 and a memory 420 storing computer program instructions.

[0113] Specifically, the processor 410 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present disclosure.

[0114] The memory 420 may include a large capacity memory for information or instructions. By way of example and not limitation, the memory 420 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a tape, or a universal serial bus (USB) drive or a combination of two or more of these. Where appropriate, the memory 420 may include a removable or non-removable (or fixed) medium. Where appropriate, the memory 420 may be inside or outside the integrated gateway device. In a particular embodiment, the memory 420 is a non-volatile solid-state memory. In a particular embodiment, the memory 420 includes a read-only memory (ROM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (Electrically Erasable Programmable ROM, EEPROM), an electrically rewritable ROM (EAROM) or a flash memory, or a combination of two or more of these.

[0115] The processor 410 reads and executes the computer program instructions stored in the memory 420 to perform the steps of the API code generation method provided in the embodiment of the present disclosure.

[0116] In one example, the electronic device may further include a transceiver 430 and a bus 440. Figure 4 As shown, the processor 410, the memory 420 and the transceiver 430 are connected via a bus 440 and communicate with each other.

[0117] The bus 440 includes hardware, software, or both. For example, but not limitation, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industrial Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a Memory bus, a MicroChannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses or a combination of two or more of these. Where appropriate, the bus 440 may include one or more buses.

[0118] The embodiments of the present disclosure also provide a computer-readable storage medium, which may store a computer program. When the computer program is executed by a processor, the processor implements the API code generation method provided by the embodiments of the present disclosure.

[0119] The above-mentioned storage medium may, for example, include a memory 420 of computer program instructions, and the above-mentioned instructions may be executed by the processor 410 of the electronic device to complete the API code generation method provided in the embodiment of the present disclosure. Optionally, the storage medium may be a non-temporary computer-readable storage medium, for example, the non-temporary computer-readable storage medium may be a ROM, a random access memory (Random Access Memory, RAM), a compact disc read-only memory (Compact Disc ROM, CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device, etc.

[0120] The embodiments of the present disclosure also provide a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, the API code generation method provided by the embodiments of the present disclosure is implemented, and the various processes and effects in the above-mentioned embodiments of the present disclosure can be implemented, which will not be elaborated here.

[0121] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for generating an API code, characterized in that: include: Acquire the data to be processed, wherein the data to be processed includes the name of the application scenario and / or the name of the task to be handled; Obtaining a target prompt word corresponding to the application scenario name and / or the name of the task to be handled; The data to be processed and the target prompt word are input into a preset large language model, and the preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code.

2. The method according to claim 1, characterized in that The target prompt words include identity description information, task description information, output format description information and preset code examples.

3. The method according to claim 1, characterized in that After outputting the API code, the method further includes: Run the API code to deploy the API and generate a Json file corresponding to the API.

4. The method according to claim 3, characterized in that Before running the API code, the method further includes: Performing data cleaning on the API code based on a preset regular expression to obtain a target API code after data cleaning; Performing format conversion processing on the target API code to obtain a target programming language code, and storing the target programming language code in a target file; The running of the API code to perform API deployment includes: The target programming language code is run to deploy the API.

5. The method according to claim 4, characterized in that The target prompt word includes one or more port numbers, and the running of the target programming language code includes: Based on the one or more port numbers, determining a target process corresponding to the one or more port numbers; The target programming language code is executed based on the target process.

6. The method according to claim 3, characterized in that After generating the Json file corresponding to the API, the method further includes: Target Json data is extracted from the Json file, and the Json file is formatted based on the target Json data and saved as a target Excel file.

7. An API code generation device, characterized in that: include: A first acquisition module is used to acquire data to be processed, wherein the data to be processed includes an application scenario name and / or a name of a task to be handled; A second acquisition module is used to acquire a target prompt word corresponding to the application scenario name and / or the name of the task to be handled; A code generation module is used to input the data to be processed and the target prompt word into a preset large language model, and the preset large language model generates an API code corresponding to the data to be processed based on the data to be processed and the target prompt word, and outputs the API code.

8. An electronic device, characterized in that: include: processor; A memory for storing executable instructions; The processor is used to read the executable instructions from the memory and execute the executable instructions to implement the API code generation method described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the API code generation method according to any one of claims 1 to 6.

10. A computer program product, comprising a computer program or instructions, characterized in that: When the computer program or instruction is executed by a processor, the API code generation method according to any one of claims 1 to 6 is implemented.

Citation Information

Cited By

  • Code generation method and device

    CN119781772A

  • Multi-source heterogeneous hybrid code unified standardization method oriented to intelligent model service

    CN120085845A

  • Method and apparatus for managing application programming interface, and device and medium

    WO2026178711A1