Response text generation method and device, electronic equipment and storage medium

By combining real-time security discrimination using generative models with deep learning context reconstruction models, the problem of balancing security and accuracy in streaming content generation using text generative models is solved, thereby improving security, compliance, and user experience.

CN122133666APending Publication Date: 2026-06-02CHONGQING LANDIAN AUTOMOBILE TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHONGQING LANDIAN AUTOMOBILE TECHNOLOGY CO LTD
Filing Date
2026-02-26
Publication Date
2026-06-02

Smart Images

  • Figure CN122133666A_ABST
    Figure CN122133666A_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, electronic device, and storage medium for generating response text. It utilizes a generative model to generate output text word-by-word from user input, and performs real-time security checks on the generated text. If unsafe content is detected, the generative model is stopped from generating content. A deep learning context reconstruction model then performs semantic continuation on the output text, generating a continuation text. Finally, the output text from the generative model and the continuation text are concatenated to obtain the target response text, which is returned to the client. By performing real-time security checks and post-processing on the generated content during streaming content generation, the continued generation and output of unsafe content can be promptly blocked. Simultaneously, the deep learning context reconstruction model enables semantic continuation, supplementing positive and coherent content based on the already generated legal context after the generation of unsafe content has stopped, avoiding abrupt interruptions for the user and improving the overall interactive experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, electronic device and storage medium for generating responsive text. Background Technology

[0002] Existing security control strategies for text generation models involve feeding the model high-quality, secure data to enable reinforcement learning, thereby imposing security constraints on the model itself.

[0003] However, existing text generation models lack effective fallback mechanisms for content security control. Even if the model generates unsafe content, it is impossible to intervene in real time. There is an irreconcilable contradiction between security and generation accuracy, making it difficult to fully cover various risk scenarios. Summary of the Invention

[0004] This application provides a response text generation method, apparatus, electronic device, and storage medium to solve the technical problem that existing text generation models cannot intervene in real time during the streaming content generation process, and it is difficult to balance security and generation accuracy.

[0005] Firstly, this application provides a method for generating response text, the method comprising: Receive user input, generate output text word by word based on the user input using a generative model, and use all or part of the currently generated output text as the current text to be detected; The current text to be detected is input into the content security discrimination model to obtain the security discrimination result of the current text to be detected. If the security determination result indicates that the current text to be detected contains unsafe content, the generative model is controlled to stop content generation and the deep learning context reconstruction model is triggered. The deep learning context reconstruction model is used to perform semantic continuation based on the output text currently generated by the generative model, and generate continuation text. Based on the output text currently generated by the generative model and the continuation text, the target response text is formed.

[0006] In one possible implementation, controlling the generative model to stop content generation includes: The generative model is controlled to continue generating output text word by word until it generates semantic breakpoint markers, at which point the generative model is controlled to stop content generation.

[0007] In one possible implementation, using all or part of the currently generated output text as the current text to be detected includes: If the length of all currently generated output text is less than or equal to a preset length threshold, then all currently generated output text is taken as the current text to be detected. If the total length of all currently generated output text is greater than a preset length threshold, the currently generated partial output text is taken as the current text to be detected; wherein, the partial output text is the output text string most recently generated by the generative model with a length of the preset length threshold, which is taken as the current text to be detected.

[0008] In one possible implementation, the content security discrimination model evaluates the current text to be detected in the following way: Multiple window text segments are extracted from the text to be detected using a sliding window mechanism; wherein, there are overlapping areas between adjacent window text segments; Each of the window text fragments is input into the semantic representation network of the content security discrimination model to generate a corresponding window semantic vector. The generated semantic vectors of multiple windows are normalized and fused to obtain the overall semantic representation of the text to be detected; The overall semantic representation is interactively weighted and calculated with multiple preset security category label vectors to obtain a weighted interactive feature vector. The weighted interactive feature vector is input into the classifier in the content security discrimination model to obtain the security discrimination result of the text to be detected.

[0009] In one possible implementation, the deep learning context reconstruction model is a finely tuned lightweight language model, trained in the following manner: A pairing dataset is constructed, which contains multiple training samples. Each training sample includes an insecure text fragment and a corresponding secure continuation text. The secure continuation text is generated by continuing the insecure text fragment in a way that complies with security standards, while preserving the original intent of the user and the user input. Using the unsafe text fragment as input and the safe continuation text as the training target, the initial language model is supervised and fine-tuned so that the deep learning context reconstruction model learns to generate continuation text based on the semantics of the output text currently generated by the generative model.

[0010] In one possible implementation, the method further includes: Before the generative model generates the semantic breakpoint marker, if the content security discrimination model detects that the subsequently generated text contains newly added unsafe content, it directly controls the generative model to stop content generation.

[0011] In one possible implementation, forming the target response text based on the currently generated output text of the generative model and the continued text includes: Extract the language style features of the output text generated by the generative model; The continuation text is style-adapted according to the language style features to ensure that the language style features of the continuation text are consistent with the language style features of the output text. The style-adapted continuation text is concatenated with the generated output text to obtain the target response text.

[0012] Secondly, this application provides a response text generation apparatus, the apparatus comprising: The text to be detected generation module is used to receive user input, generate output text word by word based on the user input through a generative model, and use all or part of the currently generated output text as the current text to be detected. The text security discrimination module is used to input the current text to be detected into the content security discrimination model to obtain the security discrimination result of the current text to be detected. The continuation trigger module is used to control the generative model to stop content generation and trigger the deep learning context reconstruction model when the security judgment result indicates that the current text to be detected contains unsafe content. The text continuation module is used to reconstruct the model through the deep learning context, and to perform semantic continuation based on the output text currently generated by the generative model to generate continuation text. The target response text generation module is used to form the target response text based on the output text currently generated by the generative model and the continuation text.

[0013] In one possible implementation, the continuation trigger module includes: The content generation stop unit is used to control the generative model to continue generating output text word by word until the generative model generates semantic breakpoint markers, at which point the generative model stops content generation.

