Model cue word generation method and device, electronic equipment and storage medium

By generating model prompts based on task type and parameters, and adjusting the prompts using a model adapter, the problems of high migration costs and poor maintainability during model changes are solved. This enables rapid cross-model adaptation and unified output, improving the reliability of prompts and the accuracy of model processing.

CN122065840APending Publication Date: 2026-05-19BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING QIYI CENTURY SCI & TECH CO LTD
Filing Date
2026-03-03
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

In existing technologies, when the model task is changed and/or the model is replaced, the prompt words need to be rewritten entirely, resulting in high migration costs and poor maintainability.

Method used

By obtaining the task type and parameters, multiple prompt word templates are obtained. The templates are set based on the task parameters, and model prompt words are generated according to preset splicing rules. The prompt words are adjusted using the model adapter to achieve rapid cross-model adaptation and unified output.

Benefits of technology

It improves the reliability of prompt words and the accuracy of model processing, reduces maintenance and migration costs, and enhances the maintainability and sustainability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122065840A_ABST
    Figure CN122065840A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a model cue word generation method and device, electronic equipment and a storage medium, and relates to the technical field of artificial intelligence content generation. The method comprises the steps that based on a received processing task, a task type and task parameters are obtained, and a plurality of cue word templates corresponding to the task type are obtained, setting a plurality of cue word templates based on the task parameters to obtain a plurality of sub cue words; and splicing the plurality of sub cue words according to a preset cue word template splicing rule to obtain a model cue word. According to the embodiment of the invention, a plurality of different cue word templates are obtained according to different task types and are combined to obtain a plurality of sub cue words for splicing to obtain the model cue word, so that the cue word is flexibly spliced for different tasks to generate the most suitable cue word, and the reliability of the cue word is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of artificial intelligence-generated content technology, and in particular to a method, apparatus, electronic device, and storage medium for generating model prompt words. Background Technology

[0002] In scenarios such as intelligent page generation and intelligent content management, with the emergence of multi-model ecosystems (GPT (Generative Pre-trained Transformer), Claude (large-scale language model), Wenxin, Tongyi Qianwen, etc.), there are significant differences in the context capacity, output format, and function calling methods of different models.

[0003] In related technologies, the Prompt design is usually a single text. When the model task changes and / or the model is replaced, the entire Prompt needs to be rewritten, which has technical problems such as high migration cost and poor maintainability. Summary of the Invention

[0004] To solve the above-mentioned technical problems, or at least partially solve them, this disclosure provides a method, apparatus, electronic device, and storage medium for generating model prompt words.

[0005] This disclosure provides a method for generating model prompt words. The method includes: obtaining a task type and task parameters based on a received processing task; obtaining multiple prompt word templates corresponding to the task type, and setting the multiple prompt word templates based on the task parameters to obtain multiple sub-prompt words; and concatenating the multiple sub-prompt words according to a preset prompt word template splicing rule to obtain model prompt words.

[0006] Optionally, obtaining multiple prompt word templates corresponding to the task type and setting the multiple prompt word templates based on the task parameters to obtain multiple sub-prompt words includes: obtaining multiple prompt word templates matching the task type from a preset task type prompt word template association database; wherein, the multiple prompt word templates include at least one of a role definition template, a domain knowledge template, a logical constraint template, and an output specification template; replacing the target placeholders in the role definition template, the domain knowledge template, the logical constraint template, and the output specification template based on the task parameters to obtain at least one of a role definition string, a domain knowledge string, a logical constraint string, and an output specification string as the multiple sub-prompt words.

[0007] Optionally, based on the processing task, obtain the model type and construct the prompt word constraint information corresponding to the model type based on the preset model adapter; obtain the number of characters of the model prompt word; obtain the context limit number, preset compression strategy and output rule based on the prompt word constraint information; if the number of characters of the model prompt word is greater than the context limit number, compress the model prompt word according to the preset compression strategy to obtain compressed prompt words; generate target prompt words based on the compressed prompt words and the output rule.

[0008] Optionally, compressing the model prompt words according to the preset compression strategy to obtain compressed prompt words includes: determining at least one target type string from the model prompt words according to a preset compression priority setting rule, and a target compression ratio corresponding to the target type string; compressing the target type knowledge string according to the target compression ratio to obtain candidate prompt words; and using the candidate prompt words as compressed prompt words until the number of characters in the candidate prompt words is less than or equal to the number of context restrictions.

[0009] Optionally, the method further includes: obtaining multiple type strings from the model prompt words; determining the compression priority and compression ratio of each type string to obtain the preset compression priority setting rule.

[0010] Optionally, the method further includes: obtaining a model output result based on the target prompt word, the prompt word constraint information, and the model response corresponding to the model type to the processing task; verifying the model output result according to a preset verification rule to obtain a verification result; generating prompt word repair information to update the target prompt word through the prompt word repair information to obtain an updated prompt word for responding to the processing task; and outputting the model output result if the verification result is correct.

