Response processing method based on dialogue mode, client and storage medium
By establishing a mapping relationship between request IDs and controller instances on the client side, the problem of inconsistent client states caused by user interruption of the dialogue flow is solved, enabling precise lifecycle management of the dialogue flow and improving client stability and performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-18
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies, when handling user-interrupted conversation flows, cause inconsistencies between the client and server states, resulting in redundant connection requests, consuming local memory, and impacting client stability and performance.
By creating a mapping relationship between request IDs and controller instances on the client side, precise lifecycle management of the conversation flow can be achieved, allowing for timely termination of streaming requests and release of memory.
It improves client stability and performance, ensuring that users can proactively and instantly abort requests, release resources, and prevent memory leaks.
Smart Images

Figure CN121833768A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of information interaction, and in particular to a response processing method based on a dialogue mode, a client, and a storage medium. BACKGROUND
[0002] In recent years, with the rapid development of artificial intelligence technology, human-computer interaction applications based on dialogue mode have penetrated into all aspects of daily life. In such applications, streaming technology is widely used because it can achieve low latency and return response content in real time, greatly improving the smoothness of user experience. However, this technology also brings new challenges, especially in scenarios where the user needs to actively interrupt the current dialogue flow (for example, the user is not satisfied with the generated content or wants to change the question).
[0003] The prior art solution usually relies on server-side state management or complex session lifecycle control when processing such interruption requests. This can cause inconsistencies between the client and the server, resulting in redundant request connections in frequent start-stop operations. Therefore, if the client fails to timely and accurately abort the issued streaming request, it will continuously consume local memory, ultimately affecting the stability and performance of the client application. SUMMARY
[0004] To solve the above technical problems, the present application provides a response processing method based on a dialogue mode, a client, and a storage medium.
[0005] The technical solutions provided in the present application are described as follows: The first aspect of the present application provides a response processing method based on a dialogue mode, applied to a client, comprising: When a user initiates a dialogue request, a request ID and a controller instance are created, the request ID is used to associate all content sent by the user in the current dialogue, and the controller instance is used to control the request associated with the request ID; A mapping relationship between the request ID and the controller instance is established in the memory of the client and stored; A streaming request is initiated to a server, the streaming request contains messages sent by the user in the current dialogue and the associated request ID; When stopping the current dialogue is triggered, the controller instance is called from the mapping relationship according to the request ID to abort the streaming request; The mapping relationship between the request ID and the controller instance is cleared from the memory after the streaming request is aborted.
[0006] Optionally, after the streaming request is initiated to the server, it further comprises: parsing the streaming data returned by the server and updating the interface.
[0007] Optionally, the parsing of the streaming data returned by the server comprises: receiving the original streaming data sent by the server; decoding the original streaming data by a text decoder to obtain text data in an event stream format; parsing valid content data from the text data.
[0008] Optionally, the interface updating comprises: incrementally updating the message content of the current conversation according to the valid content data parsed; rendering the interface to display the updated message content in real time.
[0009] Optionally, the method further comprises: managing the message state of the streaming request; wherein the message state comprises at least one of a loading state, a content state, a completion state, an error state and an interruption state.
[0010] Optionally, the message state management comprises: initializing the loading state as in progress when the user initiates the request; updating the content state according to the parsing result when the streaming data returned by the server is received; updating the completion state after the streaming data is received.
[0011] Optionally, the message state management further comprises: updating the error state when an error occurs in the streaming request process; and / or, updating the interruption state when the streaming request is aborted.
[0012] The second aspect of the present application provides a client, comprising: a creating unit configured to create a request ID and a controller instance when a user initiates a conversation request, the request ID being used to associate all content sent by the user in the current conversation, and the controller instance being used to control the request associated with the request ID; a storage unit configured to establish a mapping relationship between the request ID and the controller instance in the memory of the client and store the mapping relationship; an initiating unit configured to initiate a streaming request to a server, the streaming request containing the messages sent by the user in the current conversation and the associated request ID; a middle unit, configured to call the controller instance from the mapping relationship according to the request ID to abort the streaming request when a current session is triggered to stop; a clearing unit, configured to clear the mapping relationship between the request ID and the controller instance from the memory after the streaming request is aborted.
[0013] The third aspect of the present application provides a client, comprising: a processor, a memory, an input / output unit and a bus; the processor is connected with the memory, the input / output unit and the bus; the memory stores a program, and the processor invokes the program to execute the method of the first aspect and any optional aspect of the first aspect.
[0014] The fourth aspect of the present application provides a computer readable storage medium, which stores a program, and the program executes the method of the first aspect and any optional aspect of the first aspect when executed on a computer.
[0015] From the above technical solutions, the embodiments of the present application have the following advantages: When a user initiates a session request, the client can create a request ID and a controller instance, wherein the request ID is used to associate all the content sent by the user in the current session, and the controller instance is used to control the request associated with the request ID. The mapping relationship between the request ID and the controller instance is established in the memory of the client and is stored. In this way, the corresponding relationship among "one session-one ID-one instance" is established. When applied specifically, the client initiates a streaming request containing the message sent by the user and the request ID to the server. When the session is triggered to stop, the controller instance is called according to the corresponding relationship among the three to abort the streaming request, and the mapping relationship between the request ID and the controller instance is cleared from the memory. In this way, the client can abort the streaming request issued in time and accurately, and release the local memory, thereby improving the stability and performance of the client. BRIEF DESCRIPTION OF DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0017] Figure 1 An embodiment flowchart of the response processing method based on the session mode provided by the present application is shown in the figure; Figure 2A flowchart of an embodiment of a method for processing streaming data returned by a server in a response processing method based on a dialogue mode provided by the present application; Figure 3 A flowchart of an embodiment of message state management for a streaming request in a response processing method based on a dialogue mode provided by the present application; Figure 4 A structural diagram of an embodiment of a client for a response processing method based on a dialogue mode provided by the present application; Figure 5 A structural diagram of another embodiment of a client for a response processing method based on a dialogue mode provided by the present application. DETAILED DESCRIPTION
[0018] The present application provides a response processing method based on a dialogue mode, a client and a storage medium, which can improve the stability and performance of the client. It should be noted that the response processing method based on a dialogue mode of the present application is applied to the client.
[0019] It should be noted that the client is a kind of terminal, for example, the client can be a smart phone or a computer, a tablet computer, a smart television, a smart watch, a portable computer terminal or a desktop computer. For convenience of description, the terminal is taken as an example in the present application.
[0020] The response processing method based on a dialogue mode provided by the present application is to realize accurate life cycle management of a single dialogue flow by introducing a mapping mechanism of a request ID and a controller instance, so as to ensure that the user can actively and instantly terminate the request and effectively release resources.
[0021] Referring to Figure 1 The present application first provides an embodiment of a response processing method based on a dialogue mode, which comprises: S101, when a user initiates a dialogue request, a request ID and a controller instance are created, the request ID is used to associate all contents sent by the user in the current dialogue, and the controller instance is used to control the request associated with the request ID; The dialogue request refers to a query or instruction initiated by the user in one human-computer interaction session. For example, in a smart assistant application, the user inputs "please write a poem about winter" and presses the send key, which initiates a dialogue request.
[0022] The request ID (Request ID) is a globally unique identifier, which is used to uniquely mark an independent dialogue request. In the same dialogue thread, the user may continuously send multiple messages, and the ID is used to associate these messages to the same context session.
[0023] The controller instance refers to a functional object created on the client side, which encapsulates the ability to abort network requests. For example, it can be implemented based on modern JavaScript environment AbortController and similar technologies, which contain internal function methods to abort streaming requests.
[0024] When a user triggers a new conversation with the client in the interaction interface (such as clicking the "send" button), the system immediately performs two operations: first, generate a unique request ID, based on all the content sent by the user in the conversation, which will be associated with the unique request ID; second, create a new controller instance at the same time, which has the ability to control the entire conversation flow and abort it.
[0025] For example: suppose the user sends the instruction "please write a poem about winter" in an app named "AI assistant". At this time, the app will create a unique request ID for this conversation, and simultaneously create a new controller instance, which has the ability to abort this specific network request.
[0026] S102, establish a mapping relationship between the request ID and the controller instance in the memory of the client and store it; Since a human-computer conversation, the user will basically issue multiple instructions or questions. In order to facilitate management and positioning, the request ID and controller instance created in the previous step are taken as a key-value pair to create a mapping relationship and saved in the memory of the client (for example, in a Map object). This allows subsequent quick positioning of the controller instance managing the request through the request ID.
[0027] It should be noted that a user can establish multiple conversations on the client side, such as: the user asks "please generate a poem about winter" in the first conversation interface, and asks "please introduce Li Bai" in the second conversation interface. Then the client will generate respective request IDs and create respective controller instances based on each conversation interface, that is, achieve the one-to-one correspondence of "one conversation-one ID-one instance".
[0028] S103, initiate a streaming request to the server, which contains the messages sent by the user in the current conversation and the associated request ID; Streaming request is a network communication method. After the client sends a request to the server, the server can start returning partial results in batches without generating a complete response, forming a continuous data stream. This is common in scenarios such as large language model text generation and real-time speech recognition, where users can see the answers appearing word by word.
[0029] The client initiates a streaming request to the server, which contains not only the user's sent message (here, the message refers to a single message sent by the current user), but also a unique request ID sent to the server.
[0030] For example, the App sends a request to the server, which contains the user message "full text of Midnight" and the request ID. After receiving the request, the server starts returning the explanation content in a streaming manner, such as "the full text of Midnight is...", "the bright moonlight in front of the bed", and the App interface displays these contents word by word and line by line.
[0031] S104, when the current conversation is triggered to stop, the controller instance is called from the mapping relationship according to the request ID to abort the streaming request; In the process of returning the streaming content by the server, if the user triggers the stop operation (such as clicking the "stop generating" button) or the client is disconnected from the server due to network failure, the client will obtain the corresponding request ID from the event. Then, the request ID is used to find the corresponding controller instance in the mapping relationship, and the function method of the controller instance for aborting the conversation is immediately called.
[0032] For example, when the server is returning "lift your head and look at the bright moon...", the user feels that the content is enough or finds that the content is wrong, and clicks the "stop" button. The client captures the click event, obtains the request ID that needs to be stopped, and then finds the controller instance corresponding to the ID in the mapping relationship in the memory, and executes the stop command. The command will immediately interrupt the connection with the server, and the server stops sending subsequent data.
[0033] S105, after aborting the streaming request, the mapping relationship between the request ID and the controller instance in the memory is cleared.
[0034] After successfully aborting the streaming request, the client can perform cleaning work to delete the request ID and its corresponding controller instance in the mapping relationship in the memory, and the aborted request and its controller complete their life cycle. In this way, memory leakage is prevented, and invalid data is prevented from occupying resources for a long time, ensuring the cleanliness of the client state.
[0035] In the present application, when a user initiates a conversation request, the client can create a request ID and a controller instance, wherein the request ID is used to associate all content sent by the user in the current conversation, and the controller instance is used to control the request associated with the request ID. The client establishes a mapping relationship between the request ID and the controller instance in the memory and stores it. In this way, a corresponding relationship among "one conversation-one ID-one instance" is established. When specifically applied, the client initiates a streaming request containing the message sent by the user and the request ID to the server. When the conversation is triggered to stop, the streaming request is aborted by calling the controller instance according to the corresponding relationship among the three, and the mapping relationship between the request ID and the controller instance is cleared from the memory. In this way, the client can timely and accurately abort the streaming request issued and release the local memory, thereby improving the stability and performance of the client.
[0036] The following describes in detail the processing of the streaming data returned by the server after the client initiates a streaming request, specifically including the analysis of the streaming data returned by the server and the interface update, so as to realize the real-time rendering of the feedback content. In combination with Figure 1 Please refer to Figure 2 , Figure 2 The flowchart of one embodiment of the method for processing the streaming data returned by the server in the response processing method based on the conversation mode provided in the present application includes: S201, receiving the original streaming data sent by the server; After the client initiates a streaming request carrying specific messages and a request ID to the server, the server starts to respond, and the client continuously receives a series of binary data packets (i.e., original streaming data) through a network interface. These data packets cannot be directly read by the user.
[0037] S202, decoding the original streaming data through a text decoder to obtain text data in the event stream format; The client uses a text decoder (such as TextDecoder) to decode the received binary data packet into a readable text string in real time. The text obtained after decoding can be as follows: data: {"content":"bed front"} data: {"content":"moon"} data: {"content":"light"} S203, parsing valid content data from the text data; The augmented text is still not the readable content that the client needs most, so the client removes the data: prefix in front of each line, and then parses the remaining part (such as {"content":"bedfront"} ) into a JSON object, and finally extracts the value of the content field from this JSON object, which is the string "bedfront". This is the valid content data in this data block.
[0038] S204, according to the valid content data obtained by parsing, incrementally updating the message content of the current conversation; Incremental update refers to an update method that does not replace the entire existing content, but appends the newly parsed content segment to the end of the existing message.
[0039] The client maintains a variable currentStory for displaying the conversation, which is initially empty. When the first content "bedfront" is parsed, it is assigned to currentStory. When the second content "moon" is parsed, it is not replaced by the entire string, but is appended to the end of currentStory, making it "bedfront moon". This cycle continues to achieve cumulative growth of content.
[0040] S205, rendering the interface to display the updated message content in real time.
[0041] After the client incrementally updates currentStory each time, the user interface is re-rendered to make it appear as if the other party is showing one word at a time. The user will see the content growing word by word and sentence by sentence on the screen: "bedfront" -> "bedfront moon" -> "bedfront moonlight". This real-time rendering method provides a smooth interactive experience for users.
[0042] The following describes the message state management of the streaming request initiated by the client in detail. This embodiment is an extension and enhancement of the aforementioned response processing method, which accurately tracks and manages the entire process of a conversation request from initiation to completion through a clear state machine mechanism. This state machine mechanism provides a clear basis for the user interface (UI), enabling it to dynamically display corresponding visual feedback and interactive controls. Specifically, in the message state management of the streaming request, the message state includes at least one of the loading state, the content state, the completion state, the error state, and the interruption state.
[0043] Please refer to Figure 3 , Figure 3 The following is a flowchart of an embodiment of the message state management of the streaming request in the response processing method based on the conversation mode provided in this application, which includes: During the entire conversation, the five states can be defined as: loading (in progress): request has been issued, waiting or receiving server response; streaming (content status): steadily receiving and processing streaming data returned by the server; success (completion status): all streaming data has been normally received; error (error status): network or server error occurred during request process; aborted (interrupted status): request is actively terminated by the user.
[0044] S301, when the user initiates the request, initialize the loading state to in progress; At the moment when the user presses the "send" button, create a request ID and a controller, and at the same time, the client immediately sets the state of this conversation request to loading.
[0045] In UI display, the "send" button becomes non-clickable or becomes a "stop" button, a rotating icon of "loading" appears behind the message bubble, and the interface prompts "AI is thinking...".
[0046] S302, when receiving the streaming data returned by the server, update to content status according to the parsing result; Once the client receives the first valid data packet and successfully parses the content (i.e. S202-S203 steps are completed), the state should be immediately updated from loading to streaming. This indicates that the connection is stable and data has begun to flow continuously.
[0047] In UI display, the loading icon behind the message bubble disappears, and the feedback content begins to be printed in the bubble word by word and sentence by sentence in real time, and the "stop" button remains visible and clickable, allowing the user to interrupt at any time.
[0048] S303, after the streaming data is received, update to completion status; When the client detects that the server actively closes the streaming connection and receives a signal indicating the end, indicating that all data has been transmitted, the state is updated to success.
[0049] In UI display, the text in the message bubble stops growing, showing the complete feedback content, and the "stop" button disappears. It can also display a "copy" or "regenerate" icon at the end of the message, providing subsequent operations.
[0050] S304, when an error occurs in the streaming request process, update to error status; If a network interruption, server error or parsing exception occurs at any stage of the request (whether loading or streaming), the client will immediately capture the error and update the status to error, usually with error information logged.
[0051] In the UI display, the message bubble stops updating, an error icon and a prompt text such as "network error, please retry" are displayed inside or behind the message bubble, and the "stop" button becomes a "retry" button, allowing the user to reinitiate the request.
[0052] S305, when the streaming request is aborted, update to the interrupted state.
[0053] When the user triggers the stop operation, the controller instance successfully aborts the network request, and the client needs to update the status to aborted. This state is different from error, which indicates that the user's intention causes the abortion, rather than a system failure.
[0054] In the UI display, the text inside the message bubble immediately stops at the position when it is interrupted and no longer increases, and a "(interrupted)" prompt may be displayed behind the generated part of the content. The "stop" button becomes a "continue" or "regenerate" button, allowing the user to choose the subsequent operation.
[0055] Through the fine management of the five states, the client can clearly describe the life cycle of a conversation request. The UI component listens to the changes of these states to provide accurate, timely and friendly visual and interactive feedback to the user, and converts the background technical process into a smooth user experience on the front end.
[0056] The client based on the conversation mode provided in the present application will be described in detail below. Please refer to Figure 4 , Figure 4 The structure diagram of an embodiment of the client based on the conversation mode provided in the present application is shown in the figure. The client comprises: A creating unit 401 is configured to create a request ID and a controller instance when a user initiates a conversation request, the request ID is used to associate all the content sent by the user in the current conversation, and the controller instance is used to control the request associated with the request ID; A storage unit 402 is configured to establish a mapping relationship between the request ID and the controller instance in the memory of the client and store the mapping relationship; An initiating unit 403 is configured to initiate a streaming request to a server, the streaming request comprising a message sent by the user in the current conversation and the associated request ID; The middle unit 404 is configured to call the controller instance from the mapping relationship according to the request ID to stop the streaming request when the current conversation is triggered to stop; The clearing unit 405 is configured to clear the mapping relationship between the request ID and the controller instance from the memory after the streaming request is stopped.
[0057] The client embodiment is described with reference to the embodiment of the method Figures 1-3 , and details are not repeated here.
[0058] Participation Figure 5 As shown in the method embodiment, another embodiment of the client for the response processing based on the conversation mode provided in the application includes: The processor 501, the memory 502, the input and output unit 503, and the bus 504; The processor 501 is connected with the memory 502, the input and output unit 503, and the bus 504; The memory 502 stores a program, and the processor calls the program to execute any of the above response processing methods based on the conversation mode.
[0059] The application also relates to a computer readable storage medium, and the computer readable storage medium stores a program. When the program runs on the computer, the computer executes any of the above response processing methods based on the conversation mode. The specific embodiment is described with reference to the embodiment of the method Figures 1-3 , and details are not repeated here.
[0060] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the foregoing method embodiment, and details are not repeated here.
[0061] In the several embodiments provided in the application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division, and there can be another division manner in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.
[0062] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0063] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present alone, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0064] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical scheme of the present application essentially or the part that contributes to the prior art or the whole or part of the technical scheme can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, read-only memory), a random access memory (RAM, random access memory), a magnetic disk or an optical disk, and various program code storage media.
Claims
1. A response processing method based on a dialogue pattern, applied to a client, characterized in that, include: When a user initiates a conversation request, a request ID and a controller instance are created. The request ID is used to associate all content sent by the user in the current conversation, and the controller instance is used to control the request associated with the request ID. Establish and store the mapping relationship between the request ID and the controller instance in the client's memory; Send a streaming request to the server, the streaming request containing messages sent by the user in the current conversation and the associated request ID; When the current conversation is stopped, the controller instance is invoked from the mapping relationship according to the request ID to terminate the streaming request; After the streaming request is aborted, the mapping between the request ID and the controller instance is cleared from the memory.
2. The response processing method according to claim 1, characterized in that, After initiating the streaming request to the server, the following is also included: The streaming data returned by the server is parsed and the interface is updated.
3. The response processing method according to claim 2, characterized in that, The parsing of the streaming data returned by the server includes: Receive raw stream data sent by the server; The original stream data is decoded using a text decoder to obtain text data in event stream format; Extract valid content data from the text data.
4. The response processing method according to claim 3, characterized in that, The interface update includes: Based on the valid content data obtained from parsing, the message content of the current conversation is updated incrementally. The interface is rendered to display the updated message content in real time.
5. The response processing method according to claim 1, characterized in that, The method further includes: The streaming request is subject to message state management; wherein the message state includes at least one of the following: loading state, content state, completion state, error state, and interruption state.
6. The response processing method according to claim 5, characterized in that, The message status management includes: When a user initiates a request, the loading status is initialized to in progress; When receiving streaming data returned by the server, the content status is updated according to the parsing result; After the streaming data reception is completed, the status is updated to the completed state.
7. The response processing method according to claim 6, characterized in that, The message status management also includes: When an error occurs during the streaming request process, the error status is updated. And / or, when the streaming request is aborted, update to the interrupted state.
8. A client application, characterized in that, include: A creation unit is used to create a request ID and a controller instance when a user initiates a dialogue request. The request ID is used to associate all content sent by the user in the current dialogue, and the controller instance is used to control the request associated with the request ID. A storage unit is used to establish and store the mapping relationship between the request ID and the controller instance in the memory of the client. An initiating unit is used to initiate a streaming request to the server, the streaming request including messages sent by the user in the current conversation and the associated request ID; The termination unit is used to, when a termination of the current dialogue is triggered, invoke the controller instance from the mapping relationship according to the request ID to terminate the streaming request; A clearing unit is used to clear the mapping relationship between the request ID and the controller instance from the memory after the streaming request is aborted.
9. A client, characterized in that, include: Processor, memory, input / output units, and bus; The processor is connected to the memory, the input / output unit, and the bus; The memory stores a program, which the processor invokes to execute the method as described in claims 1-7.
10. A computer-readable storage medium having a program stored thereon, the program performing the method as claimed in any one of claims 1 to 7 when executed on a computer.