Method and device for calling API (Application Program Interface) in question answering system, computer equipment and medium

By building API configuration sets and dynamic matching technology, the question-answering system can efficiently call multiple types of APIs, solve the problem of processing users' spoken questions, achieve natural language continuity and context understanding, and improve user experience.

CN120653747APending Publication Date: 2025-09-16QI AN XIN TECHNOLOGY GROUP INC
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510792861.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-13
Publication Date
2025-09-16

AI Technical Summary

Technical Problem

When dealing with users' incomplete and colloquial natural language questions, question-answering systems find it difficult to efficiently call the APIs of different systems to generate clear answers, and lack effective use of contextual information.

Method used

By building an API configuration set, including the request address, description information, request type, and parameter passing method, combining user input and historical conversations, dynamically matching the target API, and performing parameter formatting and request structure construction, unified, intelligent, and efficient calls to multiple types of APIs can be achieved.

Benefits of technology

It improves the practicality and intelligence of the question-answering system in complex business scenarios, reduces dependence on code-layer API access logic, enhances the ability to understand natural language continuity and context, and supports multiple rounds of interactive questioning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120653747A_ABST
    Figure CN120653747A_ABST
Patent Text Reader

Abstract

The invention provides a calling method and device for an API in a question answering system, computer equipment and a medium. The method comprises the steps of determining a to-be-called target API from a preset API configuration set according to current input and description information in API configuration; parameters required by the target API are determined according to the current input and historical dialogues, and a target parameter set is obtained; formatting the target parameter set according to the request type of the target API; filling the formatted parameters into a request structure according to a parameter transmission mode of the target API; and executing an API request operation according to the request structure and the request address of the target API. According to the invention, the practicability, the intelligent level and the user experience of the question answering system in a complex service scene are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, computer equipment, and medium for calling an API in a question-and-answer system. Background Art

[0002] A question-answering system is a human-computer interaction system based on natural language processing technology and knowledge acquisition mechanism. It can receive natural language questions raised by users and generate and output structured or natural language answers through information retrieval, rule processing or external data interface (API) calls.

[0003] The inventors' research found that the question-answering system is different from the current mainstream retrieval technology in four aspects: first, the natural language questions asked by users are usually incomplete and colloquial; second, the optimal response should be a string of characters with a clear answer, and the user does not need to think about what kind of question to use to get the required answer; third, users have real-time feedback requirements for the answers; and fourth, the information contained in the context needs to be extracted and retained by the question-answering system, rather than the user including all the question information every time he asks a question.

[0004] Therefore, in question-answering systems, how to better obtain data from different systems by calling APIs to generate answers has become a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0005] The purpose of the present invention is to provide a method, device, computer equipment and medium for calling an API in a question-and-answer system, so as to solve the above-mentioned technical problems in the prior art.

[0006] On the one hand, to achieve the above-mentioned purpose, the present invention provides a method for calling an API in a question-answering system.

[0007] The API calling method in the question-and-answer system includes: determining the target API to be called from a preset API configuration set based on the current input and the description information in the API configuration, wherein the API configuration set includes multiple API configurations, and the API configuration includes the request address, the description information, the request type and the parameter passing method; determining the parameters required for the target API based on the current input and historical conversations to obtain a target parameter set; formatting the target parameter set according to the request type of the target API; filling the formatted parameters into the request structure according to the parameter passing method of the target API; and executing the API request operation according to the request structure and the request address of the target API.

[0008] Furthermore, the API configuration is completed through the following configuration steps: in response to the address input step, setting the API request address; in response to the information input step, setting the API description information; in response to the type selection step, setting the API request type; configuring the API parameter passing method, wherein, when the API adopts the URL method to pass parameters, configure the parameter name, parameter type and parameter description of each parameter; when the API adopts the form-data method to pass parameters, first configure the default JSON request body of the single-layer structure, and then configure the parameter name of each parameter, the jsonpath path of the parameter in the JSON request body and the parameter description; when the API adopts the JSON method to pass parameters, configure the default JSON request body, and then configure the parameter name of each parameter, the jsonpath path of the parameter in the JSON request body and the parameter description.

[0009] Furthermore, the API configuration also includes a reply template, and the configuration step also includes: configuring the reply template in the form of a Jinja2 template, wherein the reply template is used to generate user-oriented question and answer reply content based on the return value and request parameters of the API request.

[0010] Furthermore, the step of filling the formatted parameters into the request structure according to the parameter passing method of the target API includes: when the formatted parameters include URL parameters, splicing the URL parameters into the request address in the form of key-value pairs using equal signs; when the formatted parameters include form-data parameters or JSON parameters, filling the parameters into the corresponding positions of the JSON request body according to the configured jsonpath path.

[0011] Furthermore, the parameters required for the target API are determined based on the current input and historical conversations, and the step of obtaining the target parameter set includes: extracting the parameters in the current input to obtain the current parameter set; obtaining the global parameter set corresponding to the historical conversation; judging whether the current parameter set includes a first parameter, wherein the first parameter is a parameter with the same parameter name as the parameter name in the global parameter set, and the parameters in the global parameter set other than the first parameter are second parameters; and if the current parameter set includes the first parameter, determining that the current parameter set and the second parameter are the target parameter set.