[0011] This disclosure also provides a model prompt word generation device, comprising: an acquisition module, configured to acquire a task type and task parameters based on a received processing task; a processing module, configured to acquire multiple prompt word templates corresponding to the task type, and set the multiple prompt word templates based on the task parameters to obtain multiple sub-prompt words; and a splicing module, configured to splice the multiple sub-prompt words according to preset prompt word template splicing rules to obtain model prompt words.

[0012] This disclosure also provides an electronic device, the electronic device comprising: a processor; a memory for storing executable instructions of the processor; the processor being configured to read the executable instructions from the memory and execute the instructions to implement the model prompt word generation method provided in this disclosure.

[0013] This disclosure also provides a computer-readable storage medium storing a computer program for executing the model prompt word generation method provided in this disclosure.

[0014] This disclosure also provides a computer program product, including a computer program, wherein the computer program is executed by a processor using the model prompt word generation method provided in the embodiments of this application.

[0015] The technical solution provided in this disclosure obtains multiple prompt word templates based on different task types, and combines these templates after updating them based on task parameters to obtain model prompt words. This allows prompt words to be flexibly assembled for different tasks, and the prompt words can be flexibly adjusted according to prompt word constraint information to obtain target prompt words for subsequent processing tasks. This enables the automatic generation of the most suitable prompt words for the model based on model information during prompt word construction, improving the reliability of prompt words and thus improving the accuracy of model processing. Through a hierarchical, configurable, and transferable prompt word design, it achieves rapid adaptation and unified output across models, reducing maintenance and migration costs.

[0016] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0017] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0018] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 A flowchart illustrating a model prompt word generation method provided in this embodiment of the disclosure; Figure 2 A flowchart illustrating a model prompt word generation method provided in this embodiment of the disclosure; Figure 3 This is a schematic diagram illustrating the generation of model prompt words according to an embodiment of the present disclosure; Figure 4 This is a schematic diagram of the structure of a model prompt word generation device provided in an embodiment of the present disclosure; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0020] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0021] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.

[0022] In real-world business scenarios, different models exhibit significant differences in context capacity, output format, and function call methods. Existing prompt word design methods typically use single-text prompts, requiring a complete rewrite of the prompt words when the model task changes or / or the model is replaced. This results in technical issues such as high migration costs and poor maintainability.

[0023] To address the aforementioned issues, this embodiment proposes a model prompt word generation method. Based on the received processing task, the method obtains the task type and task parameters, acquires multiple prompt word templates corresponding to the task type, and sets multiple prompt word templates based on the task parameters to obtain multiple sub-prompt words. These sub-prompt words are then concatenated according to preset prompt word template splicing rules to obtain the model prompt word. Thus, by obtaining different prompt word templates for different task types, updating these templates based on task parameters, and combining them to obtain multiple sub-prompt words, the model prompt word is obtained. This allows for flexible assembly of prompt words to generate the most suitable prompt word for different tasks, improving the reliability of the prompt words and thus enhancing the accuracy of model processing. The hierarchical, configurable, and transferable prompt word design enables rapid cross-model adaptation and unified output, reducing maintenance and migration costs. A detailed explanation follows: Figure 1 This is a flowchart illustrating a model prompt word generation method provided in an embodiment of this disclosure. This method can be applied to electronic devices, such as computers, mobile phones, tablets, televisions, etc., without limitation. Figure 1 As shown, the method mainly includes the following steps S102 to S106: Step S102: Based on the received processing task, obtain the task type and task parameters.

[0024] In this embodiment of the disclosure, the user can select a model and input a processing task according to the actual application needs. The system can then receive the user-input processing task, parse the task, and obtain information such as model type, task type, task parameters, and request identifier. The task type refers to the type of processing task, which can be a task to generate a video page, a translation task, etc. The task parameters refer to the variable parameters in the processing task, such as a character's name, a video name, or translated text. Different processing tasks usually have different task parameters. The request identifier can be a requesting user identifier or a requesting terminal identifier, etc.

[0025] For example, a user selects to input the text "Please recommend the best period drama videos featuring actor A" into the GPT model, thereby receiving a processing task. Analyzing the processing task reveals that the task type is "generate movie / TV page", the model type is "GPT", and the task parameters are "period drama", "actor A", and "recommend video".

[0026] Step S104: Obtain multiple prompt word templates corresponding to the task type, and set multiple prompt word templates based on task parameters to obtain multiple sub-prompt words.

[0027] In this embodiment, multiple prompt word templates are pre-set for different task types. For example, N prompt word templates are set for each task type. Each prompt word template is stored as text with target placeholders, so that the target placeholders in the corresponding prompt word templates can be replaced according to the task parameters to obtain multiple sub-prompt words. Here, N is a positive integer greater than 1. In this embodiment, N can be set to 4, and four prompt word templates are set for each task type, including a role definition template, a domain knowledge template, a logical constraint template, and an output specification template. The role definition template is used to indicate the role of the model when processing the task; the domain knowledge template is used to indicate the knowledge that the model has when processing the task; the logical constraint template is used to indicate the logical constraints that the model has when processing the task; and the output specification module is used to instruct the model to output according to the output rules when processing the task.

