CN118132568A - Method for calling external API or inquiring database and storage medium - Google Patents

Method for calling external API or inquiring database and storage medium Download PDF

Info

Publication number
CN118132568A
CN118132568A CN202410559955.4A CN202410559955A CN118132568A CN 118132568 A CN118132568 A CN 118132568A CN 202410559955 A CN202410559955 A CN 202410559955A CN 118132568 A CN118132568 A CN 118132568A
Authority
CN
China
Prior art keywords
query
database
request
api
filling
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410559955.4A
Other languages
Chinese (zh)
Inventor
戴诗琪
王文山
苏康建
吴弘毅
沈继明
陈固煟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Istrong Technology Co ltd
Original Assignee
Istrong Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Istrong Technology Co ltd filed Critical Istrong Technology Co ltd
Priority to CN202410559955.4A priority Critical patent/CN118132568A/en
Publication of CN118132568A publication Critical patent/CN118132568A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a method for calling external API or inquiring database and a storage medium, the method only needs to fill in interface address, input parameter, output parameter, request mode and reply template for calling external API request, can directly call external API, and automatically take out data returned by API to fill according to reply template, without self-defining action service, so that common user can also configure, and the use threshold is reduced; for the query database, query intentions are classified in the NLU stage, the table structure is directly added into the prompt words and transmitted to the LLM, and the prompt words are directly converted into the database query language for query through a large model, so that the package service is not required for each query requirement, and the development engineering quantity is reduced.

Description

