Text format adjustment method and system based on large language model code generation
By building an API vector knowledge base and generating text formatting adjustment code using a large language model, the problems of complex format template design and numerous mouse operations in existing technologies are solved, achieving flexible and efficient text formatting adjustment.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- INSTITUTE OF INFORMATION ENGINEERING CHINESE ACADEMY OF SCIENCES
- Filing Date
- 2024-10-30
- Publication Date
- 2026-05-07
AI Technical Summary
In existing technologies, text formatting adjustment tools require predefined format templates, which have a high technical threshold, are inflexible, and are difficult to adapt to changing text format requirements. Furthermore, modifying long documents requires a large number of mouse operations.
An API vector knowledge base is built based on a large language model. Text format adjustment code is generated based on the user's input format adjustment requirements, reducing the workload of template design, adapting to various format requirements, and using the large language model to generate executable code for automatic adjustment.
It simplifies user operations, reduces mouse operations, and improves the flexibility and efficiency of text formatting adjustments, adapting to various text format requirements.
Smart Images

Figure CN2024128369_07052026_PF_FP_ABST
Abstract
Description
A Method and System for Adjusting Text Formatting Based on Large Language Model Code Generation Technical Field
[0001] This invention relates to the field of text typesetting technology, and in particular to a method and system for adjusting text format based on large language model code generation. Background Technology
[0002] Text formatting is a crucial part of document writing, significantly impacting document quality, meeting diverse needs, and improving work efficiency. It makes documents more standardized, professional, and adaptable to different scenarios, providing users with a better reading experience. However, formatting excessively long documents or those created collaboratively by multiple people can be a tedious task. Therefore, developing a text formatting tool to help users efficiently and quickly adjust text formatting is essential. With this tool, users can quickly adjust formatting, avoiding repetitive operations, saving time and effort, and allowing them to dedicate more time to content creation and core tasks.
[0003] Currently, tools for adjusting text formatting mainly include Little Dinosaur Document Formatting Assistant and No-Pit Box Formatting Assistant. Little Dinosaur Document Formatting Assistant provides users with quick document formatting functions by embedding pre-defined format templates into Word as a plugin. No-Pit Box Formatting Assistant automatically adjusts text formatting based on rules. As shown in Figure 1, this software has designed different writing formats and matching rules for different text formats. During automated text formatting, it uses regular expressions to identify the format type of different paragraphs and adjusts them to the corresponding format.
[0004] It can be seen that existing text formatting adjustment methods are mainly rule-based, requiring developers to pre-create format templates and develop corresponding plugins for users. The creation of these format templates requires software development skills, posing a significant technical barrier for users. Secondly, predefined format templates are relatively fixed and limited in number, unable to flexibly address diverse text formatting requirements, thus restricting user access when faced with documents of different styles. Finally, when users need to modify the format of long documents, existing technologies require extensive mouse operations or suffer from templates that cannot flexibly adapt to various text formatting needs.
[0005] Summary of the Invention
[0006] To address the problems of high design threshold, inflexibility, and excessive mouse operations in existing text format templates, this invention proposes a text format adjustment method and system based on large language model code generation. This method can reduce the workload of developing and designing text format templates and can more flexibly handle various format requirements.
[0007] According to a first aspect of the present disclosure, a method for adjusting text formatting based on large language model code generation is provided, including:
[0008] Based on the development documentation of the target software, an API vector knowledge base is constructed, which includes vector representations of text formatting adjustment attributes and knowledge fragments of those attributes.
[0009] Obtain user formatting requirements and input / output examples;
[0010] The user formatting adjustment requirements are vectorized, and by matching the vector representation of the user formatting adjustment requirements with the vector representation of the text formatting adjustment attributes, the corresponding knowledge fragments and input / output examples of the text formatting adjustment attributes are obtained.
[0011] The user's formatting requirements and the corresponding text formatting attributes are embedded into the code generation prompt word template along with the knowledge fragments and input / output examples, and the text formatting result R1 is generated based on the large language model.
[0012] Furthermore, when the target software is Office Word, the text formatting adjustment attributes include: alignment, left margin, first-line indent, line spacing, outline level, right margin, paragraph spacing before, paragraph spacing after, bold, italic, color, underline, font name, font size, highlight color, strikethrough, double strikethrough, subscript, and superscript.
[0013] Furthermore, the construction of an API vector knowledge base based on the development documentation of the target software includes:
[0014] In the development documentation of the target software, obtain knowledge fragments of each text formatting adjustment attribute. These knowledge fragments include: descriptions, value types, and example code.
[0015] Encode the knowledge fragments of the text formatting adjustment attributes to obtain a vector representation of the text formatting adjustment attributes;
[0016] The vector representation of the text formatting attribute and the knowledge fragment of the text formatting attribute are stored in the API vector knowledge base.
[0017] Furthermore, the process of obtaining input / output examples includes:
[0018] Based on the matching results between the vector representation of the user's formatting adjustment requirements and the vector representation of the text formatting adjustment attributes, at least one preset example is selected from the preset example library as the input and output examples;
[0019] or,
[0020] Based on the matching results between the vector representation of the user's formatting adjustment requirements and the vector representation of the text formatting adjustment attributes, at least one preset example is selected from the preset example library;
[0021] The preset example is adjusted according to user needs to obtain the input and output examples.
[0022] Furthermore, the content of the code-generated prompt template includes: task description, knowledge list, input / output examples, user format modification requirements, and output code.
[0023] Furthermore, after generating the text format adjustment result R1 based on the large language model, the process also includes:
[0024] Adjusting the text formatting result R i Parsed into executable code C i And run, where i is the iteration number;
[0025] If the executable code C i If an error occurs during execution, and the iteration count i is less than the maximum iteration count, the error message and error code are embedded into the error code correction prompt template, and the text formatting adjustment result R is obtained based on the large language model. i+1 Subsequently, based on the text format adjustment result R i+1 Re-execute the text formatting adjustment result R i Parsed into executable code C i And run;
[0026] If the executable code C i If no errors are reported during the process, or if the iteration count i equals the maximum iteration count, then the output text formatted result R is adjusted. i .
[0027] Furthermore, the error code correction prompt template includes: task description, error code, error message, and correction code.
[0028] According to a second aspect of the present disclosure, a text formatting adjustment system based on large language model code generation is provided, the system comprising:
[0029] The module is used to build an API vector knowledge base based on the development documentation of the target software. The API vector knowledge base contains vector representations of text formatting attributes and knowledge fragments of the text formatting attributes.
[0030] The acquisition module is used to acquire user formatting requirements and input / output examples;
[0031] The matching module vectorizes the user's format adjustment requirements and obtains the corresponding knowledge fragments and input / output examples of the text format adjustment attributes by matching the vector representation of the user's format adjustment requirements with the vector representation of the text format adjustment attributes.
[0032] The generation module is used to embed the user's format adjustment requirements and the corresponding text format adjustment attributes, along with knowledge fragments and input / output examples, into the code generation prompt word template, and generate the text format adjustment result R1 based on the large language model.
[0033] According to a third aspect of the present disclosure, an electronic device is provided, the electronic device comprising: a processor and a memory storing computer program instructions; wherein the processor, when executing the computer program instructions, implements the text format adjustment method based on large language model code generation as described above.
[0034] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, characterized in that the computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the text format adjustment method based on large language model code generation as described above.
[0035] According to a fifth aspect of the present disclosure, a computer program product is provided, characterized in that, when the computer program product is run on a computer device, the computer device executes the text format adjustment method based on large language model code generation as described above.
[0036] Compared with the prior art, the present invention has at least the following beneficial effects.
[0037] First, the purpose of this invention is to reduce the time users spend modifying the format of long document text. Existing technologies, such as the Little Dinosaur Document Formatting Assistant, still require selecting and formatting the text to be modified, necessitating significant mouse operations. However, using the technology proposed in this invention, users only need to input the location and format of the text to be modified; the corresponding text formatting adjustment is handled by a large language model and the runtime environment, saving users time and simplifying mouse operations.
[0038] Secondly, compared to existing technologies, this invention can adapt to a wider range of text formats. Different types of documents have different formatting requirements, such as graduation theses, business plans, and government documents. Existing technologies can only pre-define corresponding format templates for different document types, requiring developers to modify these templates when formatting requirements change, resulting in poor flexibility. This invention, however, eliminates the need for developers and users to modify or create templates, and can adapt to a wider range of text formats. Attached Figure Description
[0039] Figure 1 shows the automatic layout rule settings for the No-King Box.
[0040] Figure 2 is a flowchart of the text formatting adjustment method based on large language model code generation. Detailed Implementation
[0041] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.
[0042] This invention aims to use a large language model to take the user's text format modification request as input and query in natural language form, retrieve the corresponding knowledge fragments in the knowledge base, and guide the large language model to generate executable document format adjustment code based on prompt word strategy. The generated code is then sent to a runtime environment for execution to adjust the text format.
[0043] The following explanation uses Microsoft Word as an example. The document format code generation technology is based on a large language model with code generation capabilities, and the executable environment for the document format modification code is based on Microsoft Word and Office Add-ins.
[0044] As shown in Figure 2, the text format adjustment method based on large language model code generation of the present invention includes the following steps 1 to 4.
[0045] Step 1: Build an API vector knowledge base based on the development documentation of the target software.
[0046] This embodiment targets Microsoft Word as the text formatting adjustment software; therefore, an API vector knowledge base is constructed based on the Microsoft Office Add-ins Word development documentation. This invention selects the Microsoft Office Add-ins Word development documentation for paragraph and font formatting adjustments to construct the API vector knowledge base. The API vector knowledge base consists of two parts: an embedding model and a vector repository, used to store multiple knowledge fragments related to text formatting adjustments APIs. Specifically, each knowledge fragment in the knowledge base corresponds to a text formatting adjustment attribute, where the knowledge fragment includes a description of the text formatting adjustment attribute, its value type, and sample code. Table 1 shows an example of a knowledge fragment.
[0047] Table 1
[0048] In the knowledge base, this embodiment filters a total of 19 text formatting adjustment attributes, including: alignment, leftIndent, firstLineIndent, lineSpacing, outlineLevel, rightIndent, spaceBefore, spaceAfter, bold, italic, color, underline, name, size, highlightColor, strikeThrough, doubleStrikeThrough, subscript, and superscript.
[0049] In its storage design, the API vector knowledge base uses the Faiss vector database as its storage database and the E5-Base model as its embedding encoding model. During storage, a knowledge fragment is encoded as a vector and stored in the Faiss database for easy querying and retrieval of knowledge fragments.
[0050] It should be noted that if Microsoft Word is replaced with other software, the knowledge fragments in the API Vector Knowledge Base also need to be replaced with the corresponding API development documentation for that other software.
[0051] Step 2: Obtain user format adjustment requirements.
[0052] This invention builds a runtime environment for the Office Add-ins Word project based on the Microsoft Word development documentation. This runtime environment mainly includes four functionalities: receiving user input and sending it to a backend large language model; providing an editable environment with input / output examples for the user; receiving and executing code generated by the large language model; and providing feedback on the code execution results. This step primarily utilizes the first functionality.
[0053] It should be noted that if Microsoft Word is replaced with other software, the operating environment also needs to be replaced with the corresponding operating environment of the other software.
[0054] Step 3: Vectorize the user formatting adjustment requirements. By matching the vector representation of the user formatting adjustment requirements with the vector representation of the text formatting adjustment attributes, obtain the corresponding knowledge fragments and input / output examples of the text formatting adjustment attributes.
[0055] This step first vectorizes the user's input format adjustment requirements, then uses these vectorized requirements as query conditions. By matching the vector representations of the text format adjustment attributes, the corresponding knowledge fragments are obtained. Based on these text format adjustment attributes, at least one preset example is selected from a preset example library. Users can directly use this preset example as input / output examples, or they can further modify it according to their needs to obtain different input / output examples.
[0056] In this embodiment, during matching and retrieval, the user's text formatting requirement is used as the query. After being encoded by the embedding model, it is queried in the Faiss database to find the top n knowledge fragments with the highest similarity. In practical use, other products with the same functionality can be used instead of vector databases and embedding models.
[0057] In this embodiment, the preset examples are shown in Table 2.
[0058] Table 2
[0059] Step 4: Embed the user's formatting requirements and the corresponding text formatting attributes, along with input / output examples, into the code generation prompt template, and generate the text formatting result R1 based on the large language model.
[0060] Table 3 is an example of a code generation prompt template. This template mainly includes a task description, a knowledge list, input / output examples, user formatting modification requirements, and output code. This invention embeds the user formatting requirements, the corresponding knowledge fragments of text formatting attributes, and input / output examples into the code generation prompt template, guiding the large language model to generate the corresponding text formatting result R1 and output it to the executable environment.
[0061] Table 3
[0062] In this step, the selectable large language model can be any large language model with code generation capabilities; the model's capabilities will affect the performance of this invention. A default version of the preset example is provided in this invention, and users can modify it according to their actual needs. In the prompt word template, the "##User Format Modification Request##" field is filled with the user's input format adjustment request, the "##APIs Knowledge List##" section is filled with knowledge fragments retrieved from the API vector knowledge base, and the "##Input / Output Example##" section is filled with preset examples. The default values for the number of knowledge fragments and preset examples are 15 and 17, respectively, but users can modify them according to their actual needs in practice.
[0063] It should be noted that if Microsoft Word is replaced with other software, the details in the code-generated prompts will also need to be modified according to the specific situation.
[0064] In one embodiment, the invention further includes step 5.
[0065] Step 5: Optimize the text formatting result R1.
[0066] This invention runs format-adjusted code generated by a large language model in an executable environment. Since the code generated by the large language model is all string type, during code execution, the plugin needs to parse the generated code from strings into executable code and run it. If an error occurs during execution, the error message and error code are input to the backend large language model. The large language model reads the error message and error code, generates modified code, and then inputs the regenerated code into the executable environment for execution. This process is repeated until the execution succeeds or the maximum number of iterations is reached. The error code correction prompt template is shown in Table 4.
[0067] Table 4
[0068] As is easily understood, the above implementation scheme uses Microsoft Word as an example to illustrate the technical solution of this invention. This method is also applicable to the development of other software, such as Microsoft PowerPoint, Excel, WPS Word, and PPT. If replaced with WPS Word, the corresponding knowledge fragment examples and preset example samples are shown in Tables 5 and 6, respectively.
[0069] Table 5
[0070] Table 6
[0071] In summary, this invention is based on a large language model, allowing users to submit text formatting requirements in natural language. The large language model analyzes the user's requirements and generates corresponding text formatting adjustment code. The corresponding code is then run in a runtime environment to ultimately achieve text formatting adjustment.
[0072] Based on the same concept, this invention also discloses a text formatting adjustment system based on large language model code generation, the system comprising:
[0073] The module is used to build an API vector knowledge base based on the development documentation of the target software. The API vector knowledge base contains vector representations of text formatting attributes and knowledge fragments of the text formatting attributes.
[0074] The acquisition module is used to acquire user formatting requirements and input / output examples;
[0075] The matching module vectorizes the user's format adjustment requirements and obtains the corresponding knowledge fragments and input / output examples of the text format adjustment attributes by matching the vector representation of the user's format adjustment requirements with the vector representation of the text format adjustment attributes.
[0076] The generation module is used to embed the user's format adjustment requirements and the corresponding text format adjustment attributes, along with knowledge fragments and input / output examples, into the code generation prompt word template, and generate the text format adjustment result R1 based on the large language model.
[0077] Based on the same concept, the present invention also discloses an electronic device, the electronic device comprising: a processor and a memory storing computer program instructions; wherein the processor, when executing the computer program instructions, implements the text format adjustment method based on large language model code generation described above.
[0078] Based on the same concept, the present invention also discloses a computer-readable storage medium, characterized in that the computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the text format adjustment method based on the large language model code generation described above.
[0079] Based on the same concept, the present invention also discloses a computer program product, characterized in that, when the computer program product is run on a computer device, the computer device executes the text format adjustment method based on the large language model code generation described above.
[0080] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them. Although the present invention 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 or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.
Claims
1. A text formatting adjustment method based on large language model code generation, comprising the following steps: Based on the development documentation of the target software, an API vector knowledge base is constructed, which includes vector representations of text formatting adjustment attributes and knowledge fragments of those attributes. Obtain user formatting adjustment requests; The user formatting adjustment requirements are vectorized, and by matching the vector representation of the user formatting adjustment requirements with the vector representation of the text formatting adjustment attributes, the corresponding knowledge fragments and input / output examples of the text formatting adjustment attributes are obtained. The user's formatting requirements and the corresponding text formatting attributes are embedded into the code generation prompt word template along with the knowledge fragments and input / output examples, and the text formatting result R1 is generated based on the large language model.
2. The method according to claim 1, characterized in that, The target software is Office Word, and the text formatting adjustment attributes include: alignment, left margin, first-line indent, line spacing, outline level, right margin, spacing before and after paragraphs, bold, italic, color, underline, font name, font size, highlight color, strikethrough, double strikethrough, subscript, and superscript.
3. The method according to claim 1, characterized in that, The API vector knowledge base, constructed based on the development documentation of the target software, includes: In the development documentation of the target software, obtain knowledge fragments of each text formatting adjustment attribute. These knowledge fragments include: descriptions, value types, and example code. Encode the knowledge fragments of the text formatting adjustment attributes to obtain a vector representation of the text formatting adjustment attributes; The vector representation of the text formatting attribute and the knowledge fragment of the text formatting attribute are stored in the API vector knowledge base.
4. The method according to claim 1, characterized in that, The process of obtaining the input / output examples includes: Based on the matching results between the vector representation of the user's formatting adjustment requirements and the vector representation of the text formatting adjustment attributes, at least one preset example is selected from the preset example library as the input and output examples; or, Based on the matching results between the vector representation of the user's formatting adjustment requirements and the vector representation of the text formatting adjustment attributes, at least one preset example is selected from the preset example library; The preset example is adjusted according to user needs to obtain the input and output examples.
5. The method according to claim 1, characterized in that, The content of the code generation prompt template includes: task description, knowledge list, input / output examples, user format modification requirements, and output code.
6. The method according to any one of claims 1 to 5, characterized in that, After generating the text format adjustment result R1 based on the large language model, the following is also included: Adjusting the text formatting result R i Parsed into executable code C i And run, where i is the iteration number; If the executable code C i If an error occurs during execution, and the iteration count i is less than the maximum iteration count, the error message and error code are embedded into the error code correction prompt template, and the text formatting adjustment result R is obtained based on the large language model. i+1 Subsequently, based on the text format adjustment result R i+1 Re-execute the text formatting adjustment result R i Parsed into executable code C i And run; If the executable code C i If no errors are reported during the process, or if the iteration count i equals the maximum iteration count, then the output text formatted result R is adjusted. i .
7. The method according to claim 6, characterized in that, The error code correction prompt template includes: task description, error code, error message, and correction code.
8. A text formatting adjustment system based on large language model code generation, comprising: The module is used to build an API vector knowledge base based on the development documentation of the target software. The API vector knowledge base contains vector representations of text formatting attributes and knowledge fragments of the text formatting attributes. The acquisition module is used to acquire user formatting requirements and input / output examples; The matching module vectorizes the user's format adjustment requirements and obtains the corresponding knowledge fragments and input / output examples of the text format adjustment attributes by matching the vector representation of the user's format adjustment requirements with the vector representation of the text format adjustment attributes. The generation module is used to embed the user's format adjustment requirements and the corresponding text format adjustment attributes, along with knowledge fragments and input / output examples, into the code generation prompt word template, and generate the text format adjustment result R1 based on the large language model.
9. An electronic device, characterized in that, The electronic device includes: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, it implements the text format adjustment method based on large language model code generation as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the text formatting adjustment method based on large language model code generation as described in any one of claims 1-7.
11. A computer program product, characterized in that, When the computer program product is run on a computer device, the computer device performs the text formatting adjustment method based on large language model code generation as described in any one of claims 1-7.
Citation Information
Patent Citations
Typesetting method and device, electronic equipment and computer readable storage medium
CN113935281A
Method and system for automatically generating reusable API based on code snippets
CN117892031A
Automatic document formatting method and system
CN118690722A
Recruitment industry resume screening method and system based on LLM and knowledge base retrieval
CN118796904A
Big model-based official document generation method and device, and storage medium
CN118861276A
Cited By
Backend computer program generation method and apparatus
CN122284967A