[0028] Furthermore, based on the task parameters, the target placeholders in the role definition template, the domain knowledge template, the logical constraint template, and the output specification template are replaced to obtain the role definition string, the domain knowledge string, the logical constraint string, and the output specification string. These strings are then concatenated to obtain multiple sub-prompt words.

[0029] Step 106: Combine multiple sub-prompt words according to the preset prompt word template splicing rules to obtain the model prompt words.

[0030] Specifically, after replacing the target placeholders in one or more prompt word templates such as the role definition template, domain knowledge template, logical constraint template, and output specification template based on task parameters to obtain multiple sub-prompt words such as the role definition string, domain knowledge string, logical constraint string, and output specification string, one or more of these sub-prompt words are then concatenated according to preset prompt word template concatenation rules to obtain model prompt words.

[0031] The preset prompt word template concatenation rule refers to the concatenation order of each string. For example, the role definition string, domain knowledge string, logical constraint string, and output specification string are concatenated in sequence to obtain the model prompt word.

[0032] In summary, the model prompt word generation method of this disclosure, based on the received processing task, obtains the task type and task parameters, obtains multiple prompt word templates corresponding to the task type, and sets multiple prompt word templates based on the task parameters to obtain multiple sub-prompt words; the multiple sub-prompt words are then concatenated according to preset prompt word template splicing rules to obtain model prompt words. Thus, by obtaining different multiple prompt word templates according to different task types, and updating multiple prompt word templates based on task parameters and combining them to obtain multiple sub-prompt words for splicing to obtain model prompt words, the method enables prompt words to be flexibly assembled to generate the most suitable prompt words for different tasks, improving the reliability of prompt words and thus improving the accuracy of model processing. Through a hierarchical, configurable, and transferable prompt word design, it achieves rapid adaptation and unified output across models, reducing maintenance and migration costs.

[0033] In some embodiments, multiple prompt word templates corresponding to a task type are obtained, and multiple prompt word templates are set based on task parameters to obtain multiple sub-prompt words. This includes: obtaining multiple prompt word templates matching the task type from a preset task type prompt word template association database; wherein, the multiple prompt word templates include at least one of a role definition template, a domain knowledge template, a logical constraint template, and an output specification template; and replacing the target placeholders in the role definition template, the domain knowledge template, the logical constraint template, and the output specification template based on task parameters to obtain at least one of a role definition string, a domain knowledge string, a logical constraint string, and an output specification string as multiple sub-prompt words.

[0034] Specifically, the prompt words are pre-divided into multiple prompt word templates. That is, the prompt words of a model are divided into multiple template files. For example, the prompt words are divided into four template files: role definition template, domain knowledge template, logical constraint template, and output specification template. Each template file is stored as text with target placeholders and can support variable substitution.

[0035] Furthermore, after dividing the prompt words into multiple prompt word templates, template content is set for each prompt word template in the multiple prompt word templates for each task type, i.e., the target placeholder to be replaced. The task type and the corresponding multiple prompt word templates are associated and stored in the preset task type prompt word template association database. Thus, based on the task type obtained in the task processing, multiple prompt word templates matching the task type can be obtained from the preset task type prompt word template association database, namely role definition template, domain knowledge template, logical constraint template and output specification template.

[0036] Furthermore, based on task parameters, the target placeholders in the role definition template, domain knowledge template, logical constraint template, and output specification template are replaced to obtain at least one of the role definition string, domain knowledge string, logical constraint string, and output specification string as multiple sub-prompt words. The role definition string, domain knowledge string, logical constraint string, and output specification string are then concatenated according to preset prompt word template concatenation rules to obtain model prompt words. Here, the preset prompt word template concatenation rules refer to the concatenation order of each string. For example, the role definition string, domain knowledge string, logical constraint string, and output specification string are concatenated in sequence to obtain model prompt words.

[0037] In the above approach, by breaking down a traditional single prompt word into multiple prompt word templates, such as four structured modules—"role definition layer, domain knowledge layer, logical constraint layer, and output specification layer"—the prompt words can be developed, maintained, and combined as needed, just like code modules. Compared to related technologies where all text-based prompt words need to be rewritten, the embodiments of this disclosure completely decouple the model logic, business knowledge, and output format, which not only significantly reduces maintenance costs but also allows prompt words to be flexibly assembled for different tasks. As a result, the reusability and scalability of prompt words are improved, enabling them to adapt to the rapid changes in complex business systems and to be reused across scenarios and teams, significantly enhancing the maintainability and sustainable evolution capabilities of the system.

[0038] In some embodiments, the model type is obtained based on the processing task, and the prompt word constraint information corresponding to the model type is constructed based on the preset model adapter; the number of characters in the model prompt word is obtained; the number of context restrictions, the preset compression strategy, and the output rules are obtained based on the prompt word constraint information; if the number of characters in the model prompt is greater than the number of context restrictions, the model prompt word is compressed according to the preset compression strategy to obtain compressed prompt words; and the target prompt word is generated based on the compressed prompt word and the output rules.

