Session implementation method and device based on artificial intelligence, equipment and medium
By preprocessing and sentiment analysis of the session information entered by users in the intelligent conversation system, generating response results and pushing them through the SSE protocol, the problem of insufficient response efficiency and quality of the existing intelligent conversation system is solved, and more efficient and flexible users are achieved Interaction.
Patent Information
- Application Number
- CN202411334179.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-02-18
AI Technical Summary
The existing intelligent conversation system has shortcomings in response efficiency and response quality, and it is difficult to effectively meet the complex interaction needs of users.
By receiving the session information input by the user, preprocessing is performed, and sending a connection establishment request to the server. The server performs sentiment analysis of the preprocessed session information, generates response results, and pushes it to the client in segments through the SSE protocol.
It improves the response efficiency and response quality of the intelligent conversation system, can flexibly handle user needs, adapt to complex interactive scenarios, simplify system development and maintenance, and reduce resource consumption.
Smart Images

Figure CN119484486A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an artificial intelligence-based conversation implementation method, device, equipment and medium. Background Art
[0002] As an important application direction in the field of artificial intelligence, intelligent conversational systems aim to achieve natural language interaction between users and systems through real-time communication technology. Existing intelligent conversational systems usually rely on WebSocket technology for real-time communication and combine predefined rules or templates to generate responses. However, these methods have low response efficiency and quality in practical applications. Summary of the invention
[0003] The embodiment of the present invention provides a conversation implementation method based on artificial intelligence, which can improve the response efficiency and response quality of an intelligent conversation system.
[0004] In a first aspect, an embodiment of the present invention provides a method for realizing a conversation based on artificial intelligence, comprising:
[0005] Receiving session information input by a user, and preprocessing the session information;
[0006] Sending a connection establishment request to a server according to the preprocessed session information, so that the server responds to the connection establishment request, performing sentiment analysis on the preprocessed session information to obtain a sentiment analysis result, and generating a response result of the session information according to the sentiment analysis result;
[0007] Receive the response result pushed by the server in segments through the SSE protocol, and display the response result to the user.
[0008] Furthermore, the receiving of session information input by the user and preprocessing the session information includes:
[0009] receiving session information input by a user, and assigning a session ID to the session information; wherein the session information includes at least one of text information, voice information, and image information;
[0010] The user's historical session record is obtained, the session information is converted into a session object of a corresponding data structure according to the session type, and the session object is added to the historical session record.
[0011] Further, sending a connection establishment request to the server according to the preprocessed session information includes:
[0012] Obtaining a session ID and a timestamp of the session information;
[0013] The session ID and the timestamp are used as request parameters to send a connection establishment request to the server.
[0014] Furthermore, after the server responds to the connection establishment request, the process further includes:
[0015] Obtaining a session ID of the preprocessed session information, and obtaining session context information from the historical session record according to the session ID;
[0016] The preprocessed session information is parsed to obtain a parsing result.
[0017] Further, performing sentiment analysis on the preprocessed session information to obtain a sentiment analysis result includes:
[0018] Perform feature extraction based on the preprocessed session information to obtain feature prompt words;
[0019] The trained sentiment classification model is used to analyze the characteristic prompt words to obtain sentiment analysis results.
[0020] In a second aspect, an embodiment of the present invention provides a conversation implementation device based on artificial intelligence, including:
[0021] A session information preprocessing module, used to receive session information input by a user and preprocess the session information;
[0022] A session information response module, used to send a connection establishment request to a server according to the preprocessed session information, so that the server responds to the connection establishment request, perform sentiment analysis on the preprocessed session information to obtain a sentiment analysis result, and generate a response result of the session information according to the sentiment analysis result;
[0023] The session information display module is used to receive the response result pushed by the server in segments through the SSE protocol, and display the response result to the user.
[0024] Furthermore, the session information preprocessing module includes:
[0025] A session information receiving unit, used to receive session information input by a user and assign a session ID to the session information; wherein the session information includes at least one of text information, voice information and image information;
[0026] The session information preprocessing unit is used to obtain the user's historical session record, convert the session information into a session object of a corresponding data structure according to the session type, and add the session object to the historical session record.
[0027] Furthermore, the session information response module is also used to:
[0028] Obtaining a session ID and a timestamp of the session information;
[0029] The session ID and the timestamp are used as request parameters to send a connection establishment request to the server.
[0030] In a third aspect, an embodiment of the present invention provides an electronic device, including:
[0031] Memory for storing computer programs;
[0032] A processor, configured to execute the computer program;
[0033] Wherein, when the processor executes the computer program, it implements the artificial intelligence-based conversation implementation method described in any one of the first aspects above.
[0034] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed, the artificial intelligence-based conversation implementation method described in any one of the first aspects above is implemented.
[0035] Compared with the prior art, an artificial intelligence-based conversation implementation method provided by an embodiment of the present invention has the following beneficial effects: by receiving conversation information input by a user and preprocessing the conversation information; sending a connection establishment request to a server according to the preprocessed conversation information so that the server responds to the connection establishment request, performing sentiment analysis on the preprocessed conversation information to obtain a sentiment analysis result, and generating a response result of the conversation information according to the sentiment analysis result; receiving the response result pushed by the server in segments through the SSE protocol, and displaying the response result to the user; being able to flexibly respond to and process user needs with low resource consumption, simplifying the development and maintenance process of the conversation system, better adapting to complex interaction scenarios, and improving the simplicity and response quality of the intelligent conversation system. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical features of the embodiments of the present invention, the drawings required for use in the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0037] Figure 1 It is a flowchart of an embodiment of a conversation realization method based on artificial intelligence provided by the present invention;
[0038] Figure 2It is a structural schematic diagram of an embodiment of a conversation realization device based on artificial intelligence provided by the present invention;
[0039] Figure 3 It is a structural schematic diagram of an embodiment of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0041] In a first aspect, an embodiment of the present invention provides a method for implementing a conversation based on artificial intelligence, see Figure 1 , which is a flow chart of an embodiment of an artificial intelligence-based conversation implementation method provided by the present invention.
[0042] like Figure 1 As shown, the method comprises the following steps:
[0043] S1: receiving session information input by a user and preprocessing the session information;
[0044] S2: Sending a connection establishment request to the server according to the preprocessed session information, so that the server responds to the connection establishment request, performing sentiment analysis on the preprocessed session information to obtain a sentiment analysis result, and generating a response result of the session information according to the sentiment analysis result;
[0045] S3: Receive the response result pushed by the server in segments through the SSE protocol, and display the response result to the user.
[0046] In the conversation system of the present invention, a conversation is an interactive process between a user and a system. A user initiates a conversation message, and the system responds to the conversation message, generates a response result and feeds it back to the user. The conversation system can save the context information of the conversation so that the information can be used in subsequent message processing to provide a more accurate response. A conversation group is a collection of multiple related conversations, which helps the system to uniformly manage multiple related conversations. Conversations in the same conversation group may revolve around the same topic, task or user. There is a certain correlation between conversations in the same conversation group, but the conversations remain independent of each other. Multiple response results can be generated for the same conversation according to the user's requirements, and these response results can be presented to the user from different angles and in different forms. In the conversation system of the present invention, a user can participate in multiple conversation groups at the same time, each conversation group contains multiple conversations, and each conversation and the response result can also have a one-to-many relationship, thereby realizing flexible response and processing to user needs, so that the system can better adapt to complex interaction scenarios.
[0047] In the specific implementation, the front end adopts the front-end FetchEventSource client. The client first receives the session information input by the user and preprocesses the session information. According to the preprocessed session information, a connection establishment request is sent to the server so that the server responds to the connection establishment request. When the connection is successfully established, the server performs sentiment analysis on the preprocessed session information and generates a response result of the session information according to the sentiment analysis result. The server pushes the response result to the client in segments through the SSE protocol. The client automatically renders the user display page of the front end according to the data structure through the MVVM framework and displays the response result to the user.
[0048] In summary, the present invention receives session information input by a user and preprocesses the session information; sends a connection establishment request to a server according to the preprocessed session information so that the server responds to the connection establishment request, performs sentiment analysis on the preprocessed session information to obtain a sentiment analysis result, and generates a response result of the session information according to the sentiment analysis result; receives the response result pushed by the server in segments through the SSE protocol, and displays the response result to the user; can flexibly respond to and process user needs, with low resource consumption, simplifies the development and maintenance process of the session system, better adapts to complex interaction scenarios, and improves the simplicity and response quality of the intelligent session system.
[0049] In an optional implementation manner, the receiving session information input by the user and preprocessing the session information includes:
[0050] receiving session information input by a user, and assigning a session ID to the session information; wherein the session information includes at least one of text information, voice information, and image information;
[0051] The user's historical session record is obtained, the session information is converted into a session object of a corresponding data structure according to the session type, and the session object is added to the historical session record.
[0052] Specifically, the front-end user interface receives session information input by the user. The session information may be text information directly input by the user, voice information input through a microphone or other device, or uploaded image information. It supports multimodal input and can improve the accuracy and diversity of responses.
[0053] In order to distinguish and manage different sessions, a unique session ID is assigned to each received session information, and the session information is preprocessed, and the user's historical session record is loaded. The historical session record can be a data structure in a database or memory, which is used to store and manage all user session information. The received session information is converted into a session object of a corresponding data structure according to the session type. When the session information belongs to an existing session group, a new message object is created and stored in the position corresponding to the session group in the historical session record. When the session information is a newly created session and does not belong to an existing session group, a new session object is created as a new session group and stored in the historical session record.
[0054] In an optional implementation, sending a connection establishment request to the server according to the preprocessed session information includes:
[0055] Obtaining a session ID and a timestamp of the session information;
[0056] The session ID and the timestamp are used as request parameters to send a connection establishment request to the server.
[0057] Specifically, when a user starts a new session or continues an existing session, the client needs to establish a connection with the server. The front-end FetchEventSource client sends a request to the back-end API interface to establish a connection. In order to establish this connection, the client needs to obtain the session ID and timestamp of the session information. The timestamp records the specific time when the session occurs. When establishing a connection request, the current unique timestamp is used as the key of the hash table, and the timestamp is attached to the request stream object, which provides a time context for the request and helps to track the initiation time of the request in subsequent processing.
[0058] The session ID and timestamp of the session information are used as request parameters to send a connection establishment request to the server. The connection establishment request can be an HTTP request, which may be GET, POST, or other methods, depending on the design of the server. The request parameters can be passed through the query string of the URL or through the request body. It supports HTTP / 1.1 features and can implement cross-domain requests through CORS.
[0059] It should be noted that the session implementation method of the present invention supports simultaneous processing of multiple sessions. When the front end receives the response results of multiple sessions pushed by the server, the response result corresponding to each session information is found in the hash table through the timestamp. The intermediate auxiliary object is stored in the hash table. The auxiliary object has a reference to the target session information and has its own internal buffer. When the returned data is received, the response result is directly stored in the auxiliary object according to the timestamp key. When the auxiliary object is generated, it will continuously check its own buffer at a set frequency, and input a certain length of response result into the auxiliary object of the target session information according to the reference, so as to achieve the effect of controlling the rate, and destroy itself when the end mark is received. Each target session information has its own data stream, and the corresponding auxiliary object is responsible for processing the data stream. The processing process does not require the participation of the server, thereby reducing the server load and improving the response speed.
[0060] In an optional implementation manner, after the server responds to the connection establishment request, the method further includes:
[0061] Obtaining a session ID of the preprocessed session information, and obtaining session context information from the historical session record according to the session ID;
[0062] The preprocessed session information is parsed to obtain a parsing result.
[0063] Specifically, after receiving the connection establishment request, the back-end API interface responds to the connection establishment request. When the response is successful, the connection between the client and the server is established. The back-end obtains the session ID of the pre-processed session information, and obtains the session context information of the session information from the historical session record according to the session ID. The session context information is stored in the historical session record corresponding to the user.
[0064] The backend parses the preprocessed session information through the dialogue management module to obtain the parsing results. The parsing process can convert the original session information into structured data that can be understood and processed by the program, which is convenient for subsequent session processing or response generation.
[0065] It can be understood that the present invention adopts the FetchEventSource client and supports automatic reconnection. When the connection is interrupted, the front-end FetchEventSource client will automatically try to reconnect without the need for additional code to process the connection status, thereby improving the stability of the session system.
[0066] In an optional implementation, performing sentiment analysis on the preprocessed session information to obtain a sentiment analysis result includes:
[0067] Perform feature extraction based on the preprocessed session information to obtain feature prompt words;
[0068] The trained sentiment classification model is used to analyze the characteristic prompt words to obtain sentiment analysis results.
[0069] Specifically, after the back-end dialogue management module parses and obtains the parsing result, it calls the sentiment analysis module to perform sentiment analysis on the preprocessed conversation information. Sentiment analysis is to extract text features in the conversation information through a large model, generate feature prompt words, and analyze the feature prompt words to obtain sentiment analysis results, and pass the sentiment analysis results to the generative artificial intelligence model module on the back-end.
[0070] In a second aspect, an embodiment of the present invention provides a conversation implementation device based on artificial intelligence, see Figure 2 , which is a structural diagram of an embodiment of an artificial intelligence-based conversation implementation device provided by the present invention.
[0071] like Figure 2 As shown, the device comprises:
[0072] The session information preprocessing module 21 is used to receive the session information input by the user and preprocess the session information;
[0073] The session information response module 22 is used to send a connection establishment request to the server according to the preprocessed session information, so that the server responds to the connection establishment request, perform sentiment analysis on the preprocessed session information to obtain a sentiment analysis result, and generate a response result of the session information according to the sentiment analysis result;
[0074] The response result display module 23 is used to receive the response result pushed by the server in segments through the SSE protocol, and display the response result to the user.
[0075] In an optional implementation, the session information preprocessing module 21 includes:
[0076] A session information receiving unit, used to receive session information input by a user and assign a session ID to the session information; wherein the session information includes at least one of text information, voice information and image information;
[0077] The session information preprocessing unit is used to obtain the user's historical session record, convert the session information into a session object of a corresponding data structure according to the session type, and add the session object to the historical session record.
[0078] In an optional implementation, the session information response module 22 is further configured to:
[0079] Obtaining a session ID and a timestamp of the session information;
[0080] The session ID and the timestamp are used as request parameters to send a connection establishment request to the server.
[0081] In an optional implementation, the session information response module 22 is further configured to:
[0082] Obtaining a session ID of the preprocessed session information, and obtaining session context information from the historical session record according to the session ID;
[0083] The preprocessed session information is parsed to obtain a parsing result.
[0084] In an optional implementation, the session information response module 22 is further configured to:
[0085] Perform feature extraction based on the preprocessed session information to obtain feature prompt words;
[0086] The trained sentiment classification model is used to analyze the characteristic prompt words to obtain sentiment analysis results.
[0087] In a third aspect, an embodiment of the present invention provides an electronic device, see Figure 3 , which is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0088] like Figure 3 As shown, the device includes:
[0089] A memory 31, used for storing computer programs;
[0090] A processor 32, configured to execute the computer program;
[0091] Wherein, when the processor 32 executes the computer program, it implements the artificial intelligence-based conversation implementation method as described in any of the above embodiments.
[0092] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 31 and executed by the processor 32 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the electronic device.
[0093] The processor 32 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0094] The memory 31 can be used to store the computer program and / or module, and the processor 32 realizes various functions of the electronic device by running or executing the computer program and / or module stored in the memory 31, and calling the data stored in the memory 31. The memory 31 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 31 can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0095] It should be noted that the above electronic device includes, but is not limited to, a processor and a memory. Those skilled in the art can understand that Figure 3 The structural diagram is merely an example of the electronic device described above and does not constitute a limitation on the electronic device, and may include more components than shown in the figure, or a combination of certain components, or different components.
[0096] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed, the artificial intelligence-based conversation implementation method described in any of the above embodiments is implemented.
[0097] It should be understood that the present invention implements all or part of the processes in the above-mentioned artificial intelligence-based conversation implementation method, and can also be completed by instructing related hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, it can implement the steps of the above-mentioned artificial intelligence-based conversation implementation method. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium, etc.
[0098] The above description is only a preferred embodiment of the present invention, but the protection scope of the present invention is not limited thereto. It should be pointed out that for those skilled in the art, several equivalent obvious variations and / or equivalent substitutions can be made without departing from the technical principles of the present invention. These obvious variations and / or equivalent substitutions should also be regarded as the protection scope of the present invention.
Claims
1. A conversation implementation method based on artificial intelligence, characterized in that: include: Receiving session information input by a user, and preprocessing the session information; Sending a connection establishment request to a server according to the preprocessed session information, so that the server responds to the connection establishment request, performing sentiment analysis on the preprocessed session information to obtain a sentiment analysis result, and generating a response result of the session information according to the sentiment analysis result; Receive the response result pushed by the server in segments through the SSE protocol, and display the response result to the user.
2. The artificial intelligence-based conversation implementation method according to claim 1, characterized in that: The receiving session information input by the user and preprocessing the session information includes: receiving session information input by a user, and assigning a session ID to the session information; wherein the session information includes at least one of text information, voice information, and image information; The user's historical session record is obtained, the session information is converted into a session object of a corresponding data structure according to the session type, and the session object is added to the historical session record.
3. The artificial intelligence-based conversation implementation method according to claim 2, characterized in that: The sending a connection establishment request to the server according to the preprocessed session information includes: Obtaining a session ID and a timestamp of the session information; The session ID and the timestamp are used as request parameters to send a connection establishment request to the server.
4. The artificial intelligence-based conversation implementation method according to claim 2, characterized in that: After the server responds to the connection establishment request, the method further includes: Obtaining a session ID of the preprocessed session information, and obtaining session context information from the historical session record according to the session ID; The preprocessed session information is parsed to obtain a parsing result.
5. The artificial intelligence-based conversation implementation method according to claim 1, characterized in that: The performing sentiment analysis on the preprocessed session information to obtain a sentiment analysis result includes: Perform feature extraction based on the preprocessed session information to obtain feature prompt words; The trained sentiment classification model is used to analyze the characteristic prompt words to obtain sentiment analysis results.
6. A conversation realization device based on artificial intelligence, characterized in that: include: A session information preprocessing module, used to receive session information input by a user and preprocess the session information; A session information response module, used to send a connection establishment request to a server according to the preprocessed session information, so that the server responds to the connection establishment request, perform sentiment analysis on the preprocessed session information to obtain a sentiment analysis result, and generate a response result of the session information according to the sentiment analysis result; The response result display module is used to receive the response result pushed by the server in segments through the SSE protocol and display the response result to the user.
7. The artificial intelligence-based conversation implementation device according to claim 6, characterized in that: The session information preprocessing module includes: A session information receiving unit, used to receive session information input by a user and assign a session ID to the session information; wherein the session information includes at least one of text information, voice information and image information; The session information preprocessing unit is used to obtain the user's historical session record, convert the session information into a session object of a corresponding data structure according to the session type, and add the session object to the historical session record.
8. The artificial intelligence-based conversation implementation device according to claim 6, characterized in that: The session information response module is also used for: Obtaining a session ID and a timestamp of the session information; The session ID and the timestamp are used as request parameters to send a connection establishment request to the server.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program; Wherein, when the processor executes the computer program, the artificial intelligence-based conversation implementation method as described in any one of claims 1 to 5 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the artificial intelligence-based conversation implementation method according to any one of claims 1 to 5 is implemented.
Citation Information
Cited By
Request scheduling method and device
CN120547240A