Prompt word optimization method, device, storage medium, and program product
By dividing placeholders into declarations and references and optimizing them with different representation formats, the problems of duplicate copying and disordered placement of placeholders in user prompts are solved, achieving accuracy and consistency of optimized user prompts and ensuring the effectiveness of task processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ALIBABA CLOUD COMPUTING CO LTD
- Filing Date
- 2025-01-08
- Publication Date
- 2026-07-10
AI Technical Summary
In existing technologies, placeholders in user prompts are prone to duplicate copying, loss, or misplacement during the optimization process, resulting in the optimized user prompts not matching the original user prompts and affecting task processing performance.
Placeholders are divided into two parts: placeholder declaration and placeholder reference. Different representation formats are used to distinguish them. After generating the optimized content including the placeholder reference, the placeholder declaration information is inserted to ensure the accuracy of placeholders in the optimized user prompts.
By separating the placeholder representation format, the optimized user prompt can accurately reproduce the placeholders in the original user prompt, ensuring the accuracy and consistency of task processing.
Smart Images

Figure CN122364359A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a method, device, storage medium, and program product for optimizing prompt words. Background Technology
[0002] Although Large Language Models (LLMs) are widely used in various application scenarios, different users design corresponding prompts based on their own task requirements to guide the LLM in completing the corresponding tasks. In order to enable the LLM to complete tasks more accurately, the need to optimize the prompts has arisen.
[0003] Observations revealed that one type of user prompt, containing placeholders, exhibits inconsistent effectiveness. This is particularly true when the placeholders within different prompts are dynamic; for example, prompt 'a' might contain two placeholders, while prompt 'b' might contain a different type of placeholder. These prompts are used to introduce dynamic content into the actual LLM workflow. This dynamic content, including but not limited to, referenced documents, contextual information, and task samples, can be placed within the prompt. A placeholder, as the name suggests, is a pre-defined space within the prompt to store corresponding content; the actual content is only passed in after the LLM process begins based on the prompt.
[0004] Traditional optimization of user prompts containing placeholders often leverages the generation capabilities of LLM (Local Language Management) to treat the entire content of the prompt as text information. LLM then expands the rather coarsely described prompt with richer content to obtain the optimized prompt. However, due to the uncontrollable nature of LLM generation, issues such as multiple copies of placeholders, missing placeholders, and arbitrary changes in placeholder positions can occur. This results in significant changes to the placeholders in the optimized prompt compared to the original, leading to mismatches between placeholder usage and user needs when processing tasks based on the optimized prompt. Summary of the Invention
[0005] This application provides a method, device, storage medium, and program product for optimizing prompt words, which ensures the accuracy of placeholders in optimized user prompt words.
[0006] In a first aspect, embodiments of this application provide a method for optimizing prompt words, the method comprising:
[0007] If a placeholder is identified in the original user prompt, optimized example information matching the original user prompt is retrieved from the database. The placeholder contained in the original user prompt adopts a first representation format for declaring a placeholder.
[0008] The placeholder in the optimized example information is determined to be a second representation format representing a reference placeholder;
[0009] Generate a system prompt word containing the original user prompt word and the optimized example information, and input the system prompt word into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word based on the system prompt word, wherein the placeholders in the first part are the second representation format;
[0010] Obtain the placeholder declaration information corresponding to the placeholder in the original user prompt, and determine the placeholder declaration information as the second part of the optimized user prompt, wherein the placeholder in the placeholder declaration information is the first representation format.
[0011] Secondly, embodiments of this application provide a prompt word optimization device, the device comprising:
[0012] The identification module is used to retrieve optimized example information matching the original user prompt from the database if it is found that the original user prompt contains a placeholder, wherein the placeholder contained in the original user prompt adopts a first representation format for declaring a placeholder;
[0013] The conversion module is used to determine that the placeholder in the optimized example information is a second representation format representing a reference placeholder;
[0014] The first optimization module is used to generate a system prompt word containing the original user prompt word and the optimized example information, and input the system prompt word into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word according to the system prompt word, wherein the placeholders in the first part are the second representation format;
[0015] The second optimization module is used to obtain placeholder declaration information corresponding to the placeholder in the original user prompt, and to determine the placeholder declaration information as the second part of the optimized user prompt, wherein the placeholder in the placeholder declaration information is the first representation format.
[0016] Thirdly, embodiments of this application provide an electronic device, including: a memory, a processor, and a communication interface; wherein, the memory stores executable code, and when the executable code is executed by the processor, the processor executes the prompt word optimization method as described in the first aspect.
[0017] Fourthly, embodiments of this application provide a non-transitory machine-readable storage medium storing executable code, which, when executed by a processor of an electronic device, enables the processor to at least implement the prompt word optimization method as described in the first aspect.
[0018] Fifthly, embodiments of this application provide a computer program product, the computer program product including a computer program, which, when executed by a processor, can implement the prompt word optimization method as described in the first aspect.
[0019] In the prompt word optimization scheme provided in this application embodiment, if the original user prompt word is identified to include a placeholder using a first representation format representing a declaration placeholder, then optimized example information matching the original user prompt word is retrieved from the database, and the placeholder in the optimized example information is determined to be a second representation format representing a reference placeholder. That is, if the optimized example information contains a placeholder in the first representation format of the original user prompt word, then it is modified to a second representation format representing a reference placeholder, meaning that a placeholder is referenced here; if the optimized example information does not contain a placeholder, then the placeholder in the original user prompt word can be inserted into an appropriate position in the form of a second representation format according to the description content in the optimized example information. Afterwards, a system prompt word containing the original user prompt word and optimized example information is generated, and the system prompt word is input into a large language model, so that the large language model optimizes the original user prompt word according to the optimized example information therein, and outputs the first part of the optimized user prompt word, where the placeholders present in the first part are in the second representation format. In other words, the optimized example information serves as a sample for optimizing the original user prompts using a large language model. This allows for a richer and more detailed description of the initially coarsely described original user prompts. During optimization, placeholders in the first representation format of the original user prompts are modified to a second representation format based on the placeholder format examples in the optimized example information. Finally, the placeholder declaration information corresponding to the placeholders in the original user prompts is obtained, and this placeholder declaration information is determined as the second part of the optimized user prompts, resulting in the complete optimized user prompts. The placeholder declaration information includes the placeholders in the first representation format of the original user prompts.
[0020] In the above scheme, placeholders are described in two parts: placeholder declarations and placeholder references (or placeholder usage), distinguished by different representation formats. For example, placeholder declarations use a first representation format, and placeholder references use a second representation format. In optimizing the original user prompt containing placeholders in the first representation format, firstly, only the large language model is used to generate the first part of the optimization information—for placeholders, this only generates references to placeholders. Then, the second part of the optimization information—for placeholders, this inserts the placeholder declaration information—is inserted post-processed. Because the first part of the optimization information optimizes the description in the original user prompt, and the second part of the optimization information maintains good consistency with the declaration results of placeholders in the original user prompt, the optimized user prompt has a good optimization effect and can completely and accurately reproduce the user's usage needs for the placeholders in the original user prompt. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 A flowchart illustrating a prompt word optimization method provided in this application embodiment;
[0023] Figure 2 A flowchart illustrating a prompt word optimization method provided in this application embodiment;
[0024] Figure 3 A flowchart illustrating a prompt word optimization method provided in this application embodiment;
[0025] Figure 4 This is a schematic diagram illustrating the application of a prompt word optimization method provided in an embodiment of this application;
[0026] Figure 5 This is a schematic diagram of the structure of a prompt word optimization device provided in an embodiment of this application;
[0027] Figure 6 This is a schematic diagram of the structure of an electronic device provided in this embodiment. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application. In addition, the timing of the steps in the following method embodiments is only an example and not a strict limitation.
[0029] It should be noted that, in the cases involving user information in the embodiments of this application, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse. In addition, the various models involved in this application (including but not limited to large language models or other models) comply with relevant laws and standards.
[0030] Regarding the optimization of user prompts containing placeholders, traditional solutions using LLM (Limited Language Management) treat placeholders in the original prompt, along with other text content (such as role descriptions, task descriptions, and task requirements), as part of the overall text content. Leveraging the text understanding and generation capabilities of a pre-trained LLM, new optimized user prompts are generated character by character, resulting in richer details compared to the original. However, if placeholders are located late in the original prompt and the original prompt is long, the performance limitations of LLM may cause it to ignore the descriptions related to later placeholders, focusing instead on earlier text content. This can lead to various placeholder errors in the optimized prompt. Furthermore, LLM doesn't recognize the specific format of placeholders and treats them as ordinary text, further contributing to placeholder errors.
[0031] A placeholder error refers to a significant change in the number, representation, type, or position of placeholders in the optimized user suggestion compared to the original. Simply put, the placeholders in the original user suggestion cannot be reproduced. Common errors include, but are not limited to: copying placeholders multiple times, misaligned placeholders, missing placeholders, etc.
[0032] Understandably, the reason why placeholders are included in the original user prompts is that they are placeholders for different types of content designed by the user. When the LLM completes a task based on the input prompts, it needs to obtain the corresponding relevant information (such as relevant documents, contextual memory, task processing examples) from these placeholders and fill them into the corresponding placeholders. Only by inputting user prompts containing this relevant information into the LLM can the LLM complete the task better.
[0033] Therefore, when optimizing the original user prompts, it is necessary to ensure that the placeholder representations in the original user prompts can be reproduced in the optimized user prompts. This is so that relevant information can be obtained according to the user's needs to assist the LLM in completing the corresponding task processing and ensure the effectiveness of task processing.
[0034] To ensure the accuracy of placeholders in the optimized user suggestions, the following core approach is provided in this application embodiment:
[0035] Drawing inspiration from the rules governing variable usage in program code, variables are divided into two parts: variable declaration and usage. In this application, placeholders are treated as a special type of variable, divided into two parts: placeholder declaration and usage (i.e., reference), with different representation formats used for distinction. This ensures the accurate reproduction of user-defined placeholders in the optimized user prompt. In summary, when optimizing the original user prompt containing placeholders using LLM, the optimized content output by LLM only generates references to the placeholders. Then, through a post-processing step, the placeholder declaration information is inserted into the optimization result to obtain the final optimized user prompt.
[0036] The placeholder declarations are consistent with those in the original user prompt, serving as the basis for subsequent retrieval of relevant knowledge. The optimized content output by the LLM is essentially a rewrite of the original user prompt's text, only referencing placeholders. Even if the same placeholder is referenced multiple times or some references are missing due to LLM's limitations, it won't affect the accurate retrieval of relevant knowledge based on the placeholder declarations. Because the placeholder declarations are not generated by the LLM but inserted later, they are not affected by LLM's generation capabilities, ensuring accurate reproduction of the original user prompt's placeholder settings. Furthermore, since the optimized content generated by the LLM primarily informs the LLM of task processing requirements, errors in placeholder referencing are permissible and won't significantly impact the task processing results.
[0037] In this embodiment, the declaration of a placeholder is to indicate the placeholder's name, type, and other attribute information; the reference of a placeholder refers to the use of the placeholder in a text description. In this case, the placeholder can be considered a word with a specific introduction method. The word is used in the text description, meaning it, together with other words in the text description, forms a complete natural language sentence description. The specific introduction method of the placeholder is the second representation format for referring to the placeholder. For example, in a text description consisting of text content x@placeholder name@text content y, the placeholder is introduced as @placeholder name@, and before and after it are other text content x and text content y in this text.
[0038] To better understand the effectiveness of traditional user suggestion word optimization, the following section combines... Figure 1 Example description.
[0039] The original user suggestion words before optimization were as follows:
[0040] You are a securities expert who can provide highly professional answers to questions related to investment and the market. When necessary, you can utilize relevant tools to obtain related information.
[0041] ${document}
[0042] #Sample
[0043] ${samp le}
[0044] #Memory
[0045] When answering user questions, try to forget most irrelevant information. Only remember and use information that is highly relevant to the current question or conversation. Ensure your answer is concise, accurate, and focused on the user's current question or topic. Information:
[0046] ${memory}
[0047] In the original user prompt above, ${} represents a placeholder, and this format is called the first representation format. In this embodiment, it is used to represent a placeholder declaration. Among them, document, sample, and memory are three different types of placeholders: related document, sample, and memory, respectively.
[0048] The optimized user suggestion words are as follows:
[0049] #Role
[0050] You are a securities expert, skilled at answering questions related to investment, markets, and related topics. You have extensive experience in both domestic and international capital markets and various types of securities products, and your answers are accurate and detailed.
[0051] ##Skill
[0052] ###Skill 1: Answering Investment Questions
[0053] - Provide professional and accurate investment advice and answers based on users' questions.
[0054] - When necessary, utilize relevant tools to obtain real-time information about the securities market.
[0055] ###Skill 2: Analyzing Market Trends
[0056] -Analyze and predict market trends based on current market information and examples.
[0057] - Provides market analysis reports to help users understand current market dynamics.
[0058] Skill 3: Providing information on securities products
[0059] - Provides detailed introductions to various types of securities products.
[0060] - Recommend suitable securities products based on the user's investment needs.
[0061] ##limit:
[0062] - Only answer questions related to the securities market and investment.
[0063] - Provide professional and accurate investment advice and answers based on users' questions.
[0064] - Always maintain a professional and neutral stance, and avoid making overly pessimistic or overly optimistic predictions about the market or specific products.
[0065] Based on the examples of the optimized user prompts above, we can see that the optimized user prompts may contain multiple copies of placeholders (such as the "document" shown in bold black text above), missing placeholders (such as the missing "${memory}" placeholder), disordered placement (such as "sample" and "document" shown in bold black text), and formatting errors (such as "{document"). In addition to content related to placeholders, the optimized user prompts mainly include optimized and rewritten content from the original user prompt text, such as the roles, skills, and limitations shown above.
[0066] Based on this, when LLM optimizes the original user prompts, the optimized prompts (or system prompts) provided to LLM are, for example: You are an expert in writing and optimizing prompts. Your task is to optimize the user-provided prompts so that the optimized prompts include descriptions of the AI assistant's role or personality, skill points, and some limitations.
[0067] An LLM that optimizes the original user prompts can be the same as or different from an LLM that uses the optimized user prompts for task processing.
[0068] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Where there is no conflict between the embodiments, the following embodiments and features thereof can be combined with each other.
[0069] Figure 1 A flowchart of a prompt word optimization method provided in an embodiment of this application is shown below. Figure 1 As shown, the method includes the following steps:
[0070] 101. If a placeholder is identified in the original user prompt, retrieve optimized example information that matches the original user prompt from the database. The placeholder contained in the original user prompt adopts the first representation format for declaring a placeholder.
[0071] 102. Determine that the placeholders in the optimized example information are in a second representation format that represents a reference placeholder.
[0072] 103. Generate a system prompt word containing the original user prompt word and optimized example information, and input the system prompt word into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word based on the system prompt word. The placeholders in the first part are the second representation format.
[0073] 104. Obtain the placeholder declaration information corresponding to the placeholders in the original user prompt, and determine the placeholder declaration information as the second part of the optimized user prompt, wherein the placeholder declaration information includes the placeholders in the first representation format of the original user prompt.
[0074] When optimizing the original user prompts, it is first necessary to identify whether the original user prompts contain placeholders. If they do, the optimization process can be carried out using the solution provided in the embodiments of this application. If they do not contain placeholders, the traditional solution can be used for optimization.
[0075] In one optional embodiment, identifying whether the original user prompt contains placeholders can be achieved using regular expressions. As illustrated in the example above, suppose the first representation format of a placeholder declaration in the original user prompt is: ${var iab le}, where var iab le represents the type description of the placeholder. Then, a regular expression like ${} can be set to search for positions in the original user prompt that satisfy this regular expression. If found, it indicates that the original user prompt contains placeholders, and the placeholder type description information of the corresponding placeholders in the original user prompt can be extracted. That is, the corresponding var iab le content can be extracted from {}, such as document, sample, and memory as mentioned above. This allows us to determine which types of placeholders are specifically contained in the original user prompt.
[0076] In this embodiment, a database providing optimization example information is pre-set. This optimization example information is used to guide the LLM on how to optimize the original user prompts. In an optional embodiment, a set of optimization example information may consist of two main parts: a sample of user prompts to be optimized, and a sample of optimized user prompts.
[0077] It should be noted that the "optimized user prompt word sample" here may only correspond to the "optimized content of the first part" mentioned above, that is, it may not include the second part corresponding to the declaration placeholder, or it may include both parts.
[0078] Additionally, in some optimized example information in the database, except for the second part of the optimized user prompt word sample, other positions (including the first part of the optimized user prompt word sample and the user prompt word sample to be optimized) may or may not contain placeholders for the first expression format.
[0079] For the current input user suggestion word, optimized example information matching the original user suggestion word is retrieved from the database. Specifically, the original user suggestion word can be embedded and encoded to obtain its corresponding embedding representation vector. Similarly, each optimized example information in the database is embedded and encoded in the same way to obtain its corresponding embedding representation vector. Then, the similarity (e.g., cosine similarity) between the embedding representation vector corresponding to the original user suggestion word and the embedding representation vector corresponding to each optimized example information is calculated. Based on the similarity ranking, one or a set number of optimized example information with high similarity is selected as optimized example information matching the original user suggestion word.
[0080] Subsequently, for the selected optimized example information, if it originally contains a placeholder in the first representation format, it can be modified to a second representation format that represents a reference placeholder. If it does not contain a placeholder in the first representation format, a placeholder in the second representation format can be inserted at a reasonable position. In this case, the type of the inserted placeholder is consistent with the type of the placeholder contained in the original user prompt. The optimized example information can be rewritten appropriately to complete the insertion, which will be described in detail in the following embodiments.
[0081] In this embodiment, it is assumed that the second representation format is: @var iab le@, where var iab le represents the type description of the placeholder, such as @document@. Based on the modification of the second representation format, the LLM can be guided to optimize the original user prompt words according to this format, that is, when generating the optimized content of "first part", the second representation format is used to introduce the placeholder.
[0082] Next, a system prompt containing the original user prompt and the modified optimized example information is generated, and the system prompt is input into the LLM so that the LLM can optimize the original user prompt based on the optimized example information. The first part of the optimized user prompt corresponding to the original user prompt is output, where the placeholders in the first part are in the second representation format.
[0083] Next, the placeholder declaration information corresponding to the placeholders in the original user prompt is obtained, and the placeholder declaration information is determined as the second part of the optimized user prompt, wherein the placeholder declaration information includes the placeholders of the first representation format in the original user prompt.
[0084] This gives us the complete optimized user suggestion words, consisting of the first and second parts mentioned above.
[0085] Next, based on the placeholders in the first representation format contained in the second part of the optimized user prompts, relevant knowledge information corresponding to each placeholder can be retrieved from a preset knowledge base and filled into the placeholders in the first representation format contained in the second part. The optimized user prompts, now filled with relevant knowledge information, and the task input data are then input into the LLM to obtain the task output results. For example, in a question-and-answer scenario, the task input data is a user question, and the task output is the answer to that user question. In a summary generation scenario, the task input data is an article, and the task output is the summary content generated for that article.
[0086] For ease of understanding, an optional format for the above system prompts is given below:
[0087] You are an expert in writing and optimizing prompts. Your task is to optimize the user-provided prompt so that the optimized user prompt includes a description of the role or personality of the AI assistant, skill points, and some restrictions.
[0088] Please note:
[0089] 1. The optimized user prompt must be consistent with the original user prompt in meaning... Figure 1 ...
[0090] 2. Pay attention to the role description and skill point description...
[0091] 3. The description of the skill points should...
[0092] The following are some examples:
[0093] <Example 1>
[0094] Optimize the content of Example Information 1...
[0095] < / Example 1>
[0096] <Example 2>
[0097] Optimize the content of Example Information 2...
[0098] < / Example 2>
[0099] ...
[0100] $$Original user prompt$$: Original user prompt
[0101] $$Optimized user prompt$$:
[0102] As can be seen from the above illustration, the system prompt can include relevant content such as the optimization task description information, one or more optimized example information recalled from the database, the original user prompt input, etc.
[0103] The following gives a specific illustration of the system prompt:
[0104] You are an expert in writing and optimizing prompts. Your task is to optimize the user-provided prompt so that the optimized user prompt includes a description of the role or personality of the AI assistant, skill points, and some restrictions.
[0105] Please note:
[0106] 1. The optimized user prompt must be consistent with the original user prompt in meaning... Figure 1 ...
[0107] 2. Pay attention to the role description and skill point description...
[0108] 3. The description of skill points should...
[0109] Here are some examples:
[0110] <Example 1>
[0111] $$Original User Prompt $$: You are a securities expert who can professionally answer related investment, market, and other questions. When necessary, you can utilize relevant tools to obtain related information.
[0112] ${document}
[0113] #Sample
[0114] ${samp le}
[0115] #Memory
[0116] When answering user questions, try to forget most irrelevant information. Only remember and use information that is highly relevant to the current question or conversation. Ensure your answer is concise, accurate, and focused on the user's current question or topic. Information:
[0117] ${memory}
[0118] $$Optimized user prompt text$$:#role$$:
[0119] You are a securities expert, skilled at answering questions related to investment, markets, and related topics. You have extensive experience in both domestic and international capital markets and various types of securities products, and your answers are accurate and detailed.
[0120] ##Skill
[0121] ###Skill 1: Answering Investment Questions
[0122] - Provide professional and accurate investment advice and answers based on users' questions.
[0123] - When necessary, utilize relevant tools to obtain real-time information about the securities market.
[0124] ###Skill 2: Analyzing Market Trends
[0125] - Analyze and predict market trends based on current market information.
[0126] - Provides market analysis reports to help users understand current market dynamics.
[0127] Skill 3: Providing information on securities products
[0128] - Provides detailed introductions to various types of securities products.
[0129] - Recommend suitable securities products according to the user's investment needs.
[0130] ## Restrictions:
[0131] - Only answer questions related to the securities market and investment.
[0132] - Provide professional and accurate investment advice and answers based on the user's questions.
[0133] - Always maintain a professional and neutral stance, and avoid giving overly pessimistic or overly optimistic predictions about the market or specific products.
[0134]
【#Memory
[0135] When answering the user's questions, try to forget most of the irrelevant information. Only remember and use this information when the information provided by the user is highly relevant to the current question or conversation content. Please ensure that your answer is concise, accurate, and focused on the user's current question or conversation topic. Information:
[0136] ${memory}
[0137] # Example
[0138] ${sample}
[0139] # Knowledge Base
[0140] Please remember the following materials, which may be helpful for answering questions:
[0141] ${document}】
[0142] < / Example 1>
[0143] $$Original user prompt$$: You are called Youyou and can help you answer questions as much as possible.
[0144] # Knowledge Base
[0145] Please remember the following materials, which may be helpful for answering questions.
[0146] ${documents}
[0147] # Example
[0148] ${sample}
[0149] $$Optimized user prompt$$:
[0150] It should be noted that in the examples above, the bold text within 【】 indicates the case where the optimized user prompt in optimization example information 1 contains "part two," which is optional. The "part one" in the optimized user prompt in optimization example information 1 does not indicate the placeholder for the first representation format or the process of modifying its second representation format. The final italicized text indicates the original user prompt that needs optimization.
[0151] Based on the above examples, the first part of the optimized user prompt word output by LLM based on the above system prompt words is, for example:
[0152] #Role
[0153] You are a knowledgeable assistant, able to answer users' questions using a provided knowledge base and information from your memory. Your answers should be concise, accurate, and focused on the user's current question or topic of conversation.
[0154] ##Skill
[0155] ###Skill 1: Answering questions using a knowledge base
[0156] **Task:** Memorize and understand the given knowledge base content (@documents@).
[0157] -**implement**:
[0158] -When a user asks a question, relevant information is retrieved from the knowledge base to provide an answer.
[0159] - If there is no direct answer in the knowledge base, you can use search tools to get more information and clearly indicate the source of the information.
[0160] ###Skill 2: Processing Samples
[0161] **Task:** Refer to the sample (@samples@) to learn how to better answer similar questions.
[0162] -**implement**:
[0163] -Adjust your answers according to the format and style in the sample to ensure consistency and accuracy.
[0164] - Ensure your answers meet the professionalism and objectivity standards outlined in the sample.
[0165] ###Skill 3: Memory Management
[0166] **Task:** When answering user questions, try to forget most of the irrelevant information.
[0167] -**implement**:
[0168] - Information is only remembered and used when it is highly relevant to the current question or conversation.
[0169] - Ensure your answer is concise, accurate, and focused on the user's current question or topic of conversation.
[0170] ##limit
[0171] - **Knowledge Base Based:** Answers must be based on the provided knowledge base (@documents@) and samples (@samples@).
[0172] **Search Tools:** If you need additional information, you can use search tools to obtain it and clearly indicate the source of the information.
[0173] **Avoid going beyond the scope:** Do not provide answers that are outside the scope of the knowledge base unless the accuracy of the information has been confirmed through search tools.
[0174] **Simplicity:** Keep your answers concise and accurate, avoiding lengthy and unnecessary details.
[0175] -**Memory Management**: Only reference information from memory (@{memory@) when necessary, and ensure that this information is highly relevant to the current problem.
[0176] As illustrated above, the first part of the optimized user prompt output by LLM can contain placeholders of the same type as those in the original user prompt, only the format has changed from the first format representing a declaration to the second format representing a reference. Furthermore, the same placeholder can appear once or multiple times in the first part, with its position determined by LLM based on the generated context.
[0177] Additionally, if the placeholders in the first part of the LLM output are not in the second representation format, they can be modified to the second representation format. For example, if the first part retains some of the first representation format content declared by placeholders in the original user prompt, it can be deleted and replaced with the second representation format.
[0178] Next, based on the placeholders actually contained in the original user suggestion, the corresponding placeholder declaration information is obtained, and this placeholder declaration information is determined as the second part of the optimized user suggestion. For example, the second part can be inserted before, after, or at a predetermined position, such as before the first part. Continuing the example above, assuming it is inserted below the first part, the final optimized user suggestion is as follows:
[0179] #Role
[0180] You are a knowledgeable assistant, able to answer users' questions using a provided knowledge base and information from your memory. Your answers should be concise, accurate, and focused on the user's current question or topic of conversation.
[0181] ##Skill
[0182] ###Skill 1: Answering questions using a knowledge base
[0183] **Task:** Memorize and understand the given knowledge base content (@documents@).
[0184] -**implement**:
[0185] -When a user asks a question, relevant information is retrieved from the knowledge base to provide an answer.
[0186] - If there is no direct answer in the knowledge base, you can use search tools to get more information and clearly indicate the source of the information.
[0187] ###Skill 2: Processing Samples
[0188] **Task:** Refer to the sample (@samples@) to learn how to better answer similar questions.
[0189] -**implement**:
[0190] -Adjust your answers according to the format and style in the sample to ensure consistency and accuracy.
[0191] - Ensure your answers meet the professionalism and objectivity standards outlined in the sample.
[0192] ###Skill 3: Memory Management
[0193] **Task:** When answering user questions, try to forget most of the irrelevant information.
[0194] -**implement**:
[0195] - Information is only remembered and used when it is highly relevant to the current question or conversation.
[0196] - Ensure your answer is concise, accurate, and focused on the user's current question or topic of conversation.
[0197] ##limit
[0198] - **Knowledge Base Based:** Answers must be based on the provided knowledge base (@documents@) and samples (@samples@).
[0199] **Search Tools:** If you need additional information, you can use search tools to obtain it and clearly indicate the source of the information.
[0200] **Avoid going beyond the scope:** Do not provide answers that are outside the scope of the knowledge base unless the accuracy of the information has been confirmed through search tools.
[0201] **Simplicity:** Keep your answers concise and accurate, avoiding lengthy and unnecessary details.
[0202] -**Memory Management**: Only reference information from memory (@{memory@) when necessary, and ensure that this information is highly relevant to the current problem.
[0203] #Sample
[0204] ${samp le}
[0205] #knowledge base
[0206] Please remember the following information, as it may be helpful in answering your question:
[0207] ${document}
[0208] In the prompt word optimization scheme provided in this application embodiment, placeholders are described in two parts: placeholder declaration and placeholder reference (or placeholder usage), and different representation formats are used to distinguish them. For example, the placeholder declaration uses a first representation format, and the placeholder reference uses a second representation format. In the process of optimizing the original user prompt word containing placeholders in the first representation format, firstly, only the first part of the optimization information is generated using a large language model—for placeholders, this only generates references to placeholders. Then, the second part of the optimization information—for placeholders, this inserts placeholder declaration information—is inserted. Because the first part of the optimization information optimizes the description content in the original user prompt word, and the second part of the optimization information maintains good consistency with the declaration results of placeholders in the original user prompt word, the optimized user prompt word has a good optimization effect and can completely and accurately reproduce the user's usage needs for the placeholders in the original user prompt word.
[0209] In this embodiment of the application, the case where the original user prompt contains placeholders is further divided into the following two situations:
[0210] The first scenario: The placeholders in the original user prompt are part or all of multiple preset placeholders, meaning that the placeholders in the original user prompt are contained within multiple preset placeholders.
[0211] The second scenario: The placeholder in the original user suggestion is not included in multiple preset placeholders, which is a non-preset placeholder.
[0212] Placeholders in the database that do not have corresponding optimized example information are considered non-preset placeholders; conversely, placeholders in the database that have corresponding optimized example information are considered preset placeholders.
[0213] The following is combined with Figure 2 and Figure 3 The embodiments shown illustrate the optimization process of the original user suggestion words in the two cases described above.
[0214] Figure 2 A flowchart of a prompt word optimization method provided in an embodiment of this application is shown below. Figure 2 As shown, the method includes the following steps:
[0215] 201. If it is identified that the original user prompt word includes at least one target preset placeholder, then retrieve the first optimized example information that matches the original user prompt word from the first database. Each optimized example information in the first database includes at least one of multiple preset placeholders, and at least one target preset placeholder is included in the multiple preset placeholders. The preset placeholders included in the original user prompt word and each optimized example information adopt the first representation format for declaring placeholders.
[0216] 202. Modify the first representation format of the preset placeholder in the first optimized example information to the second representation format of the reference placeholder.
[0217] 203. Generate a first system prompt word containing the original user prompt word and the modified first optimized example information, and input the first system prompt word into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word according to the first system prompt word. At least one target preset placeholder in the first part is in the second representation format.
[0218] 204. Obtain placeholder declaration information corresponding to at least one target preset placeholder in the original user prompt, and determine the placeholder declaration information as the second part of the optimized user prompt, wherein the placeholder declaration information includes at least one target preset placeholder in a first representation format.
[0219] In this embodiment, firstly, it is necessary to identify whether the original user prompt contains preset placeholders. Specifically, based on the regular expression corresponding to the first representation format, it can be identified whether the original user prompt contains placeholders of the first representation format. If it does, the placeholder type description information of the placeholders of the first representation format in the original user prompt is extracted, and then compared with the placeholder type description information of multiple preset placeholders. If the placeholder type description information matches the placeholder type description information of at least one target preset placeholder, then the placeholder of the first representation format in the original user prompt is determined to be the at least one target preset placeholder. It can be understood that if k (k≥1) placeholder type description information is extracted from the original user prompt, and comparison reveals that all k placeholders are preset placeholders, then k target preset placeholders are obtained. The matching of placeholder description information can be completely identical or different expressions with the same semantics.
[0220] In this embodiment, a corresponding first database is set up for multiple preset placeholders. In an optional embodiment, to improve the retrieval efficiency of the database, a corresponding set of optimized example information can be set up in the first database for different combinations of these multiple preset placeholders. For example, assuming the multiple preset placeholders are: document, sample, and memory, then a total of 7 combinations can be formed. Taking one of the combinations, which includes these three placeholders (document + sample + memory), as an example, a corresponding set of optimized example information can be set up in the first database, and each optimized example information in this set contains all three placeholders.
[0221] Based on this, optionally, retrieving first optimized example information matching the original user prompt word from the first database can be implemented as follows: determining at least one optimized example information corresponding to a combination of at least one target preset placeholder in the first database, wherein each of the at least one optimized example information contains the at least one target preset placeholder; then, determining the embedding representation vector corresponding to the original user prompt word and the embedding representation vector corresponding to each of the at least one optimized example information; thereby, determining at least one first optimized example information matching the original user prompt word based on the similarity between the embedding representation vector corresponding to the original user prompt word and the embedding representation vector corresponding to each of the at least one optimized example information.
[0222] In the above example, if the combination of at least one target preset placeholder is (document+sample+memory), then the corresponding at least one optimized example information is the various optimized example information contained in the corresponding optimized example information set.
[0223] By managing the optimized example information in the first database in this way, it is possible to efficiently and accurately retrieve optimized example information that matches the original user prompt, because each retrieved first optimized example information contains a placeholder that matches the original user prompt.
[0224] Since each selected first-optimized example contains a preset placeholder with a first representation format consistent with the original user prompt, the first representation format of the preset placeholder in each first-optimized example can be directly modified to a second representation format representing a reference placeholder. Specifically, the preset placeholder for each first representation format can still be found using the regular expression method described above, and its format can be modified accordingly.
[0225] Next, a first system prompt word containing the original user prompt word and the modified first optimized example information is generated, and the first system prompt word is input into the LLM so that the LLM outputs the first part of the optimized user prompt word corresponding to the original user prompt word. As described in the foregoing embodiments, at least one target preset placeholder in this first part is in the second representation format at this time.
[0226] Then, placeholder declaration information corresponding to at least one target preset placeholder in the original user prompt is obtained, and the placeholder declaration information is determined as the second part of the optimized user prompt, wherein the placeholder declaration information includes at least one target preset placeholder in a first representation format.
[0227] In an alternative embodiment, the placeholder declaration information may be extracted from the original user prompt words using a set extraction code.
[0228] In another optional embodiment, a set of placeholder declaration information corresponding to different preset placeholder combinations can be pre-set. This set of placeholder declaration information includes preset placeholder declaration information corresponding to each preset placeholder combination. Preset placeholder declaration information corresponding to a combination of at least one target preset placeholder can be determined from this set of preset placeholder declaration information. Continuing with the above (document + sample + memory) combination, placeholder declaration information containing these three types of placeholders can be pre-set, for example:
[0229] #Memory
[0230] When answering user questions, try to forget most irrelevant information. Only remember and use information that is highly relevant to the current question or conversation. Ensure your answer is concise, accurate, and focused on the user's current question or topic. Information:
[0231] ${memory}
[0232] #Sample
[0233] ${samp le}
[0234] #knowledge base
[0235] Please remember the following information, as it may be helpful in answering your question:
[0236] ${document}
[0237] Therefore, for each original user prompt containing these three placeholders, the second part of the corresponding optimized user prompt will be the aforementioned preset placeholder declaration information.
[0238] Figure 3 A flowchart of a prompt word optimization method provided in an embodiment of this application is shown below. Figure 3 As shown, the method includes the following steps:
[0239] 301. If the original user prompt word is identified to include a non-preset placeholder using a first representation format that represents a declaration placeholder, then retrieve second optimized example information matching the original user prompt word from the second database, wherein each optimized example information in the second database does not include a preset placeholder.
[0240] 302. Generate a second system prompt word to indicate the rewriting of the second optimized example information, and input the second system prompt word into the large language model so that the large language model outputs the rewritten second optimized example information according to the second system prompt word. The rewritten second optimized example information includes a non-preset placeholder representing the second representation format of the reference placeholder.
[0241] 303. Generate a third system prompt word containing the original user prompt word and the rewritten second optimized example information, and input the third system prompt word into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word according to the third system prompt word, wherein the non-preset placeholders in the first part are the second representation format.
[0242] 304. Extract the placeholder declaration information corresponding to the non-preset placeholder from the original user prompt words, and determine the placeholder declaration information as the second part of the optimized user prompt words, wherein the non-preset placeholder in the first representation format is in the placeholder declaration information.
[0243] In this embodiment, firstly, it is necessary to identify whether the original user prompt contains non-preset placeholders. Specifically, based on the regular expression corresponding to the first representation format, it can be determined whether the original user prompt contains placeholders of the first representation format. If it does, the placeholder type description information of the placeholders of the first representation format in the original user prompt is extracted, and then compared with the placeholder type description information of the aforementioned multiple preset placeholders. If the placeholder type description information does not match the placeholder type description information of any of the preset placeholders, then the placeholders of the first representation format in the original user prompt are determined to be non-preset placeholders. It can be understood that if k (k≥1) placeholder type description information are extracted from the original user prompt, and it is found through comparison that none of these k placeholders are preset placeholders, then k non-preset placeholders are obtained.
[0244] In this embodiment, in addition to a first database in which each optimized example information contains at least one preset placeholder, a second database is also provided, in which each optimized example information does not contain a placeholder. Since the non-preset placeholders contained in the original user prompt will not appear in the optimized example information in the first database, it is necessary to recall second optimized example information matching the original user prompt from the second database. Specifically, this recall can be accomplished through the similarity between embedded representation vectors, as described in the previous embodiments, and will not be repeated here.
[0245] Since the second optimized example information recalled does not contain the non-preset placeholder from the original user prompt, in order to guide the LLM to complete the optimization of the original user prompt based on the second optimized example information, the second optimized example information can be rewritten to incorporate the non-preset placeholder.
[0246] Specifically, a second system prompt word is generated to instruct the rewriting of the second optimized example information, and the second system prompt word is input into the LLM so that the LLM outputs the rewritten second optimized example information according to the second system prompt word. The rewritten second optimized example information includes a non-preset placeholder in the second representation format.
[0247] Below is an example of a prompt word from the second system:
[0248] #Task Description
[0249] You are an expert in writing and optimizing suggestion keywords.
[0250] Here are examples of how the definitions of {matches_examples_n} placeholders are actually referenced:
[0251] {matches_examp les}
[0252] Please dynamically insert placeholder references based on the content of the following {example_n} examples:
[0253] {examp les}
[0254] #Important Notes
[0255] 1. Each sample must insert {matches_examples_n} placeholder references, and the inserted sample must maintain semantic consistency with the original sample content;
[0256] 2. The number of examples referenced by the inserted placeholders in the output must be {example_n}.
[0257] #Output Format
[0258] Output the example after inserting the placeholder reference directly; do not output any other information.
[0259] In the example above, the `{matches_examp les_n}` placeholders represent the non-preset placeholders contained in the original user suggestion words. `{matches_examp les}` is an example of inserting placeholder references. `{examp le_n}` samples represent the number of second-optimized example messages retrieved from the second database. `{examp les}` indicates the location where each second-optimized example message is filled.
[0260] After LLM rewrites the placeholders introduced in the second optimized example information based on the second system prompt, it generates a third system prompt containing the original user prompt and the rewritten second optimized example information. The third system prompt is then input into LLM so that LLM outputs the first part of the optimized user prompt corresponding to the original user prompt based on the third system prompt. At this time, the non-preset placeholders in the first part are in the second representation format.
[0261] Optionally, the placeholder declaration information corresponding to the non-preset placeholder can be extracted from the original user prompt using the set extraction code, and the placeholder declaration information can be determined as the second part of the optimized user prompt.
[0262] The final optimized user suggestion words were obtained, consisting of the first and second parts mentioned above.
[0263] It should be noted that the above embodiments mainly describe the case where the placeholders in the original user prompt are either all preset placeholders or all non-preset placeholders. In fact, if the placeholders in the original user prompt are partly preset placeholders and partly non-preset placeholders, then optionally, the processing steps described above can be used to obtain two optimized user prompts corresponding to the original user prompt. Then, the first part of the two optimized user prompts is deduplicated and merged, and the second part of the two optimized user prompts is also deduplicated and merged. Finally, the optimized user prompt is obtained by concatenating the processing results of these two parts. Alternatively, optionally, the original user prompt can be split into two parts: a user prompt containing preset placeholders and a user prompt containing non-preset placeholders. The processing steps described above can be used to obtain the optimized user prompt corresponding to each user prompt, and then deduplication and merging can be performed to obtain the final optimized user prompt.
[0264] The following is combined Figure 4 This illustrates an optional practical application process of the prompt word optimization method provided in the embodiments of this application.
[0265] like Figure 4 As shown, the application process may include the following steps:
[0266] 1. Obtain the original user prompt words. Figure 4 An example of a raw user suggestion word is given in the document.
[0267] 2. Intent Recognition. This mainly involves analyzing the placeholders in the original user prompt and vectorizing the original user prompt: embed_with_query. The analysis of placeholders in the original user prompt primarily involves identifying whether the original user prompt contains placeholders, what types of placeholders are included, and the meaning of each placeholder.
[0268] For example, as described in the previous embodiments, the original user prompt words are identified based on regular expressions as including one or more preset placeholders, or containing one or more non-preset placeholders, or not containing any placeholders.
[0269] 3. Optimized example recall. This setting includes a database without placeholders. Figure 4 (represented as DB1) and databases containing preset placeholders ( Figure 4In DB2, for example, optimized examples in DB2 all contain at least some of the preset placeholders for the declaration formats ${document}, ${sample}, and ${memory}. Based on the recognition results of the above placeholders, the following cases are identified:
[0270] If the original user suggestion does not contain placeholders, retrieve the optimized matching example from DB1;
[0271] If the original user suggestion contains a preset placeholder, retrieve the matching optimized example from DB2;
[0272] If the original user suggestion contains a non-preset placeholder, then retrieve the matching optimized example from DB1.
[0273] As described in the previous embodiments, during the recall process, the recall of matching optimized examples is completed based on the similarity between the vectorized results of the original user prompt words and the vectorized results of each optimized example in the database. The number of examples recalled can be preset.
[0274] Additionally, for the two scenarios where the original user prompt contains placeholders, the corresponding placeholders in the reference format (second representation format) need to be dynamically inserted into the retrieved optimization examples before use. For example, for the optimization example retrieved from DB2, the representation format of the placeholders is changed from the declaration format (first representation format) to the reference format (second representation format). For the optimization example retrieved from DB1, non-preset placeholders contained in the original user prompt are inserted, and their format is reference format. For the scenario where the original user prompt does not contain placeholders, existing optimization methods can be used for optimization.
[0275] 4. System prompt execution. The retrieved and processed optimized example is filled into the system prompt template to obtain the system prompt. This is then input into the LLM to obtain the first part of the optimized user prompt output by the LLM.
[0276] 5. Post-processing. Obtain the placeholder declaration information corresponding to the placeholders contained in the original user prompt, and use this as the second part of the optimized user prompt. In practice, the position of the placeholder declaration information in the optimized user prompt is not specifically limited.
[0277] Specifically, if the first part of the optimized user prompt still contains placeholders for declaration formats, the declaration formats can be deleted and replaced with reference formats to complete the correction. Then, based on the placeholders contained in the original user prompt, the corresponding placeholder declaration information is inserted into the optimized user prompt. Figure 4 The document provides an example of an optimized user suggestion word based on the original user suggestion word.
[0278] 6. User Evaluation. Users can evaluate whether the optimized user suggestion words meet their needs. If adjustments are needed, proceed to step 7; otherwise, if they meet expectations, proceed to step 8.
[0279] 7. Online editing. Users can edit and modify the optimized user prompts, and then proceed to step 8.
[0280] 8. Go live.
[0281] The prompt word optimization apparatus of one or more embodiments of this application will be described in detail below. Those skilled in the art will understand that these apparatuses can all be configured using commercially available hardware components through the steps taught in this solution.
[0282] Figure 5 This is a schematic diagram of the structure of a prompt word optimization device provided in an embodiment of this application, such as... Figure 5 As shown, the device includes: an identification module 11, a conversion module 12, a first optimization module 13, and a second optimization module 14.
[0283] The identification module 11 is used to retrieve optimized example information matching the original user prompt word from the database if the original user prompt word contains a placeholder, wherein the placeholder contained in the original user prompt word adopts a first representation format for declaring a placeholder.
[0284] The conversion module 12 is used to determine that the placeholder in the optimized example information is a second representation format representing a reference placeholder.
[0285] The first optimization module 13 is used to generate a system prompt word containing the original user prompt word and the optimized example information, and input the system prompt word into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word according to the system prompt word, wherein the placeholders in the first part are the second representation format.
[0286] The second optimization module 14 is used to obtain placeholder declaration information corresponding to the placeholder in the original user prompt, and to determine the placeholder declaration information as the second part of the optimized user prompt, wherein the placeholder in the placeholder declaration information is the first representation format.
[0287] Optionally, the identification module 11 is specifically configured to: if the original user prompt word is identified to include at least one target preset placeholder, then retrieve first optimized example information matching the original user prompt word from the first database, wherein the first optimized example information includes the at least one target preset placeholder, wherein each optimized example information in the first database includes at least one of a plurality of preset placeholders, the at least one target preset placeholder is included in the plurality of preset placeholders, and the preset placeholders included in each optimized example information adopt the first representation format.
[0288] Optionally, the conversion module 12 is specifically used to: modify the first representation format of the preset placeholder in the first optimized example information to a second representation format representing the reference placeholder.
[0289] Optionally, the first optimization module 13 is specifically used to: generate a first system prompt word containing the original user prompt word and the modified first optimized example information, and input the first system prompt word into the large language model, so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word according to the first system prompt word, wherein the at least one target preset placeholder existing in the first part is the second representation format.
[0290] Optionally, the second optimization module 14 is specifically used to: obtain placeholder declaration information corresponding to at least one target preset placeholder in the original user prompt word, and determine the placeholder declaration information as the second part of the optimized user prompt word, wherein the at least one target preset placeholder is in the first representation format in the placeholder declaration information.
[0291] Optionally, the second optimization module 14 is specifically used to: determine, from a preset set of placeholder declaration information, preset placeholder declaration information corresponding to a combination of the at least one target preset placeholder, wherein the set of placeholder declaration information includes preset placeholder declaration information corresponding to different preset placeholder combinations.
[0292] Optionally, the identification module 11 is specifically configured to: identify whether the original user prompt word contains a placeholder of the first representation format according to the regular expression corresponding to the first representation format; if it contains a placeholder, extract the placeholder type description information from the placeholder of the first representation format in the original user prompt word; if the placeholder type description information matches the placeholder type description information of the at least one target preset placeholder, determine that the placeholder of the first representation format in the original user prompt word is the at least one target preset placeholder.
[0293] Optionally, the identification module 11 is specifically configured to: determine at least one optimized example information corresponding to the combination of the at least one target preset placeholder in the first database, wherein each of the at least one optimized example information contains the at least one target preset placeholder; determine the embedding representation vector corresponding to the original user prompt word, and the embedding representation vector corresponding to each of the at least one optimized example information; and determine at least one first optimized example information matching the original user prompt word based on the similarity between the embedding representation vector corresponding to the original user prompt word and the embedding representation vector corresponding to each of the at least one optimized example information.
[0294] Optionally, the identification module 11 is specifically used to: if the original user prompt word is identified to include a non-preset placeholder in the first representation format, then retrieve second optimized example information matching the original user prompt word from the second database, wherein each optimized example information in the second database does not include a preset placeholder.
[0295] Optionally, the conversion module 12 is specifically used to: generate a second system prompt word that indicates the rewriting of the second optimized example information, and input the second system prompt word into the large language model, so that the large language model outputs the rewritten second optimized example information according to the second system prompt word, wherein the rewritten second optimized example information includes the non-preset placeholder of the second representation format.
[0296] Optionally, the first optimization module 13 is specifically used to: generate a third system prompt word containing the original user prompt word and the rewritten second optimization example information, and input the third system prompt word into the large language model, so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word according to the third system prompt word, wherein the non-preset placeholder in the first part is the second representation format.
[0297] Optionally, the second optimization module 14 is specifically used to: extract the placeholder declaration information corresponding to the non-preset placeholder from the original user prompt words, and determine the placeholder declaration information as the second part of the optimized user prompt words, wherein the non-preset placeholder is in the first representation format in the placeholder declaration information.
[0298] Optionally, the identification module 11 is specifically configured to: identify whether the original user prompt word contains a placeholder of the first representation format according to the regular expression corresponding to the first representation format; if it contains a placeholder, extract the placeholder type description information from the placeholder of the first representation format in the original user prompt word; if the placeholder type description information does not match the placeholder type description information of multiple preset placeholders, determine that the placeholder of the first representation format in the original user prompt word is a non-preset placeholder.
[0299] Optionally, the device further includes: a task processing module, configured to obtain relevant knowledge information from a preset knowledge base based on the placeholders of the first representation format contained in the second part of the optimized user prompt word, and fill them into the placeholders of the first representation format contained in the second part accordingly; and input the optimized user prompt word filled with the relevant knowledge information and the task input data into the large language model to obtain the task output result.
[0300] Figure 5 The device shown can perform the steps in the prompt word optimization method in the foregoing embodiments. For detailed execution process and technical effects, please refer to the description in the foregoing embodiments, which will not be repeated here.
[0301] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 6 As shown, in practice, this electronic device includes a memory 21 and a processor 22.
[0302] Memory 21 is used to store computer programs and can be configured to store various other data to support operation on the electronic device. Examples of this data include instructions for any application or method used to operate on the electronic device, data structures, contact data, phone book data, messages, pictures, videos, etc.
[0303] The processor 22, coupled to the memory 21, is used to execute the computer program in the memory 21 to implement the prompt word optimization method provided in the foregoing embodiments.
[0304] Furthermore, such as Figure 6 As shown, the electronic device also includes other components such as a communication component 23, a display 24, a power supply component 25, and an audio component 26. Figure 6 The diagram only shows some components and does not mean that the electronic device includes only these components. Figure 6 The components shown are as follows. The electronic device in this embodiment can be a terminal device such as a desktop computer, laptop computer, smartphone, or IoT device, or a server device such as a conventional server, cloud server, or server array.
[0305] The aforementioned memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random-Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0306] The aforementioned communication component is configured to facilitate wired or wireless communication between the device containing the communication component and other devices. The device containing the communication component can access wireless networks based on communication standards, such as 2G, 3G, 4G / LTE, 5G, or combinations thereof. In one exemplary embodiment, the communication component receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel.
[0307] The aforementioned display includes a screen, which may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation.
[0308] The aforementioned power supply components provide power to various components within the device in which they reside. These power supply components may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power to the device in which they reside.
[0309] The aforementioned audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC) configured to receive external audio signals when the device containing the audio component is in an operating mode, such as call mode, recording mode, or voice recognition mode. The received audio signals can be further stored in memory or transmitted via a communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals.
[0310] Accordingly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, enables the processor to implement the steps in the above-described method embodiments. The computer-readable storage medium includes volatile or non-volatile or a combination thereof, and can be removable or non-removable. Examples of computer-readable storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random-access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technologies, CD-ROM, digital video disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium.
[0311] Accordingly, this application also provides a computer program product, which includes a computer program or instructions that, when executed by a processor, cause the processor to implement the steps in the above method embodiments. It should be understood that each step or combination of steps in the above method flow can be implemented by the computer program or instructions. Furthermore, these computer programs or instructions can be applied to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device, enabling the processor of the general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to function as an apparatus for implementing the corresponding functions in the above method embodiments.
[0312] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for optimizing prompt words, characterized in that, include: If a placeholder is identified in the original user prompt, optimized example information matching the original user prompt is retrieved from the database. The placeholder contained in the original user prompt adopts a first representation format for declaring a placeholder. The placeholder in the optimized example information is determined to be a second representation format representing a reference placeholder; Generate a system prompt word containing the original user prompt word and the optimized example information, and input the system prompt word into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word based on the system prompt word, wherein the placeholders in the first part are the second representation format; Obtain the placeholder declaration information corresponding to the placeholder in the original user prompt, and determine the placeholder declaration information as the second part of the optimized user prompt, wherein the placeholder in the placeholder declaration information is the first representation format.
2. The method according to claim 1, characterized in that, If a placeholder is identified in the original user prompt, then optimized example information matching the original user prompt is retrieved from the database, including: If the original user prompt word is identified to include at least one target preset placeholder, then first optimized example information matching the original user prompt word is retrieved from the first database. The first optimized example information includes the at least one target preset placeholder. Each optimized example information in the first database includes at least one of a plurality of preset placeholders. The at least one target preset placeholder is included in the plurality of preset placeholders. The preset placeholders included in each optimized example information all adopt the first representation format.
3. The method according to claim 2, characterized in that, The step of determining that the placeholder in the optimized example information is a second representation format representing a reference placeholder includes: The first representation format of the preset placeholder in the first optimized example information is modified to a second representation format that represents the reference placeholder.
4. The method according to claim 2, characterized in that, The process of generating a system prompt word containing the original user prompt word and the optimized example information, and inputting the system prompt word into a large language model, so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word based on the system prompt word, includes: A first system prompt word containing the original user prompt word and the modified first optimized example information is generated, and the first system prompt word is input into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word according to the first system prompt word, wherein the at least one target preset placeholder existing in the first part is the second representation format.
5. The method according to claim 2, characterized in that, The step of obtaining the placeholder declaration information corresponding to the placeholder in the original user prompt word, and determining the placeholder declaration information as the second part of the optimized user prompt word, includes: Obtain placeholder declaration information corresponding to at least one target preset placeholder in the original user prompt word, and determine the placeholder declaration information as the second part of the optimized user prompt word, wherein the at least one target preset placeholder is in the first representation format in the placeholder declaration information.
6. The method according to claim 5, characterized in that, The step of obtaining the placeholder declaration information corresponding to at least one target preset placeholder in the original user prompt includes: From a set of preset placeholder declaration information, determine the preset placeholder declaration information corresponding to the combination of the at least one target preset placeholder, wherein the set of preset placeholder declaration information includes preset placeholder declaration information corresponding to different preset placeholder combinations.
7. The method according to claim 2, characterized in that, The method further includes: Based on the regular expression corresponding to the first representation format, identify whether the original user prompt word contains a placeholder of the first representation format; If included, extract the placeholder type description information from the placeholders in the first representation format of the original user prompt word; If the placeholder type description information matches the placeholder type description information of the at least one target preset placeholder, then the placeholder in the first representation format in the original user prompt word is determined to be the at least one target preset placeholder.
8. The method according to claim 2, characterized in that, The step of retrieving first optimized example information from the first database that matches the original user suggestion word includes: Determine at least one optimized example information in the first database corresponding to the combination of the at least one target preset placeholder, wherein the at least one optimized example information contains the at least one target preset placeholder; Determine the embedding representation vector corresponding to the original user prompt word, and the embedding representation vector corresponding to each of the at least one optimized example information; Based on the similarity between the embedding representation vector corresponding to the original user prompt word and the embedding representation vector corresponding to each of the at least one optimized example information, at least one first optimized example information matching the original user prompt word is determined.
9. The method according to claim 1, characterized in that, If a placeholder is identified in the original user prompt, then optimized example information matching the original user prompt is retrieved from the database, including: If the original user prompt word is found to contain a non-preset placeholder in the first representation format, then second optimized example information matching the original user prompt word is retrieved from the second database, wherein each optimized example information in the second database does not contain a preset placeholder.
10. The method according to claim 9, characterized in that, The step of determining that the placeholder in the optimized example information is a second representation format representing a reference placeholder includes: A second system prompt word is generated to instruct the rewriting of the second optimized example information, and the second system prompt word is input into the large language model so that the large language model outputs the rewritten second optimized example information according to the second system prompt word. The rewritten second optimized example information includes the non-preset placeholder of the second representation format.
11. The method according to claim 10, characterized in that, The process of generating a system prompt word containing the original user prompt word and the optimized example information, and inputting the system prompt word into a large language model, so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word based on the system prompt word, includes: A third system prompt word containing the original user prompt word and the rewritten second optimized example information is generated, and the third system prompt word is input into the large language model so that the large language model outputs the first part of the optimized user prompt word corresponding to the original user prompt word according to the third system prompt word, wherein the non-preset placeholders in the first part are the second representation format.
12. The method according to claim 9, characterized in that, The step of obtaining the placeholder declaration information corresponding to the placeholder in the original user prompt word, and determining the placeholder declaration information as the second part of the optimized user prompt word, includes: Extract the placeholder declaration information corresponding to the non-preset placeholder from the original user prompt words, and determine the placeholder declaration information as the second part of the optimized user prompt words, wherein the non-preset placeholder is represented in the first format in the placeholder declaration information.
13. The method according to claim 9, characterized in that, The method further includes: Based on the regular expression corresponding to the first representation format, identify whether the original user prompt word contains a placeholder of the first representation format; If included, extract the placeholder type description information from the placeholders in the first representation format of the original user prompt word; If the placeholder type description information does not match the placeholder type description information of multiple preset placeholders, then the placeholder in the first representation format in the original user prompt word is determined to be a non-preset placeholder.
14. The method according to any one of claims 1-13, characterized in that, The method further includes: Based on the placeholders of the first representation format contained in the second part of the optimized user prompt words, relevant knowledge information is obtained from the preset knowledge base and filled into the placeholders of the first representation format contained in the second part accordingly. The optimized user prompts and task input data, after being filled with the relevant knowledge information, are input into the large language model to obtain the task output results.
15. An electronic device, characterized in that, include: The device includes a memory, a processor, and a communication interface; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor performs the prompt word optimization method as described in any one of claims 1 to 14.
16. A non-transitory machine-readable storage medium, characterized in that, The non-transitory machine-readable storage medium stores executable code that, when executed by a processor of an electronic device, causes the processor to perform the prompt word optimization method as described in any one of claims 1 to 14.
17. A computer program product, characterized in that, include: A computer program, when executed by a processor of an electronic device, causes the processor to perform the prompt word optimization method as described in any one of claims 1 to 14.