[0039] In this embodiment of the disclosure, the model type refers to the type of model used to respond to the processing task, which can be GPT, large language model, etc.

[0040] In this embodiment of the disclosure, a model adapter is pre-set, that is, the configuration information of each model is pre-set. Specifically, the model name, the context length supported by the model, whether the plugin call is supported, the preferred output format, the syntax rules, and the compression strategy (such as the proportion of content to be retained, the compression method, etc.) of each model are obtained, and the data format is generated as a file in the format of "yaml (markup language)" or "json (key-value pair data)". In other words, different model types correspond to different preset model adapters. Usually, the preset model adapter can obtain model information such as the context length supported by the model corresponding to the model type and whether the plugin call is supported.

[0041] In this embodiment of the disclosure, after obtaining the model type, a preset model adapter for that model type is obtained. Based on the preset model adapter, the number of context restrictions, preset compression strategies, and output rules of the model can be obtained. Based on the number of context restrictions, preset compression strategies, and output rules of the model, prompt word constraint information corresponding to the model type is constructed.

[0042] In this embodiment of the disclosure, after multiple prompt word templates are set according to the task parameters to obtain multiple sub-prompt words, and these are then concatenated to obtain model prompt words, in order to further ensure the accuracy of the model prompt words and avoid model processing failures caused by model context limitations and format support differences, the model prompt words are adjusted through prompt word constraint information to obtain target prompt words for subsequent model processing tasks, thereby further improving the reliability of the prompt words.

[0043] In this embodiment, adjusting the model prompts based on prompt constraint information to obtain the target prompt may include acquiring the number of characters in the model prompt. If the number of characters exceeds the context limit in the prompt constraint information, the prompt is compressed according to a preset compression strategy in the prompt constraint information, and then the output rule is added to obtain the target prompt. Alternatively, if the number of characters is less than or equal to the context limit in the prompt constraint information, the model prompt can be directly used as the target prompt. Therefore, when constructing prompts, the prompts are automatically adjusted to be the most suitable for the model based on the model context information, ensuring the reliability of the model prompts.

[0044] In this embodiment of the disclosure, after obtaining the model prompt words, the number of characters in the model prompt words is counted. If the number of characters in the model prompt words is greater than the number of context limits in the prompt word constraint information, it indicates that the model processing will fail due to exceeding the number of model context limits. The model prompt words need to be adjusted. Specifically, the model prompt words are compressed according to the preset compression strategy in the prompt word constraint information. The compressed prompt words are then combined with output rules to generate the target prompt words.

[0045] Understandably, there are many ways to compress model prompts according to a preset compression strategy. Specifically, the strings corresponding to the multiple prompt templates mentioned above can be compressed sequentially. After each compression, it is determined whether the number of compressed characters is less than or equal to the number of context constraints. When the number of compressed characters is less than or equal to the number of context constraints, the compression is stopped and the compressed prompt is added to the output rules as the target prompt. The prompt templates are usually set in the following order: domain knowledge template, logical constraint template, role definition template, and output specification template.

[0046] In some embodiments, compressing model prompts according to a preset compression strategy to obtain compressed prompts includes: determining at least one target type string and a target compression ratio corresponding to the target type string from the model prompts according to a preset compression priority setting rule; compressing the target type string in the model prompts according to the target compression ratio to obtain candidate prompts; and using the candidate prompts as compressed prompts when the number of characters in the candidate prompts is less than or equal to the number of context constraints.

[0047] In this embodiment of the disclosure, multiple type strings in the model prompt words are obtained, the compression priority and compression ratio of each type string are determined, and a preset compression priority setting rule is obtained. For example, the multiple type strings include domain knowledge strings, logical constraint strings and role constraint strings. If all three types of strings exist, they are compressed in the order of compression priority of domain knowledge strings, logical constraint strings and role constraint strings.

[0048] For example, the domain knowledge string in the model prompt is compressed according to the compression ratio corresponding to the domain knowledge string in the preset compression strategy. After obtaining the first candidate prompt, the relationship between the number of characters in the first candidate prompt and the number of context restrictions is further judged. If the number of characters in the first candidate prompt is less than or equal to the number of context restrictions, the first candidate prompt is used as the compressed prompt.

[0049] In some embodiments, if the number of characters in the first candidate prompt is greater than the number of context constraints, the logical constraint string in the first candidate prompt is compressed according to the compression ratio of the logical constraint string to obtain the second candidate prompt. The number of characters in the second candidate prompt is obtained, and if the number of characters in the second candidate prompt is less than or equal to the number of context constraints, the second candidate prompt is used as the compressed prompt.

