Secure interaction method and device and storage medium

By obtaining and analyzing the security of the current query statement and historical conversation statement, selecting the security sub-statement to generate a propt prompt, it solves the security problem when generating the following text of the large language model, and improves the security and reliability of the generated content.

CN120407759APending Publication Date: 2025-08-01BEIJING CO WHEELS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410131089.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-30
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

When generating the following, the generated content may be insecure due to incorrect use of the above information.

Method used

By obtaining the current query statement and historical session statement, determine the security of each session sub-statement and query sub-statement, select the security sub-statement from it according to the security to generate a propt prompt, and enter a large language model to generate a reply statement.

Benefits of technology

Improve the security of generated reply statements, avoid security problems caused by incorrect use of the above information, and enhance the reliability of generated content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407759A_ABST
    Figure CN120407759A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of natural language processing, in particular to a secure interaction method and device and a storage medium. Comprising the steps of obtaining a current query statement and historical session sentences; wherein the current query statement comprises at least one query sub-statement, and the historical session statement comprises at least one session sub-statement; determining the security of each session sub-statement and each query sub-statement, and determining a security sub-statement from the query sub-statements and the session sub-statements according to the security; and generating a prompt prompt according to the security sub-statement, and inputting the prompt prompt into the large language model to obtain a reply statement of the current query statement. The embodiment of the invention is used for solving the problem that the security of a large language model is relatively poor.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of natural language processing, and in particular, to a secure interaction method, apparatus, and storage medium. Background Art

[0002] With the improvement of the generation ability of large language models, the use of large language models has become increasingly widespread. During the use of large language models, they can make full use of the above text to generate the following text, demonstrating strong creativity. However, precisely due to their ability to make full use of the above text to generate the following text, there may be incorrect use of the above text information during the use of large language models, resulting in security issues in the generated following text. Therefore, in order to make the generated following text of large language models more secure, there is an urgent need for a method to detect the security of large language model conversations to improve the security of large language models. Summary of the Invention

[0003] To solve the above technical problems, this application provides a secure interaction method, apparatus, and storage medium, which can improve the security of large language models.

[0004] In a first aspect, this application provides a secure interaction method, including: obtaining a current query statement and historical conversation statements; the current query statement includes at least one query sub-statement, and the historical conversation statements include at least one conversation sub-statement; determining the security of each conversation sub-statement and each query sub-statement, and determining secure sub-statements from the query sub-statements and conversation sub-statements according to the security; the security includes secure and risky; generating a prompt according to the secure sub-statements, and inputting the prompt into a large language model to obtain a reply statement for the current query statement.

[0005] In a second aspect, this application provides a secure interaction system, including: a security detection module, configured to obtain a current query statement and historical conversation statements; the current query statement includes at least one query sub-statement, and the historical conversation statements include at least one conversation sub-statement; determining the security of each conversation sub-statement and each query sub-statement, and determining secure sub-statements from the query sub-statements and conversation sub-statements according to the security; the security includes secure and risky; a conversation management module, configured to generate a prompt according to the secure sub-statements, and input the prompt into a large language model to obtain a reply statement for the current query statement.

[0006] In a third aspect, the present application provides a secure interaction device, including: an acquisition module configured to acquire a current query statement and historical conversation statements; the current query statement includes at least one query sub-statement, and the historical conversation statements include at least one conversation sub-statement; a determination module configured to determine the security of each conversation sub-statement and each query sub-statement, and determine secure sub-statements from the query sub-statements and conversation sub-statements according to the security; the security includes secure and risky; a generation module configured to generate a prompt according to the secure sub-statements, and input the prompt into a large language model to obtain a response statement for the current query statement.

[0007] In a fourth aspect, the present application provides an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor, where when the computer program is executed by the processor, it implements the secure interaction method as in the first aspect.

[0008] In a fifth aspect, the present application provides a computer-readable storage medium, including: a computer program stored on the computer-readable storage medium, where when the computer program is executed by the processor, it implements the secure interaction method as in the first aspect.

[0009] The technical solution provided by the present application has the following advantages compared with the prior art: First, the current query statement and historical conversation statements are acquired. Among them, the current query statement includes at least one query sub-statement, and the historical conversation statements include at least one conversation sub-statement. Then, the security of each conversation sub-statement and each query sub-statement is determined, and secure sub-statements are determined from the query sub-statements and conversation sub-statements according to the security. Finally, a prompt is generated according to the secure sub-statements, and the prompt is input into the large language model to obtain a response statement for the current query statement. In this way, the response statement can be generated according to the secure statements in the current query statement and historical conversation statements, avoiding the security problems in the generated subsequent text due to the incorrect use of the above information, and improving the security of the generated response statement. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.

[0011] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other accompanying drawings can be obtained based on these drawings without creative efforts.

[0012] Figure 1 FIG. is a schematic diagram of a scenario for providing a secure detection method in an embodiment of the present application;

[0013] Figure 2 One of the schematic flowcharts of the security interaction method provided by the embodiments of the present application;

[0014] Figure 3 Another schematic flowchart of the security interaction method provided by the embodiments of the present application;

[0015] Figure 4 The third schematic flowchart of the security interaction method provided by the embodiments of the present application;

[0016] Figure 5 The fourth schematic flowchart of the security interaction method provided by the embodiments of the present application;

[0017] Figure 6 The fifth schematic flowchart of the security interaction method provided by the embodiments of the present application;

[0018] Figure 7 The schematic structural diagram of a security interaction device provided by the embodiments of the present application;

[0019] Figure 8 The schematic structural diagram of an electronic device provided by the embodiments of the present application. Detailed implementation manners

[0020] In order to more clearly understand the above objects, features and advantages of the present application, the solutions of the present application will be further described below. It should be noted that, without conflict, the embodiments of the present application and the features in the embodiments may be combined with each other.

[0021] Many specific details are set forth in the following description in order to provide a thorough understanding of the present application, but the present application may be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some embodiments of the present application, rather than all embodiments.

[0022] Figure 1 The schematic diagram of the application scenario of a security interaction method provided by the embodiments of the present application. As Figure 1As shown, the scenario includes user 100 and electronic device 200. User 100 can control electronic device 200 through an input operation. For example, user 100 can input a current query statement into electronic device 200. After obtaining the current query statement, electronic device 200 acquires historical conversation statements. Here, the current query statement includes at least one query sub-statement, and the historical conversation statements include at least one conversation sub-statement. Then, the security of each conversation sub-statement and each query sub-statement is determined, and secure sub-statements are determined from the query sub-statements and conversation sub-statements based on the security. Finally, a prompt is generated according to the secure sub-statements, and the prompt is input into a large language model to obtain a response statement for the current query statement. In this way, a response statement can be generated based on the secure statements in the current query statement and the historical conversation statements, avoiding security issues in the generated subsequent text due to incorrect use of the above information and improving the security of the generated response statement.

[0023] In some embodiments, user 100 can control electronic device 200 by performing an input operation on electronic device 200 through a control device. Among them, the control device and electronic device 200 can be communicatively connected by wired or wireless means. For example, when the control device is a device such as a mouse, keyboard, or stylus, the mouse, keyboard, stylus, etc. and electronic device 200 can be connected by Universal Serial Bus (USB) or through Bluetooth protocol communication. In this way, the user can perform an input operation to control electronic device 200 by means of mouse buttons, keyboard buttons, or direct writing with a stylus. For example, the user can input the current query statement through keyboard buttons.

[0024] In some embodiments, instead of receiving instructions using the above control device, electronic device 200 can receive the control of user 100 through touch or gestures, etc.

[0025] In some embodiments, electronic device 200 can also be controlled in a manner other than through the control device. For example, it can directly receive the voice instructions of the user through a module for obtaining voice instructions configured inside electronic device 200, or receive the voice instructions of the user through a voice control device set outside electronic device 200.

[0026] In some embodiments, the secure interaction method provided in the embodiments of the present application can be executed by the above-mentioned electronic device 200.

[0027] In some embodiments, the security interaction device provided by the embodiments of the present application may be hardware or software. When the security interaction device is hardware, it may be the above-mentioned electronic device 200 with the function of running application programs, including but not limited to smart phones, TVs, tablet computers, smart watches, computers, AI devices, robots, smart vehicles, and so on. When the security interaction device is software, it may be installed in the above-listed electronic devices 200. It may be implemented as multiple software or software modules, or may be implemented as a single software or software module. No specific limitation is made here.

[0028] Figure 2 It is a schematic flowchart of the security interaction method provided by the embodiments of the present application. As Figure 2 shown, the security interaction method may include the following steps.

[0029] S21. Obtain the current query statement and the historical conversation statements.

[0030] Among them, the current query statement is the query statement input by the user to the security interaction device currently. The historical conversation statements include at least one conversation sub-statement, and the current query statement includes at least one query sub-statement.

[0031] In some embodiments, the historical conversation statements are the historical conversation statements within a preset time period, or the historical conversation statements are the historical conversation statements of a preset number of rounds, or the historical conversation statements are all the historical conversation statements of the current session. Among them, the preset time period and the preset number of rounds are preset values. For example, they may be default values, or values set by relevant technicians according to the actual situation. The current session refers to the session that the user is currently conducting.

[0032] In some embodiments, the way to obtain the historical conversation statements may be to call the historical conversation statements from the historical conversation record, or when the historical conversation record is saved locally, call the historical conversation statements from the local. The present application does not make a limitation in this regard.

[0033] S22. Determine the security of each conversation sub-statement and each query sub-statement, and determine the secure sub-statements from the query sub-statements and the conversation sub-statements according to the security.

[0034] First, determine the security of each conversation sub-statement.

[0035] In some embodiments, as Figure 3 shown, the way to determine the security of each conversation sub-statement may include the following steps:

[0036] S221. Traverse each conversation sub-statement and query the security annotation of each conversation sub-statement.

[0037] S222. When the security annotation of the session sub-statement is queried, determine the security of each session sub-statement according to the security annotation.

[0038] S223. When the security annotation of the session sub-statement is not queried, input the session sub-statement into the security detection model to obtain the security of each session sub-statement.

[0039] In the above solution, traverse each session sub-statement and query the security annotation of each session sub-statement. When the security annotation of the session sub-statement is queried, determine the security of each session sub-statement according to the security annotation. When the security annotation of the session sub-statement is not queried, input the session sub-statement into the security detection model to obtain the security of each session sub-statement. In this way, the security of the session sub-statement can be determined according to the pre-stored security annotation or the target large model, so as to determine the security sub-statement in the session sub-statement according to the security of the session sub-statement, and then generate the input of the large language model, that is, the prompt hint, according to the security sub-statement, avoiding the security problem of the generated subsequent text due to the incorrect use of the above information, and improving the security of the generated response statement.

[0040] After that, determine the security of each query sub-statement.

[0041] Specifically, the way to determine the security of each query sub-statement can be to input each of the query sub-statements into the security detection model to obtain the security of each query sub-statement.

[0042] Finally, determine the security sub-statement from the session sub-statement and the query sub-statement according to the security.

[0043] Among them, the security includes security and risk.

[0044] In some embodiments, the way to determine the security sub-statement from the session sub-statement and the query sub-statement according to the security can be to determine the first security sub-statement from the query sub-statement according to the security of the query sub-statement, determine the second security sub-statement from the session sub-statement according to the session sub-statement, and combine the first security sub-statement and the second security sub-statement to obtain the security sub-statement.

[0045] Specifically, determine the query sub-statements with security as safe in the query sub-statements as the first security sub-statements, determine the session sub-statements with security as safe in the session sub-statements as the second security sub-statements, and combine the first security sub-statements and the second security sub-statements to obtain the security sub-statements.

[0046] Exemplarily, when the query statement includes a first query sub-statement, a second query sub-statement, and a third query sub-statement, and the security level of the first query sub-statement is secure, the security level of the second query sub-statement is risky, and the security behavior of the third query sub-statement is secure, the first security sub-statement includes the first query sub-statement and the third query sub-statement. Also, for example, when the session statement includes a first session sub-statement, a second session sub-statement, and a third session sub-statement, and the security level of the first session sub-statement is secure, the security level of the second session sub-statement is secure, and the security behavior of the third session sub-statement is risky, the second security sub-statement includes the first session sub-statement and the second session sub-statement.

[0047] In some embodiments, the way to combine the first security sub-statement and the second security sub-statement to obtain the security sub-statement may be to determine the generation times of the first security sub-statement and the second security sub-statement, and then combine the first security sub-statement and the second security sub-statement in the order of their generation times to obtain the security sub-statement.

[0048] First, determine the generation times of the first security sub-statement and the second security sub-statement.

[0049] Specifically, the generation time of a certain historical session statement can be determined as the generation time of the first security statement in that historical session statement; the generation time of the current query statement is determined as the generation time of the second security sub-statement.

[0050] Exemplarily, the historical session statements include:

[0051] A: Historical query statement 1 (generation time: t - 4).

[0052] B: Historical reply statement 1 (generation time: t - 3).

[0053] A: Historical query statement 2 (generation time: t - 2).

[0054] B: Historical reply statement 2 (generation time: t - 1).

[0055] The current query statement is as follows:

[0056] A: Current query statement (generation time: t).

[0057] In this way, the generation time of the first security statement in historical query statement 1 is t - 4; the generation time of the first security statement in historical reply statement 1 is t - 3; the generation time of the first security statement in historical query statement 2 is t - 2; the generation time of the first security statement in historical reply statement 2 is t - 1; the generation time of the second security sub-statement in the current query statement is t.

[0058] Secondly, combine the first security sub-statement and the second security sub-statement in the order of their generation times to obtain the security sub-statement.

[0059] In the above solution, first, determine the first security sub-statement from the query sub-statements according to the security of the query sub-statements, and determine the second security sub-statement from the session sub-statements according to the session sub-statements. Then, determine the generation times of the first security sub-statement and the second security sub-statement. Finally, combine the first security sub-statement and the second security sub-statement in the order of their generation times to obtain the security sub-statement. In this way, the session sub-statements and query sub-statements with security level of secure can be determined as security sub-statements, avoiding the security problems in the generated subsequent context due to the incorrect use of the above context information, and improving the security of the generated response statements. In addition, the first security sub-statement and the second security sub-statement are combined according to the order of their generation times, providing a timing basis for generating prompts according to the security sub-statements later, avoiding the problem that the generated response statements are not the response statements of the previous query statements due to the unknown timing of the security sub-statements, and improving the accuracy of the generated response statements.

[0060] In some embodiments, as Figure 4 shown, before inputting the session sub-statement into the security detection model, the security interaction method further includes the following steps:

[0061] S1. Obtain at least one round of historical single-round conversation statements and at least one historical previous context statement.

[0062] Wherein, one round of historical single-round conversation statements includes one previous context statement and one subsequent context statement.

[0063] Exemplarily, when the obtained at least one round of historical single-round conversation statements are as follows:

[0064] A: What's the weather like today?

[0065] B: It's sunny today. The highest temperature is 0°C, the lowest temperature is -9°C, and the current temperature is -7°C.

[0066] A: Is it suitable to dry quilts?

[0067] B: Due to the low temperature, it is not recommended to dry quilts.

[0068] In this way, at least one round of historical single-round conversation statements includes two rounds of single-round conversation statements, which are respectively:

[0069] The first round: A: What's the weather like today? (The previous context statement of the first-round single-round conversation statement). B: It's sunny today. The highest temperature is 0°C, the lowest temperature is -9°C, and the current temperature is -7°C. (The subsequent context statement of the first-round single-round conversation statement).

[0070] Round 2: A: Is it suitable for drying quilts? (The previous sentence of the single-round conversation sentence in Round 2). B: Due to the low temperature, it is not recommended to dry quilts. (The following sentence of the single-round conversation sentence in Round 2).

[0071] In some embodiments, the at least one historical previous sentence obtained may include the previous sentence in the historical single-round conversation sentence, or may not include it, and this application does not limit this.

[0072] S2. Perform a splitting process on at least one round of historical single-round conversation sentences to obtain multi-round historical multi-round conversation sentences.

[0073] In some cases, each round of historical single-round conversation sentences is safe, but there is a risk when combined.

[0074] For example, in the following conversation, each round of historical single-round conversation sentences is a safe sentence.

[0075] Round 1: A: Introduce City X. B: City X is a city in XX Country, with an area of XX square kilometers, a longitude of XX, a latitude of XX, and the feature of City X is XX.

[0076] Round 2: A: What about its national flag? B: City X is a city, not a country, so there is no national flag.

[0077] In this way, each round of historical single-round conversation sentences is safe, but there is a potential risk in the previous sentence of Round 2. Therefore, it is necessary to perform a splitting process on the historical single-round conversation sentences to obtain multi-round historical multi-round conversation sentences and clarify the safety of each round of conversation sentences.

[0078] In some embodiments, the method of performing a splitting process on at least one round of historical single-round conversation sentences to obtain multi-round historical multi-round conversation sentences may be to use a pre-trained splitting model to perform a splitting process on at least one round of historical single-round conversation sentences to obtain multi-round historical multi-round conversation sentences; or manually perform a splitting process on at least one round of historical single-round conversation sentences to obtain multi-round historical multi-round conversation sentences.

[0079] In some embodiments, the method of splitting at least one round of historical single-round conversation sentences by means of a pre-trained splitting model to obtain multi-round historical multi-round conversation sentences may be as follows: First, manually extract multiple single-round conversations and perform manual splitting on the multiple single-round conversations to obtain multi-round conversations corresponding to the multiple single-round conversations. Then, construct a training prompt: "Please disassemble the following sentence into two sentences with the same meaning according to the following examples xxx. The input is xxxx", and replace the manually disassembled multiple single-round conversations and their corresponding multi-round conversations into "xxx" after the examples, and replace the historical single-round conversation sentence to be disassembled into "xxxx" after the input. Finally, input the complete training prompt into the large language model to obtain the historical multi-round conversation sentences.

[0080] S3. Perform security annotation on the historical previous text sentences and the historical multi-round conversation sentences to obtain annotation data.

[0081] Among them, the annotation data includes each sentence in the historical previous text sentences and the historical multi-round conversation sentences, and the security annotation corresponding to each sentence. The historical previous text sentences include at least one previous text sub-sentence, and the historical multi-round conversation sentences include multiple multi-round sub-sentences.

[0082] In some embodiments, the method of performing security annotation on the historical previous text sentences and the historical multi-round conversation sentences to obtain annotation data includes performing security annotation on each previous text sub-sentence in the historical previous text sentences and each multi-round sub-sentence in the historical multi-round conversation sentences to obtain annotation data.

[0083] In some embodiments, the method of performing security annotation on the historical previous text sentences and the historical multi-round conversation sentences to obtain annotation data may be manual annotation; it may also be annotation using a pre-trained annotation model. This application does not make any limitations in this regard.

[0084] S4. Fine-tune the initial security detection model using the annotation data to obtain a security detection model.

[0085] In some embodiments, the large language model includes an initial security detection model. The method of fine-tuning the initial security detection model using the annotation data may be to perform supervised fine-tuning (SFT) on the initial security detection model in the large language model using the annotation data under the deep learning framework to obtain a security detection model.

[0086] In the above solution, at least one round of historical single-round conversation sentences and at least one historical context sentence are obtained first. Among them, one round of historical single-round conversation sentences includes one context sentence and one next sentence. After that, the at least one round of historical single-round conversation sentences are split to obtain multi-round historical multi-round conversation sentences, and the historical context sentences and the historical multi-round conversation sentences are safety-annotated to obtain annotated data. The annotated data includes each sentence in the historical context sentences and the historical multi-round conversation sentences, and the safety annotation corresponding to each sentence. Finally, the initial safety detection model is fine-tuned using the annotated data to obtain a safety detection model. In this way, when generating a safety detection model, first, the historical single-round conversation sentences can be split to obtain multi-round historical multi-round conversation sentences, considering the situation that in some cases, each round of historical single-round conversation sentences is safe, but there is a risk when combined, improving the accuracy of the safety detection model. Second, the annotated data for fine-tuning the safety detection model includes each sentence in the historical context sentences and the historical multi-round conversation sentences, and the safety annotation corresponding to each sentence, instead of only using the safety annotation corresponding to the historical multi-round conversation sentences to fine-tune the initial safety detection model, further improving the accuracy of the fine-tuned safety detection model.

[0087] S23. Generate a prompt based on the security sub-sentence and input the prompt into the large language model to obtain a response sentence for the current query sentence.

[0088] Specifically, the method of generating a prompt based on the security sub-sentence can be to generate a prompt according to the prompt generation rule of the large language model and the security sub-sentence. Among them, the prompt generation rules of different large language models may be different, which depends on the designers of the large language models, and this application does not make a limitation in this regard.

[0089] In the above solution, the current query sentence and the historical conversation sentences are obtained first. Among them, the current query sentence includes at least one query sub-sentence, and the historical conversation sentences include at least one conversation sub-sentence. After that, the security of each conversation sub-sentence and each query sub-sentence is determined, and the security sub-sentences are determined from the query sub-sentences and the conversation sub-sentences according to the security. Finally, a prompt is generated based on the security sub-sentences and the prompt is input into the large language model to obtain a response sentence for the current query sentence. In this way, the response sentence can be generated based on the security sentences in the current query sentence and the historical conversation sentences, avoiding the security problem of the generated next sentence due to the incorrect use of the above context information, and improving the security of the generated response sentence.

[0090] In some embodiments, as Figure 5 shown, after step S23, the security interaction method further includes the following steps:

[0091] S24. Input the reply statement into the security detection model for detection to obtain the security of each content segment in the reply statement.

[0092] S25. Filter out the content segments with a security level of risk in the reply statement to obtain the final reply statement.

[0093] Among them, security includes safe and risky. In some embodiments, the method of filtering out the content segments with a security level of risk in the reply statement to obtain the final reply statement may be to filter out the content segments with a security level of risk in the reply statement, obtain the content segments with a security level of safe in the reply statement, and obtain the final reply statement.

[0094] Determine the reply content segments with a security level of safe in the first output result as the final reply statement. In this way, the content segments with a security level of safe can be determined as the final reply statement, avoiding presenting the content segments with risks in the reply statement to the user and improving the security of the conversation.

[0095] In some embodiments, the method of generating the final reply statement may also be to input the reply statement into the security detection model for detection to obtain the security of each content segment in the reply statement; and when the security of any content segment is risky, re-input the prompt into the large language model to obtain a new reply statement for the current query statement. Then, re-input the new reply statement into the security detection model for detection to obtain the security of each content segment in the new reply statement until there are no content segments with a security level of risk in the new reply statement generated by the large language model, or when the number of new reply statements generated by the large language model reaches the threshold, obtain the final reply statement. In this way, when there are content segments with risks in the generated reply statement, a new reply statement can be regenerated, ensuring the security and readability of the generated reply statement.

[0096] In the above solution, after generating the reply statement, the reply statement is also subjected to security detection using the security detection model, and the content segments with a security level of risk in the reply statement are filtered out to obtain the final reply statement, filtering out the insecure information in the reply statement and further improving the security of the generated final reply statement.

[0097] In some embodiments, as Figure 6 shown, after step S23, the secure interaction method further includes:

[0098] S6. Perform security annotation on the current conversation statement according to the security of the current conversation statement and save it.

[0099] Among them, the current conversation sentence includes at least one of the content segments of the query sub-sentence, the conversation sub-sentence, and the reply sentence.

[0100] S7. When a new query sentence is obtained, a new security sub-sentence is determined according to the security annotation of the current conversation sentence and the new query sentence.

[0101] Specifically, the method of determining the new security sub-sentence according to the security annotation of the current conversation sentence and the new query sentence is the same as the method of determining the security sub-sentence in step S22, and will not be elaborated here.

[0102] S8. According to the new security sub-sentence, a new prompt is generated, and the new prompt is input into the large language model to obtain the reply sentence of the new query sentence.

[0103] Specifically, the method of generating a new prompt according to the new security sub-sentence and inputting the new prompt into the large language model to obtain the reply sentence of the new query sentence is the same as the method of generating a prompt according to the security sub-sentence in step S23 and inputting the prompt into the large language model to obtain the reply sentence of the current query sentence, and will not be elaborated here.

[0104] In the above solution, first, the security of the current conversation sentence is annotated and saved according to the security of the current conversation sentence. Then, when a new query sentence is obtained, a new security sub-sentence is determined according to the security annotation of the current conversation sentence and the new query sentence. Finally, a new prompt is generated according to the new security sub-sentence, and the new prompt is input into the large language model to obtain the reply sentence of the new query sentence. In this way, the security of the content segments in the query sub-sentence, the conversation sub-sentence, and the reply sentence can be annotated and saved. When these content segments in the query sub-sentence, the conversation sub-sentence, and the reply sentence are used as historical conversation sentences in the future and it is necessary to determine the security sub-sentence from them, there is no need to input them into the security detection model to obtain the corresponding security, saving computational costs.

[0105] The embodiments of the present application can divide the functional modules of the security interaction device according to the above method examples. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing unit. The above integrated modules can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiments of the present application is illustrative, only a logical function division, and there may be other division methods in actual implementation.

[0106] Such as Figure 7As shown in the figure, it is a schematic structural diagram of a security interaction device provided by an embodiment of the present application. The security interaction device includes an acquisition module 61, a determination module 62, and a generation module 63.

[0107] The acquisition module 61 is used to acquire the current query statement and historical conversation statements; the current query statement includes at least one query sub-statement, and the historical conversation statements include at least one conversation sub-statement; the determination module 62 is used to determine the security of each conversation sub-statement and each query sub-statement, and determine the secure sub-statements from the conversation sub-statements and query sub-statements according to the security; the security includes secure and risky; the generation module 63 is used to generate a prompt according to the secure sub-statements, and input the prompt into a large language model to obtain a reply statement for the current query statement.

[0108] In some embodiments, the determination module 62 is specifically configured to: traverse each conversation sub-statement, and query the security annotation of each conversation sub-statement; when the security annotation of the conversation sub-statement is queried, determine the security of each conversation sub-statement according to the security annotation; when the security annotation of the conversation sub-statement is not queried, input the conversation sub-statement into a security detection model to obtain the security of each conversation sub-statement; input each query sub-statement into the security detection model to obtain the security of each query sub-statement.

[0109] In some embodiments, the determination module 62 is specifically configured to: determine the first secure sub-statement from the query sub-statements according to the security of the query sub-statements; determine the second secure sub-statement from the conversation sub-statements according to the conversation sub-statements; combine the first secure sub-statement and the second secure sub-statement to obtain the secure sub-statement.

[0110] In some embodiments, the determination module 62 is specifically configured to: determine the generation time of the first secure sub-statement and the second secure sub-statement; combine the first secure sub-statement and the second secure sub-statement in the order of the generation time to obtain the secure sub-statement.

[0111] In some embodiments, the generation module 63 is further configured to acquire at least one round of historical single-round conversation statements and at least one historical previous statement; one round of historical single-round conversation statements includes one previous statement and one next statement; perform a splitting process on at least one round of historical single-round conversation statements to obtain multi-round historical multi-round conversation statements; perform security annotation on the historical previous statements and historical multi-round conversation statements to obtain annotation data; the annotation data includes each statement in the historical previous statements and historical multi-round conversation statements, and the security annotation corresponding to each statement; use the annotation data to fine-tune the initial security detection model to obtain the security detection model.

[0112] In some embodiments, the determination module 62 is further configured to input the reply statement into a security detection model for detection to obtain the security of each content segment in the reply statement; filter out the content segments with the security of risk in the reply statement to obtain the final reply statement.

[0113] In some embodiments, the determination module 62 is further configured to perform security annotation and save the current conversation statement according to the security of the current conversation statement; the current conversation statement includes at least one of a conversation sub-statement, a query sub-statement, and a content segment of a reply statement; the determination module 62 is further configured to, when a new query statement is obtained, determine a new security sub-statement according to the security annotation of the current conversation statement and the new query statement; the generation module 63 is further configured to generate a new prompt according to the new security sub-statement and input the new prompt into the large language model to obtain a reply statement for the new query statement.

[0114] The security interaction device provided in this embodiment can execute the security interaction method provided in the above method embodiment, and its implementation principle and technical effect are similar to those of the above method, which will not be elaborated here.

[0115] Figure 8 An electronic device shown according to an exemplary embodiment. The electronic device may include a processor 802, and the processor 802 is configured to execute application program code to implement the security interaction method in the present application.

[0116] The processor 802 may be a central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the solution of the present application.

[0117] Such as Figure 8 shown, the electronic device may further include a memory 803. Among them, the memory 803 is used to store the application program code for executing the solution of the present application and is controlled by the processor 802 to execute.

[0118] The memory 803 can be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or it can also be an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but not limited thereto. The memory 803 can exist independently and be connected to the processor 802 through the bus 804. The memory 803 can also be integrated with the processor 802.

[0119] As Figure 8 shown, the electronic device can also include a communication interface 801. Among them, the communication interface 801, the processor 802, and the memory 803 can be coupled to each other. For example, they can be coupled to each other through the bus 804. The communication interface 801 is used for information interaction with other devices. For example, it supports information interaction between the electronic device and other devices.

[0120] It should be noted that Figure 8 the device structure shown in Figure 8 does not constitute a limitation on the electronic device. In addition to the

[0121] components shown, the electronic device can include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements. And the electronic device provided in this embodiment can execute the security interaction method provided in the above method embodiment. The implementation principle and technical effect are similar to those of the above method and will not be elaborated here.

[0122] Among them, the computer-readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.

[0123] An embodiment of the present application provides a computer program product. The computer program product stores a computer program. When the computer program is executed by a processor, it implements each process of the secure interaction method in the above method embodiment and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0124] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.

[0125] In the present application, the processor can be a central processing unit (CPU), or can also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0126] In the present application, the memory may include non-permanent memory in a computer-readable medium, random access memory (RAM), and / or non-volatile memory in the form of, for example, read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0127] In this application, computer-readable media include both permanent and non-permanent, removable and non-removable storage media. The storage media can implement information storage by any method or technology, and the information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media do not include transitory media such as modulated data and carrier waves.

