A method, apparatus, and electronic device for generating prompt words for a large language model.

By constructing error and correct reasoning paths, prompt words for large language models are automatically generated, solving the problem of inaccurate prompt word generation in existing technologies. This achieves automated and controllable prompt word generation, improving the stability of model reasoning and task execution performance.

CN123115309APending Publication Date: 2026-11-17SHUGUANG ZHISUAN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611161332.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-31
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing large language model prompt word optimization schemes cannot generate high-quality error counterexamples that are controllable and reproducible, and lack the ability to diagnose complete error processes, leading to model inference bias and task execution errors.

Method used

By parsing user target information, a first reasoning path representing the incorrect reasoning direction and a second reasoning path representing the correct reasoning direction are constructed. The incorrect reasoning path is executed to obtain the execution result, and prompt words are automatically generated by combining the three types of information, reducing human intervention and improving the accuracy and completeness of prompt words.

Benefits of technology

It achieves automated generation of prompt words for large language models, reduces the degree of human intervention, improves the accuracy and universality of prompt words, and avoids omissions and subjective biases that occur when manually writing them.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115309A_ABST
    Figure CN123115309A_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, and electronic device for generating prompt words for a large language model, which can be applied to the field of large language model technology. The method for generating prompt words for a large language model includes: responding to user input of target information; determining constraints of a target reasoning task based on the target information; generating a first reasoning path and a second reasoning path based on the constraints; wherein the first reasoning path represents the erroneous reasoning direction of the target reasoning task, and the second reasoning path represents the correct reasoning direction of the target reasoning task; applying a large language model to execute multiple reasoning steps in the first reasoning path, obtaining a first execution result of the first reasoning path; and determining prompt words for the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of large language model technology, specifically to a method, apparatus, and electronic device for generating prompt words for a large language model. Background Technology

[0002] Large language models are widely used in complex task scenarios such as AI agents, multi-step reasoning, and tool calls. Prompt words directly determine the stability of model reasoning and the performance of task execution, making prompt word optimization a key step in the implementation of large models.

[0003] In related technologies, prompt word optimization is mainly divided into two types of optimization schemes: manual rule writing and automatic extraction by model self-reasoning. However, existing schemes cannot generate high-quality error counterexamples that are controllable and reproducible, lack the ability to diagnose complete error processes, have unstable quality of positive example output, and have lengthy and messy extraction strategies, making it difficult to form concise and universal optimization prompt words, which can easily cause model inference bias and task execution errors. Summary of the Invention

[0004] In view of the above problems, this application provides a method, apparatus and electronic device for generating prompt words for a large language model.

[0005] The first aspect of this application provides a method for generating prompt words for a large language model. The method includes: responding to user input of target information, determining constraints of a target reasoning task based on the target information; generating a first reasoning path and a second reasoning path based on the constraints; wherein the first reasoning path represents the erroneous reasoning direction of the target reasoning task, and the second reasoning path represents the correct reasoning direction of the target reasoning task; applying a large language model to execute multiple reasoning steps in the first reasoning path, and obtaining a first execution result of the first reasoning path; and determining prompt words for the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result.

[0006] According to an embodiment of this application, the constraints of the target reasoning task are determined based on the target information, including: determining a first constraint and a second constraint for the large language model to perform the target reasoning task based on the target information; wherein the first constraint is a necessary condition to be met for performing the target reasoning task, and the second constraint represents the user's preference type for the target reasoning task.

[0007] According to an embodiment of this application, generating a first inference path based on constraints includes: determining multiple first inference steps that do not satisfy the first constraints based on a pre-configured set of inference steps of a large language model; and determining the first inference path based on the multiple first inference steps.

[0008] According to an embodiment of this application, applying a large language model to execute multiple inference steps in a first inference path and obtaining a first execution result of the first inference path includes: dividing the multiple inference steps in the first inference path into multiple inference trajectories according to a preset step size; applying a large language model to execute multiple inference trajectories to obtain multiple inference results; and for each inference result, obtaining the content that violates the constraints to obtain the first execution result.

[0009] According to an embodiment of this application, determining the prompt words for the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result includes: determining the task execution rule text of the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result, wherein the task execution rule text consists of multiple text contents; performing text compression processing on the task execution rule text, and determining a target number of text contents as the prompt words for the target reasoning task.

[0010] According to embodiments of this application, the task execution rule text includes at least one of the following: text content describing how to satisfy constraints; text content describing how to avoid the first execution result; and text content describing multiple inference steps of the second inference path.

[0011] According to an embodiment of this application, generating a second reasoning path based on constraints includes: obtaining a pre-constructed set of question samples; performing clustering processing on the set of question samples to obtain multiple question clusters, and determining a representative question from each question cluster; for each representative question, generating a sequence of reasoning steps of a large language model when performing a target reasoning task, resulting in multiple inference step sequences; and determining the inference step sequence that satisfies the constraints from the multiple inference step sequences to obtain the second reasoning path.