[0014] In one possible implementation, the text generation module is specifically used for: If the length of all currently generated output text is less than or equal to a preset length threshold, then all currently generated output text is taken as the current text to be detected. If the total length of all currently generated output text is greater than a preset length threshold, the currently generated partial output text is taken as the current text to be detected; wherein, the partial output text is the output text string most recently generated by the generative model with a length of the preset length threshold, which is taken as the current text to be detected.

[0015] In one possible implementation, the content security discrimination model in the text security discrimination module evaluates the current text to be detected in the following way: Multiple window text segments are extracted from the text to be detected using a sliding window mechanism; wherein, there are overlapping areas between adjacent window text segments; Each of the window text fragments is input into the semantic representation network of the content security discrimination model to generate a corresponding window semantic vector. The generated semantic vectors of multiple windows are normalized and fused to obtain the overall semantic representation of the text to be detected; The overall semantic representation is interactively weighted and calculated with multiple preset security category label vectors to obtain a weighted interactive feature vector. The weighted interactive feature vector is input into the classifier in the content security discrimination model to obtain the security discrimination result of the text to be detected.

[0016] In one possible implementation, the deep learning context reconstruction model in the text continuation module is a finely tuned lightweight language model, trained in the following manner: A pairing dataset is constructed, which contains multiple training samples. Each training sample includes an insecure text fragment and a corresponding secure continuation text. The secure continuation text is generated by continuing the insecure text fragment in a way that complies with security standards, while preserving the original intent of the user and the user input. Using the unsafe text fragment as input and the safe continuation text as the training target, the initial language model is supervised and fine-tuned so that the deep learning context reconstruction model learns to generate continuation text based on the semantics of the output text currently generated by the generative model.

[0017] In one possible implementation, the stop content generation unit is further configured to: Before the generative model generates the semantic breakpoint marker, if the content security discrimination model detects that the subsequently generated text contains newly added unsafe content, it directly controls the generative model to stop content generation.

[0018] In one possible implementation, the target response text generation module is specifically used for: Extract the language style features of the output text generated by the generative model; The continuation text is style-adapted according to the language style features to ensure that the language style features of the continuation text are consistent with the language style features of the output text. The style-adapted continuation text is concatenated with the generated output text to obtain the target response text.

[0019] Thirdly, this application provides an electronic device, including: a processor and a memory, wherein the processor is configured to execute a response text generation program stored in the memory to implement the response text generation method described in any one of the first aspects.

[0020] Fourthly, this application provides a storage medium storing one or more programs that can be executed by one or more processors to implement the response text generation method described in any one aspect.

[0021] Compared with the prior art, the technical solution provided in this application has the following advantages: The method provided in this application generates output text word by word based on user input through a generative model, and performs security judgment on the generated text in real time. If the generated text is judged to be unsafe content, the generative model is controlled to stop generating content, and a deep learning context reconstruction model is used to perform semantic continuation on the output text to generate continuation text. Finally, the output text containing unsafe content and the continuation text are concatenated to obtain the target response text, which is returned to the client. By performing security judgment and post-processing on the generated content in real time during the streaming content generation process, on the one hand, it can promptly block the continued generation and output of unsafe content, effectively avoid the risk of harmful information dissemination, and ensure the compliance and security of the response text; on the other hand, by using a deep learning context reconstruction model for semantic continuation, after stopping the generation of unsafe content, positive and coherent content is supplemented based on the generated legal context, which not only effectively guides the user's intentions in a positive direction, but also ensures the natural fluency of the dialogue, avoids the abruptness caused by content interruption, and improves the overall interactive experience. Furthermore, this mechanism, which combines real-time discrimination with continuation writing, can balance content security and user needs without significantly affecting generation efficiency, providing a more reliable security solution for the practical application of text generation models. Attached Figure Description

[0022] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0023] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.

[0025] Figure 1 A flowchart illustrating an embodiment of a response text generation method provided in this application; Figure 2 Flowchart of another embodiment of the response text generation method provided in this application; Figure 3 A flowchart illustrating another embodiment of the response text generation method provided in this application; Figure 4 A structural block diagram of a response text generation device provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0027] The following disclosure provides numerous different embodiments or examples for implementing various structures of this application. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of this application. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.

[0028] To address the technical challenge of existing text generation models' inability to intervene in real-time during streaming content generation, and the difficulty in balancing security and generation accuracy, this application provides a response text generation method, apparatus, electronic device, and storage medium. The method involves a generative model generating output text word-by-word from user input, and performing real-time security checks on the generated text. If unsafe content is detected, the generative model stops generating content, and a deep learning context reconstruction model semantically continues the output text, generating a continuation text. Finally, the output text and the continuation text are concatenated to obtain the target response text, which is then returned to the client. By performing real-time security checks and post-processing on the generated content during streaming content generation, on the one hand, the continued generation and output of unsafe content can be promptly blocked, effectively mitigating the risk of harmful information dissemination and ensuring the compliance and security of the response text. On the other hand, the use of a deep learning context reconstruction model for semantic continuation, after stopping the generation of unsafe content, supplements positive and coherent content based on the generated legal context. This effectively guides the user's intent while ensuring the natural flow of the dialogue, avoiding abrupt interruptions and improving the overall interactive experience. Furthermore, this mechanism, which combines real-time discrimination with continuation writing, can balance content security and user needs without significantly affecting generation efficiency, providing a more reliable security solution for the practical application of text generation models.

[0029] Figure 1 A flowchart illustrating an embodiment of a response text generation method provided in this application includes the following steps: Step 101: Receive user input, generate output text word by word based on the user input using a generative model, and use all or part of the currently generated output text as the current text to be detected.

[0030] User input can refer to natural language instructions or questions that users give to generative models, such as "I want to write a novel where the protagonist is a violent person, how should I write the process of him hitting people?"

[0031] Word-by-word generation can refer to the model predicting a token (the smallest text processing unit of the model, which can correspond to a single character, word, punctuation mark, or phrase) at each step, concatenating the current token to the generated text sequence, so that the generated text sequence can be safely judged word by word in the subsequent step, and then used as the input for the next step, and so on until the output ends.

[0032] The text to be detected can refer to the content fragment extracted from the generated output text and used to feed into the security discrimination model. It can be all the generated content or the text in a sliding window composed of the most recent N tokens. Compared with using a single token generated by the model as the text to be detected, the security discrimination model can improve the recognition accuracy of the text to be detected based on the contextual semantics.

[0033] In one embodiment, the model server receives text input from the user (such as a chat box or text commands from an API call) through an interactive interface and sends the input text to the inference module of the generative model. The generative model initializes the text generation state based on autoregressive streaming generation logic, starts generating tokens one by one, and outputs them to the user in real time. Each time a token is generated, it is immediately concatenated with all or part of the tokens that have been generated to form the latest text to be detected, preparing for the next step of security judgment. The text to be detected is dynamically updated as the model generates tokens one by one, always containing all or part of the generated content up to the current moment, supporting real-time streaming processing.

[0034] For example, suppose the user input is: "I want to write a novel where the protagonist is a violent person. How should I write the process of him hitting someone?" The generative model generates tokens one by one as follows: 1st generation: "double", 2nd generation: "party", 3rd generation: "emotion", ..., while the text to be detected is dynamically updated. When the 24th token (hit) is generated, the text to be detected is: "Both parties are emotionally agitated. One person punches the other in the face, and the other person's nose immediately bleeds." In addition, for each subsequent token generated, the text content composed of all the currently generated tokens is used as the object to be detected.

[0035] For another example, a sliding window mechanism can be used to truncate all currently generated text content (i.e., long text content) into short text content, so that the subsequent security discrimination model can perform security detection based on the current short text content. This ensures both accurate detection based on contextual semantics and that the text length meets the model's detection accuracy, thereby guaranteeing detection accuracy and precision.

[0036] Step 102: Input the current text to be detected into the content security discrimination model to obtain the security discrimination result of the current text to be detected.

[0037] Content security discrimination model refers to a streaming semantic discrimination model designed specifically for text security detection. It has deep semantic understanding capabilities and low latency characteristics, and can perform real-time security assessment on dynamically updated text to be detected. It is the perception module of the entire security control system.

[0038] The safety determination result can mean that the model only outputs two labels, safe and unsafe, without other complex classification results, simplifying the determination logic to ensure real-time performance. The label determination is based on the semantic level of the text to be detected, rather than simple keyword matching.

[0039] In one embodiment, the text to be detected generated based on the above steps is synchronously sent to the processing module of the content security discrimination model through a real-time data interface. If the length of the text to be detected exceeds the processing threshold of the model, a sliding window process is adopted: the long text is divided into multiple text windows with overlapping areas, which are then sequentially input into the semantic representation module of the model for encoding. The semantic features of the text to be detected are interacted with the classification labels, and the interactive features are sent to the classifier to quickly output the judgment result of security or insecurity. The whole process is synchronized with the generation of tokens by the generative model, with no significant delay.

[0040] For example, suppose the text to be detected is: "Both parties are emotionally agitated; one person punches the other in the face, causing immediate nosebleed." Since the length of this text does not exceed a threshold, it is directly input into the semantic representation module for semantic encoding, extracting the core semantics describing the violent details of the fight. After the semantic features interact with the classification labels, the classifier determines, based on the semantics, that the content involves a specific description of a violent scene and is therefore unsafe; that is, the final output is "unsafe." This is merely an example; the specific interaction between semantic features and classification labels will be described in detail in the relevant embodiments below.

[0041] Step 103: If the security judgment result indicates that the current text to be detected contains unsafe content, control the generative model to stop content generation and trigger the deep learning context reconstruction model.

[0042] Stopping content generation can refer to the generative model terminating the autoregressive generation of subsequent tokens after receiving a stop command, and no longer outputting new generated content to the user. It is a decision-making step in the security control system.

[0043] Deep learning context reconstruction models can refer to lightweight, dedicated models designed specifically for secure continuation writing. Their architecture is smaller than that of master generative models. Based on the generated text content, they can complete semantic coherence within the security boundary and preserve the user's original intent for continuation writing. They serve as the execution module of the entire security control system.

[0044] The deep learning context reconstruction model can be triggered through the instruction interaction mechanism of the model server. At the same time as the generative model stops generating, a start signal is sent to the deep learning context reconstruction model, and all the output text generated by the generative model is synchronized to the model.

[0045] In one embodiment, after the content security discrimination model outputs an unsafe label, it immediately sends a stop generation command to the inference module of the generative model. Upon receiving the command, the generative model stops generating content if the conditions are met, while the server triggers the startup process of the deep learning context reconstruction model, using all the output text generated by the generative model as context input and passing it to the inference module of the reconstruction model. If the discrimination result is safe, no operation is triggered, and the generative model continues to generate content token by token. The text to be detected is continuously and dynamically updated, and the above steps are repeated.

[0046] For example, suppose the current text to be detected is: "Both parties are emotionally agitated; one person punches the other in the face, causing immediate nosebleed." If the security assessment result is "unsafe," then under certain conditions, the generative model will be controlled to stop generating tokens. Simultaneously, the server triggers a deep learning context reconstruction model to synchronize the already generated complete text ("Both parties are emotionally agitated; one person punches the other in the face, causing immediate nosebleed") to the reconstruction model. This is merely an example; the specific conditions under which the generative model is controlled to stop generating content will be described in detail in the relevant embodiments below.

[0047] Step 104: Reconstruct the model through deep learning context, and perform semantic continuation based on the output text currently generated by the generative model to generate continuation text.

[0048] Semantic continuation refers to the reconstruction model extending and generating text within safe boundaries based on the contextual semantics of the already generated text, the user's core intent, and the text style. It is not a simple content splicing, but must ensure that the semantic logic of the continuation content is consistent with that of the already generated content.

[0049] Continuing text refers to the safe text content generated by the reconstruction model. It is a compliant extension of the already generated text. The core goal is to continue the text in a harmless manner and provide positive guidance, so as to satisfy the user's reasonable intentions and avoid the output of unsafe content.

[0050] In one embodiment, after receiving all the generated output text, the deep learning context reconstruction model (hereinafter referred to as the reconstruction model for ease of description) parses the text context and the user's original intent through the semantic understanding module; based on the safe continuation rules trained by the model, it selects continuation directions that conform to semantic logic within the safety boundary, and at the same time determines the continuation direction of the positive safety guidance text for unsafe content; after the continuation text is generated, it is temporarily stored on the server to prepare for the next step of forming the target response text.

[0051] For example, suppose the generative model has generated the following output text: "Both parties are emotionally agitated; one person punches the other in the face, causing immediate nosebleed." The reconstruction model, by analyzing the context, concludes that the user requested a description of the fight, and the generated content mentions the unsafe content of a nosebleed, indicating a core intent of describing a scene that does not spread violence. Based on the aforementioned prompts, the reconstruction model avoids specific violent actions and ultimately generates the following continuation text: "The scene instantly descended into chaos, and bystanders rushed forward to try and separate the two; the person who was hit was extremely angry, covering his face, his body trembling slightly with rage. He struggled to break free from the bystanders' restraints to continue arguing with the other party and even retaliate. However, such behavior not only causes physical harm to both parties but also violates legal regulations, and in serious cases, constitutes a criminal offense. Therefore, fighting should be avoided under any circumstances, and conflicts should be resolved through communication or legal means." It is evident that the reconstruction model not only generates safe text content based on the user's intent but also generates positive text guidance content based on the unsafe content output by the generative model.

[0052] Step 105: Based on the output text and continuation text already generated by the generative model, form the target response text.

[0053] The target response text can refer to the complete text formed by combining the output text generated by the generative model and the continuation text generated by the reconstructive model. It is the compliant response content that is finally output to the user and is also the final product of the entire security control method.

[0054] In one embodiment, the server obtains all valid output text generated by the generative model; it appends the continuation text generated by the reconstructed model to the end of the generated text to complete the fusion of the two texts; it performs a simple semantic check on the concatenated complete text to confirm that there are no logical breaks, stylistic inconsistencies, or other issues; and it outputs the final target response text to the user through the interactive interface to complete the entire response process.

[0055] For example, suppose the output text generated by the generative model is: "Both parties are emotionally agitated; one person punches the other in the face, causing immediate nosebleed." The reconstructed model's continuation text is: "The scene instantly descended into chaos, with bystanders rushing to try and separate the two; the person who was hit was extremely angry, covering his face, his body trembling slightly with rage. He struggled to break free from the bystanders' restraints to continue arguing with the other person and even retaliate." However, such behavior not only causes physical injury to both parties but also violates legal regulations, and in serious cases, constitutes a criminal offense. Therefore, fighting should be avoided under any circumstances, and conflicts should be resolved through communication or legal means.

[0056] Furthermore, all valid output text generated by the generative model and the continuation text generated by the context reconstruction model are directly concatenated to the end of the output text to form a complete text. The two texts are then verified to ensure semantic logic and narrative style are coherent and unbroken, without any incoherent sentences or logical contradictions caused by the concatenation. If the verification fails, transition text is generated based on the output text and the continuation text. Finally, the target response text, consisting of the output text, transition text, and continuation text, is returned to the user client in its entirety through the interactive window, completing the entire response text generation process. Since there are no logical breaks between the output text and the continuation text, they can be directly concatenated into the target response text.

[0057] The method provided in this application generates output text word by word based on user input using a generative model, and performs real-time security checks on the generated text. If unsafe content is detected, the generative model stops generating content, and a deep learning context reconstruction model performs semantic continuation on the output text to generate a continuation text. Finally, the output text containing unsafe content and the continuation text are concatenated to obtain the target response text, which is then returned to the client. By performing real-time security checks and post-processing on the generated content during streaming content generation, on the one hand, the continued generation and output of unsafe content can be promptly blocked, effectively avoiding the risk of harmful information dissemination and ensuring the compliance and security of the response text. On the other hand, by using a deep learning context reconstruction model for semantic continuation, after stopping the generation of unsafe content, positive and coherent content is supplemented based on the already generated legal context. This effectively guides the user's intent in a positive direction, ensures the natural flow of the dialogue, avoids abrupt interruptions, and improves the overall interactive experience. Furthermore, this mechanism, which combines real-time discrimination with continuation writing, can balance content security and user needs without significantly affecting generation efficiency, providing a more reliable security solution for the practical application of text generation models.

[0058] Figure 2 A flowchart of another embodiment of the response text generation method provided in this application includes the following steps: Step 201: Receive user input, generate output text word by word based on the user input using a generative model, and use all or part of the currently generated output text as the current text to be detected.

[0059] In one embodiment, the text to be detected can be determined in the following way: if the length of all currently generated output text is less than or equal to a preset length threshold, the all currently generated output text is taken as the current text to be detected; if the length of all currently generated output text is greater than the preset length threshold, a portion of the currently generated output text is taken as the current text to be detected; wherein, the portion of the output text is the output text string most recently generated by the generative model with a length of the preset length threshold, which is taken as the current text to be detected.

[0060] The preset length threshold can refer to a pre-set text length threshold (the unit can be Token or number of characters), which is used to determine the selection range of the text to be detected. It is set by the R&D personnel according to the processing capability of the content security discrimination model and the real-time detection requirements (e.g., set to 50 Tokens).

[0061] "All output text" can refer to the complete text sequence generated word by word by the generative model up to the current time, without any truncation. "Partial output text" can refer to the truncation of only the most recently generated text string with a length equal to the threshold when the total output text length exceeds a preset threshold, discarding earlier generated content and focusing on the most recently generated content for security checks.

[0062] Specifically, the model server receives natural language input from the user (such as instructions or questions) and sends it to the generative model inference module. The generative model generates output text token by token according to autoregressive streaming logic. After each token is generated, the length of all generated output text (number of tokens / number of characters) is immediately calculated. If the length is less than or equal to a preset length threshold, all generated text is used as the text to be detected. If the length is greater than the preset length threshold, only the most recently generated text string with a length equal to the threshold is extracted as the text to be detected (e.g., if the threshold is 10 tokens and 15 tokens have been generated, the text consisting of the 6th to 15th tokens is extracted). Finally, the extracted portion of the output text is sent as the text to be detected to the subsequent content security discrimination model.

[0063] Step 202: Input the current text to be detected into the content security discrimination model to obtain the security discrimination result of the current text to be detected.

[0064] In one embodiment, the content security discrimination model evaluates the current text to be detected in the following way: It extracts multiple window text fragments from the text to be detected using a sliding window mechanism; wherein adjacent window text fragments overlap; each window text fragment is input into the semantic representation network in the content security discrimination model to generate a corresponding window semantic vector; the generated multiple window semantic vectors are normalized and fused to obtain the overall semantic representation of the text to be detected; the overall semantic representation is interactively weighted with multiple preset security category label vectors to obtain a weighted interactive feature vector; the weighted interactive feature vector is input into the classifier in the content security discrimination model to obtain the security discrimination result of the text to be detected.

[0065] The sliding window mechanism refers to the method of sliding and extracting text segments by a fixed window length and a fixed step size. Adjacent segments have overlapping areas to ensure semantic continuity (e.g., window length 5 tokens, step size 3 tokens, overlap 2 tokens).

[0066] Semantic representation networks can refer to the core modules of content security discrimination models, which are used to transform text fragments into vectors that can represent semantics (semantic vectors), such as BERT, RoBERTa and other pre-trained language models.

[0067] A window semantic vector can refer to the vector output after a single window text fragment is encoded by a semantic representation network, reflecting the core semantics of that fragment.

[0068] For example, assuming a window length of 8 tokens and a step size of 4 tokens, multiple window text segments are extracted from the beginning of the text to be detected, with overlapping areas retained between adjacent segments; for example, the previous segment: Tokens 1-8, the next: Tokens 5-12, with overlapping Tokens 5-8; each window segment is input into a semantic representation network, which outputs the corresponding window semantic vector; L2 normalization is performed on all window semantic vectors (to eliminate length differences), and then a weighted average is obtained (the weights can be set according to the window position, such as the newest window having a higher weight) to obtain the overall semantic representation of the text to be detected; the overall semantic representation is then weighted by attention with preset safety category label vectors such as violence and illegality to generate a weighted interaction feature vector, amplifying the unsafe semantic features; the weighted interaction feature vector is input into a classifier, which outputs the final judgment result of "safe" or "unsafe".

[0069] Step 203: If the security judgment result indicates that the current text to be detected contains unsafe content, control the generative model to continue generating output text word by word until the generative model generates semantic breakpoint markers, then control the generative model to stop content generation.

[0070] Semantic breakpoint markers can refer to punctuation marks that can segment the semantics of text and make the generated content form complete semantic units, such as periods ".", exclamation marks "!", semicolons ";", and line breaks, ensuring that the semantics of the output content are complete and there are no incomplete sentences when generation stops.

[0071] In one embodiment, after the content security discrimination model outputs an "insecure" result, the server does not immediately send a stop command, but records the discrimination result, allowing the generative model to continue generating tokens one by one. For each new token generated, it checks whether it is a preset semantic breakpoint marker (e.g., .; !?). If a semantic breakpoint marker is detected, a stop generation command is immediately sent to the generative model, and the model terminates subsequent token generation. If no semantic breakpoint marker is detected, generation continues and the detection is repeated until a semantic breakpoint marker appears.

[0072] For example, suppose the text to be detected is deemed unsafe: "Both parties are emotionally agitated, one person punches the other in the face" (no semantic breakpoint marker). After the above statement is identified as unsafe, the model continues to generate the next token. When a period is detected, the server immediately sends a stop command, and the model terminates generation. For example: "Both parties are emotionally agitated, one person punches the other in the face, and the nose immediately bleeds." (Semantically complete, no incomplete sentences).

[0073] Step 204: Before the generative model generates semantic breakpoint markers, if the content security discrimination model detects that the subsequently generated text contains newly added unsafe content, directly control the generative model to stop content generation.

[0074] The aforementioned newly added unsafe content may refer to situations where, during the continued generation process in step 203, the newly generated token, after being concatenated, adds more serious unsafe semantics to the text to be detected (such as escalating from fighting to knife attack), or adds other categories of unsafe content (such as illegal acts). Without waiting for semantic breakpoint markers, a stop command is immediately sent, forcing the generative model to terminate generation and preventing the expansion of risky content.

[0075] For example, suppose the initial text to be detected is "Both parties are emotionally agitated and pushing each other" (the judgment result is unsafe, low level of violence). The generative model then continues to generate output text: New Token1: "and" (not a breakpoint); New Token2: "hold" (not a breakpoint); New Token3: "knife" (not a breakpoint). Although there are no breakpoints here, after generating "knife," the text to be detected is updated to "Both parties are emotionally agitated and pushing each other, one of whom is holding a knife." This text is then re-entered into the discriminative model. Although the discriminative model does not detect breakpoints, it detects the addition of "holding a knife," a more serious unsafe content, and it is considered a new high-risk addition. At this point, without waiting for semantic breakpoint marking, a stop command is immediately sent, and the model terminates generation. The final generated text is: "Both parties are emotionally agitated and pushing each other, one of whom is holding a knife" (although there are no semantic breakpoints, the model stops immediately due to the addition of high-risk unsafe content to avoid generating more serious unsafe content such as "holding a knife to injure someone").

[0076] By waiting for the semantic breakpoint marker in step 203 above, the generated text is stopped at an incomplete sentence (such as "both sides are emotionally agitated, and one person punches the other"). After splicing and continuing the text, there are no logical breaks, which improves the user experience and ensures semantic integrity.

[0077] Step 204 above directly stops the generation of newly added seriously unsafe content, preventing the model from continuing to generate more dangerous and illegal content (such as escalating from "pushing" to "stabbing someone with a knife"), further narrowing the scope of risky content exposure; and thus strictly controlling the expansion of high-risk content.

[0078] In summary, when mildly unsafe content is detected, the system waits for a semantic breakpoint before stopping (to ensure user experience), while when severe or newly added unsafe content is detected, the system stops immediately (to ensure security), achieving a fine balance between "security control" and "content semantic integrity".

[0079] Step 205: Trigger the deep learning context reconstruction model. Through the deep learning context reconstruction model, semantic continuation is performed based on the output text currently generated by the generative model to generate continuation text.

[0080] Step 206: Based on the output text and continuation text currently generated by the generative model, form the target response text.

[0081] For steps 205-206 above, please refer to the above. Figure 1 Detailed description of the relevant embodiments.

[0082] pass Figure 2 The relevant description of the illustrated embodiments is in Figure 1Building upon this foundation, the system employs a comprehensive design that combines dynamic text selection for detection, refined security assessment, tiered termination control, and secure continuation of generation. This approach addresses the shortcomings of traditional generative models in terms of real-time performance and accuracy in content security management, while achieving a refined balance between security protection, user experience, and model efficiency. Specifically, by dynamically selecting text for detection, it balances detection efficiency and real-time performance, avoiding excessive computation and response delays caused by full-scale detection of long texts. This adapts to the word-by-word streaming nature of generative models, focusing on the most recently generated content for accurate detection. Furthermore, by waiting for semantic breakpoints when detecting security risks, it maintains semantic integrity. When detecting ordinary unsafe content, it does not immediately interrupt generation but allows the model to continue generating until semantic breakpoints such as periods and semicolons, resolving the semantic fragmentation problem caused by traditional "one-size-fits-all" termination.

[0083] Figure 3 A flowchart illustrating another embodiment of the response text generation method provided in this application includes the following steps: Step 301: Receive user input, generate output text word by word based on the user input using a generative model, and use all or part of the currently generated output text as the current text to be detected.

[0084] Step 302: Input the current text to be detected into the content security discrimination model to obtain the security discrimination result of the current text to be detected.

[0085] Step 303: If the security judgment result indicates that the current text to be detected contains unsafe content, control the generative model to stop content generation and trigger the deep learning context reconstruction model.

[0086] For steps 301-303 above, please refer to the above. Figure 1 The relevant description of the illustrated embodiment.

[0087] Step 304: Reconstruct the model through deep learning context, and perform semantic continuation based on the output text currently generated by the generative model to generate continuation text.

[0088] In one embodiment, the aforementioned deep learning context reconstruction model is a finely tuned lightweight language model, trained as follows: A paired dataset is constructed, containing multiple training samples, each including an unsafe text fragment and its corresponding safe continuation text; wherein, the safe continuation text is generated by continuing the unsafe text fragment in a safe manner while preserving the original user intent expressed by the user input, while adhering to safety standards; using the unsafe text fragment as input and the safe continuation text as the training target, the initial language model is supervised and finely tuned, enabling the deep learning context reconstruction model to learn to generate the continuation text based on the semantics of the currently generated output text of the generative model.

[0089] An unsafe text fragment can refer to a portion of text generated by a generative model that is deemed to contain unsafe content by a content security discrimination model. Secure continuation text can refer to text generated by extending an unsafe text fragment in a compliant and secure manner, while preserving the user's original intent and the context of the unsafe text fragment, without any illegal semantics and closely aligned with the user's core needs.

[0090] Supervised fine-tuning can refer to a supervised model training method that uses unsafe text fragments from a paired dataset as model input and corresponding safe continuation texts as expected outputs (training targets). The model parameters are optimized through backpropagation, allowing the model to learn the mapping relationship "from unsafe text to safe continuation".

[0091] For example, suppose the generative model has generated the output text: "Both parties are emotionally agitated; one person punches the other in the face, causing immediate nosebleed." After inputting into a pre-trained reconstruction model, the model parses the user's intent as "describe a fight scene" and generates a continuation text based on fine-tuned logic: "Such violent conflict will lead to a series of adverse consequences. In addition to physical injury, it can also result in fines, detention, and other penalties for violating public security regulations. It harms others and incurs legal responsibility for oneself; resolving conflicts rationally is the right choice."

[0092] Step 305: Extract the language style features of the output text generated by the generative model.

[0093] Language style features can refer to the unique linguistic expression attributes presented by a text. They are the core features that distinguish different text styles, including sentence structure features, word choice features, tone features, etc. This application does not limit these features.

[0094] Style feature extraction refers to the process of quantitatively extracting the above-mentioned language style features from text through natural language processing technology, transforming abstract style into computable and comparable feature vectors / feature parameters.

[0095] In one embodiment, the output text input style feature extraction module generated by the generative model integrates the extracted multi-dimensional style features to generate a standardized style feature vector / feature parameter set for subsequent style adaptation of the continuation text.

[0096] For example, suppose the output text generated by the generative model is: "Both parties are emotionally agitated; one person punches the other in the face, causing immediate nosebleed." The features extracted by the style feature extraction module include: sentence structure features: primarily short sentences, declarative sentences, punctuation only including commas and periods, concise and straightforward language; word choice features: colloquial and common language, without complex formal language, objective descriptive vocabulary; tone features: purely objective declarative tone, without exclamations, advice, or other emotional responses; rhythmic expression: tightly connected sentences, without redundant connecting words, brisk descriptive pace. Furthermore, the above style feature extraction results can be integrated into style feature parameters to facilitate the subsequent style adaptation module in generating continued text. This is merely an example, and the embodiments of this application do not impose limitations.

[0097] Step 306: Perform style adaptation on the continuation text according to the language style characteristics, so that the language style characteristics of the continuation text are consistent with the language style characteristics of the output text.

[0098] Style adaptation can refer to adjusting and optimizing the original continuation text generated by the reconstruction model at the language expression level based on the language style characteristics of the text already generated by the generative model, so that the continuation text is highly consistent with the generated text in terms of sentence structure, word choice, tone, rhythm, etc., and eliminates the sense of style disconnect.

[0099] Style consistency refers to the fact that the continuation text and the generated text maintain a match in all dimensions of language style features, so that after splicing, they read as if generated by the same subject, without obvious style gaps.

[0100] In one embodiment, the style feature parameters of the generated text and the generated original continuation text are simultaneously input into the style adaptation module. This allows the style adaptation module to perform a dimension-by-dimensional style adjustment on the original continuation text, with the adjustment rules strictly adhering to the style features of the generated text. Semantic verification is then performed on the adjusted continuation text to ensure that the style adjustment only modifies the linguistic expression and does not change the core semantics of the continuation text (safety guidance, compliant expression). If the verification passes, the style-adapted continuation text is obtained.

[0101] For example, suppose the generative model has generated text with the following style characteristics: short sentences, colloquial language, objective statements, and a tight rhythm; the original continuation text generated by the reconstructive model is: Such violent conflicts, such as fighting and brawling, not only cause substantial physical damage to both parties, but also violate relevant laws and regulations. In serious cases, they may even constitute the crime of intentional injury and incur corresponding criminal liability. Therefore, when encountering conflicts and disputes, one should remain rational and calm and resolve them through legal and compliant means.

[0102] Furthermore, the style adaptation module breaks down long sentences into shorter ones, removes redundant modifiers, and adjusts word choice, tone, and rhythm to adapt the text. It transforms formal legal expressions into colloquial statements while maintaining objectivity; it also streamlines transition words to make sentences more concise. The final output is the style-adapted continuation text: Such fighting and brawling can cause physical harm to both parties and violates the Public Security Administration Punishment Law. In serious cases, it can constitute intentional injury and incur criminal liability. Therefore, when encountering conflicts and disputes, one should remain calm and resolve them through legal means.

[0103] Step 307: Concatenate the style-adapted continuation text with the generated output text to obtain the target response text.

[0104] In one embodiment, the server retrieves all valid output text generated by the generative model and the style-adapted continuation text from the local cache. The continuation text is then directly appended to the end of the generated output text in semantic logical order to form a complete combined text. A final overall verification is performed on the combined text: ensuring semantic coherence without breaks and consistent logical flow; and maintaining a unified style without disjointedness, reading in a consistent manner. Once the verification passes, the combined text becomes the target response text, ready to be output to the user client.

[0105] Furthermore, if the verification fails, intermediate transition text can be generated to ensure that the semantics of the already generated continuation text and the subsequently generated continuation text are consistent and logically unbroken.

[0106] For example, assuming the generated text and subsequent continuation text pass validation, the direct concatenation and validation would result in: "Both parties are emotionally agitated, and one person punches the other in the face; this behavior causes bodily harm and may also violate the law." As another example, assuming the generated text and subsequent continuation text fail validation due to logical jumps and a lack of effective connection, a transitional text would be generated, leading to the final target response text: "Both parties are emotionally agitated, and one person punches the other in the face." The scene would instantly descend into chaos, and escalating the conflict would only cause more harm. When encountering conflict, one should remain calm and resolve it through communication.

[0107] pass Figure 3The description of the illustrated embodiment, through the introduction of three core innovations—a lightweight reconstruction model with supervised fine-tuning, language style feature extraction and adaptation, and splicing verification and transition text generation—achieves [the following]. Figure 1 Building upon this foundation, a comprehensive upgrade has been achieved in terms of security control capabilities, naturalness of continuation writing, and user experience. By aligning sentence structure, word choice, tone, and rhythm dimension by dimension, the continuation text seamlessly integrates with the generated text, resolving the style disjointedness common in traditional secure continuation writing and ensuring users are unaware of any security intervention. Through a semantic verification mechanism, it is ensured that style adaptation only modifies the form of language expression, without altering the core semantics of secure guidance and compliant output, achieving dual protection of form adaptation and content security.

[0108] Figure 4 A response text generation apparatus provided in this application embodiment includes: The text generation module 41 is used to receive user input, generate output text word by word based on the user input through a generative model, and use all or part of the currently generated output text as the current text to be detected. The text security discrimination module 42 is used to input the current text to be detected into the content security discrimination model to obtain the security discrimination result of the current text to be detected; The continuation trigger module 43 is used to control the generative model to stop content generation and trigger the deep learning context reconstruction model when the security judgment result indicates that the current text to be detected contains unsafe content. The text continuation module 44 is used to reconstruct the model through the deep learning context, perform semantic continuation based on the output text currently generated by the generative model, and generate continuation text. The target response text generation module 45 is used to form the target response text based on the output text currently generated by the generative model and the continuation text.

[0109] In one possible implementation, the continuation trigger module 43 is specifically used for: The generative model is controlled to continue generating output text word by word until it generates semantic breakpoint markers, at which point the generative model is controlled to stop content generation.

[0110] In one possible implementation, the text generation module 41 is specifically used for: If the length of all currently generated output text is less than or equal to a preset length threshold, then all currently generated output text is taken as the current text to be detected. If the total length of all currently generated output text is greater than a preset length threshold, the currently generated partial output text is taken as the current text to be detected; wherein, the partial output text is the output text string most recently generated by the generative model with a length of the preset length threshold, which is taken as the current text to be detected.

[0111] In one possible implementation, the content security discrimination model in the text security discrimination module evaluates the current text to be detected in the following way: Multiple window text segments are extracted from the text to be detected using a sliding window mechanism; wherein, there are overlapping areas between adjacent window text segments; Each of the window text fragments is input into the semantic representation network of the content security discrimination model to generate a corresponding window semantic vector. The generated semantic vectors of multiple windows are normalized and fused to obtain the overall semantic representation of the text to be detected; The overall semantic representation is interactively weighted and calculated with multiple preset security category label vectors to obtain a weighted interactive feature vector. The weighted interactive feature vector is input into the classifier in the content security discrimination model to obtain the security discrimination result of the text to be detected.

[0112] In one possible implementation, the deep learning context reconstruction model in the text continuation module is a finely tuned lightweight language model, trained in the following manner: A pairing dataset is constructed, which contains multiple training samples. Each training sample includes an insecure text fragment and a corresponding secure continuation text. The secure continuation text is generated by continuing the insecure text fragment in a way that complies with security standards, while preserving the original intent of the user and the user input. Using the unsafe text fragment as input and the safe continuation text as the training target, the initial language model is supervised and fine-tuned so that the deep learning context reconstruction model learns to generate continuation text based on the semantics of the output text currently generated by the generative model.

[0113] In one possible implementation, the continuation trigger module is further configured to: Before the generative model generates the semantic breakpoint marker, if the content security discrimination model detects that the subsequently generated text contains newly added unsafe content, it directly controls the generative model to stop content generation.

[0114] In one possible implementation, the target response text generation module is specifically used for: Extract the language style features of the output text generated by the generative model; The continuation text is style-adapted according to the language style features to ensure that the language style features of the continuation text are consistent with the language style features of the output text. The style-adapted continuation text is concatenated with the generated output text to obtain the target response text.

[0115] like Figure 5 As shown in the figure, this application provides an electronic device, including a processor 111, a communication interface 112, a memory 113, and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114. Memory 113 is used to store computer programs; In one embodiment of this application, when the processor 111 executes the program stored in the memory 113, it implements the response text generation method provided in any of the foregoing method embodiments, including: Receive user input, generate output text word by word based on the user input using a generative model, and use all or part of the currently generated output text as the current text to be detected; The current text to be detected is input into the content security discrimination model to obtain the security discrimination result of the current text to be detected. If the security determination result indicates that the current text to be detected contains unsafe content, the generative model is controlled to stop content generation and the deep learning context reconstruction model is triggered. The deep learning context reconstruction model is used to perform semantic continuation based on the output text currently generated by the generative model, and generate continuation text. Based on the output text currently generated by the generative model and the continuation text, the target response text is formed.

[0116] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the response text generation method provided in any of the foregoing method embodiments.

[0117] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0118] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0119] It should be understood that the terminology used herein is for the purpose of describing particular exemplary embodiments only and is not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “described” as used herein may also mean including the plural forms. The terms “comprising,” “including,” “containing,” and “having” are inclusive and therefore indicate the presence of the stated features, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not construed as requiring them to be performed in a particular order described or illustrated unless the order of performance is explicitly indicated. It should also be understood that additional or alternative steps may be used.

[0120] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for generating responsive text, characterized in that, The method includes: Receive user input, generate output text word by word based on the user input using a generative model, and use all or part of the currently generated output text as the current text to be detected; The current text to be detected is input into the content security discrimination model to obtain the security discrimination result of the current text to be detected. If the security determination result indicates that the current text to be detected contains unsafe content, the generative model is controlled to stop content generation and the deep learning context reconstruction model is triggered. The deep learning context reconstruction model is used to perform semantic continuation based on the output text currently generated by the generative model, and generate continuation text. Based on the output text currently generated by the generative model and the continuation text, the target response text is formed.

2. The method according to claim 1, characterized in that, The control of the generative model to stop content generation includes: The generative model is controlled to continue generating output text word by word until it generates semantic breakpoint markers, at which point the generative model is controlled to stop content generation.

3. The method according to claim 1, characterized in that, The step of using all or part of the currently generated output text as the current text to be detected includes: If the length of all currently generated output text is less than or equal to a preset length threshold, then all currently generated output text is taken as the current text to be detected. If the total length of all currently generated output text is greater than a preset length threshold, the currently generated partial output text is taken as the current text to be detected; wherein, the partial output text is the output text string most recently generated by the generative model with a length of the preset length threshold, which is taken as the current text to be detected.

4. The method according to claim 1, characterized in that, The content security discrimination model evaluates the current text to be detected in the following ways: Multiple window text segments are extracted from the text to be detected using a sliding window mechanism; wherein, there are overlapping areas between adjacent window text segments; Each of the window text fragments is input into the semantic representation network of the content security discrimination model to generate a corresponding window semantic vector. The generated semantic vectors of multiple windows are normalized and fused to obtain the overall semantic representation of the text to be detected; The overall semantic representation is interactively weighted and calculated with multiple preset security category label vectors to obtain a weighted interactive feature vector. The weighted interactive feature vector is input into the classifier in the content security discrimination model to obtain the security discrimination result of the text to be detected.

5. The method according to claim 1, characterized in that, The deep learning context reconstruction model is a finely tuned lightweight language model, trained in the following way: A pairing dataset is constructed, which contains multiple training samples. Each training sample includes an insecure text fragment and a corresponding secure continuation text. The secure continuation text is generated by continuing the insecure text fragment in a way that complies with security standards, while preserving the original intent of the user and the user input. Using the unsafe text fragment as input and the safe continuation text as the training target, the initial language model is supervised and fine-tuned so that the deep learning context reconstruction model learns to generate continuation text based on the semantics of the output text currently generated by the generative model.

6. The method according to claim 2, characterized in that, The method further includes: Before the generative model generates the semantic breakpoint marker, if the content security discrimination model detects that the subsequently generated text contains newly added unsafe content, it directly controls the generative model to stop content generation.

7. The method according to claim 1, characterized in that, The process of forming the target response text based on the currently generated output text of the generative model and the continued text includes: Extract the language style features of the output text generated by the generative model; The continuation text is style-adapted according to the language style features to ensure that the language style features of the continuation text are consistent with the language style features of the output text. The style-adapted continuation text is concatenated with the generated output text to obtain the target response text.

8. A responsive text generation device, characterized in that, The device includes: The text to be detected generation module is used to receive user input, generate output text word by word based on the user input through a generative model, and use all or part of the currently generated output text as the current text to be detected. The text security discrimination module is used to input the current text to be detected into the content security discrimination model to obtain the security discrimination result of the current text to be detected. The continuation trigger module is used to control the generative model to stop content generation and trigger the deep learning context reconstruction model when the security judgment result indicates that the current text to be detected contains unsafe content. The text continuation module is used to reconstruct the model through the deep learning context, and to perform semantic continuation based on the output text currently generated by the generative model to generate continuation text. The target response text generation module is used to form the target response text based on the output text currently generated by the generative model and the continuation text.

9. An electronic device, characterized in that, include: A processor and a memory, the processor being configured to execute a response text generation program stored in the memory to implement the response text generation method according to any one of claims 1-7.

10. A storage medium, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the response text generation method according to any one of claims 1-7.