[0012] Furthermore, the parameters required for the target API are determined based on the current input and historical conversations, and the step of obtaining the target parameter set also includes: if the current parameter set does not include the first parameter, merging the current parameter set and the global parameter set to obtain a merged parameter set; obtaining the cache parameter set of the target API; judging whether the current parameter set includes a third parameter, wherein the third parameter is a parameter with the same parameter name as the parameter name in the cache parameter set, and the parameters in the cache parameter set other than the third parameter are fourth parameters; if the current parameter set includes the third parameter, determining the merged parameter set and the fourth parameter as the target parameter set; and if the current parameter set does not include the third parameter, using the merged parameter set and the cache parameter set as the target parameter set.

[0013] Furthermore, after obtaining the target parameter set, the method further includes: updating the global parameter set using the global parameters in the current parameter set; and updating the cache parameter set of the target API using the non-global parameters in the current parameter set.

[0014] On the other hand, to achieve the above-mentioned purpose, the present invention provides a device for calling an API in a question-answering system.

[0015] The API calling device in the question-and-answer system includes: a first determination module, used to determine the target API to be called from a preset API configuration set based on the current input and the description information in the API configuration, wherein the API configuration set includes multiple API configurations, and the API configuration includes the request address, the description information, the request type and the parameter passing method; a second determination module, used to determine the parameters required for the target API based on the current input and historical conversations to obtain a target parameter set; a first processing module, used to format the target parameter set according to the request type of the target API; a second processing module, used to fill the formatted parameters into the request structure according to the parameter passing method of the target API; a request module, used to execute the API request operation according to the request structure and the request address of the target API.

[0016] On the other hand, to achieve the above objectives, the present invention also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0017] On the other hand, to achieve the above object, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the above method when executed by a processor.

[0018] The API calling method, device, computer equipment and medium in the question-and-answer system provided by the present invention abstract each API into a unified data structure, and the configuration includes request address, description information, request type and parameter passing method, forming an API configuration set that can be identified and reused. The system performs semantic matching based on the user's current input and the description information of each API, and automatically determines the target API most relevant to the user's intention from the configuration set. The system not only extracts the parameters in the current input, but also identifies missing parameters in combination with historical conversation content, constructs a complete target parameter set, and standardizes and formats the parameter set according to the request type of the target API, and fills the parameters into the corresponding request structure according to the parameter passing method, and combines the constructed request structure with the address of the target API to complete the API request execution operation and obtain real-time response results. The API calling method provided by the present invention is aimed at the question-and-answer system scenario. Through the combination of mechanisms such as structured configuration, dynamic matching, context parameter completion and automatic request structure construction, it realizes the unified, intelligent and efficient calling capability of multiple types of APIs. It not only reduces the dependence on the code layer API access logic, improves the modularity and maintainability of the system, but also enhances the question-and-answer system's ability to understand the continuity and context of natural language, so that users can complete continuous queries or multiple rounds of interactive questions without repeated descriptions, thereby improving the practicality, intelligence level and user experience of the question-and-answer system in complex business scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present invention. The same reference symbols are used throughout the drawings to represent the same components. In the drawings: Figure 1 This is a flowchart of a method for calling an API in a question-and-answer system provided in the first embodiment of the present invention; Figure 2 A schematic diagram of the API configuration process in the question-and-answer system provided by an embodiment of the present invention; Figure 3 A schematic diagram of the API call process in the question-and-answer system provided by an embodiment of the present invention; Figure 4 A schematic diagram of the API context parameter transfer process in the question-answering system provided by an embodiment of the present invention; Figure 5 A block diagram of an API calling device in a question-and-answer system provided in the second embodiment of the present invention; Figure 6 This is a hardware structure diagram of the computer device provided in Example 3 of the present invention. DETAILED DESCRIPTION

[0020] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0021] Example 1 The embodiment of the present invention provides a method for calling an API in a question-answering system. This method, through semantic recognition and structured API configuration, implements dynamic, multi-round, context-aware API calling capabilities based on user natural language input, so as to obtain real-time data from external systems and feed it back to users. Specifically, Figure 1 This is a flowchart of a method for calling an API in a question-and-answer system according to a first embodiment of the present invention. Figure 1 As shown, the API calling method in the question-answering system provided in this embodiment includes the following steps S101 to S105.

[0022] Step S101: Determine the target API to be called from a preset API configuration set according to the current input and the description information in the API configuration.

[0023] The API configuration set includes multiple API configurations, and the API configuration includes the request address, description information, request type, and parameter passing method.

[0024] Specifically, in the Q&A system, API modular configuration tools are used to pre-configure callable APIs through a modular configuration interface or structured configuration form. This includes API parameter declarations and template settings, generating structured configuration information. The system stores this configuration structure, which can be considered an API configuration. When a call is made, parameters are extracted based on user input and contextual information, and the call is executed by referencing the configured API configuration. This pre-configured and structured API configuration also standardizes API calls, making it compatible with APIs in different formats (URL, form-data, JSON).