[0050] Specifically, if the number of characters in the first candidate prompt is greater than the number of context constraints, the logical constraint strings in the model prompt are compressed according to the compression ratio corresponding to the logical constraint strings. After obtaining the second candidate prompt, the relationship between the number of characters in the second candidate prompt and the number of context constraints is further judged. If the number of characters in the second candidate prompt is less than or equal to the number of context constraints, the second candidate prompt is used as the compressed prompt.

[0051] In some embodiments, if the number of characters in the second candidate prompt is greater than the number of context constraints, the role constraint string in the second candidate prompt is compressed according to the compression ratio of the role constraint string to obtain the third candidate prompt; the number of characters in the third candidate prompt is obtained, and if the number of characters in the third candidate prompt is less than or equal to the number of context constraints, the third candidate prompt is used as the compressed prompt.

[0052] Specifically, if the number of characters in the second candidate prompt is greater than the number of context constraints, the role constraint string in the model prompt is compressed according to the compression ratio corresponding to the role constraint string. After obtaining the third candidate prompt, the relationship between the number of characters in the third candidate prompt and the number of context constraints is further judged. If the number of characters in the third candidate prompt is less than or equal to the number of context constraints, the fourth candidate prompt is used as the compressed prompt.

[0053] Therefore, by using a pre-defined model adapter to describe the capability boundaries of different large models, the constraint information of the constructed prompt words includes context length, output rules, and whether function calls are supported. When constructing prompt words, the system automatically generates the most suitable prompt words for the model based on its capabilities. This avoids the inefficient approach of repeatedly designing a second, different prompt word for different models, significantly improving cross-model transfer capabilities. In practical applications, it can automatically avoid processing failures caused by model context limitations and differences in format support, enabling the system to maintain stable and consistent logical output in different large language model environments, improving system adaptability and robustness, and reducing the adaptation costs for engineering teams when switching models.

[0054] In the above method, during the prompt word assembly process, strategies such as summary compression, key point extraction, or safe truncation are automatically executed based on the maximum available context of the model. Intelligent compression processing is performed on the domain knowledge layer and logic layer, ensuring that the constructed prompt words always remain within the range that the model can handle. Unlike existing simple text truncation or manual simplification, this disclosure provides a structured, configurable, and scalable compression strategy, which not only ensures that the core logic in the prompt words is not lost, but also adapts to a larger knowledge base when the business scale expands. It effectively avoids response anomalies caused by excessively long contexts, improves the completeness and controllability of the generated results, and can maintain stable operation in large-scale complex tasks, thereby significantly improving the reliability of prompt word engineering in actual business systems.

[0055] In some embodiments, the model prompt word generation method further includes: obtaining model output results based on target prompt words, prompt word constraint information, and model response processing tasks corresponding to model types; verifying the model output results according to preset verification rules to obtain verification results; generating prompt word repair information to update the target prompt words through the prompt word repair information to obtain updated prompt words for response processing tasks; and outputting model output results if the verification results are correct.

[0056] In this embodiment of the disclosure, after obtaining the target prompt word, the model corresponding to the model type responds to the processing task based on the target prompt word and the corresponding prompt word constraint information, thereby obtaining the model output result. The model output result is then verified, and based on the verification result, it is further determined whether the target prompt word is the final prompt word or whether it needs to be adjusted again to obtain the final prompt word.

[0057] Specifically, to ensure that the model output is structured data in a correct, complete, and format-consistent target format (such as JSON), the preset validation rules can include target format syntax validation (such as JSON syntax validation) and structure validation. More specifically, target format syntax validation includes checking whether the model output meets the user's request, whether the target format can be parsed, whether the model output has issues such as missing trailing commas, missing quotation marks, or incorrect escape characters, and whether it contains redundant content outside the target format (such as natural language interpretation). Structure validation includes validating whether the model output conforms to the syntax rules according to the output specification template.

[0058] Furthermore, if the verification result is incorrect, the generated prompt word repair information includes the model output result, error type, error message, hard requirements for the output specification template (e.g., must output JSON) and target summary (mandatory constraints). The target prompt word is then updated using the prompt word repair information, and the updated prompt word is used to respond to the processing task. In other words, the new prompt word is resubmitted to the model for subsequent verification, and if the verification result is correct, the model output result is output.

[0059] In the above method, the prompt words can be further verified and adjusted through the model output results, thereby improving the reliability of the prompt words and significantly enhancing the sustainability and stability of the artificial intelligence model.

[0060] Figure 2 This is a flowchart illustrating a model prompt word generation method provided in an embodiment of the present disclosure. The method mainly includes the following steps S202 to S210: Step S202: Based on the received processing task, obtain the model type, task type, and task parameters.

[0061] Specifically, users input a text message as a processing task based on their actual needs, thereby obtaining information such as task type, model type, task parameters, and request identifier.

[0062] For example, the task identifier is "t-20251113-0001", the task type is "generate movie and TV page", the model type is "GPT-4o", the task parameters are "historical drama", "actor card", "recommended video" and the user is "product team" and other information.

[0063] Step S204: Construct prompt word constraint information corresponding to the model type based on the preset model adapter.