[0012] According to an embodiment of this application, the method further includes: generating a second reasoning path based on a preset prompt word template and constraints when multiple reasoning step sequences do not meet the constraints.

[0013] A second aspect of this application provides a large language model prompt word generation apparatus, comprising: an information processing module, configured to, in response to user input of target information, determine constraints of a target inference task based on the target information; a path generation module, configured to, based on the constraints, generate a first inference path and a second inference path respectively; wherein the first inference path represents an erroneous inference direction of the target inference task, and the second inference path represents a correct inference direction of the target inference task; a model application module, configured to, apply a large language model to execute multiple inference steps in the first inference path, and obtain a first execution result of the first inference path; and a prompt word generation module, configured to, based on the first inference path, the second inference path, and the first execution result, determine prompt words for the target inference task.

[0014] A third aspect of this application provides an electronic device comprising: one or more processors; and a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method described above. Attached Figure Description

[0015] The above-mentioned contents, other objects, features and advantages of this application will become clearer from the following description of embodiments of this application with reference to the accompanying drawings.

[0016] Figure 1 The illustration shows an application scenario of the method, apparatus, and electronic device for generating large language model prompt words according to embodiments of this application;

[0017] Figure 2 One of the flowcharts for a method of generating large language model prompt words according to an embodiment of this application is shown;

[0018] Figure 3 A second flowchart illustrates a method for generating large language model prompt words according to an embodiment of this application;

[0019] Figure 4 A structural block diagram of a large language model prompt word generation apparatus according to an embodiment of this application is shown;

[0020] Figure 5 A block diagram of an electronic device suitable for implementing a method for generating prompt words for a large language model according to an embodiment of this application is shown. Detailed Implementation

[0021] The embodiments of this application will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of this application. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of this application for ease of explanation. However, it will be apparent that one or more embodiments may be implemented without these specific details. Furthermore, descriptions of well-known structures and technologies are omitted in the following description to avoid unnecessarily obscuring the concepts of this application.

[0022] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The terms “comprising,” “including,” etc., as used herein indicate the presence of features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.

[0023] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.

[0024] When using expressions such as "at least one of A, B and C", they should generally be interpreted in accordance with the meaning that is commonly understood by those skilled in the art (e.g., "a system having at least one of A, B and C" should include, but is not limited to, a system having A alone, a system having B alone, a system having C alone, a system having A and B, a system having A and C, a system having B and C, and / or a system having A, B and C, etc.).

[0025] Embodiments of this application provide a method for generating prompt words for a large language model. The method includes: responding to user input of target information, determining constraints of a target reasoning task based on the target information; generating a first reasoning path and a second reasoning path based on the constraints; wherein the first reasoning path represents the erroneous reasoning direction of the target reasoning task, and the second reasoning path represents the correct reasoning direction of the target reasoning task; applying a large language model to execute multiple reasoning steps in the first reasoning path, and obtaining a first execution result of the first reasoning path; and determining prompt words for the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result.

[0026] Figure 1 The illustration shows an application scenario of a method, apparatus, and electronic device for generating large language model prompt words according to embodiments of this application.

[0027] like Figure 1 As shown, the application scenario according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 serves as a medium for providing a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0028] Users can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 via the network 104 to receive or send messages, etc. Various communication terminal applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103.

[0029] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be various electronic devices with displays that support browsing or uploading, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0030] Server 105 can be a server that provides various services, such as a backend management server that supports websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103 (this is just an example). The backend management server can analyze and process data such as received user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal devices.

[0031] It should be noted that the method for generating large language model prompts provided in this application embodiment can generally be executed by server 105. Correspondingly, the apparatus for generating large language model prompts provided in this application embodiment can generally be located in server 105. The method for generating large language model prompts provided in this application embodiment can also be executed by a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105. Correspondingly, the apparatus for generating large language model prompts provided in this application embodiment can also be located in a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105.

[0032] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0033] The following will be based on Figure 1 The described scene, through Figures 2-5 The method for generating large language model prompt words according to embodiments of this application will be described in detail.

[0034] Figure 2 One of the flowcharts for a method of generating large language model prompt words according to an embodiment of this application is shown.

[0035] like Figure 2 As shown, the method for generating large language model prompt words in this embodiment includes operations S210 to S230.

[0036] Operation S210 responds to user input of target information and determines the constraints of the target reasoning task based on the target information.

[0037] Operation S220 generates a first inference path and a second inference path based on the constraints; wherein the first inference path represents the erroneous inference direction of the target inference task, and the second inference path represents the correct inference direction of the target inference task.

[0038] Operation S230 applies the large language model to execute multiple inference steps in the first inference path and obtains the first execution result of the first inference path.

[0039] Operation S240 determines the prompt words for the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result.

[0040] In the embodiments of this application, the target information is the requirement information input by the user to initiate the target reasoning task.

