Large language model prompting method for mixed arrangement of natural language and control text
By identifying and processing natural language and control text input by users, and updating the context prompt text of the large language model, the problem of difficult to accurately control the generation process and content of the large language model in the prior art is solved, and a higher controllable content is achieved Sex and consistency.
Patent Information
- Application Number
- CN202411102475.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-08-12
Smart Images

Figure CN119476260A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a large language model prompting method for mixed arrangement of natural language and control text. Background Art
[0002] With the rapid development of artificial intelligence technology, large language models can be applied to diverse tasks such as text generation, translation, question answering, sentiment analysis, text classification, information extraction, semantic understanding, and intelligent dialogue. With their natural language processing capabilities, large language models have become an important driving force in various fields.
[0003] However, since the large language model is essentially a mathematical model built on probabilistic statistical principles and training data, its inherent randomness in probabilistic sampling leads to greater uncertainty in the generated content when the quality of the prompt words is not high.
[0004] In the prior art, the method of using natural language strings to write prompt words to guide large language models often finds it difficult to achieve precise control over the generation process and content. Summary of the Invention
[0005] The present invention provides a large language model prompt method for a mixed arrangement of natural language and control text, which is used to solve the defect in the prior art that it is difficult to accurately control the generation process and content of the large language model, resulting in a large uncertainty in the generated content. The present invention updates the context prompt text corresponding to the large language model based on the target natural language text and / or target control text, so that the output content of the large language model can be accurately controlled.
[0006] The present invention provides a large language model prompting method for mixed arrangement of natural language and control text, comprising the following steps.
[0007] Get the target input text entered by the user; Based on preset rules, identifying the text type corresponding to each of at least one text block in the target input text; the preset rules are used to characterize the parsing format of the target input text; For each of the text blocks, when the text type includes the target natural language text, the context prompt text corresponding to the large language model is updated based on the target natural language text; when the text type includes the target control text, the function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model.
[0008] According to a large language model prompting method for mixed natural language and control text provided by the present invention, the text type includes target natural language text or target control text; The identifying, based on a preset rule, a text type corresponding to each of at least one text block in the target input text includes: Determining at least one text block corresponding to the target input text based on the preset rule, and the font style and encoding content corresponding to the target input text; For each of the text blocks, the text type corresponding to the text block is determined based on the preset rule and the encoding content corresponding to the text block.
[0009] According to a large language model prompt method for mixed arrangement of natural language and control text provided by the present invention, calling a function plug-in corresponding to the target control text and updating the context prompt text corresponding to the large language model includes: Calling the function plug-in corresponding to the target control text to determine the execution result of the target control text; Based on the execution result of the target control text, the context prompt text corresponding to the large language model is updated.
[0010] According to a large language model prompting method for mixed arrangement of natural language and control text provided by the present invention, calling a function plug-in corresponding to the target control text and determining an execution result of the target control text includes: In a case where the function plug-in corresponding to the target control text includes a calling plug-in, calling the large language model to determine a first output result based on the context prompt text and the calling plug-in; In a case where the function plug-in corresponding to the target control text includes a non-calling plug-in, determining a second output result corresponding to the non-calling plug-in; An execution result of the target control text is determined based on the first output result and / or the second output result.
[0011] According to a large language model prompting method for mixed arrangement of natural language and control text provided by the present invention, calling the large language model based on the context prompt text and the calling plug-in to determine a first output result includes: In a case where the calling plug-in includes a preset plug-in, based on the preset plug-in, controlling the large language model to generate a vocabulary probability of output vocabulary corresponding to the context prompt text; and determining the first output result based on the vocabulary probability of the output vocabulary; The preset plug-in includes at least a selection plug-in and / or a regular matching plug-in.
[0012] According to a large language model prompt method for mixed arrangement of natural language and control text provided by the present invention, the updating of context prompt text corresponding to the large language model based on the target natural language text includes: The target natural language text is added to the context prompt text corresponding to the large language model.
[0013] The present invention also provides a large language model prompting device for mixed arrangement of natural language and control text, comprising the following modules: The acquisition module is used to obtain the target input text entered by the user; an identification module, configured to identify, based on preset rules, the text type corresponding to each of at least one text block in the target input text; wherein the preset rules are used to characterize the parsing format of the target input text; An updating module is configured to update, for each of the text blocks, the context prompt text corresponding to the large language model based on the target natural language text when the text type includes the target natural language text; and to call a function plug-in corresponding to the target control text to update the context prompt text corresponding to the large language model when the text type includes the target control text.
[0014] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, it implements the large language model prompting method for mixed arrangement of natural language and control text as described in any one of the above.
[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the large language model prompting method for mixed arrangement of natural language and control text as described in any of the above.
[0016] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements the large language model prompting method for mixed arrangement of natural language and control text as described in any of the above.
[0017] The large language model prompt method for mixed arrangement of natural language and control text provided by the present invention first obtains the target input text input by the user, and then identifies the text type corresponding to each of at least one text block in the target input text based on preset rules, and the preset rules are used to characterize the parsing format of the target input text. Then, for each text block, when the text type includes the target natural language text, the context prompt text corresponding to the large language model is updated based on the target natural language text; when the text type includes the target control text, the function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model. The technical solution of the present invention identifies the text type corresponding to each of at least one text block in the target input text through preset rules, and then updates the context prompt text corresponding to the large language model based on the target natural language text and / or the target control text, so that the output content of the large language model can be accurately controlled. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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 any creative work.
[0019] Figure 1 It is a flow chart of the large language model prompting method for mixed arrangement of natural language and control text provided by the present invention.
[0020] Figure 2 It is a structural diagram of the large language model prompt device for mixed arrangement of natural language and control text provided by the present invention.
[0021] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0022] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0023] In view of the above problems in the prior art, the present invention provides a large language model prompting method for mixed arrangement of natural language and control text. Figure 1 This is a flow chart of the large language model prompting method for mixed arrangement of natural language and control text provided by the present invention, such as Figure 1 As shown, the large language model prompting method for mixed arrangement of natural language and control text includes the following steps 110, 120 and 130.
[0024] Step 110: Obtain the target input text input by the user.
[0025] Specifically, a target input text input by a user may be obtained, and the target input text may be pre-written by the user based on preset rules.
[0026] Step 120: Based on preset rules, identify the text type corresponding to each of at least one text block in the target input text; the preset rules are used to characterize the parsing format of the target input text.
[0027] Specifically, after obtaining the target input text, the text type corresponding to each of at least one text block in the target input text can be identified based on a preset rule. It is easy to understand that the preset rule is both a writing rule when writing the target input text and a parsing format when parsing the target input text.
[0028] In one embodiment, the text type includes a target natural language text or a target control text; The identifying, based on a preset rule, a text type corresponding to each of at least one text block in the target input text includes: Determining at least one text block corresponding to the target input text based on the preset rule, and the font style and encoding content corresponding to the target input text; For each of the text blocks, the text type corresponding to the text block is determined based on the preset rule and the encoding content corresponding to the text block.
[0029] Specifically, at least one text block corresponding to the target input text can be determined based on preset rules and the font style and encoding content corresponding to the target input text. Exemplarily, the target input text includes text in green font and text in white font. The text portion that only includes white font can be determined as a text block. The text portion that can obtain an output result can also be determined as a text block based on the encoding content. For example, the text portion between do and done that is a mixture of green font and white font is determined as a text block. "do / done" represents a cluster text block, and do and done can include at least one text block. For another example, in the text "read from console", read is the function name of the function plug-in, from is the function plug-in parameter name, and console is the function plug-in parameter value. The execution of this text can obtain an output result, so the text "read from console" can be determined as a text block. It is easy to understand that in the actual target input text, within "read from console", "read from" is green text and "console" is white text.
[0030] Furthermore, the text type corresponding to the text block can be determined based on preset rules and the encoding content corresponding to the text block. For example, the text type corresponding to the text block "read from console" is the target control text, while the text type corresponding to the text block that only includes white fonts is the target natural language text.
[0031] In addition, the technical solution of the present invention regards natural language as a basic programming element, and realizes the distinction between natural language text and control text through preset rules and the coding content corresponding to the text blocks, optimizes the text writing structure and paradigm of the large language model prompt program, and improves the readability and maintainability of the prompt coding.
[0032] Optionally, the encoding format corresponding to the target control text can be as follows: function plug-in function name + function plug-in parameter name + function plug-in parameter value. The encoding format corresponding to the target control text can also be as follows: function plug-in function name + function plug-in parameter name + function plug-in parameter value + function plug-in parameter name + function plug-in parameter value. The encoding format corresponding to the target control text can also be a function plug-in function name, and a combination of multiple function plug-in parameter names and function plug-in parameter values. For example, there is the following text: "complete prompt is How many days in a commonyear? stop at , or . temperature is 0.9", where "complete" is a function plug-in function name, "prompt is" is a function plug-in parameter name corresponding to "complete", "How many days in a commonyear?" is the function plug-in parameter value, "stop at" and "temperature is" are two function plug-in parameter names corresponding to "complete", and ", or ." and "0.9" are function plug-in parameter values. It's easy to understand that in actual execution, "complete," "prompt is," "stop at," "temperature is," and "or" all use the same font style, while "How many days in a common year?" and "0.9" use a different font style. "or" represents a list and is a keyword in the target input text encoding. Keywords support the basic grammatical structure of the target input text. Other keywords include "as" for assignment, "and" for lists, ";" for sentence breaks, and "do / done" for program blocks.
[0033] In the above embodiment, based on preset rules, as well as the font style and encoding content corresponding to the target input text, at least one text block corresponding to the target input text is determined, and then for each text block, based on the preset rules and the encoding content corresponding to the text block, the text type corresponding to the text block is determined. This can accurately distinguish whether the text type corresponding to the text block is the target natural language text or the target control text, thereby ensuring the subsequent update of the context prompt text corresponding to the large language model.
[0034] Step 130: For each of the text blocks, when the text type includes target natural language text, update the context prompt text corresponding to the large language model based on the target natural language text; when the text type includes target control text, call the function plug-in corresponding to the target control text to update the context prompt text corresponding to the large language model.
[0035] Specifically, for each text block, when the text type includes the target natural language text, the context prompt text corresponding to the large language model can be updated based on the target natural language text. When the text type includes the target control text, the function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model. It is easy to understand that the context prompt text is constantly updated. Each time the large language model is called, the context prompt text can be input into the large language model to assist the large language model in realizing the "memory" function, that is, to ensure the context association ability of the large language model. It is easy to understand that in multiple text blocks of the target input text, the text type of the text blocks can all be the target natural language text, or they can all be the target control text. It is also possible that the text type of multiple texts includes both the target natural language text and the target control text.
[0036] In one embodiment, calling the function plug-in corresponding to the target control text and updating the context prompt text corresponding to the large language model includes: Calling the function plug-in corresponding to the target control text to determine the execution result of the target control text; Based on the execution result of the target control text, the context prompt text corresponding to the large language model is updated.
[0037] Specifically, the function plug-in corresponding to the target control text can be called to determine the execution result corresponding to the target control text. Among them, the function plug-in corresponding to the target control text includes one or more of the completion plug-in complete, the reading plug-in read, the processing return plug-in set, the conditional plug-in if, the conditional loop plug-in while, the traversal loop plug-in for, the comparison plug-in compare, the break plug-in break, the skip plug-in continue, the comment plug-in comment, the selection plug-in select, the regular matching plug-in match and the metaprogramming plug-in call. After determining the execution result of the target control text, the context prompt text corresponding to the large language model can be updated based on the encoding order of each text block in the target control text in the target input text, as well as the execution result. It is easy to understand that the content in the context prompt text is related to the encoding order of each text block in the target control text in the target input text. For example, if the encoding order of text block A in the target input text is before text block B, then the content in the context prompt text is the content corresponding to text block A in the front and the content corresponding to text block B in the back.
[0038] In the above embodiment, the function plug-in corresponding to the target control text is called to determine the execution result of the target control text. Based on the execution result of the target control text, the contextual prompt text corresponding to the large language model is updated. The contextual prompt text ensures the contextual relevance of the large language model, and because the contextual prompt text changes dynamically and in a controlled manner, it can improve the control over the large language model.
[0039] In one embodiment, calling the function plug-in corresponding to the target control text and determining the execution result of the target control text includes: In a case where the function plug-in corresponding to the target control text includes a calling plug-in, calling the large language model to determine a first output result based on the context prompt text and the calling plug-in; In a case where the function plug-in corresponding to the target control text includes a non-calling plug-in, determining a second output result corresponding to the non-calling plug-in; An execution result of the target control text is determined based on the first output result and / or the second output result.
[0040] Specifically, if the function plug-in corresponding to the target control text includes a call plug-in, the large language model is called based on the context prompt text and the call plug-in to determine the first output result. The call plug-in may include one or more of a completion plug-in, a selection plug-in, a regular expression matching plug-in, and a metaprogramming plug-in.
[0041] Exemplarily, the function plug-in corresponding to the target control text includes a completion plug-in complete, and the text form corresponding to the target control text is as follows: "complete prompt is How many days in a common year? stop at , or . temperature is 0.9", wherein the function plug-in complete can call the large language model based on the context prompt text and the function plug-in parameter value corresponding to the calling plug-in: "How many days in a common year?", ",", "." and "0.9", to determine the first output result, and the first output result is "The calendar yearincludes 365 days or 366 days".
[0042] Specifically, if the function plug-in corresponding to the target control text includes a non-call plug-in, a second output result corresponding to the non-call plug-in is determined. The non-call plug-in may include a read plug-in, a process return plug-in, a conditional plug-in, a conditional loop plug-in, a traversal loop plug-in, a compare plug-in, a break plug-in, a skip plug-in, and a comment plug-in.
[0043] The present invention is described with the following examples for different non-call plug-ins corresponding to the target control text: For the reading plug-in read, the reading plug-in read means reading external input. The corresponding text is, for example, "readfrom console", which means reading the content in the "console", that is, the second output result is the content in the "console", "console" means the data in another hardware input device console, "from" is the function plug-in parameter name corresponding to the reading plug-in read, and "from console" means that the external input source is "console".
[0044] For the processing return plug-in set, the processing return plug-in set means processing and returning the input parameters, which include literals or variables.
[0045] The if conditional plugin is used to check whether a condition is met and branch execution based on whether the condition is met. For example, the corresponding text is "if condition true then do This statement will be executed done." This text indicates that if the condition is true, the output is "This statement will be executed done." The corresponding second output result is "This statement will be executed done." "Condition" is the function plugin parameter name corresponding to the if conditional plugin, indicating the branch condition. "Then" is another function plugin parameter name corresponding to the if conditional plugin, indicating the branch program block.
[0046] For the conditional loop plug-in while, the conditional loop plug-in while is used to detect whether the condition is met and to perform loop execution according to whether the condition is met. The corresponding text is, for example, "while condition true then doexecuting loop body done". This text means that if the condition is true, the loop output is "executing loopbody", and the corresponding second output result is "executing loop body executing loop bodyexecuting loop body ...". "condition" is the function plug-in parameter name corresponding to the conditional loop plug-in while, indicating the loop condition. "then" is another function plug-in parameter name corresponding to the conditional loop plug-in while, indicating the loop program block.
[0047] The for loop plugin is used to iterate over a list and execute the loop. For example, if the corresponding text is "for each a or b or c then do item: item done as ite," the corresponding second output result is "item: a item: b item: c." "each" is the function plugin parameter name corresponding to the for loop plugin, indicating the list to be traversed. "then" is another function plugin parameter name corresponding to the for loop plugin, indicating the loop block.
[0048] The compare plugin compares the consistency of elements in a list, returning true if they are consistent, and false otherwise. For example, the corresponding text, "compare value true and false as isEqual," assigns the result of whether "true" and "false" are consistent to "isEqual." Since "true" and "false" are inconsistent, "False" is assigned to "isEqual," resulting in a second output of False. "value" is the name of the function plugin parameter corresponding to the compare plugin, representing the list of elements to be compared.
[0049] For the break plug-in, the break plug-in is used to jump out of the loop.
[0050] For the skip plug-in continue, the skip plug-in continue is used to skip the current loop and enter the next loop.
[0051] For the comment plugin comment, the comment plugin comment is used to add comments.
[0052] Furthermore, the execution result of the target control text can be determined based on the first output result and / or the second output result. It is easy to understand that when the functional plug-in corresponding to the target control text only includes a calling plug-in, only the first output result can be determined, and the execution result of the target control text is further determined based on the first output result. For example, the first output result can be determined as the execution result of the target control text. When the functional plug-in corresponding to the target control text only includes a non-calling plug-in, only the second output result can be determined, and the execution result of the target control text is further determined based on the second output result. For example, the second output result can be determined as the execution result of the target control text. When the functional plug-in corresponding to the target control text includes both a calling plug-in and a non-calling plug-in, both the first output result and the second output result can be determined, and the execution result of the target control text is further determined based on the first output result and the second output result. For example, the first output result and the second output result can be determined as the execution result of the target control text.
[0053] In the above embodiment, the execution result of the target control text is determined in different ways according to the different functional plug-ins corresponding to the target control text, so that the context prompt text corresponding to the large language model can be updated more accurately based on the target control text.
[0054] In one embodiment, calling the large language model to determine a first output result based on the context prompt text and the calling plug-in includes: In a case where the calling plug-in includes a preset plug-in, based on the preset plug-in, controlling the large language model to generate a vocabulary probability of output vocabulary corresponding to the context prompt text; and determining the first output result based on the vocabulary probability of the output vocabulary; The preset plug-in includes at least a selection plug-in and / or a regular matching plug-in.
[0055] Specifically, when the large language model is directly input with a selection-like natural language text such as "Please help me choose whether it is better to eat apples or bananas as a fruit after a meal", due to the characteristics of the large language model, the output content of the large language model does not always include only the selection results. In this case, the output content of the large language model may be "I am just a large language model and cannot make a decision for you, but I can tell you that apples have the following nutritional value: XXX, and bananas have the following nutritional value: XXX. Apples and bananas are both good fruits for after meals. The best way is to choose according to your own physical condition." In addition, when the large language model is required to output more precise content, it is also difficult to control the output results of the large language model only through natural language input. Therefore, in order to enable the large language model to accurately generate selection results, or to enable the large language model to generate more precise results, the following method can be executed.
[0056] In the case where the calling plug-in includes a preset plug-in, the vocabulary probability of the output vocabulary corresponding to the updated context prompt text generated by the large language model can be controlled based on the functional plug-in corresponding to the target control text. Among them, the preset plug-in includes at least a selection plug-in select and / or a regular matching plug-in match, and the preset plug-in may also include a metaprogramming plug-in call. That is, the vocabulary probability of the output vocabulary of the large language model for the context prompt text can be forcibly modified by selecting the plug-in select and / or the regular matching plug-in match. For example, the probability of the large language model outputting vocabulary A based only on the context prompt text is 30%, the probability of generating vocabulary B is 40%, the probability of generating vocabulary C is 10%, and the probability of generating vocabulary D is 20%. In an embodiment of the present invention, the vocabulary probabilities of generating vocabulary A and generating vocabulary B can be modified to 0 by selecting the plug-in select, so that the output of the large language model can only be selected between vocabulary C and vocabulary D. Further, after controlling the vocabulary probability of the output vocabulary of the large language model, the first output result of the large language model output can be obtained based on the vocabulary probability of the output vocabulary.
[0057] The select plugin is used to modify the vocabulary probabilities predicted by the large language model and output the selection results. For example, if the corresponding text is "select from A or B or C", the corresponding first output result may be "A". "from" is the function plugin parameter name corresponding to the select plugin, indicating the set of candidate texts.
[0058] The regular matching plug-in match is used to ensure that the large language model outputs results that conform to the regular expression based on the modified vocabulary probability. The corresponding text is, for example, "match regex \(\d{3}\) 555-\d{4,} with max token14", and the corresponding first output result can be "(189)555-5555". "regex" is the function plug-in parameter name corresponding to the regular matching plug-in match, which is used to guide the large language model to output results that conform to the regular expression. "with max token" is another function plug-in parameter name corresponding to the regular matching plug-in match, which indicates the maximum number of tokens allowed to be generated by the large language model.
[0059] The metaprogramming plug-in call is used to call other functional plug-ins and / or call external plug-ins, so the metaprogramming plug-in call may be a calling plug-in or a non-calling plug-in, which depends on the type of functional plug-in it calls. The text corresponding to the metaprogramming plug-in call is, for example, "call function complete with parameter How many days in a common year? and . and 0.9 as result", then the corresponding first output result is "A commonyear, also known as a non-leap year, has 365 days". "Function" is the functional plug-in parameter name corresponding to the metaprogramming plug-in call, which indicates the functional plug-in function name of the called functional plug-in. In the above example, the functional plug-in called is the completion plug-in complete. "with parameter" is another functional plug-in parameter name corresponding to the metaprogramming plug-in call, which indicates the functional plug-in parameter value corresponding to the called functional plug-in. In addition, the metaprogramming plug-in call can easily prompt the large language model to automatically call external tools and complete complex interactive tasks, greatly reducing the difficulty of guiding the large language model to learn to use tools and provide correct parameters. This external tool calling method implemented through metaprogramming not only simplifies the interaction process between large language models and external tools and improves text readability and maintainability, but also meets the needs of diverse scenarios and increases the flexibility and scalability of large language models.
[0060] In the above embodiment, when the calling plug-in includes a preset plug-in, the large language model is controlled based on the preset plug-in to generate the lexical probabilities of the output vocabulary corresponding to the context prompt text, and then the first output result is determined based on the lexical probabilities of the output vocabulary. This ensures that the first output result not only conforms to the context prompt text, but also ensures that the first output result includes an accurate selection result when the functional plug-in includes a selection plug-in, and further ensures that the first output result includes a result that accurately conforms to the regular expression when the functional plug-in includes a regular matching plug-in.
[0061] In one embodiment, updating the context prompt text corresponding to the large language model based on the target natural language text includes: The target natural language text is added to the context prompt text corresponding to the large language model.
[0062] Specifically, the target natural language text can be added to the context prompt text corresponding to the large language model. It is easy to understand that the order of updating the context prompt text is determined based on the encoding order of the target input text. When the natural language text is in front and the target control text is in the back, the context prompt text corresponding to the updated large language model is also in the front, and the execution result corresponding to the target control text is in the back. In the case where the order of natural language text and target control text in the target input text is alternating, such as the encoding order is natural language text A + target control text B + natural language text C + target control text D, then the context prompt text corresponding to the updated large language model is natural language text A + the execution result corresponding to the target control text B + natural language text C + the execution result corresponding to the target control text D. It is easy to understand that when the target input text contains functional plug-ins such as the traversal loop plug-in for, the conditional loop plug-in while and the conditional plug-in if, the encoding order in the target input text can be that any number of target control texts and / or target natural language texts are nested in the target control text A.
[0063] The large language model prompt method for mixed arrangement of natural language and control text provided by the present invention first obtains the target input text input by the user, and then identifies the text type corresponding to each of at least one text block in the target input text based on preset rules, and the preset rules are used to characterize the parsing format of the target input text. Then, for each text block, when the text type includes the target natural language text, the context prompt text corresponding to the large language model is updated based on the target natural language text; when the text type includes the target control text, the function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model. The technical solution of the present invention identifies the text type corresponding to each of at least one text block in the target input text through preset rules, and then updates the context prompt text corresponding to the large language model based on the target natural language text and / or the target control text, so that the output content of the large language model can be accurately controlled.
[0064] The large language model prompting device for mixed arrangement of natural language and control text provided by the present invention is described below. The large language model prompting device for mixed arrangement of natural language and control text described below and the large language model prompting method for mixed arrangement of natural language and control text described above can be referenced to each other.
[0065] Figure 2 This is a schematic diagram of the structure of the large language model prompt device for mixed arrangement of natural language and control text provided by the present invention. Figure 2 As shown, the large language model prompting device 200 for mixed arrangement of natural language and control text includes the following acquisition module 210, recognition module 220, and update module 230.
[0066] An acquisition module 210 is used to acquire a target input text input by a user; Identification module 220, for identifying the text type corresponding to each of at least one text block in the target input text based on a preset rule; the preset rule is used to characterize the parsing format of the target input text; The updating module 230 is used to update the context prompt text corresponding to the large language model based on the target natural language text for each of the text blocks, when the text type includes the target natural language text; and when the text type includes the target control text, call the function plug-in corresponding to the target control text to update the context prompt text corresponding to the large language model.
[0067] In one embodiment, the text type includes a target natural language text or a target control text, and the recognition module 220 is specifically configured to: Determining at least one text block corresponding to the target input text based on the preset rule, and the font style and encoding content corresponding to the target input text; For each of the text blocks, the text type corresponding to the text block is determined based on the preset rule and the encoding content corresponding to the text block.
[0068] In one embodiment, the update module 230 is specifically configured to: Calling the function plug-in corresponding to the target control text to determine the execution result of the target control text; Based on the execution result of the target control text, the context prompt text corresponding to the large language model is updated.
[0069] In one embodiment, the update module 230 is further configured to: In a case where the function plug-in corresponding to the target control text includes a calling plug-in, calling the large language model to determine a first output result based on the context prompt text and the calling plug-in; In a case where the function plug-in corresponding to the target control text includes a non-calling plug-in, determining a second output result corresponding to the non-calling plug-in; An execution result of the target control text is determined based on the first output result and / or the second output result.
[0070] In one embodiment, the update module 230 is further configured to: In a case where the calling plug-in includes a preset plug-in, based on the preset plug-in, controlling the large language model to generate a vocabulary probability of output vocabulary corresponding to the context prompt text; and determining the first output result based on the vocabulary probability of the output vocabulary; The preset plug-in includes at least a selection plug-in and / or a regular matching plug-in.
[0071] In one embodiment, the update module 230 is further configured to: The target natural language text is added to the context prompt text corresponding to the large language model.
[0072] The large language model prompt device for mixed arrangement of natural language and control text provided by the present invention first obtains the target input text input by the user, and then identifies the text type corresponding to each of at least one text block in the target input text based on preset rules, and the preset rules are used to characterize the parsing format of the target input text. Then, for each text block, when the text type includes the target natural language text, the context prompt text corresponding to the large language model is updated based on the target natural language text; when the text type includes the target control text, the function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model. The technical solution of the present invention identifies the text type corresponding to each of at least one text block in the target input text through preset rules, and then updates the context prompt text corresponding to the large language model based on the target natural language text and / or the target control text, so that the output content of the large language model can be accurately controlled.
[0073] Figure 3 An example of a physical structure diagram of an electronic device is shown below. Figure 3 As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340, wherein the processor 310, the communication interface 320, and the memory 330 communicate with each other via the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute the large language model prompt method for mixed arrangement of natural language and control text, which includes: Get the target input text entered by the user; Based on preset rules, identifying the text type corresponding to each of at least one text block in the target input text; the preset rules are used to characterize the parsing format of the target input text; For each of the text blocks, when the text type includes the target natural language text, the context prompt text corresponding to the large language model is updated based on the target natural language text; when the text type includes the target control text, the function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model.
[0074] Furthermore, the logic instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product, stored in a storage medium, includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, mobile hard drives, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.
[0075] On the other hand, the present invention further provides a computer program product, comprising a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the large language model prompting method for mixed arrangement of natural language and control text provided by the above methods, the method comprising: Get the target input text entered by the user; Based on preset rules, identifying the text type corresponding to each of at least one text block in the target input text; the preset rules are used to characterize the parsing format of the target input text; For each of the text blocks, when the text type includes the target natural language text, the context prompt text corresponding to the large language model is updated based on the target natural language text; when the text type includes the target control text, the function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model.
[0076] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the large language model prompting method for mixed arrangement of natural language and control text provided by the above methods is implemented. The method includes: Get the target input text entered by the user; Based on preset rules, identifying the text type corresponding to each of at least one text block in the target input text; the preset rules are used to characterize the parsing format of the target input text; For each of the text blocks, when the text type includes the target natural language text, the context prompt text corresponding to the large language model is updated based on the target natural language text; when the text type includes the target control text, the function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model.
[0077] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0078] Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a necessary general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods described in each embodiment or certain portions of the embodiments.
[0079] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A large language model prompting method for mixed arrangement of natural language and control text, characterized in that: include: Get the target input text entered by the user; Based on a preset rule, identifying a text type corresponding to each of at least one text block in the target input text; The preset rule is used to characterize the parsing format of the target input text; For each of the text blocks, when the text type includes a target natural language text, the context prompt text corresponding to the large language model is updated based on the target natural language text; when the text type includes a target control text, a function plug-in corresponding to the target control text is called to update the context prompt text corresponding to the large language model.
2. The large language model prompting method for mixed arrangement of natural language and control text according to claim 1 is characterized in that: The text type includes a target natural language text or a target control text; The step of identifying the text type corresponding to at least one text block in the target input text based on a preset rule includes: Based on the preset rule, and the font style and encoding content corresponding to the target input text, determine at least one text block corresponding to the target input text; For each of the text blocks, the text type corresponding to the text block is determined based on the preset rule and the encoding content corresponding to the text block.
3. The large language model prompting method for mixed arrangement of natural language and control text according to claim 1 is characterized in that: The calling of the function plug-in corresponding to the target control text and updating the context prompt text corresponding to the large language model includes: Calling the function plug-in corresponding to the target control text to determine the execution result of the target control text; Based on the execution result of the target control text, the context prompt text corresponding to the large language model is updated.
4. The large language model prompting method for mixed arrangement of natural language and control text according to claim 3 is characterized in that: The calling of the function plug-in corresponding to the target control text to determine the execution result of the target control text includes: In a case where the function plug-in corresponding to the target control text includes a calling plug-in, calling the large language model based on the context prompt text and the calling plug-in to determine a first output result; In a case where the function plug-in corresponding to the target control text includes a non-calling plug-in, determining a second output result corresponding to the non-calling plug-in; Based on the first output result and / or the second output result, an execution result of the target control text is determined.
5. The large language model prompting method for mixed arrangement of natural language and control text according to claim 4 is characterized in that: The calling of the large language model to determine a first output result based on the context prompt text and the calling plug-in includes: In the case where the calling plug-in includes a preset plug-in, based on the preset plug-in, controlling the large language model to generate a vocabulary probability of an output vocabulary corresponding to the context prompt text; and determining the first output result based on the vocabulary probability of the output vocabulary; The preset plug-in includes at least a selection plug-in and / or a regular matching plug-in.
6. The large language model prompting method for mixed arrangement of natural language and control text according to any one of claims 1 to 5, characterized in that: The updating of the context prompt text corresponding to the large language model based on the target natural language text includes: The target natural language text is added to the context prompt text corresponding to the large language model.
7. A large language model prompting device for mixed arrangement of natural language and control text, characterized in that: include: An acquisition module is used to acquire the target input text input by the user; An identification module, used to identify the text type corresponding to each of at least one text block in the target input text based on a preset rule; the preset rule is used to characterize the parsing format of the target input text; An updating module is used for updating the context prompt text corresponding to the large language model based on the target natural language text for each of the text blocks, when the text type includes the target natural language text; and when the text type includes the target control text, calling the function plug-in corresponding to the target control text to update the context prompt text corresponding to the large language model.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the large language model prompt method for mixed arrangement of natural language and control text as described in any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the large language model prompting method for mixed arrangement of natural language and control text as claimed in any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the large language model prompting method for mixed arrangement of natural language and control text as claimed in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Large model plug-in calling method and device, equipment and medium
CN117112064A
Large model plug-in calling method and device, equipment and medium
CN117112065A
Intelligent learning interaction method based on custom plug-in and large language model
CN117251553A
Human-computer interaction method and device, electronic equipment and storage medium
CN117332068A
Natural language question answering method and device based on large language model, medium and equipment
CN117473053A