[0025] Multiple API configurations constitute an API configuration set. Each API configuration may specifically include: the request address for executing the API request, such as "https: / / api.weather.com / query"; descriptive information generated through the API's functional description and name identification, such as "Query weather, obtain weather information"; the request type corresponding to the API, such as GET, POST, PUT, DELETE, etc.; different parameter passing methods, such as URL parameters, form-data parameters, JSON parameters, etc.

[0026] Users can engage in multiple rounds of Q&A in a single conversation. The question entered during the current Q&A session serves as the current input for this step. In this step, the Q&A system matches the most appropriate API configuration based on the semantics of the user input and the context of the historical conversation. For example, if the current input is "Check the weather in Shanghai tomorrow," the system determines that the target API to be called is the weather query interface based on the semantic match between the current input and the description in the API configuration.

[0027] Optionally, the description information in each API configuration includes several keyword tags. The keywords in the current input are extracted and matched with the description information for overlap. For example, the keyword tags of the weather query interface include: ["weather", "air temperature", "temperature"]; optionally, the description information in each API configuration is uniformly encoded into a semantic vector, and the current input is also encoded into a semantic vector, and the cosine similarity between the two is calculated for matching; or other matching methods can also be used.

[0028] Step S102: Determine the parameters required by the target API based on the current input and historical conversations to obtain a target parameter set.

[0029] Specifically, the current input refers to the natural language text being entered by the user, the historical conversation refers to the previous questions asked by the user in the context of the current session, and the target parameter set is all the input fields required to call the target API.

[0030] In this step, based on the current user input and historical conversation content, all parameters required to call the target API are extracted from the user language, and a structured target parameter set is constructed for subsequent formatting and request body filling.

[0031] Optionally, the API configuration also includes parameter descriptions. After the system determines the target API, it reads the preset parameter descriptions in the API configuration, including: parameter names (such as city, date); parameter types (such as string, date, enumeration), etc. Perform natural language parsing on the current input, including methods such as word segmentation,词性标注, named entity recognition, keyword matching, template matching, etc., and compare with the target API parameter definitions to obtain the corresponding parameters. At the same time,回溯 the current session history rounds, search for missing parameter values from the conversation content, and merge the parameters extracted from the current input and the historical conversation content to form a complete target parameter set.

[0032] For example, if the target API is a weather query interface, the historical conversation includes "Query the weather in Shanghai tomorrow", and the current input is "What about Tianjin", the target parameter set can be obtained, including a time parameter with a parameter value of "tomorrow" and a location parameter with a parameter value of "Tianjin".

[0033] Step S103: Format the target parameter set according to the request type of the target API.

[0034] Different request types (such as GET, POST) are different in parameter format and carrying method. In this step, operations such as escaping, encoding, and structure conversion are performed on the original values according to the request type to adapt each parameter value in the target parameter set to the technical specifications of the target API. For example, for a request type of GET and a parameter carrying method of URL splicing, when formatting, key=value is encoded into a query string and URL encode processing is performed, such as:?city=%E5%8C%97%E4%BA%AC.

[0035] Step S104: Fill the formatted parameters into the request structure according to the parameter passing method of the target API. <0​​​​​​In this step, the system can initiate a request using an HTTP client, for example: requests.get("https: / / api.weather.com / query?city=Tianjin"), or requests.post("https: / / api.weather.com / query", json={"city": "Tianjin"}).

[0039] After performing the API request operation, the API return value is as follows: { "weather": "Cloudy", "temp_max": 23, "temp_min": 16 } The question-and-answer system generates an answer to the current input based on this return value. For example, the generated answer is: It is cloudy in Tianjin, and the temperature is 16~23.

[0040] In the API calling method of the question-and-answer system provided in this embodiment, each API is abstracted into a unified data structure, and the configuration includes the request address, description information, request type and parameter passing method, forming an API configuration set that can be identified and reused. The system performs semantic matching based on the user's current input and the description information of each API, and automatically determines the target API most relevant to the user's intention from the configuration set. The system not only extracts the parameters in the current input, but also identifies missing parameters based on historical conversation content, constructs a complete target parameter set, and standardizes and formats the parameter set according to the request type of the target API, and fills the parameters into the corresponding request structure according to the parameter passing method. The constructed request structure is combined with the address of the target API to complete the API request execution operation and obtain real-time response results. Compared with the prior art that uses hard-coded or manually maintained configuration files to access APIs, this embodiment introduces a structured API configuration set and specifies the request address, description information, request type, and parameter passing method of each API, so that the API can be identified and called according to a unified mechanism, reducing the configuration workload required when calling the API while also reducing the configuration difficulty; by combining historical conversation records for parameter completion, it supports the construction of target parameter sets based on context, thereby achieving a more natural and coherent multi-round question-and-answer experience and reducing the burden of repeated input for users; compared with the prior art that uses fixed templates for API request construction, it automatically formats parameters according to the API request type and accurately fills them into the request structure according to different parameter passing methods, which can flexibly adapt to different API types and enhance compatibility with diverse APIs. In summary, the API calling method provided by the present invention is oriented towards the question-and-answer system scenario, and through the combination of mechanisms such as structured configuration, dynamic matching, context parameter completion, and automatic request structure construction, it realizes the unified, intelligent, and efficient calling capability for multiple types of APIs. It not only reduces the dependence on code-layer API access logic, improves the modularity and maintainability of the system, but also enhances the question-answering system's ability to understand the continuity and context of natural language, allowing users to complete continuous queries or multiple rounds of interactive questions without repeated descriptions, thereby improving the practicality, intelligence and user experience of the question-answering system in complex business scenarios.