[0041] In the embodiments of this application, the target reasoning task is a reasoning task to be processed by a large language model, which is determined based on target information.

[0042] In the embodiments of this application, the first reasoning path is a sequence of reasoning steps that characterizes the erroneous reasoning direction of the target reasoning task.

[0043] In the embodiments of this application, the second reasoning path is a sequence of reasoning steps that characterizes the correct reasoning direction of the target reasoning task.

[0044] In the embodiments of this application, the first execution result is the execution feedback information obtained after the large language model executes the reasoning steps of the first reasoning path.

[0045] In the embodiments of this application, the prompt words for the target reasoning task are strategy prompt texts generated based on the forward and reverse reasoning paths and the first execution result, used to guide the large language model to perform similar tasks.

[0046] Specifically, in related technologies, large language models mostly rely on manual summarization of experience to write prompt words, which has poor universality and is prone to omitting error avoidance rules. This application first parses the user's target information to obtain task constraints; then constructs a first reasoning path representing an erroneous reasoning process and a second reasoning path representing a correct reasoning process in parallel; runs the large model to execute the erroneous reasoning path, and collects the first execution result of the violation information generated during the reasoning process of applying the large language model; combining the three types of information—the first reasoning path, the second reasoning path, and the first execution result—automatically generates dedicated prompt words adapted to the target reasoning task. By comparing positive and negative reasoning, hidden erroneous reasoning directions that may be encountered during task execution are discovered, realizing automated generation of prompt words, reducing the degree of human intervention, and improving the accuracy of prompt words.

[0047] For example, a user inputs target information into the large language model: "Plan a 3-day business trip for me to a certain city, allowing only high-speed rail travel, with a total budget not exceeding 5,000 yuan, and prioritizing chain brand hotels." Based on this target information, the target inference task is obtained: "3-day business trip planning for a certain city," and the constraint boundaries of the target inference task are simultaneously parsed. Subsequently, based on the constraints, two completely opposite inference paths are automatically generated: one is an erroneous inference path with rule violations, i.e., a counterexample trajectory, and the other is a correct inference path that fully meets all business trip requirements. The large language model is then invoked to execute the erroneous counterexample path, collecting the complete process of the error occurrence throughout the entire chain, and obtaining the corresponding first execution result. Finally, the full-process data of the erroneous inference path, the standard planning logic of the correct inference path, and the violation record of the first execution result are fused and deduced to automatically generate a dedicated prompt word specifically adapted to the business trip planning task. This prompt word can be directly reused to handle all similar business trip planning needs, without the need for manual writing and debugging of prompt rules throughout the entire process.

[0048] By employing the above method, combining target information to determine task constraints, a first reasoning path representing the direction of incorrect reasoning and a second reasoning path representing the direction of correct reasoning are constructed in parallel. The first reasoning path is executed to obtain the corresponding first execution result. Then, the prompt words for the target reasoning task are automatically generated by integrating the three types of information. By comparing the positive reasoning process, the incorrect reasoning process, and the violation diagnosis information, the inherent execution rules of the task can be mined. This can automatically identify task constraints and potential risks in the reasoning process, reduce reliance on human experience, avoid omissions and subjective biases in manually sorting rules, realize automated generation of prompt words, and improve the completeness and universality of the generated prompt words.

[0049] According to an embodiment of this application, in operation S210, the constraints of the target reasoning task are determined based on the target information, including: determining the first constraint and the second constraint of the large language model to perform the target reasoning task based on the target information; wherein, the first constraint is a necessary condition to be met to perform the target reasoning task, and the second constraint represents the user's preference type for the target reasoning task.

[0050] In the embodiments of this application, the constraints are the limiting conditions that the large language model should follow when performing the target reasoning task, including a first constraint and a second constraint. The first constraint is a necessary condition that must be met to perform the target reasoning task; violating this condition will result in the task outcome not meeting the basic requirements. The second constraint is the user's preference type requirement for the target reasoning task, which belongs to the optimization category.

[0051] Specifically, two types of constraints with different properties are separated from the same target information. The first constraint is a hard, necessary condition; if the large language model violates the first constraint when performing inference tasks, the overall task result will fail. The second constraint is a user preference-based optimization condition used to optimize the output results and is not a mandatory bottom-line requirement. Identifying the two types of constraints separately facilitates the subsequent construction of forward and reverse inference paths.

[0052] For example, the first constraint serves as a necessary condition for the execution of the target reasoning task. For instance, based on the target message, the following first constraints might be obtained: 1. All round-trip transportation must be by high-speed rail; 2. The total cost of the three-day business trip must be strictly controlled within 5000 yuan; 3. All transportation and accommodation must cover the commuting accessibility requirements of the current city's mainstream business districts, and there should be no planning results without a return route. The second constraint represents the user's preference type. For example, 1. Prioritize national chain brand business hotels for accommodation; 2. Avoid peak morning and evening rush hours in the current city's daily itinerary; 3. Allow approximately one hour of free time between business trips for adjustments during business meetings. This type of constraint represents personalized preference requirements that align with the user's business travel habits and can be prioritized without breaking rigid constraints. The second constraint can be determined based on the user's historical question content.

