A chat intelligent question and answer streaming typing output method and system of pure front-end implementation
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHONGDIAN DATA IND CO LTD
- Filing Date
- 2023-12-27
- Publication Date
- 2026-06-26
AI Technical Summary
In intelligent question-answering scenarios, existing technologies require server-side cooperation for streaming typing output, which is costly to develop and complex to control, failing to meet the needs for easy control and low cost.
This paper describes a Chat intelligent question-and-answer streaming typing output method implemented entirely on the front end. It defines a streaming typing output class and sets dependency properties and control methods, including content properties, timer properties, callback function properties, and configuration parameter properties, to control the streaming typing output.
It improves webpage performance, reduces development costs and complexity without relying on server-side interfaces, is suitable for multiple scenarios, provides precise control over streaming typing effects, and is applicable to intelligent question answering and webpage UI interaction.
Smart Images

Figure CN117743552B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of typing output technology, and in particular to a chat intelligent question-and-answer streaming typing output method and system implemented purely on the front end. Background Technology
[0002] In the field of web front-end development, the following technical solutions are currently mainly used for streaming typing output effects: Solution 1 is a streaming typing output effect implemented based on CSS and HTML; Solution 2 is implemented based on Javascript, HTML, and CSS, using manipulation of DOM elements to achieve streaming typing output effects; Solution 3 is implemented natively based on Javascript, eventSource, and fetch; Solution 4 is implemented based on the third-party plugin @microsoft / fetch-event-source combined with Javascript and the React / Vue front-end UI framework, achieving a streaming typing output effect with the same implementation principle as Solution 3.
[0003] In practical applications, both Schemes 1 and 2 are purely front-end implementations, requiring no server-side streaming interface. They use a standard interface to retrieve the content to be streamed all at once. When the content needs to be displayed in a streaming manner, a timer is used to periodically accumulate and extract the text, then directly manipulates the page's DOM elements to assign the extracted text, thus achieving a streaming typing effect. However, Scheme 1 lacks control over the streaming typing output effect and has limited applicability. Scheme 2, by manipulating the page DOM, achieves streaming typing on the webpage, but frequent DOM manipulation consumes significant webpage performance, and its control over the output effect is too limited, making it unsuitable for intelligent question-and-answer scenarios. Schemes 3 and 4 require a server-side streaming interface. The front-end retrieves content in real-time through this interface and displays it on the page. In intelligent question-and-answer scenarios, Schemes 3 and 4 have higher overall development costs and more complex implementation processes, requiring a server-side streaming interface.
[0004] Therefore, how to provide an intelligent question-and-answer streaming typing output method that is easy to control, applicable to diverse scenarios, and low-cost has become an urgent technical problem to be solved. Summary of the Invention
[0005] In view of this, in order to overcome the shortcomings of the prior art, the present invention aims to provide a chat intelligent question-and-answer streaming typing output method and system that is purely front-end implemented.
[0006] According to a first aspect of the present invention, a chat intelligent question-and-answer streaming typing output method implemented purely in the front end is provided, comprising:
[0007] Define a streaming typing output method class, and set dependency properties and control methods in the defined streaming typing output method class;
[0008] The default constructor of the streaming typing output method class is used to receive externally passed parameters to update the dependent properties of the streaming typing output method class;
[0009] The execution of the streaming typing output method is controlled by the control methods set in the streaming typing output method class and the updated dependency properties.
[0010] Preferably, in the Chat intelligent question-answering streaming typing output method implemented purely in the front end of the present invention, a streaming typing output method class is defined, and dependency properties and control methods are set in the defined streaming typing output method class, including: using TypeScript to define a Class method class to implement the streaming typing output method, and setting corresponding dependency properties and control methods in the defined Class method class.
[0011] In the Chat intelligent question-and-answer streaming typing output method implemented purely on the front end of this invention, the dependent attributes include the content attributes of the streaming typing output, the timer attributes that control the streaming output, the callback function attributes that need to be executed after the content output is completed, the hook function attributes after each frame of text output, and the configuration parameter attributes that control the streaming typing output effect.
[0012] In the Chat intelligent question-and-answer streaming typing output method implemented purely in the front end of this invention, the configuration parameter attributes that control the streaming typing output effect include: the output content attribute of each frame, the attribute of controlling whether to stop streaming output, and the speed attribute of streaming typing output.
[0013] In the Chat intelligent question-and-answer streaming typing output method implemented purely in the front end of this invention, the control methods include: defining a class constructor for the method class, a method to start streaming typing output, a method to stop streaming typing output, a method to clear the control streaming output timer, and an initialization method.
[0014] In the pure front-end implementation of the Chat intelligent question-answering streaming typing output method of this invention, the default constructor of the streaming typing output method class is used to receive externally passed parameter values and update the dependent properties of the streaming typing output method class, including:
[0015] Receive the configuration parameters for the control stream typing output effect, and assign values to the configuration parameter property of the control stream typing output effect of the stream typing output method class using the received configuration parameters.
[0016] Receive the content parameters of the streaming typing output, and use the received content parameters of the streaming typing output to assign values to the streaming typing output content property of the streaming typing output method class.
[0017] The callback function that needs to be executed after the received content is output is used to assign a value to the callback function property of the streaming typing output method class after the content output is completed;
[0018] The hook function that receives each frame of text output is used to assign values to the hook function property of each frame of text output in the streaming typing output method class.
[0019] Set the value of the timer property that controls the streaming output to 0, and execute the initialization method of the streaming typing output method class.
[0020] In the Chat intelligent question-answering streaming typing output method implemented purely in the front end of this invention, the execution of the streaming typing output method is controlled according to the control methods set in the streaming typing output method class and the updated dependency attributes, including:
[0021] Get the value of the content attribute of the streaming typing output method class. When the value of the content attribute of the streaming typing output method class is 0, execute the callback function of the action to be executed after the content output of the streaming typing output method class is completed, and end the method of starting streaming typing output.
[0022] When the value of the content attribute of the obtained streaming typing output is not 0, a timer execution count record variable with an initial value of 0 is defined to record the execution count of the timer controlling the streaming output. The timer controlling the streaming output is executed at the speed of the streaming typing output.
[0023] In the Chat intelligent question-answering streaming typing output method implemented purely in the front end of this invention, when the value of the obtained streaming typing output content attribute is not 0, a timer execution count record variable with an initial value of 0 is defined to record the execution count of the timer controlling the streaming output. The timer controlling the streaming output is executed at intervals based on the speed of the streaming typing output, including:
[0024] Each time the timer for controlling the stream output is executed, the value of the timer execution count record variable is incremented by 1. Then, it is determined whether the value of the timer execution count record variable after incrementing is equal to the value of the content attribute of the stream typing output.
[0025] When the value of the timer execution count record variable is equal to the value of the content attribute of the streaming type output after the increment is 1, the value of the timer execution count record variable is reset to 0, the method of clearing the control streaming output timer is called to clear the control streaming output timer, and the method of starting streaming type output ends.
[0026] Get the record value of the timer execution count record variable, extract the text from the first position to the corresponding number of positions in the stream typing output, and use the extracted text as the output content of each frame;
[0027] The output content of each frame, composed of the extracted text, is used as the input parameter to execute the hook function after the output of each frame of text.
[0028] In the Chat intelligent question-answering streaming typing output method implemented purely in the front end of this invention, the execution of the streaming typing output method is controlled according to the control methods set in the streaming typing output method class and the updated dependency attributes, including:
[0029] Each time the timer for controlling the streaming output is executed, the value of the "Control whether to stop streaming output" property is obtained. When the value of the "Control whether to stop streaming output" property is true, the method to clear the timer for controlling the streaming output is called to clear the timer for controlling the streaming output, and the method to start streaming typing output ends.
[0030] Get the record value of the timer execution count record variable, extract the text from the first position to the corresponding number of positions in the stream typing output, and use the extracted text as the output content of each frame;
[0031] The output content of each frame, composed of the extracted text, is used as the input parameter to execute the hook function after the output of each frame of text.
[0032] According to a second aspect of the present invention, a chat intelligent question-answering streaming typing output system with a pure front-end implementation is provided. The system includes a streaming typing output server, which defines streaming typing output method classes, sets dependency attributes and control methods within these classes, uses the default constructor of the streaming typing output method classes to receive externally passed parameters to update the dependency attributes of the streaming typing output method classes, and controls the execution of the streaming typing output methods according to the control methods set in the streaming typing output method classes and the updated dependency attributes.
[0033] According to a third aspect of the present invention, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect of the present invention.
[0034] The pure front-end implementation of the Chat intelligent question-and-answer streaming typing output method and system of this invention can improve webpage performance without direct DOM manipulation; it does not require server-side cooperation to provide a streaming output interface, making it suitable for both webpage UI interactive effects and streaming typing effects scenarios, as well as intelligent question-and-answer scenarios where no server-side streaming interface is provided. The front-end can quickly simulate and implement streaming typing effects, providing users with a better interactive experience and reducing development costs, development cycle, and implementation complexity; it allows for precise control of the streaming typing effect, providing control over the start, stop, typing speed, and output completion callback execution of the streaming typing effect; it has a wide range of applications, including intelligent question-and-answer scenarios or webpage UI interactive effects and streaming typing effects scenarios, and is suitable for native JS and React / Vue projects with streaming typing output effects. Attached Figure Description
[0035] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the embodiments 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 creative effort.
[0036] Figure 1 This is a schematic diagram of a system for a pure front-end implementation of a Chat intelligent question-answering streaming typing output method applicable to embodiments of the present invention;
[0037] Figure 2 This is a flowchart illustrating the steps of a purely front-end implemented Chat intelligent question-and-answer streaming typing output method according to an embodiment of the present invention;
[0038] Figure 3 This is a schematic diagram of the structure of the device provided by the present invention. Detailed Implementation
[0039] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0040] It should be noted that, in the absence of conflict, the following embodiments and features can be combined with each other; and, based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0041] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this disclosure, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.
[0042] Figure 1 An exemplary system for a chat intelligent question-and-answer streaming typing output method with a pure front-end implementation suitable for embodiments of the present invention is shown. For example... Figure 1 As shown, the system may include a streaming typing server 101, a communication network 102, and / or one or more streaming typing clients 103. Figure 1 The example in the text is 103, which is a client with multiple streaming typing outputs.
[0043] The streaming typing server 101 can be any suitable server used to store information, data, programs, and / or any other suitable type of content. In some embodiments, the streaming typing server 101 can perform appropriate functions. For example, in some embodiments, the streaming typing server 101 can be used to implement Chat intelligent question-answering streaming typing output in a pure front-end. As an optional example, in some embodiments, the streaming typing server 101 can be used to define a streaming typing output method class, set dependency properties and control methods in the defined streaming typing output method class; use the default constructor of the streaming typing output method class to receive externally passed parameters to update the dependency properties of the streaming typing output method class; and control the execution of the streaming typing output method according to the control methods set in the streaming typing output method class and the updated dependency properties. Intelligent question answering is an advanced form of information retrieval system that answers user questions with accurate and concise natural language. It is a promising direction in the field of NLP. In this embodiment, Chat intelligent question answering refers to artificial intelligence question answering based on natural language processing.
[0044] As another example, in some embodiments, the streaming typing server 101 can send a purely front-end implemented Chat intelligent question-and-answer streaming typing method to the streaming typing client 103 for user use, based on a request from the streaming typing client 103.
[0045] As an optional example, in some embodiments, the streaming typing output client 103 is used to provide a visual output interface, which is used to receive a user's selection input operation for the pure front-end implementation of Chat intelligent question-and-answer streaming typing output, and to obtain and display the output interface corresponding to the option selected by the selection input operation from the streaming typing output server 101 in response to the selection input operation. The output interface displays at least the information of the pure front-end implementation of Chat intelligent question-and-answer streaming typing output and the operation options for the information of the pure front-end implementation of Chat intelligent question-and-answer streaming typing output.
[0046] In some embodiments, the communication network 102 can be any suitable combination of one or more wired and / or wireless networks. For example, the communication network 102 can include any one or more of the following: the Internet, an intranet, a wide area network (WAN), a local area network (LAN), a wireless network, a digital subscriber line (DSL) network, a frame relay network, an asynchronous transfer mode (ATM) network, a virtual private network (VPN), and / or any other suitable communication network. The streaming typing client 103 can be connected to the communication network 102 via one or more communication links (e.g., communication link 104), which can be linked to the streaming typing server 101 via one or more communication links (e.g., communication link 105). The communication link can be any communication link suitable for transmitting data between the streaming typing client 103 and the streaming typing server 101, such as a network link, a dial-up link, a wireless link, a hardwired link, any other suitable communication link, or any suitable combination of such links.
[0047] The streaming typing client 103 may include any one or more clients that present an interface related to the pure front-end implementation of Chat intelligent question-and-answer streaming typing output in a suitable form for user use and operation. In some embodiments, the streaming typing client 103 may include any suitable type of device. For example, in some embodiments, the streaming typing client 103 may include a mobile device, tablet computer, laptop computer, desktop computer, and / or any other suitable type of client device.
[0048] Although the streaming type output server 101 is illustrated as a single device, in some embodiments, any suitable number of devices may be used to perform the functions performed by the streaming type output server 101. For example, in some embodiments, multiple devices may be used to implement the functions performed by the streaming type output server 101. Alternatively, cloud services may be used to implement the functions of the streaming type output server 101.
[0049] Based on the above system, this invention provides a chat intelligent question-and-answer streaming typing output method implemented purely on the front end, which will be described in the following embodiments.
[0050] Reference Figure 2 The diagram illustrates a flowchart of a purely front-end-implemented Chat intelligent question-and-answer streaming typing output method according to an embodiment of the present invention.
[0051] The Chat intelligent question-and-answer streaming typing output method implemented in this embodiment can be executed on the streaming typing output server. This Chat intelligent question-and-answer streaming typing output method implemented in this embodiment includes the following steps:
[0052] Step S201: Define a streaming typing output method class, and set dependency properties and control methods in the defined streaming typing output method class.
[0053] The method in this embodiment of the invention uses TypeScript to define a Class method class to implement the streaming typing output method. Within the defined Class method class, corresponding dependency properties and control methods are set. TypeScript is an open-source programming language developed by Microsoft, built by adding static type definitions to JavaScript. TypeScript is translated into JavaScript code by a TypeScript compiler or Babel, and can run on any browser and any operating system. In the method of this embodiment of the invention, the Class method class is a keyword added in ECMAScript 6, specifically used to create "classes," which can be used to encapsulate implementation logic.
[0054] As an optional example, in the method of this embodiment of the invention, the dependent attributes include the content attributes of the streaming typing output, the timer attributes that control the streaming output, the callback function attributes that need to be executed after the content output is completed, the hook function attributes after each frame of text output, and the configuration parameter attributes that control the streaming typing output effect. Among them, the configuration parameter attributes that control the streaming typing output effect include: the output content attributes of each frame, the attributes that control whether to stop the streaming output, and the speed attributes of the streaming typing output.
[0055] For example, the dependency attributes set in the method of this embodiment include:
[0056] inputText is the content attribute for streaming typing output, and its type is String.
[0057] A timer that controls streaming output; its type is number.
[0058] `endCallback` is the callback function attribute that should be executed after the content is output. Its type is Function.
[0059] hooks, the hook function attribute after each frame of text output, is of type function;
[0060] The option is a configuration parameter attribute that controls the streaming typing output effect, including:
[0061] `outputText` is the output content attribute for each frame, and its type is String.
[0062] isEnd is a property that controls whether to stop streaming output; its type is Boolean.
[0063] speed, the speed attribute of streaming typing output, is measured in milliseconds (ms) and is a number.
[0064] When implementing the method of the present invention, those skilled in the art can set other suitable dependency attributes according to the actual application scenario, and this embodiment does not limit this.
[0065] As an optional example, in the method of this embodiment of the invention, the control method includes: defining a class constructor of a method class, a method to start streaming typing output, a method to stop streaming typing output, a method to clear the control streaming output timer, and an initialization method.
[0066] For example, in the method of this embodiment of the invention, the setting control method includes:
[0067] constructor, defines the class constructor of the method class. constructor is the default method of the Class class, and every Class class has this method;
[0068] `play` is the method to start streaming type output; it is a function.
[0069] `close` is a function that stops streaming typing output.
[0070] closeTimer is a method to clear the control stream output timer; it is a function.
[0071] init is the initialization method, and its type is function.
[0072] When implementing the method of the present invention, those skilled in the art can also set other suitable control methods according to the actual application scenario, and this embodiment does not limit this.
[0073] Step S202: Use the default constructor of the streaming typing output method class to receive externally passed parameters and update the dependency properties of the streaming typing output method class.
[0074] As an optional example, the method in this embodiment of the invention needs to receive configuration parameters (paramOption) for controlling the streaming typing output effect, and assign values to the configuration parameter attribute (option) of the streaming typing output method class using the received configuration parameters (paramOption); receive the content parameter (paramInputText) for streaming typing output, and assign values to the content attribute (inputText) of the streaming typing output method class using the received content parameter (paramInputText); and receive the callback function (par) for the action to be executed after the content output is completed. The `amEndCallBack` method assigns a value to the `endCallBack` property of the streaming typing output method class, which is the callback function to be executed after the received content is output. It also assigns a value to the `hooks` property of the streaming typing output method class, which is the hook function to be executed after each frame of text output. Finally, it sets the value of the timer property (which controls the streaming output) to 0 and executes the `init` method of the streaming typing output method class.
[0075] Step S203: Control the execution of the streaming typing output method according to the control method set in the streaming typing output method class and the updated dependency attributes.
[0076] As an optional example, in the method of this embodiment of the invention, the value of the inputTex attribute of the streaming typing output method class is obtained. When the value of the inputTex attribute of the streaming typing output is 0, the callback function endCallBack of the action to be executed after the content output of the streaming typing output method class is completed is executed, and the method play of starting streaming typing output is terminated.
[0077] When the value of the inputTex attribute of the obtained streaming output is not 0, a timer execution count record variable count with an initial value of 0 is defined to record the execution count of the timer controlling the streaming output. The timer controlling the streaming output is executed at the speed of the streaming output speed.
[0078] It should be noted that in the method of this embodiment of the invention, when the value of the inputTex attribute of the obtained streaming typing output is not 0, a timer execution count record variable count with an initial value of 0 is defined to record the execution count of the timer controlling the streaming output. The timer controlling the streaming output is executed at the speed of the streaming typing output, and is implemented in the following manner:
[0079] Each time the timer controlling the streaming output is executed, the value of the timer execution count variable is incremented by 1. It is then checked whether the incremented value of the timer execution count variable is equal to the value of the streaming inputTex content attribute. If the incremented value of the timer execution count variable is equal to the value of the streaming inputTex content attribute, the value of the timer execution count variable is reset to 0, the closeTimer method for clearing the streaming output timer is called to clear the streaming output timer, and the play method for starting streaming output ends. The timer execution count variable is retrieved, and text corresponding to the number of positions in the streaming inputTex content is extracted from the first position. This extracted text is used as the output content outputText for each frame. The output content outputText of each frame, composed of the extracted text, is used as the input parameter to execute the hook function hooks after each frame of text output.
[0080] As an optional example, in the method of this embodiment of the invention, each time the timer controlling the streaming output is executed, the value of the control whether to stop the streaming output is obtained. When the value of the control whether to stop the streaming output is true, the method closeTimer to clear the timer controlling the streaming output is called to clear the timer controlling the streaming output, and the method play to start the streaming typing output ends. The record value of the timer execution count record variable count is obtained. The text corresponding to the number of positions of the record value is extracted from the inputTex content of the streaming typing output. The extracted text is used as the output content outputText of each frame. The output content outputText of each frame composed of the extracted text is used as the input parameter to execute the hook function hooks after the text output of each frame.
[0081] The method of this embodiment of the invention will be described in detail below with a specific example:
[0082] Implement a function that outputs the text "Disclosure document needs to be output" to the browser console every 60ms. After output is complete, the browser console should print "Output complete". Clicking a button can stop the output.
[0083] The instantiation method of Typer defines a typer variable to store the instance of Typer. During the instantiation process, the constructor method of Typer's constructor will be executed automatically.
[0084] 1. Pass in the text to be streamed: 'Disclosure document to be output'; corresponding to paramInputText;
[0085] 2. Input the streaming typing output settings: speed is 60, isEnd is not to end (false), output is an empty string, corresponding to the option;
[0086] 3. Pass in the callback function when the streaming output is complete, and print 'output complete' to the browser console (()=>{console.log('output complete')}), corresponding to paramEndCallBack;
[0087] 4. Pass in the hook function after each frame of text output; the browser streams one piece of text every 60ms.
[0088] (output:any) => {console.log(output)}, where the output parameter in the function is equivalent to hooks, corresponding to paramHooks;
[0089] const typer = new Typer({
[0090] option:{
[0091] output:'',
[0092] speed: 30,
[0093] isEnd:false,
[0094] }
[0095] input:'The disclosure document needs to be output'
[0096] endCallback:() => {console.log('Output complete')},
[0097] hooks:(output:any)=>{console.log(output)}
[0098] })
[0099] Using a typer instance, calling close() stops the streaming typing output.
[0100] typer.close()
[0101] As can be seen from the above implementation steps, no DOM elements are manipulated.
[0102] The pure front-end implementation of the Chat intelligent question-and-answer streaming typing output method and system of this invention can improve webpage performance without direct DOM manipulation; it does not require server-side cooperation to provide a streaming output interface, making it suitable for both webpage UI interactive effects and streaming typing effects scenarios, as well as intelligent question-and-answer scenarios where no server-side streaming interface is provided. The front-end can quickly simulate and implement streaming typing effects, providing users with a better interactive experience and reducing development costs, development cycle, and implementation complexity; it allows for precise control of the streaming typing effect, providing control over the start, stop, typing speed, and output completion callback execution of the streaming typing effect; it has a wide range of applications, including intelligent question-and-answer scenarios or webpage UI interactive effects and streaming typing effects scenarios, and is suitable for native JS and React / Vue projects with streaming typing output effects.
[0103] like Figure 3As shown, the present invention also provides a device including a processor 310, a communication interface 320, a memory 330 for storing processor-executable computer programs, and a communication bus 340. The processor 310, communication interface 320, and memory 330 communicate with each other via the communication bus 340. The processor 310 implements the aforementioned pure front-end implementation of the Chat intelligent question-and-answer streaming typing output method by running the executable computer program.
[0104] The computer program in memory 330, when implemented as a software functional unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0105] The system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected based on actual needs to achieve the purpose of this embodiment. Those skilled in the art can understand and implement this without any creative effort.
[0106] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.
[0107] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A chat intelligent question-and-answer streaming typing output method implemented purely on the front end, characterized in that, The method includes: Define a class for streaming typing output methods, and set dependency properties and control methods in the defined class for streaming typing output methods; The default constructor of the streaming typing output method class is used to receive externally passed parameters to update the dependent properties of the streaming typing output method class; The execution of the streaming typing output method is controlled based on the control methods set in the streaming typing output method class and the updated dependency properties; The default constructor of the streaming typing output method class is used to receive externally passed parameters to update the dependent properties of the streaming typing output method class, including: Receive the configuration parameters for the control stream typing output effect, and assign values to the configuration parameter property of the control stream typing output effect of the stream typing output method class using the received configuration parameters. Receive the content parameters of the streaming typing output, and use the received content parameters of the streaming typing output to assign values to the streaming typing output content property of the streaming typing output method class. The callback function that needs to be executed after the received content is output is used to assign a value to the callback function property of the streaming typing output method class after the content output is completed; The hook function that receives each frame of text output is used to assign values to the hook function property of each frame of text output in the streaming typing output method class. Set the value of the timer property that controls the streaming output to 0, and execute the initialization method of the streaming typing output method class; The execution of the streaming typing output method is controlled based on the control methods set in the streaming typing output method class and the updated dependency properties, including: Get the value of the content attribute of the streaming typing output method class. When the value of the content attribute of the streaming typing output method class is 0, execute the callback function of the action to be executed after the content output of the streaming typing output method class is completed, and end the method of starting streaming typing output. When the value of the content attribute of the obtained streaming typing output is not 0, a timer execution count record variable with an initial value of 0 is defined to record the execution count of the timer controlling the streaming output. The timer controlling the streaming output is executed at the speed of the streaming typing output.
2. The Chat intelligent question-and-answer streaming typing output method implemented purely in the front end according to claim 1, characterized in that, Define a class for streaming typing output methods, and set dependency properties and control methods in the defined class, including: defining a Class method class using TypeScript to implement the streaming typing output methods, and setting the corresponding dependency properties and control methods in the defined Class method class.
3. The Chat intelligent question-and-answer streaming typing output method implemented purely in the front end according to claim 1, characterized in that, The dependency attributes include the content attributes of the streaming typing output, the timer attributes that control the streaming output, the callback function attributes that need to be executed after the content output is completed, the hook function attributes after each frame of text output, and the configuration parameter attributes that control the streaming typing output effect.
4. The Chat intelligent question-and-answer streaming typing output method implemented purely in the front end according to claim 3, characterized in that, The configuration parameters for controlling the streaming typing output effect include: the output content of each frame, the control of whether to stop streaming output, and the speed of streaming typing output.
5. The Chat intelligent question-and-answer streaming typing output method implemented purely in the front end according to claim 1, characterized in that, The control method includes: defining a class constructor for the method class, a method to start streaming typing output, a method to stop streaming typing output, a method to clear the control streaming output timer, and an initialization method.
6. The Chat intelligent question-and-answer streaming typing output method implemented purely in the front end according to claim 1, characterized in that, When the value of the content attribute of the acquired streaming type output is not 0, a timer execution count record variable with an initial value of 0 is defined to record the execution count of the timer controlling the streaming output. The timer controlling the streaming output is executed at intervals based on the speed of the streaming type output, including: Each time the timer for controlling the stream output is executed, the value of the timer execution count record variable is incremented by 1. Then, it is determined whether the value of the timer execution count record variable after incrementing is equal to the value of the content attribute of the stream typing output. When the value of the timer execution count record variable is equal to the value of the content attribute of the streaming type output after the increment is 1, the value of the timer execution count record variable is reset to 0, the method of clearing the control streaming output timer is called to clear the control streaming output timer, and the method of starting streaming type output ends. Get the record value of the timer execution count record variable, extract the text from the first position to the corresponding number of positions in the stream typing output, and use the extracted text as the output content of each frame; The output content of each frame, composed of the extracted text, is used as the input parameter to execute the hook function after the output of each frame of text.
7. The Chat intelligent question-and-answer streaming typing output method implemented purely in the front end according to claim 1, characterized in that, The execution of the streaming typing output method is controlled based on the control methods set in the streaming typing output method class and the updated dependency properties, including: Each time the timer for controlling the streaming output is executed, the value of the "Control whether to stop streaming output" property is obtained. When the value of the "Control whether to stop streaming output" property is true, the method to clear the timer for controlling the streaming output is called to clear the timer for controlling the streaming output, and the method to start streaming typing output ends. Get the record value of the timer execution count record variable, extract the text from the first position to the corresponding number of positions in the stream typing output, and use the extracted text as the output content of each frame; The output content of each frame, composed of the extracted text, is used as the input parameter to execute the hook function after the output of each frame of text.
8. A chat intelligent question-and-answer streaming typing output system implemented purely on the front end, characterized in that, The system includes a streaming typing output server. The streaming typing output server defines streaming typing output method classes, sets dependency properties and control methods within these classes, and uses the default constructor of the streaming typing output method classes to receive externally passed parameters and update the dependency properties of the streaming typing output method classes. It controls the execution of the streaming typing output methods according to the control methods set in the streaming typing output method classes and the updated dependency properties. Specifically, using the default constructor of the streaming typing output method classes to receive externally passed parameters and update the dependency properties of the streaming typing output method classes includes: receiving configuration parameters for controlling the streaming typing output effect and assigning values to the configuration parameter properties of the streaming typing output effect in the streaming typing output method classes; receiving content parameters for streaming typing output and assigning values to the content properties of the streaming typing output method classes; and receiving callback functions for actions to be executed after content output is completed. The callback function of the action assigns values to the callback function property to be executed after the content output of the streaming typing output method class is completed; it receives the hook function after each frame of text output and uses the hook function after each frame of text output to assign values to the hook function property of each frame of text output of the streaming typing output method class; it sets the value of the timer property controlling the streaming output to 0 and executes the initialization method of the streaming typing output method class; the execution of the streaming typing output method is controlled according to the control method set in the streaming typing output method class and the updated dependency property, including: obtaining the value of the streaming typing output content property of the streaming typing output method class; when the obtained value of the streaming typing output content property is 0, the callback function to be executed after the content output of the streaming typing output method class is completed is executed to end the method of starting streaming typing output; when the obtained value of the streaming typing output content property is not 0, the execution count record variable of the timer controlling the streaming output is defined with an initial value of 0 to record the execution count of the timer controlling the streaming output, and the execution timer controlling the streaming output is executed at the speed of streaming typing output.