Data interaction method and device
Through streaming and block auditing technology, latency and security issues in AI real-time interaction are solved, realizing the immediacy and security of dynamically generated content, and improving user experience.
Patent Information
- Application Number
- CN202411589464.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-02-25
AI Technical Summary
The prior art has latency problems in real-time AI interactions, and it is difficult to ensure the immediacy and security of dynamically generated content at the same time.
Through streaming, block review and real-time processing technology, we receive the client's interactive requests, stream the response data of the target interaction model, convert and process in real time, review and format conversion of preset policies, and finally follow the predefined format. Stream to the client.
It significantly reduces the waiting time for users from sending requests to receiving responses, improves the immediacy and security of the user experience, and ensures the security and immediacy of interactive content.
Smart Images

Figure CN119513286A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data transmission, and in particular to a data interaction method and device. Background Art
[0002] In the prior art, the process of dialogue with AI is generally that the user sends an interaction request from the client, the server accepts the interaction request, the server sends the interaction request to the large model, the large model infers and outputs the interaction reply, sends the interaction reply to the server, and the server then sends the interaction reply to the client. However, this method faces the problem of delay in real-time interaction with AI, that is, there is a large delay from the time the user sends the request to the time the interaction reply is received by the AI, causing the user to experience a large perceptible delay, which seriously reduces the user's interactive immersion and satisfaction. In addition, security is also a problem. Traditional methods either do not conduct content review on the output of the large model, resulting in the spread of inappropriate content, or conduct content review on the output of the large model before outputting it, further increasing the delay problem in the interaction. The immediacy and security of dynamically generated content cannot be guaranteed at the same time. Summary of the invention
[0003] In view of this, the purpose of this application is to provide a data interaction method and device, which can ensure the immediacy and security of dynamically generated content through technical means such as streaming, block review, and real-time processing.
[0004] The present application provides a data interaction method, which is applied to a server. The data interaction method includes:
[0005] Receive an interaction request sent by a client, and send the interaction request to a target interaction model;
[0006] Streamingly receiving byte interaction response data fed back by the target interaction model according to the interaction request, and converting the byte interaction response data into text interaction response data in real time; the byte interaction response data includes at least one byte;
[0007] The converted text interaction response data is processed in sequence according to the preset block strategy to determine the block data to be reviewed;
[0008] After each block of data to be reviewed is determined, the block of data to be reviewed is reviewed according to the preset review strategy;
[0009] The block data to be reviewed after review is sent to the client in a streaming manner according to the predetermined display format.
[0010] Optionally, when the interaction request is a voice interaction request, receiving the interaction request sent by the client and sending the interaction request to the target interaction model includes:
[0011] Streaming receives voice interaction requests sent by the client;
[0012] The text interaction request determined by converting the voice interaction request is sent to the target interaction model.
[0013] Optionally, the converted text interaction response data is processed in sequence according to a preset block strategy to determine the block data to be reviewed, including:
[0014] According to the preset block strategy, determine the target number of bytes required to be included in the block data to be reviewed;
[0015] According to the target number of bytes, the byte data in the received text interaction response data are reassembled in order to determine the block data to be reviewed.
[0016] Optionally, use any of the following methods to determine the block data to be reviewed:
[0017] Determine each block of byte data received in a streaming manner as a block of data to be confirmed and reviewed;
[0018] Determine the byte data of multiple blocks received in a streaming manner as one block of data to be determined and reviewed;
[0019] The byte data received in streaming mode is combined and processed according to the principle of progressive accumulation, and the data after each combination is determined as the block data to be reviewed;
[0020] Determine the byte data received in a streamed manner within a preset time as the block data to be reviewed; wherein, if no byte data is received within the preset time, determine the byte data received in a streamed manner within a previous period of time as the block data to be reviewed;
[0021] The byte data with complete semantics received in streaming is determined as the block data to be reviewed.
[0022] Optionally, when the to-be-audited block data is audited and it is determined that the audit fails, the data interaction method further includes:
[0023] The interaction request and the block data to be reviewed that are generated according to the interaction request and have passed review are re-input into the target interaction model to regenerate the byte interaction response data.
[0024] Optionally, the data interaction method further includes:
[0025] Identify the interval time of data sent to the client;
[0026] When the data interval time exceeds a preset time threshold, a transition statement is sent to the client.
[0027] Optionally, when the interaction request is a voice interaction request, while reviewing the block data to be reviewed, the data interaction method further includes:
[0028] The format of the block data to be reviewed is converted according to the predetermined display format.
[0029] Optionally, the format conversion process of the to-be-audited block data according to a predetermined display format includes:
[0030] The text interaction response data received in a streaming manner or the block data to be reviewed is reorganized to generate a speech synthesis block; wherein, if the review result of the block data to be reviewed corresponding to the speech synthesis block indicates that the review is passed, the synthesized speech generated corresponding to the speech synthesis block is streamed back to the client.
[0031] Optionally, before receiving the interaction request sent by the client, the data interaction method further includes:
[0032] receiving a connection request determined by the client according to the type of the interaction request;
[0033] Parsing the connection request to determine a target communication mode;
[0034] Establish a connection according to the target communication mode.
[0035] The embodiment of the present application further provides a data interaction device, which is applied to a server, and the data interaction device includes:
[0036] A receiving module, used for receiving an interaction request sent by a client, and sending the interaction request to a target interaction model;
[0037] A conversion module, used for streaming receiving byte interaction response data fed back by the target interaction model according to the interaction request, and converting it into text interaction response data in real time; the byte interaction response data includes at least one byte;
[0038] The block module is used to process the converted text interaction response data in sequence according to the preset block strategy to determine the block data to be reviewed;
[0039] The audit module is used to audit the block data to be audited according to the preset audit strategy after each block data to be audited is determined;
[0040] The sending module is used to stream the block data to be reviewed after the review is passed to the client in a predetermined display format.
[0041] Optionally, when the interaction request is a voice interaction request, when the receiving module is used to receive the interaction request sent by the client and send the interaction request to the target interaction model, the receiving module is used to:
[0042] Streaming receives voice interaction requests sent by the client;
[0043] The text interaction request determined by converting the voice interaction request is sent to the target interaction model.
[0044] Optionally, when the block module is used to sequentially process the converted text interaction response data according to a preset block strategy to determine the block data to be reviewed, the block module is used to:
[0045] According to the preset block strategy, determine the target number of bytes required to be included in the block data to be reviewed;
[0046] According to the target number of bytes, the byte data in the received text interaction response data are reassembled in order to determine the block data to be reviewed.
[0047] Optionally, the block module is further used to determine the block data to be reviewed in any of the following ways:
[0048] Determine each block of byte data received in a streaming manner as a block of data to be confirmed and reviewed;
[0049] Determine the byte data of multiple blocks received in a streaming manner as one block of data to be determined and reviewed;
[0050] The byte data received in streaming mode is combined and processed according to the principle of progressive accumulation, and the data after each combination is determined as the block data to be reviewed;
[0051] Determine the byte data received in a streamed manner within a preset time as the block data to be reviewed; wherein, if no byte data is received within the preset time, determine the byte data received in a streamed manner within a previous period of time as the block data to be reviewed;
[0052] The byte data with complete semantics received in streaming is determined as the block data to be reviewed.
[0053] Optionally, the data interaction device further includes a regeneration module, wherein the regeneration module is used to:
[0054] When the block data to be reviewed is reviewed and it is determined that the review fails, the interaction request and the block data to be reviewed that are generated based on the interaction request and have passed the review are re-input into the target interaction model to regenerate the byte interaction response data.
[0055] Optionally, the data interaction device further includes a transition module, and the transition module is used to:
[0056] Identify the interval time of data sent to the client;
[0057] When the data interval time exceeds a preset time threshold, a transition statement is sent to the client.
[0058] Optionally, the data interaction device further includes a parallel module, and the parallel module is used to:
[0059] When the interaction request is a voice interaction request, while the to-be-audited block data is being audited, the to-be-audited block data is format-converted according to a predetermined display format.
[0060] Optionally, when the parallel module is used to perform format conversion processing on the block data to be reviewed according to a predetermined display format, the parallel module is used to:
[0061] The text interaction response data received in a streaming manner or the block data to be reviewed is reorganized to generate a speech synthesis block; wherein, if the review result of the block data to be reviewed corresponding to the speech synthesis block indicates that the review is passed, the synthesized speech generated corresponding to the speech synthesis block is streamed back to the client.
[0062] Optionally, the data interaction device further includes a connection module, and the connection module is used to:
[0063] Before receiving the interaction request sent by the client, receiving a connection request determined by the client according to the type of the interaction request;
[0064] Parsing the connection request to determine a target communication mode;
[0065] Establish a connection according to the target communication mode.
[0066] An embodiment of the present application also provides a server, including: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the server is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps of the data interaction method as described above are performed.
[0067] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data interaction method as described above are executed.
[0068] A data interaction method and device are provided in an embodiment of the present application. The data interaction method is applied to a server and includes: receiving an interaction request sent by a client and sending the interaction request to a target interaction model; streaming receiving byte interaction response data fed back by the target interaction model according to the interaction request, and converting it into text interaction response data in real time; the byte interaction response data includes at least one byte; processing the converted text interaction response data in sequence according to a preset block strategy to determine block data to be reviewed; after each block data to be reviewed is determined, reviewing the block data to be reviewed according to a preset review strategy; and streaming the block data to be reviewed that has passed the review to the client in a predetermined display format.
[0069] In this way, this solution adopts a streaming method of receiving and processing byte interactive response data, which can process it immediately after receiving part of the data, rather than waiting for the entire response to be completed. This processing method significantly reduces the waiting time for users from sending requests to receiving responses, especially in voice interaction scenarios. Real-time conversion of voice to text interaction requests can speed up the entire interaction process, reduce latency, and improve the immediacy of user experience. And through the preset block strategy, the received interactive response data can be processed by byte blocks, and each block of data will be reviewed block by block according to the preset audit strategy before being transmitted to the client. In this way, it will not cause large-scale response delays, and can filter inappropriate content in a timely manner to ensure the security of interactive content, and will not significantly increase the response time due to the audit process.
[0070] Therefore, this data interaction method, through technical means such as streaming, block review, and real-time processing, significantly reduces the system's response delay while ensuring the security of the interactive content, thereby improving the user's immediacy and security experience in AI interaction.
[0071] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0073] Figure 1 A flowchart of a data interaction method provided in an embodiment of the present application;
[0074] Figure 2A simplified schematic diagram of the processing process of a data interaction method provided in this application;
[0075] Figure 3 A schematic diagram of the structure of a data interaction device provided in an embodiment of the present application;
[0076] Figure 4 A schematic diagram of the structure of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0077] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, each other embodiment obtained by those skilled in the art without making creative work belongs to the scope of protection of the present application.
[0078] In the prior art, the process of dialogue with AI is generally that the user sends an interaction request from the client, the server accepts the interaction request, the server sends the interaction request to the large model, the large model infers and outputs the interaction reply, sends the interaction reply to the server, and the server then sends the interaction reply to the client. However, this method faces the problem of delay in real-time interaction with AI, that is, there is a large delay from the time the user sends the request to the time the interaction reply is received by the AI, causing the user to experience a large perceptible delay, which seriously reduces the user's interactive immersion and satisfaction. In addition, security is also a problem. Traditional methods either do not conduct content review on the output of the large model, resulting in the spread of inappropriate content, or conduct content review on the output of the large model before outputting it, further increasing the delay problem in the interaction. The immediacy and security of dynamically generated content cannot be guaranteed at the same time.
[0079] Based on this, the embodiments of the present application provide a data interaction method and device, which can ensure the immediacy and security of dynamically generated content.
[0080] See also Figure 1 , Figure 1 A flow chart of a data interaction method provided in an embodiment of the present application. Applied to a server, such as Figure 1 As shown in , the data interaction method provided in the embodiment of the present application includes:
[0081] S101: Receive an interaction request sent by a client, and send the interaction request to a target interaction model.
[0082] S102: Streamingly receive the byte interaction response data fed back by the target interaction model according to the interaction request, and convert the byte interaction response data into text interaction response data in real time.
[0083] S103, processing the converted text interaction response data in sequence according to a preset block strategy to determine the block data to be reviewed;
[0084] S104: After each block of data to be reviewed is determined, the block of data to be reviewed is reviewed according to a preset review strategy.
[0085] S105. Stream the approved block data to the client in a predetermined display format.
[0086] Before executing step S101, in an implementation manner provided in the present application, the data interaction method further includes:
[0087] S201: Receive a connection request determined by a client according to a type of interaction request.
[0088] S202: parse the connection request to determine a target communication mode.
[0089] S203: Establish a connection according to the target communication mode.
[0090] For step S201, the types of the interaction request may include text type, voice type, picture, etc. Therefore, the interaction request may be a text interaction request, a voice interaction request, or a picture interaction request. This application mainly processes text interaction requests and voice interaction requests.
[0091] In this step, the client generates a corresponding connection request according to the type of interaction request, and then sends the generated connection request to the server, informing the server what type of interaction the client expects, so that the server can select an appropriate processing method according to the specific needs of the interaction.
[0092] With respect to step S202, the server parses the received connection request and determines detailed information in the request, which may include the interaction type and the desired communication method.
[0093] Here, if the request is for voice interaction, the server may need to establish communication through a different protocol; if it is for text interaction, another method may be used.
[0094] For example, when the type of interaction request is text type, the determined target communication mode may be SSE protocol communication; when the type of interaction request is voice type, the determined target communication mode may be SSE protocol communication or WebSocket protocol communication.
[0095] SSE (Server-Sent Events) is a technology used to enable the server to actively push data to the client, also known as "Event Stream". It is based on the HTTF protocol and uses its long connection characteristics to establish a persistent connection between the client and the server, and through this connection, the server can push streaming data to the client in real time and securely. The basic principle of SSE technology: the client sends a GET request to the server with a specified header, indicating that the event stream type can be received and disabling any event cache. The server returns a response with a specified header indicating the media type and encoding of the event, and uses chunked transfer encoding to stream dynamically generated content.
[0096] With respect to step S203, the server establishes a communication connection with the client according to the parsed communication mode.
[0097] By establishing a communication connection, it is ensured that the data transmission channel is ready and can support subsequent interactive requests and response processing. Different communication methods involve different protocols (such as SSE, WebSocket, etc.), and the server will select the optimal communication method for connection based on the type of interactive request.
[0098] Regarding step S101, in this step, the server receives an interaction request sent by the client, and sends the interaction request to the target interaction model for processing.
[0099] The interaction request may be a voice interaction request or a text interaction request.
[0100] When the interaction request is a voice interaction request, in an implementation manner provided in the present application, receiving the interaction request sent by the client and sending the interaction request to the target interaction model includes:
[0101] S1011. Streamingly receive a voice interaction request sent by a client.
[0102] S1012: Send a text interaction request determined by converting the voice interaction request to a target interaction model.
[0103] With respect to step S1011, when the client sends a voice interaction request, the server receives the request in a streaming manner.
[0104] This way, the server will continue to receive voice data instead of waiting for the entire voice input to be completed before processing. This can reduce processing latency because the server can start processing as soon as it receives partial voice data without having to wait for the entire voice request to be completed.
[0105] Among them, in the prior art, sending a voice request for interaction is similar to the text input method. The client intercepts the voice input by the user. For example, the 300ms period from monitoring to starting to speak to stopping speaking without voice input is a voice input. The client intercepts and sends it to the server, and the server performs subsequent processing such as voice-to-text conversion. At this time, the link between the client and the server can be an SSE link.
[0106] In this solution, the client monitors the voice input and streams it to the server, which intercepts the voice input. At this time, the connection between the client and the server can be a WebSocket connection. This setting can make voice acquisition more stable and reliable, avoiding problems such as interception failure and transmission delay caused by unstable client system, and also saves the time delay of sending voice input to the server compared with the existing technology.
[0107] With respect to step S1012, when converting the voice interaction request into a text interaction request, this can be done by calling an external module or by a submodule within the large model.
[0108] Among them, when voice data is converted into text data, it is usually completed through voice recognition technology.
[0109] In this way, in the voice interaction scenario, by streaming voice requests, converting voice into text in real time, and sending it to the AI model, the delay problem in the interaction is greatly reduced, and the timeliness and fluency of voice interaction are improved. Through this processing, the user's voice request can get AI feedback more quickly, improving the overall interaction experience.
[0110] With respect to step S102, the byte interaction response data includes at least one byte.
[0111] In this step, the server receives the response data from the target interaction model in a streaming manner. After receiving the interaction request, the target model will gradually return the interaction response data in the form of bytes, rather than returning the complete result at one time. The server will convert these byte data into the corresponding text interaction response data in real time.
[0112] It should be noted that the response data in byte form is generated step by step, rather than waiting for the complete data to be generated before processing.
[0113] For example, if the target interaction model infers the interaction response content of 1 TOKEN, the interaction response content of 1 TOKEN is transmitted, or if the target interaction model infers the interaction response content of 10 TOKENs, the interaction response content of 10 TOKENs is transmitted.
[0114] In this step, the server and the target interaction model can be connected using GRPC. On the one hand, the server can make full use of the computing power of the target interaction model distributed in various places to perform inference services, and call the service of the target interaction model like calling local services, without worrying about the connection problem of remote calls. On the other hand, the target interaction model can also return the model output to the server in a streaming manner. For example, the target interaction model can be a large speech model.
[0115] Regarding step S103, in this step, after the interactive response data is converted into text, the server processes the data in sequence according to a preset block strategy.
[0116] The block strategy specifies how many bytes of data each block contains, which facilitates subsequent block-by-block review. In this way, data can be reviewed and sent step by step without waiting for the complete interactive response to be generated.
[0117] In an implementation manner provided in the present application, the converted text interaction response data is processed in sequence according to a preset block strategy to determine the block data to be reviewed, including:
[0118] S1031, according to the preset block strategy, determine the target number of bytes that the block data to be reviewed needs to contain.
[0119] S1032. According to the target number of bytes, the byte data in the received text interaction response data are reassembled in order to determine the block data to be reviewed.
[0120] With respect to step S1031, the server determines the target number of bytes that each block of data to be reviewed needs to contain according to a preset block strategy.
[0121] The preset block strategy can be set according to different scenarios and requirements, such as how many bytes each block of data should contain before it can be submitted for review. In this way, it can ensure that the amount of data in each block is moderate, which can meet the review requirements without causing excessive review delays.
[0122] For step S1032, based on the previously determined target byte number, the server will reassemble the byte data in the received text interaction response data in sequence (for example, the server will segment and rearrange the received text interaction response data according to the target byte number) to generate block data to be reviewed.
[0123] In this way, it is ensured that the data in each block meets the predetermined byte requirements, and this block processing method can ensure the efficient implementation of the audit process, while also avoiding the impact of excessive or small data volume on the audit effect.
[0124] In an implementation manner provided in the present application, the block data to be reviewed may be determined by any of the following methods, but not limited to:
[0125] The byte data of each block received by streaming is determined as a block data to be reviewed; that is, each block of streaming output can be reviewed as a review block.
[0126] The byte data of the multiple blocks received in streaming are determined as one block of data to be reviewed; that is, the multiple blocks received in streaming can be reviewed as one review block.
[0127] The byte data received in streaming is combined and processed according to the principle of progressive accumulation, and the data after each combination is determined as the block data to be reviewed; that is, the first streaming block received can be used as a review block, the second and third streaming blocks can be used as review blocks, and so on.
[0128] The byte data received in a streaming manner within a preset time is determined as the block data to be reviewed; wherein, if no byte data is received within the preset time, the byte data received in a streaming manner within a previous period of time is determined as the block data to be reviewed.
[0129] The byte data with complete semantics received in streaming is determined as the block data to be reviewed.
[0130] The specific setting rules can be adaptively set according to the actual situation and are not limited here.
[0131] Regarding step S104, in this step, after the server generates each block of data (block of data to be reviewed), it will review the content according to the preset review strategy.
[0132] Here, the audit policy can include sensitive content filtering, compliance checks, etc. to ensure that the data is safe and compliant before being sent to the client.
[0133] In an implementation manner provided in the present application, when the interaction request is a voice interaction request, while reviewing the block data to be reviewed, the data interaction method further includes: performing format conversion processing on the block data to be reviewed according to a predetermined display format.
[0134] The format conversion processing of the block data to be reviewed according to the predetermined display format includes: data reorganization processing of the streaming received text interaction response data or the block data to be reviewed to generate a speech synthesis block; wherein, if the review result of the block data to be reviewed corresponding to the speech synthesis block indicates that the review is passed, the synthesized speech generated corresponding to the speech synthesis block is streamed back to the client.
[0135] The speech synthesis block can be understood as a piece of text data that converts text into speech, and synthesized speech is gradually generated in the form of blocks to meet the needs of real-time response.
[0136] Here, while the audit is being conducted, the server will also perform format conversion processing on the block data to be audited according to the predetermined display format. In this way, the audit and format conversion are performed in parallel, rather than being completed one by one.
[0137] For voice interaction, format conversion may include converting text data into voice format, or performing appropriate processing according to specific display requirements, such as adjusting the text to a format suitable for the user interface or a standard format for speech synthesis.
[0138] In this way, content review can be performed in parallel while converting to speech, which can shorten the response interaction time from the original model generation time to the time it takes for the model to generate the first streaming packet. Except for the beginning and the end, text, speech, content review, and output can be done in parallel most of the time, greatly shortening the serial time delay.
[0139] By synergizing the generation process of text and speech models in real time, the text and speech models can work in parallel and output the results in a streaming manner, thereby reducing the overall response time and significantly reducing the time delay from user input to receiving a reply. In this way, a block content review mechanism is integrated to ensure that even when content is generated quickly, all generated content is properly reviewed without sacrificing response speed, preventing the spread of inappropriate content and ensuring the security and compliance of the output content.
[0140] In another embodiment provided in the present application, when the block data to be reviewed is reviewed and it is determined that the review fails, the data interaction method further includes: re-inputting the interaction request and the block data to be reviewed generated according to the interaction request and passed the review into the target interaction model to regenerate the byte interaction response data.
[0141] In this step, when the server reviews the block data to be reviewed, if it is found that the block data does not meet the preset review standards (for example, contains inappropriate content or illegal information), the server will determine that the review has failed. At this time, the server cannot send the non-compliant data to the client.
[0142] The server then re-enters the initial interaction request and previously approved chunked data into the target interaction model, thus generating new response data based on the existing compliance data and request, thus avoiding completely restarting the process and saving time and resources.
[0143] Then, the target interaction model generates new byte interaction response data based on these inputs. In this way, by regenerating new byte interaction response data, you can try to pass the audit.
[0144] In this way, it is ensured that non-compliant content will not be passed to the client, while ensuring the continuity of the entire interaction process and the compliance of the data.
[0145] For example, in a text interaction request scenario, the target interaction model streams out ABCD..., ABC content passes the review, but D fails the review, then A1A2B1B2C1C2 can be streamed out to the client in sequence, but D and subsequent blocks need to be re-said. At this time, the interaction request is input into the target interaction model together with the ABC content for re-inference to generate interactive content that meets the content review specifications. At the same time, since A1A2B1B2C1C2 is being streamed out in sequence, the client does not perceive an increase in delay for model re-speaking, and since ABC is input into the model together, the model re-speaking can well continue the content before the review fails, and the user will not have problems with the previous and subsequent sentences being incoherent due to the model re-speaking, which increases content compliance, greatly reduces the interaction delay felt by the user, and improves the user experience.
[0146] In the voice interaction request scenario, it is the same as text. For example, the first packet A of the text streaming output is 2 TOKENs, which are sent to the content review at the same time. The content review block size is A. The text-to-speech module converts the two TOKENs of A into 1 TOKEN and 1 streaming packet A1A2, and then performs subsequent streaming speech synthesis and streaming returns to the client. If the D package is not reviewed, the D1D2 voice streaming package and subsequent text packages and voice packages are discarded, and the interaction request and output content ABC are input into the model for rewriting, thereby ensuring that the interaction response time delay is shortened while the security review is performed, and the smoothness of the user experience is not affected even if the security review fails.
[0147] Regarding step S105, in this step, the approved block data will be streamed to the client in a predetermined display format. In this way, the client can receive part of the content as early as possible without waiting for the entire data to be processed, thereby improving the immediacy of interaction.
[0148] For example, when each approved block data is streamed to the client, the data block of the streaming output here can be different from the streaming block size of the streaming output from the model output end to the server. For example, the streaming block from the model to the server is 2 TOKENs, and the content review block is 1 streaming block, that is, 2 TOKENs. After the content review is passed, the 2 TOKEN content will be transmitted to the client as 1 TOKEN as a streaming block.
[0149] In addition, in another implementation manner provided by the present application, the data interaction method further includes: identifying the interval time of data sent to the client; when the data interval time exceeds a preset time threshold, sending a transition statement to the client.
[0150] Here, the time threshold is used to define the maximum allowable time interval for data transmission. If the data transmission interval exceeds this preset threshold, it means that the current data transmission speed or response time may be delayed. At this time, measures need to be taken to avoid a decrease in user experience.
[0151] The transition statement is usually some prompt or explanation to tell the user that the data is being processed to avoid discomfort caused by long waiting time. For example, the transition statement can be "Please wait, processing", "Please wait, content will be generated soon", "Oh, right, I suddenly thought of it", which is used to relieve the user's anxiety and improve the user experience.
[0152] For example: Continuing with the above example, after the approved A1A2B1B2C1C2 is streamed to the client and completed, if the model is not received for re-statement (rewriting) to generate E1E2, or if the estimated interval time for generating E1E2 after the model is re-statement (rewriting) exceeds the preset value when it is about to be completed, or if the estimated interval time after completion exceeds the preset value, a preset transition statement is inserted after C2 and returned to the client, such as "Oh, by the way, I suddenly thought of it", etc., to prevent interaction jams.
[0153] For a clearer understanding of the interaction process of this application, please refer to Figure 2 , Figure 2A simplified schematic diagram of the processing of a data interaction method provided in the present application. The processing includes: S1, the client sends a connection request to the server; S2, the server determines the target communication mode according to the received connection request; S3, the server establishes a communication connection with the client according to the determined target communication mode; S4, the client sends an interaction request to the server; S5, the server determines whether conversion processing is required according to the received interaction request to ensure that the interaction request input to the target interaction model is in text format, and sends the text-type interaction request to the target interaction model (it should be noted that another implementation of S5 can also send the received interaction request directly to the model, and the model performs text recognition and conversion processing); S6, the target interaction model streams the byte interaction response data generated according to the interaction request to the server; S7, the server converts the received byte interaction response data into text interaction response data; S8, the server processes the converted text interaction response data in sequence according to the preset block strategy, determines the block data to be reviewed, and reviews them in sequence; if the review is passed, execute step S9, if the review is not passed, execute step S10; S9, the server streams the data that has passed the review to the client in a predetermined format; S10, the server resends the original interaction request and the data that has passed the review to the target interaction model for re-derivation.
[0154] In this way, this solution can shorten the response interaction time from the original model generation time to the model generation time of the first streaming packet; if content review is added, the time will also be shortened from the model generation time + the time of all content review to the model generation time of the first streaming packet + the time of the first review packet; if the review fails, the time delay will be shortened even more. And the streaming communication method based on grpc and the sse communication protocol on the end side are adopted to improve the data transmission efficiency and support streaming interaction, which provides users with a more natural and smoother conversation experience.
[0155] Based on the same inventive concept, a data interaction device corresponding to the data interaction method is also provided in the embodiment of the present application. Since the principle of solving the problem by the device in the embodiment of the present application is similar to the above-mentioned data interaction method in the embodiment of the present application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0156] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of a data interaction device provided in an embodiment of the present application. Figure 3 As shown in , the data interaction device 300 includes:
[0157] The receiving module 310 is used to receive an interaction request sent by a client and send the interaction request to a target interaction model;
[0158] The conversion module 320 is used to stream the byte interaction response data fed back by the target interaction model according to the interaction request, and convert it into text interaction response data in real time; the byte interaction response data includes at least one byte;
[0159] The block module 330 is used to process the converted text interaction response data in sequence according to a preset block strategy to determine the block data to be reviewed;
[0160] The review module 340 is used to review the block data to be reviewed according to a preset review strategy after each block data to be reviewed is determined;
[0161] The sending module 350 is used to stream the approved block data to the client in a predetermined display format.
[0162] Optionally, when the interaction request is a voice interaction request, when the receiving module 310 is used to receive the interaction request sent by the client and send the interaction request to the target interaction model, the receiving module 310 is used to:
[0163] Streaming receives voice interaction requests sent by the client;
[0164] The text interaction request determined by converting the voice interaction request is sent to the target interaction model.
[0165] Optionally, when the block module 330 is used to sequentially process the converted text interaction response data according to a preset block strategy to determine the block data to be reviewed, the block module 330 is used to:
[0166] According to the preset block strategy, determine the target number of bytes required to be included in the block data to be reviewed;
[0167] According to the target number of bytes, the byte data in the received text interaction response data are reassembled in order to determine the block data to be reviewed.
[0168] Optionally, the block module 330 is further configured to determine the block data to be reviewed in any of the following ways:
[0169] Determine each block of byte data received in a streaming manner as a block of data to be confirmed and reviewed;
[0170] Determine the byte data of multiple blocks received in a streaming manner as one block of data to be determined and reviewed;
[0171] The byte data received in streaming mode is combined and processed according to the principle of progressive accumulation, and the data after each combination is determined as the block data to be reviewed;
[0172] Determine the byte data received in a streamed manner within a preset time as the block data to be reviewed; wherein, if no byte data is received within the preset time, determine the byte data received in a streamed manner within a previous period of time as the block data to be reviewed;
[0173] The byte data with complete semantics received in streaming is determined as the block data to be reviewed.
[0174] Optionally, the data interaction device 300 further includes a regeneration module 360 (not shown in the figure), and the regeneration module 360 (not shown in the figure) is used to:
[0175] When the block data to be reviewed is reviewed and it is determined that the review fails, the interaction request and the block data to be reviewed that are generated based on the interaction request and have passed the review are re-input into the target interaction model to regenerate the byte interaction response data.
[0176] Optionally, the data interaction device 300 further includes a transition module 370 (not shown in the figure), and the transition module 370 (not shown in the figure) is used to:
[0177] Identify the interval time of data sent to the client;
[0178] When the data interval time exceeds a preset time threshold, a transition statement is sent to the client.
[0179] Optionally, the data interaction device 300 further includes a parallel module 380 (not shown in the figure), and the parallel module 380 (not shown in the figure) is used to:
[0180] When the interaction request is a voice interaction request, while the to-be-audited block data is being audited, the to-be-audited block data is format-converted according to a predetermined display format.
[0181] Optionally, when the parallel module 380 (not shown in the figure) is used to perform format conversion processing on the block data to be reviewed according to a predetermined display format, the parallel module 380 (not shown in the figure) is used to:
[0182] The text interaction response data received in a streaming manner or the block data to be reviewed is reorganized to generate a speech synthesis block; wherein, if the review result of the block data to be reviewed corresponding to the speech synthesis block indicates that the review is passed, the synthesized speech generated corresponding to the speech synthesis block is streamed back to the client.
[0183] Optionally, the data interaction device 300 further includes a connection module 390 (not shown in the figure), and the connection module 390 (not shown in the figure) is used to:
[0184] Before receiving the interaction request sent by the client, receiving a connection request determined by the client according to the type of the interaction request;
[0185] Parsing the connection request to determine a target communication mode;
[0186] Establish a connection according to the target communication mode.
[0187] See also Figure 4 , Figure 4 A schematic diagram of the structure of a server provided in an embodiment of the present application. Figure 4 As shown in , the server 400 includes a processor 410 , a memory 420 and a bus 430 .
[0188] The memory 420 stores machine-readable instructions executable by the processor 410. When the server 400 is running, the processor 410 communicates with the memory 420 via the bus 430. When the machine-readable instructions are executed by the processor 410, the above-mentioned Figure 1 as well as Figure 2 The specific implementation of the steps in the method embodiment shown can be found in the method embodiment, and will not be repeated here.
[0189] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer program can execute the above-mentioned Figure 1 as well as Figure 2 The specific implementation of the steps in the method embodiment shown can be found in the method embodiment, and will not be repeated here.
[0190] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0191] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0192] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0193] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0194] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application can essentially be embodied in the form of a software product, or in other words, the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0195] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A data interaction method, characterized in that: Applied to the server, the data interaction method includes: Receive an interaction request sent by a client, and send the interaction request to a target interaction model; Streamingly receiving byte interaction response data fed back by the target interaction model according to the interaction request, and converting the byte interaction response data into text interaction response data in real time; the byte interaction response data includes at least one byte; The converted text interaction response data is processed in sequence according to the preset block strategy to determine the block data to be reviewed; After each block of data to be reviewed is determined, the block of data to be reviewed is reviewed according to the preset review strategy; The block data to be reviewed after review is sent to the client in a streaming manner according to the predetermined display format.
2. The data interaction method according to claim 1, characterized in that: When the interaction request is a voice interaction request, receiving the interaction request sent by the client and sending the interaction request to the target interaction model includes: Streaming receives voice interaction requests sent by the client; The text interaction request determined by converting the voice interaction request is sent to the target interaction model.
3. The data interaction method according to claim 1, characterized in that: The converted text interaction response data is processed in sequence according to the preset block strategy to determine the block data to be reviewed, including: According to the preset block strategy, determine the target number of bytes required to be included in the block data to be reviewed; According to the target number of bytes, the byte data in the received text interaction response data are reassembled in order to determine the block data to be reviewed.
4. The data interaction method according to claim 3, characterized in that: Use any of the following methods to determine the block data to be reviewed: Determine each block of byte data received in a streaming manner as a block of data to be confirmed and reviewed; Determine the byte data of multiple blocks received in a streaming manner as one block of data to be determined and reviewed; The byte data received in streaming mode is combined and processed according to the principle of progressive accumulation, and the data after each combination is determined as the block data to be reviewed; Determine the byte data received in a streamed manner within a preset time as the block data to be reviewed; wherein, if no byte data is received within the preset time, determine the byte data received in a streamed manner within a previous period of time as the block data to be reviewed; The byte data with complete semantics received in streaming is determined as the block data to be reviewed.
5. The data interaction method according to claim 1, characterized in that: When the block data to be reviewed is reviewed and it is determined that the review fails, the data interaction method further includes: The interaction request and the block data to be reviewed that are generated according to the interaction request and have passed review are re-input into the target interaction model to regenerate the byte interaction response data.
6. The data interaction method according to claim 1, characterized in that: The data interaction method further includes: Identify the interval time of data sent to the client; When the data interval time exceeds a preset time threshold, a transition statement is sent to the client.
7. The data interaction method according to claim 1, characterized in that: When the interaction request is a voice interaction request, while reviewing the block data to be reviewed, the data interaction method further includes: The format of the block data to be reviewed is converted according to the predetermined display format.
8. The data interaction method according to claim 7, characterized in that: The format conversion process of the block data to be reviewed according to the predetermined display format includes: The text interaction response data received in a streaming manner or the block data to be reviewed is reorganized to generate a speech synthesis block; wherein, if the review result of the block data to be reviewed corresponding to the speech synthesis block indicates that the review is passed, the synthesized speech generated corresponding to the speech synthesis block is streamed back to the client.
9. The data interaction method according to claim 1, characterized in that: Before receiving the interaction request sent by the client, the data interaction method further includes: receiving a connection request determined by the client according to the type of the interaction request; Parsing the connection request to determine a target communication mode; Establish a connection according to the target communication mode.
10. A data interaction device, characterized in that: Applied to a server, the data interaction device comprises: A receiving module, used for receiving an interaction request sent by a client, and sending the interaction request to a target interaction model; A conversion module, used for streaming receiving byte interaction response data fed back by the target interaction model according to the interaction request, and converting it into text interaction response data in real time; the byte interaction response data includes at least one byte; The block module is used to process the converted text interaction response data in sequence according to the preset block strategy to determine the block data to be reviewed; The audit module is used to audit the block data to be audited according to the preset audit strategy after each block data to be audited is determined; The sending module is used to stream the block data to be reviewed after the review is passed to the client in a predetermined display format.