[0053] According to an embodiment of this application, in operation S220, a first reasoning path is generated based on constraints, including operations S2210 to S2220.

[0054] Operation S2210 identifies multiple first inference steps that do not satisfy the first constraint condition based on the pre-configured set of inference steps of the large language model.

[0055] Operation S2220 determines the first inference path based on multiple first inference steps.

[0056] In the embodiments of this application, the pre-configured set of inference steps is a set of basic inference steps that are pre-built for the target inference task and can be invoked.

[0057] Specifically, based on a pre-established set of reasoning steps, reasoning steps that do not meet the hard necessary conditions are selected, and these steps are organized into a complete erroneous reasoning path. By adopting the above method, it is ensured that all reasoning steps come from the set of legal steps, and errors are only due to deviations in internal parameters and logic of the steps, rather than invalid operations.

[0058] For example, the task action space for a business trip planning scenario is constructed in advance, resulting in a set of all executable inference steps for the large model under this task. For instance, the inference step set might include the following steps: filtering round-trip high-speed rail services; matching chain hotel rooms; calculating daily food and accommodation costs; estimating commuting time; and calculating the total cost. Based on this inference step set, a first inference step that does not meet the first constraint condition is generated. For example, the first inference step might include: 1. skipping round-trip transportation verification and directly selecting flights; 2. randomly arranging high-star non-chain hotels without calculating the total cost; 3. directly deriving a solution far exceeding the budget of 5000 yuan without verifying the cost; 4. directly generating an itinerary without matching the commuting routes between the high-speed rail station and the destination. These first inference steps are then pieced together to form a structurally complete first inference path, serving as a counterexample trajectory when the large language model performs the target inference task.

[0059] According to an embodiment of this application, in operation S230, a large language model is applied to execute multiple inference steps in the first inference path to obtain the first execution result of the first inference path, including operations S2310 to S2330.

[0060] Operation S2310 divides multiple reasoning steps in the first reasoning path into multiple reasoning trajectories according to the preset step size.

[0061] Operate S2320 to execute multiple inference trajectories using a large language model, and obtain multiple inference results.

[0062] Operation S2330 retrieves the content that violates the constraints from each inference result, and obtains the first execution result.

[0063] In the embodiments of this application, the preset step size is a pre-set fixed segmentation granularity used to divide the reasoning steps in the first reasoning path.

[0064] In the embodiments of this application, the reasoning trajectory is a segmented reasoning step fragment obtained by dividing the first reasoning path according to a preset step size.

[0065] In the embodiments of this application, each reasoning result is the output content obtained by the large language model executing the corresponding reasoning trajectory.

[0066] Specifically, a pre-set fixed step size is used to uniformly divide the first inference path of a long sequence into multiple independent inference trajectories. These independent inference trajectories are then fed into a large model for execution, yielding segmented inference results. New violations in each inference result are identified sequentially, and these are aggregated to form a temporally sequenced first execution result. By employing this method, fine-grained temporal diagnosis can be achieved, distinguishing between root-cause initial errors and subsequent derived errors, and reconstructing the complete process of how errors gradually arise.

[0067] For example, following a preset step size, the entire first reasoning path is divided into multiple independent reasoning sub-trajectories. The large language model executes each sub-trajectory segment by segment. After each segment is completed, newly occurring violations of task constraints are extracted separately and accumulated incrementally to obtain the first execution result: After the first sub-trajectory is executed, the newly added violation is recorded as "failed to verify the mode of transportation as required, directly setting the outbound transportation to air travel"; after the second sub-trajectory is executed, the newly added violation is recorded as "failed to verify the hotel's qualifications, selecting a non-chain boutique homestay as the accommodation"; after the third sub-trajectory is executed, the newly added violation is recorded as "failed to calculate the total cost, the final overall cost of the plan is 6200 yuan, exceeding the budget threshold of 5000 yuan". By accumulating erroneous evidence segment by segment, a complete erroneous reasoning process is formed.

[0068] By employing the above methods, large language models can identify how erroneous inference results for a target inference task occur step by step, thereby more accurately aligning with the user's questions during the inference strategy generation stage. This achieves more granular and reliable error attribution than traditional single-reflection, further improving the accuracy of large language models in selecting inference strategies.

[0069] According to an embodiment of this application, in operation S240, a prompt word for the target reasoning task is determined based on the first reasoning path, the second reasoning path, and the first execution result, including operations S2410 to S2420.

[0070] Operation S2410 determines the task execution rule text of the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result. The task execution rule text consists of multiple text contents.

[0071] Operation S2420 performs text compression on the task execution rule text and determines the target amount of text content as prompts for the target reasoning task.