[0064] Specifically, the preset model adapter "AdapterConfig" includes the model name, the context length (number of tokens) supported by the model, whether plugin calls are supported, the preferred output format, syntax rules, and compression strategies (such as the percentage of content to be retained, compression methods, etc.).

[0065] For example, the default model adapter is a "GPT_adapter.yaml" file, which includes the model name "GPT-4o", the context length supported by the model is "16000", it supports plugin calls, the preferred output format is "json", the syntax rules are "must output pure JSON, without any extra text", "all keys use camelCase", and the allowed content retention ratio, such as the knowledge domain compression ratio of "0.7" and the compression method is "summary or overview".

[0066] Among them, the prompt word constraint information refers to the objects derived from the preset model adapter at runtime (including the calculated number of context constraints "effective_context_limit", output rules "syntax_wrappers", etc.).

[0067] Step S206: Obtain the role definition template, domain knowledge template, logical constraint template, and output specification template that match the task type from the preset task type prompt word template association database. Replace the target placeholders in the role definition template, domain knowledge template, logical constraint template, and output specification template based on the task parameters. Concatenate the role definition string, domain knowledge string, logical constraint string, and output specification string to obtain the model prompt word.

[0068] Specifically, the prompt words are broken down into multiple prompt word templates (such as role definition templates, domain knowledge templates, logical constraint templates, and output specification templates). Through a prompt word layering mechanism, a model adaptation mechanism, and dynamic assembly, the prompt words can be transferred and reused in a structured manner across different large models.

[0069] Step S208: Obtain the number of characters in the model prompt words; obtain the context limit number, preset compression strategy, and output rules based on the prompt word constraint information; if the number of characters in the model prompt words is greater than the context limit number, compress the model prompt words according to the preset compression strategy to obtain compressed prompt words; and generate target prompt words based on compressed prompt words and output rules.

[0070] Specifically, the domain knowledge string in the model prompt is compressed according to the preset compression ratio to obtain the first candidate prompt. The number of characters in the first candidate prompt is obtained, and if the number of characters in the first candidate prompt is less than or equal to the number of characters in the context limit, the first candidate prompt is used as the compressed prompt.

[0071] Specifically, if the number of characters in the first candidate prompt is greater than the number of context constraints, the logical constraint string in the first candidate prompt is compressed according to the preset compression ratio of the domain knowledge string to obtain the second candidate prompt. The number of characters in the second candidate prompt is obtained, and if the number of characters in the second candidate prompt is less than or equal to the number of context constraints, the second candidate prompt is used as the compressed prompt.

[0072] Specifically, if the number of characters in the second candidate prompt is greater than the number of context constraints, the role constraint string in the second candidate prompt is compressed according to the preset compression ratio of the domain knowledge string to obtain the third candidate prompt; the number of characters in the third candidate prompt is obtained, and if the number of characters in the third candidate prompt is less than or equal to the number of context constraints, the third candidate prompt is used as the compressed prompt.

[0073] Furthermore, based on the compressed prompt words and output rules, target prompt words are generated.

[0074] Step S210: Based on the target prompt word, prompt word constraint information, and the model response processing task corresponding to the model type, obtain the model output result. Validate the model output result according to the preset validation rules to obtain the validation result. If the validation result is incorrect, generate prompt word repair information to update the target prompt word. Obtain the updated prompt word for the response processing task. If the validation result is correct, output the model output result.

[0075] For example, such as Figure 3 As shown, step 3.1 reads the preset model adapter and constructs the prompt word constraint information corresponding to the model type, which can provide information such as the number of context restrictions and output rules; step 3.2 obtains multiple prompt word templates according to the task type, including role definition templates, domain knowledge templates, logical constraint templates, and output specification templates; step 3.3 dynamically concatenates the multiple prompt word templates after character replacement according to the task parameters to obtain the model prompt words; step 3.4 compresses or rewrites the model prompt words according to the prompt word constraint information to generate target prompt words; step 3.5 calls the model to process the task based on the target prompt words to obtain the model output results; step 3.6 performs target format JSON validation and structured parsing on the model output results, thereby repairing the target prompt words corresponding to validation errors and determining the final prompt words through secondary processing by the model.

[0076] Specifically, the user submits a processing task, such as inputting information like task identifier, task type, model type, and task parameters. The task is then queued and enters a waiting state, and is recorded in the corresponding database. After receiving the processing task, the task identifier is returned to the user. Next, the preset model adapter corresponding to the model type is loaded, and the model deployment context "ModelContext" is constructed using the preset model adapter. If the preset model adapter corresponding to the model type cannot be loaded, the default model adapter is used to configure the model deployment context, further ensuring the continuity and flexibility of subsequent processing.