Method for calling external API or inquiring database and storage medium
Technical Field
The application relates to the technical field of natural language processing, in particular to a method for calling an external API or inquiring a database based on a Rasa framework and a storage medium.
Background
With the continuous progress of artificial intelligence technology, the question-answering robot is widely applied in various fields, such as education, medical treatment, finance and the like, helps users solve common problems and provides faster and more accurate information and services. In order to acquire richer information and functions and meet more demands of users, calling external APIs is an effective solution, such as weather, stock quotations and the like, and real-time updating can be realized by calling the external APIs, so that the users can acquire the latest information. In the vertical application field, the question-answering robot can provide more accurate and comprehensive answers by calling corresponding service APIs, and the application range of the question-answering robot can be expanded by supporting query databases aiming at the scenes of partial unpackaged service APIs, so that the user experience is improved.
Rasa is an open source machine learning framework for constructing a conversational robot, covers almost all functions of a conversational system, has good expandability for each module, and has higher efficiency and flexibility compared with a traditional conversational robot framework. The framework mainly includes Rasa NLU and Rasa Core, where Rasa NLU is mainly responsible for converting user's input into intent and entity information, rasa Core is mainly responsible for deciding the next action (action) based on current and historical dialog records, the next action including a specific response action (responses) and Custom actions (Custom actions). The method can realize the operations of calling external APIs and inquiring databases in the custom action, has certain expandability, but has insufficient flexibility, because the remote service of the custom action needs to be additionally written, the code definition input and output and the final answer generation are written in the service, which is equivalent to the need of carrying out secondary encapsulation on the external APIs, and the service needs to be independently constructed for each attribute needing to be inquired, so that the development quantity is larger.
Disclosure of Invention
In view of the above problems, the application provides a method for calling an external API or querying a database based on a Rasa framework and a storage medium, which solve the problems that the existing Rasa framework has insufficient operation flexibility for realizing external API and database query and the like, a user is required to additionally write a remote service of a custom action, and each attribute to be queried is required to be independently provided with a service, so that the development amount is large.
To achieve the above object, the present inventors provide a method for calling an external API or querying a database based on Rasa framework, including:
After receiving the inquiry problem of the user, determining to return target service information by calling an external API or inquiring a database;
When the external API is determined to be called, adding API configuration in domain of the Rasa framework according to the received query problem to carry out query parameter filling and request body parameter filling;
Then executing external API request according to the interface address, the query parameter, the request header parameter, the request body parameter and the request mode in the API configuration;
Receiving a query result returned by an external API request;
When the database is determined to be queried, determining a corresponding database table structure from DB configuration in domain according to the intention type of the database query in the NLU stage;
Fusing the determined database table structure and the query problem, transmitting the fused database table structure and the query problem to a large language model, converting the fused database table structure and the query problem into a database query sentence, and obtaining a query result;
And generating a reply sentence according to the query result returned by calling the external API request or the query result acquired by the query database, and returning the reply sentence to the user.
In some embodiments, the query parameter filling comprises the steps of:
Judging whether the variable in the query parameter in the API configuration file has a filling mark or not;
if so, determining a corresponding entity value according to the query parameters in the query problem, and then filling the determined entity value into a filling identifier corresponding to the query parameters of the API configuration.
In some embodiments, the request body parameter filling specifically includes the following steps:
determining a request mode in API configuration;
when the request mode is POST, determining a corresponding entity value according to the request body parameter in the query problem, and then filling the determined entity value into a filling identifier corresponding to the request body parameter of the API configuration;
When the request mode is GET, then the request body parameter filling is not needed.
In some embodiments, the generating the reply sentence according to the query result returned by calling the external API request or the query result obtained by querying the database specifically includes the following steps:
Combining the entity corresponding to the query parameter extracted from the query problem and the query result into the same dictionary;
and filling the entities in the dictionary into the reply templates according to the reply templates with successful requests to obtain reply sentences.
In some embodiments, the determining to return the target service information by calling an external API or querying a database specifically includes the steps of:
judging whether API configuration is added in domain of Rasa frame;
if yes, determining to return target service information through an external API;
If not, determining to return the target service information by querying the database.
In another aspect, a storage medium stores a computer program that, when executed by a processor, performs the steps of:
After receiving the inquiry problem of the user, determining to return target service information by calling an external API or inquiring a database;
When the external API is determined to be called, adding API configuration in domain of the Rasa framework according to the received query problem to carry out query parameter filling and request body parameter filling;
Then executing external API request according to the interface address, the query parameter, the request header parameter, the request body parameter and the request mode in the API configuration;
Receiving a query result returned by an external API request;
When the database is determined to be queried, determining a corresponding database table structure from DB configuration in domain according to the intention type of the database query in the NLU stage;
Fusing the determined database table structure and the query problem, transmitting the fused database table structure and the query problem to a large language model, converting the fused database table structure and the query problem into a database query sentence, and obtaining a query result;
And generating a reply sentence according to the query result returned by calling the external API request or the query result acquired by the query database, and returning the reply sentence to the user.
In some embodiments, the query parameter filling comprises the steps of:
Judging whether the variable in the query parameter in the API configuration file has a filling mark or not;
if so, determining a corresponding entity value according to the query parameters in the query problem, and then filling the determined entity value into a filling identifier corresponding to the query parameters of the API configuration.
In some embodiments, the request body parameter filling specifically includes the following steps:
determining a request mode in API configuration;
when the request mode is POST, determining a corresponding entity value according to the request body parameter in the query problem, and then filling the determined entity value into a filling identifier corresponding to the request body parameter of the API configuration;
When the request mode is GET, then the request body parameter filling is not needed.
In some embodiments, the generating the reply sentence according to the query result returned by calling the external API request or the query result obtained by querying the database specifically includes the following steps:
Combining the entity corresponding to the query parameter extracted from the query problem and the query result into the same dictionary;
and filling the entities in the dictionary into the reply templates according to the reply templates with successful requests to obtain reply sentences.
In some embodiments, the determining to return the target service information by calling an external API or querying a database specifically includes the steps of:
judging whether API configuration is added in domain of Rasa frame;
if yes, determining to return target service information through an external API;
If not, determining to return the target service information by querying the database.
Different from the prior art, according to the technical scheme, when the query problem of the user is received, the target service information is returned by calling an external API or querying a database, and when the target service information is acquired by calling an external API request is determined, the query parameter filling and the request body parameter filling are performed on the API configuration added in domain of the Rasa framework according to the received query problem, wherein the API configuration comprises an interface address, a query parameter, a request head parameter, a request body parameter and a request mode; after the filling of the query parameters and the filling of the request body parameters are completed, executing an external API request according to an interface address, a query parameter, a request header parameter, a request body parameter and a request mode in the API configuration, returning a query result, determining a corresponding database table structure from DB configuration in domain through the intention type of database query in an NLU stage when determining that target service information is acquired through the query database, wherein the DB configuration record database table structure is added in the domain, and the database table structure and the query problem are fused and transferred to a large language model to be converted into a database query statement to acquire the query result; after the external API is called to request to acquire the query result or the query database acquires the query result, a reply sentence is generated according to the query result and returned to the user. When an external API request is called, a user-defined action service is not needed, so that a common user can also perform configuration, and the use threshold is reduced; meanwhile, no matter the external API is called or the database is queried, the service does not need to be packaged for each query requirement, and the development engineering quantity is reduced.
The foregoing summary is merely an overview of the present application, and may be implemented according to the text and the accompanying drawings in order to make it clear to a person skilled in the art that the present application may be implemented, and in order to make the above-mentioned objects and other objects, features and advantages of the present application more easily understood, the following description will be given with reference to the specific embodiments and the accompanying drawings of the present application.
Drawings
The drawings are only for purposes of illustrating the principles, implementations, applications, features, and effects of the present application and are not to be construed as limiting the application.
In the drawings of the specification:
FIG. 1 is a schematic flow chart of a method for calling external APIs or querying a database based on a Rasa framework according to an embodiment;
FIG. 2 is a schematic diagram of a front end configuration interface of an API configuration according to an embodiment;
FIG. 3 is a schematic diagram of a file format yml acquired by a back end of an API configuration according to an embodiment;
FIG. 4 is a schematic diagram of a file format yml acquired by a back end of the DB configuration according to the embodiment;
Fig. 5 is a schematic structural view of a storage medium according to an embodiment.
Reference numerals referred to in the above drawings are explained as follows:
510. The storage medium may be a storage medium,
520. A processor.
Detailed Description
In order to describe the possible application scenarios, technical principles, practical embodiments, and the like of the present application in detail, the following description is made with reference to the specific embodiments and the accompanying drawings. The embodiments described herein are only for more clearly illustrating the technical aspects of the present application, and thus are only exemplary and not intended to limit the scope of the present application.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearances of the phrase "in various places in the specification are not necessarily all referring to the same embodiment, nor are they particularly limited to independence or relevance from other embodiments. In principle, in the present application, as long as there is no technical contradiction or conflict, the technical features mentioned in each embodiment may be combined in any manner to form a corresponding implementable technical solution.
Unless defined otherwise, technical terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application pertains; the use of related terms herein is for the purpose of describing particular embodiments only and is not intended to limit the application.
In the description of the present application, the term "and/or" is a representation for describing a logical relationship between objects, which means that three relationships may exist, for example a and/or B, representing: there are three cases, a, B, and both a and B. In addition, the character "/" herein generally indicates that the front-to-back associated object is an "or" logical relationship.
In the present application, terms such as "first" and "second" are used merely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual number, order, or sequence of such entities or operations.
Without further limitation, the use of the terms "comprising," "including," "having," or other like terms in this specification is intended to cover a non-exclusive inclusion, such that a process, method, or article of manufacture that comprises a list of elements does not include additional elements but may include other elements not expressly listed or inherent to such process, method, or article of manufacture.
As in the understanding of "review guidelines," the expressions "greater than", "less than", "exceeding" and the like are understood to exclude this number in the present application; the expressions "above", "below", "within" and the like are understood to include this number. Furthermore, in the description of embodiments of the present application, the meaning of "a plurality of" is two or more (including two), and similarly, the expression "a plurality of" is also to be understood as such, for example, "a plurality of" and the like, unless specifically defined otherwise.
In the description of embodiments of the present application, spatially relative terms such as "center," "longitudinal," "transverse," "length," "width," "thickness," "up," "down," "front," "back," "left," "right," "vertical," "horizontal," "vertical," "top," "bottom," "inner," "outer," "clockwise," "counter-clockwise," "axial," "radial," "circumferential," etc., are used herein as a basis for the description of the embodiments or as a basis for the description of the embodiments, and are not intended to indicate or imply that the devices or components referred to must have a particular position, a particular orientation, or be configured or operated in a particular orientation and therefore should not be construed as limiting the embodiments of the present application.
Unless specifically stated or limited otherwise, the terms "mounted," "connected," "affixed," "disposed," and the like as used in the description of embodiments of the application should be construed broadly. For example, the "connection" may be a fixed connection, a detachable connection, or an integral arrangement; the device can be mechanically connected, electrically connected and communicated; it can be directly connected or indirectly connected through an intermediate medium; which may be a communication between two elements or an interaction between two elements. The specific meaning of the above terms in the embodiments of the present application can be understood by those skilled in the art to which the present application pertains according to circumstances.
Referring to fig. 1, the present embodiment provides a method for calling an external API or querying a database based on a Rasa framework, including:
Step S110: after receiving the inquiry problem of the user, determining to return target service information by calling an external API or inquiring a database;
Step S120: when the external API is determined to be called, adding API configuration in domain of the Rasa framework according to the received query problem to carry out query parameter filling and request body parameter filling;
Step S130: then executing external API request according to the interface address, the query parameter, the request header parameter, the request body parameter and the request mode in the API configuration;
Step S140: receiving a query result returned by an external API request;
step S150: when the database is determined to be queried, determining a corresponding database table structure from DB configuration in domain according to the intention type of the database query in the NLU stage;
Step S160: fusing the determined database table structure and the query problem, transmitting the fused database table structure and the query problem to a large language model, converting the fused database table structure and the query problem into a database query sentence, and obtaining a query result;
step S170: and generating a reply sentence according to the query result returned by calling the external API request or the query result acquired by the query database, and returning the reply sentence to the user.
When a query problem of a user is received, determining to return target service information by calling an external API or a query database, and when the target service information is determined to be acquired by calling an external API request, performing query parameter filling and request body parameter filling on API configuration added in domain of a Rasa frame according to the received query problem, wherein the API configuration comprises an interface address, a query parameter, a request header parameter, a request body parameter and a request mode by adding the API configuration in domain of the Rasa frame, the user can input the interface address, the query parameter, the request body parameter, the request mode, a reply template and the like in a front-end configuration interface of the API configuration, and when the user queries the problem in a dependent, the user can call the external API request through the API configuration; after the filling of the query parameters and the filling of the request body parameters are completed, executing an external API request according to an interface address, a query parameter, a request header parameter, a request body parameter and a request mode in the API configuration, returning a query result, determining a corresponding database table structure from DB configuration in domain through the intention type of database query in an NLU stage when determining that target service information is acquired through the query database, wherein the DB configuration record database table structure is added in the domain, and the database table structure and the query problem are fused and transferred to a large language model to be converted into a database query statement to acquire the query result; after the external API is called to request to acquire the query result or the query database acquires the query result, a reply sentence is generated according to the query result and returned to the user. When an external API request is called, a user-defined action service is not needed, so that a common user can also perform configuration, and the use threshold is reduced; meanwhile, no matter the external API is called or the database is queried, the service does not need to be packaged for each query requirement, and the development engineering quantity is reduced.
In some embodiments, the query parameter filling comprises the steps of:
Judging whether the variable in the query parameter in the API configuration file has a filling mark or not;
if so, determining a corresponding entity value according to the query parameters in the query problem, and then filling the determined entity value into a filling identifier corresponding to the query parameters of the API configuration.
Query parameter query filling, wherein the query parameters are spliced on the request address in the form of key value pairs and are generally used for transmitting smaller data, and if entity values need to be transmitted in the query parameters, the entity values need to be filled, for example, a user asks "what is the maximum wind force of mangosteen typhoons? The entity value of typhoon _name is extracted as 'mangosteen' in the NLU stage and recorded in a tracker of dialogue tracking, and the corresponding query API needs to input parameters TyphoonName, and a symbol of '{ }' is used for identifying entity variables in configuration, namely the parameter in the configuration parameters is { 'TyphoonName': { typhoon _name }, and the value of the input API after filling is { 'TyphoonName': mangosteen }. Wherein the padding is identified as { }.
In some embodiments, the request body parameter filling specifically includes the following steps:
determining a request mode in API configuration;
when the request mode is POST, determining a corresponding entity value according to the request body parameter in the query problem, and then filling the determined entity value into a filling identifier corresponding to the request body parameter of the API configuration;
When the request mode is GET, then the request body parameter filling is not needed.
The body parameter is filled in the request body, the body parameter is the data of the request main body part, and is usually used for transmitting larger data, when the request mode is POST, if the entity value needs to be filled in the request body parameter, the filling is carried out according to the same method in the filling of the query parameter, and when the request mode is GET, the query parameter can only be transmitted without the request body parameter.
In some embodiments, the generating the reply sentence according to the query result returned by calling the external API request or the query result obtained by querying the database specifically includes the following steps:
Combining the entity corresponding to the query parameter extracted from the query problem and the query result into the same dictionary;
and filling the entities in the dictionary into the reply templates according to the reply templates with successful requests to obtain reply sentences.
Adding ApiNaturalLanguageGenerator classes, generating replies aiming at the results returned by the API, combining the entity extracted from the problem and the results returned by the API request into the same dictionary, filling the values in the dictionary into a reply template according to success_template, wherein the variables to be filled are still represented by "{ }, and the parameter filling is different from the parameter filling in the request, which supports the value filling of the dictionary and the list, thereby avoiding the value packaging of the results returned by the API in the code, wherein the dictionary is represented by".', and the list is represented by "[ ]". If success_template is "good", the data queried by you is { response_body.data [0] }. When the dictionary is matched to the existence of the "{ }", firstly, dividing the hierarchy of the dictionary according to the "hereof, including two hierarchies of the" response_body "and the" data [0] "wherein the" response_body "does not include the" [ ] "mark, directly taking the value 0 in the" [ ] "according to the dictionary, then further extracting the value with the key as the" data "from the value of the previous hierarchy, taking the value of the 0 th element according to the list, filling, if the value is the" 15 level ", finally returning the" good, and the data queried by you is the 15 level ".
In some embodiments, the determining to return the target service information by calling an external API or querying a database specifically includes the steps of:
judging whether API configuration is added in domain of Rasa frame;
if yes, determining to return target service information through an external API;
If not, determining to return the target service information by querying the database.
When API configuration is added in domain of Rasa frame, when the inquiry problem needs to be replied, the method of calling external API request is adopted to obtain target service information, and when non-API configuration is added in domain, the database is inquired to obtain target service information. In other embodiments, when an API configuration is added to domain of Rasa framework, the user may also obtain the requirement to make a selection to call an external API or query the database to return the target service information.
In another embodiment, the Rasa framework based method of invoking external APIs or querying databases aims at adding two Action classes, actionAPI for executing the invocation of external APIs and ActionDB for executing the database query, in addition to the specific response Action (responses) and Custom actions. And adding an NLG class ApiNaturalLanguageGenerator, and generating a reply aiming at the result of calling the external API and the database query.
The specific steps for calling the external API are as follows:
1. The API configuration is added in domain, a front-end configuration interface is shown in fig. 2, a yml file format acquired by the back-end is shown in fig. 3, wherein an action_api_name is an API interface name to be called, details of an API in details include a method request mode, a url interface address, a parameters query parameter, a headers request header parameter, a body request body parameter, a success_template is a reply template when the API request is successful, an error_template is a reply template when the request is failed, and a default_ nlg is an option of whether to call a large language model for color rendering.
2. The default Action ActionAPI is added, and the difference between the default Action and the custom Action is that the remote service is not called, and three steps of query parameter query filling, request body parameter filling and API request are executed by default, specifically as follows:
(1) Query parameter query filling, in which query parameters are spliced on a request address in the form of key-value pairs, and are generally used for transmitting smaller data, if an entity value needs to be transmitted in the query parameters, the entity value needs to be filled, for example, a user asks "what is the maximum wind power of mangosteen typhoons? The entity value of typhoon _name is extracted as 'mangosteen' in the NLU stage and recorded in a tracker of dialogue tracking, and the corresponding query API needs to input parameters TyphoonName, and a symbol of '{ }' is used for identifying entity variables in configuration, namely the parameter in the configuration parameters is { 'TyphoonName': { typhoon _name }, and the value of the input API after filling is { 'TyphoonName': mangosteen }.
(2) And (2) filling a request body parameter body, wherein the body parameter is data of a request main body part and is generally used for transmitting larger data, when a request mode is POST, if a filling entity value is required in the request body parameter, filling is carried out according to the same method in the step (1), and when the request mode is GET, only query parameters can be transmitted without the request body parameter.
(3) And executing an external API request according to url, method, headers, params, body, if the request fails, directly returning to the configured error_template, and if the request succeeds, storing the acquired result into a response_body and calling an NLG module.
3. Adding ApiNaturalLanguageGenerator classes, generating replies aiming at the results returned by the API, combining the entity extracted from the problem and the results returned by the API request into the same dictionary, filling the values in the dictionary into a reply template according to success_template, wherein the variables to be filled are still represented by "{ }, and the parameter filling is different from the parameter filling in the request, which supports the value filling of the dictionary and the list, thereby avoiding the value packaging of the results returned by the API in the code, wherein the dictionary is represented by".', and the list is represented by "[ ]". If success_template is "good", the data queried by you is { response_body.data [0] }. When the dictionary is matched to the existence of the "{ }", firstly, dividing the hierarchy of the dictionary according to the "hereof, including two hierarchies of the" response_body "and the" data [0] "wherein the" response_body "does not include the" [ ] "mark, directly taking the value 0 in the" [ ] "according to the dictionary, then further extracting the value with the key as the" data "from the value of the previous hierarchy, taking the value of the 0 th element according to the list, filling, if the value is the" 15 level ", finally returning the" good, and the data queried by you is the 15 level ".
The database query steps are as follows:
4. In the NLU stage, the intention category of database query is increased, each query intention corresponds to a different database table, a DB configuration record database table structure is increased in domain, as shown in fig. 4, wherein action_db_name is the operation name of the database query to be executed, table_name is the corresponding database table name, info is the description of the table, field is the attribute contained in the table, all attribute names and the meaning and types thereof are listed, success_template is a reply template when the database query is successful, error_template is a reply template when failure is caused, and default_ nlg is an option of whether to call a large language model for color rendering.
5. Adding a default action ActionDB, transferring the database table structure and the user problem fusion to a large language model, converting the database table structure and the user problem fusion into a database query sentence so as to obtain a query result, taking a MySQL database as an example, and setting the prompt words as follows:
"you are a MySQL expert please write out the query statement according to the given table Schema and questions.
The schema is as follows:
{schema}
The problems are as follows:
{question}
The query statement is written below: "
Filling up schema and question, wherein schema is all contents in a table_name level in configuration, and question is question text of a user question. And executing the query statement converted by the large language model on the database to obtain a final query result, and storing the final query result into the response_body.
6. And calling ApiNaturalLanguageGenerator class, generating a reply aiming at the database query result, and synchronizing step 3.
For the request of calling the external API, only the interface address, the input parameters, the output parameters, the request mode and the reply template are required to be filled, the external API can be directly called, the data returned by the API is automatically taken out to be filled according to the reply template, the custom action service is not required, the common user can also perform configuration, and the use threshold is reduced; for the query database, query intentions are classified in the NLU stage, the table structure is directly added into the prompt words and transmitted to the LLM, and the prompt words are directly converted into the database query language for query through a large model, so that the package service is not required for each query requirement, and the development engineering quantity is reduced.
The method does not need to encapsulate the service API for the second time, can directly multiplex the original interface, and reduces the development cost. The remote action service is not required to be configured, and the deployment is lighter. The code removal is realized, the common user can configure the code removal, the use threshold is reduced, and the maintenance is easier. Aiming at the scene without the packaging business API, the method supports the direct query of the database to acquire more business information, and the query statement is intelligently converted by using a large model, so that the method is simpler, more convenient and more flexible than the manual setting rule conversion.
Referring to fig. 5, in another embodiment, a storage medium 510 stores a computer program, and when the computer program is executed by a processor 520, the following steps are performed:
After receiving the inquiry problem of the user, determining to return target service information by calling an external API or inquiring a database;
When the external API is determined to be called, adding API configuration in domain of the Rasa framework according to the received query problem to carry out query parameter filling and request body parameter filling;
Then executing external API request according to the interface address, the query parameter, the request header parameter, the request body parameter and the request mode in the API configuration;
Receiving a query result returned by an external API request;
When the database is determined to be queried, determining a corresponding database table structure from DB configuration in domain according to the intention type of the database query in the NLU stage;
Fusing the determined database table structure and the query problem, transmitting the fused database table structure and the query problem to a large language model, converting the fused database table structure and the query problem into a database query sentence, and obtaining a query result;
And generating a reply sentence according to the query result returned by calling the external API request or the query result acquired by the query database, and returning the reply sentence to the user.
When the query problem of the user is received, determining to return target service information by calling an external API or a query database, and when the target service information is determined to be acquired by calling an external API request, performing query parameter filling and request body parameter filling on API configuration added in domain of the Rasa frame according to the received query problem, wherein the API configuration comprises an interface address, a query parameter, a request header parameter, a request body parameter and a request mode; after the filling of the query parameters and the filling of the request body parameters are completed, executing an external API request according to an interface address, a query parameter, a request header parameter, a request body parameter and a request mode in the API configuration, returning a query result, determining a corresponding database table structure from DB configuration in domain through the intention type of database query in an NLU stage when determining that target service information is acquired through the query database, wherein the DB configuration record database table structure is added in the domain, and the database table structure and the query problem are fused and transferred to a large language model to be converted into a database query statement to acquire the query result; after the external API is called to request to acquire the query result or the query database acquires the query result, a reply sentence is generated according to the query result and returned to the user. When an external API request is called, a user-defined action service is not needed, so that a common user can also perform configuration, and the use threshold is reduced; meanwhile, no matter the external API is called or the database is queried, the service does not need to be packaged for each query requirement, and the development engineering quantity is reduced.
In some embodiments, the query parameter filling comprises the steps of:
Judging whether the variable in the query parameter in the API configuration file has a filling mark or not;
if so, determining a corresponding entity value according to the query parameters in the query problem, and then filling the determined entity value into a filling identifier corresponding to the query parameters of the API configuration.
Query parameter query filling, wherein the query parameters are spliced on the request address in the form of key value pairs and are generally used for transmitting smaller data, and if entity values need to be transmitted in the query parameters, the entity values need to be filled, for example, a user asks "what is the maximum wind force of mangosteen typhoons? The entity value of typhoon _name is extracted as 'mangosteen' in the NLU stage and recorded in a tracker of dialogue tracking, and the corresponding query API needs to input parameters TyphoonName, and a symbol of '{ }' is used for identifying entity variables in configuration, namely the parameter in the configuration parameters is { 'TyphoonName': { typhoon _name }, and the value of the input API after filling is { 'TyphoonName': mangosteen }. Wherein the padding is identified as { }.
In some embodiments, the request body parameter filling specifically includes the following steps:
determining a request mode in API configuration;
when the request mode is POST, determining a corresponding entity value according to the request body parameter in the query problem, and then filling the determined entity value into a filling identifier corresponding to the request body parameter of the API configuration;
When the request mode is GET, then the request body parameter filling is not needed.
The body parameter is filled in the request body, the body parameter is the data of the request main body part, and is usually used for transmitting larger data, when the request mode is POST, if the entity value needs to be filled in the request body parameter, the filling is carried out according to the same method in the filling of the query parameter, and when the request mode is GET, the query parameter can only be transmitted without the request body parameter.
In some embodiments, the generating the reply sentence according to the query result returned by calling the external API request or the query result obtained by querying the database specifically includes the following steps:
Combining the entity corresponding to the query parameter extracted from the query problem and the query result into the same dictionary;
and filling the entities in the dictionary into the reply templates according to the reply templates with successful requests to obtain reply sentences.
Adding ApiNaturalLanguageGenerator classes, generating replies aiming at the results returned by the API, combining the entity extracted from the problem and the results returned by the API request into the same dictionary, filling the values in the dictionary into a reply template according to success_template, wherein the variables to be filled are still represented by "{ }, and the parameter filling is different from the parameter filling in the request, which supports the value filling of the dictionary and the list, thereby avoiding the value packaging of the results returned by the API in the code, wherein the dictionary is represented by".', and the list is represented by "[ ]". If success_template is "good", the data queried by you is { response_body.data [0] }. When the dictionary is matched to the existence of the "{ }", firstly, dividing the hierarchy of the dictionary according to the "hereof, including two hierarchies of the" response_body "and the" data [0] "wherein the" response_body "does not include the" [ ] "mark, directly taking the value 0 in the" [ ] "according to the dictionary, then further extracting the value with the key as the" data "from the value of the previous hierarchy, taking the value of the 0 th element according to the list, filling, if the value is the" 15 level ", finally returning the" good, and the data queried by you is the 15 level ".
In some embodiments, the determining to return the target service information by calling an external API or querying a database specifically includes the steps of:
judging whether API configuration is added in domain of Rasa frame;
if yes, determining to return target service information through an external API;
If not, determining to return the target service information by querying the database.
When API configuration is added in domain of Rasa frame, when the inquiry problem needs to be replied, the method of calling external API request is adopted to obtain target service information, and when non-API configuration is added in domain, the database is inquired to obtain target service information. In other embodiments, when an API configuration is added to domain of Rasa framework, the user may also obtain the requirement to make a selection to call an external API or query the database to return the target service information.
Finally, it should be noted that, although the embodiments have been described in the text and the drawings, the scope of the application is not limited thereby. The technical scheme generated by replacing or modifying the equivalent structure or equivalent flow by utilizing the content recorded in the text and the drawings of the specification based on the essential idea of the application, and the technical scheme of the embodiment directly or indirectly implemented in other related technical fields are included in the patent protection scope of the application.