[0041] Optionally, in one embodiment, the API configuration is completed through the following configuration steps: in response to the address input step, setting the API request address; in response to the information input step, setting the API description information; in response to the type selection step, setting the API request type; configuring the API parameter passing method, wherein, when the API adopts the URL method to pass parameters, configure the parameter name, parameter type and parameter description of each parameter; when the API adopts the form-data method to pass parameters, first configure the default JSON request body of the single-layer structure, and then configure the parameter name of each parameter, the jsonpath path of the parameter in the JSON request body and the parameter description; when the API adopts the JSON method to pass parameters, configure the default JSON request body, and then configure the parameter name of each parameter, the jsonpath path of the parameter in the JSON request body and the parameter description.

[0042] In this embodiment, the configuration of the API is completed through a modular configuration process, and the user or system operation and maintenance personnel gradually completes the structured modeling of the API access information through a graphical interface or a configuration management platform.

[0043] Specifically, Figure 2 This is a schematic diagram of the API configuration process in the question-answering system provided by an embodiment of the present invention, such as Figure 2 As shown, the system provides an address input bar, and the user fills in the request URL of the API to be accessed. The system responds to the address input step and sets the API request address, which serves as the target endpoint for subsequent system requests. During the configuration process, the function description of the API is entered, and the information input step is responded to, and the description information of the API is set, which is used to provide a semantic reference when the subsequent system matches the user's intention. First, complete the configuration of the API request address and API description information as the basic information of the API.

[0044] The system provides request type options (such as GET, POST, PUT, etc.). Users select the request type that matches the API protocol. This setting will directly affect the parameter formatting method and request structure generation logic.