[0077] Furthermore, based on the task type, multiple prompt word templates are loaded, including role definition templates, domain knowledge templates, logical constraint templates, and output specification templates. For each prompt word template, multiple strings are concatenated by replacing the target placeholder according to the task parameters to obtain the model prompt word. The concatenated model prompt word is then checked for character count based on the number of context constraints in the prompt word constraint information. If the character count exceeds the number of context constraints, the domain knowledge template is compressed according to a preset compression strategy. If this is still insufficient, compression continues in the order of logical constraint template, role definition template, and output specification template. Finally, the compressed text is processed. The system adds output rules to the prompt words to obtain the target prompt words. The main model is then called to process the prompt words based on the target prompt words and their constraints. During model processing, the system determines whether to call plugins based on the prompt word constraints and sets appropriate prompt words based on the output rules. In case of timeouts or errors, retrying is performed a preset number of times. After obtaining the model output, the system verifies and parses the results. If the target format parsing and validation fails, prompt word repair information is generated, including the model output and the number of retries, and the prompt words are adjusted and retried. If the target format parsing and validation are correct, the model output is provided to the front-end or the caller.

[0078] This disclosure embodiment utilizes a model adapter mechanism to enable the smooth migration of the same prompt word logic between multiple different models without rewriting it. This allows for flexible switching between larger models that offer higher cost-effectiveness or are more suitable for business scenarios, and rapid integration with new models without rewriting a large number of prompt words. Consequently, it significantly improves the sustainability, stability, and cost control capabilities of the artificial intelligence product system.

[0079] In summary, by using prompt word self-adaptation and model context optimization mechanisms, prompt words can be automatically compressed to occupy fewer characters, and cheaper models can be automatically selected for execution while meeting requirements. This avoids repeated debugging of format errors and reduces the cost of manually maintaining prompt words for multiple models.

[0080] Corresponding to the aforementioned model prompt word generation method, this disclosure further provides a model prompt word generation apparatus. Figure 4 This is a schematic diagram of a model prompt word generation device provided in an embodiment of the present disclosure. The device can be implemented by software and / or hardware, and includes: The acquisition module 402 is used to acquire the task type and task parameters based on the received processing task; The processing module 404 is used to obtain multiple prompt word templates corresponding to the task type, and set the multiple prompt word templates based on the task parameters to obtain multiple sub-prompt words; The splicing module 406 is used to splice the multiple sub-prompt words according to the preset prompt word template splicing rules to obtain the model prompt words.

[0081] The apparatus provided in this embodiment obtains multiple prompt word templates for different task types, updates the multiple prompt word templates based on task parameters, and then combines them to obtain multiple sub-prompt words for splicing to obtain model prompt words. This enables prompt words to be flexibly assembled to generate the most suitable prompt words for different tasks, improving the reliability of prompt words and thus improving the accuracy of model processing. Through the hierarchical, configurable, and transferable prompt word design, it achieves rapid adaptation and unified output across models, reducing maintenance and migration costs.

[0082] In some embodiments, the processing module 404 is specifically configured to: obtain multiple prompt word templates matching the task type from a preset task type prompt word template association database; wherein, the multiple prompt word templates include at least one of a role definition template, a domain knowledge template, a logical constraint template, and an output specification template; and replace the target placeholders in the role definition template, the domain knowledge template, the logical constraint template, and the output specification template based on the task parameters to obtain at least one of a role definition string, a domain knowledge string, a logical constraint string, and an output specification string as the multiple sub-prompt words.

[0083] In some embodiments, the apparatus further includes an adjustment module, comprising: a construction unit, configured to acquire a model type based on the processing task and construct prompt word constraint information corresponding to the model type based on a preset model adapter; an acquisition unit, configured to acquire the number of characters in the model prompt word; acquire a context limit number, a preset compression strategy, and an output rule based on the prompt word constraint information; a compression unit, configured to compress the model prompt word according to the preset compression strategy when the number of characters in the model prompt word is greater than the context limit number, to obtain a compressed prompt word; and a generation unit, configured to generate the target prompt word based on the compressed prompt word and the output rule.

[0084] In some implementations, the compression unit is specifically used to: determine at least one target type string and a target compression ratio corresponding to the target type string from the model prompt words according to a preset compression priority setting rule; compress the target type string according to the target compression ratio to obtain candidate prompt words, and use the candidate prompt words as the compressed prompt words when the number of characters of the candidate prompt words is less than or equal to the number of context restrictions.

[0085] In some implementations, the compression unit is further configured to: acquire multiple type strings from the model prompt words; determine the compression priority and compression ratio of each type string, and obtain the preset compression priority setting rule.

[0086] In some embodiments, the apparatus further includes: a task processing module, configured to respond to the processing task based on the target prompt word, the prompt word constraint information, and the model corresponding to the model type, and obtain a model output result; a verification module, configured to verify the model output result according to a preset verification rule, and obtain a verification result; a generation module, configured to generate prompt word repair information if the verification result is incorrect, so as to update the target prompt word through the prompt word repair information, and obtain an updated prompt word for responding to the processing task; and an output module, configured to output the model output result if the verification result is correct.

[0087] The model prompt word generation device provided in this disclosure can execute the model prompt word generation method provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects of the execution method.

[0088] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device embodiments can be referred to the corresponding process in the method embodiments, and will not be repeated here.