Claims (10)

1. A method of invoking an external API or querying a database, comprising:
After receiving the inquiry problem of the user, determining to return target service information by calling an external API or inquiring a database;
When the external API is determined to be called, carrying out query parameter filling and request body parameter filling on API configuration added in domain of the Rasa framework according to the received query problem;
Then executing external API request according to the interface address, the query parameter, the request header parameter, the request body parameter and the request mode in the API configuration;
Receiving a query result returned by an external API request;
When the database is determined to be queried, determining a corresponding database table structure from DB configuration in domain according to the intention type of the database query in the NLU stage;
Fusing the determined database table structure and the query problem, transmitting the fused database table structure and the query problem to a large language model, converting the fused database table structure and the query problem into a database query sentence, and obtaining a query result;
And generating a reply sentence according to the query result returned by calling the external API request or the query result acquired by the query database, and returning the reply sentence to the user.
2. The method of claim 1, wherein the query parameter filling comprises the steps of:
Judging whether the variable in the query parameter in the API configuration file has a filling mark or not;
if so, determining a corresponding entity value according to the query parameters in the query problem, and then filling the determined entity value into a filling identifier corresponding to the query parameters of the API configuration.
3. The method of claim 1, wherein the request body parameter filling specifically comprises the following steps:
determining a request mode in API configuration;
when the request mode is POST, determining a corresponding entity value according to the request body parameter in the query problem, and then filling the determined entity value into a filling identifier corresponding to the request body parameter of the API configuration;
When the request mode is GET, then the request body parameter filling is not needed.
4. The method for calling external API or querying a database according to claim 1, wherein said generating a reply sentence according to the query result returned by the external API or the query result obtained by the query database comprises the steps of:
Combining the entity corresponding to the query parameter extracted from the query problem and the query result into the same dictionary;
and filling the entities in the dictionary into the reply templates according to the reply templates with successful requests to obtain reply sentences.
5. The method for calling external APIs or querying a database according to claim 1, wherein said determining to return the target service information by calling external APIs or querying a database comprises the steps of:
judging whether API configuration is added in domain of Rasa frame;
if yes, determining to return target service information through an external API;
If not, determining to return the target service information by querying the database.
6. A storage medium storing a computer program, characterized in that the computer program when run by a processor performs the steps of:
After receiving the inquiry problem of the user, determining to return target service information by calling an external API or inquiring a database;
When the external API is determined to be called, adding API configuration in domain of the Rasa framework according to the received query problem to carry out query parameter filling and request body parameter filling;
Then executing external API request according to the interface address, the query parameter, the request header parameter, the request body parameter and the request mode in the API configuration;
Receiving a query result returned by an external API request;
When the database is determined to be queried, determining a corresponding database table structure from DB configuration in domain according to the intention type of the database query in the NLU stage;
Fusing the determined database table structure and the query problem, transmitting the fused database table structure and the query problem to a large language model, converting the fused database table structure and the query problem into a database query sentence, and obtaining a query result;
And generating a reply sentence according to the query result returned by calling the external API request or the query result acquired by the query database, and returning the reply sentence to the user.
7. The storage medium of claim 6, wherein the query parameter filling comprises the steps of:
Judging whether the variable in the query parameter in the API configuration file has a filling mark or not;
if so, determining a corresponding entity value according to the query parameters in the query problem, and then filling the determined entity value into a filling identifier corresponding to the query parameters of the API configuration.
8. The storage medium of claim 6, wherein the request body parameter filling specifically comprises the steps of:
determining a request mode in API configuration;
when the request mode is POST, determining a corresponding entity value according to the request body parameter in the query problem, and then filling the determined entity value into a filling identifier corresponding to the request body parameter of the API configuration;
When the request mode is GET, then the request body parameter filling is not needed.
9. The storage medium of claim 6, wherein the generating the reply sentence according to the query result returned by the external API call or the query result obtained by the query database specifically comprises the steps of:
Combining the entity corresponding to the query parameter extracted from the query problem and the query result into the same dictionary;
and filling the entities in the dictionary into the reply templates according to the reply templates with successful requests to obtain reply sentences.
10. The storage medium of claim 6, wherein the determining to return the target service information by calling an external API or querying a database comprises:
judging whether API configuration is added in domain of Rasa frame;
if yes, determining to return target service information through an external API;
If not, determining to return the target service information by querying the database.
CN202410559955.4A 2024-05-08 2024-05-08 Method for calling external API or inquiring database and storage medium Pending CN118132568A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410559955.4A CN118132568A (en) 2024-05-08 2024-05-08 Method for calling external API or inquiring database and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410559955.4A CN118132568A (en) 2024-05-08 2024-05-08 Method for calling external API or inquiring database and storage medium