[0072] In the embodiments of this application, the task execution rule text is the original strategy text obtained by combining the first reasoning path, the second reasoning path and the first execution result, which contains multiple unorganized task execution logic contents.

[0073] In the embodiments of this application, text compression processing is a process of removing redundant content and standardizing the expression of task execution rule text, including compression extraction and structured rewriting.

[0074] In the embodiments of this application, the target number is a pre-set threshold for the number of entries, used to control the content size of the final prompt word.

[0075] Specifically, the task execution rule text is generated by integrating the first reasoning path, the second reasoning path, and the first execution result. The task execution rule text includes a complete reasoning process, case description, and error analysis. The task execution rule text is then compressed to remove redundant narrative content and to perform structural regularization. Rule entries of an appropriate size are selected as the final prompt words. The text compression process is used to solve the problems of the original rule text being too long, occupying the context window, and being unfavorable to the understanding of large models.

[0076] For example, the system integrates three types of information: the erroneous reasoning trajectory of the first reasoning path, the correct reasoning trajectory of the second reasoning path, and the segmented violation records of the first execution result. This comprehensive reasoning generates the original task execution rule text adapted to business trip planning. Subsequently, this long text rule undergoes automatic text compression and structured rewriting. Without losing the core rule logic, the long rule is refined and simplified into a target-limited number of core rules. This ultimately yields travel planning-specific prompts adapted to the context length of a large model, avoiding the reasoning deviation problem caused by excessive prompt expansion.

[0077] According to embodiments of this application, the task execution rule text includes at least one of the following: text content describing how to satisfy constraints; text content describing how to avoid the first execution result; and text content describing multiple inference steps of the second inference path.

[0078] Specifically, the task execution rule text includes three types of information: positive execution guidelines that meet the constraints, avoidance requirements for identified violations, and standard execution procedures corresponding to the correct reasoning path. These three types of information complement each other, ensuring that the extracted prompts during subsequent compression processing not only clearly define the correct execution method but also possess risk avoidance capabilities.

[0079] For example, the text describing how to meet all task constraints includes: prioritizing high-speed rail for round-trip transportation, keeping all costs within a budget of 5000 yuan, prioritizing chain brand business hotels, and avoiding peak traffic hours when planning commuting routes. The text describing how to avoid all violations in the first execution result includes: avoiding skipping transportation verification and directly selecting non-high-speed rail travel methods such as airplanes, avoiding selecting non-chain or non-compliant accommodations, and avoiding planning results exceeding 5000 yuan in total cost. The text describing the multiple reasoning steps of the second reasoning path includes: aligning with the standard process of correct business trip planning, and standardizing the execution of the reasoning process in the order of verifying round-trip high-speed rail schedules, matching nearby chain hotel accommodations, calculating daily individual costs, estimating commuting time, calculating overall total expenses, and outputting a complete 3-day itinerary.

[0080] Figure 3 A second flowchart illustrates a method for generating large language model prompt words according to an embodiment of this application.

[0081] According to an embodiment of this application, in operation S220, a second reasoning path is generated based on constraints, including operations S310 to S340.

[0082] Operate S310 to obtain a pre-built set of question samples.

[0083] Operation S320 performs clustering on the question sample set to obtain multiple question clusters, and determines a representative question from each question cluster.

[0084] Operate S330 to generate a sequence of inference steps for the large language model when performing the target inference task for each representative question, resulting in multiple inference step sequences.

[0085] Operation S340 determines the sequence of inference steps that satisfies the constraints from multiple inference step sequences, thus obtaining the second inference path.

[0086] In the embodiments of this application, the question sample set is a pre-constructed high-quality question example set consisting of a large number of typical user questions.

[0087] In the embodiments of this application, question clustering is a grouping of samples obtained by dividing samples within the question sample set based on semantic similarity.

[0088] In the embodiments of this application, the representative problem is a problem sample selected from a single problem cluster that can represent the characteristics of the cluster samples.

[0089] In the embodiments of this application, the reasoning step sequence is an ordered step-by-step reasoning link generated using zero-shot thought chains for representative problems.

[0090] Specifically, based on a pre-accumulated set of question samples, a clustering algorithm is used to group the questions semantically; representative questions are selected from each cluster; multiple reasoning step sequences are generated for the representative questions using a large model; and the reasoning step sequences that meet all constraints are selected and processed to form a second reasoning path.

[0091] For example, a pre-built sample set of questions related to business trip planning is retrieved. This sample set contains multiple typical requirements that closely resemble real user input and have been cleaned and deduplicated. An example sample is shown below:

[0092] Question Sample 1: Please help me plan a 3-day business trip to region A. I can only travel by high-speed rail, and my total budget is no more than 5,000 yuan. I prefer chain hotels.

[0093] Question Sample 2: I need a 2-day short business trip plan for region B, round trip by high-speed rail, with an overall budget of under 3000.

[0094] Question Sample 3: Planning a 4-day business trip to region C, traveling by high-speed rail, with a budget of up to 6,000 yuan, and trying to choose chain hotels close to the business district;

[0095] Question Sample 4: A 3-day work trip arrangement in Region A, air travel is prohibited, and the total cost of transportation and accommodation should not exceed 5000;

[0096] Question Sample 5: Two-day business trip to region B, round trip by high-speed rail, total expenses not exceeding 3000 yuan.

[0097] Furthermore, a semantic clustering algorithm was used to cluster all samples in the question sample set. The samples were grouped according to semantic similarity based on the desired destination, travel duration, and budget range, resulting in three clusters: Cluster A: 3-day business trip needs in region A, including samples 1 and 4; Cluster B: 2-day short-distance business trip needs in region B, including samples 2 and 5; Cluster C: 4-day business trip needs in region C, including sample 3. A representative question was selected from each cluster: sample 1 for cluster A, sample 2 for cluster B, and sample 3 for cluster C.

[0098] For each representative question, the input information for the large language model is determined to drive the model to autonomously generate an ordered sequence of reasoning steps. The input information includes a request text and guiding words. The request text is a representative question from the question sample set, simulating a real user input format for a natural language task request. It contains the task objective and constraints corresponding to the target reasoning task, serving as the original input material to trigger the large language model to perform step-by-step reasoning. The guiding words guide the large language model to not directly output the final task answer, but actively break down the thought process, outputting ordered, logically sequential step-by-step reasoning content, and generating a sequence of reasoning steps.

[0099] Taking the representativeness problem of cluster A as an example, the complete input to the large model is:

[0100] "Please help me plan a 3-day business trip to region A. I can only travel by high-speed rail, and the total budget is no more than 5,000 yuan. I prefer chain hotels. Please think about how to plan it step by step."

[0101] Large models autonomously output a sequence of inference steps:

[0102] Step 1: Review the task constraints. The hard constraints are: trip duration of 3 days, transportation limited to high-speed rail, and a total budget limit of 5,000 yuan; preference is to choose chain hotels.

[0103] Step 2: Determine the round-trip transportation plan, select high-speed rail services between the origin and destination, and calculate the high-speed rail transportation costs.

[0104] Step 3: Filter chain hotels based on travel dates and estimate daily accommodation costs.

[0105] Step 4: Summarize transportation and accommodation expenses, and reserve a small amount of funds for food and beverages.

[0106] Step 5: Calculate the total cost. If the total cost exceeds the budget, adjust the hotel category and recalculate.

[0107] Step 6: Organize transportation information, accommodation arrangements, and expense details to generate a structured business trip planning checklist.

[0108] Perform the same operation on representative questions for clusters B and C, and finally obtain 3 independent sequences of reasoning steps.

[0109] Finally, constraint verification is performed, comparing each set of inference step sequences with the first and second constraints of the current target inference task item by item. The verification process checks: whether the mode of transportation, total travel time, and budget limit used in the inference link meet the first constraint; and whether the inference link reflects the second constraint of prioritizing chain hotels. Inference step sequences with logical conflicts or violations of hard constraints are eliminated. The inference step sequences that pass all constraint verifications are standardized and aligned with the task's inference step expression, forming the second inference path corresponding to this task.

[0110] By employing the above method, the question sample set is clustered and representative questions are selected to generate multiple reasoning step sequences. Then, the reasoning step sequences that meet the constraints are selected to obtain the second reasoning path. Compared with the traditional method of manually customizing reasoning templates and relying on a large number of labeled demonstration examples, this method can reduce manual intervention and lower sample labeling costs. The clustering method ensures that representative questions cover a variety of typical task scenarios, and the constraint screening mechanism can eliminate non-compliant reasoning sequences to obtain reliable positive reasoning materials. This provides a high-quality second reasoning path for the subsequent comprehensive derivation of task execution rule text, improving the completeness and scenario matching of the prompt word generation results.

[0111] According to an embodiment of this application, in operation S220, generating a second reasoning path based on constraints further includes: generating a second reasoning path based on a preset prompt word template and constraints when multiple reasoning step sequences do not satisfy the constraints.

[0112] In the embodiments of this application, the preset prompt word template may be a pre-written expert rule template.

[0113] Specifically, when all reasoning step sequences generated by existing sample clustering fail to meet the constraints, the reasoning step sequences generated by the samples are no longer relied upon. By combining the preset prompt word template with the current task constraints, a compliant second reasoning path is constructed to ensure that the correct reasoning path can still be output normally in scenarios where matching historical samples are lacking.

[0114] Based on the above-mentioned method for generating prompt words for large language models, this application also provides a device for generating prompt words for large language models. The following will combine... Figure 4 The device is described in detail.

[0115] Figure 4 A structural block diagram of a large language model prompt word generation apparatus according to an embodiment of this application is shown.

[0116] like Figure 4 As shown, the large language model prompt word generation device 400 of this embodiment includes an information processing module 410, a path generation module 420, a model application module 430, and a prompt word generation module 440.

[0117] The information processing module 410 is used to respond to user input of target information and determine the constraints of the target reasoning task based on the target information.

[0118] The path generation module 420 is used to generate a first reasoning path and a second reasoning path based on constraints; wherein the first reasoning path represents the erroneous reasoning direction of the target reasoning task, and the second reasoning path represents the correct reasoning direction of the target reasoning task.

[0119] The model application module 430 is used to apply the large language model to execute multiple inference steps in the first inference path and obtain the first execution result of the first inference path.

[0120] The prompt word generation module 440 is used to determine the prompt words for the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result.

[0121] According to an embodiment of this application, the information processing module 410 is further configured to determine a first constraint and a second constraint for the large language model to perform the target reasoning task based on the target information; wherein the first constraint is a necessary condition to be met for performing the target reasoning task, and the second constraint represents the user's preference type for the target reasoning task.

[0122] According to an embodiment of this application, the path generation module 420 is further configured to determine multiple first inference steps that do not satisfy the first constraint based on a pre-configured set of inference steps of a large language model; and to determine a first inference path based on the multiple first inference steps.

[0123] According to an embodiment of this application, the model application module 430 is further configured to divide multiple inference steps in the first inference path into multiple inference trajectories according to a preset step size; apply a large language model to execute multiple inference trajectories to obtain multiple inference results; and for each inference result, obtain the content that violates the constraints to obtain a first execution result.

[0124] According to an embodiment of this application, the prompt word generation module 440 is used to determine the task execution rule text of the target reasoning task based on the first reasoning path, the second reasoning path and the first execution result. The task execution rule text consists of multiple text contents. The task execution rule text is subjected to text compression processing to determine a target number of text contents as prompt words for the target reasoning task.

[0125] According to an embodiment of this application, the path generation module 420 is further configured to obtain a pre-constructed question sample set; perform clustering processing on the question sample set to obtain multiple question clusters, and determine a representative question from each question cluster; for each representative question, generate a sequence of reasoning steps of the large language model when performing the target reasoning task, and obtain multiple reasoning step sequences; determine the reasoning step sequence that satisfies the constraints from the multiple reasoning step sequences, and obtain a second reasoning path.

[0126] According to an embodiment of this application, the path generation module 420 is further configured to generate a second reasoning path based on a preset prompt word template and constraints when multiple reasoning step sequences do not meet the constraints.

[0127] According to embodiments of this application, any multiple modules among the information processing module 410, path generation module 420, model application module 430, and prompt word generation module 440 can be merged into one module, or any one of these modules can be split into multiple modules. Alternatively, at least some of the functions of one or more of these modules can be combined with at least some of the functions of other modules and implemented in one module. According to embodiments of this application, at least one of the information processing module 410, path generation module 420, model application module 430, and prompt word generation module 440 can be at least partially implemented as hardware circuitry, such as a field-programmable gate array (FPGA), a programmable logic array (PLA), a system-on-a-chip, a system-on-a-substrate, a system-on-package, an application-specific integrated circuit (ASIC), or any other reasonable means of integrating or packaging circuitry, or implemented in software, hardware, or firmware, or in any suitable combination of any of these three implementation methods. Alternatively, at least one of the information processing module 410, path generation module 420, model application module 430, and prompt word generation module 440 can be at least partially implemented as a computer program module, which can perform corresponding functions when the computer program module is run.

[0128] Figure 5 A block diagram of an electronic device suitable for implementing a method for generating prompt words for a large language model according to an embodiment of this application is shown.

[0129] like Figure 5As shown, an electronic device 500 according to an embodiment of this application includes a processor 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage portion 508 into a random access memory (RAM) 503. The processor 501 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 501 may also include onboard memory for caching purposes. The processor 501 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of this application.

[0130] RAM 503 stores various programs and data required for the operation of electronic device 500. Processor 501, ROM 502, and RAM 503 are interconnected via bus 504. Processor 501 executes various operations of the method flow according to embodiments of this application by executing programs in ROM 502 and / or RAM 503. It should be noted that programs may also be stored in one or more memories other than ROM 502 and RAM 503. Processor 501 may also execute various operations of the method flow according to embodiments of this application by executing programs stored in one or more memories.

[0131] According to embodiments of this application, the electronic device 500 may further include an input / output (I / O) interface 505, which is also connected to a bus 504. The electronic device 500 may also include one or more of the following components connected to the input / output (I / O) interface 505: an input section 506 including a keyboard, mouse, etc.; an output section 507 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the input / output (I / O) interface 505 as needed. A removable medium 511, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 510 as needed so that computer programs read from it can be installed into the storage section 508 as needed.

[0132] This application also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The aforementioned computer-readable storage medium carries one or more programs, which, when executed, implement the method for generating large language model prompt words according to the embodiments of this application.

[0133] According to embodiments of this application, the computer-readable storage medium can be a non-volatile computer-readable storage medium, such as including but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of this application, the computer-readable storage medium may include ROM 502 and / or RAM 503 and / or one or more memories other than ROM 502 and RAM 503 described above.

[0134] Embodiments of this application also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code is used to enable the computer system to implement the method for generating large language model prompt words provided in the embodiments of this application.

[0135] When the computer program is executed by the processor 501, it performs the functions defined in the system / apparatus of this application embodiment. According to the embodiments of this application, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.

[0136] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and may be downloaded and installed via the communication section 509, and / or installed from a removable medium 511. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.

[0137] In such an embodiment, the computer program can be downloaded and installed from a network via communication section 509, and / or installed from removable medium 511. When the computer program is executed by processor 501, it performs the functions defined in the system of this application embodiment. According to embodiments of this application, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.

[0138] According to embodiments of this application, program code for executing the computer programs provided in the embodiments of this application can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, languages ​​such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0139] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0140] Those skilled in the art will understand that the features described in the various embodiments of this application can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this application. In particular, the features described in the various embodiments of this application can be combined and / or combined in various ways without departing from the spirit and teachings of this application. All such combinations and / or combinations fall within the scope of this application.

Claims

1. A method for generating prompt words for a large language model, characterized in that, The method includes: In response to user input of target information, constraints for the target reasoning task are determined based on the target information; Based on the constraints, a first reasoning path and a second reasoning path are generated respectively; wherein, the first reasoning path represents the erroneous reasoning direction of the target reasoning task, and the second reasoning path represents the correct reasoning direction of the target reasoning task; The large language model is applied to execute multiple inference steps in the first inference path to obtain the first execution result of the first inference path. Based on the first reasoning path, the second reasoning path, and the first execution result, the prompt words for the target reasoning task are determined.

2. The method according to claim 1, characterized in that, The step of determining the constraints of the target reasoning task based on the target information includes: Based on the target information, a first constraint and a second constraint are determined for the large language model to perform the target reasoning task; wherein, the first constraint is a necessary condition to be met for performing the target reasoning task, and the second constraint represents the user's preference type for the target reasoning task.

3. The method according to claim 2, characterized in that, Based on the constraints, the first reasoning path is generated, including: Based on a pre-configured set of reasoning steps for a large language model, identify multiple first reasoning steps that do not satisfy the first constraint. The first reasoning path is determined based on multiple first reasoning steps.

4. The method according to claim 1, characterized in that, The application of a large language model executes multiple inference steps in the first inference path to obtain a first execution result of the first inference path, including: According to the preset step size, the multiple reasoning steps in the first reasoning path are divided into multiple reasoning trajectories; The large language model is applied to execute the multiple inference trajectories to obtain multiple inference results; For each reasoning result, the content that violates the constraints is obtained to get the first execution result.

5. The method according to claim 1, characterized in that, The step of determining the prompt words for the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result includes: Based on the first inference path, the second inference path, and the first execution result, the task execution rule text of the target inference task is determined, and the task execution rule text consists of multiple text contents; The task execution rule text is compressed to determine a target amount of text content as prompts for the target reasoning task.

6. The method according to claim 5, characterized in that, The task execution rule text includes at least one of the following: Text content describing how the constraints are satisfied; The text content describes how to avoid the first execution result; The text content describing the multiple reasoning steps of the second reasoning path.

7. The method according to claim 1, characterized in that, Based on the aforementioned constraints, a second reasoning path is generated, including: Obtain a pre-built set of question samples; Clustering is performed on the question sample set to obtain multiple question clusters, and a representative question is determined from each question cluster; For each representative problem, a sequence of inference steps is generated when the large language model performs the target inference task, resulting in multiple inference step sequences; The second reasoning path is obtained by determining the sequence of reasoning steps that satisfies the constraints from multiple sequences of reasoning steps.

8. The method according to claim 7, characterized in that, The method further includes: If none of the multiple reasoning step sequences satisfy the constraints, a second reasoning path is generated based on the preset prompt word template and the constraints.

9. A device for generating prompt words for a large language model, characterized in that, The device includes: The information processing module is used to respond to user input of target information and, based on the target information, determine the constraints of the target reasoning task. The path generation module is used to generate a first reasoning path and a second reasoning path based on the constraints; wherein the first reasoning path represents the erroneous reasoning direction of the target reasoning task, and the second reasoning path represents the correct reasoning direction of the target reasoning task. The model application module is used to apply the large language model to execute multiple inference steps in the first inference path and obtain the first execution result of the first inference path. The prompt word generation module is used to determine the prompt words for the target reasoning task based on the first reasoning path, the second reasoning path, and the first execution result.

10. An electronic device, comprising: One or more processors; Memory, used to store one or more computer programs. The characteristic feature is that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 8.