[0128] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the existence of additional identical elements in the process, method, article or device comprising the said element.

[0129] The above are only specific embodiments of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application will not be limited to these embodiments described herein, but rather will conform to the broadest scope consistent with the principles and novel features disclosed herein.

Claims

1. A secure interaction method, characterized in that, Including: Obtain the current query statement and historical conversation statements; the current query statement includes at least one query sub-statement, and the historical conversation statements include at least one conversation sub-statement; Determine the security of each of the conversation sub-statements and each of the query sub-statements, and determine secure sub-statements from the query sub-statements and the conversation sub-statements according to the security; the security includes secure and risky; Generate a prompt according to the secure sub-statements, and input the prompt into a large language model to obtain a response statement for the current query statement.

2. The security interaction method according to claim 1, characterized in that Determining the security of each of the conversation sub-statements includes: Traverse each of the conversation sub-statements and query the security annotation of each of the conversation sub-statements; When the security annotation of the conversation sub-statement is queried, determine the security of each of the conversation sub-statements according to the security annotation; When the security annotation of the conversation sub-statement is not queried, input the conversation sub-statement into a security detection model to obtain the security of each conversation sub-statement; Determining the security of each of the query sub-statements includes: Input each of the query sub-statements into a security detection model to obtain the security of each query sub-statement.

3. The security interaction method according to claim 1, wherein The determining secure sub-statements from the query sub-statements and the conversation sub-statements according to the security includes: Determine the first secure sub-statement from the query sub-statements according to the security of the query sub-statements; Determine the second secure sub-statement from the conversation sub-statements according to the conversation sub-statements; Combine the first secure sub-statement and the second secure sub-statement to obtain a secure sub-statement.

4. The security interaction method according to claim 3, wherein The combining the first secure sub-statement and the second secure sub-statement to obtain a secure sub-statement includes: determining the generation time of the first secure sub-statement and the second secure sub-statement; Combine the first secure sub-statement and the second secure sub-statement in the order of the generation time to obtain a secure sub-statement.

5. The secure interaction method according to claim 2, wherein The training process of the security detection model includes: Obtain at least one round of historical single-round conversation statements and at least one historical previous statement; one round of historical single-round conversation statements includes one previous statement and one next statement; Perform a splitting process on the at least one round of historical single-round conversation statements to obtain multiple rounds of historical multi-round conversation statements; Perform security annotation on the historical previous statements and the historical multi-round conversation statements to obtain annotation data; the annotation data includes each statement in the historical previous statements and the historical multi-round conversation statements, and the security annotation corresponding to each statement; Use the annotation data to fine-tune an initial security detection model to obtain the security detection model.

6. The security interaction method according to claim 1, characterized in that After obtaining the response statement for the current query statement, the method further includes: Input the response statement into a security detection model for detection to obtain the security of each content segment in the response statement; Filter out the content segments with risky security in the content segments of the response statement to obtain a final response statement.

7. The security interaction method according to any one of claims 1-6, characterized in that After obtaining the response statement for the current query statement, the method further includes: Perform security annotation and save the current conversation sentence according to the security of the current conversation sentence; the current conversation sentence includes at least one of the conversation sub-sentences, the query sub-sentences, and the content segments of the reply sentences; When a new query sentence is obtained, determine a new security sub-sentence according to the security annotation of the current conversation sentence and the new query sentence; Generate a new prompt according to the new security sub-sentence, and input the new prompt into the large language model to obtain the reply sentence of the new query sentence.

8. A secure interaction device, characterized in that, It includes: An acquisition module for acquiring a current query sentence and a historical conversation sentence; the current query sentence includes at least one query sub-sentence, and the historical conversation sentence includes at least one conversation sub-sentence; A determination module for determining the security of each of the conversation sub-sentences and each of the query sub-sentences, and determining security sub-sentences from the query sub-sentences and the conversation sub-sentences according to the security; the security includes security and risk; A generation module for generating a prompt according to the security sub-sentence, and inputting the prompt into the large language model to obtain the reply sentence of the current query sentence.

9. An electronic device, characterized in that, It includes: A processor, a memory, and a computer program stored on the memory and executable on the processor, where the computer program, when executed by the processor, implements the security interaction method according to any one of claims 1 to 5.

10. A computer-readable storage medium, characterized in that, It includes: A computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the security interaction method according to any one of claims 1 to 5 is implemented.