Publications (1)

Publication Number Publication Date
CN118132568A true CN118132568A (en) 2024-06-04

Family

ID=91248304

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410559955.4A Pending CN118132568A (en) 2024-05-08 2024-05-08 Method for calling external API or inquiring database and storage medium

Country Status (1)

Country Link
CN (1) CN118132568A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109101415A (en) * 2018-06-25 2018-12-28 平安科技(深圳)有限公司 Interface test method, system, equipment and the storage medium compared based on database
CN112685032A (en) * 2020-12-31 2021-04-20 北京赛思信安技术股份有限公司 Dynamic api visualization generation method based on spring boot frame
US20210124805A1 (en) * 2019-10-23 2021-04-29 Bayerische Motoren Werke Aktiengesellschaft Hybrid Policy Dialogue Manager for Intelligent Personal Assistants
CN117370523A (en) * 2023-10-17 2024-01-09 中国电信股份有限公司 Large language model application service method and device
CN117370493A (en) * 2023-09-22 2024-01-09 中国司法大数据研究院有限公司 Intelligent interaction method and device for system based on large language model

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109101415A (en) * 2018-06-25 2018-12-28 平安科技(深圳)有限公司 Interface test method, system, equipment and the storage medium compared based on database
US20210124805A1 (en) * 2019-10-23 2021-04-29 Bayerische Motoren Werke Aktiengesellschaft Hybrid Policy Dialogue Manager for Intelligent Personal Assistants
CN112685032A (en) * 2020-12-31 2021-04-20 北京赛思信安技术股份有限公司 Dynamic api visualization generation method based on spring boot frame
CN117370493A (en) * 2023-09-22 2024-01-09 中国司法大数据研究院有限公司 Intelligent interaction method and device for system based on large language model
CN117370523A (en) * 2023-10-17 2024-01-09 中国电信股份有限公司 Large language model application service method and device

