Document-based code generation method and device, equipment and storage medium

By converting initial document information into a preset format and automatically extracting interface metadata using a large language model, MCP Server code is generated, solving the problem of merchants or institutions manually developing code in payment, marketing, and risk control systems, and achieving efficient and accurate code generation.

CN121433652APending Publication Date: 2026-01-30CHINA UNIONPAY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511598183.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-03
Publication Date
2026-01-30

AI Technical Summary

Technical Problem

In business systems such as payment, marketing, and risk control, merchants or institutions need to manually develop MCP Server code based on complex unstructured API interface documents, resulting in high development thresholds, low efficiency, and a high risk of errors, making it difficult to quickly integrate AI intelligent agents.

Method used

By receiving initial document information and converting it into a preset format, the system automatically extracts interface metadata using a large language model to generate MCP Server code. This process includes document parsing, metadata extraction, and code generation, and is automated using a multi-agent framework.

Benefits of technology

It enables efficient parsing of unstructured documents, lowers the barrier to code development, improves code generation efficiency and accuracy, and saves manpower and time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121433652A_ABST
    Figure CN121433652A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a document-based code generation method and device, equipment and a storage medium. The method comprises the following steps: receiving initial document information, and converting the initial document information into document information in a preset format; wherein the document information represents a mode required for calling an interface, and the preset format represents a format of a preset standard document of the MCP; determining meta-information of the interface according to the document information in the preset format; wherein the meta-information represents attribute description of the interface; determining code information of the interface according to the meta-information of the interface; wherein the code information is used for accessing a preset intelligent agent by calling an interface of the MCP. According to the method, interface meta-information can be extracted for documents in various formats, codes are automatically generated, and the generation efficiency and precision of the codes are improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, and in particular to a code generation method and device based on a document, an equipment and a storage medium. BACKGROUND

[0002] In a business system such as payment, marketing, and risk control, a large number of API (Application Programming Interface) interfaces need to interact with AI (Artificial Intelligence) agents to realize intelligent service expansion. When a merchant or an institution accesses such a system, it usually needs to develop adaptive code based on complex interface documents to communicate with the backend system.

[0003] This requires the merchant organization to read various parameter definitions, protocol specifications, encryption rules, and other content in the interface document in depth, and to develop an adaptive interface calling program independently, which consumes a large amount of time and human cost, and the code generation efficiency is low. SUMMARY

[0004] The embodiments of the present application provide a code generation method and device based on a document, an equipment and a storage medium to improve the generation efficiency of the code.

[0005] In a first aspect, the embodiments of the present application provide a code generation method based on a document, comprising:

[0006] receiving initial document information and converting the initial document information into document information in a preset format; wherein the document information represents a way required for calling an interface, and the preset format represents a format of a preset specification document of a model context protocol (MCP);

[0007] determining meta information of the interface according to the document information in the preset format; wherein the meta information represents an attribute description of the interface of the MCP;

[0008] determining code information of the interface according to the meta information of the interface; wherein the code information is used to access a preset agent by calling the interface of the MCP.

[0009] In a second aspect, the embodiments of the present application provide a code generation device based on a document, comprising:

[0010] a format conversion unit configured to receive initial document information and convert the initial document information into document information in a preset format; wherein the document information represents a way required for calling an interface, and the preset format represents a format of a preset specification document of a model context protocol (MCP);

[0011] The information determining unit is configured to determine meta information of the interface according to the document information in the preset format, wherein the meta information represents attribute description of the interface of the MCP.

[0012] The code generating unit is configured to determine code information of the interface according to the meta information of the interface, wherein the code information is used to access the preset agent by calling the interface of the MCP.

[0013] In a third aspect, an electronic device is provided, including a memory and a processor.

[0014] The memory stores computer execution instructions.

[0015] The processor executes the computer execution instructions stored in the memory, so that the processor executes the implementation manner of the first aspect.

[0016] In a fourth aspect, a computer readable storage medium is provided, and the computer readable storage medium stores computer execution instructions. When the computer execution instructions are executed by a processor, the computer execution instructions are used to implement the implementation manner of the first aspect.

[0017] In a fifth aspect, a computer program product is provided, and the computer program product includes a computer program. When the computer program is executed by a processor, the computer program implements the implementation manner of the first aspect.

[0018] The code generation method, device, equipment and storage medium based on a document provided by the embodiments of the present application can convert initial document information in different formats into document information in a preset format by receiving initial document information. The embodiments of the present application can realize unified and efficient parsing of non-structured documents such as PDF, DOCX and HTML, so that the extraction of interface meta information does not depend on manual work, improves the information extraction efficiency and is not prone to errors. According to the document information in the preset format, the meta information of the MCP interface is automatically extracted, the final code is generated according to the meta information of the interface, the function of the MCP interface is called, and the subsequent human-computer interaction by using the agent is facilitated. By automatically extracting the meta information and automatically generating the code, the development threshold of the code can be reduced, the manpower and time can be saved, and the generation efficiency and precision of the MCP code can be effectively improved. BRIEF DESCRIPTION OF DRAWINGS

[0019] The accompanying drawings, which are incorporated into and form a part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the application.

[0020] Figure 1 A flowchart of a code generation method based on a document provided by the embodiments of the present application is shown in the figure.

[0021] Figure 2A flowchart of a code generation method based on a document provided by an embodiment of the present application is shown in the figure;

[0022] Figure 3 A flowchart of a code generation method based on a document provided by an embodiment of the present application is shown in the figure;

[0023] Figure 4 An interaction process diagram between multiple agents provided by an embodiment of the present application is shown in the figure;

[0024] Figure 5 A flowchart of a code generation method based on a document provided by an embodiment of the present application is shown in the figure;

[0025] Figure 6 An interface diagram of interface selection provided by an embodiment of the present application is shown in the figure;

[0026] Figure 7 A structural diagram of a code generation device based on a document provided by an embodiment of the present application is shown in the figure;

[0027] Figure 8 A structural diagram of an electronic device provided by an embodiment of the present application is shown in the figure.

[0028] Through the above figures, the specific embodiments of the present application have been shown, and more detailed descriptions will be given in the following. These figures and textual descriptions are not intended to limit the scope of the concept of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0029] The exemplary embodiments will be described in detail herein with reference to the accompanying drawings. In the following description, the same numbers refer to the same or similar elements unless otherwise represented. The embodiments described in the following exemplary embodiments do not represent all the embodiments consistent with the present application. Rather, they are merely examples of devices and methods consistent with some aspects of the present application.

[0030] First, the terms involved in the present application are explained:

[0031] MCP: Model Context Protocol, model context protocol, which defines the interaction standard of LLM and external tools / data sources, including request format, context management, tool calling specification, etc., the core of which is to realize the access of LLM to real-time data through standardized interface, such as payment system, risk control system, etc.;

[0032] LLM: Large Language Model, large language model, for short, large model;

[0033] Multi-Agent: Multi-Agent, through task decomposition, Agent collaboration, to realize complex process automation, for example, one Agent is responsible for document parsing, another Agent is responsible for code generation, and they work together through sharing state and communication mechanism.

[0034] The use scenarios involved in the embodiments of the present application mainly focus on the automation processing needs of enterprises or merchants for unstructured API interface documents. Specifically, in payment, marketing, risk control and other business systems, a large number of API interfaces need to be called based on AI agents to realize intelligent service expansion. When accessing such business systems, merchants or institutions usually need to develop adaptive MCP Server (service) code based on complex interface documents, such as PDF, DOCX, HTML and other unstructured formats, in order to communicate with the backend business system through the MCP protocol. However, the existing interface document types are diverse, the formats are not unified, and the content description methods differ greatly, lacking standardized structure. The document may also contain a large amount of non-technical descriptions, such as version records, background introductions, etc., which interfere with the extraction of important information.

[0035] Merchants or institutions need to invest a lot of manpower to study the documents and manually write MCP Server code, which has high development threshold, long development cycle and is prone to errors. With the popularization of AI technology, the application demand of MCP protocol as a standard protocol for LLM and external tool interaction has surged. If you need to quickly access the business system of AI agents, you need a MCP Server generation scheme that does not require manual code writing and supports automatic parsing of unstructured documents.

[0036] Currently, there are significant deficiencies in handling unstructured API documents, reducing the development threshold, and improving code generation quality, which cannot meet the business needs of quickly accessing MCP protocol in the AI era.

[0037] The present application provides a code generation method and device based on documents, equipment and storage medium, applied to the field of artificial intelligence technology, in order to improve the generation efficiency and precision of code.

[0038] It should be noted that the model and data in this embodiment are not for a specific user and cannot reflect the personal information of a specific user. It should be noted that the data in this embodiment comes from a public data set.

[0039] In the technical solution of the present application, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the present application comply with the relevant legal regulations and do not violate public order and good customs.

[0040] In order to enable the reader to understand the implementation principle of the present application more deeply, the embodiments are further refined.

[0041] Figure 1 A flowchart of a code generation method based on a document according to an embodiment of the present disclosure is provided. The method can be executed by a code generation device based on a document. As shown in the figure, the method comprises the following steps: Figure 1

[0042] S101, receiving initial document information, and converting the initial document information into document information in a preset format; wherein the document information represents a manner required for calling an interface, and the preset format represents a format of a preset specification document of a model context protocol (MCP).

[0043] Exemplarily, a business system is a system for implementing various business functions, and each business function can correspond to its own business API. The definition specifications of various business APIs are uneven, and the developers of the business system pre-configure document information for each business API. The document information pre-configured by the developers is taken as the initial document information. The initial document information can represent a manner of calling a corresponding API, that is, an interface document. When calling an API, the MCP protocol specification needs to be learned according to the initial document information, and then a code for specification conversion is written, so that the API is used through the code. Therefore, the initial document information contains the required content in the code. For example, it can contain interface field description, message organization manner, signature mechanism, etc.

[0044] In this embodiment, the document format of the initial document information is not specifically limited. For example, it can be an interface document in the form of DOCX, PDF, HTML, etc. The formats of interface documents of different business systems can be different, and the formats of interface documents corresponding to different APIs in the same business system can also be different.

[0045] When a user needs to access the API of a business system, the user needs to generate an MCP Server code according to the initial document information corresponding to the API. In this embodiment, the code can be automatically generated according to the initial document information. The user can be a merchant or an institution that needs to use the business system. The user uploads the initial document information, that is, the pre-configured interface document. After receiving the initial document information, the initial document information can be format-converted regardless of the form of the initial document information. That is, non-structured interface documents in various forms of DOCX, PDF, HTML, etc. can be converted into document information in a preset format. The initial document information and the document information in the preset format represent the same meaning but have different formats. In this embodiment, the preset format can be the format of a specification document adapted to the MCP protocol.

[0046] S102, determining meta information of the interface according to the document information in the preset format; wherein the meta information represents an attribute description of the interface of the MCP.​

[0047] Exemplarily, one or more interfaces can be contained in one document information, and after obtaining the document information in the preset format, the meta information of the one or more interfaces contained can be extracted from the document information in the preset format. Each interface can correspond to its own meta information, and the meta information can represent the attribute description of the interface. For example, the meta information can include the signature mechanism of the interface message, the encryption mechanism, the decryption mechanism, the message organization method, the interface field description, the message request address, etc. The interface in the embodiment can be an MCP interface used by the MCP to call the agent.

[0048] In the embodiment, a large model can be used to extract the meta information. For example, an Agent (agent) for extracting meta information can be preset, and the interface meta information can be obtained by using the Agent. The Agent can be referred to as a meta information extraction Agent. Generally, the content of the document information is more, and in view of the limited LLM calling Token, a large model can be called to intelligently segment the document. Token refers to the basic unit of model processing, that is, the Token limit of LLM refers to the upper limit of the total amount of text that the model can receive and generate in a single interaction. It is like the capacity ceiling of the short-term memory of the model, which limits the total length of input and output. Subsequently, the segmented document blocks are used to accurately identify the redundant information, security information, interface field description information and other interface related information in each document block. According to the extracted information, the interface meta information is generated. For example, the extracted information can be added to a preset template to generate complete meta information.

[0049] In the embodiment, the document information in the preset format and the meta information are input into a preset second model to obtain an output first similarity. The preset second model is used to determine the similarity between the document information in the preset format and the meta information, and the first similarity represents the similarity between the document information in the preset format and the meta information. If the first similarity is greater than a preset similarity threshold, the code information of the interface is determined according to the meta information of the interface.

[0050] Specifically, a second model is preset, and the second model is a large model constructed and trained in advance and used to verify the interface meta information. For example, an information verification Agent can be generated according to the preset second model, so that the information verification Agent is used to verify the meta information. In the embodiment, the architecture of the large model in each Agent is not limited.

[0051] After obtaining the interface metadata, the document information in a preset format and the obtained interface metadata can be input into the information verification Agent, which is the preset second model. In this embodiment, the document information in the preset format may have been segmented into multiple document blocks before obtaining the interface metadata. Therefore, each document block and the interface metadata can also be input into the preset second model together.

[0052] Using a pre-defined second model, the similarity between document information and metadata in a pre-defined format can be calculated, serving as the first similarity. The first similarity characterizes the degree of similarity between the document information and metadata in the pre-defined format; that is, it can assess whether there are omissions or errors in the interface metadata. In this embodiment, the calculation method for the first similarity is not specifically limited.

[0053] A similarity threshold is preset. The first similarity is compared to this threshold. If the first similarity is greater than the preset threshold, the interface code information can be determined based on the interface's metadata, i.e., step S103 is executed. If the first similarity is less than or equal to the preset threshold, the process of re-extracting metadata is automatically triggered until the first similarity is greater than the threshold. For example, if the similarity threshold is 60%, and the first similarity is less than 60%, the re-extraction process is automatically triggered.

[0054] The advantage of this setup is that, to ensure the accuracy and completeness of the extracted interface metadata, an LLM (Limited Language Management) is introduced as the information verification agent. The information verification agent receives the interface document and the initially generated interface metadata, and the LLM evaluates the accuracy of the extracted information, significantly improving the quality of the extracted interface metadata.

[0055] S103. Determine the code information of the interface based on the meta information of the interface; wherein, the code information is used to access the preset intelligent agent by calling the interface of MCP.

[0056] For example, the metadata of an interface contains the content required by the code information. This metadata may include the interface name, request / response fields, default values, required / optional fields, interface type, message format, etc. The interface metadata is converted into code to obtain the corresponding code information for that interface. For instance, a code template can be pre-set. This template has a fixed format and blank spaces; the interface metadata can be filled into the corresponding positions in the template to obtain the complete code information, which generates the MCP Server.

[0057] In this embodiment, an MCP Server generation agent can be pre-built. Interface metadata is input into the MCP Server generation agent, and the MCP Server is output, thus realizing the generation of an MCP Server from unstructured API documents using a multi-agent framework. After generating the MCP Server code, a large model can be used to validate the generated code, improving its quality. For example, the large model can validate the code information based on a preset code format to determine if there are formatting issues; or, the large model can perform semantic recognition on the code information to determine if there are semantic errors. In this embodiment, the method for validating code information is not specifically limited.

[0058] The code information can be used to connect to an Agent, allowing users to interact with the computer. For example, a user can input a query request for transaction information through the Agent, which will then call the relevant interface via the code information. This interface will access the corresponding database, retrieve the answer to the request from the database, and return it to the user, completing the interaction process.

[0059] This application provides a document-based code generation method that, by receiving initial document information, can convert initial document information of different formats into document information of a preset format. It enables efficient parsing of unstructured documents such as PDF, DOCX, and HTML, making the extraction of interface metadata independent of manual intervention, improving information extraction efficiency and reducing errors. Based on the preset format document information, it automatically extracts the interface metadata and generates the final code to call the interface function. By automatically extracting metadata and automatically generating code, it lowers the development threshold, saves manpower and time, and effectively improves the efficiency and accuracy of code generation.

[0060] Figure 2 This application provides a flowchart illustrating a document-based code generation method, as shown in the embodiments below. Figure 2 As shown, in this embodiment... Figure 1 Based on the embodiments, a document-based code generation method is described in detail, which includes:

[0061] S201. Receive initial document information, determine the file format of the initial document information, and determine the document converter corresponding to the file format of the initial document information based on a preset first association relationship; wherein, the preset first association relationship represents the association relationship between the file format and the document converter.

[0062] Exemplarily, the interface document uploaded by the user is received, i.e., initial document information is obtained. The initial document information can be in various formats, and after the initial document information is obtained, the file format of the initial document information can be determined. The file format can be determined according to the suffix of the file name. For example, if the suffix of the file name is.docx, the file format is DOCX; if the suffix of the file name is.pdf, the file format is PDF.

[0063] For documents in different formats, conversion to a preset format is required. For example, the preset format can be the format of Markdown, which is a lightweight markup language. Different formats of documents use different methods or tools when converting to Markdown. Therefore, for document information in different file formats, targeted format conversion is required.

[0064] A first association relationship is pre-set, which represents the association relationship between the file format and the document converter. The document converter is a tool for format conversion of the document, which can convert the document to the format of Markdown. After the file format of the initial document information is determined, the document converter corresponding to the file format can be found from the pre-set first association relationship. For example, for an interface document in HTML, it can be determined that an HTML converter needs to be called; for an interface document in PDF, it can be determined that a PDF converter needs to be called; and for an interface document in DOCX, it can be determined that a DOCX converter needs to be called. In this embodiment, each document converter can be an open source tool.

[0065] S202, format conversion processing is performed on the initial document information according to the document converter corresponding to the file format of the initial document information, to obtain document information in a preset format.

[0066] Exemplarily, after the corresponding document converter is determined, the document converter is used to convert the initial document information into document information in a preset format, i.e., data in the format of Markdown is obtained. The data in the format of Markdown can facilitate subsequent understanding of the large model. In this embodiment, the process of document format conversion is not limited.

[0067] In this embodiment, the initial document information is subjected to format conversion processing according to a document converter corresponding to the file format of the initial document information, to obtain document information in a preset format, including: performing title recognition processing on the initial document information to determine the titles in the initial document information and the level information of each title; determining the level identifier corresponding to the level information of each title according to a preset second association relationship; wherein the preset second association relationship represents the association relationship between the level information and the level identifier, and the level identifier represents the corresponding level information; for each title in the initial document information, the level identifier corresponding to the title is added to the initial document information to obtain first target document information; the first target document information is subjected to format conversion processing according to the document converter corresponding to the file format of the initial document information, to obtain document information in a preset format.

[0068] Specifically, the document information in a preset format is a Markdown document. To solve the problem of easy loss of titles in the converted Markdown document, the titles in the original document can be converted universally, that is, the titles in the initial document information are converted.

[0069] First, the initial document information is subjected to title recognition processing to determine the titles contained in the initial document information. For example, semantic understanding technology or a preset rule can be used to recognize the titles. Each title can correspond to its own level information, and the level information of different titles can be the same or different. The level information is the level of the title, for example, the level information of the title can be a first-level title, a second-level title, a third-level title, etc. After recognizing the titles in the document, the level information corresponding to the titles can also be determined, for example, a preset large model can be used to recognize the titles and the level information of the titles.

[0070] Different level information corresponds to different level identifiers, and the association relationship between the level information and the level identifier is preset as a second association relationship. For example, for a chapter title, the corresponding level identifier is "Heading 1"; for a first-level item title, the corresponding level identifier is "Heading 2"; for a second-level item title, the corresponding level identifier is "Heading 3".

[0071] For each title in the initial document information, the corresponding level identifier is found from the preset second association relationship according to the level information of the title. The level identifier corresponding to the title is added to the initial document information. The initial document information with the added level identifier is used as the first target document information. Then, the first target document information is subjected to format conversion processing according to the determined document converter, to obtain document information in a preset format, that is, a Markdown document.

[0072] The beneficial effect of such arrangement is that preprocessing can be performed before document conversion to improve conversion quality. For example, to solve the problem of easy loss of headings in the converted Markdown document, the headings in the original document are converted in a unified manner, such as converting "chapter title", "first-level section title", "second-level section title" in DOCX to "Heading 1", "Heading 2", "Heading 3" respectively. This significantly improves the quality of the converted Markdown document, which is beneficial to subsequent parsing and processing by large language models and improves the generation accuracy of the code.

[0073] In this embodiment, the initial document information is subjected to format conversion processing according to the document converter corresponding to the file format of the initial document information, to obtain document information in a preset format, including: analyzing the initial document information to determine redundant information in the initial document information; deleting the redundant information in the initial document information to obtain second target document information; and subjecting the second target document information to format conversion processing according to the document converter corresponding to the file format of the initial document information, to obtain document information in a preset format.

[0074] Specifically, the interface document often contains some introductory and explanatory content, such as "version change information", "introduction", "background", "appendix", "drafter", etc. These contents are helpful for users to understand the interface, but are redundant information for LLM, i.e., redundant information refers to information that does not need to appear in the code information. To improve the efficiency of subsequent large models and save valuable large model Token consumption, redundant information can be identified and deleted in the preprocessing stage. For example, the initial document information can be analyzed based on a preset semantic recognition algorithm to determine the redundant information in the initial document information. In this embodiment, the preset semantic recognition algorithm is not specifically limited. For example, the semantics of the title in the document can be recognized, and if the semantics of the title belongs to at least one of "version change information", "introduction", "background", "appendix", "drafter", etc., the text content under the title is regarded as redundant information.

[0075] After obtaining the redundant information, the redundant information is deleted from the initial document information, and the initial document information after deleting the redundant information is determined as the second target document information. Then, the second target document information is subjected to format conversion processing according to the determined document converter, to obtain document information in a preset format, i.e., to obtain a Markdown document.

[0076] The specific recognition and deletion process can be as follows: First, the entire document is split by chapter, and then titles belonging to redundant information are recognized through predefined regular rules, such as "Table of Contents", "Table Information", etc. The regular expressions used can cover multi-level Chinese and English judgments. For example, the regular expression can be "^[\s\u3000]*([\dA-Za-z一二三四五六七八九十百千万零]+[章节部分辑卷]?[、,.,。]?[\s\u3000]*)*(目录|目次|目錄|内容目录|目录索引)[\s\u3000,,.。、]*$".

[0077] The beneficial effect of such a setting is that for complex and diverse interface documents, preprocessing is performed before conversion, such as removing blank pages, deleting redundant data, etc., which significantly reduces the Token usage and improves the subsequent processing efficiency.

[0078] In this embodiment, the preprocessing process can include both the addition of title level identifiers and the deletion of redundant information. For example, redundant information can be first recognized and deleted. On the basis of deleting redundant information, the level information of the title is recognized, and the corresponding level identifier is added. Finally, format conversion is performed to obtain document information in a preset format.

[0079] S203. Determine the meta information of the interface according to the document information in the preset format; where the meta information represents the attribute description of the interface of the MCP.

[0080] Exemplarily, this step can refer to the above step S102 and will not be elaborated here.

[0081] S204. Determine the code information of the interface according to the meta information of the interface; where the code information is used to access a preset intelligent agent by calling the interface of the MCP.

[0082] Exemplarily, this step can refer to the above step S103 and will not be elaborated here.

[0083] A document-based code generation method provided by an embodiment of the present application can convert initial document information in different formats into document information in a preset format by receiving the initial document information. It realizes efficient parsing of unstructured documents such as PDF, DOCX, HTML, etc., makes the extraction of interface meta information not rely on manual work, improves the information extraction efficiency and is not prone to errors. According to the document information in the preset format, the meta information of the interface is automatically extracted, and according to the meta information of the interface, the final code is generated to realize the call of the interface function. By automatically extracting meta information and automatically generating code, the development threshold of the code can be reduced, manpower and time can be saved, and the code generation efficiency and accuracy can be effectively improved.

[0084] Figure 3A flowchart of a code generation method based on a document provided by an embodiment of the present application is shown in Figure 3 As shown in Figure 1 and Figure 2 The embodiment is based on the above-mentioned embodiments, and a code generation method based on a document is described in detail, which comprises the following steps.

[0085] S301, receiving initial document information, and converting the initial document information into document information in a preset format; wherein the document information represents the manner required by the calling interface, and the preset format represents the format of the preset specification document of the model context protocol (MCP).

[0086] By way of example, this step can refer to the above-mentioned step S101, and will not be described again.

[0087] S302, determining the document type of the document information in the preset format based on a preset semantic understanding technology; wherein the document type comprises a first type and a second type, the first type represents that the document information only describes one interface, and the second type represents that the document information describes at least two interfaces.

[0088] By way of example, after obtaining the document information in the preset format, the preset semantic understanding technology can be used to perform semantic understanding on the document information in the preset format. According to the result of semantic understanding, the document type of the document information in the preset format is determined. The document type can represent the complexity of the structure of the document information. For example, the document type can be divided into the first type and the second type. For a document with simple content and clear structure, it can be the first type, and for a more complex document, it can be the second type. In the embodiment, the number of interfaces described in the document can be used to determine the complexity of the document. The first type represents that the document information only describes the related content of one interface, and the second type represents that the document information describes the related content of at least two interfaces.

[0089] That is, based on the preset semantic understanding technology, all the interfaces contained in the document information are identified, and the number of interfaces is determined. If the number of interfaces is 1, the document type is determined to be the first type; if the number of interfaces is greater than 1, the document type is determined to be the second type.

[0090] S303, determining the initial information of the interface from the document information in the preset format according to the document type of the document information in the preset format; wherein the initial information is the information of the attribute description of the interface extracted from the document information.

[0091] Exemplarily, different manners can be adopted to extract the information related to the interface from the document information in the preset format as the initial information for different document types. That is, the initial information is the information directly obtained from the document and represents the attribute description of the interface extracted from the document information. Different information extraction algorithms can be preconfigured for different document types, so as to realize the targeted extraction of the initial information.

[0092] In this embodiment, the initial information of the interface is determined from the document information in the preset format according to the document type of the document information in the preset format, including: if the document type of the document information in the preset format is the first type, the initial information of the interface is extracted from the document information in the preset format according to the preset information extraction rule.

[0093] Specifically, if it is determined that the document type of the document information in the preset format is the first type, it can be considered that the document information in the preset format is an interface document with concise content and clear structure, for example, the document information only describes the request and response information of a single interface. For this case, the information extraction rule is pre-set, and the initial information of the interface is directly extracted based on the preset information extraction rule. For example, the preset information extraction rule is to identify a specific character in the document information, and the content of a preset number of characters after the specific character is taken as the initial information.

[0094] After determining that the document information in the preset format is of the first type, it can also be judged whether the document information contains security information. The security information refers to the content related to the security of the message of the interface, for example, it can be a signature verification or Authorization mechanism. If the document information in the preset format does not involve security information, the initial information can be directly extracted according to the preset information extraction rule.

[0095] If the document information in the preset format involves security information, the type of signature verification and other information can be extracted from the security information, and based on the preset association relationship, an algorithm corresponding to the type of signature verification is determined, which represents that the message of the interface needs to be signed and verified by the algorithm. Then, information is extracted from the document information in the preset format according to the preset information extraction rule, and the extracted information and the determined algorithm are taken as the initial information of the interface.

[0096] The beneficial effect of such setting is that whether the document belongs to the type of only describing the request and response information of a single interface is distinguished, if it belongs to this type, the interface information is directly extracted, the determination efficiency of the meta information is improved, and the generation efficiency of the code is further improved.

[0097] In this embodiment, the initial information of the interface is determined from the preset format document information according to the document type of the preset format document information, including: if the document type of the preset format document information is the second type, the preset format document information is split to obtain at least two document blocks; for each document block, the content type of the document block is determined based on the preset first model; wherein the content type represents the type of the content in the document block, and the preset first model is used to identify the content type of the document block; the key information is extracted from the document block according to the content type of the document block; wherein the key information represents the information related to the interface in the document block; and the initial information of all interfaces in the preset format document information is determined according to the key information of each document block.

[0098] Specifically, if it is determined that the document type of the preset format document information is the second type, it can be considered that the preset format document information belongs to a more complex document. In order to overcome the limitation of the number of Token input by the large model, the preset format document information can be split into multiple document blocks. For example, the preset format document information can be split into multiple document blocks according to the title, and one title corresponds to one document block. The first model is preset, and the first model is a large model, which can be used as a document block recognition agent to identify the content type of the document block. For each document block, the content type of the document block can be determined by means of the preset first model and the preset prompt word, that is, it is determined that the content in the document block belongs to what type of content. For example, there are six types of content, which are type0, type1, type2, type3, type4, type5 and type6.

[0099] The prompt word is a pre-set text, and an example of the prompt word is as follows:

[0100] "## Role

[0101] You are a Markdown format interface document content type identification expert who can accurately identify the Markdown content type given by the user, and the type definition is as follows:

[0102] 1. The document contains signature mechanism or method, signature verification mechanism or method, encryption mechanism or method, decryption mechanism or method, and explains how to sign, verify, encrypt and decrypt the message field. It is type1

[0103] 2. Explain the message organization method, which is type2

[0104] 3. It involves interface field description, such as request, response and message field description, which is type3

[0105] 4. It contains the message request address, which is type4

[0106] 5. The content related to the symbol convention, such as the content related to the field in the message being mandatory, optional, mandatory under the condition, etc., is type 5

[0107] 6. The content other than the above, or the content inferred to be meaningless, is type 0

[0108] 7. If the above content is contained at the same time, such as type 3 related to the interface field description and type 4 related to the message request address, multiple types need to be returned, and are connected with underscores, such as type3_type4

[0109] ## Skills

[0110] ### Skill 1: Accurately read and understand the interface document in Markdown format, distinguish the content type, and accurately return the content type, the content type value is only "type0", "type1", "type2", "type3", "type4", "type5"

[0111] ### Skill 2: Return "type0" if the content type cannot be distinguished

[0112] ## Limitations

[0113] ### Limitation 1: Cannot answer other content, only answer "type0", "type1", "type2", "type3", "type4", "type5", or multiple types connected with underscores, such as "type3_type4"

[0114] ### Limitation 2: Answer "type0" if the answer is not accurate

[0115] Based on the above prompt words, the document block recognition agent can accurately identify the content type of each document block. Different information extraction prompt words are set in advance for different content types. The information extraction prompt words are different from the prompt words used to identify the content type. An information extraction agent is set in advance, and the information extraction agent uses the corresponding information extraction prompt word to extract key information from the document block. The key information represents the information related to the interface in the document block, which is part of the initial information. For example, for a document block of type3_type4_type5, the interface name, request / response field, default value, mandatory / optional field, etc. can be extracted as key information; for a document block of type2, the interface type and message format can be extracted as key information. Combining the key information in each document block, the initial information of all interfaces in the preset format of the document information is obtained. For example, the key information of the document block can be arranged according to the order of the document block in the document information.

[0116] The beneficial effect of such an arrangement is that for more complex documents, the document is split into multiple independent parts, the content type of the document block is determined with the aid of a large model, key information is extracted for different types, and initial information is obtained by integration, avoiding the omission of initial information and improving the accuracy and efficiency of subsequent meta-information determination.

[0117] In S304, according to the initial information of the interface, meta-information of the interface is generated based on a preset information template; the preset information template is in JSON format.

[0118] For example, an information template of interface meta-information is preset, and after obtaining the initial information, the initial information can be supplemented into the information template to generate complete interface meta-information. In this embodiment, the preset information template is in JSON format, that is, the interface meta-information is in JSON format. That is, according to the extracted initial information, the JSON data of the interface is generated by combining the preset JSON format template, as the interface meta-information.

[0119] In S305, code information of the interface is determined according to the meta-information of the interface; the code information is used to access a preset agent through an interface of an MCP.

[0120] For example, this step can refer to the above-mentioned step S103, and will not be described again.

[0121] In this embodiment, a multi-agent application is constructed based on the Lang chain agent framework, and the Lang chain is a framework for developing applications driven by large language models. Based on the powerful capabilities of LLM, it can quickly and accurately analyze natural language description of unstructured interface documents and create MCP Server code corresponding to the interface. Figure 4 The interaction process diagram between the multi-agent. Figure 4In the specific implementation, the user uploads initial document information, pre-processes the initial document information, and then performs file format recognition on the pre-processed document information to determine a corresponding document converter. For example, the document converter can be a PDF converter, a DOCX converter, an HTML converter, a JSON converter, or the like. The corresponding document converter is used to generate Markdown data, i.e., document information in a preset format. The document information in the preset format is input to a multi-agent structure of a Lang chain, which includes a document parsing agent, a document block identification agent, a meta information extraction agent, an information verification agent, and an MCP server generation agent. The document parsing agent can be used to parse the Markdown to determine the document type. The document block identification agent can be used to split the document block to determine the content type of the document block. The meta information extraction agent is used to extract interface meta information. The information verification agent is used to verify the accuracy and integrity of the interface meta information. The MCP server generation agent is used to generate code information.

[0122] The code generation method based on a document provided in the embodiments of the present application can convert initial document information in different formats into document information in a preset format by receiving the initial document information. The code generation method based on a document provided in the embodiments of the present application can efficiently parse non-structured documents such as PDF, DOCX, and HTML, so that the extraction of interface meta information does not depend on manual operation, improves the information extraction efficiency, and is less likely to make mistakes. According to the document information in the preset format, the meta information of the interface is automatically extracted, and the final code is generated according to the meta information of the interface, so that the function of the interface can be called. By automatically extracting the meta information and automatically generating the code, the development threshold of the code can be reduced, the manpower and time can be saved, and the generation efficiency and precision of the code can be effectively improved.

[0123] Figure 5 A flowchart of a code generation method based on a document provided in the embodiments of the present application is shown in FIG. 1. Figure 5 The embodiments of the present application are based on the embodiments of the present application, and a code generation method based on a document is described in detail. The method comprises the following steps. Figures 1-4 The embodiments of the present application are based on the embodiments of the present application, and a code generation method based on a document is described in detail. The method comprises the following steps.

[0124] S501, receiving initial document information, and converting the initial document information into document information in a preset format; wherein the document information represents a mode required for calling an interface, and the preset format represents a format of a preset specification document of a model context protocol (MCP).

[0125] By way of example, this step can refer to step S101 described above, and will not be described again.

[0126] S502, determining meta information of an interface according to the document information in the preset format; wherein the meta information represents a property description of the interface.

[0127] Exemplarily, the step can refer to the step S102 described above, and will not be described again.

[0128] S503, if the interface meta-information contains security information, performing feature extraction processing on the security information to obtain a feature vector of the security information; wherein the security information represents message signature and authorization mechanism.

[0129] Exemplarily, whether the interface meta-information contains security information can be determined by directly performing semantic recognition on the interface meta-information to determine whether the interface meta-information contains related semantics of security information. If yes, it is determined that the interface meta-information contains security information. If no, it is determined that the interface meta-information does not contain security information. Alternatively, the content type of each document block can be determined. If the content type contains type1, it is determined that the interface meta-information contains security information. If the content type does not contain type1, it is determined that the interface meta-information does not contain security information.

[0130] If it is determined that the interface meta-information does not contain security information, the interface meta-information is filled in the corresponding position in the code template to obtain complete code information. If it is determined that the interface meta-information contains security information, feature extraction processing can be performed on the security information based on a preset feature extraction network to obtain a feature vector of the security information. The security information can be a text description of message signature and authorization mechanism, i.e., the feature vector can be a text vector. NLP (Natural Language Processing) technology can be used to determine the feature vector of the security information.

[0131] S504, according to the feature vector of the security information, searching for a code segment corresponding to the security information from a preset vector database; wherein the preset vector database includes a plurality of code segments, and the code segment is partial code information.

[0132] Exemplarily, a vector database is preset, and a large number of code segments are stored in the vector database. Different code segments correspond to different security information, so that a code segment corresponding to the security information can be searched from the preset vector database. For example, each code segment is associated with a feature vector. If the feature vector of the security information is completely consistent with the feature vector of the code segment, the code segment is determined as the code segment corresponding to the security information, and the code segment is part of the code information.

[0133] In this embodiment, according to the feature vector of the security information, a code segment corresponding to the security information is searched from a preset vector database, including: for each code segment in the preset vector database, performing feature extraction processing on the code segment to obtain a feature vector of the code segment; determining a second similarity between the feature vector of the security information and the feature vector of the code segment; if the second similarity satisfies a preset condition, determining the code segment corresponding to the second similarity as the code segment corresponding to the security information.

[0134] Specifically, for each code segment in the vector database, a preset feature extraction network can be used to perform feature extraction processing on the code segment to obtain a feature vector of the code segment. The feature vectors of the respective code segments can also be pre-stored in the vector database, and the feature vectors represent the text description related to the security information corresponding to the code segment.

[0135] The feature vector of the security information and the feature vector of each code segment are respectively calculated for similarity to obtain the similarity between the feature vector of the security information and the feature vector of the code segment as the second similarity. The second similarity represents the consistency between the feature vector of the security information and the feature vector of the code segment, and the second similarity can be determined by using the calculation method of the cosine similarity to realize the matching at the semantic level.

[0136] A judgment condition of the second similarity is pre-set, and the code segment corresponding to the second similarity that satisfies the preset condition is determined as the code segment corresponding to the security information. For example, the preset condition can be that the code segment with the maximum second similarity is determined as the code segment corresponding to the security information.

[0137] The beneficial effect of such setting is that, in view of the problem of low quality of security information related code in practice, the cross-modal retrieval technology between natural language and code is introduced, the cosine similarity between the text vector of the security information in the interface document and the vector of the code segment is calculated by using the NLP embedding model, and the matching at the semantic level is realized. The code segment with high matching degree related to the security information can be effectively retrieved, and the reliability of code generation is improved.

[0138] S505, according to the meta information of the interface and the code segment corresponding to the security information, generating code information of the interface based on a preset code template.

[0139] Exemplarily, a code template is preset, and the code template can have no position of security information. The interface element information is filled in the code template, that is, the code except the security information is obtained as initial code. The code segment determined in S504 is combined, that is, the complete code information is obtained. For example, the code segment can be inserted into the preset position in the initial code to obtain the code information. The code segment with high matching degree related to the security information is effectively searched out, and the reliable and usable code information is generated by combining the code template.

[0140] In this embodiment, the code information of the interface is determined according to the element information of the interface, including: determining the identification information of each interface, displaying the identification information of each interface on the visual interface; determining a target interface from the interfaces in response to an interface selection operation made by a user; and determining the code information of the target interface according to the element information of the target interface.

[0141] Specifically, for the operation of the user, the user can upload the initial document information through the visual interface. After the user uploads, the user can click “analysis” on the interface to start processing the initial document information. That is, the initial document information can be converted into document information in a preset format, and the interfaces and the element information of each interface contained in the document information in the preset format are determined.

[0142] Each interface corresponds to unique identification information, and each identification information is preset. After the interfaces contained in the document information are determined, the identification information of the interfaces is determined, and the determined identification information is displayed on the visual interface. The user can select one or more interfaces on the interface, that is, the user can make an interface selection operation to determine the interfaces selected by the user as target interfaces. After the user selects the target interfaces, the user can issue a code generation instruction. In response to the code generation instruction, the element information of the target interfaces is acquired, and the code information of the target interfaces is automatically generated. Figure 6 The interface schematic diagram for interface selection. Figure 6 Five interfaces are displayed on the interface, the user selects the “consumer transaction” interface, and then clicks “generate code package” to automatically generate the code information of the “consumer transaction”. The generated code information can be displayed on the visual interface for the user to view and download.

[0143] The beneficial effect of such a setting is that for the user, the code information can be generated through simple operation, without the need for professional R&D personnel to write code, saving manpower and time, and greatly reducing the difficulty of user access to the business system.

[0144] The code generation method based on a document provided by the embodiment of the application can convert initial document information in different formats into document information in a preset format by receiving the initial document information. The method can efficiently parse non-structured documents such as PDF, DOCX, and HTML, so that the extraction of interface meta information does not depend on manual operation, improves the information extraction efficiency, and is less prone to errors. According to the document information in the preset format, the meta information of the interface is automatically extracted, and the final code is generated according to the meta information of the interface, so that the function of the interface is called. By automatically extracting the meta information and automatically generating the code, the development threshold of the code can be reduced, the manpower and time can be saved, and the generation efficiency and accuracy of the code can be effectively improved.

[0145] Figure 7 The structure diagram of the code generation device based on a document provided by the embodiment of the application is shown in FIG. 7, and the code generation device 70 provided by the embodiment of the application includes: Figure 7

[0146] The format conversion unit 701 is configured to receive initial document information and convert the initial document information into document information in a preset format. The document information represents a manner required for calling an interface, and the preset format represents a format of a preset specification document of a model context protocol (MCP).

[0147] The information determination unit 702 is configured to determine meta information of the interface according to the document information in the preset format. The meta information represents a property description of the interface of the MCP.

[0148] The code generation unit 703 is configured to determine code information of the interface according to the meta information of the interface. The code information is used to access a preset intelligent agent by calling the interface of the MCP.

[0149] In a possible implementation, the format conversion unit 701 includes:

[0150] The converter determination module is configured to determine a file format of the initial document information, determine a document converter corresponding to the file format of the initial document information based on a preset first association relationship, and determine the association relationship between the file format and the document converter.

[0151] The format conversion module is configured to perform format conversion processing on the initial document information according to the document converter corresponding to the file format of the initial document information, and obtain the document information in the preset format.

[0152] In a possible implementation, the format conversion module is specifically configured to:

[0153] perform title recognition processing on the initial document information, and determine titles in the initial document information and level information of each title.​

[0154] determine a level identifier corresponding to the level information of each title according to a preset second association relationship; wherein, the preset second association relationship represents an association relationship between the level information and the level identifier, and the level identifier represents the corresponding level information;

[0155] add the level identifier corresponding to the title to the initial document information to obtain first target document information for each title in the initial document information;

[0156] perform format conversion processing on the first target document information according to a document converter corresponding to the file format of the initial document information to obtain the document information in the preset format.

[0157] In a possible implementation, the format conversion module is specifically configured to:

[0158] analyze the initial document information to determine redundant information in the initial document information;

[0159] delete the redundant information in the initial document information to obtain second target document information;

[0160] perform format conversion processing on the second target document information according to a document converter corresponding to the file format of the initial document information to obtain the document information in the preset format.

[0161] In a possible implementation, the information determination unit 702 includes:

[0162] a type determination module configured to determine a document type of the document information in the preset format based on a preset semantic understanding technology; wherein, the document type includes a first type and a second type, the first type represents that the document information describes only one interface, and the second type represents that the document information describes at least two interfaces;

[0163] an initial determination module configured to determine initial information of the interface from the document information in the preset format according to the document type of the document information in the preset format; wherein, the initial information is information of a property description of the interface extracted from the document information;

[0164] a meta-information determination module configured to generate meta-information of the interface based on a preset information template according to the initial information of the interface; wherein, the preset information template is in a JSON format.

[0165] In a possible implementation, the initial determination module is specifically configured to:

[0166] if the document type of the document information in the preset format is the first type, extract the initial information of the interface from the document information in the preset format according to a preset information extraction rule.

[0167] In a possible implementation, the initial determining module is specifically configured to:

[0168] If the document type of the document information in the preset format is the second type, the document information in the preset format is split to obtain at least two document blocks;

[0169] For each document block, a content type of the document block is determined based on a preset first model, where the content type represents a type of content in the document block, and the preset first model is used to identify the content type of the document block.

[0170] According to the content type of the document block, key information is extracted from the document block, where the key information represents information related to the interface in the document block.

[0171] According to the key information of each document block, initial information of all interfaces in the document information in the preset format is determined.

[0172] In a possible implementation, the method further includes:

[0173] The similarity determining unit is configured to input the document information in the preset format and the meta information into a preset second model to obtain an output first similarity, where the preset second model is used to determine a similarity between the document information in the preset format and the meta information, and the first similarity represents the similarity between the document information in the preset format and the meta information.

[0174] The similarity comparing unit is configured to, if the first similarity is greater than a preset similarity threshold, execute the determining of the code information of the interface according to the meta information of the interface.

[0175] In a possible implementation, the code generating unit 703 includes:

[0176] The feature extraction module is configured to, if the meta information of the interface contains security information, perform feature extraction processing on the security information to obtain a feature vector of the security information, where the security information represents message signature and authorization mechanism.

[0177] The fragment determining module is configured to search, according to the feature vector of the security information, a code fragment corresponding to the security information from a preset vector database, where the preset vector database includes a plurality of code fragments, and the code fragment is partial code information.

[0178] The code generating module is configured to generate, according to the meta information of the interface and the code fragment corresponding to the security information, the code information of the interface based on a preset code template.

[0179] In a possible implementation, the fragment determining module is specifically configured to:

[0180] For each code snippet in the preset vector database, feature extraction is performed on the code snippet to obtain a feature vector of the code snippet;

[0181] determining a second similarity between the feature vector of the security information and the feature vector of the code snippet;

[0182] If the second similarity meets a preset condition, the code snippet corresponding to the second similarity is determined as the code snippet corresponding to the security information.

[0183] In a possible implementation, the code generation unit 703 comprises:

[0184] An identification display module is configured to display the identification information of each interface on the visual interface after determining the meta information of the interface;

[0185] An interface selection module is configured to determine a target interface from the interfaces in response to an interface selection operation made by a user.

[0186] A code determination module is configured to determine the code information of the target interface according to the meta information of the target interface.

[0187] The code generation apparatus based on a document provided in this embodiment can execute the method provided in the method embodiments, and has similar implementation principles and technical effects, which will not be described here in detail.

[0188] Figure 8 A structural schematic diagram of an electronic device provided in this application is shown in FIG. 8. Figure 8 As shown in FIG. 8, the electronic device 80 provided in this embodiment comprises at least one processor 801 and a memory 802. Optionally, the device 80 further comprises a communication component 803. The processor 801, the memory 802 and the communication component 803 are connected through a bus 804.

[0189] In the specific implementation process, the at least one processor 801 executes the computer execution instructions stored in the memory 802, so that the at least one processor 801 executes the method described above.

[0190] The specific implementation process of the processor 801 can refer to the method embodiments described above, and has similar implementation principles and technical effects, which will not be described here in detail.

[0191] In the above embodiments, it should be understood that the processor can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the application can be directly embodied as hardware processor execution, or executed by a combination of hardware and software modules in the processor.

[0192] The memory can include a random access memory (RAM), and can also include a non-volatile memory (NVM), such as at least one disk memory.

[0193] The bus can be an industry standard architecture (ISA) bus, a peripheral component (PCI) bus, or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application does not limit to only one bus or one type of bus.

[0194] The present application also provides a computer program product, comprising a computer program, which, when executed by a processor, implements the above method.

[0195] The present application also provides a computer readable storage medium, which stores computer execution instructions, and when a processor executes the computer execution instructions, the above method is implemented.

[0196] The above readable storage medium 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 memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.

[0197] An example readable storage medium is coupled to the processor such that the processor can read information from the readable storage medium and can write information to the readable storage medium. Of course, the readable storage medium can also be a part of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in the device.

[0198] The division of units is only a logical functional division, and in actual implementation, there can be another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.