[0089] This disclosure provides an electronic device, which includes: a storage device storing a computer program thereon; and a processing device for executing the computer program in the storage device to implement the steps of any method of this disclosure.

[0090] The following is for reference. Figure 5 This diagram illustrates a structural schematic of an electronic device 500 suitable for implementing embodiments of the present disclosure. The terminal devices in these embodiments may include, but are not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0091] like Figure 5As shown, the electronic device 500 may include a processing unit 501 (e.g., a central processing unit, a graphics processor, etc.), 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 device 508 into a random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of the electronic device 500. The processing unit 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0092] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 508 including, for example, magnetic tapes, hard disks, etc.; and communication devices 509. Communication device 509 allows electronic device 500 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 An electronic device 500 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0093] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, it performs the functions defined in the methods of embodiments of this disclosure.

[0094] In addition to the methods and devices described above, embodiments of this disclosure can also be computer program products, comprising computer program instructions that, when executed by a processor, cause the processor to perform the image processing methods provided in the embodiments of this disclosure. The computer program product can be written in any combination of one or more programming languages ​​to perform the operations of the embodiments of this disclosure. The programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on a user's computing device, partially on a user's device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0095] Furthermore, embodiments of this disclosure may also be computer-readable storage media storing computer program instructions that, when executed by a processor, cause the processor to perform the model prompt word generation method provided in embodiments of this disclosure.

[0096] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.

[0097] This disclosure also provides a computer program product, including a computer program / instruction that, when executed by a processor, implements the model prompt word generation method in this disclosure.

[0098] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.

[0099] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.

[0100] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0101] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.

[0102] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0103] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for generating model prompt words, characterized in that, include: Based on the received processing task, obtain the task type and task parameters; Obtain multiple prompt word templates corresponding to the task type, and set the multiple prompt word templates based on the task parameters to obtain multiple sub-prompt words; The multiple sub-prompt words are concatenated according to the preset prompt word template concatenation rules to obtain the model prompt words.

2. The method according to claim 1, characterized in that, The process involves obtaining multiple prompt word templates corresponding to the task type, and setting these templates based on the task parameters to obtain multiple sub-prompt words, including: Obtain multiple prompt word templates matching the task type from the preset task type prompt word template association database; wherein, the multiple prompt word templates include at least one of role definition template, domain knowledge template, logical constraint template and output specification template; Based on the task parameters, the target placeholders in the role definition template, the domain knowledge template, the logical constraint template, and the output specification template are replaced to obtain at least one of the role definition string, the domain knowledge string, the logical constraint string, and the output specification string as the plurality of sub-prompt words.

3. The method according to claim 1, characterized in that, The method further includes: The model type is obtained based on the processing task, and the prompt word constraint information corresponding to the model type is constructed based on the preset model adapter; Obtain the number of characters in the model prompt words, and based on the prompt word constraint information, obtain the context limit number, preset compression strategy, and output rules; If the number of characters in the model prompt word is greater than the number of characters in the context limit, the model prompt word is compressed according to the preset compression strategy to obtain a compressed prompt word. Based on the compressed prompt words and the output rules, target prompt words are generated.

4. The method according to claim 3, characterized in that, The step of compressing the model prompt words according to the preset compression strategy to obtain compressed prompt words includes: According to the preset compression priority setting rules, at least one target type string and the target compression ratio corresponding to the target type string are determined from the model prompt words; The target type string is compressed according to the target compression ratio to obtain candidate prompt words. When the number of characters in the candidate prompt words is less than or equal to the number of characters in the context limit, the candidate prompt words are used as the compressed prompt words.

5. The method according to claim 4, characterized in that, The method further includes: Obtain multiple types of strings from the model prompt words; The compression priority and compression ratio of each type of string are determined to obtain the preset compression priority setting rule.

6. The method according to claim 3, characterized in that, The method further includes: Based on the target prompt word, the prompt word constraint information, and the model response corresponding to the model type, the model output result is obtained from the processing task. The model output is validated according to preset validation rules to obtain validation results. If the verification result is incorrect, prompt word repair information is generated to update the target prompt word, and the updated prompt word is used to respond to the processing task. If the verification result is correct, the model output result is output.

7. A model prompt word generation device, characterized in that, include: The acquisition module is used to obtain the task type and task parameters based on the received processing task; The processing module is used to obtain multiple prompt word templates corresponding to the task type, and set the multiple prompt word templates based on the task parameters to obtain multiple sub-prompt words; The splicing module is used to splice the multiple sub-prompt words according to the preset prompt word template splicing rules to obtain the model prompt words.

8. An electronic device, characterized in that, The electronic device includes: A storage device on which computer programs are stored; A processing device for executing the computer program in the storage device to implement the steps of the model prompt word generation method according to any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The storage medium stores a computer program for executing the model prompt word generation method according to any one of claims 1-6.

10. A computer program product, characterized in that, It includes a computer program, wherein the computer program is executed by a processor using the model prompt word generation method according to any one of claims 1-6.