Similar Documents

Publication Publication Date Title
CN101203906B (en) Method, equipment and system of dialogue management using scripts
CN100428241C (en) System and method for defining and translating chat abbreviations
CN117056471A (en) Knowledge base construction method and question-answer dialogue method and system based on generation type large language model
US6446098B1 (en) Method for converting two-dimensional data into a canonical representation
CN108491443A (en) By computer-implemented and method and computer system of user session
CN108446313B (en) Data format conversion method and device
CN109902087B (en) Data processing method and device for questions and answers and server
CN116483980A (en) Man-machine interaction method, device and system
CN107220274A (en) One kind visualization data-interface fairground implementation method
US6999934B2 (en) Method and system for processing, storing, retrieving and presenting information with an extendable interface for natural and artificial languages
CN116701601A (en) Man-machine interaction method
CN115714030A (en) Medical question-answering system and method based on pain perception and active interaction
CN109471957B (en) Metadata conversion method and device based on uniform tags
CN117668182A (en) Standard intelligent question-answering method and system integrating knowledge graph and large language model
CN118132568A (en) Method for calling external API or inquiring database and storage medium
CN115577085A (en) Processing method and equipment for table question-answering task
US20190108290A1 (en) Human assisted automated question and answer system using natural language processing of real-time requests assisted by humans for requests of low confidence
EP1297451B1 (en) Service provision in a communications network
CN111611344B (en) Complex attribute query method, system and equipment based on dictionary and knowledge graph
CN110210014B (en) Intelligent form system
CN117828064B (en) Question-answering system and construction method thereof
CN117573842B (en) Document retrieval method and automatic question-answering method
CN117951171A (en) Data processing method, device, electronic equipment and storage medium
Glasner et al. Automatic Construction of Explanation Networks for a Cooperative User Interface.
Soffer et al. Reusability of conceptual models: The problem of model variations

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination