Reliable dialogue method and system
By obtaining user target messages in the dialogue system and determining matching dialogue processes based on preset dialogue processes, the problems of consistency and coherence in long dialogues are solved, and the reliability and accuracy of dialogue content are achieved.
Patent Information
- Application Number
- CN202510291783.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-12
- Publication Date
- 2025-06-27
AI Technical Summary
The prior art is difficult to maintain consistency and coherence in long conversations, and it is prone to "illusion" phenomena, resulting in a lack of reliability in dialogue systems.
By obtaining the user's target message and searching based on the preset dialogue process, a matching dialogue process is determined, and a command list is generated to call the target data to ensure that the content of the reply is consistent with the facts and logically coherent.
The reliability of the conversation content is achieved, the risk of hallucination is eliminated, and the matching and accuracy of the conversation is ensured.
Smart Images

Figure CN120216644A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular, to a reliable dialogue method and system. Background Art
[0002] The dialogue system is one of the popular research directions in the field of natural language processing. With the development of artificial intelligence, the dialogue system has evolved from a simple rule-based system to a more complex machine learning-based model. Among them, dialogues in the form of task-oriented dialogues, as an important form of human-computer interaction, have been widely used in fields such as customer service, information query, and e-commerce.
[0003] In related technologies, artificial intelligence large models are often used to understand and respond to user inputs, and can even perform complex tasks without explicit programming. However, although artificial intelligence large models perform well in dialogues, their ability to maintain consistency and coherence in long dialogues is limited, and they are prone to the so-called "hallucination" phenomenon - that is, generating dialogue content that does not conform to facts or is illogical. This uncertainty leads to the lack of reliability of the dialogue system. Summary of the Invention
[0004] What the present invention aims to solve is the problem that when using related technologies for dialogue, the generated dialogue content does not conform to facts or is illogical, resulting in the lack of reliability of the dialogue system.
[0005] To solve the above problems, in a first aspect, the present invention provides a reliable dialogue method, including:
[0006] Obtain a user's first target message, and retrieve based on a preset dialogue process to obtain a first dialogue process that matches the user's first target message, where the preset dialogue process is the steps required to complete the dialogue, and the preset dialogue process includes the first dialogue process;
[0007] Reply to the user's first target message according to the first dialogue process, and obtain a user's second target message, where the user's second target message is the user's target message after the user's first target message;
[0008] Generate a command list according to the user's first target message, the user's second target message, and the first dialogue process;
[0009] According to the command list, call target data that matches the step, and reply to the user's second target message according to the target data.
[0010] Optionally, the obtaining a user's first target message and retrieving based on a preset dialogue process to obtain a first dialogue process that matches the user's first target message includes:
[0011] Convert the user's first target message into a first vector;
[0012] Search in a preset vector database according to the first vector, and determine a second vector that meets the preset similarity condition with the first vector. Among them, the preset vector database is a set of vectors corresponding to the definition description of the preset dialogue process, and the second vector is the vector corresponding to the definition description of the first dialogue process.
[0013] Optionally, replying to the user's first target message according to the first dialogue process and obtaining the user's second target message includes:
[0014] Judge whether the user's first target message contains slot data corresponding to the steps of the first dialogue process, where the slot data is a variable in the steps required to complete the dialogue;
[0015] If so, obtain the user's second target message, and the user's second target message includes user confirmation information;
[0016] If not, request to obtain the user's second target message, and the user's second target message contains the slot data.
[0017] Optionally, judge whether the type of the steps of the first dialogue process meets the preset type;
[0018] If so, automatically fill the slot data corresponding to the steps of the preset type according to the pre-stored slot data.
[0019] Optionally, generating a command list according to the user's first target message, the user's second target message, and the first dialogue process includes:
[0020] Fill a prompt template containing a prompt instruction according to the first dialogue process, the user's first target message, and the user's second target message to generate a prompt statement, and input the prompt statement into a preset model to generate the command list, where the prompt statement is used to instruct the preset model to output the command list that meets the set format according to the input.
[0021] Optionally, filling a prompt template containing a prompt instruction according to the first dialogue process, the user's first target message, and the user's second target message to generate a prompt statement, and inputting the prompt statement into a preset model to generate the command list includes:
[0022] Determine the current conversation based on the user's first target message, the user's second target message, and the first conversation flow, where the current conversation includes the latest user message;
[0023] Fill the prompt template according to the first conversation flow and the current conversation to generate the prompt statement, input the prompt statement into the language large model, and generate the command list. The prompt statement includes starting the first conversation flow according to the defined description, filling the slot data according to the current conversation, correcting the filled slot data according to the latest user message, and handling abnormal situations. The command list corresponds to the prompt statement, and the preset model includes the language large model.
[0024] Optionally, the replying to the user's second target message according to the target data matching the step according to the command list includes:
[0025] Execute the command list and call the target data matching the step in a preset manner. The preset manner includes calling an API, querying a database, and querying a knowledge base.
[0026] Optionally, if there are multiple first conversation flows, the executing the command list includes:
[0027] Push the multiple first conversation flows into the conversation stack, locate the steps of each first conversation flow through a process cursor, process the first conversation flows one by one in the reverse order of the entry sequence into the conversation stack, and continue to process the next first conversation flow based on the step located by the process cursor after processing the previous first conversation flow. The processing order of the first conversation flow is the reverse order of the entry sequence into the conversation stack, and each first conversation flow is popped out of the conversation stack after being processed.
[0028] Optionally, it further includes:
[0029] Determine whether the latest user message deviates from the normal preset conversation flow;
[0030] If so, generate a correction command, where the correction command is used for deviation correction processing according to the latest user message.
[0031] A reliable conversation method provided by the present invention obtains the user's first target message and retrieves it based on a preset conversation flow to obtain a first conversation flow that matches the user's first target message; replies to the user's first target message according to the first conversation flow and obtains the user's second target message. Thus, it realizes the guidance and reply to the user's target message, and ensures the matching degree of replying to the user's target message through the determined first conversation flow, rather than completing the subsequent conversation by guessing, thereby eliminating the risk of hallucination. Further, according to the user's first target message, the user's second target message and the first conversation flow, a command list is generated. The command list can be generated by, for example, a language model. Then, according to the command list, target data matching the steps is called. The target data can be obtained through an external real-time interface. According to the target data, the user's second target message is replied. Since the target data comes from (real-time updated) facts and strictly matches the steps in the first conversation flow, that is, matches the user's target message, thus, accurate natural language understanding can be realized and the user's target message can be replied, ensuring the reliability of the conversation.
[0032] In a second aspect, the present invention further provides a reliable conversation system that applies the reliable conversation method described in any one of the above, including:
[0033] A service module for obtaining the user's first target message and retrieving it based on a preset conversation flow to obtain a first conversation flow that matches the user's first target message. Wherein, the preset conversation flow is the steps required to complete the conversation, and the preset conversation flow includes the first conversation flow;
[0034] An agent module for replying to the user's first target message according to the first conversation flow and obtaining the user's second target message. Wherein, the user's second target message is the user's target message after the user's first target message;
[0035] The agent module is further configured to: generate a command list according to the user's first target message, the user's second target message and the first conversation flow;
[0036] The agent module is further configured to: call target data matching the steps according to the command list, and the target data is used to reply to the user's second target message.
[0037] In a third aspect, the present invention provides an electronic device, including a memory and a processor;
[0038] The memory is used to store a computer program;
[0039] The processor is used to implement the reliable dialogue method as described in the first aspect when executing the computer program.
[0040] In a fourth aspect, the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the reliable dialogue method as described in the first aspect is implemented.
[0041] The beneficial effects of the reliable dialogue system, electronic device, and computer-readable storage medium provided by the present invention relative to the prior art are the same as those of the reliable dialogue method relative to the prior art, and will not be elaborated here. Description of the Drawings
[0042] Figure 1 It shows a schematic flowchart of a reliable dialogue method in an embodiment of the present invention;
[0043] Figure 2 It shows a schematic structural diagram of a process stack in an embodiment of the present invention;
[0044] Figure 3 It shows a schematic structural diagram of a reliable dialogue system in an embodiment of the present invention;
[0045] Figure 4 It shows a schematic structural diagram of an electronic device in an embodiment of the present invention. Detailed Embodiments
[0046] To make the above objects, features, and advantages of the present invention more obvious and understandable, the following detailed description of the specific embodiments of the present invention will be given with reference to the accompanying drawings.
[0047] It should be noted that relational terms such as "first" and "second" in the present invention are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including", or any other variation thereof is intended to cover a non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0048] In the description of this specification, the descriptions referring to terms such as "embodiment", "one embodiment", and "one implementation manner" mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or implementation manner are included in at least one embodiment or implementation manner of the present invention. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment or implementation manner. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or implementation manners.
[0049] Referring to Figure 1 As shown, an embodiment of the present invention provides a reliable dialogue method;
[0050] The reliable dialogue method includes:
[0051] S100: Obtain the user's first target message, and perform a search based on a preset dialogue process to obtain a first dialogue process that matches the user's first target message, where the preset dialogue process is the steps required to complete a dialogue, and the preset dialogue process includes the first dialogue process.
[0052] Specifically, the user's first target message is generally a relatively formal message input by the user at the beginning, rather than a chat or wake-up message. The user's first target message generally has the purpose of querying a message, and the dialogue in the present invention mainly includes dialogues in vertical fields (referring to fields further subdivided according to specific requirements or goals under a certain large field, such as water level monitoring and management, groundwater hydrology, soil moisture, etc. in the hydrology field), and search for the first dialogue process corresponding to the user's message. The preset dialogue process includes the steps to complete the dialogue in this dialogue field. For example, for the process of querying water conditions, the steps respectively include asking about time and asking about the type of hydrological measurement.
[0053] S200: Reply to the user's first target message according to the first dialogue process, and obtain the user's second target message, where the user's second target message is the user's target message after the user's first target message.
[0054] Specifically, when replying to the user's first target message according to the first conversation flow, the corresponding steps in the first conversation flow are used to reply to the user's first target message. For example, when the user's first target message is "want to query the water level of a hydrological station", based on the preset conversation flow, the reply is: May I ask what time you want to query? And the user's second target message is the target message after the user's first target message, and the user's second target message is also not a casual chat or wake-up message. For example, at this time, the user's second target message is "the current moment". It should be noted that when there are multiple sub-steps in the preset conversation flow, correspondingly, the user's target message needs to be replied to multiple times until the step of finally determining the data to be called is determined according to the first conversation flow. For example, after determining the time, further determine that the type of hydrological station is a reservoir.
[0055] S300: Generate a command list according to the user's first target message, the user's second target message, and the first conversation flow.
[0056] Specifically, in order to call the target data, before calling the target data according to the user's target message, it is necessary to synthesize the user's target message and the first conversation flow, etc., to generate a command list. The command list can realize the format conversion from unstructured text to structured text, so as to convert unstructured text, such as natural language, etc. into structured text, such as data tables, JSON formats, etc., so as to meet the format requirements of the call.
[0057] S400: According to the command list, call the target data matching the step, and reply to the user's second target message according to the target data.
[0058] Specifically, before calling the target data according to the command list, the call interface needs to be pre-connected, such as an application programming interface (API). Since the command list already meets the format requirements of structured text, it is possible to realize the rapid call of the target data, so as to reply to the second target message. According to the foregoing example, for example, the finally replied is the current water situation of the reservoir.
[0059] When this embodiment is applied in practice, by obtaining the user's first target message and retrieving based on a preset conversation flow to obtain a first conversation flow that matches the user's first target message; replying to the user's first target message according to the first conversation flow, and obtaining the user's second target message. Thus, it realizes the guidance and reply to the user's target message, and ensures the matching degree of replying to the user's target message through the determined first conversation flow, rather than completing the subsequent conversation by guessing, thereby eliminating the risk of hallucination. Further, according to the user's first target message, the user's second target message and the first conversation flow, a command list is generated. The command list can be generated by, for example, a language model. Then, according to the command list, target data matching the steps is called. The target data can be obtained through an external real-time interface. According to the target data, the user's second target message is replied. Since the target data is sourced from (real-time updated) facts and strictly matches the steps in the first conversation flow, that is, matches the user's target message, thus, it can achieve accurate natural language understanding and reply to the user's target message, ensuring the reliability of the conversation.
[0060] It should be noted that since it avoids completing the conversation by guessing and obtains the target data through the command list to achieve the user's final reply, to a certain extent, it can reduce the labeled data required for guessing conversations and the labeled data required when directly using a large model for conversations in related technologies. Furthermore, to a certain extent, it also reduces the amount of data training, ensuring the scalability and maintainability of the conversation system.
[0061] As an optional embodiment of the present invention, the obtaining the user's first target message and retrieving based on a preset conversation flow to obtain a first conversation flow that matches the user's first target message includes:
[0062] Converting the user's first target message into a first vector.
[0063] Specifically, when converting the user's first target message into a first vector, natural language processing techniques are often used. For example, the user's first target message text is processed through an Embedding model and then converted into a vector.
[0064] Embedding model: A model that maps high-dimensional data (such as text, images, etc.) to a low-dimensional continuous vector space. These vectors (i.e., Embeddings) can capture the semantic information of the data and are used for various machine learning tasks. The core goal of the Embedding model is to convert discrete data (such as words, categories) into continuous numerical representations for the computer to better process and understand.
[0065] Search in the preset vector database according to the first vector, and determine a second vector that meets the preset similarity condition with the first vector, where the preset vector database is a set of vectors corresponding to the definition description of the preset conversation flow, and the second vector is the vector corresponding to the definition description of the first conversation flow.
[0066] Specifically, the text of the definition description of the preset conversation flow will be vectorized by an Embedding model and stored in the preset vector database. According to the first vector, after calculating the similarity, a second vector that meets the preset similarity threshold with the first vector is found, so as to determine the corresponding first conversation flow.
[0067] When applied in practice, this embodiment can effectively improve the accuracy and efficiency of the system in processing user messages by adopting a dialogue system design based on vector retrieval, so that the user intention can be accurately matched and the user needs can be more effectively met, in order to efficiently determine the first conversation flow that matches the user's first target message. It should be noted that the first conversation flow includes at least one conversation flow.
[0068] As an optional embodiment of the present invention, the replying to the user's first target message according to the first conversation flow and obtaining the user's second target message includes:
[0069] Judge whether the user's first target message contains the slot data corresponding to the steps of the first conversation flow, where the slot data is a variable in the steps required to complete the conversation.
[0070] Specifically, for the slot data, its specific role is to help the system extract the key information required to complete the task from the user's input. Simply put, the slot (data) is a "variable" used to store specific information in the dialogue system. When the user's first target message may include the variable of the slot data or may not include this variable. According to the first conversation flow, after the process description is triggered, the process starts. At this time, the time slot data should be confirmed. Therefore, it is first judged based on the user's first target message.
[0071] Exemplarily, when the user's conversation is "I want to query the water level of the station (the first case, not including the time slot in the first conversation flow)" or "I want to query the current water level of the station (the second case includes the time slot in the first conversation flow)".
[0072] If so, obtain the user's second target message, and the user's second target message includes user confirmation information;
[0073] Specifically, in the second case, confirmation from the user is required. At this time, the user's second target message includes user confirmation information.
[0074] If not, request to obtain the second target message of the user, where the second target message of the user includes the slot data.
[0075] Specifically, in the first case, the slot data is obtained through a conversation at this time. For example, for the time in the first case, the conversation reply at this time can be: What time do you need to query?
[0076] When applied in practice, this embodiment can quickly determine the desired slot data by based on the first conversation flow and in combination with the first target message of the user, and ensure that the slot data is directly replied or directly extracted and then determined, that is, valid.
[0077] As an optional embodiment of the present invention, it further includes:
[0078] Determine whether the type of the step of the first conversation flow meets a preset type;
[0079] If so, automatically fill the slot data corresponding to the step of the preset type with the pre-stored slot data. When it is a negative case, the step of obtaining the slot data needs to be executed.
[0080] Specifically, in the process of actively filling the slot data, the slot data does not come from the user but from pre-storage. For example, if it is a reservoir type, after querying the water situation, setting an early warning process, the personnel mobile phone number and different measuring station types are directly obtained from the storage, and then warning information is sent to the mobile phone through the mobile phone number for early warning.
[0081] When applied in practice, this embodiment can realize the retrieval and use of target data in some special cases by automatically filling the slot data, so as to ensure the effective use of the target data under the previous slot data.
[0082] As an optional embodiment of the present invention, the generating a command list according to the first target message of the user, the second target message of the user, and the first conversation flow includes:
[0083] Fill the prompt template containing prompt instructions according to the first conversation flow, the user's first target message, and the user's second target message to generate a prompt statement, and input the prompt statement into a preset model to generate the command list. The prompt statement is used to instruct the preset model to output the command list that conforms to the set format. The set format includes structured statements or semi-structured statements. Therefore, the target data can be called through the statements in this set format. Therefore, there is no need to directly conduct a question-and-answer through the preset model, ensuring that the user is replied with the target data, and the replied data is relatively accurate, ensuring the reliability of the conversation.
[0084] Table 1 below gives an example of a preset conversation flow.
[0085] Table 1:
[0086]
[0087] In the process of Table 1, it is defined using the YAML format (including action). Among them, the process id is a unique identifier to ensure that each process has a unique identifier to avoid conflicts; the description field is a description and summary of the process, which determines when to start this process; the condition field is used to define the trigger condition of the process, supporting script languages such as python; the steps field is used to define the steps required to complete the task. Each step has a type, and the type determines the functions it supports. The types are divided into action (behavior step, execute custom behaviors, such as calling an API, querying a database or a knowledge base to return information, etc., which are pre-connected by developers and performed after collect), collect (collection step, used to request information from the user to fill the slot data, such as a time type slot), set_slots (used to set the slot data, mainly to actively set the slot data, not from the user), call (used to start other sub-processes in the current process and continue the steps of the current process after the sub-process is completed); the step contains an id field (unique identifier) and a next field (used to specify the id of the next step, which can be used in combination with conditional statements such as if-else).
[0088] The following gives an example of a conversation.
[0089] A: I want to query the water level of the measuring station.
[0090] R: What time do you need to query?
[0091] A: Right now.
[0092] R: What is the type of the measuring station to be queried?
[0093] A: Tell me a joke.
[0094] R: xx (content of a cold joke).
[0095] R: What is the type of the hydrological station for which you need to query the water regime?
[0096] A: For a reservoir.
[0097] R: Okay, the current water regime of the reservoir hydrological station is as follows: xx0 Reservoir, 412.51m, and the reservoir capacity is 20 million m³.
[0098] Among them, R represents the message replied by the system, and A represents the user's message.
[0099] The corresponding commands are given below:
[0100] StartFlow(water_query_flow) # Start the process with the process ID water_query_flow; Setslot(time,'2025-01-08 08:00:00') # Set the value of the time slot time to '2025-01-08 08:00:00';
[0101] Chitchat # A chitchat command that triggers the processing of the dialogue correction module 300;
[0102] Setslot(stationType,'reservoir') # Set the value of the station type slot stationType to'reservoir'.
[0103] The above respectively shows a simple scenario of querying the water regime of a hydrological station. The examples of the dialogue will ultimately be converted into corresponding commands. The command types are divided into StartFlow (start a process), SetSlot (set slot data), CancelFlow (cancel a process, trigger the processing of the dialogue correction module 300), SkipStep (skip a step, trigger the processing of the dialogue correction module 300), CorrectSlot (correct slot data, trigger the processing of the dialogue correction module 300), ChitChat (chitchat, trigger the processing of the dialogue correction module 300), Error (internal error, trigger the processing of the dialogue correction module 300), HumanHandoff (transfer to an operator, trigger the processing of the dialogue correction module 300), and CantHandle (unable to handle, trigger the processing of the dialogue correction module 300).
[0104] Specifically, a detailed example of a prompt template (including restricted prompt words) is given below. The prompt template is used to fill in the corresponding information according to the first dialogue process, the user's first target message, and the second user information to obtain a prompt statement.
[0105] Your task is to analyze the context of the current conversation and generate a set of commands to start a new process, extract slot information, or answer casual conversations and knowledge questions (with limited prompts).
[0106] The following are the available processes, including the process ID (flow_id), its process description, and slot information:
[0107] {%for flow in available_flows%};
[0108] {{flow.name}}: {{flow.description}};
[0109] {%for slot in flow.slots-%};
[0110] slot: {{slot.name}}{%if slot.description%}-{{slot.description}}{%endif%}{%endfor%};
[0111] {%-endfor%};
[0112] ===
[0113] This is the context of the current conversation:
[0114] {{current_conversation}};
[0115] ===
[0116] {%if current_flow!=None%};
[0117] You are currently in the process of "{{current_flow}}";
[0118] You just asked the user for the slot "{{current_slot}}"{%if current_slot_description%}-{{current_slot_description}}{%endif%};
[0119] {%else%};
[0120] You have not started any process yet, which means you can only set slots when a process that requires slots is started, and you can only set the required slots (with limited prompts).
[0121] {%endif%};
[0122] If you have enabled the process, you can choose to fill the slots of the process with the information provided by the user in their message.
[0123] The user just said "{{user_message}}";
[0124] ===
[0125] Generate a list of commands you want to execute according to the above information and format requirements. Your task is to start the process and fill the slots when appropriate, and the subsequent logic is handled by the command execution module (prompt word limit).
[0126] The following are the commands that can be executed:
[0127] - Start the process, in the format of "StartFlow(flow_id)", e.g., StartFlow(water_query_flow) - Set slot data, in the format of "SetSlot(slot_name,slot_value)", e.g., SetSlot(time,'2025-01-08 08:00:00');
[0128] - Cancel the current process, in the format of "CancelFlow()";
[0129] - Intercept and handle messages that bypass the current process step, in the format of "SkipStep()", e.g., when the user intends to skip the inquiry for collecting slot data;
[0130] - Correct slot data, in the format of "CorrectSlot()", e.g., when the user wants to modify the previous slot information - Internal error, generated when an unknown error occurs inside the system, in the format of "Error()";
[0131] - Transfer to human, generated when the user appears frustrated or explicitly requests to talk to a human customer service, in the format of "HumanHandoff()";
[0132] - Chat, in the format of "ChitChat";
[0133] - Can't handle, default generated when you can't accurately generate the correct command, in the format of "CantHandle()";
[0134] ===
[0135] The following requirements you must strictly abide by (prompt word limit):
[0136] - Generate a list of commands you want to execute, one per line, arranged in the order of execution;
[0137] - Do not generate any information other than the command list;
[0138] - Do not use abstract values or placeholders to fill in the slots;
[0139] - Only use the information provided by the user;
[0140] - Only start the process when the user's intention is fully determined. If it is not fully determined, confirm with the user;
[0141] - Don't be overconfident. Adopt a conservative approach and confirm with the user before proceeding;
[0142] - Focus on the last user message and process it step by step;
[0143] - Only use the previous conversation context to help with understanding.
[0144] The above is the detailed format of the prompt template. Combining the foregoing answers regarding the command format, it is not difficult to obtain the above results.
[0145] When this embodiment is applied in practice, by combining the user's conversation and the corresponding slot data in the first conversation process, for example, through summary processing, only using the information provided by the user, and when the user's intention is fully confirmed, combining an intelligent model to output the format of the command list to be executed (set format). This set format includes the YAML format. YAML is a format specifically used for data serialization and is often used in configuration files and data exchange.
[0146] As an alternative embodiment of the present invention, filling the prompt template containing prompt instructions according to the first conversation process, the user's first target message, and the user's second target message, generating a prompt statement and inputting the prompt statement into a preset model to generate the command list includes:
[0147] Determine the current conversation according to the user's first target message, the user's second target message, and the first conversation process. The current conversation includes the latest user message;
[0148] Specifically, when determining the current conversation, it is only necessary to complete one slot data. Screen the conversation regarding the latest slot data to obtain the current conversation. Generally, it is necessary to remove the conversations with no actual meaning, and the current conversation includes the user's latest message. For example, the context of the current conversation obtained from the foregoing conversation example is as follows.
[0149] This is the context of the current conversation:
[0150] {"user": "I want to query the water level of the measuring station"};
[0151] {"bot": "May I ask what time you want to query?"};
[0152] {"user": "Right now"}.
[0153] Based on the first conversation flow and the current conversation, fill the prompt template to generate the prompt statement, input the prompt statement into the language model, and generate the command list. Among them, the prompt statement includes starting the first conversation flow according to the definition description, filling the slot data according to the current conversation, correcting the filled slot data according to the latest user message, and handling exception situations. The command list corresponds to the prompt statement, and the preset model includes the language model.
[0154] Specifically, when filling the prompt template, only the first conversation flow needs to be filled each time. Correspondingly, information such as process descriptions is also required. The current conversation also needs to be filled. The prompt template is used to prompt the language model to generate commands according to requirements, realizing the conversion of unstructured text into structured text (meeting the set format) for retrieving target data. According to the above, the command types are mainly divided into StartFlow (starting the process: starting the first conversation flow according to the definition description), SetSlot (setting slot data: filling the slot data according to the current conversation), and handling exception situations.
[0155] Among them, handling exception situations includes, for example, changing slot data, indicating that the user hopes to modify the previous slot data, correcting the slot data, in the format of "CorrectSlot()", for example, the user hopes to modify the previous slot information (specific details can be found in the subsequent part of handling exception situations).
[0156] The following gives a practical example based on the above-mentioned prompt template.
[0157] Your task is to analyze the context of the current conversation and generate a set of commands for starting a new process, extracting slot information, or answering casual conversations and knowledge questions.
[0158] ===
[0159] The following are the available processes, including the process id (flow_id), its process description, and slot information:
[0160] - water_query_flow: This process is used to query the water conditions of hydrological stations;
[0161] slot: time - Query time slot;
[0162] slot: stationType - Hydrological station type slot;
[0163] ===
[0164] This is the context of the current conversation:
[0165] {"user": "I want to query the water level of the measuring station"};
[0166] {"bot": "May I ask what time you want to query?"};
[0167] {"user": "Right now"};
[0168] ===
[0169] You haven't started any process yet. This means that you can only set slots when a process that requires slots is started, and only set the required slots.
[0170] If you start a process, you can choose to fill the slots of the process with the information provided by the user in their message.
[0171] The user just said "Right now"
[0172] ===
[0173] Generate a list of commands you want to execute according to the above information and format requirements. Your task is to start the process and fill the slots appropriately, and the subsequent logic will be handled by the command execution sub-module.
[0174] The following are the commands that can be executed:
[0175] - Start the process, in the format of "StartFlow(flow_id)", for example, StartFlow(water_query_flow);
[0176] - Set the slot data, in the format of "SetSlot(slot_name,slot_value)", for example, SetSlot(time,'2025-01-08 08:00:00');
[0177] - Cancel the current process, in the format of "CancelFlow()";
[0178] - Intercept and process messages that bypass the current process step, in the format of "SkipStep()", for example, when the user intends to skip the inquiry for collecting slot data;
[0179] - Correct the slot data, in the format of "CorrectSlot()", for example, when the user wants to modify the previous slot information;
[0180] - Internal error, generated when an unknown error occurs inside the system, in the format of "Error()";
[0181] - Transfer to human, generated when the user appears frustrated or explicitly requests to talk to a human customer service representative, in the format of "HumanHandoff()";
[0182] - ChitChat, in the format of "ChitChat";
[0183] - Can't Handle, the default command generated when you can't accurately generate the correct command, in the format of "CantHandle()";
[0184] ===
[0185] The following requirements must be strictly adhered to:
[0186] - Generate a list of commands you want to execute, one per line, arranged in the order of execution;
[0187] - Don't generate any other information except the command list;
[0188] - Don't fill slots with abstract values or placeholders;
[0189] - Only use the information provided by the user;
[0190] - Only start the process when you are completely sure of the user's intention. If not, you need to confirm with the user;
[0191] - Don't be overconfident, adopt a conservative approach, and confirm with the user before proceeding;
[0192] - Focus on the last user message and process it step by step;
[0193] - Only use the previous conversation context to help with understanding.
[0194] Combined with the foregoing statements and the cases of actual prompt templates, the above embodiments can satisfy the process of setting slot data in normal conversation scenarios and the correction process in abnormal scenarios, and generate a command list based on a language large model according to the set format. Thus, accurate natural language understanding can be achieved without relying on additional labeled data, greatly reducing the workload of data preparation. By using a language large model to determine how the user wishes to conduct the conversation (output a fixed set of commands), rather than guessing the correct steps to complete the process, and using the Flow Policy sub-module to control the precise execution of the process, the generated content strictly conforms to facts and logic, improving the reliability of the conversation.
[0195] The process handling process of the process policy sub-module is introduced in detail below. It is applied to the handling of multiple conversation processes. The process policy sub-module is used when there are multiple first conversation processes. Executing the command list. When there are multiple first conversation processes, the execution of the command list specifically includes:
[0196] Push multiple first conversation processes into the conversation stack, and position the steps of each first conversation process through a process cursor. Process the first conversation processes one by one in the reverse order of the order of entering the conversation stack. After processing the previous first conversation process, continue to process the next first conversation process based on the step positioned by the process cursor. Among them, the processing order of the first conversation process is the reverse order of the order of entering the conversation stack, and each first conversation process is popped out of the conversation stack after being processed.
[0197] It should be noted that the above is the processing process of the first conversation process without digressing, using a LIFO (Last In First Out) conversation stack and internal process slots to manage the state of the conversation.
[0198] Specifically, as Figure 2 shown, it is the structure of the conversation stack. When a process (the first conversation process) starts, it is pushed into the conversation stack and removed from the conversation stack after the process ends. The process cursor is used to track the steps that each process is currently at (when there is slot data), ensuring that the latest started first conversation process (indicating the start of a certain step in its process) will be processed first, and the old process will continue after the new process is completed. This structure can manage the states and execution orders of multiple processes, which means it can support complex conversation scenarios, which may involve the start and interaction of multiple first conversation processes (the first conversation processes in the conversation stack are all considered to be in the open state).
[0199] It should be noted that when it comes to the step of collecting slot data, the system will ask the user to request to fill in the relevant slot data, and the next step can only be carried out after the user's reply. When there may be a situation deviating from the normal business logic, the processing process of the correction command will be triggered.
[0200] As an optional embodiment of the present invention, the handling of abnormal situations further includes:
[0201] Judge whether the latest user message deviates from the normal preset conversation process;
[0202] If so, generate a correction command, where the correction command is used to perform deviation correction processing based on the latest user message.
[0203] For example: Process CancelFlow (cancel the process, trigger the processing of the dialogue correction module 300);
[0204] SkipStep (skip the step, trigger the processing of the dialogue correction module 300), CorrectSlot (correct the slot data, trigger the processing of the dialogue correction module 300), ChitChat (chat, trigger the processing of the dialogue correction module 300), Error (internal error, trigger the processing of the dialogue correction module 300), HumanHandoff (transfer to human, trigger the processing of the dialogue correction module 300), and CantHandle (unable to handle, trigger the processing of the dialogue correction module 300).
[0205] Accordingly, the format of the command list generated by the language model is as follows:
[0206] - Cancel the current process, in the format of "CancelFlow()";
[0207] - Intercept and process the message that bypasses the current process step, in the format of "SkipStep()", for example, the user intends to skip the inquiry for collecting slot data;
[0208] - Correct the slot data, in the format of "CorrectSlot()", for example, the user hopes to modify the previous slot information;
[0209] - Internal error, generated when an unknown error occurs inside the system, in the format of "Error()";
[0210] - Transfer to human, generated when the user appears frustrated or explicitly requests to talk to a human customer service, in the format of "HumanHandoff()";
[0211] - Chat, in the format of "ChitChat";
[0212] - Unable to handle, this command is generated by default when you are unable to accurately generate the correct command, in the format of "CantHandle()".
[0213] Specifically, always pay attention to the latest user messages to handle possible situations that deviate from the normal business logic, such as when the user interrupts the current dialogue process or starts chatting, including off-topic, correcting information, canceling the process, skipping steps, chatting, unclear intent, unknown system errors, tasks that cannot be handled, and requests to transfer to human, etc. Each situation defines a corresponding default processing flow. The following is the description of various situations and the corresponding processing flows.
[0214] Off-topic occurs when the user switches from the current process to another process. The processing flow is as follows: (The system) continues the previous process (there may be a query asking whether to continue the current conversation process, and this processing logic is different from the processing of multiple first conversation processes when executing the command list); correction of information occurs when the user hopes to modify the previous information or correct an error. The processing flow is as follows: confirm the modified information with the user; cancellation of the process occurs when the user cancels a certain process in the middle of the conversation. The processing flow is as follows: cancel the process and reply with a cancellation message; skipping steps occurs when the user intends to skip the query for the number of collected slots. The processing flow is as follows: confirm with the user whether to continue answering or cancel the process; small talk occurs during the conversation but does not affect the progress of the process. The processing flow is as follows: the large language model makes a small talk reply; unclear intention occurs when the user's intention cannot be recognized or there are multiple process matches. The processing flow is as follows: list the possible processes for the user to select and confirm; unknown system error occurs when an unknown error appears inside (the system). The processing flow is as follows: remind the user that the system is under maintenance and notify the administrator to perform maintenance through text message or email; unprocessable task occurs when the large language model cannot accurately generate the correct command. The processing flow is as follows: request the user to rephrase; request for transfer to an operator occurs when the user requests to contact an operator for a reply. The processing flow is as follows: access the conversation channel for the operator's reply.
[0215] When this embodiment is applied in practice, the above can ensure the rectification of the deviation from the normal preset conversation process and improve the human-computer efficiency of the user.
[0216] As an optional embodiment of the present invention, the step of calling the target data matching the step according to the command list and replying to the user with the second target message according to the target data includes:
[0217] Execute the command list and call the target data matching the step through a preset method. The preset method includes calling an API, querying a database, and querying a knowledge base.
[0218] Specifically, when calling an API, communication can be carried out with external or internal systems through the application programming interface (API) to obtain real-time data. For example, the latest weather data and the latest order situation can be requested from a third-party service through a RESTful API (Representational State Transfer, an application programming interface API based on the REST architectural style); when querying a database, access the data stored in the database, which may include executing SQL queries to retrieve specified information, such as user records, order information, etc.; when querying a knowledge base, access a structured knowledge base to obtain relevant knowledge or information, which may involve text, documents, or other unstructured data; the data structure is usually highly structured, in the format of a relational database management system (such as MySQL, PostgreSQL) or a non-relational database (such as MongoDB), and the data is stored in tabular form with clear fields and data types, while the structure of the database is more flexible, usually semi-structured or unstructured, containing text, images, and other media files, and natural language processing technology can be used to process and understand the data.
[0219] As Figure 3 shown, the present invention also provides a reliable dialogue system, which applies the reliable dialogue method described in the above embodiments, including:
[0220] A business module 100, configured to obtain a first target message of a user and retrieve based on a preset dialogue process to obtain a first dialogue process that matches the first target message of the user, where the preset dialogue process is the steps required to complete a dialogue, and the preset dialogue process includes the first dialogue process;
[0221] An agent module 200, configured to reply to the first target message of the user according to the first dialogue process and obtain a second target message of the user, where the second target message of the user is the user target message after the first target message of the user;
[0222] The agent module 200 is further configured to: generate a command list according to the first target message of the user, the second target message of the user, and the first dialogue process;
[0223] The agent module 200 further includes a command execution sub-module, configured to: call target data that matches the step according to the command list, and the target data is used to reply to the second target message of the user.
[0224] It can be understood that an Agent is a general problem solver. Based on a large language model, it has the abilities of planning and thinking, retrieval and memory, and using tools. It is a computer program that can autonomously complete a given task similar to a human being.
[0225] The specific implementation manners of this embodiment can also refer to the corresponding implementation methods described above, and will not be elaborated here.
[0226] As Figure 3 shown, further, the reliable dialogue system further includes a dialogue correction module 300. The dialogue correction module 300 is used to determine whether the latest user message deviates from the normal preset dialogue process.
[0227] If so, a correction command is generated, where the correction command is used to perform a deviation correction process based on the latest user message.
[0228] The specific implementation of this embodiment can refer to the corresponding method described above, and will not be elaborated here.
[0229] As Figure 4 shown, an electronic device 400 provided by an embodiment of the present invention includes a memory 410 and a processor 420; the memory 410 is used to store a computer program; the processor 420 is used to implement the reliable dialogue method as described above when executing the computer program.
[0230] Or, an electronic device 400 includes a memory 410 and a processor 420 coupled to the memory 410; the memory 410 is configured to store a computer program; the processor 420 is configured to perform the following operations when executing the computer program:
[0231] Obtain a first target message of the user, and perform a retrieval based on a preset dialogue process to obtain a first dialogue process that matches the first target message of the user, where the preset dialogue process is the steps required to complete the dialogue, and the preset dialogue process includes the first dialogue process.
[0232] Reply to the first target message of the user according to the first dialogue process, and obtain a second target message of the user, where the second target message of the user is the user target message after the first target message of the user.
[0233] Generate a command list according to the first target message of the user, the second target message of the user, and the first dialogue process.
[0234] According to the command list, call target data that matches the step, and reply to the second target message of the user according to the target data.
[0235] A computer-readable storage medium provided by an embodiment of the present invention, on which a computer program is stored. When the computer program is executed by a processor, the reliable dialogue method described above is implemented.
[0236] Or, a non-volatile computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the processor performs the following operations:
[0237] Obtain a first target message of a user, and perform a search based on a preset dialogue process to obtain a first dialogue process that matches the first target message of the user. Wherein, the preset dialogue process is the steps required to complete a dialogue, and the preset dialogue process includes the first dialogue process;
[0238] Reply to the first target message of the user according to the first dialogue process, and obtain a second target message of the user. Wherein, the second target message of the user is the user target message after the first target message of the user;
[0239] Generate a command list according to the first target message of the user, the second target message of the user, and the first dialogue process;
[0240] According to the command list, call target data that matches the step, and reply to the second target message of the user according to the target data.
[0241] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided by the present invention can include non-volatile and / or volatile memories. Non-volatile memories can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memories can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0242] The above are only specific embodiments of the present invention, enabling those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but rather to the broadest scope consistent with the principles and novel features invented herein.
[0243] Although the present invention is disclosed as above, the protection scope of the present invention is not limited thereto. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention, and these changes and modifications will all fall within the protection scope of the present invention.
Claims
1. A reliable dialogue method, characterized in that: include: Acquire a first target message of the user, and perform a search based on a preset dialogue process to obtain a first dialogue process that matches the first target message of the user, wherein the preset dialogue process is the steps required to complete the dialogue, and the preset dialogue process includes the first dialogue process; Reply to the user's first target message according to the first dialogue process, and obtain the user's second target message, wherein the user's second target message is the user's target message after the user's first target message; Generate a command list according to the user's first target message, the user's second target message and the first dialogue flow; According to the command list, the target data matching the steps is called, and the second target message of the user is replied according to the target data.
2. The reliable dialogue method according to claim 1, characterized in that: The step of obtaining the first target message of the user and searching based on a preset dialogue process to obtain a first dialogue process matching the first target message of the user includes: Converting the user's first target message into a first vector; A second vector that satisfies a preset similarity condition with the first vector is determined by searching in a preset vector database based on the first vector, wherein the preset vector database is a set of vectors corresponding to the definition description of the preset dialogue flow, and the second vector is the vector corresponding to the definition description of the first dialogue flow.
3. The reliable dialogue method according to claim 2, characterized in that: The replying to the user's first target message according to the first dialogue process and obtaining the user's second target message includes: Determining whether the user's first target message contains slot data corresponding to the step of the first dialogue process, wherein the slot data is a variable in the step required to complete the dialogue; If yes, obtaining the second target message of the user, wherein the second target message of the user includes user confirmation information; If not, then request to obtain the user's second target message, wherein the user's second target message includes the slot data.
4. The reliable dialogue method according to claim 3, characterized in that: Also includes: Determining whether the type of the step of the first dialogue process meets a preset type; If so, the slot data corresponding to the step of the preset type is automatically filled in according to the pre-stored slot data.
5. The reliable dialogue method according to any one of claims 2 to 4, characterized in that: The generating a command list according to the user's first target message, the user's second target message and the first dialogue flow comprises: According to the first dialogue flow, the user's first target message and the user's second target message, a prompt template containing prompt instructions is filled in, a prompt statement is generated and the prompt statement is input into a preset model to generate the command list, wherein the prompt statement is used to instruct the preset model to output the command list that conforms to a set format based on the input.
6. The reliable dialogue method according to claim 5, characterized in that: The step of filling a prompt template including prompt instructions according to the first dialogue flow, the first target message of the user, and the second target message of the user, generating a prompt sentence, and inputting the prompt sentence into a preset model to generate the command list includes: Determine a current dialogue according to the user's first target message, the user's second target message, and the first dialogue process, wherein the current dialogue includes the latest user message; According to the first dialogue process and the current dialogue, the prompt template is filled to generate the prompt sentence, the prompt sentence is input into the language model, and the command list is generated, wherein the prompt sentence includes starting the first dialogue process according to the definition description, filling the slot data according to the current dialogue, correcting the filled slot data according to the latest user message, and handling abnormal situations, the command list corresponds to the prompt sentence, and the preset model includes the language model.
7. The reliable dialogue method according to claim 6, characterized in that: The calling of target data matching the step according to the command list, and replying the second target message to the user according to the target data comprises: The command list is executed, and target data matching the steps is called in a preset manner, wherein the preset manner includes calling an API, querying a database, and querying a knowledge base.
8. The reliable dialogue method according to claim 7, characterized in that: If there are multiple first dialogue processes, the execution of the command list includes: Push multiple first dialogue flows into a dialogue stack, and locate the step of each first dialogue flow through a flow cursor, process the first dialogue flows one by one in the order of entering the dialogue stack, and after processing the previous first dialogue flow, continue to process the next first dialogue flow based on the step located by the flow cursor, wherein the processing order of the first dialogue flows is the reverse order of the order of entering the dialogue stack, and each first dialogue flow is pushed out of the dialogue stack after being processed.
9. The reliable dialogue method according to any one of claims 6 to 8, characterized in that: Handling exceptions includes: Determining whether the latest user message deviates from the normal preset dialogue process; If so, a correction command is generated, wherein the correction command is used to perform correction processing according to the latest user message.
10. A reliable dialogue system, characterized in that: Applying the reliable dialogue method according to any one of claims 1 to 9, comprising: A business module, used to obtain a first target message of a user, and perform a search based on a preset dialogue process to obtain a first dialogue process that matches the first target message of the user, wherein the preset dialogue process is a step required to complete a dialogue, and the preset dialogue process includes the first dialogue process; An agent module, used to reply to the user's first target message according to the first dialogue process, and obtain the user's second target message, wherein the user's second target message is the user's target message after the user's first target message; The agent module is also used to: generate a command list according to the user's first target message, the user's second target message and the first dialogue flow; The intelligent agent module is also used to: call target data matching the steps according to the command list, and the target data is used to reply to the user's second target message.