[0199] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, that is, can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.

[0200] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit.

[0201] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the part of the present application that essentially contributes to the prior art or the part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The foregoing storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various program code storage media.

[0202] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware. The foregoing program can be stored in a computer readable storage medium. The program executes to perform the steps of the above-mentioned method embodiments; and the foregoing storage medium includes various media capable of storing program codes, such as ROM, RAM, magnetic disk, or optical disk.

[0203] Finally, it should be noted that other embodiments of the present application will readily occur to those skilled in the art upon consideration of the specification and practice of the present application disclosed herein. The present application is intended to include all such variations as fall within the general scope of the application, and includes the generic principles disclosed and the best mode known to the inventors to be currently practiced as well as variations thereof, without departing from the scope of the present application as defined by the claims. The specification and examples give the best application of the present application as currently known, and together with the description of the application serve to best illustrate the principles of the application. The scope of the application is expressly set forth in the claims.

Claims

1. A code generation method based on a document, characterized by, The method comprises the following steps: receiving initial document information, and converting the initial document information into document information in a preset format; wherein the document information represents a manner required for calling an interface, and the preset format represents a format of a preset specification document of a model context protocol (MCP) ; determining meta information of the interface according to the document information in the preset format; wherein the meta information represents an attribute description of the interface of the MCP; determining code information of the interface according to the meta information of the interface; wherein the code information is used to access a preset agent through calling the interface of the MCP.

2. The method of claim 1, wherein, The method of converting the initial document information into document information in a preset format comprises the following steps: determining a file format of the initial document information, and determining a document converter corresponding to the file format of the initial document information based on a preset first association relationship; wherein the preset first association relationship represents an association relationship between a file format and a document converter; performing format conversion processing on the initial document information according to the document converter corresponding to the file format of the initial document information, to obtain the document information in the preset format.

3. The method of claim 2, wherein, The method of performing format conversion processing on the initial document information according to the document converter corresponding to the file format of the initial document information, to obtain the document information in the preset format, comprises the following steps: performing title recognition processing on the initial document information, to determine titles in the initial document information and level information of each title; determining a level identifier corresponding to the level information of each title according to a preset second association relationship; wherein the preset second association relationship represents an association relationship between level information and a level identifier, and the level identifier represents corresponding level information; for each title in the initial document information, adding the level identifier corresponding to the title to the initial document information, to obtain first target document information; performing format conversion processing on the first target document information according to the document converter corresponding to the file format of the initial document information, to obtain the document information in the preset format.

4. The method of claim 2, wherein, The method of performing format conversion processing on the initial document information according to the document converter corresponding to the file format of the initial document information, to obtain the document information in the preset format, comprises the following steps: performing analysis on the initial document information, to determine redundant information in the initial document information; deleting the redundant information in the initial document information, to obtain second target document information; performing format conversion processing on the second target document information according to the document converter corresponding to the file format of the initial document information, to obtain the document information in the preset format.

5. The method of claim 1, wherein, The method of determining meta information of the interface according to the document information in the preset format comprises the following steps: determining a document type of the document information in the preset format based on a preset semantic understanding technology; wherein the document type comprises a first type and a second type, the first type represents that the document information describes only one interface, and the second type represents that the document information describes at least two interfaces. According to a document type of the document information in the preset format, initial information of the interface is determined from the document information in the preset format; wherein the initial information is information of attribute description of the interface extracted from the document information; According to the initial information of the interface, meta information of the interface is generated based on a preset information template; wherein the preset information template is in a JSON format.

6. The method of claim 5, wherein, According to a document type of the document information in the preset format, initial information of the interface is determined from the document information in the preset format, comprising: If the document type of the document information in the preset format is a first type, the initial information of the interface is extracted from the document information in the preset format according to a preset information extraction rule.

7. The method of claim 5, wherein, According to a document type of the document information in the preset format, initial information of the interface is determined from the document information in the preset format, comprising: If the document type of the document information in the preset format is a second type, the document information in the preset format is split to obtain at least two document blocks; For each document block, a content type of the document block is determined based on a preset first model; wherein the content type represents a type of content in the document block, and the preset first model is used to identify the content type of the document block; According to the content type of the document block, key information is extracted from the document block; wherein the key information represents information related to the interface in the document block; According to the key information of each document block, initial information of all interfaces in the document information in the preset format is determined.

8. The method of claim 1, wherein, Further comprising: The document information in the preset format and the meta information are input into a preset second model to obtain an output first similarity; wherein the preset second model is used to determine a similarity between the document information in the preset format and the meta information, and the first similarity represents the similarity between the document information in the preset format and the meta information; If the first similarity is greater than a preset similarity threshold, the determination of the code information of the interface according to the meta information of the interface is performed.

9. The method of claim 1, wherein, According to the meta information of the interface, the code information of the interface is determined, comprising: If the meta information of the interface contains security information, feature extraction processing is performed on the security information to obtain a feature vector of the security information; wherein the security information represents message signature and authorization mechanism; According to the feature vector of the security information, a code segment corresponding to the security information is searched from a preset vector database; wherein the preset vector database includes a plurality of code segments, and the code segment is partial code information; According to the meta information of the interface and the code segment corresponding to the security information, the code information of the interface is generated based on a preset code template.

10. The method of claim 9, wherein, According to the feature vector of the security information, a code segment corresponding to the security information is searched from a preset vector database, comprising: For each code segment in the preset vector database, feature extraction processing is performed on the code segment to obtain a feature vector of the code segment; determining a second similarity between a feature vector of the security information and a feature vector of the code segment; if the second similarity satisfies a preset condition, determining the code segment corresponding to the second similarity as the code segment corresponding to the security information.

11. The method according to any one of claims 1-10, characterized in that, determining code information of the interface according to the meta information of the interface, comprising: determining identification information of each interface, and displaying the identification information of each interface on a visual interface; in response to an interface selection operation made by a user, determining a target interface from the interfaces; determining code information of the target interface according to the meta information of the target interface.

12. A document-based code generation apparatus characterized by comprising: comprising: a format conversion unit, configured to receive initial document information, and convert the initial document information into document information in a preset format; wherein the document information represents a manner required for calling an interface, and the preset format represents a format of a preset specification document of a model context protocol (MCP) ; an information determination unit, configured to determine meta information of the interface according to the document information in the preset format; wherein the meta information represents an attribute description of an interface of the MCP; a code generation unit, configured to determine code information of the interface according to the meta information of the interface; wherein the code information is used to access a preset intelligent agent by calling the interface of the MCP.

13. An electronic device, comprising: comprising: a memory and a processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory, so that the processor executes the method according to any one of claims 1-11.

14. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer execution instructions, and the computer execution instructions are executed by the processor to implement the method according to any one of claims 1-11.

15. A computer program product, characterised in that, comprising a computer program, which is executed by the processor to implement the method according to any one of claims 1-11.