Large language model guide prompt template placeholder analysis method and system
By decomposing the template string into characters and using a matcher for character matching, the problem that placeholder formats cannot be flexibly adjusted in the template engine is solved, and support for multiple placeholder formats and custom formats is achieved, improving the Prompt templates are universal and safe.
Patent Information
- Application Number
- CN202411336842.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2024-12-27
AI Technical Summary
When existing template engines use different large language models, the placeholder format cannot be flexibly adjusted, resulting in poor versatility of Prompt templates and complex logic and security risks, making it difficult to adapt to multiple placeholder formats and custom formats.
Provide a large language model boot prompt template placeholder parsing method and system, decompose template strings into characters through parser, and use matchers to match characters by character, supporting multiple placeholder formats and custom formats to avoid Regular expression matching improves placeholder flexibility and security.
It realizes flexible adaptation to different large language models, simplifies template processing flow, improves analysis efficiency, avoids backtracking problems, and enhances the compatibility and security of placeholder formats.
Smart Images

Figure CN119203974A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a large language model guided prompt template placeholder parsing method and system. Background Art
[0002] In the process of interacting with the AI big model, the Prompt template is used to stimulate the communication and answering process of the big language model. The Prompt template defines a fixed-format text structure and uses placeholder variables to mark replaceable content, making it convenient for the object to dynamically generate specific Prompt information in actual application.
[0003] A placeholder variable consists of a start flag, a variable name, and an end flag. For example, "{{name}}" in "Hello{{name}}" is a placeholder. The object can fill the Prompt template by providing corresponding values for each placeholder, and finally generate specific Prompt information.
[0004] To achieve this placeholder replacement operation, related technologies rely on template engine technology, such as Jinja, Handlebars, and Mustache, which are widely used in the field of Web development, mainly for dynamically generating HTML pages, and provide developers with functions such as template parsing and variable replacement, thereby simplifying the separation of the front-end interface and the back-end logic. However, there are many problems in using the template engine directly for the generation of Prompt templates. The placeholder variable format of each template engine is fixed at the beginning of the design. For example, Jinja stipulates that placeholders must be wrapped in "{{" and "}}". Different placeholder formats may be used for different AI large model applications. However, the existing template engines limit the versatility of templates due to fixed grammatical rules, and the placeholder naming flexibility is poor, resulting in the Prompt template cannot be flexibly changed between different large language models. Summary of the invention
[0005] In view of this, the present invention provides a large language model guided prompt template placeholder parsing method and system to solve how to improve the flexibility of Prompt template placeholder setting.
[0006] In a first aspect, the present invention provides a large language model guided prompt template placeholder parsing device, including a parser and a matcher;
[0007] The parser is used to obtain a guide prompt template string uploaded by the object; decompose the guide prompt template string into at least one character, and sequentially pass the at least one character to the matcher, wherein the guide prompt template string represents a preset text instruction framework, which is used to guide or stimulate the large language model to generate response content;
[0008] The matcher is used to match the characters passed in in sequence and return matching response information to the parser;
[0009] The parser is also used to determine whether the matcher successfully matches at least one character based on the matching response information; if any matcher successfully matches at least one character, the matcher returns target placeholder information corresponding to at least one character after the match is successful; the target placeholder information is displayed on the human-computer interaction page so that the object can modify the target placeholder information through the human-computer interaction page to facilitate the generation of a new guidance prompt template.
[0010] The embodiment of the present invention is applied to a large language model guidance prompt template placeholder parsing system. The parser decomposes the entire guidance prompt template string into at least one character and gradually passes it to the matcher for parsing. Any form of placeholder format can be parsed, such as "{{}}" of the Jinja template engine, "{{{and}}}" of the Mustache template engine, or the definition format of other template engines. This avoids the limitation that traditional template engines only support fixed placeholder formats and improves the flexibility of placeholder parsing. The matcher can identify and parse a variety of placeholder forms based on character-by-character matching operations, and can also be a customized format, and is not limited to a specific template engine syntax. This solves the problem in the related art that the template engine cannot be flexibly adjusted when different large language models use different placeholder formats, thereby improving the versatility of the guidance prompt template. The characters are parsed by the parser and passed into the matcher. The matcher matches the characters one by one to obtain flexible placeholder information. It can adapt to various existing placeholder formats in the field and even analyze custom placeholder formats. It overcomes the problems of fixed placeholder formats and poor versatility in related technologies, and greatly improves the flexibility of the placeholders of the guidance prompt template in the interaction of AI large models.
[0011] In a second aspect, the present invention provides a large language model guided prompt template placeholder parsing method, which is applied to a parser, and the method includes:
[0012] Get the template string of the boot prompt for object upload;
[0013] Decomposing the guide prompt template string into at least one character, and sequentially passing the at least one character into the matcher, so that the matcher sequentially matches the characters passed in, and returns matching response information to the parser;
[0014] The guiding prompt template character string represents a preset text instruction framework, which is used to guide or stimulate the large language model to generate response content;
[0015] Whether the matcher successfully matches at least one character is determined based on the matching response information; if any matcher successfully matches at least one character, then after the match is successful, the matcher returns the target placeholder information corresponding to the at least one character, and displays the target placeholder information on the human-computer interaction page, so that the object can modify the target placeholder information through the human-computer interaction page, thereby facilitating the generation of a new guidance prompt template.
[0016] The embodiment of the present invention decomposes the guidance prompt template string into characters and sends these characters to the matcher one by one. The matcher can flexibly identify and parse the placeholders in the template. The object can modify the placeholders according to actual needs to generate a guidance prompt template that meets the specific application scenario. Compared with the complex logic and strict placeholder naming restrictions of the existing template engine, this embodiment simplifies the template processing flow, avoids the backtracking problem, and improves the parsing efficiency. By gradually matching the placeholders and dynamically modifying them in the human-computer interaction interface, more flexible placeholder format support is provided, which improves the flexibility of placeholder parsing.
[0017] In an optional implementation, before the step of decomposing the guidance prompt template string into at least one character and sequentially passing the at least one character into the matcher, the step further includes:
[0018] Obtain one or more placeholder formats corresponding to the boot prompt template string uploaded by the object;
[0019] A corresponding matcher is created according to the placeholder format, wherein each placeholder format corresponds to a matcher.
[0020] In an embodiment of the present invention, since the placeholder formats in the engine template of the large language model may be different, by creating a specific matcher for each placeholder format, the matcher can more accurately identify the corresponding placeholder and is less likely to produce mismatches. In other words, the placeholder format is no longer limited to the format type defined by the object itself. As long as there is a placeholder of a new format in a new guidance prompt template, a new matcher can be created for matching, thereby improving the flexibility of placeholder settings.
[0021] In an optional implementation, the matcher is represented by a matching function, and the matching function represents a logic code for matching characters; and the step of creating a corresponding matcher according to the placeholder format specifically includes:
[0022] Extracting the placeholder marker in the placeholder format and the number of the placeholder markers;
[0023] The placeholder marker and the number of the placeholder markers are input as input parameters to a preset matcher creation function to obtain a return parameter of the matcher creation function; wherein the return parameter includes a logic code of a matching character corresponding to the matching function.
[0024] In the embodiment of the present invention, the matcher is represented by a matching function, and the matching function represents the logic code for matching characters, that is, the matching logic of the placeholder can be set completely freely, and the matching logic is set according to different placeholders, and is no longer limited to the preset syntax of a specific template engine. The parser can extract the placeholder identifier and quantity in the placeholder format, and input them as parameters to the matcher creation function. The parameters returned by the matcher creation function include the logic code required by the matching function, that is, the parser can dynamically create a matcher according to the actual boot template, further improving the flexibility of the matcher when matching placeholders.
[0025] In an optional implementation, the method further includes:
[0026] The priority of each matcher is determined according to the number of the placeholder markers corresponding to the matcher, wherein the size of the priority is negatively correlated with the number of the placeholder markers corresponding to the matcher, and the priority is used to indicate the sorting order of each matcher when at least one character is passed into the matcher.
[0027] The parser of the embodiment of the present invention determines the priority of each matcher according to the number of placeholder identifiers of each matcher, and the priority is negatively correlated with the number of identifiers. That is to say, the fewer the characters of the start and end identifiers, the higher the priority of the matcher, so that the placeholders in the short character format (such as {{}}) can be matched first and parsed first during template parsing. By sorting according to the priority of the placeholder identifiers, placeholders of different lengths and formats can coexist in the same parsing process without causing conflicts due to the parsing order, so that a variety of nested and parallel placeholder formats can be supported in the template, which greatly improves the compatibility and flexibility of the placeholder format.
[0028] In an optional implementation, the step of sequentially passing the at least one character into the matcher specifically includes:
[0029] Assigning an index value to each of the characters;
[0030] The characters and the corresponding index values are sequentially transmitted to each matcher corresponding to the priority level according to the priority level of each matcher.
[0031] The embodiment of the present invention assigns index values to all characters respectively, providing an index basis in the subsequent matcher matching process, and according to the priority, a shorter placeholder identifier can be matched earlier during template parsing. When a shorter placeholder is successfully matched, the parser no longer needs to try to pass the part of characters to other low-priority matchers for matching, thereby reducing unnecessary repeated matching operations and saving computing resources. At the same time, since each character is transmitted separately, the combination of different characters can be freely set without affecting the effect of the characters forming the overall placeholder, supporting a variety of different placeholder formats and improving the flexibility of template placeholder parsing.
[0032] In an optional embodiment, the method further includes:
[0033] If any matcher matches successfully, the characters in the placeholder buffer corresponding to all other matchers are cleared.
[0034] In the embodiment of the present invention, when any matcher matches successfully, the cache of other matchers is immediately cleared, which is beneficial for processing nested placeholders. Since placeholders may be nested, only the innermost placeholders are considered legal. Clearing the cache of other matchers can ensure that when processing nested structures, the outer placeholders will not affect the matching of the inner placeholders, thereby improving the flexibility of processing nested placeholders.
[0035] In a third aspect, the present invention provides a large language model guided prompt template placeholder parsing method, which is applied to a matcher, and the method comprises:
[0036] Match the characters passed in one by one;
[0037] The matching response information is returned to the parser.
[0038] The embodiment of the present invention gradually matches the incoming characters and returns the matched response information to the parser, thereby flexibly parsing placeholders of different formats, thereby solving the problem of limited placeholder formats in existing engines. Secondly, no regular expression matching is required, which avoids performance problems caused by backtracking and ensures the flexibility of placeholder naming.
[0039] In an optional implementation, each matcher corresponds to a placeholder buffer; the placeholder buffer includes a start flag buffer, a placeholder name buffer, and an end flag buffer; the matching is performed in sequence according to the characters input, specifically including:
[0040] Store the current character in the start mark buffer, and compare the current character with the preset placeholder start symbol;
[0041] If the current character is different from the preset placeholder start symbol, clear the character in the start mark buffer, continue to obtain the next character and re-store the next character in the start mark buffer, and compare the next character with the preset placeholder start symbol. When the next character is the same as the preset placeholder start symbol, determine that the next character is the first target character, and store the first target character in the storage space of the start mark buffer; until the storage space of the start mark buffer is completely occupied by the first target character, stop storing characters in the start mark buffer;
[0042] Recording the start mark index value corresponding to the last first target character stored in the start mark buffer;
[0043] When it is determined that the character storage in the start mark buffer is no longer continued, the next character corresponding to the last first target character in the start mark buffer is continuously acquired, and the next character of the last first target character is stored in the placeholder name buffer and the end mark buffer;
[0044] Compare each character after the last first target character with the preset placeholder end symbol, and if one or more consecutive characters after the first target character are different from the preset placeholder end symbol, clear the characters in the end mark buffer;
[0045] When a second target character identical to the preset placeholder end symbol is obtained, the second target character is stored in the end mark buffer area; and the next character after the second target character is obtained.
[0046] and comparing the next character after the second target character with the preset placeholder end symbol until the end mark buffer is completely occupied by the second target character, and no more characters are stored in the end mark buffer;
[0047] Recording the end mark index value corresponding to the last second target character stored in the end mark buffer at this time;
[0048] Remove the characters in the placeholder name buffer area that are the same as those in the end mark buffer area to obtain the placeholder name information, and record the index value corresponding to the placeholder name information at this time;
[0049] The characters in the start mark buffer area are used as the start mark information, and the characters in the end mark buffer area are used as the end mark information, and the target placeholder information is generated according to the start mark information, the end mark information, the placeholder name information, the start mark index value, the end mark index value, and the index value corresponding to the placeholder name information.
[0050] In the embodiment of the present invention, each matcher has a separate cache space, including a start mark cache area, a placeholder name cache area and an end mark cache area. The start mark, the placeholder name and the end mark are stored in different cache areas respectively. Different cache areas are processed independently, avoiding confusion of the placeholder format content, which is conducive to flexible parsing of the placeholder format. Through operations for different cache areas, the start symbol and the end symbol are allowed to be compared step by step. When the matcher performs character comparison, if the current character does not match the preset symbol, the character in the cache area will be cleared and the matching will be restarted. Even if characters that do not conform to the rules appear in certain positions, the overall matching process will not be affected. Only when a whole mark (the first target character and the second target character) are completely matched, the match will be determined to be successful. The matcher not only records the index values corresponding to the start and end marks, but also generates target placeholder information according to these index values, accurately locates the start and end positions of each placeholder, and effectively marks the index position of the placeholder when processing multiple placeholders at the same time, thereby improving the flexibility of parsing the placeholder characters.
[0051] In an optional implementation, the method further includes:
[0052] The number of characters stored in the start mark buffer is recorded, and the starting position of the placeholder name is determined according to the index value corresponding to the placeholder name information and the number of characters stored in the start mark buffer.
[0053] The embodiment of the present invention directly calculates the position according to the number of characters in the buffer area and the index value, which can avoid the string matching algorithm of traversing again, directly locate the position of the placeholder name, and further reduce the matching process of the matcher.
[0054] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the large language model guided prompt template placeholder parsing method of any corresponding implementation manner of the second aspect or the third aspect above.
[0055] In a fifth aspect, the present invention provides a computer program product, including computer instructions, which are used to enable a computer to execute the large language model guided prompt template placeholder parsing method of any corresponding implementation method of the second aspect or the third aspect above. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the related technologies, the drawings required for use in the specific embodiments or the related technical descriptions will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0057] Figure 1 is a structural schematic diagram of a large language model guided prompt template placeholder parsing device according to an embodiment of the present invention;
[0058] Figure 2 is a flowchart of a method for parsing a placeholder of a large language model-guided prompt template according to an embodiment of the present invention;
[0059] Figure 3 is a character parsing schematic diagram of a large language model guided prompt template placeholder parsing method according to an embodiment of the present invention;
[0060] Figure 4 is a schematic diagram of the matching principle of a matcher according to a large language model guided prompt template placeholder parsing method according to an embodiment of the present invention;
[0061] Figure 5 is a flow chart of another method for parsing a placeholder of a language model-guided prompt template according to an embodiment of the present invention;
[0062] Figure 6 is a flow chart of another method for parsing a placeholder of a language model-guided prompt template according to an embodiment of the present invention;
[0063] Figure 7 is an application sequence diagram of a large language model guided prompt template placeholder parsing system according to an embodiment of the present invention;
[0064] Figure 8 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0065] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0066] When interacting with AI big model applications, objects usually store some fixed format or text that can be more easily understood by big models as prompt templates. Some placeholder variables are set in the prompt template. When using the prompt template, the corresponding placeholder variables are replaced with real information.
[0067] The placeholder variable in the prompt template usually consists of a start mark, a variable name, and an end mark. For example, in the string "Hello{{name}}", "{{name}}" constitutes a placeholder variable, and the object will replace "{{name}}" with real information when it is used.
[0068] AI large model applications usually provide a friendly interactive interface to simplify the operation process of objects using Prompt templates, and do not require objects to manually modify the placeholder variables in the template. When implementing this operation logic, it is necessary to parse the placeholder variables in the Prompt template, then the object sets a value for each placeholder variable, and finally fills the value set by the object into the template to generate a complete Prompt message.
[0069] In related technologies, a technology called template engine is usually used to perform these operations. For example, commonly used third-party tools such as Jinja, Handlebars, and Mustache can be used to parse prompt templates and generate prompt information. However, the original intention of the template engine is to generate HTML pages, and there are great limitations when using it to process prompt information. The more obvious disadvantages are as follows:
[0070] (1) The template engine not only provides the function of replacing placeholder variables, but also comes with complex logical operations such as filters, conditional judgments, and loops. As a result, the final code package is often large and difficult to directly apply to lightweight WEB programs, because these programs usually require a smaller size to improve loading speed and operating efficiency.
[0071] (2) The placeholder variable format of each template engine is fixed at the beginning of the design. For example, Jinja stipulates that placeholders must be wrapped in "{{" and "}}". Different placeholder formats may be used for different AI large model applications, and the existing template engines cannot flexibly adapt to these changes. The same set of prompt templates is difficult to reuse in different applications, which limits the degree of sharing of template engines.
[0072] (3) Most template engines are designed based on a certain programming language. For example, Jinja is designed for Python. Therefore, the placeholder variable name must follow the variable naming rules of the corresponding language. It is not possible to arbitrarily specify characters as placeholder names, such as the use of hyphens (-) or spaces. In some cases, the placeholders of the prompt template may need to use non-standard names, such as names with special symbols, and existing template engines have difficulty handling such requirements.
[0073] (4) Template engines usually use regular expressions to match and parse placeholders in templates. Regular expressions are prone to "backtracking" problems when processing complex text. When multiple matching paths exist, the regular expression engine needs to try every possible path, fall back after failure, and try other paths. Backtracking mechanisms often exist in template engines, which greatly affects computing performance when faced with complex template syntax.
[0074] (5) The template engine supports inserting executable code into the template, which is supported in HTML web pages, but there is a huge security risk in the prompt template scenario. Since the prompt template is usually entered by the object itself, if a malicious object inserts destructive code into the template, the server may cause security problems when parsing the template.
[0075] (6) Existing template engines have strict requirements for the naming of placeholders, restricting the placeholder names from containing special characters such as spaces, dashes, and brackets. For example, in Jinja, writing formats such as "{{ab}}", "{{ab}}" or "{{a{b}}" are not allowed. Different template engines have different restrictions on placeholders, but almost none of them provide sufficient flexibility for the naming of placeholders. In the Prompt template, objects often need to accurately convey their meaning through placeholder names, and even use multiple words or Chinese characters, such as "{{the identity of the protagonist}}" or even use Chinese as the placeholder name. None of the current template engines support the above flexible expressions.
[0076] The embodiment of the present invention provides a large language model guidance prompt template placeholder parsing method, based on a large language model guidance prompt template placeholder parsing device, including a parser and a matcher, wherein the parser is responsible for extracting information from a text string character by character and recording successfully matched placeholders; the matcher is responsible for matching text according to the placeholder format and reporting the matching result to the parser for processing. When placeholders of multiple formats are used in the same Prompt template, a matcher needs to be created for each format. Each matcher only matches placeholders of a specific format. In the actual processing process, the parser first splits the Prompt template into separate characters, and then passes the characters to each matcher one by one. After receiving the characters, the matcher will cache them and check whether the current cache content conforms to the placeholder format it is responsible for. When any matcher successfully matches the placeholder, the matcher will report the matching result (including the complete string, starting position and ending position of the placeholder) to the parser. After the match is successful, all matchers will clear the cache and wait to receive the next character passed by the parser. This process will continue until all characters in the template are processed. Finally, the parser aggregates and processes all successfully matched placeholder information. The coordination between the parser and the matcher in the embodiment of the present invention decomposes the string, solves the drawback (1) in the above-mentioned related art, simplifies complex logical operations such as conditional judgment and looping, adapts to resource-constrained WEB applications, and improves loading speed and operating efficiency. Multiple matchers are created to process placeholders of different formats, which solves the drawback (2) in the above-mentioned related art and flexibly adapts to a variety of prompt template formats, thereby improving the versatility across applications. The placeholder parsing method of the present invention does not rely on the naming rules of a certain programming language, and also meets the need for flexible expression of the meaning of the placeholder in the prompt template, thereby solving the drawbacks (3) and (6) in the above-mentioned related art. The present invention solves the drawback (4) in the above-mentioned related art by passing characters to the matcher character by character, caching and matching by character. The method of the present invention is limited to the parsing and matching of placeholders, and does not involve the execution of code, thereby avoiding the security risks of malicious code injection, and solving the drawback (5) in the above-mentioned related art.
[0077] According to an embodiment of the present invention, an embodiment of a large language model guided prompt template placeholder parsing method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0078] In this embodiment, a large language model guided prompt template placeholder parsing device is provided, including a parser and a matcher, such as Figure 1 As shown:
[0079] The parser is used to obtain a guidance prompt template string uploaded by the object; decompose the guidance prompt template string into at least one character, and pass the at least one character into the matcher in sequence, wherein the guidance prompt template string represents a preset text instruction framework, which is used to guide or stimulate the large language model to generate response content.
[0080] The method of the embodiment of the present invention can directly configure a large language model-guided prompt template placeholder parsing device on an AI platform, and the AI platform is a software program based on artificial intelligence that provides an interactive dialogue function, and the object can communicate with the artificial intelligence program through text or instructions.
[0081] It should be noted that in the field of artificial intelligence (AI), it refers to the text or instructions that provide input to the model to guide it to generate specific output. It is a text paragraph provided by the object when interacting with the model, which is used to describe the information, answers, text, etc. that the object wants to obtain from the model. The purpose of setting the prompt template is to guide the large language model (such as GPT) to produce the required response, so as to better control the generated output. It contains placeholders and other statements. What the object needs is to replace the placeholders in the template to generate prompt information suitable for different scenarios. Placeholders refer to variable elements in the template, which are used to represent the content that the object wants to add, and are wrapped by identifiers (such as {{}}, []).
[0082] It is understandable that the guide prompt template is in the form of a string containing placeholders, and the function of the parser is to decompose the entire string into multiple characters and pass them to the matcher one by one. Specifically, a string traversal algorithm is used to disassemble the guide prompt template word by word, and each character after disassembly is passed to the matcher. Different from the existing template engine, the character-by-character parsing method avoids the use of large-scale regular expressions. When parsing to the last character, whether or not the match is successful, the parsing will not be restarted. Regular expressions have a backtracking problem, and the character-by-character parsing of the present invention can avoid the occurrence of the backtracking problem.
[0083] The matcher is used to perform matching in sequence according to the characters input, and return matching response information to the parser.
[0084] It should be noted that the matcher needs to identify whether the input character by character contains content that conforms to the placeholder format. The placeholder may be marked as "{{}}". The matcher needs to identify the identifier and return the matching result. Specifically, a character matching algorithm can be used to identify specific identifiers, such as "{{" and "}}", and return the placeholder name between these characters to the parser.
[0085] It is understandable that compared with the template engine in the related technology, the matcher is more flexible in matching placeholder formats, for example, it supports symbols such as spaces and dashes, and adapts to the guidance prompt template format requirements of different AI platforms.
[0086] The parser is also used to determine whether the matcher successfully matches at least one character based on the matching response information; if any matcher successfully matches at least one character, the matcher returns target placeholder information corresponding to at least one character after the match is successful; the target placeholder information is displayed on the human-computer interaction page so that the object can modify the target placeholder information through the human-computer interaction page to facilitate the generation of a new guidance prompt template.
[0087] Specifically, the parser detects whether the placeholder is successfully matched based on the return result of the matcher through a judgment statement. After a successful match, the parser returns the placeholder information to the human-computer interaction page for the object to modify or fill in, and displays the placeholder variable to the object for operation. This avoids the complicated logic judgment, loop and other operations of modifying placeholders in the existing template engine, and simplifies the object operation process.
[0088] The embodiment of the present invention is applied to a large language model guidance prompt template placeholder parsing system. The parser decomposes the entire guidance prompt template string into at least one character and gradually passes it to the matcher for parsing. Any form of placeholder format can be parsed, such as "{{}}" of the Jinja template engine, "{{{and}}}" of the Mustache template engine, or the definition format of other template engines. This avoids the limitation that traditional template engines only support fixed placeholder formats and improves the flexibility of placeholder parsing. The matcher can identify and parse a variety of placeholder forms based on character-by-character matching operations, and can also be a customized format, and is not limited to a specific template engine syntax. This solves the problem in the related art that the template engine cannot be flexibly adjusted when different large language models use different placeholder formats, thereby improving the versatility of the guidance prompt template. The characters are parsed by the parser and passed into the matcher. The matcher matches the characters one by one to obtain flexible placeholder information. It can adapt to various existing placeholder formats in the field and even analyze custom placeholder formats. It overcomes the problems of fixed placeholder formats and poor versatility in related technologies, and greatly improves the flexibility of the placeholders of the guidance prompt template in the interaction of AI large models.
[0089] The embodiment of the present invention also provides a large language model guided prompt template placeholder parsing method, which is applied to a parser, such as Figure 2 As shown, the method includes:
[0090] Step S201, obtaining the guidance prompt template character string uploaded by the object;
[0091] Step S202, decomposing the guidance prompt template character string into at least one character, and sequentially inputting the at least one character into the matcher, so that the matcher sequentially performs matching according to the input characters, and returns matching response information to the parser;
[0092] Step S203, wherein the guiding prompt template character string represents a preset text instruction framework, which is used to guide or stimulate the large language model to generate response content;
[0093] Step S204, judging whether the matcher successfully matches at least one character according to the matching response information; if any matcher successfully matches at least one character, then after the match is successful, the matcher returns the target placeholder information corresponding to the at least one character, and displays the target placeholder information on the human-computer interaction page, so that the object can modify the target placeholder information through the human-computer interaction page, so as to generate a new guidance prompt template.
[0094] The embodiment of the present invention decomposes the guidance prompt template string into characters and sends these characters to the matcher one by one. The matcher can flexibly identify and parse the placeholders in the template. The object can modify the placeholders according to actual needs to generate a guidance prompt template that meets the specific application scenario. Compared with the complex logic and strict placeholder naming restrictions of the existing template engine, this embodiment simplifies the template processing flow, avoids the backtracking problem, and improves the parsing efficiency. By gradually matching the placeholders and dynamically modifying them in the human-computer interaction interface, more flexible placeholder format support is provided, which improves the flexibility of placeholder parsing.
[0095] In an optional implementation, before the step of decomposing the guidance prompt template string into at least one character and sequentially passing the at least one character into the matcher, the step further includes:
[0096] Obtain one or more placeholder formats corresponding to the boot prompt template string uploaded by the object; create a corresponding matcher according to the placeholder format, wherein each placeholder format corresponds to a matcher.
[0097] It should be noted that in the string template, the placeholder consists of a start mark and an end mark, and the name of the placeholder is between these two marks.
[0098] For example, the object defines the entire guide prompt template. The first placeholder format uses "{{" as the start mark and "}}" as the end mark. For example: {{placeholder1}}. The second placeholder format uses "[" as the start mark and "]" as the end mark. For example: [placeholder2]. That is to say, in a string guide prompt template, there can be multiple placeholders of different types, and multiple specific matchers are created. According to the placeholder format defined by the object, matchers are created for these two formats respectively. The first matcher is used to identify the placeholders in the template that start with "{{" and end with "}}", and the second matcher is used to identify the placeholders in the template that start with "[" and end with "]".
[0099] In an embodiment of the present invention, since the placeholder formats in the engine template of the large language model may be different, by creating a specific matcher for each placeholder format, the matcher can more accurately identify the corresponding placeholder and is less likely to produce mismatches. In other words, the placeholder format is no longer limited to the format type defined by the object itself. As long as there is a placeholder of a new format in a new guidance prompt template, a new matcher can be created for matching, thereby improving the flexibility of placeholder settings.
[0100] In an optional embodiment, the matcher is represented by a matching function, which characterizes a logical code for matching characters; creating a corresponding matcher according to the placeholder format specifically includes: extracting the placeholder marker and the number of placeholder markers in the placeholder format; inputting the placeholder marker and the number of placeholder markers as input parameters into a preset matcher creation function to obtain a return parameter of the matcher creation function; wherein the return parameter includes the logical code of the matching character corresponding to the matching function.
[0101] It should be noted that the matcher creation function refers to dynamically generating logic codes of the matching function according to the identifier and number of the placeholders, so as to identify placeholders of different formats.
[0102] Exemplarily, the number of placeholder identifiers in the placeholder "{{}}" is four, and the matcher creation function dynamically creates the matching logic corresponding to the matcher for matching "{{}}" according to the different placeholder identifiers.
[0103] Specifically, the preset matcher creation function is used to define the character number variable in the matcher creation function code as the placeholder symbol, and at the same time, define the character quantity variable in the matcher creation function code as the number of the placeholder characters, and generate a matching function according to the preset matching character logic code based on the placeholder symbol variable and the character quantity variable after the definition is completed, as a return parameter.
[0104] Exemplarily, the placeholder is "{{}}", the placeholder identifier is "{", and the number is 2. The matcher creation function generates a function for matching "{{}}" according to the logic of single character comparison based on these two parameters.
[0105] Among them, the comparison logic of a single character includes: defining the first variable as a placeholder symbol, defining the second variable as the number of placeholder characters, comparing the first variable with the actual character input variable, and performing cyclic comparison and judgment according to the number of times of the second variable, using the judgment result as the output parameter, and defining the output parameter as the fourth variable.
[0106] Finally, a matching function will be generated according to the preset logic code of the matching characters based on the defined placeholder symbol variable and the character quantity variable as the return parameter, that is, the code form corresponding to the matcher.
[0107] It is understandable that, unlike the hard-coded matching logic of a specific template engine, the dynamic creation in this embodiment allows the matching logic to be flexibly generated according to the input placeholder format, rather than being hard-coded in advance, thereby improving the flexibility of the matcher when facing different prompt guide templates.
[0108] In the embodiment of the present invention, the matcher is represented by a matching function, and the matching function represents the logic code for matching characters, that is, the matching logic of the placeholder can be set completely freely, and the matching logic is set according to different placeholders, and is no longer limited to the preset syntax of a specific template engine. The parser can extract the placeholder identifier and quantity in the placeholder format, and input them as parameters to the matcher creation function. The parameters returned by the matcher creation function include the logic code required by the matching function, that is, the parser can dynamically create a matcher according to the actual boot template, further improving the flexibility of the matcher when matching placeholders.
[0109] In an optional embodiment, the method further includes: determining the priority of each matcher based on the number of placeholder markers corresponding to the matcher, wherein the size of the priority is negatively correlated with the number of placeholder markers corresponding to the matcher, and the priority is used to indicate the sorting order of each matcher when at least one character is passed into the matcher.
[0110] It should be noted that in this embodiment, the priority is determined by the number of placeholders. The fewer the placeholders, the higher the priority. When various symbols are nested in the template, shorter start and end markers can complete the matching earlier, which can save the amount of calculation. For example, using the two placeholder formats of "<>" and "{}", in the string "<aaa{bbb> ccc}" will be parsed as "<aaa{bbb> ", while "{bbb>ccc}" is not considered as a placeholder, ensuring that from left to right, the former can complete the match earlier.
[0111] The parser of the embodiment of the present invention determines the priority of each matcher according to the number of placeholder identifiers of each matcher, and the priority is negatively correlated with the number of identifiers. That is to say, the fewer the characters of the start and end identifiers, the higher the priority of the matcher, so that the placeholders in the short character format (such as {{}}) can be matched first and parsed first during template parsing. By sorting according to the priority of the placeholder identifiers, placeholders of different lengths and formats can coexist in the same parsing process without causing conflicts due to the parsing order, so that a variety of nested and parallel placeholder formats can be supported in the template, which greatly improves the compatibility and flexibility of the placeholder format.
[0112] In an optional implementation, the step of sequentially transmitting the at least one character to the matcher specifically includes: assigning an index value to each of the characters; sequentially transmitting the characters and the corresponding index values to each matcher corresponding to the priority level of each matcher.
[0113] It should be noted that the parser determines the priority of each matcher by the number of placeholder markers in the matcher. The priority is negatively correlated with the number of placeholder markers, that is, the fewer the markers in the placeholder, the higher the priority, and the match will be given priority during matching.
[0114] For details, please refer to Figure 3 , the Prompt template content of the object is "first placeholder {{placeholder1}}, second placeholder [placeholder2]". The parser breaks the above string into individual characters and assigns an index value to each character starting from 0.
[0115] Reference Figure 4, there are three matchers from high to low priority, namely matcher "<>", matcher "[]", and matcher "{{}}". After the parser reads the Promopt template and decomposes the characters, it first transfers the character with index 0 to the matcher "<>" in order of priority. When the matcher "<>" does not match successfully, the character with index 0 is transferred to the matcher "[]", and so on. When all three matchers are matched successfully, the character with index 1 continues to be transferred to the matcher "<>". Repeat the above steps until any of the three matchers matches successfully. After it uploads the matching result, the parser continues to transfer from the next character, and the matcher continues to match.
[0116] The embodiment of the present invention assigns index values to all characters respectively, providing an index basis in the subsequent matcher matching process, and according to the priority, a shorter placeholder identifier can be matched earlier during template parsing. When a shorter placeholder is successfully matched, the parser no longer needs to try to pass the part of characters to other low-priority matchers for matching, thereby reducing unnecessary repeated matching operations and saving computing resources. At the same time, since each character is transmitted separately, the combination of different characters can be freely set without affecting the effect of the characters forming the overall placeholder, supporting a variety of different placeholder formats and improving the flexibility of template placeholder parsing.
[0117] In an optional embodiment, the method further includes:
[0118] If any matcher matches successfully, the characters in the placeholder buffer corresponding to all other matchers are cleared.
[0119] It is understandable that when any matcher matches successfully, the cache of the successfully matched matcher is already full, so it is necessary to upload the target placeholder information to the parser first, and then clear the cache. Since other matchers did not match the corresponding characters, or matched part of them, it means that the placeholder format corresponding to other matchers did not appear in the string, or only a single character such as a "{" or a "<" appeared. Therefore, clearing the cache of other matchers ensures that when there are nested placeholders, the inner placeholders are matched first, and part of the cache content of the outer placeholder is invalid in this case. If the cache of the outer matcher is not cleared, the outer match will retain some illegal or invalid characters, resulting in subsequent matching errors. Clearing the cache of other matchers can accurately identify legal placeholders in nested structures, thereby improving the accuracy and flexibility of matching.
[0120] In the embodiment of the present invention, when any matcher matches successfully, the cache of other matchers is immediately cleared, which is beneficial for processing nested placeholders. Since placeholders may be nested, only the innermost placeholders are considered legal. Clearing the cache of other matchers can ensure that when processing nested structures, the outer placeholders will not affect the matching of the inner placeholders, thereby improving the flexibility of processing nested placeholders.
[0121] The embodiment of the present invention also provides a large language model guide prompt template placeholder parsing method, which is applied to a matcher, such as Figure 5 As shown, the method includes:
[0122] Step S501, matching the characters in sequence according to the input;
[0123] Step S502: Return matching response information to the parser.
[0124] The embodiment of the present invention gradually matches the incoming characters and returns the matched response information to the parser, thereby flexibly parsing placeholders of different formats, thereby solving the problem of limited placeholder formats in existing engines. Secondly, no regular expression matching is required, which avoids performance problems caused by backtracking and ensures the flexibility of placeholder naming.
[0125] In an optional implementation, each matcher corresponds to a placeholder buffer; the placeholder buffer includes a start flag buffer, a placeholder name buffer, and an end flag buffer; the matching is performed in sequence according to the characters input, specifically including:
[0126] a1, store the current character into the start mark buffer, and compare the current character with the preset placeholder start symbol;
[0127] a2, if the current character is different from the preset placeholder start symbol, clear the character in the start mark buffer, continue to obtain the next character and re-store the next character in the start mark buffer, and compare the next character with the preset placeholder start symbol. When the next character is the same as the preset placeholder start symbol, determine that the next character is the first target character, and store the first target character in the storage space of the start mark buffer; until the storage space of the start mark buffer is completely occupied by the first target character, stop storing characters in the start mark buffer;
[0128] a3, recording the start mark index value corresponding to the last first target character stored in the start mark buffer;
[0129] a4, and when it is determined that the character storage in the start mark buffer is no longer continued, continue to obtain the next character corresponding to the last first target character in the start mark buffer, and store the next character of the last first target character in the placeholder name buffer and the end mark buffer;
[0130] a5, comparing each character after the last first target character with the preset placeholder end symbol, if one or more consecutive characters after the first target character are different from the preset placeholder end symbol, clearing the characters in the end mark buffer;
[0131] a6, until a second target character identical to the preset placeholder end symbol is obtained, the second target character is stored in the end mark buffer area; and the next character after the second target character is continuously obtained;
[0132] a7, and compare the next character after the second target character with the preset placeholder end symbol, until the end mark buffer area is completely occupied by the second target character, and no longer continue to store characters in the end mark buffer area;
[0133] a8, recording the end mark index value corresponding to the last second target character stored in the end mark buffer at this time;
[0134] a9, removing the characters in the placeholder name buffer area that are identical to those in the end mark buffer area, obtaining the placeholder name information, and recording the index value corresponding to the placeholder name information at this time;
[0135] a10, uses the characters in the start mark buffer as the start mark information, uses the characters in the end mark buffer as the end mark information, and generates the target placeholder information according to the start mark information, the end mark information, the placeholder name information, the start mark index value, the end mark index value, and the index value corresponding to the placeholder name information.
[0136] For example, refer to Figure 6 , Figure 6Shows the matching principle and internal logic of the matcher "{{}}". When the character "第" at index 0 and the character "一" at index 2 are obtained, they are first cached in the start flag buffer. After passing through the logical judgment step of the matcher, they are not the same as the preset start flag character "{". Therefore, the information of the character "第" at index 0 and the character "一" at index 2 in the buffer is cleared, and the character corresponding to the next index is continuously obtained until the character "{" at index 6 is the same as the preset start flag character "{", so it does not need to be cleared. At the same time, the next character is obtained again, and the consecutive character "{" at index 7 is the same as the preset start flag character "{", and it is cached in the start flag buffer (i.e., the first target character).
[0137] At this time, the start flag buffer has been filled with the first target character. Then, continue to obtain the placeholder name after the start flag. First, store the consecutive characters after the first target character in the placeholder name buffer and the end flag buffer respectively. Similarly, in the above loop judgment method, compare whether the character is the same as the preset end flag character "}". If not, only clear the characters in the end flag buffer and do not clear the content of the placeholder name buffer. Therefore, when the character "}" at index 20 is obtained, it is the same as the preset end flag character, and it is cached in the end flag buffer. Then, obtain the character "}" at index 21 and also cache it in the end flag buffer until the end flag buffer is filled, and the matching of the current matcher "{{}}" is successful. Since the characters in the placeholder name buffer have not been cleared, when the end flag character is finally matched, the end flag character is also stored in the placeholder name buffer.
[0138] During the matching process, the matcher records the start flag index value corresponding to the last first target character stored in the start flag buffer, records the end flag index value corresponding to the last second target character stored in the end flag buffer, records the characters in the placeholder name buffer after removing the same characters as the end flag buffer to obtain the placeholder name characters, and records each index value corresponding to the placeholder name characters.
[0139] According to the characters in the above-mentioned start mark buffer area as the start mark information, the characters in the end mark buffer area are used as the end mark information, and the target placeholder information is generated according to the start mark information, the end mark information, the placeholder name information, the start mark index value, the end mark index value, and the index value corresponding to the placeholder name information. For example, the placeholder "{{placeholder1}}", named "placeholder1", has a start index of 7, an end index of 21, and placeholder name indexes of 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19. The placeholder "[placeholder2]", named "placeholder2", has a start index of 29, an end index of 42, and placeholder name indexes of 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41.
[0140] In the embodiment of the present invention, each matcher has a separate cache space, including a start mark cache area, a placeholder name cache area and an end mark cache area. The start mark, the placeholder name and the end mark are stored in different cache areas respectively. Different cache areas are processed independently, avoiding confusion of the placeholder format content, which is conducive to flexible parsing of the placeholder format. Through operations for different cache areas, the start symbol and the end symbol are allowed to be compared step by step. When the matcher performs character comparison, if the current character does not match the preset symbol, the character in the cache area will be cleared and the matching will be restarted. Even if characters that do not conform to the rules appear in certain positions, the overall matching process will not be affected. Only when a whole mark (the first target character and the second target character) are completely matched, the match will be determined to be successful. The matcher not only records the index values corresponding to the start and end marks, but also generates target placeholder information according to these index values, accurately locates the start and end positions of each placeholder, and effectively marks the index position of the placeholder when processing multiple placeholders at the same time, thereby improving the flexibility of parsing the placeholder characters.
[0141] In an optional implementation, the method further includes:
[0142] The number of characters stored in the start mark buffer is recorded, and the starting position of the placeholder name is determined according to the index value corresponding to the placeholder name information and the number of characters stored in the start mark buffer.
[0143] It is understandable that since there are many characters in the placeholder name, it is not necessary to record the index of each character. Therefore, it is necessary to determine the starting position of the placeholder name based on the index value corresponding to the placeholder name information and the number of characters stored in the start mark buffer. In the end, only the starting position of the placeholder name needs to be uploaded. The calculation formula for the starting position of the placeholder name is:
[0144] S = s1 – L + 1;
[0145] Among them, S represents the starting position of the placeholder name, s1 represents the current character index of the placeholder name, and L represents the number of start identification characters.
[0146] The embodiment of the present invention directly calculates the position according to the number of characters in the buffer area and the index value, which can avoid the string matching algorithm of traversing again, directly locate the position of the placeholder name, and further reduce the matching process of the matcher.
[0147] In actual application, refer to Figure 7 , the AI platform transmits the boot prompt template string and placeholder format; the parser obtains the boot prompt template string transmitted by the AI platform, decomposes the string into characters, and creates a matcher according to the placeholder format; the parser decomposes the string into characters and assigns index values and transmits them to the matcher; the matcher matches the characters in sequence and returns the final matched placeholder information to the parser; the parser then returns the placeholder information to the AI platform for display on the human-computer interaction page. It provides a high degree of freedom for writing Prompt templates for objects, which can meet the various requirements of objects for Prompt template placeholders. At the same time, it ensures that when processing the Prompt template, each character in the template will only be processed once, and supports various custom placeholder formats, which can greatly reduce the amount of code during programming implementation, and is very beneficial when applied to WEB programs. The situation of parsing placeholders in actual applications of the present invention is as follows:
[0148] (1) The prompt template can contain placeholders of various forms; (2) Placeholders are closed in pairs, that is, they contain a clear start mark and end mark; (3) In a complete placeholder, there will be no newline (\r), carriage return (\n), tab (\t) and other characters; (4) Placeholders are generally not allowed to be nested. When nesting occurs, only the innermost placeholder will be considered valid, and the outer part will be treated as ordinary characters. For example, in {{hello{{world}}}}, only {{world}} is a valid placeholder; (5) When there is ambiguity in different placeholder formats, some placeholders may be invalid. For example, when both {} and <{}> formats are used at the same time, all placeholders will be parsed as {} format according to the principle of innermost parsing. (6) The fewer characters in the start and end marks, the higher the matching priority, because fewer characters means that the match is completed earlier, or it will be in the inner layer in the case of nesting; (7) When multiple placeholder formats intersect or overlap, they are parsed according to the principle of "left end first". For example, when using the <> and {} formats, the string<aaa{bbb> ccc} will be parsed as<aaa{bbb> , while {bbb>ccc} is not recognized as a placeholder because the former is matched earlier according to the left-to-right parsing order.
[0149] In actual application, the embodiment of the present invention can ensure that each character is processed only once, and supports various custom placeholder formats, thereby reducing the complexity of programming implementation, and is particularly suitable for the development of WEB programs.
[0150] It should be noted that in the relevant technology, there is a method of using the rule engine to set placeholder information. This method is mainly used for the application of the rule engine, and it solves the problem of how to flexibly generate different business processes through the rule engine. The placeholder is only used as an auxiliary operator to improve the flexibility of the operator. The core focus is on how to define and use the rule engine operator, which solves the problem of process-based business logic.
[0151] The present invention solves the placeholder problem in Prompt template parsing, focusing on the steps and algorithms for parsing placeholders from strings. It does not involve operator definition or process control of the rule engine, but focuses on processing placeholders in templates. It is a more fine-grained parsing task and solves the flexible definition and parsing requirements of Prompt templates.
[0152] In addition, the focus of placeholder parsing in the related art is on the definition of operators and their application in the rule engine. Operators are tools that assist the rule engine in implementing business logic. The core of the present invention lies in the placeholder itself, including definitions, rules and their parsing methods. Even if there are terms related to rule definition, cache / queue, parsing and generation in the written description, these terms are just common concepts for solving different technical problems. In specific technical implementation, "rule definition" and "parsing" in the rule engine are for the logical operation of the process, and "cache / queue" is an auxiliary tool in process scheduling. In the present invention, rule definition and parsing are all centered on the processing of placeholders, and the cache mechanism is used for efficient parsing of Prompt templates. These differences show that even if there is a placeholder parsing technology similar to the technical terms in the present invention, the technical subject matter and logic of the present invention are essentially different.
[0153] If we look at it from the perspective of relevant technical means, its main technical feature is to predefine a set of operators. An operator is a node in the process, and each operator is responsible for a specific task in the process (data processing). These operators are then used to combine into different processes. From this we can see that each operator of the rule engine must be predefined and contain specific data processing logic. Since operators need to be defined in advance, flexibility may be limited in actual use. For example, an operator that "checks whether the data is greater than 100" may also need to check whether the data is greater than 200 in actual scenarios. Therefore, "placeholders", that is, variables, may be introduced in related technologies to improve the applicability of operators, but in essence they are still solving process problems.
[0154] The method provided in this embodiment does not introduce the concept of "placeholder" into the Prompt template, but enhances the ability to use "placeholder" in related technologies. This embodiment involves two core technical features: (1) multiple placeholder formats can be used in the Prompt template; (2) the placeholder format in the Prompt template can be customized by the user. These two technical features are not reflected in the related technical features. The placeholder in the related technology is a variable attached to the operator. It only needs to define the variable. The placeholder format can be any placeholder that can be parsed by any related technology. There is no improvement on the related technology of placeholders. Of course, the key problem to be solved in the related technology is not placeholder parsing.
[0155] In addition, the common technical terms "rule definition, cache / queue, parsing, generation" are also the basic processes of computer data processing and are used in many technical solutions. However, when solving different technical problems, the objects anchored by the technical terms vary greatly. Under different problems, how to define rules, what kind of rules to define, what characteristics the cache queue has, what data should be cached, etc., these specific differences will be reflected in their respective technical solutions. The embodiment of the present invention completely proposes a new technical solution, namely, a large language model guided prompt template placeholder parsing method, thereby ensuring that (1) multiple placeholder formats can be used in the Prompt template; (2) the placeholder format in the Prompt template can be customized by the user.
[0156] An embodiment of the present invention further provides a computer device having the above-mentioned large language model guided prompt template placeholder parsing device.
[0157] See also Figure 8 , Figure 8 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 8 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 8 A processor 10 is taken as an example.
[0158] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0159] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0160] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0161] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0162] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0163] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0164] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0165] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the defined scope.
Claims
1. A large language model guided prompt template placeholder parsing device, characterized in that: Including parsers and matchers; The parser is used to obtain a guide prompt template string uploaded by the object; decompose the guide prompt template string into at least one character, and sequentially pass the at least one character to the matcher, wherein the guide prompt template string represents a preset text instruction framework, which is used to guide or stimulate the large language model to generate response content; The matcher is used to match the characters passed in in sequence and return matching response information to the parser; The parser is also used to determine whether the matcher successfully matches at least one character based on the matching response information; if any matcher successfully matches at least one character, the matcher returns target placeholder information corresponding to at least one character after the match is successful; the target placeholder information is displayed on the human-computer interaction page so that the object can modify the target placeholder information through the human-computer interaction page to facilitate the generation of a new guidance prompt template.
2. A large language model guided prompt template placeholder parsing method, characterized in that: A parser applied to a large language model guided prompt template placeholder parsing device as claimed in claim 1, the method comprising: Get the template string of the boot prompt for object upload; Decomposing the guidance prompt template string into at least one character, and sequentially passing the at least one character into the matcher, so that the matcher sequentially matches the characters passed in, and returns matching response information to the parser; wherein the guidance prompt template string represents a preset text instruction framework, which is used to guide or stimulate the large language model to generate response content; Whether the matcher successfully matches at least one character is determined based on the matching response information; if any matcher successfully matches at least one character, then after the match is successful, the matcher returns the target placeholder information corresponding to the at least one character, and displays the target placeholder information on the human-computer interaction page, so that the object can modify the target placeholder information through the human-computer interaction page, thereby facilitating the generation of a new guidance prompt template.
3. The method according to claim 2, characterized in that Before the step of decomposing the guide prompt template string into at least one character and sequentially passing the at least one character into the matcher, the step further includes: Obtain one or more placeholder formats corresponding to the boot prompt template string uploaded by the object; A corresponding matcher is created according to the placeholder format, wherein each placeholder format corresponds to a matcher.
4. The method according to claim 3, characterized in that The matcher is represented by a matching function, and the matching function represents a logic code for matching characters; and the creating a corresponding matcher according to the placeholder format specifically includes: Extracting the placeholder marker in the placeholder format and the number of the placeholder markers; The placeholder marker and the number of the placeholder markers are input as input parameters to a preset matcher creation function to obtain a return parameter of the matcher creation function; wherein the return parameter includes a logic code of a matching character corresponding to the matching function.
5. The method according to claim 4, characterized in that The method further comprises: The priority of each matcher is determined according to the number of the placeholder markers corresponding to the matcher, wherein the size of the priority is negatively correlated with the number of the placeholder markers corresponding to the matcher, and the priority is used to indicate the sorting order of each matcher when at least one character is passed into the matcher.
6. The method according to claim 4, characterized in that The step of sequentially passing the at least one character into the matcher specifically includes: Assigning an index value to each of the characters; The characters and the corresponding index values are sequentially transmitted to each matcher corresponding to the priority level according to the priority level of each matcher.
7. The method according to any one of claims 2 to 6, characterized in that: The method further comprises: If any matcher matches successfully, the characters in the placeholder buffer corresponding to all other matchers are cleared.
8. A large language model guided prompt template placeholder parsing method, characterized in that: A matcher applied to a large language model guided prompt template placeholder parsing device as claimed in claim 1, the method comprising: Match the characters passed in one by one; The matching response information is returned to the parser.
9. The method according to claim 8, characterized in that Each matcher corresponds to a placeholder buffer; the placeholder buffer includes a start flag buffer, a placeholder name buffer, and an end flag buffer; the matching is performed in sequence according to the characters passed in, specifically including: Store the current character in the start mark buffer, and compare the current character with the preset placeholder start symbol; If the current character is different from the preset placeholder start symbol, clear the character in the start mark buffer, continue to obtain the next character and re-store the next character in the start mark buffer, and compare the next character with the preset placeholder start symbol. When the next character is the same as the preset placeholder start symbol, determine that the next character is the first target character, and store the first target character in the storage space of the start mark buffer; until the storage space of the start mark buffer is completely occupied by the first target character, stop storing characters in the start mark buffer; Recording the start mark index value corresponding to the last first target character stored in the start mark buffer; When it is determined that the character storage in the start mark buffer is no longer continued, the next character corresponding to the last first target character in the start mark buffer is continuously acquired, and the next character of the last first target character is stored in the placeholder name buffer and the end mark buffer; Compare each character after the last first target character with the preset placeholder end symbol, and if one or more consecutive characters after the first target character are different from the preset placeholder end symbol, clear the characters in the end mark buffer; When a second target character identical to the preset placeholder end symbol is obtained, the second target character is stored in the end mark buffer area; and the next character after the second target character is obtained. and comparing the next character after the second target character with the preset placeholder end symbol until the end mark buffer is completely occupied by the second target character, and no more characters are stored in the end mark buffer; Recording the end mark index value corresponding to the last second target character stored in the end mark buffer at this time; Remove the characters in the placeholder name buffer area that are the same as those in the end mark buffer area to obtain the placeholder name information, and record the index value corresponding to the placeholder name information at this time; The characters in the start mark buffer area are used as the start mark information, and the characters in the end mark buffer area are used as the end mark information, and the target placeholder information is generated according to the start mark information, the end mark information, the placeholder name information, the start mark index value, the end mark index value, and the index value corresponding to the placeholder name information.
10. The method according to claim 9, characterized in that The method further comprises: The number of characters stored in the start mark buffer is recorded, and the starting position of the placeholder name is determined according to the index value corresponding to the placeholder name information and the number of characters stored in the start mark buffer.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the large language model guidance prompt template placeholder parsing device to perform the guidance prompt template placeholder parsing method described in any one of claims 2-7 or claims 8-10.
Citation Information
Cited By
Prompt word template release access method and device, equipment and medium
CN122673333A
