Method for generating self-consistent text based on specific structure and text content and related device
By constructing a tree-structured node set and using a recursive traversal algorithm to generate structured prompt words, the problem of structural and content consistency in long text generation by large-scale pre-trained language models is solved, and efficient and automated generation of self-consistent text is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING XIN INTERNET TECHNOLOGY CO LTD
- Filing Date
- 2026-04-07
- Publication Date
- 2026-07-10
AI Technical Summary
Existing large-scale pre-trained language models struggle to simultaneously satisfy structural norms and content accuracy when generating long texts, often resulting in inconsistencies and fact drift, and lacking global structured generation capabilities.
By acquiring the text outline, a tree-structured node set is constructed. Initial context information is built using a recursive traversal algorithm and a knowledge base. Structured prompt words are generated, and a large model is called to generate text fragments. The fragments are then assembled into self-consistent text in real time to ensure that the generated content is consistent.
It achieves precise structural control and global content self-consistency in long text generation, reduces the number of manual modifications, lowers the threshold for professional text creation, and alleviates the risks of delays and memory overflows in long text generation.
Smart Images

Figure CN122366366A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, specifically to a method and related equipment for generating self-consistent text based on a specific structure and text content. Background Technology
[0002] Currently, text generation technology based on large-scale pre-trained language models has been widely applied in content creation, summary generation, and dialogue systems. However, it still has limitations in professional text generation scenarios (such as report writing, scheme design, and structured narrative) where both structural norms and content accuracy must be met simultaneously. The fundamental problem lies in the autoregressive generation mechanism of large models—which essentially predicts the next word based on local context, lacking the ability to globally plan the macro-information architecture and logical flow of the entire text. When generating long texts involving multiple paragraphs and facts, this generation logic, lacking global planning capabilities, is prone to inconsistencies and fact drift. The model's insufficient global structured generation capability stems from a deeper cognitive deficiency: during the pre-training stage, the model does not explicitly learn to strongly associate the abstract logical structure of the text with specific surface language forms, resulting in a weak "structural awareness." The model's understanding of structure is prone to bias, making it difficult to accurately generate text that conforms to a specific structure and content accuracy. Summary of the Invention
[0003] To address the aforementioned issues, this application provides a method and related apparatus for generating self-consistent text based on a specific structure and text content, which enables precise structural control and global self-consistency of long text generation.
[0004] The technical solution of this application embodiment is as follows: In a first aspect, embodiments of this application provide a method for generating self-consistent text based on a specific structure and text content, the method comprising: Obtain the text outline to be generated, identify the hierarchical identifiers in the text outline, and construct a tree-structured node set containing hierarchical relationships based on the hierarchical identifiers; Determine whether the knowledge base is enabled. If the knowledge base is enabled, execute the pre-configured retrieval strategy to obtain the corresponding knowledge base text content, and construct initial context information based on the knowledge base text content. The tree structure node set is processed sequentially using a recursive traversal algorithm. For the currently processed tree structure node, the following steps are performed: generate structured prompt words based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure node, the initial context information, and the obtained generation control parameters; call the preset large model interface to generate the text fragment corresponding to the current tree structure node based on the structured prompt words. Simultaneously, based on the initial context information and the text content, current context information including the initial context information is generated, and the current context information is encapsulated into a data transmission object and passed as a recursive parameter to all child nodes of the current tree structure node; The generated text fragments are received in real time, and the text fragments are assembled into a complete self-consistent target text according to the order of the tree structure nodes.
[0005] In the above technical solution, the text outline to be generated is obtained, the hierarchical identifiers in the text outline are identified, and a tree-structured node set containing hierarchical relationships is constructed based on the hierarchical identifiers. This converts the unstructured text into a traversable tree-structured data structure, providing a foundation for subsequent recursive algorithms and ensuring that the generation order is consistent with the text outline, thus achieving accurate control over the global structure of the generated text. It is then determined whether a knowledge base is enabled. If the knowledge base is enabled, a pre-configured retrieval strategy is executed to obtain the corresponding knowledge base text content, and initial context information is constructed based on the knowledge base text content. By using a knowledge base, it ensures that the generated content is based on real and specific data, avoiding fact drift. A recursive traversal algorithm is used to process the tree-structured node set sequentially. For the currently processed tree-structured node, context passing is introduced into the recursive traversal algorithm to ensure consistency in the generated content, avoiding inconsistencies. The following steps are performed: Based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure nodes, the initial context information, and the acquired generation control parameters, structured prompt words are generated; a preset large model interface is called to generate text fragments corresponding to the current tree structure nodes based on the structured prompt words. Context, structural position, and rules are forcibly injected into the prompt words to generate content that meets specific structural requirements; simultaneously, current context information, including the initial context information, is generated based on the initial context information and text content. This current context information is encapsulated in the data transmission object and passed as a recursive parameter to all child nodes of the current tree structure node, ensuring the logical connection and consistency of the generated long text; each generated text fragment is received in real time and assembled into a complete self-consistent target text according to the order of the tree structure nodes, achieving precise structural control and global content self-consistency in long text generation.
[0006] In some embodiments of this application, generating current context information, including the initial context information, based on the initial context information and the text fragment includes: The text fragment is summarized using a preset text processing algorithm to obtain the node context information corresponding to the current tree structure node; The initial context information is embedded in the node context information to obtain the current context information, which includes the initial context information.
[0007] In some embodiments of this application, the step of encapsulating the current context information into a data transmission object and passing it as a recursive parameter to all child nodes of the current tree structure node includes: Create a key-value pair collection object as the data transfer object; The current context information is stored as a fixed value in the key-value pair collection object; If the current tree structure node has child nodes, the recursive traversal algorithm is invoked, the child node is taken as the current tree structure node, the current context information is taken as the initial context information, and the key-value pair collection object is passed to the recursive function so that the initial context information can be directly read when processing the child node.
[0008] In some embodiments of this application, generating structured prompts based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure node, the initial context information, and the obtained generation control parameters includes: Obtain a prompt word template, which includes a structure injection module, a knowledge injection module, a streaming history injection module, and a rule injection module; The structure injection module is filled with the set of tree-like nodes; Extract the initial context information from the data transmission object, and fill the initial context information into the knowledge injection module corresponding to the hierarchical relationship; Read the last text of the preceding node corresponding to the child node in the same hierarchical relationship, and fill the last text into the streaming history injection module; The generation control parameters are filled into the rule injection module, and the structured prompt words are formed based on the filled structure injection module, the knowledge injection module, the streaming history injection module and the rule injection module.
[0009] In some embodiments of this application, the structure injection module includes title tags, chapter tags, and table of contents tags; The step of filling the structure injection module with the tree-structured node set includes: Based on the set of tree-structured nodes, extract the root node of the tree-structured nodes and fill it into the question label; Fill the parent nodes of the tree structure nodes, excluding the root node, into the chapter tags according to the hierarchical relationship; Fill all the parent nodes and their corresponding child nodes into the directory tags, and then form the filled title tags, chapter tags, and target tags into the filled structure injection module.
[0010] In some embodiments of this application, the step of executing a pre-configured retrieval strategy to obtain the corresponding knowledge base text content includes: In response to the selected chunked search strategy, search keywords are determined based on the text outline; The search keywords are used to perform similarity matching in the knowledge base to obtain a preset number of related text blocks; The acquired related text blocks are serialized to obtain the knowledge base text content.
[0011] In some embodiments of this application, the step of executing a pre-configured retrieval strategy to obtain the corresponding knowledge base text content includes: In response to selecting a pre-configured full search strategy, a preset file identifier is matched according to the text outline, and the complete content of the corresponding file in the knowledge base is read using the text identifier; Determine whether the length of the complete content exceeds a preset threshold; If the preset threshold is not exceeded, the complete content will be used as the knowledge base text content.
[0012] In a second aspect, this application provides an electronic device including one or more processors and a memory; the memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, and the one or more processors invoking the computer instructions to cause the electronic device to perform the method described in the first aspect and any possible implementation thereof.
[0013] Thirdly, this application provides a computer program product containing instructions that, when the computer program product is run on an electronic device, cause the electronic device to perform the method described in the first aspect and any possible implementation thereof.
[0014] Fourthly, this application provides a computer-readable storage medium including instructions that, when executed on an electronic device, cause the electronic device to perform the method described in the first aspect and any possible implementation thereof.
[0015] In summary, one or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. By first obtaining the outline of the text to be generated and constructing a tree-structured node set, unstructured text is converted into structured data, facilitating traversal while achieving accurate control over the global structure. When the knowledge base is activated, the text content of the knowledge base is obtained and initial context information is constructed to ensure the authenticity of the generated content. A recursive traversal algorithm is used to process the tree structure, and an encapsulated data transfer object is used to pass the initial context and dynamically generated current context information to all child nodes, ensuring the relevance and consistency of the generated text content. Based on structured prompts, a large model is called to generate text fragments, which are finally assembled into complete text, achieving precise structural control and global content self-consistency in long text generation. Therefore, this method effectively solves the problem in related technologies of accurately generating text that conforms to a specific structure and content.
[0016] 2. By using a segmented retrieval strategy, the limitation of excessively large text size caused by long text generation can be alleviated, and the automatic generation of long text can be achieved.
[0017] 3. In the full-search strategy, determine whether the length of the complete content exceeds the threshold to implement a circuit breaker mechanism and prevent model memory overflow.
[0018] 4. By traversing the tree structure and combining it with the construction of structured prompts, the number of manual modifications and adjustments required to obtain the ideal text is reduced, realizing an efficient and automated process of "input structure - content requirements, output high-quality final draft", thus lowering the threshold and cost of professional text creation.
[0019] 5. By providing a URL, conduct an online search to address the issue of outdated knowledge bases and obtain the latest information.
[0020] 6. Long text generation is slow. Streaming generation can alleviate long waiting times for users and prevent long content from being interrupted. Attached Figure Description
[0021] Figure 1 This is a flowchart illustrating a method for generating self-consistent text based on a specific structure and text content, provided in one embodiment of this application. Figure 2 This is a tree structure diagram of a method for generating self-consistent text based on a specific structure and text content provided in one embodiment of this application; Figure 3 This is a schematic diagram of a structured prompt word template illustrating a method for generating self-consistent text based on a specific structure and text content, provided in one embodiment of this application. Figure 4 This is a schematic diagram of the structure of a system for generating self-consistent text based on a specific structure and text content, provided in one embodiment of this application. Figure 5 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application. Detailed Implementation
[0022] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0023] In the description of the embodiments of this application, the words "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "for example" or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Rather, the use of the words "for example" or "for instance" is intended to present the relevant concepts in a specific manner.
[0024] In the description of the embodiments of this application, the term "multiple" means two or more. For example, multiple systems means two or more systems, and multiple screen terminals means two or more screen terminals. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.
[0025] In related technologies, text generation techniques based on large-scale pre-trained language models have been widely applied in content creation, summarization, and dialogue systems. However, in professional text generation scenarios that require simultaneously satisfying complex constraints on both "structure" and "content," existing technologies reveal significant shortcomings, mainly in the following three aspects: At the first level, there's a heavy reliance on prompting engineering, where the structure is described in the input instructions (e.g., "Please generate a report containing an introduction, methods, and conclusions"). However, this approach is implicit and vague, making it prone to biases in the model's understanding of the structure and hindering the precise generation of text that conforms to specific hierarchical, sequential, and format requirements. A deeper reason is that large models, during pre-training, do not explicitly learn to strongly associate the abstract logical structure of text with concrete surface-level language forms, resulting in a weak "structural awareness." The challenge in addressing this lies in designing a mechanism that allows the model to deeply understand and internalize the user's structural intent while maintaining its flexibility in language generation, rather than simply using template filling.
[0026] Secondly, when generating long texts involving multiple paragraphs and facts, existing models are prone to problems such as inconsistencies, fact drift, or information redundancy. The root cause lies in the fact that the autoregressive generation mechanism of large models is essentially based on predicting the next term from a local context, lacking a global plan and consistency maintenance of the overall information architecture and logical flow of the text. During the generation process, content generated earlier is easily ignored or violated by subsequent generation steps. Previous attempts to solve this problem by extending the context window or introducing post-editing are either computationally expensive or cumbersome, failing to fundamentally achieve real-time, dynamic consistency constraints during the generation process.
[0027] Thirdly, it's difficult to coordinate compound instructions like "follow this structure" and "include these specific contents." Models often fail to address either aspect effectively, resulting in either correct structure but empty or non-existent content, or content that conforms but disrupts or destroys the intended structure. This is because structural and content constraints create different guiding signals within the model, which can interfere with each other without an effective coordination mechanism. Previous techniques struggled to balance and integrate these two different types of control signals within a unified generative framework, leading to discrepancies between the generated results and the user's complex intentions.
[0028] Based on this, embodiments of this application provide a method, electronic device, program product, and storage medium for generating self-consistent text based on a specific structure and text content. The method first obtains the outline of the text to be generated, identifies the hierarchical identifiers in the text outline, and constructs a tree-structured node set containing hierarchical relationships based on the hierarchical identifiers, converting unstructured text into a traversable tree-structured data structure, providing a foundation for subsequent recursive algorithms, ensuring the generation order is consistent with the text outline, and achieving accurate control over the global structure of the generated text. It then determines whether a knowledge base is enabled; if enabled, it executes a pre-configured retrieval strategy to obtain the corresponding knowledge base text content and constructs initial context information based on the knowledge base text content. By using a knowledge base, it ensures that the generated content is based on real and specific data, avoiding fact drift. Finally, it employs a recursive traversal algorithm to process the tree-structured node set sequentially. For the currently processed tree-structured node, it references... By passing context information, the generated content remains consistent and inconsistencies are avoided. The following steps are performed: First, structured prompts are generated based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure nodes, initial context information, and acquired generation control parameters. Second, a preset large model interface is called to generate text fragments corresponding to the current tree structure nodes based on the structured prompts. Context, structural position, and rules are forcibly injected into the prompts to generate content that conforms to specific structural requirements. Third, current context information, including the initial context information, is generated based on the initial context information and text content. This current context information is encapsulated in the data transmission object and passed as recursive parameters to all child nodes of the current tree structure node, ensuring logical coherence and consistency in the generated long text. Fourth, the generated text fragments are received in real time and assembled into a complete, self-consistent target text according to the order of the tree structure nodes, achieving precise structural control and global content self-consistency in long text generation.
[0029] It should be noted that this method of generating self-consistent text based on specific structure and text content can be applied to the automatic generation of text for report writing, program design, structured narrative, etc.
[0030] The technical solutions provided in the embodiments of this application will be further described below with reference to the accompanying drawings.
[0031] Reference Figure 1 , Figure 1This is a flowchart illustrating a method for generating self-consistent text based on a specific structure and text content, as provided in an embodiment of this application. The method for generating self-consistent text based on a specific structure and text content is executed by a processor in an electronic device or a readable storage medium. The method includes steps S100, S200, S300, S400, and S500.
[0032] Step S100: Obtain the text outline to be generated, identify the hierarchical identifiers in the text outline, and construct a tree-structured node set containing hierarchical relationships based on the hierarchical identifiers.
[0033] In one embodiment, the text outline refers to the user-inputted text skeleton containing hierarchical relationships, typically in Markdown format, using # to represent first-level headings, ## to represent second-level headings, and so on. Identifying the hierarchical identifiers in the text outline involves recognizing the Markdown-formatted first-level headings, second-level headings, etc., and the relationships between these levels, such as relationships within the same level and relationships between different levels. Specifically, the Markdown-formatted outline string is split line by line, and regular expressions (such as #) are used to identify the identifier of each line to obtain the hierarchical identifiers.
[0034] Specifically, the header line is first extracted as level 0. Then, line break recognition is performed, and a level identifier is identified for each line. The level of each line is determined by the number of '#' symbols, and then the '#' symbols are removed to extract the header text. A list of node objects is constructed using the level mechanism. For the current node, the system traverses the list in reverse order, finding the first element with a level depth less than the current node and marking it as the "logical parent node." Through this step, a complete parent-child nested pointer relationship is established, reconstructing the linear outline into a multi-way tree data structure, providing a foundation for subsequent traversal.
[0035] For example, the Markdown format of a text outline is represented as follows: # Chapter 1 AI Technology ## 1.1 Deep Learning # Chapter Two: Applications of AI Technology ## 2.1 Deep Learning Applications.
[0036] After structuring the object, hierarchical identifiers indicate the current level and its relationship with the next level. Based on these hierarchical identifiers, a tree structure is constructed. The root node's level is 0, representing the name corresponding to the text outline. The root node includes all child nodes, each with a level of 1. The child nodes' child nodes have a level of 2. The parent node points to levels 0 and 1; level 0 points to the name, level 1 points to Chapter 1, and child nodes point to level 2, such as deep learning or deep learning applications. Based on each hierarchical identifier, a tree-structured node set containing hierarchical relationships is constructed. By constructing this tree structure, unstructured text is transformed into a traversable tree data structure, providing a foundation for subsequent recursive algorithms. This ensures the generation order is completely consistent with the outline, thereby achieving accurate control over the global structure and facilitating the automatic generation of prompts for content.
[0037] like Figure 2 The diagram shows the constructed tree structure, which corresponds to the Markdown format. The root node is the name. The first level consists of the root node's child nodes, which act as parent nodes, including Chapter 1, Chapter 2, etc. The second level consists of the parent node's child nodes, including the sub-sections within Chapter 1 and Chapter 2. Each sub-section also has a logical relationship with the others. For example, in the process of generating long text, the last section of one chapter may be related to the content of the next chapter. Taking Chapter 1 and Chapter 2 as examples, both belong to the same level, but their generated content has a progressive relationship. The last section of Chapter 1 is related to the first section of Chapter 2 or the summary section of Chapter 2.
[0038] Step S200: Determine whether the knowledge base is enabled. If the knowledge base is enabled, execute the pre-configured retrieval strategy, obtain the corresponding knowledge base text content, and construct initial context information based on the knowledge base text content.
[0039] In one embodiment, the knowledge base includes pre-stored structured or semi-structured knowledge units that provide factual basis, rule guidance, or contextual support for the generation process. These include formatted texts such as product manuals, technical documents, and policy documents, which can be directly used as generation references, as well as operational procedures, business rules, and reasoning rules. Initial contextual information refers to background information, core definitions, or statistical data retrieved from the knowledge base to guide full-text generation. The product's front-end page has an option for users to enable or disable the knowledge base function. Enabling the knowledge base function is determined by whether a selection operation to enable the knowledge base is received from the front-end. If the selection is received, the knowledge base function is enabled. When the knowledge base is enabled, a pre-configured retrieval strategy is executed to retrieve the knowledge base text content from a vector database or file storage, and initial contextual information is constructed based on the retrieved knowledge base text content. This ensures that the generated content is based on real, specific external data, rather than the general memory used during model training, thus solving the "illusion" problem in specialized fields.
[0040] For example, a user writes a "New Energy Vehicle Report" and retrieves "Battery Technical Parameters for 2024". This text is then cleaned (garbled characters and HTML tags are removed) and packaged into a string or JSON format as "initial context information".
[0041] In one embodiment, a pre-configured retrieval strategy is executed to obtain the corresponding knowledge base text content, including but not limited to the following steps: Step S210: In response to the selected chunked search strategy, determine the search keywords based on the text outline.
[0042] In some possible embodiments of this application, when the knowledge base file is large, such as a manual of several hundred pages, a chunked search strategy is set due to memory limitations. The front-end page displays both a chunked search strategy and a full search strategy, with prompts after each strategy. These prompts suggest choosing the chunked search strategy if the file is large, and the full search strategy if the file is small. Users can make this selection. In response to the user's selected chunked search strategy, search keywords are first determined based on the text outline. Specifically, the text outline is recursively parsed according to the heading level, and heading words in the text outline are used as search keywords. These search keywords are then used to retrieve relevant content and generate the knowledge base text content.
[0043] It should be noted that the outline can also be recursively parsed according to the title level to obtain multiple candidate words. A pre-defined Bidirectional Encoder Representations from Transformers (BERT) model is then used to generate expanded words for each candidate word, which are then used as search keywords. The BERT model is an existing model and will not be elaborated upon here.
[0044] Step S220: Use search keywords to perform similarity matching search in the knowledge base to obtain a preset number of related text blocks.
[0045] In some possible embodiments of this application, a preset matching algorithm is used to perform similarity matching between each search keyword and the content in the knowledge base, resulting in multiple matching contents. These are then sorted according to their similarity values, and the top k matching contents with the highest similarity are selected as relevant text blocks. The preset matching algorithm can be a text similarity algorithm or the BM25 algorithm; k can be 5, etc., to facilitate the subsequent retrieval of the knowledge base text content based on the relevant text blocks. Step S230: Serialize the acquired multiple related text blocks to obtain the knowledge base text content.
[0046] In some possible embodiments of this application, the K text block objects obtained in step S220 are converted into a single string format to obtain the knowledge base text content, so as to generate initial context information and provide support for subsequent filling in of structured prompt words and generating context information.
[0047] In another embodiment, a pre-configured retrieval strategy is executed to obtain the corresponding knowledge base text content, including but not limited to the following steps: In step S240, in response to selecting a pre-configured full search strategy, a preset file identifier is matched based on the text outline, and the complete content of the corresponding file in the knowledge base is read using the text identifier.
[0048] In some possible embodiments of this application, when the expected generated file is small, such as a two-page summary, the user selects a full-scale search strategy. In response to the user's selection of the full-scale search strategy, the text outline is first recursively parsed by heading level. The heading words in the text outline are used as keywords. These keywords are then matched with the keywords indicated by the file identifier. A successful match is considered achieved if the similarity exceeds a preset threshold. The text identifier is then used to read the complete content of the corresponding file in the knowledge base. This allows for subsequent determination of whether to trigger a chunked search strategy to generate knowledge base text content based on the length of the complete content. The preset file identifier is an identifier pointing to a specific document in the knowledge base. This text identifier is associated with the file's storage address, storage type, keywords, and metadata. When storing a document in the knowledge base, the text identifier of that document is constructed to facilitate the extraction of the corresponding document content. The preset similarity threshold is 70% to ensure that relevant content can be matched.
[0049] Step S250: Determine whether the length of the complete content exceeds a preset threshold.
[0050] In some possible embodiments of this application, the preset threshold can be set to a 32k flag, which serves as an indicator for the context window. This flag is determined based on the memory available to support the full-search strategy and can be set to a larger or smaller value. The number of characters in the complete content is counted, and it is determined whether the number of characters exceeds the preset threshold, thereby determining whether to trigger the circuit breaker mechanism.
[0051] Step S260: If the preset threshold is not exceeded, the complete content is used as the knowledge base text content.
[0052] In some possible embodiments of this application, if a preset threshold is not exceeded, it indicates that the model content can support the retrieval of text, and the complete content is used as the knowledge base text content. If the preset threshold is exceeded, a circuit breaker mechanism is triggered, and an error message is displayed. Alternatively, the full-search strategy can be automatically converted to a block-based search strategy to obtain the knowledge base text content.
[0053] It should be noted that, without the knowledge base enabled, users enter a search URL to perform an online search. Based on the user-entered search URL, either explicit URLs are extracted using regular expression validation, or implicit related links are obtained by calling the search engine API. Parallel crawling tasks are distributed through multi-threading to reduce latency and achieve timely response. Based on the retrieved HTML source code, a DOM parser is used to remove irrelevant nodes such as advertisements and navigation bars. The cleaned plain text data is used as external reference material, which then becomes the text content of the knowledge base.
[0054] It should also be noted that corresponding priorities are set for knowledge base, external URL retrieval, and API data, and retrieval is performed in order of priority, from highest to lowest: knowledge base, external URL retrieval, and API data. Once the knowledge base text content is retrieved, it is further differentiated according to priority by adding knowledge tagging and other methods.
[0055] In one embodiment, the obtained knowledge base text content includes text fragments, source document names, page numbers, matching scores, etc. The knowledge base text content undergoes data cleaning, removing redundant whitespace, residual HTML tags, and merging sentences. Each preprocessed text is traversed, and an index header is added to each text. The index header can be an identifier and a source name. The text with the added index header is serialized using JSON or XML format to form initial context information, providing a foundation for subsequent information transmission.
[0056] The initial context information can be represented as: <knowledge_base> <doc id="ref_1" title="2024年Q1财报"> Revenue increased by 15% year-on-year, and net profit reached 5 billion yuan. Market share expanded to 25%.
[0057] < / doc> <doc id="ref_2" title="CEO内部讲话"> We need to focus on developing AI business and reduce investment in traditional hardware.
[0058] < / doc> < / knowledge_base> Step S300: A recursive traversal algorithm is used to process the tree structure node set sequentially. For the currently processed tree structure node, the following steps are performed: Based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure node, the initial context information, and the obtained generation control parameters, a structured prompt word is generated; the preset large model interface is called to generate the text fragment corresponding to the current tree structure node based on the structured prompt word.
[0059] In one embodiment, a recursive traversal algorithm is used to process the tree-structured node set sequentially. This means starting from the root node corresponding to the text outline and traversing layer by layer to visit each child node (first-level headings, second-level headings, etc.). If a node has child nodes, a depth-first search strategy is used to traverse it, processing the child nodes first, until the lowest-level leaf node is reached, pointing to a specific paragraph, where the generation operation is performed. The recursive traversal algorithm is a depth-first search strategy. The data transfer object is a container for transferring information between nodes. It can be in key-value pairs or dictionary format, and can package and transmit the context information of the parent node to the child nodes, passing it down level by level. Using the data transfer object ensures that each node shares the same background as the node at the next higher level, making the generated text logically consistent and avoiding inconsistencies and factual drift.
[0060] It should be noted that a traversal pattern combining depth-first search and breadth-first search strategies can also be adopted. The depth-first search strategy traverses the relationships between nodes at the upper level and their child nodes at the lower level, while the breadth-first search strategy traverses the relationships between nodes at the same level. This is to facilitate the subsequent transmission of context information to lower levels and to nodes at the same level.
[0061] In one embodiment, the following steps are performed: Based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure nodes, initial context information, and acquired generation control parameters, a structured prompt word is generated, including but not limited to the following steps: Step S310: Obtain the prompt word template, which includes a structure injection module, a knowledge injection module, a streaming history injection module, and a rule injection module.
[0062] In one embodiment, the prompt word template refers to an input instruction template assembled from specific modules that are easy to understand by the large model, including a structure injection module, a knowledge injection module, a streaming history injection module, and a rule injection module. For example... Figure 3 As shown, the content within the symbols <> in each module is variable depending on the text outline. The structure injection module is for filling in the structure corresponding to the text outline, thus building a global framework and achieving overall control over the global structure; the knowledge injection module is for filling in the generated content; the streaming history injection module is for filling in the content related to the restricted display output method; and the rule injection module is for filling in validation rules, etc. The prompt word module divides the text into different parts so that corresponding content can be filled in different parts to generate text fragments that conform to the prompt word format requirements.
[0063] Step S320: Fill the structure injection module with the set of tree structure nodes.
[0064] Specifically, the structure injection module includes title tags, chapter tags, and table of contents tags. The title tags correspond to the title of the text to be generated, which is consistent with the title name of the text outline. The chapter tags are the headings of each level in the text outline, and the table of contents tags are the overall structural directory of the text outline. Through the structure injection module, the global structure of the text to be generated can be controlled as a whole, realizing a deep connection between structure and content, thereby generating a logically consistent text file.
[0065] Based on the tree-structured node set, the structure injection module is populated, including but not limited to the following steps: Step S321: Based on the set of tree structure nodes, extract the root node of the tree structure nodes and fill it into the question label.
[0066] In some possible embodiments of this application, since the tree structure node set corresponds to the structure of the text outline, the corresponding content is filled in according to each node of the tree structure node. The root node of the tree structure node is level 0, and the content corresponding to the root node is extracted and filled into the title tag so that a dynamically filled structure injection module can be obtained later.
[0067] Step S322: Fill in the chapter labels with the parent nodes of the tree structure nodes, excluding the root node, according to the hierarchical relationship.
[0068] In some possible embodiments of this application, the parent nodes of the tree structure nodes, excluding the root node, represent the various levels of headings in the text outline. Chapter tags are filled in according to the hierarchical relationship of the tree structure nodes, and chapter tags are dynamically generated so that the dynamically filled structure injection module can be obtained later.
[0069] Step S323: Fill all parent nodes and their corresponding child nodes into the directory tags, and inject the filled title tags, chapter tags and target tags into the filled structure injection module.
[0070] In some possible embodiments of this application, parent nodes and child nodes constitute the overall structure of the generated text. Filling this structure into directory tags facilitates control over the generation of the overall content and promotes the consistency of the overall logic of the generated text. The filled-in title tags, chapter tags, and target tags form the structure injection module, making the structure injection module for prompt words dynamically generated. This allows for text generation that meets the requirements of different text outlines, and the generated structure is clear and logically consistent.
[0071] It should be noted that since the tree-structured node set corresponds to the hierarchical structure of the text outline, it is easier to read and process the corresponding data by traversing the structured data of the tree-structured nodes, thus saving the limitations of traversing unstructured text outline data.
[0072] Step S330: Extract initial context information from the data transmission object and fill the initial context information into the knowledge injection module corresponding to the hierarchical relationship.
[0073] In one embodiment, initial context information is extracted from the data transmission object. Based on the hierarchical relationship, this context information is filled into the knowledge injection module corresponding to each level. This hierarchical relationship not only ensures structural consistency but also enhances the connection between different levels through the initial context information. By dynamically filling the initial context information into the corresponding knowledge injection module and introducing it into the prompt words, the logic of each chapter of the generated text is ensured to remain consistent when using the large model subsequently, avoiding inconsistencies in the generated content.
[0074] Step S340: Read the last text of the predecessor node corresponding to the child node in the same hierarchical relationship, and fill the last text into the streaming history injection module.
[0075] In one embodiment, to ensure the sequential relationship between child nodes within the same hierarchical hierarchy, the text of the last part of the preceding node corresponding to the child node is extracted using text regular expression matching, and an index header (i.e., derived from the hierarchical title corresponding to the preceding node) is added to obtain the last text. This last text is then filled into the streaming history injection module. The streaming history injection module integrates the preceding parts of the current child node in the text outline, further improving the sequential logic of the generated text.
[0076] Step S350: The generated control parameters are filled into the rule injection module. Based on the filled structure injection module, knowledge injection module, streaming history injection module and rule injection module, structured prompt words are formed.
[0077] In one embodiment, the generation control parameters integrate relevant constraints input by the user, such as word limits and prohibition of colloquial language. The user input is received via a pre-defined API, concatenated in JSON format to form the generation control parameters, and then filled into the rule injection module. The filled structure injection module, knowledge injection module, streaming history injection module, and rule injection module are combined to form structured prompts, constituting dynamically generated structured prompts. These structured prompts correspond to the overall structure of the text outline and incorporate contextual information, guiding the generation of text with accurate overall structure control and consistent logical flow.
[0078] In another embodiment, the rule injection module employs a four-layer structured instruction system, decomposing a single generation control parameter into a multi-dimensional cognitive matrix to ensure that the generated structured prompts have a global generation perspective. The four-layer structured instruction system includes a global role, recursive path, multi-source knowledge fusion, and micro-constraints. The global role is a preset SEO expert, injected with dynamic parameters for identity declaration, preventing deviations in the theme's direction. The recursive path saves the depth-first search path and fills it into the rule as a constraint. Multi-source knowledge fusion involves fusing keywords from a knowledge base and online information. This fused keyword requires the original sentences to be quoted in the generated text and is instantly labeled with tags to prevent fictitious text. Micro-constraints include title length, prohibition of ellipses, and prohibition of repeated words, guiding the generated text to conform to common text expressions and increasing the text's rhythm. By filling the rule injection module with the four-layer structured instruction system, the generated structured prompts better meet the needs of the generated text.
[0079] In one embodiment, the preset large model interface can be a GPT-4 interface, a Tongyi Qianwen interface, a deep mining large model interface, etc. The preset large model interface is called, and based on the structured prompts generated above, it guides the generation of text fragments corresponding to the current tree structure node. After traversing and combining all tree structure nodes, a self-consistent text file corresponding to the complete text outline is generated.
[0080] It should be noted that the prompt word template also includes a validation module. This module uses structured prompt words to constrain and validate the generated text fragments, determining whether the text fragments meet the prompt word constraints. For example, it checks for summary statements; if a summary word exists and is at the end of the text, it is removed. It also checks for XML tags and whether the text length meets the requirements. The constraint validation rules are entered into the validation module and added to the structured prompt words to ensure the generated text fragments are of standardized content.
[0081] It should also be noted that, based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure nodes, the initial context information, and the obtained generation control parameters, the above-mentioned indicated content is automatically injected into the prompt word template, so that structured prompt words are automatically generated and conform to the corresponding structure of the text outline, thereby generating long text content that matches the text outline.
[0082] In step S400, simultaneously, current context information, including the initial context information, is generated based on the initial context information and the text fragment. The current context information is then encapsulated into a data transmission object and passed as a recursive parameter to all child nodes of the current tree structure node.
[0083] In one embodiment, while traversing the current node of the tree structure node set, current context information is generated so that subsequent node traversals can refer to the aforementioned background for generation, ensuring consistency of logic before and after.
[0084] Specifically, generating current context information, including the initial context information, based on the initial context information and the text fragment includes, but is not limited to, the following steps: Step S410: Use a preset text processing algorithm to summarize the text fragment to obtain the node context information corresponding to the current tree structure node.
[0085] In one embodiment, the text processing algorithm can summarize text fragments using a recurrent neural network model or a transform model to generate summary information. This summary information includes the main content of the text fragment and is passed as background knowledge to child nodes to obtain the node context information corresponding to the currently traversed tree structure node. This is then used to generate the current node's context information subsequently, so as to pass the node's information to each of its child nodes.
[0086] Step S420: Embed the initial context information into the node context information to obtain the current context information including the initial context information.
[0087] In one embodiment, since the initial context information represents the context information of the node one level above the current node, context information is passed through the hierarchical relationship. The initial context information is represented as key-value pairs and stored in a dictionary. The node context information is also represented as key-value pairs and stored in a dictionary format. The dictionary format of the node context information is embedded within the dictionary of the initial context information to obtain the current context information, including the initial context information. This facilitates subsequent information transmission and ensures consistent logic in the generated text.
[0088] In one embodiment, the current context information is encapsulated into a data transmission object and passed as a recursive parameter to all child nodes of the current tree structure node, including but not limited to the following steps: Step S430: Create a key-value pair collection object as the data transfer object.
[0089] Specifically, a key-value pair collection object is created as a data transfer object. This data transfer object can store key-value pairs in a dictionary format, using the corresponding level as the key and the current context information corresponding to that level as the value. This key-value pair collection storage method can not only store context information for multiple hierarchical relationships but also context information for the same level, facilitating the identification of corresponding hierarchical relationships and the retrieval of corresponding information.
[0090] Step S440: Store the current context information as a fixed value in the key-value pair collection object.
[0091] Specifically, the current context information is stored as a fixed value rather than a variable value in the key-value pair collection object. The background knowledge is fixed, indicating that the background knowledge of the previous level is used at the same level. The fixed value ensures the consistency of information, thereby generating logically consistent text.
[0092] Step S450: If the current tree structure node has child nodes, call the recursive traversal algorithm, take the child node as the current tree structure node, take the current context information as the initial context information, and pass the key-value pair collection object to the recursive function so that the initial context information can be read directly when processing the child node.
[0093] Specifically, when a node in the current tree structure has child nodes, a recursive traversal algorithm is invoked layer by layer, treating the child node as the current tree structure node and the current context information as the initial context information to ensure the reusability of the recursive traversal algorithm. Current context information is generated for each node, and a key-value pair collection object based on the current context information is passed to the recursive function as a parameter, allowing direct reading of the initial context information when processing child nodes. This ensures that the text generation of the current node can reference the generated content of the previous node.
[0094] It should be noted that if a node in the current tree structure has no child nodes, it is considered a leaf node. After generating this leaf node, there is no need to generate any more text. The recursive traversal algorithm call ends, that is, the AI large model is called to generate all text fragments.
[0095] To further improve the logical consistency between generated texts, a combination of depth-first search and breadth-first search is used when performing recursive traversal. Depth-first search transmits the current context information to all child nodes of the current tree structure node through a recursive function, while breadth-first search transmits the current context information to the next node at the same level of the current tree structure node through a recursive function. This ensures the logical relevance between chapters and improves the self-consistency of the generated text.
[0096] In one embodiment, the traversal method combining depth-first search and breadth-first search is as follows: A tree-structured node set generated from the text outline is traversed using a recursive traversal algorithm. For a given node, context information from the traversal is stored. First, breadth-first search is used to traverse each node, storing the data flow relationships at the same level. No content generation is performed; the data flow relationships at the same level are stored as key-value pairs. Then, depth-first search is performed. During the traversal, content generation is performed, reading the context information and the stored data flow relationships at the same level to generate the current context information. This current context information is then transmitted to all child nodes and nodes at the same level via a recursive function.
[0097] Step S500: Receive the generated text fragments in real time, and assemble the text fragments into a complete self-consistent target text according to the order of the tree structure nodes.
[0098] In one embodiment, based on the text fragments generated by the recursive traversal algorithm, the generated text fragments are received in real time via API calls, and an ordered list is maintained. The text fragments corresponding to each node are assembled according to the order of the tree-structured nodes to obtain a complete self-consistent target text. This self-consistent target text input text outline has a structure where content is interconnected and logically consistent, thus achieving the generation of text that accurately conforms to a specific structure and content.
[0099] It should be noted that a real-time streaming reception mode can be adopted to receive individual text fragments and obtain generated text fragments in real time. During streaming reception and display, a thread-safe state traversal is first initialized, streaming mode is enabled, the streaming API is called to process each stream, the token is updated after processing, text blocks are processed, and content is assembled in real time according to recursive calls. Simultaneously, a context buffer is built, and the previously generated text blocks are accumulated in real time using the `StringBuilder previous` variable. A summary of the previously completed content is used as background before each new paragraph, or as a guide to repeating content. The received text fragment is immediately appended to the traversal node to achieve streaming presentation, ensuring that the content of the previous node corresponds to the current node, achieving logical continuity. Streaming generation avoids long user wait times that could interrupt the generation process. A multi-threaded model can also be set up to ensure that multiple users provide text outlines, generating self-consistent target text. A message queue is used to distribute streaming events, improving throughput through concurrent processing. A WebSocket connection is established, and the server maintains the session. During streaming generation, each text block is pushed via WebSocket for real-time rendering.
[0100] It should also be noted that during the streaming assembly process, after appending text fragments to the traversed nodes, the rule injection module in the prompt words is used to perform format constraint validation on the generated text. This directly calls the four-layer structured instruction system of the rule injection module in the structured prompt words. Based on each layer of instructions, the text fragments generated up to the current node are validated. If the validation passes, streaming generation continues. Text validation can employ the Transformer model and spelling and grammar checks, which will not be elaborated here. If validation fails, the CompletableFuture architecture is used for concurrent generation. Validation exceptions during the generation process are captured, triggering a local reshaping mechanism for that node. This involves generating current context information, including the initial context information, based on the initial context information and the text fragments. The current context information is then encapsulated in a data transfer object and passed as a recursive parameter to all child nodes of the current tree structure node. This process regenerates the text fragments of that node, ensuring that the generated content is compliant and meets the generation requirements.
[0101] like Figure 4As shown, this application also provides a system for generating self-consistent text based on a specific structure and text content. The system obtains the outline of the text to be generated through a text acquisition module 110, identifies the hierarchical markers in the text outline, and constructs a tree-structured node set containing hierarchical relationships based on the hierarchical markers. A retrieval module 120 determines whether a knowledge base is enabled. If the knowledge base is enabled, a pre-configured retrieval strategy is executed to obtain the corresponding knowledge base text content, and initial context information is constructed based on the knowledge base text content. A traversal module 130 uses a recursive traversal algorithm to process the tree-structured node set sequentially. For the currently processed tree-structured node, the following steps are performed: Based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure nodes, the initial context information, and the acquired generation control parameters, structured prompt words are generated. A preset large model interface is called to generate text fragments corresponding to the current tree structure nodes based on the structured prompt words. Simultaneously, the traversal module 130 generates current context information, including the initial context information, based on the initial context information and text content. This current context information is encapsulated in the data transmission object and passed as recursive parameters to all child nodes of the current tree structure node. The text assembly module 140 receives the generated text fragments in real time and assembles them into a complete self-consistent target text according to the order of the tree structure nodes.
[0102] It should be noted that the text acquisition module 110 is connected to the retrieval module 120, the retrieval module 120 is connected to the traversal module 130, and the traversal module 130 is connected to the text assembly module 140.
[0103] It should also be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0104] The following describes an exemplary electronic device 700 provided in an embodiment of this application. Figure 5 This is an exemplary hardware structure diagram of the electronic device 700 provided in the embodiments of this application.
[0105] In some embodiments, the electronic device 700 is a computer device or includes a computer device. The computer device includes a processor, memory, and a network interface connected via a system bus. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device stores data. The network interface of the computer device is used to communicate with other external terminals or servers via a network connection. In some embodiments, the network interface can be a wired network interface; in some embodiments, the network interface can also be a wireless network interface. When the computer program is executed by the processor, it implements the methods in the embodiments of this application.
[0106] Those skilled in the art will understand that Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0107] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0108] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.
[0109] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
[0110] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0111] In the various embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between apparatuses or units may be electrical or other forms.
[0112] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0113] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0114] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory 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 of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, portable hard drives, magnetic disks, or optical disks.
[0115] The above are merely exemplary embodiments of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Other embodiments of this disclosure will readily conceive of those skilled in the art upon consideration of the specification and the disclosure of practical truths.
[0116] This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.
Claims
1. A method for generating self-consistent text based on a specific structure and text content, characterized in that, The method includes: Obtain the text outline to be generated, identify the hierarchical identifiers in the text outline, and construct a tree-structured node set containing hierarchical relationships based on the hierarchical identifiers; Determine whether the knowledge base is enabled. If the knowledge base is enabled, execute the pre-configured retrieval strategy to obtain the corresponding knowledge base text content, and construct initial context information based on the knowledge base text content. The tree structure node set is processed sequentially using a recursive traversal algorithm. For the currently processed tree structure node, the following steps are performed: generate structured prompt words based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure node, the initial context information, and the obtained generation control parameters; call the preset large model interface to generate the text fragment corresponding to the current tree structure node based on the structured prompt words. Simultaneously, based on the initial context information and the text fragment, current context information including the initial context information is generated, and the current context information is encapsulated into a data transmission object and passed as a recursive parameter to all child nodes of the current tree structure node; The generated text fragments are received in real time, and the text fragments are assembled into a complete self-consistent target text according to the order of the tree structure nodes.
2. The method according to claim 1, characterized in that, The process of generating current context information, including the initial context information and the text fragment, based on the initial context information and the text fragment includes: The text fragment is summarized using a preset text processing algorithm to obtain the node context information corresponding to the current tree structure node; The initial context information is embedded in the node context information to obtain the current context information, which includes the initial context information.
3. The method according to claim 2, characterized in that, The step of encapsulating the current context information into a data transmission object and passing it as a recursive parameter to all child nodes of the current tree structure node includes: Create a key-value pair collection object as the data transfer object; The current context information is stored as a fixed value in the key-value pair collection object; If the current tree structure node has child nodes, the recursive traversal algorithm is invoked, the child node is taken as the current tree structure node, the current context information is taken as the initial context information, and the key-value pair collection object is passed to the recursive function so that the initial context information can be directly read when processing the child node.
4. The method according to claim 1, characterized in that, The step of generating structured prompts based on the encapsulated data transmission object, the hierarchical relationship of the current tree structure nodes, the initial context information, and the obtained generation control parameters includes: Obtain a prompt word template, which includes a structure injection module, a knowledge injection module, a streaming history injection module, and a rule injection module; The structure injection module is filled with the set of tree-like nodes; Extract the initial context information from the data transmission object, and fill the initial context information into the knowledge injection module corresponding to the hierarchical relationship; Read the last text of the preceding node corresponding to the child node in the same hierarchical relationship, and fill the last text into the streaming history injection module; The generation control parameters are filled into the rule injection module, and the structured prompt words are formed based on the filled structure injection module, the knowledge injection module, the streaming history injection module and the rule injection module.
5. The method according to claim 4, characterized in that, The structure injection module includes title tags, chapter tags, and table of contents tags; The step of filling the structure injection module with the tree-structured node set includes: Based on the set of tree-structured nodes, extract the root node of the tree-structured nodes and fill it into the question label; Fill the parent nodes of the tree structure nodes, excluding the root node, into the chapter tags according to the hierarchical relationship; Fill all the parent nodes and their corresponding child nodes into the directory tags, and then form the filled title tags, chapter tags, and target tags into the filled structure injection module.
6. The method according to claim 1, characterized in that, The step of executing a pre-configured retrieval strategy to obtain the corresponding knowledge base text content includes: In response to the selected chunked search strategy, search keywords are determined based on the text outline; The search keywords are used to perform similarity matching in the knowledge base to obtain a preset number of related text blocks; The acquired related text blocks are serialized to obtain the knowledge base text content.
7. The method according to claim 1, characterized in that, The step of executing a pre-configured retrieval strategy to obtain the corresponding knowledge base text content includes: In response to selecting a pre-configured full search strategy, a preset file identifier is matched according to the text outline, and the complete content of the corresponding file in the knowledge base is read using the text identifier; Determine whether the length of the complete content exceeds a preset threshold; If the preset threshold is not exceeded, the complete content will be used as the knowledge base text content.
8. An electronic device, characterized in that, It includes one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the electronic device to perform the method as described in any one of claims 1-7.
9. A computer program product containing instructions, characterized in that, When the computer program product is run on an electronic device, it causes the electronic device to perform the method as described in any one of claims 1-7.
10. A computer-readable storage medium comprising instructions, characterized in that, When the instructions are executed on an electronic device, the electronic device causes the electronic device to perform the method as described in any one of claims 1-7.