[0045] Configure the API parameter passing method based on the target API's parameter carrying format. When passing parameters via a URL, configure each parameter individually, including the parameter name (e.g., city), parameter type (e.g., string, date, enumeration), and parameter description (e.g., the target city to query). If you use the request body format, you can choose to pass parameters using either form-data or JSON. When using form-data, first configure a default JSON request body structured as a single-layer dictionary. Then, for each parameter, configure the parameter name (such as unit), the parameter's JSONPath path in the JSON request body (such as $.unit), and the parameter description (such as temperature units (C / F supported). When calling, the parameter is automatically filled into the corresponding fields in the JSON request body, and a request is initiated using the Content-Type: application / x-www-form-urlencoded or multipart / form-data format. When using JSON, the configuration steps are similar to form-data, except that the request body may contain nested structures. JSONPath expressions can be used to precisely describe field locations. For each parameter, configure the parameter name (such as date), the parameter's JSONPath path in the JSON request body (such as $.query.date), and the parameter description (such as the query date in the format of yyyy-mm-dd). JSONPath parses the structure path and correctly inserts the parameter value into the request body.

[0046] By adopting the API calling method in the question-and-answer system provided by this embodiment, all API access configurations are standardized, supporting unified storage and management, supporting three parameter passing methods: URL, form-data, and JSON, adapting to different system interfaces, and flexible parameter passing. Through jsonpath, it can support arbitrarily deeply nested request structures without code rewriting, realizing structured editing. Subsequent systems only need to reference this configuration to automatically complete parameter filling and request generation, thereby realizing automated calling.

[0047] Optionally, in one embodiment, the API configuration also includes a reply template, and the configuration step further includes: configuring the reply template in the form of a Jinja2 template, wherein the reply template is used to generate user-oriented question and answer reply content based on the return value and request parameters of the API request.

[0048] In this embodiment, the API configuration not only includes the request address, description information, request type and parameter passing method, but also further includes the configuration of the response template. The template is used to convert the API request return value and request parameter information into a natural language question and answer response for the user, thereby improving the comprehensibility and readability of the system output.

[0049] Continue to refer Figure 2 The system provides a response template configuration module in the API configuration interface. Developers can freely define the output format based on the API's return structure and possible request parameters. Configurators use Jinja2 template syntax to write the text content to be output, embedding variable placeholders in the text. These placeholders can reference: original fields in the request parameters (such as city, date), key fields in the API return results (such as weather, temperature), and optional contextual tags (such as user titles, time tags, etc.). The template content is bound to the current API configuration, and the referenced variable names are recorded to ensure correct parsing and filling during subsequent runtime. Variable binding supports nested path parsing, such as result.weather.summary. When the API is called, the system extracts the current round of request parameters and the field values ​​in the return results, injects these variables into the pre-configured template, and generates the final natural language response for the user through Jinja2 rendering.

[0050] Figure 3 A schematic diagram of the API call process in the question-answering system provided by an embodiment of the present invention, such as Figure 3 As shown, based on the above API configuration process, the API calling process is also more streamlined. The specific steps are: 1. Fill in the API address.

[0051] 2. Fill in the API request type.

[0052] 3. The parameter name and original text of the parameter are retained, and the parameter name is formatted according to the selected type.

[0053] 4. Fill the formatted parameters according to the type of parameter passed. Use the equal sign to splice the URL parameters into the URL. Fill the form-data or json parameters into the corresponding position of json according to the jsonpath path.

[0054] 5. Execute the API request to obtain the API return result.

[0055] 6. According to the filled-in response template, combine the input parameter name, original text and return result, format the Jinja2 template, and finally get the final return result of the API call.

[0056] By using the API calling method in the question-and-answer system provided in this embodiment, the structured data returned by the API is converted into natural language question-and-answer content through a reply template, thereby improving user readability. At the same time, the template is flexible and controllable, and the output style and word usage habits can be adjusted without changing the code, and multi-language expansion is supported.

[0057] Optionally, in one embodiment, the step of filling the formatted parameters into the request structure according to the parameter passing method of the target API includes: when the formatted parameters include URL parameters, the URL parameters are spliced ​​into the request address in the form of key-value pairs using an equal sign; when the formatted parameters include form-data parameters or JSON parameters, the parameters are filled into the corresponding position of the JSON request body according to the configured jsonpath path.

[0058] In this embodiment, for the parameters that have completed the formatting processing of the target API, the system fills the parameters into the API request structure according to the preset parameter passing method of the API. This step is differentiated according to the type of parameter and the parameter passing path. Specifically, for processing URL parameters, each formatted URL parameter is encoded in the form of key=value, and multiple parameters are separated by &, spliced ​​at the end of the API request address to construct a complete request URL, wherein the system automatically URL encodes the parameter value to ensure the security of special character transmission. For processing form-data or JSON request body parameters, the initial JSON structure is first constructed according to the default request body template specified in the API configuration. Subsequently, for each parameter, the system accurately locates the position where it should be inserted according to the jsonpath path set in the configuration, fills in the formatted value, and uses the JSON structure as the request body content, and issues an API request together with the request address.

[0059] The API calling method in the question-and-answer system provided by this embodiment supports multiple parameter passing mechanisms, can flexibly adapt to API calling interfaces such as GET and POST, can realize deep field insertion through jsonpath, adapt to JSON request bodies with complex nested structures, automatically fill in parameters, and eliminate the need for manual construction of request structures, thereby reducing the error rate and enhancing the system's scalability and API general adaptability.

[0060] Optionally, in one embodiment, the step of determining the parameters required for the target API according to the current input and the historical conversation to obtain the target parameter set includes: extracting the parameters in the current input to obtain the current parameter set; obtaining the global parameter set corresponding to the historical conversation; determining whether the current parameter set includes a first parameter, where the first parameter is a parameter whose parameter name is the same as that in the global parameter set, and the parameters in the global parameter set other than the first parameter are second parameters; and if the current parameter set includes the first parameter, determining the current parameter set and the second parameters as the target parameter set.

[0061] In this embodiment, before making an API call, in order to determine the complete parameter set required for the target API, the system jointly extracts parameters from the current user input and the historical conversation context. Specifically, Figure 4 FIG. is a schematic diagram of the API context parameter passing process in the question and answer system provided by the embodiment of the present invention. As Figure 4 shown, the system performs parameter recognition on the current user's natural language input, extracts the directly expressed entity information, and forms the current parameter set. At the same time, the system maintains context parameters that can span multiple rounds of conversations, records the parameter information mentioned by the user in previous rounds, such as context-stable parameters such as time, unit, quantity, etc., and forms a global parameter set, which is not limited to the target API.

[0062] Then, the parameter names of the current parameter set and the global parameter set are compared to find whether there are duplicate fields. For the convenience of description, the parameter in the current parameter set whose parameter name is the same as that in the global parameter set is defined as the first parameter, and the parameters in the global parameter set other than the first parameter are second parameters. It should be noted that the first parameter, the second parameter, and the nth parameter in the following are only used to distinguish each other and do not constitute an order limitation. For example, the current parameter set is { "city": "Tianjin"}; the global parameter set is { "city": "Beijing", "date": "today"}, and the same-name parameter "city" → "city" is the first parameter, and the parameter other than "city" in the global parameter, that is, "date", is the second parameter.

[0063] If there are duplicate parameters between the current parameter set and the global parameter set, the second parameters in the global parameter set are merged with the current parameter set to form the final target parameter set, and the API call process is executed. Optionally, if there are no duplicate parameters between the current parameter set and the global parameter set, the global parameter set can be directly merged with the current parameter set to form the final target parameter set, and the API call process is executed, or the steps of the following embodiment can also be executed.

[0064] The API calling method in the question-and-answer system provided by this embodiment supports context parameter memory and reuse, avoids repeated user input, improves conversation continuity, and implements parameter priority management. When there is a conflict, the user's current expression is always used as the basis, thereby improving the naturalness of the interaction.

[0065] Optionally, in one embodiment, the parameters required for the target API are determined based on the current input and historical conversations, and the step of obtaining the target parameter set also includes: if the current parameter set does not include the first parameter, merging the current parameter set and the global parameter set to obtain a merged parameter set; obtaining the cached parameter set of the target API; determining whether the current parameter set includes a third parameter, wherein the third parameter is a parameter with the same parameter name as the parameter name in the cached parameter set, and the parameters in the cached parameter set other than the third parameter are fourth parameters; if the current parameter set includes the third parameter, determining the merged parameter set and the fourth parameter as the target parameter set; and if the current parameter set does not include the third parameter, using the merged parameter set and the cached parameter set as the target parameter set.

[0066] In this embodiment, global parameters and API cache parameters are further integrated to construct a more complete target parameter set to solve the problem of incomplete user expression in consecutive rounds of dialogue.

[0067] Specifically, continue to refer to Figure 4 If there are no duplicate parameters between the current parameter set and the global parameter set, the current parameter set is merged with the global parameter set to define the merged parameter set. At the same time, the system also maintains an independent cache parameter set for each API local field to record the specific API parameters used by users in historical interactions.

[0068] Then, the parameter names of the current parameter set and the cached parameter set are compared to find out whether there are duplicate fields. For ease of description, the parameters with the same parameter names in the current parameter set and the cached parameter set are defined as the third parameter, and the other parameters in the cached parameter set except the third parameter are defined as the fourth parameter. If there are duplicate parameters in the current parameter set and the cached parameter set, the fourth parameter in the cached parameter set is merged with the merged parameter set to form the final target parameter set, and the API call process is executed. If there are no duplicate parameters in the current parameter set and the cached parameter set, the cached parameter set is merged with the merged parameter set to form the final target parameter set, and the API call process is executed.

[0069] The API calling method in the question-and-answer system provided in this embodiment is used to integrate the current input, context global parameters and historical cache parameters, support intelligent parameter completion in complex multi-round question-and-answer scenarios, combine the global and API local contexts, and finely distinguish the parameter scope and priority, avoid repeated inquiries, and improve the natural fluency of question-and-answer and the integrity of system responses.

[0070] Optionally, in one embodiment, after obtaining the target parameter set, the method further includes: updating the global parameter set using the global parameters in the current parameter set; and updating the cache parameter set of the target API using the non-global parameters in the current parameter set.

[0071] Continue to refer Figure 4 Before obtaining the target parameter set, the system extracts the parameters from the current input to form the current parameter set. Parameters in this current parameter set are categorized into global and non-global parameters based on their name and purpose. Global parameters include those with strong contextual versatility and can be used across multiple conversations, such as time (date), region (city), and language (lang). Non-global parameters include those specific to the current API and not globally shared, such as reimbursement number, business type, and product ID. This classification is identified by the parameter type or scope tag set by the system when configuring the API. The system updates the global parameters in the current parameter set to the global parameter set. Specifically, if a parameter with the same name already exists in the global parameter set, it is overwritten; if no field with the same name exists, a new record is created. The system identifies non-global parameters in the current parameter set and uses them to update the cached parameter set of the target API being called, so that they can be inherited and used when the same API is subsequently called.

[0072] By using the API calling method in the question-and-answer system provided in this embodiment, after obtaining the target parameter set through current input and historical conversations, the system further performs a parameter update operation to support parameter reuse and context connection in subsequent multiple rounds of conversations.

[0073] Optionally, when there is no duplication of parameters between the current parameter set and the cache parameter set, after the API call process, first determine whether the cache parameter set is empty. If not, the cache parameters remain unchanged. If it is empty, all parameters in the current parameter set except the global parameters are cached.

[0074] Specifically, the cache parameter set is usually obtained from the user's explicit expression and has a high confidence level. If the current parameter set does not contain parameters that are repeated in the cache, that is, there is no explicit conflict, then the new parameters may only be auxiliary information or a fuzzy expression. In this case, the existing cache is not updated to avoid mistakenly updating the existing valid cache with possibly ambiguous or incomplete parameters, and to ensure the source consistency of the cache parameters, that is, the cache parameters originate from the same valid conversation. If there is no explicit conflict information, that is, the current parameter set does not contain parameters that are repeated in the cache parameter set, the current cache is maintained to avoid the inclusion of uncertain parameters from another conversation in the cache.

[0075] Example 2 Corresponding to the above-mentioned embodiment 1, embodiment 2 of the present invention provides an API calling device in a question-and-answer system. The corresponding technical feature details and corresponding technical effects can be referred to the above-mentioned embodiment 1 and will not be repeated in this embodiment. Figure 3 A block diagram of an API calling device in a question-answering system according to a second embodiment of the present invention is shown in FIG. Figure 5 As shown, the apparatus includes: a first determining module 201 , a second determining module 202 , a first processing module 203 , a second processing module 204 and a requesting module 205 .

[0076] Among them, the first determination module 201 is used to determine the target API to be called from a preset API configuration set based on the current input and the description information in the API configuration, wherein the API configuration set includes multiple API configurations, and the API configuration includes the request address, the description information, the request type and the parameter passing method; the second determination module 202 is used to determine the parameters required for the target API based on the current input and historical conversations to obtain the target parameter set; the first processing module 203 is used to format the target parameter set according to the request type of the target API; the second processing module 204 is used to fill the formatted parameters into the request structure according to the parameter passing method of the target API; the request module 205 is used to perform API request operations according to the request structure and the request address of the target API.

[0077] Optionally, in one embodiment, the API configuration is completed through the following configuration steps: in response to the address input step, setting the API request address; in response to the information input step, setting the API description information; in response to the type selection step, setting the API request type; configuring the API parameter passing method, wherein, when the API adopts URL method to pass parameters, configure the parameter name, parameter type and parameter description of each parameter; when the API adopts form-data method to pass parameters, first configure the default JSON request body of the single-layer structure, and then configure the parameter name of each parameter, the jsonpath path of the parameter in the JSON request body and the parameter description; when the API adopts JSON method to pass parameters, configure the default JSON request body, and then configure the parameter name of each parameter, the jsonpath path of the parameter in the JSON request body and the parameter description.

[0078] Optionally, in one embodiment, the API configuration also includes a reply template, and the configuration step further includes: configuring the reply template in the form of a Jinja2 template, wherein the reply template is used to generate user-oriented question and answer reply content based on the return value and request parameters of the API request.

[0079] Optionally, in one embodiment, the second processing module 204 includes: a first processing unit, used to, when the formatted parameters include URL parameters, splice the URL parameters into the request address in the form of key-value pairs using equal signs; and a second processing unit, used to, when the formatted parameters include form-data parameters or JSON parameters, fill the parameters into the corresponding positions of the JSON request body according to the configured jsonpath path.

[0080] Optionally, in one embodiment, the second determination module 202 includes: an extraction unit, used to extract parameters in the current input to obtain a current parameter set; a first acquisition unit, used to obtain a global parameter set corresponding to the historical conversation; a first judgment unit, used to judge whether the current parameter set includes a first parameter, wherein the first parameter is a parameter with the same parameter name as the parameter name in the global parameter set, and the parameters in the global parameter set other than the first parameter are second parameters; and a first determination unit, used to determine that the current parameter set and the second parameter are the target parameter set if the current parameter set includes the first parameter.

[0081] Optionally, in one embodiment, the second determination module 202 further includes: a merging unit, for merging the current parameter set and the global parameter set to obtain a merged parameter set if the current parameter set does not include the first parameter; a second acquisition unit, for acquiring the cache parameter set of the target API; a second judgment unit, for judging whether the current parameter set includes a third parameter, wherein the third parameter is a parameter with the same parameter name as the parameter name in the cache parameter set, and the parameters in the cache parameter set other than the third parameter are fourth parameters; a second determination unit, for determining that the merged parameter set and the fourth parameter are the target parameter set if the current parameter set includes the third parameter; and a third determination unit, for using the merged parameter set and the cache parameter set as the target parameter set if the current parameter set does not include the third parameter.

[0082] Optionally, in one embodiment, the device further includes an updating module for updating the global parameter set using the global parameters in the current parameter set; and updating the cache parameter set of the target API using the non-global parameters in the current parameter set.

[0083] Example 3 This embodiment also provides a computer device, such as a smart phone, tablet computer, laptop computer, desktop computer, rack server, blade server, tower server or cabinet server (including an independent server or a server cluster composed of multiple servers) that can execute programs. Figure 6As shown, the computer device 01 of this embodiment includes at least but not limited to: a memory 012 and a processor 011 which can be interconnected via a system bus. Figure 6 It should be pointed out that Figure 6 The computer device 01 is shown only with components memory 012 and processor 011 , but it should be understood that implementation of all of the components shown is not a requirement and more or fewer components may alternatively be implemented.

[0084] In this embodiment, memory 012 (i.e., readable storage medium) includes flash memory, a hard disk, a multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic storage, a magnetic disk, an optical disk, etc. In some embodiments, memory 012 may be an internal storage unit of computer device 01, such as the hard disk or internal memory of computer device 01. In other embodiments, memory 012 may also be an external storage device of computer device 01, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash memory card, etc. equipped on computer device 01. Of course, memory 012 may also include both internal storage units and external storage devices of computer device 01. In this embodiment, memory 012 is typically used to store the operating system installed on computer device 01 and various reference software, such as the program code of the API calling device in the question-and-answer system of Example 2. In addition, the memory 012 can also be used to temporarily store various types of data that have been output or are to be output.

[0085] In some embodiments, processor 011 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. Processor 011 is typically used to control the overall operation of computer device 01. In this embodiment, processor 011 is used to execute program code stored in memory 012 or process data, such as methods for calling APIs in a question-and-answer system.

[0086] Example 4 This embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic storage device, a magnetic disk, an optical disk, a server, an app reference store, etc., storing a computer program that, when executed by a processor, implements corresponding functions. The computer-readable storage medium of this embodiment is used to store an API calling device in the question-and-answer system, and, when executed by the processor, implements the API calling method in the question-and-answer system of Example 1.

[0087] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.

[0088] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.

[0089] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method.

[0090] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for calling an API in a question-answering system, characterized in that: include: Determine the target API to be called from a preset API configuration set based on the current input and the description information in the API configuration, wherein the API configuration set includes multiple API configurations, and the API configuration includes the request address, the description information, the request type, and the parameter passing method; Determine the parameters required by the target API based on the current input and historical conversations to obtain a target parameter set; Formatting the target parameter set according to the request type of the target API; Fill the formatted parameters into the request structure according to the parameter passing method of the target API; An API request operation is performed according to the request structure and the request address of the target API.

2. The method for calling an API in a question-answering system according to claim 1, characterized in that: The API configuration is completed through the following configuration steps: In response to the address input step, setting the API request address; In response to the information input step, setting description information of the API; In response to the type selection step, setting the request type of the API; Configure the API parameter passing method. When the API uses URL to pass parameters, configure the parameter name, parameter type, and parameter description of each parameter. When the API uses form-data to pass parameters, first configure the default JSON request body of the single-layer structure, and then configure the parameter name of each parameter, the jsonpath path of the parameter in the JSON request body, and the parameter description. When the API uses JSON to pass parameters, configure the default JSON request body, and then configure the parameter name of each parameter, the jsonpath path of the parameter in the JSON request body, and the parameter description.

3. The method for calling an API in a question-answering system according to claim 2, wherein: The API configuration also includes a reply template, and the configuration steps further include: The reply template is configured in the form of a Jinja2 template, wherein the reply template is used to generate user-oriented question and answer reply content according to the return value and request parameters of the API request.

4. The method for calling an API in a question-answering system according to claim 2, wherein: The step of filling the formatted parameters into the request structure according to the parameter passing method of the target API includes: When the formatted parameters include URL parameters, the URL parameters are concatenated into the request address in the form of key-value pairs using an equal sign; When the formatted parameters include form-data parameters or JSON parameters, the parameters are filled into the corresponding positions of the JSON request body according to the configured jsonpath path.

5. The method for calling an API in a question-answering system according to claim 1, wherein: The step of determining the parameters required by the target API according to the current input and the historical conversation, and obtaining the target parameter set includes: Extracting parameters from the current input to obtain a current parameter set; Obtaining a global parameter set corresponding to the historical conversation; Determining whether the current parameter set includes a first parameter, wherein the first parameter is a parameter with the same parameter name as a parameter in the global parameter set, and the parameters in the global parameter set other than the first parameter are second parameters; and If the current parameter set includes the first parameter, the current parameter set and the second parameter are determined to be the target parameter set.

6. The method for calling an API in a question-answering system according to claim 5, characterized in that: The step of determining the parameters required by the target API based on the current input and the historical conversation, and obtaining the target parameter set further includes: If the current parameter set does not include the first parameter, merging the current parameter set and the global parameter set to obtain a merged parameter set; Obtaining a cache parameter set for the target API; Determining whether the current parameter set includes a third parameter, wherein the third parameter is a parameter having the same parameter name as a parameter in the cache parameter set, and the parameters in the cache parameter set other than the third parameter are fourth parameters; If the current parameter set includes the third parameter, determining the combined parameter set and the fourth parameter as the target parameter set; and If the current parameter set does not include the third parameter, the merged parameter set and the cached parameter set are used as the target parameter set.

7. The method for calling an API in a question-answering system according to claim 6, wherein: After obtaining the target parameter set, the method further includes: Updating the global parameter set using the global parameters in the current parameter set; The cache parameter set of the target API is updated using the non-global parameters in the current parameter set.

8. A device for calling an API in a question-answering system, characterized in that: include: A first determination module is configured to determine a target API to be called from a preset API configuration set based on current input and description information in the API configuration, wherein the API configuration set includes multiple API configurations, and the API configuration includes a request address, the description information, the request type, and a parameter passing method; A second determination module is configured to determine the parameters required by the target API based on the current input and historical conversations to obtain a target parameter set; A first processing module is configured to format the target parameter set according to the request type of the target API; A second processing module is used to fill the formatted parameters into the request structure according to the parameter passing method of the target API; The request module is used to perform an API request operation according to the request structure and the request address of the target API.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • JsonPath-based unified service calling method

    CN113138811A

  • API (Application Program Interface) text retrieval method and device and electronic equipment

    CN119311832A

  • Conversation processing method and device, equipment and storage medium

    CN119476484A

  • Schema-based integration of external APIs with natural language applications

    US11922144B1